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