Rev 1289 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1289 | Rev 1291 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2005 Ondrej Palkovsky |
2 | # Copyright (C) 2005 Ondrej Palkovsky |
3 | # Copyright (C) 2006 Martin Decky |
3 | # Copyright (C) 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/mm/ptl.h> |
33 | #include <arch/mm/ptl.h> |
34 | #include <arch/pm.h> |
34 | #include <arch/pm.h> |
35 | #include <arch/cpu.h> |
35 | #include <arch/cpu.h> |
36 | #include <arch/cpuid.h> |
36 | #include <arch/cpuid.h> |
37 | 37 | ||
38 | #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) |
38 | #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) |
39 | 39 | ||
40 | .section K_TEXT_START, "ax" |
40 | .section K_TEXT_START, "ax" |
41 | 41 | ||
42 | .code32 |
42 | .code32 |
43 | .align 4 |
43 | .align 4 |
44 | .global multiboot_image_start |
44 | .global multiboot_image_start |
45 | multiboot_header: |
45 | multiboot_header: |
46 | .long MULTIBOOT_HEADER_MAGIC |
46 | .long MULTIBOOT_HEADER_MAGIC |
47 | .long MULTIBOOT_HEADER_FLAGS |
47 | .long MULTIBOOT_HEADER_FLAGS |
48 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
48 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
49 | .long multiboot_header |
49 | .long multiboot_header |
50 | .long unmapped_ktext_start |
50 | .long unmapped_ktext_start |
51 | .long 0 |
51 | .long 0 |
52 | .long 0 |
52 | .long 0 |
53 | .long multiboot_image_start |
53 | .long multiboot_image_start |
54 | 54 | ||
55 | multiboot_image_start: |
55 | multiboot_image_start: |
56 | movl $START_STACK, %esp # initialize stack pointer |
56 | movl $START_STACK, %esp # initialize stack pointer |
57 | lgdt bootstrap_gdtr # initialize Global Descriptor Table register |
57 | lgdt bootstrap_gdtr # initialize Global Descriptor Table register |
58 | 58 | ||
59 | movw $gdtselector(KDATA_DES), %cx |
59 | movw $gdtselector(KDATA_DES), %cx |
60 | movw %cx, %es |
60 | movw %cx, %es |
61 | movw %cx, %ds # kernel data + stack |
61 | movw %cx, %ds # kernel data + stack |
62 | movw %cx, %ss |
62 | movw %cx, %ss |
63 | # Simics seems to remove hidden part of GS on entering user mode |
63 | # Simics seems to remove hidden part of GS on entering user mode |
64 | # when _visible_ part of GS does not point to user-mode segment |
64 | # when _visible_ part of GS does not point to user-mode segment |
65 | movw $gdtselector(UDATA_DES), %cx |
65 | movw $gdtselector(UDATA_DES), %cx |
66 | movw %cx, %fs |
66 | movw %cx, %fs |
67 | movw %cx, %gs |
67 | movw %cx, %gs |
68 | 68 | ||
69 | jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point |
69 | jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point |
70 | multiboot_meeting_point: |
70 | multiboot_meeting_point: |
71 | 71 | ||
72 | movl %eax, grub_eax # save parameters from GRUB |
72 | movl %eax, grub_eax # save parameters from GRUB |
73 | movl %ebx, grub_ebx |
73 | movl %ebx, grub_ebx |
74 | 74 | ||
75 | #ifdef CONFIG_FB |
75 | #ifdef CONFIG_FB |
76 | mov $vesa_init,%esi; |
76 | mov $vesa_init,%esi; |
77 | mov $VESA_INIT_SEGMENT<<4,%edi; |
77 | mov $VESA_INIT_SEGMENT<<4,%edi; |
78 | mov $e_vesa_init-vesa_init,%ecx; |
78 | mov $e_vesa_init-vesa_init,%ecx; |
79 | cld; |
79 | cld; |
80 | rep movsb; |
80 | rep movsb; |
81 | 81 | ||
82 | mov $VESA_INIT_SEGMENT<<4,%edi; |
82 | mov $VESA_INIT_SEGMENT<<4,%edi; |
83 | call *%edi; |
83 | call *%edi; |
84 | mov %esi,KA2PA(vesa_ph_addr); |
84 | mov %esi,KA2PA(vesa_ph_addr); |
85 | mov %di,KA2PA(vesa_height); |
85 | mov %di,KA2PA(vesa_height); |
86 | shr $16,%edi; |
86 | shr $16,%edi; |
87 | mov %di,KA2PA(vesa_width); |
87 | mov %di,KA2PA(vesa_width); |
88 | mov %bx,KA2PA(vesa_scanline); |
88 | mov %bx,KA2PA(vesa_scanline); |
89 | shr $16,%ebx; |
89 | shr $16,%ebx; |
90 | mov %bx,KA2PA(vesa_bpp); |
90 | mov %bx,KA2PA(vesa_bpp); |
91 | #endif |
91 | #endif |
92 | 92 | ||
93 | # Protected 32-bit. We want to reuse the code-seg descriptor, |
93 | # Protected 32-bit. We want to reuse the code-seg descriptor, |
94 | # the Default operand size must not be 1 when entering long mode |
94 | # the Default operand size must not be 1 when entering long mode |
95 | 95 | ||
96 | movl $0x80000000, %eax |
96 | movl $0x80000000, %eax |
97 | cpuid |
97 | cpuid |
98 | cmp $0x80000000, %eax # any function > 80000000h? |
98 | cmp $0x80000000, %eax # any function > 80000000h? |
99 | jbe long_mode_unsupported |
99 | jbe long_mode_unsupported |
100 | movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001 |
100 | movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001 |
101 | cpuid |
101 | cpuid |
102 | bt $29, %edx # Test if long mode is supported. |
102 | bt $29, %edx # Test if long mode is supported. |
103 | jc long_mode_supported |
103 | jc long_mode_supported |
104 | 104 | ||
105 | long_mode_unsupported: |
105 | long_mode_unsupported: |
106 | cli |
106 | cli |
107 | hlt |
107 | hlt |
108 | 108 | ||
109 | long_mode_supported: |
109 | long_mode_supported: |
110 | 110 | ||
111 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
111 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
112 | # Paging is not enabled until after long mode is enabled |
112 | # Paging is not enabled until after long mode is enabled |
113 | 113 | ||
114 | movl %cr4, %eax |
114 | movl %cr4, %eax |
115 | btsl $5, %eax |
115 | btsl $5, %eax |
116 | movl %eax, %cr4 |
116 | movl %eax, %cr4 |
117 | 117 | ||
118 | # Set up paging tables |
118 | # Set up paging tables |
119 | 119 | ||
120 | leal ptl_0, %eax |
120 | leal ptl_0, %eax |
121 | movl %eax, %cr3 |
121 | movl %eax, %cr3 |
122 | 122 | ||
123 | # Enable long mode |
123 | # Enable long mode |
124 | 124 | ||
125 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
125 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
126 | rdmsr # Read EFER |
126 | rdmsr # Read EFER |
127 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
127 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
128 | wrmsr # Write EFER |
128 | wrmsr # Write EFER |
129 | 129 | ||
130 | # Enable paging to activate long mode (set CR0.PG=1) |
130 | # Enable paging to activate long mode (set CR0.PG=1) |
131 | 131 | ||
132 | movl %cr0, %eax |
132 | movl %cr0, %eax |
133 | btsl $31, %eax |
133 | btsl $31, %eax |
134 | movl %eax, %cr0 |
134 | movl %eax, %cr0 |
135 | 135 | ||
136 | # At this point we are in compatibility mode |
136 | # At this point we are in compatibility mode |
137 | 137 | ||
138 | jmpl $gdtselector(KTEXT_DES), $start64 |
138 | jmpl $gdtselector(KTEXT_DES), $start64 |
139 | 139 | ||
140 | .code64 |
140 | .code64 |
141 | start64: |
141 | start64: |
142 | movq $(PA2KA(START_STACK)), %rsp |
142 | movq $(PA2KA(START_STACK)), %rsp |
143 | movl grub_eax, %eax |
143 | movl grub_eax, %eax |
144 | movl grub_ebx, %ebx |
144 | movl grub_ebx, %ebx |
145 | 145 | ||
146 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
146 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
147 | je valid_boot |
147 | je valid_boot |
148 | 148 | ||
149 | xorl %ecx, %ecx # no memory size or map available |
149 | xorl %ecx, %ecx # no memory size or map available |
150 | movl %ecx, e801memorysize |
150 | movl %ecx, e801memorysize |
151 | movl %ecx, e820counter |
151 | movl %ecx, e820counter |
152 | 152 | ||
153 | jmp invalid_boot |
153 | jmp invalid_boot |
154 | 154 | ||
155 | valid_boot: |
155 | valid_boot: |
156 | 156 | ||
157 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
157 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
158 | 158 | ||
159 | bt $0, %eax # mbi->flags[0] (mem_lower, mem_upper valid) |
159 | bt $0, %eax # mbi->flags[0] (mem_lower, mem_upper valid) |
160 | jc mem_valid |
160 | jc mem_valid |
161 | 161 | ||
162 | xorl %ecx, %ecx |
162 | xorl %ecx, %ecx |
163 | jmp mem_invalid |
163 | jmp mem_invalid |
164 | 164 | ||
165 | mem_valid: |
165 | mem_valid: |
166 | movl 4(%ebx), %ecx # mbi->mem_lower |
166 | movl 4(%ebx), %ecx # mbi->mem_lower |
167 | addl 8(%ebx), %ecx # mbi->mem_upper |
167 | addl 8(%ebx), %ecx # mbi->mem_upper |
168 | 168 | ||
169 | mem_invalid: |
169 | mem_invalid: |
170 | movl %ecx, e801memorysize |
170 | movl %ecx, e801memorysize |
171 | 171 | ||
172 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
172 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
173 | jc mods_valid |
173 | jc mods_valid |
174 | 174 | ||
175 | xorq %rcx, %rcx |
175 | xorq %rcx, %rcx |
176 | movq %rcx, init |
176 | movq %rcx, init |
177 | jmp mods_end |
177 | jmp mods_end |
178 | 178 | ||
179 | mods_valid: |
179 | mods_valid: |
180 | 180 | ||
181 | xorq %rcx, %rcx |
181 | xorq %rcx, %rcx |
182 | movl 20(%ebx), %ecx # mbi->mods_count |
182 | movl 20(%ebx), %ecx # mbi->mods_count |
183 | movq %rcx, init |
183 | movq %rcx, init |
184 | 184 | ||
185 | cmpl $0, %ecx |
185 | cmpl $0, %ecx |
186 | je mods_end |
186 | je mods_end |
187 | 187 | ||
188 | movl 24(%ebx), %esi # mbi->mods_addr |
188 | movl 24(%ebx), %esi # mbi->mods_addr |
189 | movq $init, %rdi |
189 | movq $init, %rdi |
190 | 190 | ||
191 | mods_loop: |
191 | mods_loop: |
192 | 192 | ||
193 | xorq %rdx, %rdx |
193 | xorq %rdx, %rdx |
194 | movl 0(%esi), %edx # mods->mod_start |
194 | movl 0(%esi), %edx # mods->mod_start |
195 | movq $0xffff800000000000, %r10 |
195 | movq $0xffff800000000000, %r10 |
196 | addq %r10, %rdx |
196 | addq %r10, %rdx |
197 | movq %rdx, 8(%rdi) |
197 | movq %rdx, 8(%rdi) |
198 | 198 | ||
199 | xorq %rdx, %rdx |
199 | xorq %rdx, %rdx |
200 | movl 4(%esi), %edx |
200 | movl 4(%esi), %edx |
201 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
201 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
202 | movq %rdx, 16(%rdi) |
202 | movq %rdx, 16(%rdi) |
203 | 203 | ||
204 | addl $16, %esi |
204 | addl $16, %esi |
205 | addq $16, %rdi |
205 | addq $16, %rdi |
206 | 206 | ||
207 | loop mods_loop |
207 | loop mods_loop |
208 | 208 | ||
209 | mods_end: |
209 | mods_end: |
210 | 210 | ||
211 | bt $6, %eax # mbi->flags[6] (mmap_length, mmap_addr valid) |
211 | bt $6, %eax # mbi->flags[6] (mmap_length, mmap_addr valid) |
212 | jc mmap_valid |
212 | jc mmap_valid |
213 | 213 | ||
214 | xorl %edx, %edx |
214 | xorl %edx, %edx |
215 | jmp mmap_invalid |
215 | jmp mmap_invalid |
216 | 216 | ||
217 | mmap_valid: |
217 | mmap_valid: |
218 | movl 44(%ebx), %ecx # mbi->mmap_length |
218 | movl 44(%ebx), %ecx # mbi->mmap_length |
219 | movl 48(%ebx), %esi # mbi->mmap_addr |
219 | movl 48(%ebx), %esi # mbi->mmap_addr |
220 | movq $e820table, %rdi |
220 | movq $e820table, %rdi |
221 | xorl %edx, %edx |
221 | xorl %edx, %edx |
222 | 222 | ||
223 | mmap_loop: |
223 | mmap_loop: |
224 | cmpl $0, %ecx |
224 | cmpl $0, %ecx |
225 | jle mmap_end |
225 | jle mmap_end |
226 | 226 | ||
227 | movl 4(%esi), %eax # mmap->base_addr_low |
227 | movl 4(%esi), %eax # mmap->base_addr_low |
228 | movl %eax, (%rdi) |
228 | movl %eax, (%rdi) |
229 | 229 | ||
230 | movl 8(%esi), %eax # mmap->base_addr_high |
230 | movl 8(%esi), %eax # mmap->base_addr_high |
231 | movl %eax, 4(%rdi) |
231 | movl %eax, 4(%rdi) |
232 | 232 | ||
233 | movl 12(%esi), %eax # mmap->length_low |
233 | movl 12(%esi), %eax # mmap->length_low |
234 | movl %eax, 8(%rdi) |
234 | movl %eax, 8(%rdi) |
235 | 235 | ||
236 | movl 16(%esi), %eax # mmap->length_high |
236 | movl 16(%esi), %eax # mmap->length_high |
237 | movl %eax, 12(%rdi) |
237 | movl %eax, 12(%rdi) |
238 | 238 | ||
239 | movl 20(%esi), %eax # mmap->type |
239 | movl 20(%esi), %eax # mmap->type |
240 | movl %eax, 16(%rdi) |
240 | movl %eax, 16(%rdi) |
241 | 241 | ||
242 | movl (%esi), %eax # mmap->size |
242 | movl (%esi), %eax # mmap->size |
243 | addl $0x4, %eax |
243 | addl $0x4, %eax |
244 | addl %eax, %esi |
244 | addl %eax, %esi |
245 | subl %eax, %ecx |
245 | subl %eax, %ecx |
246 | addq $MEMMAP_E820_RECORD_SIZE, %rdi |
246 | addq $MEMMAP_E820_RECORD_SIZE, %rdi |
247 | incl %edx |
247 | incl %edx |
248 | jmp mmap_loop |
248 | jmp mmap_loop |
249 | 249 | ||
250 | mmap_end: |
250 | mmap_end: |
251 | 251 | ||
252 | mmap_invalid: |
252 | mmap_invalid: |
253 | movl %edx, e820counter |
253 | movl %edx, e820counter |
254 | 254 | ||
255 | invalid_boot: |
255 | invalid_boot: |
256 | 256 | ||
257 | #ifdef CONFIG_SMP |
257 | #ifdef CONFIG_SMP |
258 | 258 | ||
259 | # copy AP bootstrap routines below 1 MB |
259 | # copy AP bootstrap routines below 1 MB |
260 | 260 | ||
261 | movq $BOOT_OFFSET, %rsi |
261 | movq $BOOT_OFFSET, %rsi |
262 | movq $AP_BOOT_OFFSET, %rdi |
262 | movq $AP_BOOT_OFFSET, %rdi |
263 | movq $_hardcoded_unmapped_size, %rcx |
263 | movq $_hardcoded_unmapped_size, %rcx |
264 | cld |
264 | cld |
265 | rep movsb |
265 | rep movsb |
266 | 266 | ||
267 | #endif |
267 | #endif |
268 | 268 | ||
269 | call main_bsp # never returns |
269 | call main_bsp # never returns |
270 | 270 | ||
271 | cli |
271 | cli |
272 | hlt |
272 | hlt |
273 | 273 | ||
274 | #ifdef CONFIG_FB |
274 | #ifdef CONFIG_FB |
275 | .code32 |
275 | .code32 |
276 | vesa_init: |
276 | vesa_init: |
277 | jmp $gdtselector(VESA_INIT_DES),$vesa_init_real-vesa_init; |
277 | jmp $gdtselector(VESA_INIT_DES),$vesa_init_real-vesa_init; |
278 | .code16 |
278 | .code16 |
279 | vesa_init_real: |
279 | vesa_init_real: |
280 | 280 | ||
281 | mov %cr0,%eax; |
281 | mov %cr0,%eax; |
282 | and $~1,%eax; |
282 | and $~1,%eax; |
283 | mov %eax,%cr0; |
283 | mov %eax,%cr0; |
284 | 284 | ||
285 | 285 | ||
286 | jmp $VESA_INIT_SEGMENT,$vesa_init_real2-vesa_init; |
286 | jmp $VESA_INIT_SEGMENT,$vesa_init_real2-vesa_init; |
287 | 287 | ||
288 | vesa_init_real2: |
288 | vesa_init_real2: |
289 | 289 | ||
290 | 290 | ||
291 | mov %esp,%ebp; |
291 | mov %esp,%ebp; |
292 | mov %ss,%cx; |
292 | mov %ss,%cx; |
293 | mov $VESA_INIT_SEGMENT,%bx; |
293 | mov $VESA_INIT_SEGMENT,%bx; |
294 | mov %bx,%ss; |
294 | mov %bx,%ss; |
295 | mov $0x0000fffc,%esp; |
295 | mov $0x0000fffc,%esp; |
296 | push %ds; |
296 | push %ds; |
297 | push %es; |
297 | push %es; |
298 | push %fs; |
298 | push %fs; |
299 | push %gs; |
299 | push %gs; |
300 | push %ebp; |
300 | push %ebp; |
301 | push %cx; |
301 | push %cx; |
302 | 302 | ||
303 | mov %bx,%ds; |
303 | mov %bx,%ds; |
304 | mov %bx,%es; |
304 | mov %bx,%es; |
305 | mov %bx,%fs; |
305 | mov %bx,%fs; |
306 | mov %bx,%gs; |
306 | mov %bx,%gs; |
307 | 307 | ||
308 | 308 | ||
309 | mov $vesa_idt-vesa_init,%ebx; |
309 | mov $vesa_idt-vesa_init,%ebx; |
310 | lidtl (%ebx); |
310 | lidtl (%ebx); |
311 | 311 | ||
312 | #define VESA_INFO_SIZE 1024 |
312 | #define VESA_INFO_SIZE 1024 |
313 | 313 | ||
314 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
314 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
315 | #define VESA_MODE_WIDTH_OFFSET 18 |
315 | #define VESA_MODE_WIDTH_OFFSET 18 |
316 | #define VESA_MODE_HEIGHT_OFFSET 20 |
316 | #define VESA_MODE_HEIGHT_OFFSET 20 |
317 | #define VESA_MODE_BPP_OFFSET 25 |
317 | #define VESA_MODE_BPP_OFFSET 25 |
318 | #define VESA_MODE_SCANLINE_OFFSET 16 |
318 | #define VESA_MODE_SCANLINE_OFFSET 16 |
319 | #define VESA_MODE_PHADDR_OFFSET 40 |
319 | #define VESA_MODE_PHADDR_OFFSET 40 |
320 | 320 | ||
321 | #define VESA_END_OF_MODES 0xffff |
321 | #define VESA_END_OF_MODES 0xffff |
322 | 322 | ||
323 | #define VESA_OK 0x4f |
323 | #define VESA_OK 0x4f |
324 | 324 | ||
325 | #define VESA_GET_INFO 0x4f00 |
325 | #define VESA_GET_INFO 0x4f00 |
326 | #define VESA_GET_MODE_INFO 0x4f01 |
326 | #define VESA_GET_MODE_INFO 0x4f01 |
327 | #define VESA_SET_MODE 0x4f02 |
327 | #define VESA_SET_MODE 0x4f02 |
328 | 328 | ||
329 | #define CONFIG_VESA_BPP_a 255 |
329 | #define CONFIG_VESA_BPP_a 255 |
330 | 330 | ||
331 | #if CONFIG_VESA_BPP==24 |
331 | #if CONFIG_VESA_BPP==24 |
332 | #undef CONFIG_VESA_BPP_a |
332 | #undef CONFIG_VESA_BPP_a |
333 | #define CONFIG_VESA_BPP_a 32 |
333 | #define CONFIG_VESA_BPP_a 32 |
334 | #endif |
334 | #endif |
335 | 335 | ||
336 | 336 | ||
337 | mov $VESA_GET_INFO,%ax; |
337 | mov $VESA_GET_INFO,%ax; |
338 | mov $e_vesa_init-vesa_init,%di |
338 | mov $e_vesa_init-vesa_init,%di |
339 | push %di; |
339 | push %di; |
340 | int $0x10; |
340 | int $0x10; |
341 | pop %di; |
341 | pop %di; |
342 | cmp $VESA_OK,%al; |
342 | cmp $VESA_OK,%al; |
343 | jnz 0f; |
343 | jnz 0f; |
344 | mov 2+VESA_MODE_LIST_PTR_OFFSET(%di),%si; |
344 | mov 2+VESA_MODE_LIST_PTR_OFFSET(%di),%si; |
345 | mov %si,%gs; |
345 | mov %si,%gs; |
346 | mov VESA_MODE_LIST_PTR_OFFSET(%di),%si; |
346 | mov VESA_MODE_LIST_PTR_OFFSET(%di),%si; |
347 | 347 | ||
348 | add $VESA_INFO_SIZE,%di; |
348 | add $VESA_INFO_SIZE,%di; |
349 | 349 | ||
350 | 1:# Try next mode |
350 | 1:# Try next mode |
351 | mov %gs:(%si),%cx; |
351 | mov %gs:(%si),%cx; |
352 | cmp $VESA_END_OF_MODES,%cx; |
352 | cmp $VESA_END_OF_MODES,%cx; |
353 | jz 0f; |
353 | jz 0f; |
354 | inc %si; |
354 | inc %si; |
355 | inc %si; |
355 | inc %si; |
356 | push %cx; |
356 | push %cx; |
357 | push %di; |
357 | push %di; |
358 | push %si; |
358 | push %si; |
359 | mov $VESA_GET_MODE_INFO,%ax; |
359 | mov $VESA_GET_MODE_INFO,%ax; |
360 | int $0x10; |
360 | int $0x10; |
361 | pop %si; |
361 | pop %si; |
362 | pop %di; |
362 | pop %di; |
363 | pop %cx; |
363 | pop %cx; |
364 | cmp $VESA_OK,%al; |
364 | cmp $VESA_OK,%al; |
365 | jnz 0f; |
365 | jnz 0f; |
366 | 366 | ||
367 | 367 | ||
368 | mov $CONFIG_VESA_WIDTH,%ax; |
368 | mov $CONFIG_VESA_WIDTH,%ax; |
369 | cmp VESA_MODE_WIDTH_OFFSET(%di),%ax; |
369 | cmp VESA_MODE_WIDTH_OFFSET(%di),%ax; |
370 | jnz 1b; |
370 | jnz 1b; |
371 | mov $CONFIG_VESA_HEIGHT,%ax; |
371 | mov $CONFIG_VESA_HEIGHT,%ax; |
372 | cmp VESA_MODE_HEIGHT_OFFSET(%di),%ax; |
372 | cmp VESA_MODE_HEIGHT_OFFSET(%di),%ax; |
373 | jnz 1b; |
373 | jnz 1b; |
374 | mov $CONFIG_VESA_BPP,%al; |
374 | mov $CONFIG_VESA_BPP,%al; |
375 | cmp VESA_MODE_BPP_OFFSET(%di),%al; |
375 | cmp VESA_MODE_BPP_OFFSET(%di),%al; |
376 | jz 2f; |
376 | jz 2f; |
377 | mov $CONFIG_VESA_BPP_a,%al; |
377 | mov $CONFIG_VESA_BPP_a,%al; |
378 | cmp VESA_MODE_BPP_OFFSET(%di),%al; |
378 | cmp VESA_MODE_BPP_OFFSET(%di),%al; |
379 | jnz 1b; |
379 | jnz 1b; |
380 | 380 | ||
381 | 2: |
381 | 2: |
382 | 382 | ||
383 | mov %cx,%bx; |
383 | mov %cx,%bx; |
384 | or $0xC000,%bx; |
384 | or $0xC000,%bx; |
385 | push %di; |
385 | push %di; |
386 | mov $VESA_SET_MODE,%ax; |
386 | mov $VESA_SET_MODE,%ax; |
387 | int $0x10; |
387 | int $0x10; |
388 | pop %di; |
388 | pop %di; |
389 | cmp $VESA_OK,%al; |
389 | cmp $VESA_OK,%al; |
390 | jnz 0f; |
390 | jnz 0f; |
391 | 391 | ||
392 | mov VESA_MODE_PHADDR_OFFSET(%di),%esi; |
392 | mov VESA_MODE_PHADDR_OFFSET(%di),%esi; |
393 | mov VESA_MODE_WIDTH_OFFSET(%di),%ax; |
393 | mov VESA_MODE_WIDTH_OFFSET(%di),%ax; |
394 | shl $16,%eax; |
394 | shl $16,%eax; |
395 | mov VESA_MODE_HEIGHT_OFFSET(%di),%ax; |
395 | mov VESA_MODE_HEIGHT_OFFSET(%di),%ax; |
396 | mov VESA_MODE_BPP_OFFSET(%di),%bl; |
396 | mov VESA_MODE_BPP_OFFSET(%di),%bl; |
397 | xor %bh,%bh; |
397 | xor %bh,%bh; |
398 | shl $16,%ebx; |
398 | shl $16,%ebx; |
399 | mov VESA_MODE_SCANLINE_OFFSET(%di),%bx; |
399 | mov VESA_MODE_SCANLINE_OFFSET(%di),%bx; |
400 | mov %eax,%edi; |
400 | mov %eax,%edi; |
401 | 401 | ||
402 | 402 | ||
403 | 403 | ||
404 | 8: |
404 | 8: |
405 | 405 | ||
406 | mov %cr0,%eax; |
406 | mov %cr0,%eax; |
407 | or $1,%eax; |
407 | or $1,%eax; |
408 | mov %eax,%cr0; |
408 | mov %eax,%cr0; |
409 | 409 | ||
410 | jmp 9f; |
410 | jmp 9f; |
411 | 9: |
411 | 9: |
412 | 412 | ||
413 | pop %cx; |
413 | pop %cx; |
414 | pop %ebp; |
414 | pop %ebp; |
415 | pop %gs; |
415 | pop %gs; |
416 | pop %fs; |
416 | pop %fs; |
417 | pop %es; |
417 | pop %es; |
418 | pop %ds; |
418 | pop %ds; |
419 | mov %cx,%ss; |
419 | mov %cx,%ss; |
420 | mov %ebp,%esp; |
420 | mov %ebp,%esp; |
421 | 421 | ||
422 | ljmpl $gdtselector(KTEXT32_DES),$(vesa_init_protect-vesa_init+VESA_INIT_SEGMENT<<4); |
422 | ljmpl $gdtselector(KTEXT32_DES),$(vesa_init_protect-vesa_init+VESA_INIT_SEGMENT<<4); |
423 | 423 | ||
424 | vesa_init_protect: |
- | |
425 | .code32 |
- | |
426 | ret; |
- | |
427 | - | ||
428 | 0: #Error no Prefered mode found |
- | |
429 | 424 | ||
- | 425 | 0:#Error no Prefered mode found |
|
430 | mov $0x111,%cx; |
426 | mov $0x111,%cx; |
431 | push %di; |
427 | push %di; |
432 | push %cx; |
428 | push %cx; |
433 | mov $VESA_GET_MODE_INFO,%ax; |
429 | mov $VESA_GET_MODE_INFO,%ax; |
434 | int $0x10; |
430 | int $0x10; |
435 | pop %cx; |
431 | pop %cx; |
436 | pop %di; |
432 | pop %di; |
437 | cmp $VESA_OK,%al; |
433 | cmp $VESA_OK,%al; |
438 | jnz 1f; |
434 | jnz 1f; |
439 | jmp 2b; |
435 | jz 2b; /* Force relative jump */ |
440 | 436 | ||
- | 437 | ||
441 | 1:mov $0x0003,%ax; |
438 | 1:mov $0x0003,%ax; |
442 | int $0x10; |
439 | int $0x10; |
443 | mov $0xffffffff,%edi; /* EGA text mode used, because of problems with VESA */ |
440 | mov $0xffffffff,%edi; /* EGA text mode used, because of problems with VESA */ |
- | 441 | xor %ax,%ax |
|
- | 442 | jz 8b; /* Force relative jump */ |
|
- | 443 | ||
- | 444 | ||
- | 445 | vesa_init_protect: |
|
- | 446 | .code32 |
|
444 | jmp 8; |
447 | ret; |
445 | 448 | ||
446 | 449 | ||
447 | vesa_idt: |
450 | vesa_idt: |
448 | .word 0x03ff |
451 | .word 0x03ff |
449 | .long 0 |
452 | .long 0 |
450 | .align 4 |
453 | .align 4 |
451 | e_vesa_init: |
454 | e_vesa_init: |
452 | #endif |
455 | #endif |
453 | 456 | ||
454 | 457 | ||
455 | 458 | ||
456 | .section K_DATA_START, "aw", @progbits |
459 | .section K_DATA_START, "aw", @progbits |
457 | .align 4096 |
460 | .align 4096 |
458 | 461 | ||
459 | # Identical mapping of first 64MB and the same of -2GB -> 0 |
462 | # Identical mapping of first 64MB and the same of -2GB -> 0 |
460 | .global ptl_2 |
463 | .global ptl_2 |
461 | ptl_2: |
464 | ptl_2: |
462 | .quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
465 | .quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
463 | .quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
466 | .quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
464 | .quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
467 | .quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
465 | .quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
468 | .quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
466 | .quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
469 | .quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
467 | .quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
470 | .quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
468 | .quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
471 | .quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
469 | .quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
472 | .quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
470 | .quad 0x1000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
473 | .quad 0x1000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
471 | .quad 0x1200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
474 | .quad 0x1200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
472 | .quad 0x1400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
475 | .quad 0x1400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
473 | .quad 0x1600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
476 | .quad 0x1600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
474 | .quad 0x1800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
477 | .quad 0x1800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
475 | .quad 0x1a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
478 | .quad 0x1a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
476 | .quad 0x1c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
479 | .quad 0x1c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
477 | .quad 0x1e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
480 | .quad 0x1e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
478 | .quad 0x2000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
481 | .quad 0x2000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
479 | .quad 0x2200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
482 | .quad 0x2200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
480 | .quad 0x2400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
483 | .quad 0x2400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
481 | .quad 0x2600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
484 | .quad 0x2600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
482 | .quad 0x2800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
485 | .quad 0x2800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
483 | .quad 0x2a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
486 | .quad 0x2a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
484 | .quad 0x2c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
487 | .quad 0x2c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
485 | .quad 0x2e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
488 | .quad 0x2e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
486 | .quad 0x3000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
489 | .quad 0x3000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
487 | .quad 0x3200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
490 | .quad 0x3200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
488 | .quad 0x3400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
491 | .quad 0x3400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
489 | .quad 0x3600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
492 | .quad 0x3600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
490 | .quad 0x3800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
493 | .quad 0x3800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
491 | .quad 0x3a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
494 | .quad 0x3a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
492 | .quad 0x3c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
495 | .quad 0x3c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
493 | .quad 0x3e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
496 | .quad 0x3e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
494 | 497 | ||
495 | .align 4096 |
498 | .align 4096 |
496 | .global ptl_1 |
499 | .global ptl_1 |
497 | ptl_1: |
500 | ptl_1: |
498 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
501 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
499 | .fill 509,8,0 |
502 | .fill 509,8,0 |
500 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
503 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
501 | .fill 1,8,0 |
504 | .fill 1,8,0 |
502 | 505 | ||
503 | .align 4096 |
506 | .align 4096 |
504 | .global ptl_0 |
507 | .global ptl_0 |
505 | ptl_0: |
508 | ptl_0: |
506 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
509 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
507 | .fill 255,8,0 |
510 | .fill 255,8,0 |
508 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
511 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
509 | .fill 254,8,0 |
512 | .fill 254,8,0 |
510 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
513 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
511 | 514 | ||
512 | .global bootstrap_gdtr |
515 | .global bootstrap_gdtr |
513 | bootstrap_gdtr: |
516 | bootstrap_gdtr: |
514 | .word gdtselector(GDT_ITEMS) |
517 | .word gdtselector(GDT_ITEMS) |
515 | .long KA2PA(gdt) |
518 | .long KA2PA(gdt) |
516 | 519 | ||
517 | grub_eax: |
520 | grub_eax: |
518 | .long 0 |
521 | .long 0 |
519 | 522 | ||
520 | grub_ebx: |
523 | grub_ebx: |
521 | .long 0 |
524 | .long 0 |
522 | 525 |