Changeset a35b458 in mainline for kernel/arch/amd64/src/boot/multiboot.S
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/boot/multiboot.S
r3061bc1 ra35b458 78 78 cli 79 79 cld 80 80 81 81 /* Initialize stack pointer */ 82 82 movl $START_STACK, %esp 83 83 84 84 /* 85 85 * Initialize Global Descriptor Table and … … 88 88 lgdtl bootstrap_gdtr 89 89 lidtl bootstrap_idtr 90 90 91 91 /* Kernel data + stack */ 92 92 movw $GDT_SELECTOR(KDATA_DES), %cx … … 94 94 movw %cx, %ds 95 95 movw %cx, %ss 96 96 97 97 /* 98 98 * Simics seems to remove hidden part of GS on entering user mode … … 102 102 movw %cx, %fs 103 103 movw %cx, %gs 104 104 105 105 jmpl $GDT_SELECTOR(KTEXT32_DES), $multiboot_meeting_point 106 106 multiboot_meeting_point: 107 107 108 108 /* 109 109 * Protected 32-bit. We want to reuse the code-seg descriptor, 110 110 * the Default operand size must not be 1 when entering long mode. 111 111 */ 112 112 113 113 /* Save multiboot arguments */ 114 114 movl %eax, multiboot_eax 115 115 movl %ebx, multiboot_ebx 116 116 117 117 pm_status $status_prot 118 118 119 119 movl $(INTEL_CPUID_EXTENDED), %eax 120 120 cpuid 121 121 cmp $(INTEL_CPUID_EXTENDED), %eax 122 122 ja extended_cpuid_supported 123 123 124 124 pm_error $err_extended_cpuid 125 125 126 126 extended_cpuid_supported: 127 127 128 128 movl $(AMD_CPUID_EXTENDED), %eax 129 129 cpuid 130 130 bt $(AMD_EXT_LONG_MODE), %edx 131 131 jc long_mode_supported 132 132 133 133 pm_error $err_long_mode 134 134 135 135 long_mode_supported: 136 136 137 137 bt $(AMD_EXT_NOEXECUTE), %edx 138 138 jc noexecute_supported 139 139 140 140 pm_error $err_noexecute 141 141 142 142 noexecute_supported: 143 143 144 144 movl $(INTEL_CPUID_STANDARD), %eax 145 145 cpuid 146 146 bt $(INTEL_FXSAVE), %edx 147 147 jc fx_supported 148 148 149 149 pm_error $err_fx 150 150 151 151 fx_supported: 152 152 153 153 bt $(INTEL_SSE2), %edx 154 154 jc sse2_supported 155 155 156 156 pm_error $err_sse2 157 157 158 158 sse2_supported: 159 159 160 160 #include "vesa_prot.inc" 161 161 162 162 pm2_status $status_prot2 163 163 164 164 /* 165 165 * Enable 64-bit page translation entries - CR4.PAE = 1. 166 166 * Paging is not enabled until after long mode is enabled. 167 167 */ 168 168 169 169 movl %cr4, %eax 170 170 orl $CR4_PAE, %eax 171 171 movl %eax, %cr4 172 172 173 173 /* Set up paging tables */ 174 174 leal ptl_0, %eax 175 175 movl %eax, %cr3 176 176 177 177 /* Enable long mode */ 178 178 movl $AMD_MSR_EFER, %ecx … … 180 180 orl $AMD_LME, %eax /* set LME = 1 */ 181 181 wrmsr 182 182 183 183 /* Enable paging to activate long mode (set CR0.PG = 1) */ 184 184 movl %cr0, %eax 185 185 orl $CR0_PG, %eax 186 186 movl %eax, %cr0 187 187 188 188 /* At this point we are in compatibility mode */ 189 189 jmpl $GDT_SELECTOR(KTEXT_DES), $start64 … … 204 204 movl $0xb8000, %edi /* base of EGA text mode memory */ 205 205 xorl %eax, %eax 206 206 207 207 /* Read bits 8 - 15 of the cursor address */ 208 208 movw $0x3d4, %dx 209 209 movb $0xe, %al 210 210 outb %al, %dx 211 211 212 212 movw $0x3d5, %dx 213 213 inb %dx, %al 214 214 shl $8, %ax 215 215 216 216 /* Read bits 0 - 7 of the cursor address */ 217 217 movw $0x3d4, %dx 218 218 movb $0xf, %al 219 219 outb %al, %dx 220 220 221 221 movw $0x3d5, %dx 222 222 inb %dx, %al 223 223 224 224 /* Sanity check for the cursor on screen */ 225 225 cmp $2000, %ax 226 226 jb err_cursor_ok 227 227 228 228 movw $1998, %ax 229 229 230 230 err_cursor_ok: 231 231 232 232 movw %ax, %bx 233 233 shl $1, %eax 234 234 addl %eax, %edi 235 235 236 236 err_ploop: 237 237 lodsb 238 238 239 239 cmp $0, %al 240 240 je err_ploop_end 241 241 242 242 movb $0x0c, %ah /* black background, light red foreground */ 243 243 stosw 244 244 245 245 /* Sanity check for the cursor on the last line */ 246 246 inc %bx 247 247 cmp $2000, %bx 248 248 jb err_ploop 249 249 250 250 /* Scroll the screen (24 rows) */ 251 251 movl %esi, %edx … … 254 254 movl $960, %ecx 255 255 rep movsl 256 256 257 257 /* Clear the 24th row */ 258 258 xorl %eax, %eax 259 259 movl $40, %ecx 260 260 rep stosl 261 261 262 262 /* Go to row 24 */ 263 263 movl %edx, %esi 264 264 movl $0xb8f00, %edi 265 265 movw $1920, %bx 266 266 267 267 jmp err_ploop 268 268 err_ploop_end: 269 269 270 270 /* Write bits 8 - 15 of the cursor address */ 271 271 movw $0x3d4, %dx 272 272 movb $0xe, %al 273 273 outb %al, %dx 274 274 275 275 movw $0x3d5, %dx 276 276 movb %bh, %al 277 277 outb %al, %dx 278 278 279 279 /* Write bits 0 - 7 of the cursor address */ 280 280 movw $0x3d4, %dx 281 281 movb $0xf, %al 282 282 outb %al, %dx 283 283 284 284 movw $0x3d5, %dx 285 285 movb %bl, %al 286 286 outb %al, %dx 287 287 288 288 cli 289 289 hlt1: … … 311 311 pushl %edx 312 312 pushl %edi 313 313 314 314 movl $0xb8000, %edi /* base of EGA text mode memory */ 315 315 xorl %eax, %eax 316 316 317 317 /* Read bits 8 - 15 of the cursor address */ 318 318 movw $0x3d4, %dx 319 319 movb $0xe, %al 320 320 outb %al, %dx 321 321 322 322 movw $0x3d5, %dx 323 323 inb %dx, %al 324 324 shl $8, %ax 325 325 326 326 /* Read bits 0 - 7 of the cursor address */ 327 327 movw $0x3d4, %dx 328 328 movb $0xf, %al 329 329 outb %al, %dx 330 330 331 331 movw $0x3d5, %dx 332 332 inb %dx, %al 333 333 334 334 /* Sanity check for the cursor on screen */ 335 335 cmp $2000, %ax 336 336 jb pm_puts_cursor_ok 337 337 338 338 movw $1998, %ax 339 339 340 340 pm_puts_cursor_ok: 341 341 342 342 movw %ax, %bx 343 343 shl $1, %eax 344 344 addl %eax, %edi 345 345 346 346 pm_puts_ploop: 347 347 lodsb 348 348 349 349 cmp $0, %al 350 350 je pm_puts_ploop_end 351 351 352 352 movb $0x0a, %ah /* black background, light green foreground */ 353 353 stosw 354 354 355 355 /* Sanity check for the cursor on the last line */ 356 356 inc %bx 357 357 cmp $2000, %bx 358 358 jb pm_puts_ploop 359 359 360 360 /* Scroll the screen (24 rows) */ 361 361 movl %esi, %edx … … 364 364 movl $960, %ecx 365 365 rep movsl 366 366 367 367 /* Clear the 24th row */ 368 368 xorl %eax, %eax 369 369 movl $40, %ecx 370 370 rep stosl 371 371 372 372 /* Go to row 24 */ 373 373 movl %edx, %esi 374 374 movl $0xb8f00, %edi 375 375 movw $1920, %bx 376 376 377 377 jmp pm_puts_ploop 378 378 pm_puts_ploop_end: 379 379 380 380 /* Write bits 8 - 15 of the cursor address */ 381 381 movw $0x3d4, %dx 382 382 movb $0xe, %al 383 383 outb %al, %dx 384 384 385 385 movw $0x3d5, %dx 386 386 movb %bh, %al 387 387 outb %al, %dx 388 388 389 389 /* Write bits 0 - 7 of the cursor address */ 390 390 movw $0x3d4, %dx 391 391 movb $0xf, %al 392 392 outb %al, %dx 393 393 394 394 movw $0x3d5, %dx 395 395 movb %bl, %al 396 396 outb %al, %dx 397 397 398 398 popl %edi 399 399 popl %edx … … 401 401 popl %ebx 402 402 popl %eax 403 403 404 404 ret 405 405 … … 414 414 415 415 start64: 416 416 417 417 /* 418 418 * Long mode. 419 419 */ 420 420 421 421 movq $(PA2KA(START_STACK)), %rsp 422 422 423 423 /* Create the first stack frame */ 424 424 pushq $0 425 425 movq %rsp, %rbp 426 426 427 427 long_status $status_long 428 428 429 429 /* Call amd64_pre_main(multiboot_eax, multiboot_ebx) */ 430 430 movl multiboot_eax, %edi 431 431 movl multiboot_ebx, %esi 432 432 433 433 #ifdef MEMORY_MODEL_large 434 434 movabsq $amd64_pre_main, %rax … … 437 437 callq amd64_pre_main 438 438 #endif 439 439 440 440 long_status $status_main 441 441 442 442 /* Call main_bsp() */ 443 443 #ifdef MEMORY_MODEL_large … … 447 447 callq main_bsp 448 448 #endif 449 449 450 450 /* Not reached */ 451 451 cli … … 468 468 */ 469 469 early_puts: 470 470 471 471 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 472 472 473 473 /* Prologue, save preserved registers */ 474 474 pushq %rbp 475 475 movq %rsp, %rbp 476 476 pushq %rbx 477 477 478 478 movq %rdi, %rsi 479 479 movq $(PA2KA(0xb8000)), %rdi /* base of EGA text mode memory */ 480 480 xorq %rax, %rax 481 481 482 482 /* Read bits 8 - 15 of the cursor address */ 483 483 movw $0x3d4, %dx 484 484 movb $0xe, %al 485 485 outb %al, %dx 486 486 487 487 movw $0x3d5, %dx 488 488 inb %dx, %al 489 489 shl $8, %ax 490 490 491 491 /* Read bits 0 - 7 of the cursor address */ 492 492 movw $0x3d4, %dx 493 493 movb $0xf, %al 494 494 outb %al, %dx 495 495 496 496 movw $0x3d5, %dx 497 497 inb %dx, %al 498 498 499 499 /* Sanity check for the cursor on screen */ 500 500 cmp $2000, %ax 501 501 jb early_puts_cursor_ok 502 502 503 503 movw $1998, %ax 504 504 505 505 early_puts_cursor_ok: 506 506 507 507 movw %ax, %bx 508 508 shl $1, %rax 509 509 addq %rax, %rdi 510 510 511 511 early_puts_ploop: 512 512 lodsb 513 513 514 514 cmp $0, %al 515 515 je early_puts_ploop_end 516 516 517 517 movb $0x0e, %ah /* black background, yellow foreground */ 518 518 stosw 519 519 520 520 /* Sanity check for the cursor on the last line */ 521 521 inc %bx 522 522 cmp $2000, %bx 523 523 jb early_puts_ploop 524 524 525 525 /* Scroll the screen (24 rows) */ 526 526 movq %rsi, %rdx … … 529 529 movl $480, %ecx 530 530 rep movsq 531 531 532 532 /* Clear the 24th row */ 533 533 xorl %eax, %eax 534 534 movl $20, %ecx 535 535 rep stosq 536 536 537 537 /* Go to row 24 */ 538 538 movq %rdx, %rsi 539 539 movq $(PA2KA(0xb8f00)), %rdi 540 540 movw $1920, %bx 541 541 542 542 jmp early_puts_ploop 543 543 early_puts_ploop_end: 544 544 545 545 /* Write bits 8 - 15 of the cursor address */ 546 546 movw $0x3d4, %dx 547 547 movb $0xe, %al 548 548 outb %al, %dx 549 549 550 550 movw $0x3d5, %dx 551 551 movb %bh, %al 552 552 outb %al, %dx 553 553 554 554 /* Write bits 0 - 7 of the cursor address */ 555 555 movw $0x3d4, %dx 556 556 movb $0xf, %al 557 557 outb %al, %dx 558 558 559 559 movw $0x3d5, %dx 560 560 movb %bl, %al 561 561 outb %al, %dx 562 562 563 563 /* Epilogue, restore preserved registers */ 564 564 popq %rbx 565 565 leave 566 566 567 567 #endif 568 568 569 569 ret 570 570
Note:
See TracChangeset
for help on using the changeset viewer.