Skip to content

Commit 029e53d

Browse files
authored
[MINIHAL] Minor improvements (reactos#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
1 parent 0089017 commit 029e53d

File tree

11 files changed

+64
-23
lines changed

11 files changed

+64
-23
lines changed

boot/freeldr/freeldr/arch/arm/debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Rs232PortPutByte(UCHAR ByteToSend)
2424
*UART0DR = ByteToSend;
2525
}
2626

27+
DECLSPEC_NORETURN
2728
VOID
2829
FrLdrBugCheckWithMessage(
2930
ULONG BugCode,

boot/freeldr/freeldr/arch/i386/i386bug.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ typedef struct _FRAME
1212

1313
static const CHAR *i386ExceptionDescriptionText[] =
1414
{
15-
"Exception 00: DIVIDE BY ZERO",
16-
"Exception 01: DEBUG EXCEPTION",
17-
"Exception 02: NON-MASKABLE INTERRUPT EXCEPTION",
18-
"Exception 03: BREAKPOINT (INT 3)",
19-
"Exception 04: OVERFLOW",
20-
"Exception 05: BOUND EXCEPTION",
21-
"Exception 06: INVALID OPCODE",
22-
"Exception 07: FPU NOT AVAILABLE",
23-
"Exception 08: DOUBLE FAULT",
24-
"Exception 09: COPROCESSOR SEGMENT OVERRUN",
25-
"Exception 0A: INVALID TSS",
26-
"Exception 0B: SEGMENT NOT PRESENT",
27-
"Exception 0C: STACK EXCEPTION",
28-
"Exception 0D: GENERAL PROTECTION FAULT",
29-
"Exception 0E: PAGE FAULT",
30-
"Exception 0F: Reserved",
31-
"Exception 10: COPROCESSOR ERROR",
32-
"Exception 11: ALIGNMENT CHECK",
33-
"Exception 12: MACHINE CHECK"
15+
"DIVIDE BY ZERO",
16+
"DEBUG EXCEPTION",
17+
"NON-MASKABLE INTERRUPT EXCEPTION",
18+
"BREAKPOINT (INT 3)",
19+
"OVERFLOW",
20+
"BOUND EXCEPTION",
21+
"INVALID OPCODE",
22+
"FPU NOT AVAILABLE",
23+
"DOUBLE FAULT",
24+
"COPROCESSOR SEGMENT OVERRUN",
25+
"INVALID TSS",
26+
"SEGMENT NOT PRESENT",
27+
"STACK EXCEPTION",
28+
"GENERAL PROTECTION FAULT",
29+
"PAGE FAULT",
30+
"Reserved",
31+
"COPROCESSOR ERROR",
32+
"ALIGNMENT CHECK",
33+
"MACHINE CHECK"
3434
};
3535

3636
#define SCREEN_ATTR 0x1F // Bright white on blue background
@@ -118,7 +118,10 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGIST
118118

119119
PrintText("FreeLdr " KERNEL_VERSION_STR " " KERNEL_VERSION_BUILD_STR "\n"
120120
"Report this error on the ReactOS Bug Tracker: https://jira.reactos.org\n\n"
121-
"0x%02lx: %s\n\n", TrapIndex, i386ExceptionDescriptionText[TrapIndex]);
121+
"0x%02lx: Exception %02X: %s\n\n",
122+
TrapIndex,
123+
TrapIndex,
124+
i386ExceptionDescriptionText[TrapIndex]);
122125

123126
#ifdef _M_IX86
124127
PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
@@ -194,6 +197,7 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGIST
194197
InstructionPointer[6], InstructionPointer[7]);
195198
}
196199

200+
DECLSPEC_NORETURN
197201
VOID
198202
FrLdrBugCheckWithMessage(
199203
ULONG BugCode,
@@ -227,8 +231,9 @@ FrLdrBugCheckWithMessage(
227231
for (;;);
228232
}
229233

234+
static
235+
DECLSPEC_NORETURN
230236
void
231-
NTAPI
232237
FrLdrBugCheckEx(
233238
ULONG BugCode,
234239
PCHAR File,
@@ -256,6 +261,7 @@ FrLdrBugCheckEx(
256261
for (;;);
257262
}
258263

264+
DECLSPEC_NORETURN
259265
void
260266
NTAPI
261267
FrLdrBugCheck(ULONG BugCode)

boot/freeldr/freeldr/arch/i386/i386trap.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ TRAP_STUB _i386AlignmentCheck, 17
142142
TRAP_STUB _i386MachineCheck, 18
143143
TRAP_STUB _i386SimdFloatError, 19
144144

145+
#if DBG
145146
/************************************************************************
146147
* DEBUGGING SUPPORT FUNCTIONS
147148
************************************************************************/
@@ -176,5 +177,6 @@ BREAKPOINT_TEMPLATE _MEMORY_WRITE_BREAKPOINT3, HEX(0f0ffffff), HEX(001000330)
176177
BREAKPOINT_TEMPLATE _INSTRUCTION_BREAKPOINT4, HEX(00fffffff), HEX(0000003c0)
177178
BREAKPOINT_TEMPLATE _MEMORY_READWRITE_BREAKPOINT4, HEX(00fffffff), HEX(0300003c0)
178179
BREAKPOINT_TEMPLATE _MEMORY_WRITE_BREAKPOINT4, HEX(00fffffff), HEX(0100003c0)
180+
#endif // DBG
179181

180182
END

boot/freeldr/freeldr/arch/uefi/uefildr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ExecuteLoaderCleanly(PVOID PreviousStack)
8080
}
8181

8282
#ifndef _M_ARM
83+
DECLSPEC_NORETURN
8384
VOID __cdecl Reboot(VOID)
8485
{
8586
//TODO: Replace with a true firmware reboot eventually

boot/freeldr/freeldr/include/arch/arm/hardware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern ULONG gDiskReadBuffer, gFileSysBuffer;
3434

3535
#define DriveMapGetBiosDriveNumber(DeviceName) 0
3636

37+
DECLSPEC_NORETURN
3738
FORCEINLINE VOID Reboot(VOID)
3839
{
3940
DbgBreakPoint();

boot/freeldr/freeldr/include/arch/pc/hardware.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
#define TAG_HW_RESOURCE_LIST 'lRwH'
2424
#define TAG_HW_DISK_CONTEXT 'cDwH'
2525

26+
/*
27+
* These aren't defined in the ioaccess.h header.
28+
* Because of that we manually define the symbols we need to make use of I/O ports.
29+
*/
30+
#define READ_PORT_BUFFER_UCHAR(port, buffer, count) __inbytestring(H2I(port), buffer, count)
31+
#define READ_PORT_BUFFER_USHORT(port, buffer, count) __inwordstring(H2I(port), buffer, count)
32+
#define READ_PORT_BUFFER_ULONG(port, buffer, count) __indwordstring(H2I(port), buffer, count)
33+
#define WRITE_PORT_BUFFER_UCHAR(port, buffer, count) __outbytestring(H2I(port), buffer, count)
34+
#define WRITE_PORT_BUFFER_USHORT(port, buffer, count) __outwordstring(H2I(port), buffer, count)
35+
#define WRITE_PORT_BUFFER_ULONG(port, buffer, count) __outdwordstring(H2I(port), buffer, count)
36+
2637
/* PROTOTYPES ***************************************************************/
2738

2839
/* hardware.c */

boot/freeldr/freeldr/include/arch/pc/pcbios.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,17 @@ VOID __cdecl ChainLoadBiosBootSectorCode(
182182
IN UCHAR BootDrive OPTIONAL,
183183
IN ULONG BootPartition OPTIONAL);
184184

185+
DECLSPEC_NORETURN
185186
VOID __cdecl Relocator16Boot(
186187
IN REGS* In,
187188
IN USHORT StackSegment,
188189
IN USHORT StackPointer,
189190
IN USHORT CodeSegment,
190191
IN USHORT CodePointer);
191192

193+
DECLSPEC_NORETURN
192194
VOID __cdecl Reboot(VOID);
195+
193196
VOID DetectHardware(VOID);
194197

195198
#endif /* ! __ASM__ */

boot/freeldr/freeldr/include/debug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
//
8686
// You may have as many BREAKPOINT()'s as you like but you may only
8787
// have up to four of any of the others.
88-
#define BREAKPOINT() __asm__ ("int $3");
88+
#define BREAKPOINT() __debugbreak()
8989
void INSTRUCTION_BREAKPOINT1(unsigned long addr);
9090
void MEMORY_READWRITE_BREAKPOINT1(unsigned long addr);
9191
void MEMORY_WRITE_BREAKPOINT1(unsigned long addr);
@@ -125,10 +125,12 @@ void MEMORY_WRITE_BREAKPOINT4(unsigned long addr);
125125

126126
#endif // DBG
127127

128+
DECLSPEC_NORETURN
128129
void
129130
NTAPI
130131
FrLdrBugCheck(ULONG BugCode);
131132

133+
DECLSPEC_NORETURN
132134
VOID
133135
FrLdrBugCheckWithMessage(
134136
ULONG BugCode,

boot/freeldr/freeldr/include/linux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef struct
129129
#include <poppack.h>
130130

131131
// Implemented in linux.S
132+
DECLSPEC_NORETURN
132133
VOID __cdecl
133134
BootLinuxKernel(
134135
_In_ ULONG KernelSize,

hal/halx86/include/halp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,20 @@ HalInitializeBios(
588588
#define KiEnterInterruptTrap(TrapFrame) /* We do all neccessary in asm code */
589589
#endif // _M_AMD64
590590

591+
#ifdef _MINIHAL_
592+
#if defined(_M_IX86) || defined(_M_AMD64)
593+
/* Use intrinsics for IA-32 and amd64 */
594+
#include <ioaccess.h>
595+
596+
#define READ_PORT_BUFFER_UCHAR(port, buffer, count) __inbytestring(H2I(port), buffer, count)
597+
#define READ_PORT_BUFFER_USHORT(port, buffer, count) __inwordstring(H2I(port), buffer, count)
598+
#define READ_PORT_BUFFER_ULONG(port, buffer, count) __indwordstring(H2I(port), buffer, count)
599+
#define WRITE_PORT_BUFFER_UCHAR(port, buffer, count) __outbytestring(H2I(port), buffer, count)
600+
#define WRITE_PORT_BUFFER_USHORT(port, buffer, count) __outwordstring(H2I(port), buffer, count)
601+
#define WRITE_PORT_BUFFER_ULONG(port, buffer, count) __outdwordstring(H2I(port), buffer, count)
602+
#endif
603+
#endif
604+
591605
extern BOOLEAN HalpNMIInProgress;
592606

593607
extern ADDRESS_USAGE HalpDefaultIoSpace;

0 commit comments

Comments
 (0)