]> rtime.felk.cvut.cz Git - jailhouse.git/blobdiff - inmates/lib/x86/header.S
inmates: x86: Add basic SMP support
[jailhouse.git] / inmates / lib / x86 / header.S
index b178dc1a07fb7e64276f42f497b77a6a9bb6467d..af8e918504171e97af42fa71d048b425d38c06ba 100644 (file)
@@ -70,21 +70,62 @@ start32:
 
        .code64
 start64:
-       mov $stack_top,%rsp
+       xor %rbx,%rbx
+       xchg ap_entry,%rbx
+       or %rbx,%rbx
+       jnz call_entry
+
+       mov $1,%edi
+       lock xadd %edi,cpu_number + FSEGMENT_BASE
+
+       cmp $SMP_MAX_CPUS,%edi
+       jae stop
+
+       mov $0x01,%eax
+       cpuid
+       shr $24,%ebx
+       mov %bl,smp_cpu_ids(%edi)
+
+       lock incl smp_num_cpus
+
+       cmp $0,%edi
+       jne stop
 
        xor %rax,%rax
        mov $bss_start,%rdi
        mov $bss_qwords,%rcx
        rep stosq
 
-       mov $inmate_main,%rax
-       callq *%rax
+       mov $inmate_main,%rbx
+
+call_entry:
+       mov $stack_top,%rsp
+       callq *%rbx
 
 stop:  cli
        hlt
        jmp stop
 
 
+       .pushsection ".data"
+
+       .globl ap_entry
+ap_entry:
+       .quad   0
+
+       .globl smp_num_cpus
+smp_num_cpus:
+       .long   0
+
+       .globl smp_cpu_ids
+smp_cpu_ids:
+       .fill   SMP_MAX_CPUS, 1, 0
+
+       .popsection
+
+cpu_number:
+       .long   0
+
        .align(16)
 gdt:
        .quad   0