From 4fccb348e8405f4422352f331938ffba8d0a273d Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 7 Jun 2007 16:17:45 +0300 Subject: [PATCH] kvm: testsuite: extend smp boot to 64-bits --- kvm/user/Makefile | 4 +- kvm/user/test/cstart64.S | 112 ++++++++++++++++++++++++++++++++++++++--------- kvm/user/test/smp.c | 4 ++ 3 files changed, 97 insertions(+), 23 deletions(-) diff --git a/kvm/user/Makefile b/kvm/user/Makefile index a6cbaf6fab..140659a746 100644 --- a/kvm/user/Makefile +++ b/kvm/user/Makefile @@ -43,9 +43,9 @@ balloon_ctl: balloon_ctl.o libkvm.a: kvmctl.o $(AR) rcs $@ $^ -flatfiles-common = test/bootstrap test/vmexit.flat +flatfiles-common = test/bootstrap test/vmexit.flat test/smp.flat -flatfiles-32 = test/smp.flat +flatfiles-32 = flatfiles-64 = test/access.flat test/irq.flat test/sieve.flat test/simple.flat test/stringio.flat test/memtest1.flat diff --git a/kvm/user/test/cstart64.S b/kvm/user/test/cstart64.S index 5026d65124..9d6e7ba530 100644 --- a/kvm/user/test/cstart64.S +++ b/kvm/user/test/cstart64.S @@ -1,8 +1,15 @@ +#include "apic.h" + +boot_idt = 0 + +ipi_vector = 0x20 + +max_cpus = 4 .bss - . = . + 4096 + . = . + 4096 * max_cpus .align 16 stacktop: @@ -40,23 +47,34 @@ gdt64: .quad 0x00cf93000000ffff // 64-bit data segment .quad 0x00affb000000ffff // 64-bit code segment (user) .quad 0x00cff3000000ffff // 64-bit data segment (user) -tss_descr: +tss_descr: + .rept max_cpus .quad 0x000089000000ffff // 64-bit avail tss .quad 0 // tss high addr + .endr gdt64_end: +i = 0 tss: + .rept max_cpus .long 0 - .quad ring0stacktop + .quad ring0stacktop - i * 4096 .quad 0, 0, 0 .quad 0, 0, 0, 0, 0, 0, 0, 0 .long 0, 0, 0 - +i = i + 1 + .endr +tss_end: + .section .init .code32 + call prepare_64 + jmpl $8, $start64 + +prepare_64: lgdt gdt64_desc - + mov %cr4, %eax bts $5, %eax // pae mov %eax, %cr4 @@ -74,28 +92,80 @@ efer = 0xc0000080 bts $0, %eax bts $31, %eax mov %eax, %cr0 - - jmpl $8, $start64 + ret + + +smp_init_ipi: + call prepare_64 + jmpl $8, $ap_start64 .code64 -start64: +ap_start64: + call load_tss + sti + nop + +1: hlt + jmp 1b + +start64: lea stacktop, %rsp + + call load_tss + call smp_init + call main + +1: hlt + jmp 1b + +load_tss: mov $0, %eax mov %ax, %ss - - mov $tss, %rax - mov %ax, tss_descr+2 + mov $(APIC_BASE + APIC_REG_ID), %dx + in %dx, %eax + mov %eax, %ebx + shl $4, %ebx + mov $((tss_end - tss) / max_cpus), %edx + imul %edx + add $tss, %rax + mov %ax, tss_descr+2(%rbx) shr $16, %rax - mov %al, tss_descr+4 + mov %al, tss_descr+4(%rbx) shr $8, %rax - mov %al, tss_descr+7 + mov %al, tss_descr+7(%rbx) shr $8, %rax - mov %eax, tss_descr+8 - mov $(tss_descr-gdt64), %rax + mov %eax, tss_descr+8(%rbx) + lea tss_descr-gdt64(%rbx), %rax ltr %ax - - call main -1: // hlt - jmp 1b - - + ret + +smp_init: + lea boot_idt + ipi_vector * 8, %rdi + mov $smp_init_ipi, %eax + mov %ax, (%rdi) + mov %cs, %ax + mov %ax, 2(%rdi) + movw $0x8e00, 4(%rdi) + shr $16, %eax + mov %ax, 6(%rdi) + + mov $(APIC_BASE + APIC_REG_IPI_VECTOR), %dx + mov $ipi_vector, %eax + out %eax, %dx + + mov $(APIC_BASE + APIC_REG_NCPU), %dx + in %dx, %eax + mov %eax, %ecx + mov $1, %esi +smp_loop: + cmp %esi, %ecx + je smp_init_done + + mov $(APIC_BASE + APIC_REG_SEND_IPI), %dx + mov %esi, %eax + out %eax, %dx + + inc %esi + jmp smp_loop +smp_init_done: + ret diff --git a/kvm/user/test/smp.c b/kvm/user/test/smp.c index 2ec876792f..7cfee578c8 100644 --- a/kvm/user/test/smp.c +++ b/kvm/user/test/smp.c @@ -49,7 +49,11 @@ static __attribute__((used)) void ipi() asm ( "ipi_entry: \n" " call ipi \n" +#ifndef __x86_64__ " iret" +#else + " iretq" +#endif ); -- 2.11.4.GIT