Rev 1805 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1805 | decky | 1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
||
3 | # Copyright (C) 2005-2006 Martin Decky |
||
4 | # All rights reserved. |
||
5 | # |
||
6 | # Redistribution and use in source and binary forms, with or without |
||
7 | # modification, are permitted provided that the following conditions |
||
8 | # are met: |
||
9 | # |
||
10 | # - Redistributions of source code must retain the above copyright |
||
11 | # notice, this list of conditions and the following disclaimer. |
||
12 | # - Redistributions in binary form must reproduce the above copyright |
||
13 | # notice, this list of conditions and the following disclaimer in the |
||
14 | # documentation and/or other materials provided with the distribution. |
||
15 | # - The name of the author may not be used to endorse or promote products |
||
16 | # derived from this software without specific prior written permission. |
||
17 | # |
||
18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | # |
||
29 | |||
30 | #include <arch/boot/boot.h> |
||
31 | #include <arch/mm/page.h> |
||
32 | #include <arch/pm.h> |
||
33 | |||
34 | .section __xen_guest |
||
35 | .ascii "GUEST_OS=HelenOS," |
||
36 | .ascii "XEN_VER=xen-3.0," |
||
37 | .ascii "HYPERCALL_PAGE=0x2," |
||
38 | .ascii "LOADER=generic," |
||
39 | .ascii "PT_MODE_WRITABLE" |
||
40 | .byte 0 |
||
41 | |||
42 | #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) |
||
43 | |||
44 | .section K_TEXT_START, "ax" |
||
45 | |||
46 | KTEXT=8 |
||
47 | KDATA=16 |
||
48 | |||
49 | .code32 |
||
50 | .align 4 |
||
51 | .global multiboot_image_start |
||
52 | multiboot_header: |
||
53 | .long MULTIBOOT_HEADER_MAGIC |
||
54 | .long MULTIBOOT_HEADER_FLAGS |
||
55 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
||
56 | .long multiboot_header |
||
57 | .long unmapped_ktext_start |
||
58 | .long 0 |
||
59 | .long 0 |
||
60 | .long multiboot_image_start |
||
61 | |||
62 | multiboot_image_start: |
||
63 | movl $START_STACK, %esp # initialize stack pointer |
||
64 | lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register |
||
65 | |||
66 | movw $KDATA, %cx |
||
67 | movw %cx, %es |
||
68 | movw %cx, %fs |
||
69 | movw %cx, %gs |
||
70 | movw %cx, %ds # kernel data + stack |
||
71 | movw %cx, %ss |
||
72 | |||
73 | jmpl $KTEXT, $multiboot_meeting_point |
||
74 | multiboot_meeting_point: |
||
75 | |||
76 | pushl %ebx # save parameters from GRUB |
||
77 | pushl %eax |
||
78 | |||
79 | #ifdef CONFIG_FB |
||
80 | mov $vesa_init, %esi |
||
81 | mov $VESA_INIT_SEGMENT << 4, %edi |
||
82 | mov $e_vesa_init - vesa_init, %ecx |
||
83 | cld |
||
84 | rep movsb |
||
85 | |||
86 | mov $VESA_INIT_SEGMENT << 4, %edi |
||
87 | jmpl %edi |
||
88 | |||
89 | vesa_meeting_point: |
||
90 | |||
91 | mov %esi, KA2PA(vesa_ph_addr) |
||
92 | mov %di, KA2PA(vesa_height) |
||
93 | shr $16, %edi |
||
94 | mov %di, KA2PA(vesa_width) |
||
95 | mov %bx, KA2PA(vesa_scanline) |
||
96 | shr $16, %ebx |
||
97 | mov %bx, KA2PA(vesa_bpp) |
||
98 | #endif |
||
99 | |||
100 | call map_kernel # map kernel and turn paging on |
||
101 | |||
102 | popl %eax |
||
103 | popl %ebx |
||
104 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
||
105 | je valid_boot |
||
106 | |||
107 | xorl %ecx, %ecx # no memory size or map available |
||
108 | movl %ecx, e801memorysize |
||
109 | movl %ecx, e820counter |
||
110 | |||
111 | jmp invalid_boot |
||
112 | |||
113 | valid_boot: |
||
114 | |||
115 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
||
116 | |||
117 | bt $0, %eax # mbi->flags[0] (mem_lower, mem_upper valid) |
||
118 | jc mem_valid |
||
119 | |||
120 | xorl %ecx, %ecx |
||
121 | jmp mem_invalid |
||
122 | |||
123 | mem_valid: |
||
124 | movl 4(%ebx), %ecx # mbi->mem_lower |
||
125 | addl 8(%ebx), %ecx # mbi->mem_upper |
||
126 | |||
127 | mem_invalid: |
||
128 | movl %ecx, e801memorysize |
||
129 | |||
130 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
||
131 | jc mods_valid |
||
132 | |||
133 | xorl %ecx, %ecx |
||
134 | movl %ecx, init |
||
135 | jmp mods_end |
||
136 | |||
137 | mods_valid: |
||
138 | |||
139 | movl 20(%ebx), %ecx # mbi->mods_count |
||
140 | movl %ecx, init |
||
141 | |||
142 | cmpl $0, %ecx |
||
143 | je mods_end |
||
144 | |||
145 | movl 24(%ebx), %esi # mbi->mods_addr |
||
146 | movl $init, %edi |
||
147 | |||
148 | mods_loop: |
||
149 | |||
150 | movl 0(%esi), %edx # mods->mod_start |
||
151 | addl $0x80000000, %edx |
||
152 | movl %edx, 4(%edi) |
||
153 | |||
154 | movl 4(%esi), %edx |
||
155 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
||
156 | movl %edx, 8(%edi) |
||
157 | |||
158 | addl $16, %esi |
||
159 | addl $8 , %edi |
||
160 | |||
161 | loop mods_loop |
||
162 | |||
163 | mods_end: |
||
164 | |||
165 | invalid_boot: |
||
166 | |||
167 | #ifdef CONFIG_SMP |
||
168 | |||
169 | # copy AP bootstrap routines below 1 MB |
||
170 | |||
171 | movl $BOOT_OFFSET, %esi |
||
172 | movl $AP_BOOT_OFFSET, %edi |
||
173 | movl $_hardcoded_unmapped_size, %ecx |
||
174 | cld |
||
175 | rep movsb |
||
176 | |||
177 | #endif |
||
178 | |||
179 | call main_bsp # never returns |
||
180 | |||
181 | cli |
||
182 | hlt |
||
183 | |||
184 | .global map_kernel |
||
185 | map_kernel: |
||
186 | # |
||
187 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
||
188 | # For simplicity, we map the entire 4G space. |
||
189 | # |
||
190 | movl %cr4, %ecx |
||
191 | orl $(1<<4), %ecx |
||
192 | movl %ecx, %cr4 # turn PSE on |
||
193 | |||
194 | movl $(page_directory+0), %esi |
||
195 | movl $(page_directory+2048), %edi |
||
196 | xorl %ecx, %ecx |
||
197 | xorl %ebx, %ebx |
||
198 | 0: |
||
199 | movl $((1<<7)|(1<<0)), %eax |
||
200 | orl %ebx, %eax |
||
201 | movl %eax, (%esi,%ecx,4) # mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M |
||
202 | movl %eax, (%edi,%ecx,4) # mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M |
||
203 | addl $(4*1024*1024), %ebx |
||
204 | |||
205 | incl %ecx |
||
206 | cmpl $512, %ecx |
||
207 | jl 0b |
||
208 | |||
209 | movl %esi, %cr3 |
||
210 | |||
211 | # turn paging on |
||
212 | movl %cr0, %ebx |
||
213 | orl $(1<<31), %ebx |
||
214 | movl %ebx, %cr0 |
||
215 | ret |
||
216 | |||
217 | #ifdef CONFIG_FB |
||
218 | vesa_init: |
||
219 | jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init |
||
220 | |||
221 | .code16 |
||
222 | vesa_init_real: |
||
223 | |||
224 | mov %cr0, %eax |
||
225 | and $~1, %eax |
||
226 | mov %eax, %cr0 |
||
227 | |||
228 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init |
||
229 | |||
230 | vesa_init_real2: |
||
231 | |||
232 | mov $VESA_INIT_SEGMENT, %bx |
||
233 | |||
234 | mov %bx, %es |
||
235 | mov %bx, %fs |
||
236 | mov %bx, %gs |
||
237 | mov %bx, %ds |
||
238 | mov %bx, %ss |
||
239 | |||
240 | movl %esp, %eax |
||
241 | movl $0x0000fffc, %esp |
||
242 | movl $0x0000fffc, %ebp |
||
243 | pushl %eax |
||
244 | |||
245 | #define VESA_INFO_SIZE 1024 |
||
246 | |||
247 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
||
248 | #define VESA_MODE_WIDTH_OFFSET 18 |
||
249 | #define VESA_MODE_HEIGHT_OFFSET 20 |
||
250 | #define VESA_MODE_BPP_OFFSET 25 |
||
251 | #define VESA_MODE_SCANLINE_OFFSET 16 |
||
252 | #define VESA_MODE_PHADDR_OFFSET 40 |
||
253 | |||
254 | #define VESA_END_OF_MODES 0xffff |
||
255 | |||
256 | #define VESA_OK 0x4f |
||
257 | |||
258 | #define VESA_GET_INFO 0x4f00 |
||
259 | #define VESA_GET_MODE_INFO 0x4f01 |
||
260 | #define VESA_SET_MODE 0x4f02 |
||
261 | |||
262 | #define CONFIG_VESA_BPP_a 255 |
||
263 | |||
264 | #if CONFIG_VESA_BPP == 24 |
||
265 | #undef CONFIG_VESA_BPP_a |
||
266 | #define CONFIG_VESA_BPP_a 32 |
||
267 | #endif |
||
268 | |||
269 | mov $VESA_GET_INFO, %ax |
||
270 | mov $e_vesa_init - vesa_init, %di |
||
271 | push %di |
||
272 | int $0x10 |
||
273 | |||
274 | pop %di |
||
275 | cmp $VESA_OK, %al |
||
276 | jnz 0f |
||
277 | |||
278 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
||
279 | mov %si, %gs |
||
280 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
||
281 | |||
282 | add $VESA_INFO_SIZE, %di |
||
283 | |||
284 | 1:# Try next mode |
||
285 | mov %gs:(%si), %cx |
||
286 | cmp $VESA_END_OF_MODES, %cx |
||
287 | jz 0f |
||
288 | |||
289 | inc %si |
||
290 | inc %si |
||
291 | push %cx |
||
292 | push %di |
||
293 | push %si |
||
294 | mov $VESA_GET_MODE_INFO, %ax |
||
295 | int $0x10 |
||
296 | |||
297 | pop %si |
||
298 | pop %di |
||
299 | pop %cx |
||
300 | cmp $VESA_OK, %al |
||
301 | jnz 0f |
||
302 | |||
303 | mov $CONFIG_VESA_WIDTH, %ax |
||
304 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
||
305 | jnz 1b |
||
306 | |||
307 | mov $CONFIG_VESA_HEIGHT,%ax |
||
308 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
||
309 | jnz 1b |
||
310 | |||
311 | mov $CONFIG_VESA_BPP, %al |
||
312 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
||
313 | jz 2f |
||
314 | |||
315 | mov $CONFIG_VESA_BPP_a, %al |
||
316 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
||
317 | jnz 1b |
||
318 | |||
319 | 2: |
||
320 | |||
321 | mov %cx, %bx |
||
322 | or $0xc000, %bx |
||
323 | push %di |
||
324 | mov $VESA_SET_MODE, %ax |
||
325 | int $0x10 |
||
326 | |||
327 | pop %di |
||
328 | cmp $VESA_OK, %al |
||
329 | jnz 0f |
||
330 | |||
331 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
||
332 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
||
333 | shl $16, %eax |
||
334 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
||
335 | mov VESA_MODE_BPP_OFFSET(%di), %bl |
||
336 | xor %bh, %bh |
||
337 | shl $16, %ebx |
||
338 | mov VESA_MODE_SCANLINE_OFFSET(%di), %bx |
||
339 | mov %eax, %edi |
||
340 | |||
341 | 8: |
||
342 | |||
343 | mov %cr0, %eax |
||
344 | or $1, %eax |
||
345 | mov %eax, %cr0 |
||
346 | |||
347 | jmp 9f |
||
348 | 9: |
||
349 | |||
350 | ljmpl $KTEXT, $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) |
||
351 | |||
352 | 0:# No prefered mode found |
||
353 | mov $0x111, %cx |
||
354 | push %di |
||
355 | push %cx |
||
356 | mov $VESA_GET_MODE_INFO, %ax |
||
357 | int $0x10 |
||
358 | |||
359 | pop %cx |
||
360 | pop %di |
||
361 | cmp $VESA_OK, %al |
||
362 | jnz 1f |
||
363 | jz 2b # Force relative jump |
||
364 | |||
365 | 1: |
||
366 | mov $0x0003, %ax |
||
367 | int $0x10 |
||
368 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
||
369 | xor %ax, %ax |
||
370 | jz 8b # Force relative jump |
||
371 | |||
372 | |||
373 | .code32 |
||
374 | vesa_init_protect: |
||
375 | popl %esp |
||
376 | |||
377 | movw $KDATA, %cx |
||
378 | movw %cx, %es |
||
379 | movw %cx, %fs |
||
380 | movw %cx, %gs |
||
381 | movw %cx, %ds # kernel data + stack |
||
382 | movw %cx, %ss |
||
383 | |||
384 | jmpl $KTEXT, $vesa_meeting_point |
||
385 | |||
386 | .align 4 |
||
387 | e_vesa_init: |
||
388 | #endif |
||
389 | |||
390 | .section K_DATA_START, "aw", @progbits |
||
391 | |||
392 | .align 4096 |
||
393 | page_directory: |
||
394 | .space 4096, 0 |