2 #include "config_gdt.h"
6 #define OFFS(x) ((x)-(_tramp_mp_entry))
17 #define CPU_NR_COUNTER (config_num_ap_cpus)
19 .section .mp_tramp , "awx", @progbits
24 .global _tramp_mp_entry
27 /* Basic setup of the processor (stack not yet needed) */
34 /* Switch to protected mode (needed to read APIC-ID) */
35 lgdtl OFFS(_tramp_mp_init_gdt_pdesc)
39 ljmpl $0x08, $PHYS(_tramp_mp_entry32)
46 /* Initialize paging, needs linear mapping of this page! (first 4MB are linear mapped, due to lucky cirumstances) */
47 movl PHYS(_tramp_mp_startup_pdbr), %eax
49 // Initialize cr4 before, because we may run on a 4MB-page and need the extension enabled before
50 movl PHYS(_tramp_mp_startup_cr4), %eax
61 movl PHYS(_tramp_mp_startup_cr0), %eax
64 ljmpl $0x18, $PHYS(_tramp_mp_entry64)
68 jmp *PHYS(_ptr_64virt)
76 /* Reinitialize the gdt, reloads segments with kernel values */
77 lgdt PHYS(_tramp_mp_startup_gdt_pdesc)
79 movl PHYS(_tramp_mp_startup_cr0), %eax
81 ljmp $GDT_CODE_KERNEL, $1f
82 1: movw $GDT_DATA_KERNEL, %ax
89 /* Increase CPU counter */
90 1: mov CPU_NR_COUNTER, %eax
93 lock ; cmpxchg %edi, CPU_NR_COUNTER
96 /* Acquire spinlock */
97 1: cmpl $0, _tramp_mp_spinlock
102 xchg _tramp_mp_spinlock, %CX
106 /* we've the lock, can run on the init_stack */
107 mov $_tramp_mp_init_stack_top, %SP
108 mov %edi, %eax /* IA32: cpu-num in %eax, AMD64: %rdi */
114 * Pseudo_descriptor for the initial GDT
117 _tramp_mp_init_gdt_pdesc:
119 .long PHYS(_tramp_mp_init_gdt)
123 * Initial GDT, used for switch to protected mode, will be
124 * used only until startup sequence (from this point we use
125 * the OS provided GDT).
129 .long 0x00000000, 0x00000000 /* dummy */
130 .long 0x0000FFFF, 0x00CF9A00 /* r-x/0..4GB/PL0/32bit */
131 .long 0x0000FFFF, 0x00CF9200 /* rw-/0..4GB/PL0/32bit */
132 .long 0x0000FFFF, 0x00AF9B00 /* r-x/0..4GB/PL0/64bit */
134 .global _tramp_mp_startup_cr0
135 _tramp_mp_startup_cr0:
138 .global _tramp_mp_startup_cr4
139 _tramp_mp_startup_cr4:
142 .global _tramp_mp_startup_pdbr
143 _tramp_mp_startup_pdbr:
146 .global _tramp_mp_startup_gdt_pdesc
147 _tramp_mp_startup_gdt_pdesc:
152 .global _tramp_mp_spinlock
157 _tramp_mp_init_stack:
159 /* glibc *printf-functions */
164 _tramp_mp_init_stack_top: