From bf20ce47a9d5dcad841e4549a68f4ec3db3c57de Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Wed, 1 Feb 2023 04:00:48 +0100 Subject: AP -> long mode; testing mutex --- kernel/src/scheduler/ap_init.S | 69 +++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'kernel/src/scheduler/ap_init.S') diff --git a/kernel/src/scheduler/ap_init.S b/kernel/src/scheduler/ap_init.S index 8cb4314..17cffab 100644 --- a/kernel/src/scheduler/ap_init.S +++ b/kernel/src/scheduler/ap_init.S @@ -6,34 +6,34 @@ .SET bspdone, 0x3000100 .SET aprunning, 0x3000200 -# this code will be relocated to 0x8000, sets up environment for calling a C function .code16 ap_trampoline: cli cld - ljmp $0, $0x8040 + ljmp $0, $_start16 .align 16 -_L8010_GDT_table: +gdt32: .long 0, 0 .long 0x0000FFFF, 0x00CF9A00 # flat code .long 0x0000FFFF, 0x008F9200 # flat data .long 0x00000068, 0x00CF8900 # tss -_L8030_GDT_value: - .word _L8030_GDT_value - _L8010_GDT_table - 1 +gdt32p: + .word gdt32p - gdt32 - 1 .long 0x8010 .long 0, 0 .align 64 -_L8040: +_start16: xorw %ax, %ax movw %ax, %ds - lgdtl 0x8030 + lgdtl gdt32p movl %cr0, %eax orl $1, %eax movl %eax, %cr0 - ljmp $8, $0x8060 - .align 32 - .code32 -_L8060: + ljmp $8, $_start32 + +.align 32 +.code32 +_start32: movw $16, %ax movw %ax, %ds movw %ax, %ss @@ -46,26 +46,45 @@ _L8060: # set up 32k stack, one for each core. It is important that all core must have its own stack movl $stack_top, %esp - mov %edi, %ecx -2: + movl %ebx, %ecx +22: addl $stack_off, %esp decl %ecx cmp $0, %ecx - jne 2b + jne 22b + - shll $15, %ebx - subl %ebx, %esp - pushl %edi - # spinlock, wait for the BSP to finish -1: +# spinlock, wait for the BSP to finish +11: pause cmpb $0, bspdone - jz 1b - lock incb aprunning + jz 11b + + call enable_paging + lgdt gdtp -3: - hlt - jmp 3b # jump into C code (should never return) - # ljmp $8, $ap_startup + ljmp $8, $_start64 + +.set KERNEL_VMA, 0xffffffff80000000 + +.align 64 +.code64 +_start64: + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %ss + mov %ax, %fs + mov %ax, %gs + + + add $KERNEL_VMA, %rsp + movabs $_higher_half, %rax + jmp *%rax + +.section .text +_higher_half: + lock incb aprunning + call ap_startup -- cgit v1.2.3