[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
This commit is contained in:
Timo Kreuzer
2011-06-17 23:44:07 +00:00
parent f19fc81b23
commit 0e3fe37eaa
6 changed files with 39 additions and 33 deletions
@@ -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
@@ -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
@@ -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"
@@ -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
@@ -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
@@ -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