Author: tkreuzer
Date: Mon Jun 13 20:03:55 2011
New Revision: 52221
URL:
http://svn.reactos.org/svn/reactos?rev=52221&view=rev
Log:
[FREELDR]
Start moving the 16 bit code into the raw binary chunk.
We now switch to protected mode before jumping to the PE entry point
Added:
trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S
- copied, changed from r52207, trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S
Modified:
trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
trunk/reactos/boot/freeldr/freeldr/arch/realmode/i386.S
trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h
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] Mon Jun 13 20:03:55
2011
@@ -9,26 +9,9 @@
endif()
if(ARCH MATCHES i386)
- if(MSVC)
- list(APPEND FREELDR_BASE64K_SOURCE
- arch/i386/realmode.S)
- else()
- list(APPEND FREELDR_STARTUP_SOURCE
- arch/i386/arch.S)
- endif()
-elseif(ARCH MATCHES amd64)
- if(MSVC)
- list(APPEND FREELDR_BASE64K_SOURCE
- arch/amd64/stubs.S)
- else()
- list(APPEND FREELDR_STARTUP_SOURCE
- arch/amd64/arch.S)
- endif()
-endif()
-
-if(ARCH MATCHES i386)
if(NOT MSVC)
list(APPEND FREELDR_BASE64K_SOURCE
+ arch/i386/entry.S
arch/i386/boot.S
arch/i386/drvmap.S
arch/i386/i386cpu.S
@@ -40,15 +23,21 @@
arch/i386/linux.S
arch/i386/mb.S
arch/i386/i386bug.c)
+ else()
+ list(APPEND FREELDR_BASE64K_SOURCE
+ arch/i386/realmode.S)
endif()
elseif(ARCH MATCHES amd64)
if(NOT MSVC)
- list(APPEND FREELDR_BASE64K_SOURCE
- arch/i386/drvmap.S
- arch/i386/i386cpu.S
- arch/i386/i386idt.S
- arch/i386/i386trap.S
- arch/amd64/mb.S)
+ list(APPEND FREELDR_BASE64K_SOURCE
+ arch/i386/drvmap.S
+ arch/i386/i386cpu.S
+ arch/i386/i386idt.S
+ arch/i386/i386trap.S
+ arch/amd64/mb.S)
+ else()
+ list(APPEND FREELDR_BASE64K_SOURCE
+ arch/amd64/stubs.S)
endif()
endif()
@@ -187,7 +176,6 @@
list(APPEND FREELDR_SOURCE
bootmgr.c
- ${FREELDR_STARTUP_SOURCE}
${FREELDR_BASE64K_SOURCE}
${FREELDR_BASE_SOURCE}
)
@@ -242,7 +230,6 @@
endif()
list(APPEND SETUPLDR_SOURCE
- ${FREELDR_STARTUP_SOURCE}
${FREELDR_BASE64K_SOURCE}
${FREELDR_BASE_SOURCE}
${SETUPLDR_MAIN_SOURCE})
Copied: trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S (from r52207,
trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S)
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/entry.S [iso-8859-1] Mon Jun 13 20:03:55
2011
@@ -20,52 +20,49 @@
.intel_syntax noprefix
#define HEX(y) 0x##y
+#include <asm.inc>
#include <arch/pc/x86common.h>
#include <multiboot.h>
- .code16
-
-EXTERN(_RealEntryPoint)
-
- cli
-
- /* Setup segment registers */
- xor ax, ax
+.code32
+
+PUBLIC _RealEntryPoint
+_RealEntryPoint:
+
+ /* Setup segment selectors */
+ mov ax, PMODE_DS
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
- /* Setup a stack */
- mov sp, word ptr ds:stack16
-
- sti
-
- /* Init pmode */
- call switch_to_prot
-
- .code32
-
- /* Zero BootDrive and BootPartition */
+ /* Setup protected mode stack */
+ mov esp, dword ptr [stack32]
+
+ /* Load the IDT */
+ lidt i386idtptr
+
+ /* Continue execution */
+ jmp dword ptr [_ContinueAddress]
+
+_ContinueAddress:
+ .long _FrldrStartup
+
+
+_FrldrStartup:
+
+ /* Store BootDrive and BootPartition */
+ xor eax, eax
+ mov al, dl
+ mov dword ptr [_FrldrBootDrive], eax
+ mov al, dh
+ mov dword ptr [_FrldrBootPartition], eax
+
+ /* GO! */
xor eax, eax
- mov dword ptr [_FrldrBootDrive], eax
- mov dword ptr [_FrldrBootPartition], eax
-
- /* Store the boot drive */
- mov byte ptr [_FrldrBootDrive], dl
-
- /* Store the boot partition */
- mov byte ptr [_FrldrBootPartition], dh
-
- /* GO! */
push eax
- call _BootMain
-
- call switch_to_real
- .code16
-
- int HEX(19)
+ call _BootMain
/* We should never get here */
stop:
@@ -399,12 +396,12 @@
mov eax, [ebx + MB_INFO_BOOT_DEVICE_OFFSET]
shr eax, 16
inc al
- mov byte ptr _FrldrBootPartition, al
- mov byte ptr _FrldrBootDrive, ah
+ mov byte ptr [_FrldrBootPartition], al
+ mov byte ptr [_FrldrBootDrive], ah
jmp mb6
mb5: /* No boot device known, assume first partition of first harddisk */
- mov byte ptr _FrldrBootDrive, HEX(80)
- mov byte ptr _FrldrBootPartition, 1
+ mov byte ptr [_FrldrBootDrive], HEX(80)
+ mov byte ptr [_FrldrBootPartition], 1
mb6:
/* Check for command line */
mov eax, offset cmdline
@@ -495,8 +492,12 @@
cmdline:
.fill CMDLINE_SIZE, 1, 0
-EXTERN(_FrldrBootDrive)
+PUBLIC _FrldrBootDrive
+_FrldrBootDrive:
.long 0
-EXTERN(_FrldrBootPartition)
+PUBLIC _FrldrBootPartition
+_FrldrBootPartition:
.long 0
+
+END
Modified: trunk/reactos/boot/freeldr/freeldr/arch/realmode/i386.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/realmode/i386.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/realmode/i386.S [iso-8859-1] Mon Jun 13
20:03:55 2011
@@ -12,17 +12,101 @@
#include "fathelp.inc"
.org 512
-RealEntryPoint:
+RealModeEntryPoint:
+
+ cli
+
+ /* Setup segment registers */
+ xor ax, ax
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov ss, ax
+
+ /* Setup the stack */
+ mov sp, word ptr ds:stack16
/* Get address of optional header */
mov eax, dword ptr ds:[FREELDR_PE_BASE + IMAGE_DOS_HEADER_e_lfanew]
add eax, FREELDR_PE_BASE + 4 + IMAGE_FILE_HEADER_SIZE
- /* Jump to address of entry point */
+ /* Get address of entry point */
mov eax, dword ptr ds:[eax + IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint]
add eax, FREELDR_PE_BASE
- jmp ax
+ /* Safe the entry point */
+ mov dword ptr [BSS_EntryPoint], eax
+
+ /* Patch the long jump instruction */
+ mov word ptr [pm_offset], ax
+
+/*
+ * Switches the processor to protected mode
+ * it destroys eax
+ */
+switch_to_prot:
+
+ /* Load the GDT */
+ lgdt gdtptr
+
+ /* Enable Protected Mode */
+ mov eax, cr0
+ or eax, CR0_PE_SET
+ mov cr0, eax
+
+ /* Clear prefetch queue & correct CS */
+ .byte HEX(0ea) // jmp far PMODE_CS:entry_point
+pm_offset:
+ .word 0 // receives address of PE entry point
+ .word PMODE_CS
+ nop
+
+
+
+ /* 16-bit stack pointer */
+stack16:
+ .word STACK16ADDR
+
+
+.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 */
+
+.org 1024
#include "helpers.inc"
Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h [iso-8859-1] Mon Jun 13
20:03:55 2011
@@ -4,8 +4,8 @@
#endif
/* Memory layout */
-#define STACK16ADDR HEX(7000) /* The 16-bit stack top will be at 0000:7000 */
-#define BSS_START HEX(7000)
+#define STACK16ADDR HEX(6F00) /* The 16-bit stack top will be at 0000:6F00 */
+#define BSS_START HEX(6F00)
#define FREELDR_BASE HEX(8000)
#define FREELDR_PE_BASE HEX(9000)
#define STACK32ADDR HEX(78000) /* The 32-bit stack top will be at 7000:8000, or
0x78000 */
@@ -17,15 +17,12 @@
#define DISKREADBUFFER_SIZE 512
/* These addresses specify the realmode "BSS section" layout */
-#define BSS_CallbackAddress BSS_START + 0
-#define BSS_CallbackReturn BSS_START + 8
-#define BSS_BootDrive BSS_START + 16
-#define BSS_BootPartition BSS_START + 20
+#define BSS_EntryPoint (BSS_START + 0)
+#define BSS_CallbackAddress (BSS_START + 4)
+#define BSS_CallbackReturn (BSS_START + 8)
+#define BSS_BootDrive (BSS_START + 12)
+#define BSS_BootPartition (BSS_START + 16)
-#ifdef _M_AMD64
-#define FrldrBootDrive *((PULONG)BSS_BootDrive)
-#define FrldrBootPartition *((PULONG)BSS_BootPartition)
-#endif
// Flag Masks
#define I386FLAG_CF HEX(0001) // Carry Flag
@@ -45,13 +42,13 @@
#define CR0_PE_CLR HEX(FFFFFFFE) /* AND this value with CR0 to disable pmode */
/* Defines needed for switching between real and protected mode */
-#ifdef _M_IX86
+//#ifdef _M_IX86
#define NULL_DESC HEX(00) /* NULL descriptor */
#define PMODE_CS HEX(08) /* PMode code selector, base 0 limit 4g */
#define PMODE_DS HEX(10) /* PMode data selector, base 0 limit 4g */
#define RMODE_CS HEX(18) /* RMode code selector, base 0 limit 64k */
#define RMODE_DS HEX(20) /* RMode data selector, base 0 limit 64k */
-#endif
+//#endif
/* Makes "x" a global variable or label */
#define EXTERN(x) .global x; x: