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 /* Address the image with es segment */
37 mov ax, FREELDR_PE_BASE / 16
40 /* Get address of optional header */
41 mov eax, dword ptr es:[IMAGE_DOS_HEADER_e_lfanew]
42 add eax, 4 + IMAGE_FILE_HEADER_SIZE
44 /* Get address of entry point */
45 mov eax, dword ptr es:[eax + IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint]
46 add eax, FREELDR_PE_BASE
48 /* Save entry point */
49 mov dword ptr ds:[pm_entrypoint], eax
58 /* This is the entry point from protected mode */
61 /* Restore segment registers to correct limit */
69 /* Disable Protected Mode */
74 /* Clear prefetch queue & correct CS */
78 /* Set real mode segments */
86 /* Clear out the high 16-bits of ESP */
87 /* This is needed because I have one */
88 /* machine that hangs when booted to dos if */
89 /* anything other than 0x0000 is in the high */
90 /* 16-bits of ESP. Even though real-mode */
91 /* code should only use SP and not ESP. */
94 /* Restore real mode stack */
95 mov sp, word ptr ds:[stack16]
97 /* Load IDTR with real mode value */
99 lidt fword ptr rmode_idtptr
104 sti /* These are ok now */
106 /* Do the callback, specified by bx */
108 call word ptr ds:callback_table[bx]
112 * Switches the processor to protected mode
119 /* Safe current stack pointer */
120 mov word ptr ds:[stack16], sp
124 lgdt fword ptr gdtptr
129 /* Enable Protected Mode */
134 /* Clear prefetch queue & correct CS */
135 ljmp16 PMODE_CS, inpmode
137 .byte HEX(0ff), HEX(25) // opcode of indirect jump
138 .word pm_entrypoint, 0
140 .long 0 // receives address of PE entry point
146 .word ChainLoadBiosBootSectorCode
148 .word PnpBiosGetDeviceNodeCount
149 .word PnpBiosGetDeviceNode
150 .word BootLinuxKernel
153 /* 16-bit stack pointer */
158 .align 4 /* force 4-byte alignment */
160 /* NULL Descriptor */
178 /* 16-bit real mode CS */
184 /* 16-bit real mode DS */
190 /* GDT table pointer */
192 .word HEX(27) /* Limit */
193 .word gdt, 0 /* Base Address */
195 /* Real-mode IDT pointer */
197 .word HEX(3ff) /* Limit */
198 .long 0 /* Base Address */
200 #include "int386.inc"
204 #include "helpers.inc"
206 .org (FREELDR_PE_BASE - FREELDR_BASE - 1)