Rev 2302 | Rev 2784 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2302 | Rev 2725 | ||
---|---|---|---|
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 | .code32 |
39 | .code32 |
40 | .align 4 |
40 | .align 4 |
41 | .global multiboot_image_start |
41 | .global multiboot_image_start |
42 | multiboot_header: |
42 | multiboot_header: |
43 | .long MULTIBOOT_HEADER_MAGIC |
43 | .long MULTIBOOT_HEADER_MAGIC |
44 | .long MULTIBOOT_HEADER_FLAGS |
44 | .long MULTIBOOT_HEADER_FLAGS |
45 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
45 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
46 | .long multiboot_header |
46 | .long multiboot_header |
47 | .long unmapped_ktext_start |
47 | .long unmapped_ktext_start |
48 | .long 0 |
48 | .long 0 |
49 | .long 0 |
49 | .long 0 |
50 | .long multiboot_image_start |
50 | .long multiboot_image_start |
51 | 51 | ||
52 | multiboot_image_start: |
52 | multiboot_image_start: |
53 | movl $START_STACK, %esp # initialize stack pointer |
53 | movl $START_STACK, %esp # initialize stack pointer |
54 | lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register |
54 | lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register |
55 | 55 | ||
56 | movw $selector(KDATA_DES), %cx |
56 | movw $selector(KDATA_DES), %cx |
57 | movw %cx, %es |
57 | movw %cx, %es |
58 | movw %cx, %fs |
58 | movw %cx, %fs |
59 | movw %cx, %gs |
59 | movw %cx, %gs |
60 | movw %cx, %ds # kernel data + stack |
60 | movw %cx, %ds # kernel data + stack |
61 | movw %cx, %ss |
61 | movw %cx, %ss |
62 | 62 | ||
63 | jmpl $selector(KTEXT_DES), $multiboot_meeting_point |
63 | jmpl $selector(KTEXT_DES), $multiboot_meeting_point |
64 | multiboot_meeting_point: |
64 | multiboot_meeting_point: |
65 | 65 | ||
66 | movl %eax, grub_eax # save parameters from GRUB |
66 | movl %eax, grub_eax # save parameters from GRUB |
67 | movl %ebx, grub_ebx |
67 | movl %ebx, grub_ebx |
68 | 68 | ||
69 | xorl %eax, %eax |
69 | xorl %eax, %eax |
70 | cpuid |
70 | cpuid |
71 | cmp $0x0, %eax # any function > 0? |
71 | cmp $0x0, %eax # any function > 0? |
72 | jbe pse_unsupported |
72 | jbe pse_unsupported |
73 | movl $0x1, %eax # Basic function code 1 |
73 | movl $0x1, %eax # Basic function code 1 |
74 | cpuid |
74 | cpuid |
75 | bt $3, %edx # Test if PSE is supported |
75 | bt $3, %edx # Test if PSE is supported |
76 | jc pse_supported |
76 | jc pse_supported |
77 | 77 | ||
78 | pse_unsupported: |
78 | pse_unsupported: |
79 | movl $pse_msg, %esi |
79 | movl $pse_msg, %esi |
80 | jmp error_halt |
80 | jmp error_halt |
81 | 81 | ||
82 | pse_supported: |
82 | pse_supported: |
83 | 83 | ||
84 | #ifdef CONFIG_FB |
84 | #ifdef CONFIG_FB |
85 | mov $vesa_init, %esi |
85 | mov $vesa_init, %esi |
86 | mov $VESA_INIT_SEGMENT << 4, %edi |
86 | mov $VESA_INIT_SEGMENT << 4, %edi |
87 | mov $e_vesa_init - vesa_init, %ecx |
87 | mov $e_vesa_init - vesa_init, %ecx |
88 | cld |
88 | cld |
89 | rep movsb |
89 | rep movsb |
90 | 90 | ||
91 | mov $VESA_INIT_SEGMENT << 4, %edi |
91 | mov $VESA_INIT_SEGMENT << 4, %edi |
92 | jmpl *%edi |
92 | jmpl *%edi |
93 | 93 | ||
94 | vesa_meeting_point: |
94 | vesa_meeting_point: |
95 | 95 | ||
96 | mov %esi, KA2PA(vesa_ph_addr) |
96 | mov %esi, KA2PA(vesa_ph_addr) |
97 | mov %di, KA2PA(vesa_height) |
97 | mov %di, KA2PA(vesa_height) |
98 | shr $16, %edi |
98 | shr $16, %edi |
99 | mov %di, KA2PA(vesa_width) |
99 | mov %di, KA2PA(vesa_width) |
100 | mov %bx, KA2PA(vesa_scanline) |
100 | mov %bx, KA2PA(vesa_scanline) |
101 | shr $16, %ebx |
101 | shr $16, %ebx |
102 | mov %bx, KA2PA(vesa_bpp) |
102 | mov %bx, KA2PA(vesa_bpp) |
103 | #endif |
103 | #endif |
104 | 104 | ||
105 | call map_kernel # map kernel and turn paging on |
105 | call map_kernel # map kernel and turn paging on |
106 | 106 | ||
107 | movl grub_eax, %eax |
107 | movl grub_eax, %eax |
108 | movl grub_ebx, %ebx |
108 | movl grub_ebx, %ebx |
109 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
109 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
110 | je valid_boot |
110 | je valid_boot |
111 | 111 | ||
112 | xorl %ecx, %ecx # no memory size or map available |
112 | xorl %ecx, %ecx # no memory map available |
113 | movl %ecx, e801memorysize |
- | |
114 | movl %ecx, e820counter |
113 | movl %ecx, e820counter |
115 | 114 | ||
116 | jmp invalid_boot |
115 | jmp invalid_boot |
117 | 116 | ||
118 | valid_boot: |
117 | valid_boot: |
119 | 118 | ||
120 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
119 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
121 | 120 | ||
122 | bt $0, %eax # mbi->flags[0] (mem_lower, mem_upper valid) |
- | |
123 | jc mem_valid |
- | |
124 | - | ||
125 | xorl %ecx, %ecx |
- | |
126 | jmp mem_invalid |
- | |
127 | - | ||
128 | mem_valid: |
- | |
129 | movl 4(%ebx), %ecx # mbi->mem_lower |
- | |
130 | addl 8(%ebx), %ecx # mbi->mem_upper |
- | |
131 | - | ||
132 | mem_invalid: |
- | |
133 | movl %ecx, e801memorysize |
- | |
134 | - | ||
135 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
121 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
136 | jc mods_valid |
122 | jc mods_valid |
137 | 123 | ||
138 | xorl %ecx, %ecx |
124 | xorl %ecx, %ecx |
139 | movl %ecx, init |
125 | movl %ecx, init |
140 | jmp mods_end |
126 | jmp mods_end |
141 | 127 | ||
142 | mods_valid: |
128 | mods_valid: |
143 | 129 | ||
144 | movl 20(%ebx), %ecx # mbi->mods_count |
130 | movl 20(%ebx), %ecx # mbi->mods_count |
145 | movl %ecx, init |
131 | movl %ecx, init |
146 | 132 | ||
147 | cmpl $0, %ecx |
133 | cmpl $0, %ecx |
148 | je mods_end |
134 | je mods_end |
149 | 135 | ||
150 | movl 24(%ebx), %esi # mbi->mods_addr |
136 | movl 24(%ebx), %esi # mbi->mods_addr |
151 | movl $init, %edi |
137 | movl $init, %edi |
152 | 138 | ||
153 | mods_loop: |
139 | mods_loop: |
154 | 140 | ||
155 | movl 0(%esi), %edx # mods->mod_start |
141 | movl 0(%esi), %edx # mods->mod_start |
156 | addl $0x80000000, %edx |
142 | addl $0x80000000, %edx |
157 | movl %edx, 4(%edi) |
143 | movl %edx, 4(%edi) |
158 | 144 | ||
159 | movl 4(%esi), %edx |
145 | movl 4(%esi), %edx |
160 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
146 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
161 | movl %edx, 8(%edi) |
147 | movl %edx, 8(%edi) |
162 | 148 | ||
163 | addl $16, %esi |
149 | addl $16, %esi |
164 | addl $8 , %edi |
150 | addl $8 , %edi |
165 | 151 | ||
166 | loop mods_loop |
152 | loop mods_loop |
167 | 153 | ||
168 | mods_end: |
154 | mods_end: |
169 | 155 | ||
170 | bt $6, %eax # mbi->flags[6] (mmap_length, mmap_addr valid) |
156 | bt $6, %eax # mbi->flags[6] (mmap_length, mmap_addr valid) |
171 | jc mmap_valid |
157 | jc mmap_valid |
172 | 158 | ||
173 | xorl %edx, %edx |
159 | xorl %edx, %edx |
174 | jmp mmap_invalid |
160 | jmp mmap_invalid |
175 | 161 | ||
176 | mmap_valid: |
162 | mmap_valid: |
177 | movl 44(%ebx), %ecx # mbi->mmap_length |
163 | movl 44(%ebx), %ecx # mbi->mmap_length |
178 | movl 48(%ebx), %esi # mbi->mmap_addr |
164 | movl 48(%ebx), %esi # mbi->mmap_addr |
179 | movl $e820table, %edi |
165 | movl $e820table, %edi |
180 | xorl %edx, %edx |
166 | xorl %edx, %edx |
181 | 167 | ||
182 | mmap_loop: |
168 | mmap_loop: |
183 | cmpl $0, %ecx |
169 | cmpl $0, %ecx |
184 | jle mmap_end |
170 | jle mmap_end |
185 | 171 | ||
186 | movl 4(%esi), %eax # mmap->base_addr_low |
172 | movl 4(%esi), %eax # mmap->base_addr_low |
187 | movl %eax, (%edi) |
173 | movl %eax, (%edi) |
188 | 174 | ||
189 | movl 8(%esi), %eax # mmap->base_addr_high |
175 | movl 8(%esi), %eax # mmap->base_addr_high |
190 | movl %eax, 4(%edi) |
176 | movl %eax, 4(%edi) |
191 | 177 | ||
192 | movl 12(%esi), %eax # mmap->length_low |
178 | movl 12(%esi), %eax # mmap->length_low |
193 | movl %eax, 8(%edi) |
179 | movl %eax, 8(%edi) |
194 | 180 | ||
195 | movl 16(%esi), %eax # mmap->length_high |
181 | movl 16(%esi), %eax # mmap->length_high |
196 | movl %eax, 12(%edi) |
182 | movl %eax, 12(%edi) |
197 | 183 | ||
198 | movl 20(%esi), %eax # mmap->type |
184 | movl 20(%esi), %eax # mmap->type |
199 | movl %eax, 16(%edi) |
185 | movl %eax, 16(%edi) |
200 | 186 | ||
201 | movl (%esi), %eax # mmap->size |
187 | movl (%esi), %eax # mmap->size |
202 | addl $0x4, %eax |
188 | addl $0x4, %eax |
203 | addl %eax, %esi |
189 | addl %eax, %esi |
204 | subl %eax, %ecx |
190 | subl %eax, %ecx |
205 | addl $MEMMAP_E820_RECORD_SIZE, %edi |
191 | addl $MEMMAP_E820_RECORD_SIZE, %edi |
206 | incl %edx |
192 | incl %edx |
207 | jmp mmap_loop |
193 | jmp mmap_loop |
208 | 194 | ||
209 | mmap_end: |
195 | mmap_end: |
210 | 196 | ||
211 | mmap_invalid: |
197 | mmap_invalid: |
212 | movl %edx, e820counter |
198 | movl %edx, e820counter |
213 | 199 | ||
214 | invalid_boot: |
200 | invalid_boot: |
215 | 201 | ||
216 | #ifdef CONFIG_SMP |
202 | #ifdef CONFIG_SMP |
217 | 203 | ||
218 | # copy AP bootstrap routines below 1 MB |
204 | # copy AP bootstrap routines below 1 MB |
219 | 205 | ||
220 | movl $BOOT_OFFSET, %esi |
206 | movl $BOOT_OFFSET, %esi |
221 | movl $AP_BOOT_OFFSET, %edi |
207 | movl $AP_BOOT_OFFSET, %edi |
222 | movl $_hardcoded_unmapped_size, %ecx |
208 | movl $_hardcoded_unmapped_size, %ecx |
223 | cld |
209 | cld |
224 | rep movsb |
210 | rep movsb |
225 | 211 | ||
226 | #endif |
212 | #endif |
227 | 213 | ||
228 | call main_bsp # never returns |
214 | call main_bsp # never returns |
229 | 215 | ||
230 | cli |
216 | cli |
231 | hlt |
217 | hlt |
232 | 218 | ||
233 | .global map_kernel |
219 | .global map_kernel |
234 | map_kernel: |
220 | map_kernel: |
235 | # |
221 | # |
236 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
222 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
237 | # For simplicity, we map the entire 4G space. |
223 | # For simplicity, we map the entire 4G space. |
238 | # |
224 | # |
239 | movl %cr4, %ecx |
225 | movl %cr4, %ecx |
240 | orl $(1 << 4), %ecx # turn PSE on |
226 | orl $(1 << 4), %ecx # turn PSE on |
241 | andl $(~(1 << 5)), %ecx # turn PAE off |
227 | andl $(~(1 << 5)), %ecx # turn PAE off |
242 | movl %ecx, %cr4 |
228 | movl %ecx, %cr4 |
243 | 229 | ||
244 | movl $(page_directory + 0), %esi |
230 | movl $(page_directory + 0), %esi |
245 | movl $(page_directory + 2048), %edi |
231 | movl $(page_directory + 2048), %edi |
246 | xorl %ecx, %ecx |
232 | xorl %ecx, %ecx |
247 | xorl %ebx, %ebx |
233 | xorl %ebx, %ebx |
248 | 0: |
234 | 0: |
249 | movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax |
235 | movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax |
250 | orl %ebx, %eax |
236 | orl %ebx, %eax |
251 | movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
237 | movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
252 | movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
238 | movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
253 | addl $(4 * 1024 * 1024), %ebx |
239 | addl $(4 * 1024 * 1024), %ebx |
254 | 240 | ||
255 | incl %ecx |
241 | incl %ecx |
256 | cmpl $512, %ecx |
242 | cmpl $512, %ecx |
257 | jl 0b |
243 | jl 0b |
258 | 244 | ||
259 | movl %esi, %cr3 |
245 | movl %esi, %cr3 |
260 | 246 | ||
261 | movl %cr0, %ebx |
247 | movl %cr0, %ebx |
262 | orl $(1 << 31), %ebx # turn paging on |
248 | orl $(1 << 31), %ebx # turn paging on |
263 | movl %ebx, %cr0 |
249 | movl %ebx, %cr0 |
264 | ret |
250 | ret |
265 | 251 | ||
266 | # Print string from %esi to EGA display (in red) and halt |
252 | # Print string from %esi to EGA display (in red) and halt |
267 | error_halt: |
253 | error_halt: |
268 | movl $0xb8000, %edi # base of EGA text mode memory |
254 | movl $0xb8000, %edi # base of EGA text mode memory |
269 | xorl %eax, %eax |
255 | xorl %eax, %eax |
270 | 256 | ||
271 | movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
257 | movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
272 | movb $0xe, %al |
258 | movb $0xe, %al |
273 | outb %al, %dx |
259 | outb %al, %dx |
274 | 260 | ||
275 | movw $0x3d5, %dx |
261 | movw $0x3d5, %dx |
276 | inb %dx, %al |
262 | inb %dx, %al |
277 | shl $8, %ax |
263 | shl $8, %ax |
278 | 264 | ||
279 | movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
265 | movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
280 | movb $0xf, %al |
266 | movb $0xf, %al |
281 | outb %al, %dx |
267 | outb %al, %dx |
282 | 268 | ||
283 | movw $0x3d5, %dx |
269 | movw $0x3d5, %dx |
284 | inb %dx, %al |
270 | inb %dx, %al |
285 | 271 | ||
286 | cmp $1920, %ax |
272 | cmp $1920, %ax |
287 | jbe cursor_ok |
273 | jbe cursor_ok |
288 | movw $1920, %ax # sanity check for the cursor on the last line |
274 | movw $1920, %ax # sanity check for the cursor on the last line |
289 | cursor_ok: |
275 | cursor_ok: |
290 | 276 | ||
291 | movw %ax, %bx |
277 | movw %ax, %bx |
292 | shl $1, %eax |
278 | shl $1, %eax |
293 | addl %eax, %edi |
279 | addl %eax, %edi |
294 | 280 | ||
295 | movw $0x0c00, %ax # black background, light red foreground |
281 | movw $0x0c00, %ax # black background, light red foreground |
296 | cld |
282 | cld |
297 | 283 | ||
298 | ploop: |
284 | ploop: |
299 | lodsb |
285 | lodsb |
300 | cmp $0, %al |
286 | cmp $0, %al |
301 | je ploop_end |
287 | je ploop_end |
302 | stosw |
288 | stosw |
303 | inc %bx |
289 | inc %bx |
304 | jmp ploop |
290 | jmp ploop |
305 | ploop_end: |
291 | ploop_end: |
306 | 292 | ||
307 | movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
293 | movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
308 | movb $0xe, %al |
294 | movb $0xe, %al |
309 | outb %al, %dx |
295 | outb %al, %dx |
310 | 296 | ||
311 | movw $0x3d5, %dx |
297 | movw $0x3d5, %dx |
312 | movb %bh, %al |
298 | movb %bh, %al |
313 | outb %al, %dx |
299 | outb %al, %dx |
314 | 300 | ||
315 | movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
301 | movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
316 | movb $0xf, %al |
302 | movb $0xf, %al |
317 | outb %al, %dx |
303 | outb %al, %dx |
318 | 304 | ||
319 | movw $0x3d5, %dx |
305 | movw $0x3d5, %dx |
320 | movb %bl, %al |
306 | movb %bl, %al |
321 | outb %al, %dx |
307 | outb %al, %dx |
322 | 308 | ||
323 | cli |
309 | cli |
324 | hlt |
310 | hlt |
325 | 311 | ||
326 | #ifdef CONFIG_FB |
312 | #ifdef CONFIG_FB |
327 | vesa_init: |
313 | vesa_init: |
328 | jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init |
314 | jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init |
329 | 315 | ||
330 | .code16 |
316 | .code16 |
331 | vesa_init_real: |
317 | vesa_init_real: |
332 | 318 | ||
333 | mov %cr0, %eax |
319 | mov %cr0, %eax |
334 | and $~1, %eax |
320 | and $~1, %eax |
335 | mov %eax, %cr0 |
321 | mov %eax, %cr0 |
336 | 322 | ||
337 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init |
323 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init |
338 | 324 | ||
339 | vesa_init_real2: |
325 | vesa_init_real2: |
340 | 326 | ||
341 | mov $VESA_INIT_SEGMENT, %bx |
327 | mov $VESA_INIT_SEGMENT, %bx |
342 | 328 | ||
343 | mov %bx, %es |
329 | mov %bx, %es |
344 | mov %bx, %fs |
330 | mov %bx, %fs |
345 | mov %bx, %gs |
331 | mov %bx, %gs |
346 | mov %bx, %ds |
332 | mov %bx, %ds |
347 | mov %bx, %ss |
333 | mov %bx, %ss |
348 | 334 | ||
349 | movl %esp, %eax |
335 | movl %esp, %eax |
350 | movl $0x0000fffc, %esp |
336 | movl $0x0000fffc, %esp |
351 | movl $0x0000fffc, %ebp |
337 | movl $0x0000fffc, %ebp |
352 | pushl %eax |
338 | pushl %eax |
353 | 339 | ||
354 | #define VESA_INFO_SIZE 1024 |
340 | #define VESA_INFO_SIZE 1024 |
355 | 341 | ||
356 | #define VESA_MODE_ATTRIBUTES_OFFSET 0 |
342 | #define VESA_MODE_ATTRIBUTES_OFFSET 0 |
357 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
343 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
358 | #define VESA_MODE_SCANLINE_OFFSET 16 |
344 | #define VESA_MODE_SCANLINE_OFFSET 16 |
359 | #define VESA_MODE_WIDTH_OFFSET 18 |
345 | #define VESA_MODE_WIDTH_OFFSET 18 |
360 | #define VESA_MODE_HEIGHT_OFFSET 20 |
346 | #define VESA_MODE_HEIGHT_OFFSET 20 |
361 | #define VESA_MODE_BPP_OFFSET 25 |
347 | #define VESA_MODE_BPP_OFFSET 25 |
362 | #define VESA_MODE_PHADDR_OFFSET 40 |
348 | #define VESA_MODE_PHADDR_OFFSET 40 |
363 | 349 | ||
364 | #define VESA_END_OF_MODES 0xffff |
350 | #define VESA_END_OF_MODES 0xffff |
365 | 351 | ||
366 | #define VESA_OK 0x4f |
352 | #define VESA_OK 0x4f |
367 | 353 | ||
368 | #define VESA_GET_INFO 0x4f00 |
354 | #define VESA_GET_INFO 0x4f00 |
369 | #define VESA_GET_MODE_INFO 0x4f01 |
355 | #define VESA_GET_MODE_INFO 0x4f01 |
370 | #define VESA_SET_MODE 0x4f02 |
356 | #define VESA_SET_MODE 0x4f02 |
371 | #define VESA_SET_PALETTE 0x4f09 |
357 | #define VESA_SET_PALETTE 0x4f09 |
372 | 358 | ||
373 | #if CONFIG_VESA_BPP == 24 |
359 | #if CONFIG_VESA_BPP == 24 |
374 | #define CONFIG_VESA_BPP_VARIANT 32 |
360 | #define CONFIG_VESA_BPP_VARIANT 32 |
375 | #endif |
361 | #endif |
376 | 362 | ||
377 | mov $VESA_GET_INFO, %ax |
363 | mov $VESA_GET_INFO, %ax |
378 | mov $e_vesa_init - vesa_init, %di |
364 | mov $e_vesa_init - vesa_init, %di |
379 | push %di |
365 | push %di |
380 | int $0x10 |
366 | int $0x10 |
381 | 367 | ||
382 | pop %di |
368 | pop %di |
383 | cmp $VESA_OK, %al |
369 | cmp $VESA_OK, %al |
384 | jnz 0f |
370 | jnz 0f |
385 | 371 | ||
386 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
372 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
387 | mov %si, %gs |
373 | mov %si, %gs |
388 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
374 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
389 | 375 | ||
390 | add $VESA_INFO_SIZE, %di |
376 | add $VESA_INFO_SIZE, %di |
391 | 377 | ||
392 | 1:# Try next mode |
378 | 1:# Try next mode |
393 | mov %gs:(%si), %cx |
379 | mov %gs:(%si), %cx |
394 | cmp $VESA_END_OF_MODES, %cx |
380 | cmp $VESA_END_OF_MODES, %cx |
395 | jz 0f |
381 | jz 0f |
396 | 382 | ||
397 | inc %si |
383 | inc %si |
398 | inc %si |
384 | inc %si |
399 | push %cx |
385 | push %cx |
400 | push %di |
386 | push %di |
401 | push %si |
387 | push %si |
402 | mov $VESA_GET_MODE_INFO, %ax |
388 | mov $VESA_GET_MODE_INFO, %ax |
403 | int $0x10 |
389 | int $0x10 |
404 | 390 | ||
405 | pop %si |
391 | pop %si |
406 | pop %di |
392 | pop %di |
407 | pop %cx |
393 | pop %cx |
408 | cmp $VESA_OK, %al |
394 | cmp $VESA_OK, %al |
409 | jnz 0f |
395 | jnz 0f |
410 | 396 | ||
411 | mov $CONFIG_VESA_WIDTH, %ax |
397 | mov $CONFIG_VESA_WIDTH, %ax |
412 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
398 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
413 | jnz 1b |
399 | jnz 1b |
414 | 400 | ||
415 | mov $CONFIG_VESA_HEIGHT, %ax |
401 | mov $CONFIG_VESA_HEIGHT, %ax |
416 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
402 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
417 | jnz 1b |
403 | jnz 1b |
418 | 404 | ||
419 | mov $CONFIG_VESA_BPP, %al |
405 | mov $CONFIG_VESA_BPP, %al |
420 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
406 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
421 | 407 | ||
422 | #ifdef CONFIG_VESA_BPP_VARIANT |
408 | #ifdef CONFIG_VESA_BPP_VARIANT |
423 | jz 2f |
409 | jz 2f |
424 | 410 | ||
425 | mov $CONFIG_VESA_BPP_VARIANT, %al |
411 | mov $CONFIG_VESA_BPP_VARIANT, %al |
426 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
412 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
427 | #endif |
413 | #endif |
428 | jnz 1b |
414 | jnz 1b |
429 | 415 | ||
430 | 2: |
416 | 2: |
431 | 417 | ||
432 | mov %cx, %bx |
418 | mov %cx, %bx |
433 | or $0xc000, %bx |
419 | or $0xc000, %bx |
434 | push %di |
420 | push %di |
435 | mov $VESA_SET_MODE, %ax |
421 | mov $VESA_SET_MODE, %ax |
436 | int $0x10 |
422 | int $0x10 |
437 | 423 | ||
438 | pop %di |
424 | pop %di |
439 | cmp $VESA_OK, %al |
425 | cmp $VESA_OK, %al |
440 | jnz 0f |
426 | jnz 0f |
441 | 427 | ||
442 | #if CONFIG_VESA_BPP == 8 |
428 | #if CONFIG_VESA_BPP == 8 |
443 | 429 | ||
444 | # Set 3:2:3 VGA palette |
430 | # Set 3:2:3 VGA palette |
445 | 431 | ||
446 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
432 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
447 | push %di |
433 | push %di |
448 | mov $vga323 - vesa_init, %di |
434 | mov $vga323 - vesa_init, %di |
449 | mov $0x100, %ecx |
435 | mov $0x100, %ecx |
450 | 436 | ||
451 | bt $5, %ax # Test if VGA compatible registers are present |
437 | bt $5, %ax # Test if VGA compatible registers are present |
452 | jnc vga_compat |
438 | jnc vga_compat |
453 | 439 | ||
454 | # Try VESA routine to set palette |
440 | # Try VESA routine to set palette |
455 | 441 | ||
456 | mov $VESA_SET_PALETTE, %ax |
442 | mov $VESA_SET_PALETTE, %ax |
457 | xor %bl, %bl |
443 | xor %bl, %bl |
458 | xor %dx, %dx |
444 | xor %dx, %dx |
459 | int $0x10 |
445 | int $0x10 |
460 | 446 | ||
461 | jmp vga_not_compat |
447 | jmp vga_not_compat |
462 | 448 | ||
463 | vga_compat: |
449 | vga_compat: |
464 | 450 | ||
465 | # Try VGA registers to set palette |
451 | # Try VGA registers to set palette |
466 | 452 | ||
467 | movw $0x3c6, %dx # Set palette mask |
453 | movw $0x3c6, %dx # Set palette mask |
468 | movb $0xff, %al |
454 | movb $0xff, %al |
469 | outb %al, %dx |
455 | outb %al, %dx |
470 | 456 | ||
471 | movw $0x3c8, %dx # First index to set |
457 | movw $0x3c8, %dx # First index to set |
472 | xor %al, %al |
458 | xor %al, %al |
473 | outb %al, %dx |
459 | outb %al, %dx |
474 | 460 | ||
475 | movw $0x3c9, %dx # Data port |
461 | movw $0x3c9, %dx # Data port |
476 | vga_loop: |
462 | vga_loop: |
477 | movb %es:2(%di), %al |
463 | movb %es:2(%di), %al |
478 | outb %al, %dx |
464 | outb %al, %dx |
479 | 465 | ||
480 | movb %es:1(%di), %al |
466 | movb %es:1(%di), %al |
481 | outb %al, %dx |
467 | outb %al, %dx |
482 | 468 | ||
483 | movb %es:(%di), %al |
469 | movb %es:(%di), %al |
484 | outb %al, %dx |
470 | outb %al, %dx |
485 | 471 | ||
486 | addw $4, %di |
472 | addw $4, %di |
487 | loop vga_loop |
473 | loop vga_loop |
488 | 474 | ||
489 | vga_not_compat: |
475 | vga_not_compat: |
490 | 476 | ||
491 | pop %di |
477 | pop %di |
492 | 478 | ||
493 | #endif |
479 | #endif |
494 | 480 | ||
495 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
481 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
496 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
482 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
497 | shl $16, %eax |
483 | shl $16, %eax |
498 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
484 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
499 | mov VESA_MODE_BPP_OFFSET(%di), %bl |
485 | mov VESA_MODE_BPP_OFFSET(%di), %bl |
500 | xor %bh, %bh |
486 | xor %bh, %bh |
501 | shl $16, %ebx |
487 | shl $16, %ebx |
502 | mov VESA_MODE_SCANLINE_OFFSET(%di), %bx |
488 | mov VESA_MODE_SCANLINE_OFFSET(%di), %bx |
503 | mov %eax, %edi |
489 | mov %eax, %edi |
504 | 490 | ||
505 | 8: |
491 | 8: |
506 | 492 | ||
507 | mov %cr0, %eax |
493 | mov %cr0, %eax |
508 | or $1, %eax |
494 | or $1, %eax |
509 | mov %eax, %cr0 |
495 | mov %eax, %cr0 |
510 | 496 | ||
511 | jmp 9f |
497 | jmp 9f |
512 | 9: |
498 | 9: |
513 | 499 | ||
514 | ljmpl $selector(KTEXT_DES), $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) |
500 | ljmpl $selector(KTEXT_DES), $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) |
515 | 501 | ||
516 | 0:# No prefered mode found |
502 | 0:# No prefered mode found |
517 | mov $0x111, %cx |
503 | mov $0x111, %cx |
518 | push %di |
504 | push %di |
519 | push %cx |
505 | push %cx |
520 | mov $VESA_GET_MODE_INFO, %ax |
506 | mov $VESA_GET_MODE_INFO, %ax |
521 | int $0x10 |
507 | int $0x10 |
522 | 508 | ||
523 | pop %cx |
509 | pop %cx |
524 | pop %di |
510 | pop %di |
525 | cmp $VESA_OK, %al |
511 | cmp $VESA_OK, %al |
526 | jnz 1f |
512 | jnz 1f |
527 | jz 2b # Force relative jump |
513 | jz 2b # Force relative jump |
528 | 514 | ||
529 | 1: |
515 | 1: |
530 | mov $0x0003, %ax |
516 | mov $0x0003, %ax |
531 | int $0x10 |
517 | int $0x10 |
532 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
518 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
533 | xor %ax, %ax |
519 | xor %ax, %ax |
534 | jz 8b # Force relative jump |
520 | jz 8b # Force relative jump |
535 | 521 | ||
536 | vga323: |
522 | vga323: |
537 | #include "vga323.pal" |
523 | #include "vga323.pal" |
538 | 524 | ||
539 | .code32 |
525 | .code32 |
540 | vesa_init_protect: |
526 | vesa_init_protect: |
541 | movw $selector(KDATA_DES), %cx |
527 | movw $selector(KDATA_DES), %cx |
542 | movw %cx, %es |
528 | movw %cx, %es |
543 | movw %cx, %fs |
529 | movw %cx, %fs |
544 | movw %cx, %gs |
530 | movw %cx, %gs |
545 | movw %cx, %ds # kernel data + stack |
531 | movw %cx, %ds # kernel data + stack |
546 | movw %cx, %ss |
532 | movw %cx, %ss |
547 | 533 | ||
548 | movl $START_STACK, %esp # initialize stack pointer |
534 | movl $START_STACK, %esp # initialize stack pointer |
549 | 535 | ||
550 | jmpl $selector(KTEXT_DES), $vesa_meeting_point |
536 | jmpl $selector(KTEXT_DES), $vesa_meeting_point |
551 | 537 | ||
552 | .align 4 |
538 | .align 4 |
553 | e_vesa_init: |
539 | e_vesa_init: |
554 | #endif |
540 | #endif |
555 | 541 | ||
556 | .section K_DATA_START, "aw", @progbits |
542 | .section K_DATA_START, "aw", @progbits |
557 | 543 | ||
558 | .align 4096 |
544 | .align 4096 |
559 | page_directory: |
545 | page_directory: |
560 | .space 4096, 0 |
546 | .space 4096, 0 |
561 | 547 | ||
562 | grub_eax: |
548 | grub_eax: |
563 | .long 0 |
549 | .long 0 |
564 | 550 | ||
565 | grub_ebx: |
551 | grub_ebx: |
566 | .long 0 |
552 | .long 0 |
567 | 553 | ||
568 | pse_msg: |
554 | pse_msg: |
569 | .asciz "Page Size Extension not supported. System halted." |
555 | .asciz "Page Size Extension not supported. System halted." |
570 | 556 |