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