1 2#include "apic-defs.h" 3 4.globl online_cpus 5 6ipi_vector = 0x20 7 8max_cpus = MAX_TEST_CPUS 9 10.bss 11 12 . = . + 4096 * max_cpus 13 .align 16 14stacktop: 15 16.data 17 18.align 4096 19ptl2: 20i = 0 21 .rept 512 * 4 22 .quad 0x1e7 | (i << 21) 23 i = i + 1 24 .endr 25 26.align 4096 27ptl3: 28 .quad ptl2 + 7 + 0 * 4096 29 .quad ptl2 + 7 + 1 * 4096 30 .quad ptl2 + 7 + 2 * 4096 31 .quad ptl2 + 7 + 3 * 4096 32 33.align 4096 34ptl4: 35 .quad ptl3 + 7 36 37.align 4096 38ptl5: 39 .quad ptl4 + 7 40 41.align 4096 42 43mb_boot_info: .quad 0 44 45pt_root: .quad ptl4 46 47#include "trampolines.S" 48 49.section .init 50.code32 51 52mb_magic = 0x1BADB002 53mb_flags = 0x0 54 55 # multiboot header 56 .long mb_magic, mb_flags, 0 - (mb_magic + mb_flags) 57mb_cmdline = 16 58 59.macro load_tss 60 movq %rsp, %rdi 61 call setup_tss 62 ltr %ax 63.endm 64 65.globl start 66start: 67 mov %ebx, mb_boot_info 68 mov $stacktop, %esp 69 setup_percpu_area 70 call prepare_64 71 jmpl $8, $start64 72 73switch_to_5level: 74 /* Disable CR4.PCIDE */ 75 mov %cr4, %eax 76 btr $17, %eax 77 mov %eax, %cr4 78 79 mov %cr0, %eax 80 btr $31, %eax 81 mov %eax, %cr0 82 83 mov $ptl5, %eax 84 mov %eax, pt_root 85 86 /* Enable CR4.LA57 */ 87 mov %cr4, %eax 88 bts $12, %eax 89 mov %eax, %cr4 90 91 mov $0x10, %ax 92 mov %ax, %ss 93 94 call enter_long_mode 95 jmpl $8, $lvl5 96 97smp_stacktop: .long stacktop - 4096 98 99.align 16 100 101gdt32: 102 .quad 0 103 .quad 0x00cf9b000000ffff // flat 32-bit code segment 104 .quad 0x00cf93000000ffff // flat 32-bit data segment 105gdt32_end: 106 107.code64 108save_id: 109 movl $(APIC_DEFAULT_PHYS_BASE + APIC_ID), %eax 110 movl (%rax), %eax 111 shrl $24, %eax 112 lock btsl %eax, online_cpus 113 retq 114 115ap_start64: 116 call load_idt 117 load_tss 118 call reset_apic 119 call enable_apic 120 call save_id 121 call enable_x2apic 122 sti 123 nop 124 lock incw cpu_online_count 125 1261: hlt 127 jmp 1b 128 129start64: 130 call load_idt 131 load_tss 132 call reset_apic 133 call mask_pic_interrupts 134 call enable_apic 135 call save_id 136 mov mb_boot_info(%rip), %rbx 137 mov %rbx, %rdi 138 call setup_multiboot 139 call setup_libcflat 140 mov mb_cmdline(%rbx), %eax 141 mov %rax, __args(%rip) 142 call __setup_args 143 144 call ap_init 145 call enable_x2apic 146 call smp_init 147 148 mov __argc(%rip), %edi 149 lea __argv(%rip), %rsi 150 lea __environ(%rip), %rdx 151 call main 152 mov %eax, %edi 153 call exit 154 155.globl setup_5level_page_table 156setup_5level_page_table: 157 /* Check if 5-level paging has already enabled */ 158 mov %cr4, %rax 159 test $0x1000, %eax 160 jnz lvl5 161 162 pushq $32 163 pushq $switch_to_5level 164 lretq 165lvl5: 166 retq 167 168online_cpus: 169 .fill (max_cpus + 7) / 8, 1, 0 170