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 /* Safe real mode entry point in shared memory */
34 mov dword ptr ds:[BSS_RealModeEntry], offset switch_to_real16
36 /* Get address of optional header */
37 mov eax, dword ptr ds:[FREELDR_PE_BASE + IMAGE_DOS_HEADER_e_lfanew]
38 add eax, FREELDR_PE_BASE + 4 + IMAGE_FILE_HEADER_SIZE
40 /* Get address of entry point */
41 mov eax, dword ptr ds:[eax + IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint]
42 add eax, FREELDR_PE_BASE
44 /* Save entry point */
45 mov dword ptr ds:[pm_entrypoint], eax
50 /* This is the entry point from protected mode */
53 /* Restore segment registers to correct limit */
61 /* Disable Protected Mode */
66 /* Clear prefetch queue & correct CS */
70 /* Set real mode segments */
78 /* Clear out the high 16-bits of ESP */
79 /* This is needed because I have one */
80 /* machine that hangs when booted to dos if */
81 /* anything other than 0x0000 is in the high */
82 /* 16-bits of ESP. Even though real-mode */
83 /* code should only use SP and not ESP. */
86 /* Restore real mode stack */
87 mov sp, word ptr ds:[stack16]
89 /* Load IDTR with real mode value */
91 lidt fword ptr rmode_idtptr
96 sti /* These are ok now */
98 /* Do the callback, specified by bx */
100 call word ptr ds:callback_table[bx]
104 * Switches the processor to protected mode
111 /* Safe current stack pointer */
112 mov word ptr ds:[stack16], sp
116 lgdt fword ptr gdtptr
121 /* Enable Protected Mode */
126 /* Clear prefetch queue & correct CS */
127 ljmp16 PMODE_CS, inpmode
129 .byte HEX(0ff), HEX(25) // opcode of indirect jump
130 .word pm_entrypoint, 0
132 .long 0 // receives address of PE entry point
138 .word ChainLoadBiosBootSectorCode
140 .word PnpBiosGetDeviceNodeCount
141 .word PnpBiosGetDeviceNode
142 .word BootLinuxKernel
145 /* 16-bit stack pointer */
150 .align 4 /* force 4-byte alignment */
152 /* NULL Descriptor */
170 /* 16-bit real mode CS */
176 /* 16-bit real mode DS */
182 /* GDT table pointer */
184 .word HEX(27) /* Limit */
185 .word gdt, 0 /* Base Address */
187 /* Real-mode IDT pointer */
189 .word HEX(3ff) /* Limit */
190 .long 0 /* Base Address */
192 #include "int386.inc"
196 #include "helpers.inc"
198 .org (FREELDR_PE_BASE - FREELDR_BASE - 1)