3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <arch/pc/x86common.h>
22 #include <arch/pc/pcbios.h>
27 //EXTERN _i386idtptr:FWORD
31 PUBLIC _RealEntryPoint
34 /* Setup segment selectors */
42 /* Setup protected mode stack */
43 mov esp, dword ptr ds:[stack32]
47 lidt fword ptr ds:[i386idtptr]
52 /* Continue execution */
53 jmp dword ptr ds:[ContinueAddress]
55 PUBLIC ContinueAddress
62 /* Store BootDrive and BootPartition */
63 mov byte ptr ds:[_FrldrBootDrive], dl
66 mov dword ptr ds:[_FrldrBootPartition], eax
68 /* Patch long jump with real mode entry point */
69 mov eax, dword ptr ds:[BSS_RealModeEntry]
70 mov dword ptr ds:[SwitchToReal16Address], eax
72 /* Initialize the idt */
78 mov edi, offset __bss_start__
79 mov ecx, offset __bss_end__ + 3
84 /* Pass the command line to BootMain */
85 mov eax, offset cmdline
94 /* We should never get here */
102 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
108 /* copy entry point */
112 mov dword ptr ds:[BSS_PxeEntryPoint], eax
116 mov word ptr ds:[BSS_PxeFunction], ax
118 /* convert pointer to data buffer to segment/offset */
122 mov word ptr ds:[BSS_PxeBufferSegment], ax
125 mov word ptr ds:[BSS_PxeBufferOffset], ax
129 /* Set the function ID and call realmode */
130 mov bx, FNID_PxeCallApi
131 call i386CallRealMode
135 mov ax, word ptr [BSS_PxeResult]
142 /* Set the function ID */
145 /* Switch to real mode (we don't return) */
149 PUBLIC _ChainLoadBiosBootSectorCode
150 _ChainLoadBiosBootSectorCode:
151 /* Set the boot drive */
152 mov dl, byte ptr [_FrldrBootDrive]
154 /* Set the function ID */
155 mov bx, FNID_ChainLoadBiosBootSectorCode
157 /* Switch to real mode (we don't return) */
161 PUBLIC i386CallRealMode
163 /* Set continue address and switch to real mode */
164 mov dword ptr [ContinueAddress], offset i386CallRealMode_return
166 i386CallRealMode_return:
170 /* Entrypoint for realmode function calls
171 * ContinueAddress must be set to the return point from realmode
172 * bx must be set to the ID of the realmode function to call. */
175 /* Set sane segments */
183 /* Save 32-bit stack pointer */
184 mov dword ptr [stack32], esp
186 /* jmp to 16-bit segment to set the limit correctly */
187 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
188 SwitchToReal16Address:
189 .long 0 // receives address of switch_to_real16
194 /* 16-bit stack pointer */
198 /* 32-bit stack pointer */
202 .align 4 /* force 4-byte alignment */
204 /* NULL Descriptor */
222 /* 16-bit real mode CS */
228 /* 16-bit real mode DS */
234 /* GDT table pointer */
236 .word HEX(27) /* Limit */
237 .long gdt /* Base Address */
239 /* Real-mode IDT pointer */
241 .word HEX(3ff) /* Limit */
242 .long 0 /* Base Address */
246 .word 255 /* Limit */
247 .long _i386Idt /* Base Address */
249 PUBLIC _FrldrBootDrive
253 PUBLIC _FrldrBootPartition