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]
61 /* Store BootDrive and BootPartition */
62 mov byte ptr ds:[_FrldrBootDrive], dl
65 mov dword ptr ds:[_FrldrBootPartition], eax
67 /* Patch long jump with real mode entry point */
68 mov eax, dword ptr ds:[BSS_RealModeEntry]
69 mov dword ptr ds:[SwitchToReal16Address], eax
71 /* Initialize the idt */
77 mov edi, offset __bss_start__
78 mov ecx, offset __bss_end__ + 3
83 /* Pass the command line to BootMain */
84 mov eax, offset cmdline
93 /* We should never get here */
105 * int Int386(int ivec, REGS* in, REGS* out);
110 /* Get the function parameters */
111 mov eax, dword ptr [esp + 4]
112 mov dword ptr ds:[BSS_IntVector], eax
113 mov eax, dword ptr [esp + 8]
114 mov dword ptr [Int386_regsin], eax
115 mov eax, dword ptr [esp + 12]
116 mov dword ptr [Int386_regsout], eax
118 /* Save all registers + segment registers */
125 /* Copy input registers */
126 mov esi, dword ptr [Int386_regsin]
127 mov edi, BSS_RegisterSet
128 mov ecx, REGS_SIZE / 4
131 /* Set the function ID */
134 /* Set continue address and switch to real mode */
135 mov dword ptr [ContinueAddress], offset Int386_return
140 /* Copy output registers */
141 mov esi, BSS_RegisterSet
142 mov edi, dword ptr [Int386_regsout]
143 mov ecx, REGS_SIZE / 4
155 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
167 /* copy entry point */
171 mov dword ptr ds:[BSS_PxeEntryPoint], eax
175 mov word ptr ds:[BSS_PxeFunction], ax
177 /* convert pointer to data buffer to segment/offset */
181 mov word ptr ds:[BSS_PxeBufferSegment], ax
184 mov word ptr ds:[BSS_PxeBufferOffset], ax
186 /* Set the function ID and call realmode */
187 mov bx, FNID_PxeCallApi
188 call i386CallRealMode
196 mov ax, word ptr [BSS_PxeResult]
203 /* Set the function ID */
206 /*Switch to real mode (We don't return) */
210 PUBLIC _ChainLoadBiosBootSectorCode
211 _ChainLoadBiosBootSectorCode:
212 /* Set the boot drive */
213 mov dl, byte ptr [_FrldrBootDrive]
215 /* Set the function ID */
216 mov bx, FNID_ChainLoadBiosBootSectorCode
218 /*Switch to real mode (We don't return) */
222 PUBLIC i386CallRealMode
224 /* Set continue address and switch to real mode */
225 mov dword ptr [ContinueAddress], offset i386CallRealMode_return
227 i386CallRealMode_return:
231 /* Entrypoint for realmode function calls
232 * ContinueAddress must be set to the return point from realmode
233 * bx must be set to the ID of the realmode function to call. */
235 /* Set sane segments */
243 /* Save 32-bit stack pointer */
244 mov dword ptr [stack32], esp
246 /* jmp to 16-bit segment to set the limit correctly */
247 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
248 SwitchToReal16Address:
249 .long 0 // receives address of switch_to_real16
254 /* 16-bit stack pointer */
258 /* 32-bit stack pointer */
262 .align 4 /* force 4-byte alignment */
264 /* NULL Descriptor */
282 /* 16-bit real mode CS */
288 /* 16-bit real mode DS */
294 /* GDT table pointer */
296 .word HEX(27) /* Limit */
297 .long gdt /* Base Address */
299 /* Real-mode IDT pointer */
301 .word HEX(3ff) /* Limit */
302 .long 0 /* Base Address */
306 .word 255 /* Limit */
307 .long _i386Idt /* Base Address */
309 PUBLIC _FrldrBootDrive
313 PUBLIC _FrldrBootPartition