Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/x86/smp_x86.S # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / x86 / smp_x86.S` 107 lines ยท 3645 bytes Raw Blame History 1 /* smp_x86.S -- the start-up trampoline for the secondary cores of 2 * AIENOS-IMAC-KERNEL-1 (native/kernel/x86). 3 * 4 * kmain_x86.c copies ck_x86_tramp_start..ck_x86_tramp_end to a page below 5 * 1 MiB, fills the patch slots (GDTR base, the two far-jump targets, CR3, 6 * stack, entry, argument) with absolute addresses for that page, and sends 7 * INIT, SIPI, SIPI with the page number as the vector. A core then starts 8 * here in real mode at CS = page >> 4, IP = 0, and walks: 16-bit -> 32-bit 9 * protected mode (the trampoline's own flat GDT) -> PAE + the kernel's page 10 * tables + EFER.LME/NXE + paging and CR0.WP -> 64-bit, then calls entry(arg) 11 * on its own stack (-mabi=ms: the argument in rcx, 32 bytes of shadow space). 12 * If entry returns, the core halts with interrupts off. Once paging is on the 13 * page is read-only executable (W^X, kmain_x86.c tramp_prot), so the GDT 14 * descriptors carry their accessed bit already: the CPU never writes them. */ 15 16 .text 17 .globl ck_x86_tramp_start, ck_x86_tramp_end 18 .globl ck_x86_tramp_gdtr, ck_x86_tramp_far32, ck_x86_tramp_far64 19 .globl ck_x86_tramp_cr3, ck_x86_tramp_stack, ck_x86_tramp_entry, ck_x86_tramp_arg 20 .p2align 12 21 .code16 22 ck_x86_tramp_start: 23 cli 24 cld 25 mov %cs, %ax 26 mov %ax, %ds 27 xor %ebx, %ebx 28 mov %cs, %bx 29 shl $4, %ebx /* ebx = linear address of the page */ 30 lgdtl ck_x86_tramp_gdtr - ck_x86_tramp_start 31 mov %cr0, %eax 32 or $1, %eax 33 mov %eax, %cr0 34 ljmpl *(ck_x86_tramp_far32 - ck_x86_tramp_start) 35 36 .code32 37 tramp_pm32: 38 mov $0x10, %ax 39 mov %ax, %ds 40 mov %ax, %es 41 mov %ax, %ss 42 mov %cr4, %eax 43 or $0x20, %eax /* PAE */ 44 mov %eax, %cr4 45 mov (ck_x86_tramp_cr3 - ck_x86_tramp_start)(%ebx), %eax 46 mov %eax, %cr3 47 mov $0xc0000080, %ecx /* EFER */ 48 rdmsr 49 or $0x900, %eax /* LME + NXE: the kernel's tables carry NX bits */ 50 wrmsr 51 mov %cr0, %eax 52 #ifdef CK_X86_WX_MUTANT_AP_NO_WP 53 or $0x80000000, %eax /* TEST-ONLY mutant (#484): PG without WP on the AP */ 54 #else 55 or $0x80010000, %eax /* PG + WP: read-only pages bind this core too */ 56 #endif 57 mov %eax, %cr0 58 ljmpl *(ck_x86_tramp_far64 - ck_x86_tramp_start)(%ebx) 59 60 .code64 61 tramp_lm64: 62 mov %ebx, %ebx /* zero the upper half */ 63 mov $0x10, %ax 64 mov %ax, %ds 65 mov %ax, %es 66 mov %ax, %ss 67 mov (ck_x86_tramp_stack - ck_x86_tramp_start)(%rbx), %rsp 68 mov (ck_x86_tramp_arg - ck_x86_tramp_start)(%rbx), %rcx 69 mov (ck_x86_tramp_entry - ck_x86_tramp_start)(%rbx), %rax 70 sub $32, %rsp 71 call *%rax 72 1: cli 73 hlt 74 jmp 1b 75 76 .p2align 3 77 tramp_gdt: 78 .quad 0 79 .quad 0x00cf9b000000ffff /* 0x08: 32-bit code, accessed */ 80 .quad 0x00cf93000000ffff /* 0x10: data, accessed */ 81 .quad 0x00209b0000000000 /* 0x18: 64-bit code, accessed */ 82 ck_x86_tramp_gdtr: 83 .word 31 84 .long 0 /* page + (tramp_gdt - start) */ 85 .p2align 2 86 ck_x86_tramp_far32: 87 .long 0 /* page + (tramp_pm32 - start) */ 88 .word 0x08 89 .p2align 2 90 ck_x86_tramp_far64: 91 .long 0 /* page + (tramp_lm64 - start) */ 92 .word 0x18 93 .p2align 2 94 ck_x86_tramp_cr3: 95 .long 0 96 .p2align 3 97 ck_x86_tramp_stack: 98 .quad 0 99 ck_x86_tramp_entry: 100 .quad 0 101 ck_x86_tramp_arg: 102 .quad 0 103 .globl ck_x86_tramp_gdt, ck_x86_tramp_pm32, ck_x86_tramp_lm64 104 .set ck_x86_tramp_gdt, tramp_gdt 105 .set ck_x86_tramp_pm32, tramp_pm32 106 .set ck_x86_tramp_lm64, tramp_lm64 107 ck_x86_tramp_end: