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 EXTERN __bss_start__:DWORD
32 EXTERN __bss_end__:DWORD
37 PUBLIC _RealEntryPoint
40 /* Setup segment selectors */
48 /* Setup protected mode stack */
49 mov esp, dword ptr ds:[stack32]
53 lidt fword ptr ds:[i386idtptr]
58 /* Continue execution */
59 jmp dword ptr ds:[ContinueAddress]
61 PUBLIC ContinueAddress
68 ASSUME /*CS:_TEXT,*/ DS:_DATA, ES:_DATA, FS:_DATA, GS:_DATA, SS:_DATA
70 /* Store BootDrive and BootPartition */
71 mov byte ptr ds:[_FrldrBootDrive], dl
74 mov dword ptr ds:[_FrldrBootPartition], eax
76 /* Patch long jump with real mode entry point */
77 mov eax, dword ptr ds:[BSS_RealModeEntry]
78 mov dword ptr ds:[SwitchToReal16Address], eax
82 mov edi, offset __bss_start__
83 mov ecx, offset __bss_end__ + 3
88 /* Initialize the idt */
91 /* Pass the command line to BootMain */
92 mov eax, offset cmdline
98 /* We should never get here */
106 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
112 /* copy entry point */
116 mov dword ptr ds:[BSS_PxeEntryPoint], eax
120 mov word ptr ds:[BSS_PxeFunction], ax
122 /* convert pointer to data buffer to segment/offset */
126 mov word ptr ds:[BSS_PxeBufferSegment], ax
129 mov word ptr ds:[BSS_PxeBufferOffset], ax
133 /* Set the function ID and call realmode */
134 mov bx, FNID_PxeCallApi
135 call i386CallRealMode
139 mov ax, word ptr [BSS_PxeResult]
146 /* Set the function ID */
149 /* Switch to real mode (we don't return) */
153 PUBLIC _ChainLoadBiosBootSectorCode
154 _ChainLoadBiosBootSectorCode:
155 /* Set the boot drive */
156 mov dl, byte ptr ds:[_FrldrBootDrive]
158 /* Set the function ID */
159 mov bx, FNID_ChainLoadBiosBootSectorCode
161 /* Switch to real mode (we don't return) */
165 PUBLIC i386CallRealMode
167 /* Set continue address and switch to real mode */
168 mov dword ptr ds:[ContinueAddress], offset i386CallRealMode_return
170 i386CallRealMode_return:
174 /* Entrypoint for realmode function calls
175 * ContinueAddress must be set to the return point from realmode
176 * bx must be set to the ID of the realmode function to call. */
179 /* Set sane segments */
187 /* Save 32-bit stack pointer */
188 mov dword ptr ds:[stack32], esp
190 /* jmp to 16-bit segment to set the limit correctly */
191 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
192 SwitchToReal16Address:
193 .long 0 // receives address of switch_to_real16
198 /* 16-bit stack pointer */
202 /* 32-bit stack pointer */
206 .align 4 /* force 4-byte alignment */
208 /* NULL Descriptor */
226 /* 16-bit real mode CS */
232 /* 16-bit real mode DS */
238 /* GDT table pointer */
240 .word HEX(27) /* Limit */
241 .long gdt /* Base Address */
243 // See _i386IdtDescriptor
246 .word 255 /* Limit */
247 .long _i386Idt /* Base Address */
249 PUBLIC _FrldrBootDrive
253 PUBLIC _FrldrBootPartition