[MINIHAL] Minor improvements (#7398)
authorDmitry Borisov <di.sean@protonmail.com>
Tue, 11 Mar 2025 07:30:14 +0000 (13:30 +0600)
committerGitHub <noreply@github.com>
Tue, 11 Mar 2025 07:30:14 +0000 (10:30 +0300)
* [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
boot/freeldr/freeldr/arch/i386/i386bug.c
boot/freeldr/freeldr/arch/i386/i386trap.S
boot/freeldr/freeldr/arch/uefi/uefildr.c
boot/freeldr/freeldr/include/arch/arm/hardware.h
boot/freeldr/freeldr/include/arch/pc/hardware.h
boot/freeldr/freeldr/include/arch/pc/pcbios.h
boot/freeldr/freeldr/include/debug.h
boot/freeldr/freeldr/include/linux.h
hal/halx86/include/halp.h
hal/halx86/minihal/CMakeLists.txt

index f7d65d2..97fea6e 100644 (file)
@@ -24,6 +24,7 @@ Rs232PortPutByte(UCHAR ByteToSend)
     *UART0DR = ByteToSend;
 }
 
+DECLSPEC_NORETURN
 VOID
 FrLdrBugCheckWithMessage(
     ULONG BugCode,
index 1276dda..0627f1d 100644 (file)
@@ -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)
index bbc5367..95b41cc 100644 (file)
@@ -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
index 69d5041..e694b7a 100644 (file)
@@ -80,6 +80,7 @@ ExecuteLoaderCleanly(PVOID PreviousStack)
 }
 
 #ifndef _M_ARM
+DECLSPEC_NORETURN
 VOID __cdecl Reboot(VOID)
 {
     //TODO: Replace with a true firmware reboot eventually
index 51ed5a8..a821391 100644 (file)
@@ -34,6 +34,7 @@ extern ULONG gDiskReadBuffer, gFileSysBuffer;
 
 #define DriveMapGetBiosDriveNumber(DeviceName) 0
 
+DECLSPEC_NORETURN
 FORCEINLINE VOID Reboot(VOID)
 {
     DbgBreakPoint();
index de408b7..6ca98ed 100644 (file)
 #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 */
index f3539d2..5b876d0 100644 (file)
@@ -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__ */
index 6460cac..efff30f 100644 (file)
@@ -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,
index f7591db..d55bf8d 100644 (file)
@@ -129,6 +129,7 @@ typedef struct
 #include <poppack.h>
 
 // Implemented in linux.S
+DECLSPEC_NORETURN
 VOID __cdecl
 BootLinuxKernel(
     _In_ ULONG KernelSize,
index ef61116..5c323ff 100644 (file)
@@ -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;
index 4a7ca0f..13faf2e 100644 (file)
@@ -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