3 #include "../../include/arch/pc/x86common.h"
5 #define IMAGE_DOS_HEADER_e_lfanew 60
6 #define IMAGE_FILE_HEADER_SIZE 20
7 #define IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint 16
12 #include "fathelp.inc"
19 /* Setup segment registers */
28 mov sp, word ptr ds:stack16
30 /* Enable A20 address line */
33 /* Get address of optional header */
34 mov eax, dword ptr ds:[FREELDR_PE_BASE + IMAGE_DOS_HEADER_e_lfanew]
35 add eax, FREELDR_PE_BASE + 4 + IMAGE_FILE_HEADER_SIZE
37 /* Get address of entry point */
38 mov eax, dword ptr ds:[eax + IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint]
39 add eax, FREELDR_PE_BASE
41 /* Safe the entry point */
42 mov dword ptr [BSS_EntryPoint], eax
44 /* Patch the long jump instruction */
45 mov word ptr [pm_offset], ax
48 * Switches the processor to protected mode
56 /* Enable Protected Mode */
61 /* Clear prefetch queue & correct CS */
62 .byte HEX(0ea) // jmp far PMODE_CS:entry_point
64 .word 0 // receives address of PE entry point
70 /* 16-bit stack pointer */
75 .align 4 /* force 4-byte alignment */
95 /* 16-bit real mode CS */
101 /* 16-bit real mode DS */
107 /* GDT table pointer */
109 .word HEX(27) /* Limit */
110 .long gdt /* Base Address */
114 #include "helpers.inc"
116 .org (FREELDR_PE_BASE - FREELDR_BASE)