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
67 /* Store BootDrive and BootPartition */
68 mov byte ptr ds:[_FrldrBootDrive], dl
71 mov dword ptr ds:[_FrldrBootPartition], eax
73 /* Patch long jump with real mode entry point */
74 mov eax, dword ptr ds:[BSS_RealModeEntry]
75 mov dword ptr ds:[SwitchToReal16Address], eax
79 mov edi, offset __bss_start__
80 mov ecx, offset __bss_end__ + 3
85 /* Initialize the idt */
88 /* Pass the command line to BootMain */
89 mov eax, offset cmdline
95 /* We should never get here */
104 /* Set the function ID */
107 /* Switch to real mode (we don't return) */
112 * VOID __cdecl ChainLoadBiosBootSectorCode(
113 * IN UCHAR BootDrive OPTIONAL,
114 * IN ULONG BootPartition OPTIONAL);
118 PUBLIC _ChainLoadBiosBootSectorCode
119 _ChainLoadBiosBootSectorCode:
120 /* Set the boot drive */
124 mov dl, byte ptr ds:[_FrldrBootDrive]
126 /* Set the boot partition */
131 mov eax, dword ptr ds:[_FrldrBootPartition]
133 /* Store the 1-byte truncated partition number in DH */
136 /* Set the function ID */
137 mov bx, FNID_ChainLoadBiosBootSectorCode
139 /* Switch to real mode (we don't return) */
144 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
150 /* copy entry point */
154 mov dword ptr ds:[BSS_PxeEntryPoint], eax
158 mov word ptr ds:[BSS_PxeFunction], ax
160 /* convert pointer to data buffer to segment/offset */
164 mov word ptr ds:[BSS_PxeBufferSegment], ax
167 mov word ptr ds:[BSS_PxeBufferOffset], ax
171 /* Set the function ID and call realmode */
172 mov bx, FNID_PxeCallApi
173 call i386CallRealMode
177 mov ax, word ptr [BSS_PxeResult]
182 PUBLIC i386CallRealMode
184 /* Set continue address and switch to real mode */
185 mov dword ptr ds:[ContinueAddress], offset i386CallRealMode_return
187 i386CallRealMode_return:
191 /* Entrypoint for realmode function calls
192 * ContinueAddress must be set to the return point from realmode
193 * bx must be set to the ID of the realmode function to call. */
196 /* Set sane segments */
204 /* Save 32-bit stack pointer */
205 mov dword ptr ds:[stack32], esp
207 /* jmp to 16-bit segment to set the limit correctly */
208 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
209 SwitchToReal16Address:
210 .long 0 // receives address of switch_to_real16
215 /* 16-bit stack pointer */
219 /* 32-bit stack pointer */
223 .align 4 /* force 4-byte alignment */
225 /* NULL Descriptor */
243 /* 16-bit real mode CS */
249 /* 16-bit real mode DS */
255 /* GDT table pointer */
257 .word HEX(27) /* Limit */
258 .long gdt /* Base Address */
260 // See _i386IdtDescriptor
263 .word 255 /* Limit */
264 .long _i386Idt /* Base Address */
266 PUBLIC _FrldrBootDrive
270 PUBLIC _FrldrBootPartition