From 0e3fe37eaad7d372b9feb4907969f15c8a7ae251 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Fri, 17 Jun 2011 23:44:07 +0000 Subject: [PATCH] [FREELDR] - Instead of using the far jmp when switching to protected mode to go to the entry point, use a relative absolute jmp instruction, manually encoded - Remove the END from fathelp.inc, that was terminating the code - fix code for ML svn path=/trunk/; revision=52325 --- .../freeldr/freeldr/arch/realmode/fathelp.inc | 3 +- .../freeldr/freeldr/arch/realmode/helpers.inc | 20 +++++------ .../boot/freeldr/freeldr/arch/realmode/i386.S | 33 +++++++++++-------- .../freeldr/freeldr/arch/realmode/int386.inc | 4 +-- .../freeldr/freeldr/arch/realmode/pnp.inc | 8 ++--- .../freeldr/freeldr/arch/realmode/pxe.inc | 4 +-- 6 files changed, 39 insertions(+), 33 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/fathelp.inc b/reactos/boot/freeldr/freeldr/arch/realmode/fathelp.inc index 11c8c8a6507..3e28eddda40 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/fathelp.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/fathelp.inc @@ -217,9 +217,8 @@ IsFat12_Done: ret -msgLoading: .asciz "Loading FreeLoader...\r\n" +msgLoading: .asciz "Loading FreeLoader...", CR, LF .org 510 // Pad to 510 bytes .word HEX(0aa55) // BootSector signature -END diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc b/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc index 4121850f6a0..dd1fd492748 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc @@ -1,10 +1,10 @@ Empty8042: - .word 0x00eb,0x00eb // jmp $+2, jmp $+2 - in al, 0x64 - cmp al, 0xff // legacy-free machine without keyboard + .word HEX(00eb), HEX(00eb) // jmp $+2, jmp $+2 + in al, HEX(64) + cmp al, HEX(0ff) // legacy-free machine without keyboard jz Empty8042_ret // controllers on Intel Macs read back 0xFF - test al, 0x02 + test al, 2 jnz Empty8042 Empty8042_ret: ret @@ -12,11 +12,11 @@ Empty8042_ret: EnableA20: pusha call Empty8042 - mov al, 0xD1 // command write - out 0x64, al + mov al, HEX(0D1) // command write + out HEX(064), al call Empty8042 - mov al, 0xDF // A20 on - out 0x60, al + mov al, HEX(0DF) // A20 on + out HEX(060), al call Empty8042 popa ret @@ -46,9 +46,9 @@ writestr_end: writechr: pushf pusha - mov ah, 0x0E + mov ah, HEX(0E) xor bx, bx - int 0x10 + int HEX(10) popa popf ret diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/i386.S b/reactos/boot/freeldr/freeldr/arch/realmode/i386.S index bfa5cde7c87..bab9d0c2020 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/i386.S +++ b/reactos/boot/freeldr/freeldr/arch/realmode/i386.S @@ -31,7 +31,7 @@ RealModeEntryPoint: call EnableA20 /* Safe real mode entry point in shared memory */ - mov dword ptr [BSS_RealModeEntry], offset switch_to_real16 + mov dword ptr ds:[BSS_RealModeEntry], offset switch_to_real16 /* Get address of optional header */ mov eax, dword ptr ds:[FREELDR_PE_BASE + IMAGE_DOS_HEADER_e_lfanew] @@ -41,8 +41,8 @@ RealModeEntryPoint: mov eax, dword ptr ds:[eax + IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint] add eax, FREELDR_PE_BASE - /* Patch the long jump instruction */ - mov word ptr [pm_offset], ax + /* Save entry point */ + mov dword ptr [pm_entrypoint], eax jmp exit_to_protected @@ -87,7 +87,12 @@ inrmode: mov sp, word ptr ds:[stack16] /* Load IDTR with real mode value */ +#ifdef _USE_ML + DB 0Fh, 01h, 1Eh + DW rmode_idtptr +#else lidt rmode_idtptr +#endif sti /* These are ok now */ @@ -108,7 +113,12 @@ exit_to_protected: mov word ptr ds:[stack16], sp /* Load the GDT */ +#ifdef _USE_ML + DB 0Fh, 01h, 16h + DW rmode_idtptr +#else lgdt gdtptr +#endif /* Enable Protected Mode */ mov eax, cr0 @@ -116,14 +126,13 @@ exit_to_protected: 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 + ljmp16 PMODE_CS, inpmode +inpmode: + .byte HEX(0ff), HEX(25) // opcode of indirect jump + .word pm_entrypoint, 0 +pm_entrypoint: + .long 0 // receives address of PE entry point nop -// FIXME: use ljmp16 PMODE_CS:inpmode + hexed 32bit jump - - callback_table: .word Int386 @@ -174,15 +183,13 @@ gdt: /* GDT table pointer */ gdtptr: .word HEX(27) /* Limit */ - .long gdt /* Base Address */ + .word gdt, 0 /* Base Address */ /* Real-mode IDT pointer */ rmode_idtptr: .word HEX(3ff) /* Limit */ .long 0 /* Base Address */ -//.org 1024 - #include "int386.inc" #include "pxe.inc" #include "pnp.inc" diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/int386.inc b/reactos/boot/freeldr/freeldr/arch/realmode/int386.inc index dc7e0b77f50..1fe18fb6062 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/int386.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/int386.inc @@ -34,9 +34,9 @@ Int386: /* Call the interrupt vector */ /*int Int386_vector*/ - .byte 0xcd + .byte HEX(0cd) Int386_vector_opcode: - .byte 0x00 + .byte 00 /* Save the registers */ mov dword ptr cs:[BSS_RegisterSet + REGS_EAX], eax diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/pnp.inc b/reactos/boot/freeldr/freeldr/arch/realmode/pnp.inc index d02ce3f5c5a..14ca2e93472 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/pnp.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/pnp.inc @@ -15,11 +15,11 @@ PnpBiosGetDeviceNodeCount: push 0 - call dword ptr [BSS_PnpBiosEntryPoint] + call dword ptr ds:[BSS_PnpBiosEntryPoint] add sp, 12 movzx ecx, ax - mov dword ptr [BSS_PnpResult], ecx + mov dword ptr ds:[BSS_PnpResult], ecx ret @@ -48,11 +48,11 @@ PnpBiosGetDeviceNode: push 1 /* call entry point */ - call dword ptr [BSS_PnpBiosEntryPoint] + call dword ptr ds:[BSS_PnpBiosEntryPoint] add sp, 14 movzx ecx, ax - mov [BSS_PnpResult], ecx + mov dword ptr ds:[BSS_PnpResult], ecx ret diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/pxe.inc b/reactos/boot/freeldr/freeldr/arch/realmode/pxe.inc index eae957db8bc..f254fe5f268 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/pxe.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/pxe.inc @@ -26,8 +26,8 @@ PxeCallApi: push ax mov ax, [BSS_PxeFunction] push ax - call dword ptr [BSS_PxeEntryPoint] + call dword ptr ds:[BSS_PxeEntryPoint] add esp, 6 - mov [BSS_PxeResult], ax + mov word ptr ds:[BSS_PxeResult], ax ret