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>
26 //EXTERN _i386idtptr:FWORD
30 PUBLIC _RealEntryPoint
33 /* Setup segment selectors */
41 /* Setup protected mode stack */
42 mov esp, dword ptr ds:[stack32]
46 lidt fword ptr ds:[i386idtptr]
51 /* Continue execution */
52 jmp dword ptr ds:[ContinueAddress]
60 /* Store BootDrive and BootPartition */
61 mov byte ptr ds:[_FrldrBootDrive], dl
64 mov dword ptr ds:[_FrldrBootPartition], eax
66 /* Patch long jump with real mode entry point */
67 mov eax, dword ptr ds:[BSS_RealModeEntry]
68 mov dword ptr ds:[SwitchToReal16Address], eax
70 /* Initialize the idt */
76 mov edi, offset __bss_start__
77 mov ecx, offset __bss_end__ + 3
82 /* Pass the command line to BootMain */
83 mov eax, offset cmdline
92 /* We should never get here */
104 * int Int386(int ivec, REGS* in, REGS* out);
109 /* Get the function parameters */
110 mov eax, dword ptr [esp + 4]
111 mov dword ptr ds:[BSS_IntVector], eax
112 mov eax, dword ptr [esp + 8]
113 mov dword ptr [Int386_regsin], eax
114 mov eax, dword ptr [esp + 12]
115 mov dword ptr [Int386_regsout], eax
117 /* Save all registers + segment registers */
124 /* Copy input registers */
125 mov esi, dword ptr [Int386_regsin]
126 mov edi, BSS_RegisterSet
127 mov ecx, REGS_SIZE / 4
130 /* Set the function ID */
133 /* Set continue address and switch to real mode */
134 mov dword ptr [ContinueAddress], offset Int386_return
139 /* Copy output registers */
140 mov esi, BSS_RegisterSet
141 mov edi, dword ptr [Int386_regsout]
142 mov ecx, REGS_SIZE / 4
154 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
166 /* copy entry point */
170 mov dword ptr ds:[BSS_PxeEntryPoint], eax
174 mov word ptr ds:[BSS_PxeFunction], ax
176 /* convert pointer to data buffer to segment/offset */
180 mov word ptr ds:[BSS_PxeBufferSegment], ax
183 mov word ptr ds:[BSS_PxeBufferOffset], ax
185 /* Set the function ID and call realmode */
186 mov bx, FNID_PxeCallApi
187 call i386CallRealMode
195 mov ax, word ptr [BSS_PxeResult]
202 /* Set the function ID */
203 mov bx, FNID_SoftReboot
205 /*Switch to real mode (We don't return) */
209 PUBLIC _ChainLoadBiosBootSectorCode
210 _ChainLoadBiosBootSectorCode:
211 /* Set the boot drive */
212 mov dl, byte ptr [_FrldrBootDrive]
214 /* Set the function ID */
215 mov bx, FNID_ChainLoadBiosBootSectorCode
217 /*Switch to real mode (We don't return) */
221 PUBLIC i386CallRealMode
223 /* Set continue address and switch to real mode */
224 mov dword ptr [ContinueAddress], offset i386CallRealMode_return
226 i386CallRealMode_return:
230 /* Entrypoint for realmode function calls
231 * ContinueAddress must be set to the return point from realmode
232 * bx must be set to the ID of the realmode function to call. */
234 /* Set sane segments */
242 /* Save 32-bit stack pointer */
243 mov dword ptr [stack32], esp
245 /* jmp to 16-bit segment to set the limit correctly */
246 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
247 SwitchToReal16Address:
248 .long 0 // receives address of switch_to_real16
253 /* 16-bit stack pointer */
257 /* 32-bit stack pointer */
261 .align 4 /* force 4-byte alignment */
263 /* NULL Descriptor */
281 /* 16-bit real mode CS */
287 /* 16-bit real mode DS */
293 /* GDT table pointer */
295 .word HEX(27) /* Limit */
296 .long gdt /* Base Address */
298 /* Real-mode IDT pointer */
300 .word HEX(3ff) /* Limit */
301 .long 0 /* Base Address */
305 .word 255 /* Limit */
306 .long _i386Idt /* Base Address */
308 PUBLIC _FrldrBootDrive
312 PUBLIC _FrldrBootPartition