https://git.reactos.org/?p=reactos.git;a=commitdiff;h=029e53ddb56a5eb4e94d30a17ef9bcd40ef7434e

commit 029e53ddb56a5eb4e94d30a17ef9bcd40ef7434e
Author:     Dmitry Borisov <di.s...@protonmail.com>
AuthorDate: Tue Mar 11 13:30:14 2025 +0600
Commit:     GitHub <nore...@github.com>
CommitDate: Tue Mar 11 10:30:14 2025 +0300

    [MINIHAL] Minor improvements (#7398)
    
    * [FREELDR] Mark noreturn functions
    
    * [FREELDR] Compile hw debugging support code only in debug builds
    
    - Make BREAKPOINT() portable
    
    * [FREELDR] Consolidate identical names into a single string
    
    * [FREELDR] Use intrinsics for string I/O operations on x86 and x64
    
    Stop them being pulled in from a static minihal library
    
    * [MINIHAL] Exclude unnecessary portio dependency
---
 boot/freeldr/freeldr/arch/arm/debug.c            |  1 +
 boot/freeldr/freeldr/arch/i386/i386bug.c         | 48 +++++++++++++-----------
 boot/freeldr/freeldr/arch/i386/i386trap.S        |  2 +
 boot/freeldr/freeldr/arch/uefi/uefildr.c         |  1 +
 boot/freeldr/freeldr/include/arch/arm/hardware.h |  1 +
 boot/freeldr/freeldr/include/arch/pc/hardware.h  | 11 ++++++
 boot/freeldr/freeldr/include/arch/pc/pcbios.h    |  3 ++
 boot/freeldr/freeldr/include/debug.h             |  4 +-
 boot/freeldr/freeldr/include/linux.h             |  1 +
 hal/halx86/include/halp.h                        | 14 +++++++
 hal/halx86/minihal/CMakeLists.txt                |  1 -
 11 files changed, 64 insertions(+), 23 deletions(-)

diff --git a/boot/freeldr/freeldr/arch/arm/debug.c 
b/boot/freeldr/freeldr/arch/arm/debug.c
index f7d65d2bfc5..97fea6e6a31 100644
--- a/boot/freeldr/freeldr/arch/arm/debug.c
+++ b/boot/freeldr/freeldr/arch/arm/debug.c
@@ -24,6 +24,7 @@ Rs232PortPutByte(UCHAR ByteToSend)
     *UART0DR = ByteToSend;
 }
 
+DECLSPEC_NORETURN
 VOID
 FrLdrBugCheckWithMessage(
     ULONG BugCode,
diff --git a/boot/freeldr/freeldr/arch/i386/i386bug.c 
b/boot/freeldr/freeldr/arch/i386/i386bug.c
index 1276ddad9bc..0627f1d5d24 100644
--- a/boot/freeldr/freeldr/arch/i386/i386bug.c
+++ b/boot/freeldr/freeldr/arch/i386/i386bug.c
@@ -12,25 +12,25 @@ typedef struct _FRAME
 
 static const CHAR *i386ExceptionDescriptionText[] =
 {
-    "Exception 00: DIVIDE BY ZERO",
-    "Exception 01: DEBUG EXCEPTION",
-    "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION",
-    "Exception 03: BREAKPOINT (INT 3)",
-    "Exception 04: OVERFLOW",
-    "Exception 05: BOUND EXCEPTION",
-    "Exception 06: INVALID OPCODE",
-    "Exception 07: FPU NOT AVAILABLE",
-    "Exception 08: DOUBLE FAULT",
-    "Exception 09: COPROCESSOR SEGMENT OVERRUN",
-    "Exception 0A: INVALID TSS",
-    "Exception 0B: SEGMENT NOT PRESENT",
-    "Exception 0C: STACK EXCEPTION",
-    "Exception 0D: GENERAL PROTECTION FAULT",
-    "Exception 0E: PAGE FAULT",
-    "Exception 0F: Reserved",
-    "Exception 10: COPROCESSOR ERROR",
-    "Exception 11: ALIGNMENT CHECK",
-    "Exception 12: MACHINE CHECK"
+    "DIVIDE BY ZERO",
+    "DEBUG EXCEPTION",
+    "NON-MASKABLE INTERRUPT EXCEPTION",
+    "BREAKPOINT (INT 3)",
+    "OVERFLOW",
+    "BOUND EXCEPTION",
+    "INVALID OPCODE",
+    "FPU NOT AVAILABLE",
+    "DOUBLE FAULT",
+    "COPROCESSOR SEGMENT OVERRUN",
+    "INVALID TSS",
+    "SEGMENT NOT PRESENT",
+    "STACK EXCEPTION",
+    "GENERAL PROTECTION FAULT",
+    "PAGE FAULT",
+    "Reserved",
+    "COPROCESSOR ERROR",
+    "ALIGNMENT CHECK",
+    "MACHINE CHECK"
 };
 
 #define SCREEN_ATTR 0x1F    // Bright white on blue background
@@ -118,7 +118,10 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME 
TrapFrame, PKSPECIAL_REGIST
 
     PrintText("FreeLdr " KERNEL_VERSION_STR " " KERNEL_VERSION_BUILD_STR "\n"
               "Report this error on the ReactOS Bug Tracker: 
https://jira.reactos.org\n\n";
-              "0x%02lx: %s\n\n", TrapIndex, 
i386ExceptionDescriptionText[TrapIndex]);
+              "0x%02lx: Exception %02X: %s\n\n",
+              TrapIndex,
+              TrapIndex,
+              i386ExceptionDescriptionText[TrapIndex]);
 
 #ifdef _M_IX86
     PrintText("EAX: %.8lx        ESP: %.8lx        CR0: %.8lx        DR0: 
%.8lx\n",
@@ -194,6 +197,7 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME 
TrapFrame, PKSPECIAL_REGIST
               InstructionPointer[6], InstructionPointer[7]);
 }
 
+DECLSPEC_NORETURN
 VOID
 FrLdrBugCheckWithMessage(
     ULONG BugCode,
@@ -227,8 +231,9 @@ FrLdrBugCheckWithMessage(
     for (;;);
 }
 
+static
+DECLSPEC_NORETURN
 void
-NTAPI
 FrLdrBugCheckEx(
     ULONG BugCode,
     PCHAR File,
@@ -256,6 +261,7 @@ FrLdrBugCheckEx(
     for (;;);
 }
 
+DECLSPEC_NORETURN
 void
 NTAPI
 FrLdrBugCheck(ULONG BugCode)
diff --git a/boot/freeldr/freeldr/arch/i386/i386trap.S 
b/boot/freeldr/freeldr/arch/i386/i386trap.S
index bbc5367d70d..95b41ccd80a 100644
--- a/boot/freeldr/freeldr/arch/i386/i386trap.S
+++ b/boot/freeldr/freeldr/arch/i386/i386trap.S
@@ -142,6 +142,7 @@ TRAP_STUB _i386AlignmentCheck, 17
 TRAP_STUB _i386MachineCheck, 18
 TRAP_STUB _i386SimdFloatError, 19
 
+#if DBG
 /************************************************************************
  * DEBUGGING SUPPORT FUNCTIONS
  ************************************************************************/
@@ -176,5 +177,6 @@ BREAKPOINT_TEMPLATE _MEMORY_WRITE_BREAKPOINT3, 
HEX(0f0ffffff), HEX(001000330)
 BREAKPOINT_TEMPLATE _INSTRUCTION_BREAKPOINT4, HEX(00fffffff), HEX(0000003c0)
 BREAKPOINT_TEMPLATE _MEMORY_READWRITE_BREAKPOINT4, HEX(00fffffff), 
HEX(0300003c0)
 BREAKPOINT_TEMPLATE _MEMORY_WRITE_BREAKPOINT4, HEX(00fffffff), HEX(0100003c0)
+#endif // DBG
 
 END
diff --git a/boot/freeldr/freeldr/arch/uefi/uefildr.c 
b/boot/freeldr/freeldr/arch/uefi/uefildr.c
index 69d5041d2ca..e694b7aa2b0 100644
--- a/boot/freeldr/freeldr/arch/uefi/uefildr.c
+++ b/boot/freeldr/freeldr/arch/uefi/uefildr.c
@@ -80,6 +80,7 @@ ExecuteLoaderCleanly(PVOID PreviousStack)
 }
 
 #ifndef _M_ARM
+DECLSPEC_NORETURN
 VOID __cdecl Reboot(VOID)
 {
     //TODO: Replace with a true firmware reboot eventually
diff --git a/boot/freeldr/freeldr/include/arch/arm/hardware.h 
b/boot/freeldr/freeldr/include/arch/arm/hardware.h
index 51ed5a8ebcf..a821391265a 100644
--- a/boot/freeldr/freeldr/include/arch/arm/hardware.h
+++ b/boot/freeldr/freeldr/include/arch/arm/hardware.h
@@ -34,6 +34,7 @@ extern ULONG gDiskReadBuffer, gFileSysBuffer;
 
 #define DriveMapGetBiosDriveNumber(DeviceName) 0
 
+DECLSPEC_NORETURN
 FORCEINLINE VOID Reboot(VOID)
 {
     DbgBreakPoint();
diff --git a/boot/freeldr/freeldr/include/arch/pc/hardware.h 
b/boot/freeldr/freeldr/include/arch/pc/hardware.h
index de408b74cd9..6ca98ed6a0c 100644
--- a/boot/freeldr/freeldr/include/arch/pc/hardware.h
+++ b/boot/freeldr/freeldr/include/arch/pc/hardware.h
@@ -23,6 +23,17 @@
 #define TAG_HW_RESOURCE_LIST    'lRwH'
 #define TAG_HW_DISK_CONTEXT     'cDwH'
 
+/*
+ * These aren't defined in the ioaccess.h header.
+ * Because of that we manually define the symbols we need to make use of I/O 
ports.
+ */
+#define READ_PORT_BUFFER_UCHAR(port, buffer, count)   
__inbytestring(H2I(port), buffer, count)
+#define READ_PORT_BUFFER_USHORT(port, buffer, count)  
__inwordstring(H2I(port), buffer, count)
+#define READ_PORT_BUFFER_ULONG(port, buffer, count)   
__indwordstring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_UCHAR(port, buffer, count)  
__outbytestring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_USHORT(port, buffer, count) 
__outwordstring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_ULONG(port, buffer, count)  
__outdwordstring(H2I(port), buffer, count)
+
 /* PROTOTYPES ***************************************************************/
 
 /* hardware.c */
diff --git a/boot/freeldr/freeldr/include/arch/pc/pcbios.h 
b/boot/freeldr/freeldr/include/arch/pc/pcbios.h
index f3539d21426..5b876d07ae8 100644
--- a/boot/freeldr/freeldr/include/arch/pc/pcbios.h
+++ b/boot/freeldr/freeldr/include/arch/pc/pcbios.h
@@ -182,6 +182,7 @@ VOID __cdecl ChainLoadBiosBootSectorCode(
     IN UCHAR BootDrive OPTIONAL,
     IN ULONG BootPartition OPTIONAL);
 
+DECLSPEC_NORETURN
 VOID __cdecl Relocator16Boot(
     IN REGS*  In,
     IN USHORT StackSegment,
@@ -189,7 +190,9 @@ VOID __cdecl Relocator16Boot(
     IN USHORT CodeSegment,
     IN USHORT CodePointer);
 
+DECLSPEC_NORETURN
 VOID __cdecl Reboot(VOID);
+
 VOID DetectHardware(VOID);
 
 #endif /* ! __ASM__ */
diff --git a/boot/freeldr/freeldr/include/debug.h 
b/boot/freeldr/freeldr/include/debug.h
index 6460cacd2c3..efff30f3954 100644
--- a/boot/freeldr/freeldr/include/debug.h
+++ b/boot/freeldr/freeldr/include/debug.h
@@ -85,7 +85,7 @@
     //
     // You may have as many BREAKPOINT()'s as you like but you may only
     // have up to four of any of the others.
-#define    BREAKPOINT()                __asm__ ("int $3");
+#define    BREAKPOINT()                __debugbreak()
 void    INSTRUCTION_BREAKPOINT1(unsigned long addr);
 void    MEMORY_READWRITE_BREAKPOINT1(unsigned long addr);
 void    MEMORY_WRITE_BREAKPOINT1(unsigned long addr);
@@ -125,10 +125,12 @@ void    MEMORY_WRITE_BREAKPOINT4(unsigned long addr);
 
 #endif // DBG
 
+DECLSPEC_NORETURN
 void
 NTAPI
 FrLdrBugCheck(ULONG BugCode);
 
+DECLSPEC_NORETURN
 VOID
 FrLdrBugCheckWithMessage(
     ULONG BugCode,
diff --git a/boot/freeldr/freeldr/include/linux.h 
b/boot/freeldr/freeldr/include/linux.h
index f7591db7410..d55bf8d51da 100644
--- a/boot/freeldr/freeldr/include/linux.h
+++ b/boot/freeldr/freeldr/include/linux.h
@@ -129,6 +129,7 @@ typedef struct
 #include <poppack.h>
 
 // Implemented in linux.S
+DECLSPEC_NORETURN
 VOID __cdecl
 BootLinuxKernel(
     _In_ ULONG KernelSize,
diff --git a/hal/halx86/include/halp.h b/hal/halx86/include/halp.h
index ef6111654df..5c323ffbc02 100644
--- a/hal/halx86/include/halp.h
+++ b/hal/halx86/include/halp.h
@@ -588,6 +588,20 @@ HalInitializeBios(
 #define KiEnterInterruptTrap(TrapFrame) /* We do all neccessary in asm code */
 #endif // _M_AMD64
 
+#ifdef _MINIHAL_
+#if defined(_M_IX86) || defined(_M_AMD64)
+/* Use intrinsics for IA-32 and amd64 */
+#include <ioaccess.h>
+
+#define READ_PORT_BUFFER_UCHAR(port, buffer, count)   
__inbytestring(H2I(port), buffer, count)
+#define READ_PORT_BUFFER_USHORT(port, buffer, count)  
__inwordstring(H2I(port), buffer, count)
+#define READ_PORT_BUFFER_ULONG(port, buffer, count)   
__indwordstring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_UCHAR(port, buffer, count)  
__outbytestring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_USHORT(port, buffer, count) 
__outwordstring(H2I(port), buffer, count)
+#define WRITE_PORT_BUFFER_ULONG(port, buffer, count)  
__outdwordstring(H2I(port), buffer, count)
+#endif
+#endif
+
 extern BOOLEAN HalpNMIInProgress;
 
 extern ADDRESS_USAGE HalpDefaultIoSpace;
diff --git a/hal/halx86/minihal/CMakeLists.txt 
b/hal/halx86/minihal/CMakeLists.txt
index 4a7ca0f9d89..13faf2ee5fc 100644
--- a/hal/halx86/minihal/CMakeLists.txt
+++ b/hal/halx86/minihal/CMakeLists.txt
@@ -5,7 +5,6 @@
 add_definitions(-D_MINIHAL_)
 
 list(APPEND MINI_HAL_SOURCE
-    ../generic/portio.c
     ../legacy/bus/bushndlr.c
     ../legacy/bus/cmosbus.c
     ../legacy/bus/isabus.c

Reply via email to