[FREELDR] Remove unneeded ASSUME line.
[reactos.git] / boot / freeldr / freeldr / arch / i386 / entry.S
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #include <asm.inc>
21 #include <arch/pc/x86common.h>
22 #include <arch/pc/pcbios.h>
23
24 EXTERN _BootMain:PROC
25 EXTERN _InitIdt:PROC
26 EXTERN _i386Idt:DWORD
27 //EXTERN _i386idtptr:FWORD
28 EXTERN cmdline:DWORD
29
30 #ifdef _USE_ML
31 EXTERN __bss_start__:DWORD
32 EXTERN __bss_end__:DWORD
33 #endif
34
35 .code32
36
37 PUBLIC _RealEntryPoint
38 _RealEntryPoint:
39
40 /* Setup segment selectors */
41 mov ax, PMODE_DS
42 mov ds, ax
43 mov es, ax
44 mov fs, ax
45 mov gs, ax
46 mov ss, ax
47
48 /* Setup protected mode stack */
49 mov esp, dword ptr ds:[stack32]
50
51 /* Load the IDT */
52 #ifdef _USE_ML
53 lidt fword ptr ds:[i386idtptr]
54 #else
55 lidt i386idtptr
56 #endif
57
58 /* Continue execution */
59 jmp dword ptr ds:[ContinueAddress]
60
61 PUBLIC ContinueAddress
62 ContinueAddress:
63 .long _FrldrStartup
64
65
66 _FrldrStartup:
67
68 /* Store BootDrive and BootPartition */
69 mov byte ptr ds:[_FrldrBootDrive], dl
70 xor eax, eax
71 mov al, dh
72 mov dword ptr ds:[_FrldrBootPartition], eax
73
74 /* Patch long jump with real mode entry point */
75 mov eax, dword ptr ds:[BSS_RealModeEntry]
76 mov dword ptr ds:[SwitchToReal16Address], eax
77
78 /* Clean out BSS */
79 xor eax, eax
80 mov edi, offset __bss_start__
81 mov ecx, offset __bss_end__ + 3
82 sub ecx, edi
83 shr ecx, 2
84 rep stosd
85
86 /* Initialize the idt */
87 call _InitIdt
88
89 /* Pass the command line to BootMain */
90 mov eax, offset cmdline
91
92 /* GO! */
93 push eax
94 call _BootMain
95
96 /* We should never get here */
97 stop:
98 jmp short stop
99 nop
100 nop
101
102
103 /*
104 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
105 *
106 * RETURNS:
107 */
108 PUBLIC _PxeCallApi
109 _PxeCallApi:
110 /* copy entry point */
111 mov eax, [esp + 4]
112 shl eax, 16
113 mov ax, [esp + 8]
114 mov dword ptr ds:[BSS_PxeEntryPoint], eax
115
116 /* copy function */
117 mov ax, [esp + 12]
118 mov word ptr ds:[BSS_PxeFunction], ax
119
120 /* convert pointer to data buffer to segment/offset */
121 mov eax, [esp + 16]
122 shr eax, 4
123 and eax, HEX(0f000)
124 mov word ptr ds:[BSS_PxeBufferSegment], ax
125 mov eax, [esp + 16]
126 and eax, HEX(0ffff)
127 mov word ptr ds:[BSS_PxeBufferOffset], ax
128
129 pusha
130
131 /* Set the function ID and call realmode */
132 mov bx, FNID_PxeCallApi
133 call i386CallRealMode
134
135 popa
136
137 mov ax, word ptr [BSS_PxeResult]
138
139 ret
140
141
142 PUBLIC _Reboot
143 _Reboot:
144 /* Set the function ID */
145 mov bx, FNID_Reboot
146
147 /* Switch to real mode (we don't return) */
148 jmp SwitchToReal
149
150
151 PUBLIC _ChainLoadBiosBootSectorCode
152 _ChainLoadBiosBootSectorCode:
153 /* Set the boot drive */
154 mov dl, byte ptr ds:[_FrldrBootDrive]
155
156 /* Set the function ID */
157 mov bx, FNID_ChainLoadBiosBootSectorCode
158
159 /* Switch to real mode (we don't return) */
160 jmp SwitchToReal
161
162
163 PUBLIC i386CallRealMode
164 i386CallRealMode:
165 /* Set continue address and switch to real mode */
166 mov dword ptr ds:[ContinueAddress], offset i386CallRealMode_return
167 jmp SwitchToReal
168 i386CallRealMode_return:
169 ret
170
171
172 /* Entrypoint for realmode function calls
173 * ContinueAddress must be set to the return point from realmode
174 * bx must be set to the ID of the realmode function to call. */
175 PUBLIC SwitchToReal
176 SwitchToReal:
177 /* Set sane segments */
178 mov ax, PMODE_DS
179 mov ds, ax
180 mov es, ax
181 mov fs, ax
182 mov gs, ax
183 mov ss, ax
184
185 /* Save 32-bit stack pointer */
186 mov dword ptr ds:[stack32], esp
187
188 /* jmp to 16-bit segment to set the limit correctly */
189 .byte HEX(0ea) // jmp far RMODE_CS:switch_to_real16
190 SwitchToReal16Address:
191 .long 0 // receives address of switch_to_real16
192 .word RMODE_CS
193 nop
194
195
196 /* 16-bit stack pointer */
197 stack16:
198 .word STACK16ADDR
199
200 /* 32-bit stack pointer */
201 stack32:
202 .long STACKADDR
203
204 .align 4 /* force 4-byte alignment */
205 gdt:
206 /* NULL Descriptor */
207 .word HEX(0000)
208 .word HEX(0000)
209 .word HEX(0000)
210 .word HEX(0000)
211
212 /* 32-bit flat CS */
213 .word HEX(FFFF)
214 .word HEX(0000)
215 .word HEX(9A00)
216 .word HEX(00CF)
217
218 /* 32-bit flat DS */
219 .word HEX(FFFF)
220 .word HEX(0000)
221 .word HEX(9200)
222 .word HEX(00CF)
223
224 /* 16-bit real mode CS */
225 .word HEX(FFFF)
226 .word HEX(0000)
227 .word HEX(9E00)
228 .word HEX(0000)
229
230 /* 16-bit real mode DS */
231 .word HEX(FFFF)
232 .word HEX(0000)
233 .word HEX(9200)
234 .word HEX(0000)
235
236 /* GDT table pointer */
237 gdtptr:
238 .word HEX(27) /* Limit */
239 .long gdt /* Base Address */
240
241 // See _i386IdtDescriptor
242 PUBLIC i386idtptr
243 i386idtptr:
244 .word 255 /* Limit */
245 .long _i386Idt /* Base Address */
246
247 PUBLIC _FrldrBootDrive
248 _FrldrBootDrive:
249 .byte 0
250
251 PUBLIC _FrldrBootPartition
252 _FrldrBootPartition:
253 .long 0
254
255 END