Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/amd64/mpboot.S
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | jmp_32: | ||||
/* | /* | ||||
* At this point, we are running in 32 bit legacy protected mode. | * At this point, we are running in 32 bit legacy protected mode. | ||||
*/ | */ | ||||
.code32 | .code32 | ||||
protmode: | protmode: | ||||
mov $bootdata-gdt, %eax | mov $bootdata-gdt, %eax | ||||
mov %ax, %ds | mov %ax, %ds | ||||
/* Turn on the PAE bit for when paging is enabled */ | /* Turn on the PAE and optionally LA57 bit for when paging is enabled */ | ||||
alc: See earlier comment. | |||||
mov %cr4, %eax | mov %cr4, %eax | ||||
orl $CR4_PAE, %eax | orl $CR4_PAE, %eax | ||||
mov %eax, %cr4 | cmpb $0, mptramp_la57-mptramp_start(%ebx) | ||||
je 1f | |||||
orl $CR4_LA57, %eax | |||||
1: mov %eax, %cr4 | |||||
/* | /* | ||||
* Enable EFER.LME so that we get long mode when all the prereqs are | * Enable EFER.LME so that we get long mode when all the prereqs are | ||||
* in place. In this case, it turns on when CR0_PG is finally enabled. | * in place. In this case, it turns on when CR0_PG is finally enabled. | ||||
* Pick up a few other EFER bits that we'll use need we're here. | * Pick up a few other EFER bits that we'll use need we're here. | ||||
*/ | */ | ||||
movl $MSR_EFER, %ecx | movl $MSR_EFER, %ecx | ||||
rdmsr | rdmsr | ||||
Show All 22 Lines | 1: mov %eax, %cr4 | ||||
*/ | */ | ||||
mov %cr0, %eax | mov %cr0, %eax | ||||
orl $CR0_PG, %eax | orl $CR0_PG, %eax | ||||
mov %eax, %cr0 | mov %eax, %cr0 | ||||
/* | /* | ||||
* At this point paging is enabled, and we are in "compatibility" mode. | * At this point paging is enabled, and we are in "compatibility" mode. | ||||
* We do another far jump to reload %cs with the 64 bit selector. | * We do another far jump to reload %cs with the 64 bit selector. | ||||
* %cr3 points to a 4-level page table page. | * %cr3 points to a 4- or 5-level page table page. | ||||
Done Inline ActionsDrop the final "page" from this sentence. alc: Drop the final "page" from this sentence. | |||||
* We cannot yet jump all the way to the kernel because we can only | * We cannot yet jump all the way to the kernel because we can only | ||||
* specify a 32 bit linear address. So, yet another trampoline. | * specify a 32 bit linear address. So, yet another trampoline. | ||||
Done Inline Actions"So, we use yet another ..." alc: "So, we use yet another ..." | |||||
* | * | ||||
* The following instruction is: | * The following instruction is: | ||||
* ljmp $kernelcode-gdt, $tramp_64-mptramp_start | * ljmp $kernelcode-gdt, $tramp_64-mptramp_start | ||||
* but gas cannot assemble that. And besides, we patch the targets | * but gas cannot assemble that. And besides, we patch the targets | ||||
* in early startup and its a little clearer what we are patching. | * in early startup and its a little clearer what we are patching. | ||||
*/ | */ | ||||
jmp_64: | jmp_64: | ||||
.byte 0xea /* opcode for far jump */ | .byte 0xea /* opcode for far jump */ | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | gdtend: | ||||
/* | /* | ||||
* The address of our page table pages that the boot code | * The address of our page table pages that the boot code | ||||
* uses to trampoline up to kernel address space. | * uses to trampoline up to kernel address space. | ||||
*/ | */ | ||||
.globl mptramp_pagetables | .globl mptramp_pagetables | ||||
mptramp_pagetables: | mptramp_pagetables: | ||||
.long 0 | .long 0 | ||||
/* 5-level paging ? */ | |||||
.globl mptramp_la57 | |||||
mptramp_la57: | |||||
.long 0 | |||||
/* | /* | ||||
* The pseudo descriptor for lgdt to use. | * The pseudo descriptor for lgdt to use. | ||||
*/ | */ | ||||
lgdt_desc: | lgdt_desc: | ||||
.word gdtend-gdt /* Length */ | .word gdtend-gdt /* Length */ | ||||
.long gdt-mptramp_start /* Offset plus %ds << 4 */ | .long gdt-mptramp_start /* Offset plus %ds << 4 */ | ||||
mptramp_end: | mptramp_end: | ||||
Show All 26 Lines | entry_64: | ||||
orl $EFER_NXE, %eax | orl $EFER_NXE, %eax | ||||
wrmsr | wrmsr | ||||
1: | 1: | ||||
/* | /* | ||||
* Load a real %cr3 that has all the direct map stuff and switches | * Load a real %cr3 that has all the direct map stuff and switches | ||||
* off the 1GB replicated mirror. Load a stack pointer and jump | * off the 1GB replicated mirror. Load a stack pointer and jump | ||||
* into AP startup code in C. | * into AP startup code in C. | ||||
*/ | */ | ||||
cmpl $0, la57 | |||||
jne 2f | |||||
movq KPML4phys, %rax | movq KPML4phys, %rax | ||||
movq %rax, %cr3 | jmp 3f | ||||
2: movq KPML5phys, %rax | |||||
3: movq %rax, %cr3 | |||||
movq bootSTK, %rsp | movq bootSTK, %rsp | ||||
jmp init_secondary | jmp init_secondary |
See earlier comment.