Author: tkreuzer
Date: Wed Jun 15 21:00:52 2011
New Revision: 52256
URL:
http://svn.reactos.org/svn/reactos?rev=52256&view=rev
Log:
[FREELDR]
- Setup the IDT in C code instead of using 16 bit assembly and relying on trap handlers
being below 64k
- Make the trap handler code MSVC compatible
- Add back multiboot code
Added:
trunk/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c (with props)
Modified:
trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S
trunk/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S
trunk/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S
Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/CMake…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] Wed Jun 15 21:00:52
2011
@@ -9,22 +9,23 @@
endif()
if(ARCH MATCHES i386)
+ list(APPEND FREELDR_BASE64K_SOURCE
+ arch/i386/entry.S
+ arch/i386/i386idt.c
+ arch/i386/i386trap.S
+ arch/i386/i386bug.c)
if(NOT MSVC)
list(APPEND FREELDR_BASE64K_SOURCE
- arch/i386/entry.S
arch/i386/boot.S
arch/i386/drvmap.S
arch/i386/i386cpu.S
- arch/i386/i386idt.S
arch/i386/i386pnp.S
arch/i386/i386pxe.S
- arch/i386/i386trap.S
arch/i386/linux.S
- arch/i386/mb.S
- arch/i386/i386bug.c)
+ arch/i386/multiboot.S
+ arch/i386/mb.S)
else()
list(APPEND FREELDR_BASE64K_SOURCE
- arch/i386/entry.S
arch/i386/realmode.S)
endif()
elseif(ARCH MATCHES amd64)
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S [iso-8859-1] Wed Jun 15 21:00:52
2011
@@ -19,10 +19,11 @@
#include <asm.inc>
#include <arch/pc/x86common.h>
-#include <multiboot.h>
EXTERN _BootMain:PROC
EXTERN _InitIdt:PROC
+EXTERN _i386Idt:DWORD
+//EXTERN _i386idtptr:FWORD
.code32
@@ -41,7 +42,11 @@
mov esp, dword ptr [stack32]
/* Load the IDT */
+#ifdef _USE_ML
+ lidt fword ptr [i386idtptr]
+#else
lidt i386idtptr
+#endif
/* Continue execution */
jmp dword ptr [ContinueAddress]
@@ -62,6 +67,9 @@
/* Patch long jump with real mode entry point */
mov eax, dword ptr ds:[BSS_RealModeEntry]
mov dword ptr ds:[SwitchToReal16Address], eax
+
+ /* Initialize the idt */
+ call _InitIdt
/* GO! */
xor eax, eax
@@ -106,8 +114,9 @@
/* Load the GDT */
lgdt gdtptr
+
/* Load the IDT */
- lidt i386idtptr
+ lidt i386idtptr
/* Enable Protected Mode */
mov eax, cr0
@@ -352,6 +361,11 @@
.word HEX(3ff) /* Limit */
.long 0 /* Base Address */
+PUBLIC i386idtptr
+i386idtptr:
+ .word 255 /* Limit */
+ .long _i386Idt /* Base Address */
+
PUBLIC _FrldrBootDrive
_FrldrBootDrive:
.long 0
Added: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c (added)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c [iso-8859-1] Wed Jun 15
21:00:52 2011
@@ -1,0 +1,42 @@
+
+#include <freeldr.h>
+
+
+KIDTENTRY DECLSPEC_ALIGN(4) i386Idt[32];
+KDESCRIPTOR i386IdtDescriptor = {0, 255, i386Idt};
+
+static
+void
+InitIdtVector(
+ UCHAR Vector,
+ PVOID ServiceHandler,
+ USHORT Access)
+{
+ i386Idt[Vector].Offset = (ULONG)ServiceHandler & 0xffff;
+ i386Idt[Vector].ExtendedOffset = (ULONG)ServiceHandler >> 16;
+ i386Idt[Vector].Selector = PMODE_CS;
+ i386Idt[Vector].Access = Access;
+}
+
+void
+InitIdt(void)
+{
+ InitIdtVector(0, i386DivideByZero, 0x8e00);
+ InitIdtVector(1, i386DebugException, 0x8e00);
+ InitIdtVector(2, i386NMIException, 0x8e00);
+ InitIdtVector(3, i386Breakpoint, 0x8e00);
+ InitIdtVector(4, i386Overflow, 0x8e00);
+ InitIdtVector(5, i386BoundException, 0x8e00);
+ InitIdtVector(6, i386InvalidOpcode, 0x8e00);
+ InitIdtVector(7, i386FPUNotAvailable, 0x8e00);
+ InitIdtVector(8, i386DoubleFault, 0x8e00);
+ InitIdtVector(9, i386CoprocessorSegment, 0x8e00);
+ InitIdtVector(10, i386InvalidTSS, 0x8e00);
+ InitIdtVector(11, i386SegmentNotPresent, 0x8e00);
+ InitIdtVector(12, i386StackException, 0x8e00);
+ InitIdtVector(13, i386GeneralProtectionFault, 0x8e00);
+ InitIdtVector(14, i386PageFault, 0x8e00);
+ InitIdtVector(16, i386CoprocessorError, 0x8e00);
+ InitIdtVector(17, i386AlignmentCheck, 0x8e00);
+ InitIdtVector(18, i386MachineCheck, 0x8e00);
+}
Propchange: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S [iso-8859-1] Wed Jun 15
21:00:52 2011
@@ -17,16 +17,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-.intel_syntax noprefix
- .text
- .code16
-
+#include <asm.inc>
#include <arch/pc/x86common.h>
#include <ver.h>
#define SCREEN_ATTR 0x1f /* Bright white on blue background */
-.macro SAVE_CPU_REGS
+EXTERN _i386PrintExceptionText@12:PROC
+
+.code32
+
+MACRO(SAVE_CPU_REGS)
/* push the rest of the KTRAP_FRAME */
push ebp
push ebx
@@ -60,8 +61,8 @@
sub esp, 44
sgdt [esp]
sidt [esp + 8]
- str [esp + 16]
- sldt [esp + 18]
+ str word ptr [esp + 16]
+ sldt word ptr [esp + 18]
mov eax, dr7;
push eax
mov eax, dr6;
@@ -82,16 +83,14 @@
push eax
mov eax, cr0;
push eax
-.endm
+ENDM
/* Set by each exception handler to the address of the description text */
i386ExceptionIndex:
.long 0
-
/************************************************************************/
i386CommonExceptionHandler:
- .code32
SAVE_CPU_REGS
@@ -108,21 +107,32 @@
iret
-.macro TRAP_STUB function, index
- EXTERN(\function)
+MACRO(TRAP_STUB, function, index)
+ PUBLIC VAL(function)
+#ifdef _USE_ML
+ function:
+#else
+ \function:
+#endif
push 0 // Fake error code
- mov dword ptr i386ExceptionIndex, \index
+ mov dword ptr i386ExceptionIndex, VAL(index)
jmp i386CommonExceptionHandler
-.endm
+ENDM
-.macro TRAP_STUB2 function, index
- EXTERN(\function)
- mov dword ptr i386ExceptionIndex, \index
+MACRO(TRAP_STUB2, function, index)
+ PUBLIC VAL(function)
+#ifdef _USE_ML
+ function:
+#else
+ \function:
+#endif
+ mov dword ptr i386ExceptionIndex, VAL(index)
jmp i386CommonExceptionHandler
-.endm
+ENDM
/************************************************************************/
TRAP_STUB _i386DivideByZero, 0
+
TRAP_STUB _i386DebugException, 1
TRAP_STUB _i386NMIException, 2
TRAP_STUB _i386Breakpoint, 3
@@ -147,30 +157,36 @@
* DEBUGGING SUPPORT FUNCTIONS
************************************************************************/
-.macro BREAKPOINT_TEPLATE functionname, mask1, mask2
- EXTERN(\functionname)
+MACRO(BREAKPOINT_TEPLATE, functionname, mask1, mask2)
+ PUBLIC VAL(functionname)
+#ifdef _USE_ML
+ functionname:
+#else
+ \functionname:
+#endif
push eax
mov eax, [esp + 8]
mov dr3, eax
mov eax, dr7
- and eax, \mask1
- or eax, \mask2
+ and eax, VAL(mask1)
+ or eax, VAL(mask2)
mov dr7, eax
pop eax
ret
-.endm
+ENDM
-BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT1, 0xfff0ffff, 0x00000303
-BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT1, 0xfff0ffff, 0x00030303
-BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT1, 0xfff0ffff, 0x00010303
-BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT2, 0xff0fffff, 0x0000030c
-BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT2, 0xff0fffff, 0x0030030c
-BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT2, 0xff0fffff, 0x0010030c
-BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT3, 0xf0ffffff, 0x00000330
-BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT3, 0xf0ffffff, 0x03000330
-BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT3, 0xf0ffffff, 0x01000330
-BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT4, 0x0fffffff, 0x000003c0
-BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT4, 0x0fffffff, 0x300003c0
-BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT4, 0x0fffffff, 0x100003c0
+BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT1, HEX(0fff0ffff), HEX(000000303)
+BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT1, HEX(0fff0ffff), HEX(000030303)
+BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT1, HEX(0fff0ffff), HEX(000010303)
+BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT2, HEX(0ff0fffff), HEX(00000030c)
+BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT2, HEX(0ff0fffff), HEX(00030030c)
+BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT2, HEX(0ff0fffff), HEX(00010030c)
+BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT3, HEX(0f0ffffff), HEX(000000330)
+BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT3, HEX(0f0ffffff), HEX(003000330)
+BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT3, HEX(0f0ffffff), HEX(001000330)
+BREAKPOINT_TEPLATE _INSTRUCTION_BREAKPOINT4, HEX(00fffffff), HEX(0000003c0)
+BREAKPOINT_TEPLATE _MEMORY_READWRITE_BREAKPOINT4, HEX(00fffffff), HEX(0300003c0)
+BREAKPOINT_TEPLATE _MEMORY_WRITE_BREAKPOINT4, HEX(00fffffff), HEX(0100003c0)
+END
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S [iso-8859-1] Wed Jun 15
21:00:52 2011
@@ -26,6 +26,8 @@
*
* Allows freeldr to be loaded as a "multiboot kernel" by
* other boot loaders like Grub
+ * This code is not referenced from anywhere. GRUB searches for
+ * the header signature and uses the header to load it.
*/
#define MB_INFO_SIZE 90
@@ -172,6 +174,43 @@
cmdline:
.fill CMDLINE_SIZE, 1, 0
+.align 4 /* force 4-byte alignment */
+gdt:
+ /* NULL Descriptor */
+ .word HEX(0000)
+ .word HEX(0000)
+ .word HEX(0000)
+ .word HEX(0000)
+
+ /* 32-bit flat CS */
+ .word HEX(FFFF)
+ .word HEX(0000)
+ .word HEX(9A00)
+ .word HEX(00CF)
+
+ /* 32-bit flat DS */
+ .word HEX(FFFF)
+ .word HEX(0000)
+ .word HEX(9200)
+ .word HEX(00CF)
+
+ /* 16-bit real mode CS */
+ .word HEX(FFFF)
+ .word HEX(0000)
+ .word HEX(9E00)
+ .word HEX(0000)
+
+ /* 16-bit real mode DS */
+ .word HEX(FFFF)
+ .word HEX(0000)
+ .word HEX(9200)
+ .word HEX(0000)
+
+/* GDT table pointer */
+gdtptr:
+ .word HEX(27) /* Limit */
+ .long gdt /* Base Address */
+
/* Initial GDT table pointer for multiboot */
gdtptrhigh:
.word HEX(27) /* Limit */