Changes in kernel/arch/ia32/src/boot/boot.S [873c681:bac86377] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/boot/boot.S
r873c681 rbac86377 1 /* 2 * Copyright (c) 2001Jakub Jermar3 * Copyright (c) 2005Martin Decky4 *All rights reserved.5 * 6 *Redistribution and use in source and binary forms, with or without7 *modification, are permitted provided that the following conditions8 *are met:9 * 10 *- Redistributions of source code must retain the above copyright11 *notice, this list of conditions and the following disclaimer.12 *- Redistributions in binary form must reproduce the above copyright13 *notice, this list of conditions and the following disclaimer in the14 *documentation and/or other materials provided with the distribution.15 *- The name of the author may not be used to endorse or promote products16 *derived from this software without specific prior written permission.17 * 18 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19 *IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20 *OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21 *IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22 *INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24 *DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25 *THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26 *(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27 *THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 */ 1 # 2 # Copyright (c) 2001-2004 Jakub Jermar 3 # Copyright (c) 2005-2006 Martin Decky 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 10 # - Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # - Redistributions in binary form must reproduce the above copyright 13 # notice, this list of conditions and the following disclaimer in the 14 # documentation and/or other materials provided with the distribution. 15 # - The name of the author may not be used to endorse or promote products 16 # derived from this software without specific prior written permission. 17 # 18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # 29 29 30 30 #include <arch/boot/boot.h> … … 34 34 #include <arch/cpuid.h> 35 35 36 #define START_STACK 36 #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) 37 37 38 38 .section K_TEXT_START, "ax" 39 39 40 40 .code32 41 42 .macro pm_error msg43 movl \msg, %esi44 jmp pm_error_halt45 .endm46 47 .macro pm_status msg48 #ifdef CONFIG_EGA49 pushl %esi50 movl \msg, %esi51 call pm_early_puts52 popl %esi53 #endif54 .endm55 56 .macro pm2_status msg57 pushl \msg58 call early_puts59 .endm60 61 41 .align 4 62 42 .global multiboot_image_start … … 64 44 .long MULTIBOOT_HEADER_MAGIC 65 45 .long MULTIBOOT_HEADER_FLAGS 66 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) /* checksum */46 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum 67 47 .long multiboot_header 68 48 .long unmapped_ktext_start … … 73 53 multiboot_image_start: 74 54 cld 75 76 /* Initialize stack pointer */ 77 movl $START_STACK, %esp 78 79 /* Initialize Global Descriptor Table register */ 80 lgdtl KA2PA(bootstrap_gdtr) 81 82 /* Kernel data + stack */ 55 movl $START_STACK, %esp # initialize stack pointer 56 lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register 57 83 58 movw $gdtselector(KDATA_DES), %cx 84 59 movw %cx, %es 85 60 movw %cx, %fs 86 61 movw %cx, %gs 87 movw %cx, %ds 62 movw %cx, %ds # kernel data + stack 88 63 movw %cx, %ss 89 64 … … 91 66 multiboot_meeting_point: 92 67 93 /* Save GRUB arguments */ 94 movl %eax, grub_eax 68 movl %eax, grub_eax # save parameters from GRUB 95 69 movl %ebx, grub_ebx 96 97 pm_status $status_prot98 70 99 71 movl $(INTEL_CPUID_LEVEL), %eax 100 72 cpuid 101 cmp $0x0, %eax /* any function > 0? */73 cmp $0x0, %eax # any function > 0? 102 74 jbe pse_unsupported 103 75 … … 108 80 109 81 pse_unsupported: 110 111 pm_error $err_pse82 movl $pse_msg, %esi 83 jmp error_halt 112 84 113 85 pse_supported: 114 86 115 87 #include "vesa_prot.inc" 116 117 /* Map kernel and turn paging on */88 89 # map kernel and turn paging on 118 90 call map_kernel 119 91 120 /* Create the first stack frame */ 121 pushl $0 122 movl %esp, %ebp 123 124 pm2_status $status_prot2 125 126 /* Call arch_pre_main(grub_eax, grub_ebx) */ 92 # call arch_pre_main(grub_eax, grub_ebx) 127 93 pushl grub_ebx 128 94 pushl grub_eax 129 95 call arch_pre_main 130 131 pm2_status $status_main 132 133 /* Call main_bsp() */ 96 97 # Create the first stack frame 98 pushl $0 99 movl %esp, %ebp 100 134 101 call main_bsp 135 102 136 /* Not reached */103 # not reached 137 104 cli 138 105 hlt0: … … 140 107 jmp hlt0 141 108 142 /** Setup mapping for the kernel.143 *144 * Setup mapping for both the unmapped and mapped sections145 * of the kernel. For simplicity, we map the entire 4G space.146 *147 */148 109 .global map_kernel 149 110 map_kernel: 111 # 112 # Here we setup mapping for both the unmapped and mapped sections of the kernel. 113 # For simplicity, we map the entire 4G space. 114 # 150 115 movl %cr4, %ecx 151 orl $(1 << 4), %ecx /* PSE on */152 andl $(~(1 << 5)), %ecx /* PAE off */116 orl $(1 << 4), %ecx # turn PSE on 117 andl $(~(1 << 5)), %ecx # turn PAE off 153 118 movl %ecx, %cr4 154 119 … … 161 126 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax 162 127 orl %ebx, %eax 163 /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 164 movl %eax, (%esi, %ecx, 4) 165 /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 166 movl %eax, (%edi, %ecx, 4) 128 movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M 129 movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M 167 130 addl $(4 * 1024 * 1024), %ebx 168 131 … … 174 137 175 138 movl %cr0, %ebx 176 orl $(1 << 31), %ebx /* paging on */139 orl $(1 << 31), %ebx # turn paging on 177 140 movl %ebx, %cr0 178 141 ret 179 142 180 /** Print string to EGA display (in light red) and halt. 181 * 182 * Should be executed from 32 bit protected mode with paging 183 * turned off. Stack is not required. This routine is used even 184 * if CONFIG_EGA is not enabled. Since we are going to halt the 185 * CPU anyway, it is always better to at least try to print 186 * some hints. 187 * 188 * @param %esi NULL-terminated string to print. 189 * 190 */ 191 pm_error_halt: 192 movl $0xb8000, %edi /* base of EGA text mode memory */ 143 # Print string from %esi to EGA display (in red) and halt 144 error_halt: 145 movl $0xb8000, %edi # base of EGA text mode memory 193 146 xorl %eax, %eax 194 147 195 /* Read bits 8 - 15 of the cursor address */ 196 movw $0x3d4, %dx 148 movw $0x3d4, %dx # read bits 8 - 15 of the cursor address 197 149 movb $0xe, %al 198 150 outb %al, %dx … … 202 154 shl $8, %ax 203 155 204 /* Read bits 0 - 7 of the cursor address */ 205 movw $0x3d4, %dx 156 movw $0x3d4, %dx # read bits 0 - 7 of the cursor address 206 157 movb $0xf, %al 207 158 outb %al, %dx … … 210 161 inb %dx, %al 211 162 212 /* Sanity check for the cursor on screen */ 213 cmp $2000, %ax 214 jb err_cursor_ok 215 216 movw $1998, %ax 217 218 err_cursor_ok: 163 cmp $1920, %ax 164 jbe cursor_ok 165 166 movw $1920, %ax # sanity check for the cursor on the last line 167 168 cursor_ok: 219 169 220 170 movw %ax, %bx … … 222 172 addl %eax, %edi 223 173 224 err_ploop: 174 movw $0x0c00, %ax # black background, light red foreground 175 176 ploop: 225 177 lodsb 226 227 178 cmp $0, %al 228 je err_ploop_end 229 230 movb $0x0c, %ah /* black background, light red foreground */ 179 je ploop_end 231 180 stosw 232 233 /* Sanity check for the cursor on the last line */234 181 inc %bx 235 cmp $2000, %bx 236 jb err_ploop 237 238 /* Scroll the screen (24 rows) */ 239 movl %esi, %edx 240 movl $0xb80a0, %esi 241 movl $0xb8000, %edi 242 movl $1920, %ecx 243 rep movsw 244 245 /* Clear the 24th row */ 246 xorl %eax, %eax 247 movl $80, %ecx 248 rep stosw 249 250 /* Go to row 24 */ 251 movl %edx, %esi 252 movl $0xb8f00, %edi 253 movw $1920, %bx 254 255 jmp err_ploop 256 err_ploop_end: 257 258 /* Write bits 8 - 15 of the cursor address */ 259 movw $0x3d4, %dx 182 jmp ploop 183 ploop_end: 184 185 movw $0x3d4, %dx # write bits 8 - 15 of the cursor address 260 186 movb $0xe, %al 261 187 outb %al, %dx … … 265 191 outb %al, %dx 266 192 267 /* Write bits 0 - 7 of the cursor address */ 268 movw $0x3d4, %dx 193 movw $0x3d4, %dx # write bits 0 - 7 of the cursor address 269 194 movb $0xf, %al 270 195 outb %al, %dx … … 279 204 jmp hlt1 280 205 281 /** Print string to EGA display (in light green).282 *283 * Should be called from 32 bit protected mode with paging284 * turned off. A stack space of at least 24 bytes is required,285 * but the function does not establish a stack frame.286 *287 * Macros such as pm_status take care that this function288 * is used only when CONFIG_EGA is enabled.289 *290 * @param %esi NULL-terminated string to print.291 *292 */293 pm_early_puts:294 pushl %eax295 pushl %ebx296 pushl %ecx297 pushl %edx298 pushl %edi299 300 movl $0xb8000, %edi /* base of EGA text mode memory */301 xorl %eax, %eax302 303 /* Read bits 8 - 15 of the cursor address */304 movw $0x3d4, %dx305 movb $0xe, %al306 outb %al, %dx307 308 movw $0x3d5, %dx309 inb %dx, %al310 shl $8, %ax311 312 /* Read bits 0 - 7 of the cursor address */313 movw $0x3d4, %dx314 movb $0xf, %al315 outb %al, %dx316 317 movw $0x3d5, %dx318 inb %dx, %al319 320 /* Sanity check for the cursor on screen */321 cmp $2000, %ax322 jb pm_puts_cursor_ok323 324 movw $1998, %ax325 326 pm_puts_cursor_ok:327 328 movw %ax, %bx329 shl $1, %eax330 addl %eax, %edi331 332 pm_puts_ploop:333 lodsb334 335 cmp $0, %al336 je pm_puts_ploop_end337 338 movb $0x0a, %ah /* black background, light green foreground */339 stosw340 341 /* Sanity check for the cursor on the last line */342 inc %bx343 cmp $2000, %bx344 jb pm_puts_ploop345 346 /* Scroll the screen (24 rows) */347 movl %esi, %edx348 movl $0xb80a0, %esi349 movl $0xb8000, %edi350 movl $1920, %ecx351 rep movsw352 353 /* Clear the 24th row */354 xorl %eax, %eax355 movl $80, %ecx356 rep stosw357 358 /* Go to row 24 */359 movl %edx, %esi360 movl $0xb8f00, %edi361 movw $1920, %bx362 363 jmp pm_puts_ploop364 pm_puts_ploop_end:365 366 /* Write bits 8 - 15 of the cursor address */367 movw $0x3d4, %dx368 movb $0xe, %al369 outb %al, %dx370 371 movw $0x3d5, %dx372 movb %bh, %al373 outb %al, %dx374 375 /* Write bits 0 - 7 of the cursor address */376 movw $0x3d4, %dx377 movb $0xf, %al378 outb %al, %dx379 380 movw $0x3d5, %dx381 movb %bl, %al382 outb %al, %dx383 384 popl %edi385 popl %edx386 popl %ecx387 popl %ebx388 popl %eax389 390 ret391 392 /** Print string to EGA display.393 *394 * Should be called from 32 bit protected mode (with paging395 * enabled and stack established). This function is ABI compliant.396 *397 * If CONFIG_EGA is undefined or CONFIG_FB is defined398 * then this function does nothing.399 *400 * @param %ebp+0x08 NULL-terminated string to print.401 *402 */403 early_puts:404 405 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))406 407 /* Prologue, save preserved registers */408 pushl %ebp409 movl %esp, %ebp410 pushl %ebx411 pushl %esi412 pushl %edi413 414 movl 0x08(%ebp), %esi415 movl $(PA2KA(0xb8000)), %edi /* base of EGA text mode memory */416 xorl %eax, %eax417 418 /* Read bits 8 - 15 of the cursor address */419 movw $0x3d4, %dx420 movb $0xe, %al421 outb %al, %dx422 423 movw $0x3d5, %dx424 inb %dx, %al425 shl $8, %ax426 427 /* Read bits 0 - 7 of the cursor address */428 movw $0x3d4, %dx429 movb $0xf, %al430 outb %al, %dx431 432 movw $0x3d5, %dx433 inb %dx, %al434 435 /* Sanity check for the cursor on screen */436 cmp $2000, %ax437 jb early_puts_cursor_ok438 439 movw $1998, %ax440 441 early_puts_cursor_ok:442 443 movw %ax, %bx444 shl $1, %eax445 addl %eax, %edi446 447 early_puts_ploop:448 lodsb449 450 cmp $0, %al451 je early_puts_ploop_end452 453 movb $0x0e, %ah /* black background, yellow foreground */454 stosw455 456 /* Sanity check for the cursor on the last line */457 inc %bx458 cmp $2000, %bx459 jb early_puts_ploop460 461 /* Scroll the screen (24 rows) */462 movl %esi, %edx463 movl $(PA2KA(0xb80a0)), %esi464 movl $(PA2KA(0xb8000)), %edi465 movl $1920, %ecx466 rep movsw467 468 /* Clear the 24th row */469 xorl %eax, %eax470 movl $80, %ecx471 rep stosw472 473 /* Go to row 24 */474 movl %edx, %esi475 movl $(PA2KA(0xb8f00)), %edi476 movw $1920, %bx477 478 jmp early_puts_ploop479 early_puts_ploop_end:480 481 /* Write bits 8 - 15 of the cursor address */482 movw $0x3d4, %dx483 movb $0xe, %al484 outb %al, %dx485 486 movw $0x3d5, %dx487 movb %bh, %al488 outb %al, %dx489 490 /* Write bits 0 - 7 of the cursor address */491 movw $0x3d4, %dx492 movb $0xf, %al493 outb %al, %dx494 495 movw $0x3d5, %dx496 movb %bl, %al497 outb %al, %dx498 499 /* Epilogue, restore preserved registers */500 popl %edi501 popl %esi502 popl %ebx503 leave504 505 #endif506 507 ret508 509 206 #include "vesa_real.inc" 510 207 … … 521 218 .long 0 522 219 523 err_pse:220 pse_msg: 524 221 .asciz "Page Size Extension not supported. System halted." 525 222 526 status_prot:527 .asciz "[prot] "528 status_vesa_copy:529 .asciz "[vesa_copy] "530 status_grub_cmdline:531 .asciz "[grub_cmdline] "532 status_vesa_real:533 .asciz "[vesa_real] "534 status_prot2:535 .asciz "[prot2] "536 status_main:537 .asciz "[main] "
Note:
See TracChangeset
for help on using the changeset viewer.