# HG changeset patch # User kaf24@scramble.cl.cam.ac.uk # Date 1107538522 0 # Node ID 8c6281ec88605a788322d7e8ca0a2fbdf589075a # Parent 715c644ba9efd1b2ac80cad8192d6ce6fa6d1b92 bitkeeper revision 1.1159.212.87 (4203b25aTB_XSOA2G0yxgrj0ey-vIA) Defined per-CPU SYSCALL entry point for hypercalls. We enter the DOM0 kernel and can receive hypercalls. Now probably need to fix the user-access (uaccess.h) functions and macros. Signed-off-by: keir.fraser@cl.cam.ac.uk diff -r 715c644ba9ef -r 8c6281ec8860 xen/arch/x86/setup.c --- a/xen/arch/x86/setup.c Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/arch/x86/setup.c Fri Feb 04 17:35:22 2005 +0000 @@ -298,6 +298,7 @@ void __init identify_cpu(struct cpuinfo_ unsigned long cpu_initialized; void __init cpu_init(void) { + extern void percpu_traps_init(void); int nr = smp_processor_id(); struct tss_struct *t = &init_tss[nr]; @@ -335,6 +336,8 @@ void __init cpu_init(void) CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7); #undef CD + percpu_traps_init(); + /* Install correct page table. */ write_ptbase(¤t->mm); diff -r 715c644ba9ef -r 8c6281ec8860 xen/arch/x86/traps.c --- a/xen/arch/x86/traps.c Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/arch/x86/traps.c Fri Feb 04 17:35:22 2005 +0000 @@ -470,7 +470,7 @@ asmlinkage int do_general_protection(str unsigned long fixup; DEBUGGER_trap_entry(TRAP_gp_fault, regs); - + if ( regs->error_code & 1 ) goto hardware_gp; @@ -732,8 +732,6 @@ void __init trap_init(void) #if defined(__i386__) _set_gate(idt_table+HYPERCALL_VECTOR, 14, 1, &hypercall); -#elif defined(__x86_64__) - _set_gate(idt_table+HYPERCALL_VECTOR, 14, 3, &hypercall); #endif /* CPU0 uses the master IDT. */ diff -r 715c644ba9ef -r 8c6281ec8860 xen/arch/x86/x86_32/traps.c --- a/xen/arch/x86/x86_32/traps.c Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/arch/x86/x86_32/traps.c Fri Feb 04 17:35:22 2005 +0000 @@ -196,6 +196,10 @@ void __init doublefault_init(void) set_task_gate(TRAP_double_fault, __DOUBLEFAULT_TSS_ENTRY<<3); } +void __init percpu_traps_init(void) +{ +} + long set_fast_trap(struct exec_domain *p, int idx) { trap_info_t *ti; diff -r 715c644ba9ef -r 8c6281ec8860 xen/arch/x86/x86_64/entry.S --- a/xen/arch/x86/x86_64/entry.S Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/arch/x86/x86_64/entry.S Fri Feb 04 17:35:22 2005 +0000 @@ -12,25 +12,27 @@ #include ENTRY(hypercall) - iret - + movl $0x0833,8(%rsp) + pushq %r11 + pushq $0x082b + pushq %rcx + pushq $0 + SAVE_ALL + andq $(NR_hypercalls-1),%rax + leaq SYMBOL_NAME(exception_table)(%rip),%rcx + callq *(%rcx,%rax,8) + RESTORE_ALL + addq $8,%rsp + popq %rcx + addq $8,%rsp + popq %r11 + cli + popq %rsp + sysretq + ENTRY(ret_from_intr) restore_all_xen: - popq %r15 - popq %r14 - popq %r13 - popq %r12 - popq %rbp - popq %rbx - popq %r11 - popq %r10 - popq %r9 - popq %r8 - popq %rax - popq %rcx - popq %rdx - popq %rsi - popq %rdi + RESTORE_ALL addq $8,%rsp iretq @@ -156,3 +158,33 @@ ENTRY(exception_table) .quad SYMBOL_NAME(do_alignment_check) .quad SYMBOL_NAME(do_machine_check) .quad SYMBOL_NAME(do_simd_coprocessor_error) + +ENTRY(hypercall_table) + .quad SYMBOL_NAME(do_set_trap_table) /* 0 */ + .quad SYMBOL_NAME(do_mmu_update) + .quad SYMBOL_NAME(do_set_gdt) + .quad SYMBOL_NAME(do_stack_switch) + .quad SYMBOL_NAME(do_set_callbacks) + .quad SYMBOL_NAME(do_fpu_taskswitch) /* 5 */ + .quad SYMBOL_NAME(do_sched_op) + .quad SYMBOL_NAME(do_dom0_op) + .quad SYMBOL_NAME(do_set_debugreg) + .quad SYMBOL_NAME(do_get_debugreg) + .quad SYMBOL_NAME(do_update_descriptor) /* 10 */ + .quad SYMBOL_NAME(do_ni_hypercall) # do_set_fast_trap + .quad SYMBOL_NAME(do_dom_mem_op) + .quad SYMBOL_NAME(do_multicall) + .quad SYMBOL_NAME(do_update_va_mapping) + .quad SYMBOL_NAME(do_set_timer_op) /* 15 */ + .quad SYMBOL_NAME(do_event_channel_op) + .quad SYMBOL_NAME(do_xen_version) + .quad SYMBOL_NAME(do_console_io) + .quad SYMBOL_NAME(do_physdev_op) + .quad SYMBOL_NAME(do_grant_table_op) /* 20 */ + .quad SYMBOL_NAME(do_vm_assist) + .quad SYMBOL_NAME(do_update_va_mapping_otherdomain) + .quad SYMBOL_NAME(do_ni_hypercall) # do_switch_vm86 + .quad SYMBOL_NAME(do_boot_vcpu) + .rept NR_hypercalls-((.-hypercall_table)/4) + .quad SYMBOL_NAME(do_ni_hypercall) + .endr diff -r 715c644ba9ef -r 8c6281ec8860 xen/arch/x86/x86_64/traps.c --- a/xen/arch/x86/x86_64/traps.c Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/arch/x86/x86_64/traps.c Fri Feb 04 17:35:22 2005 +0000 @@ -7,6 +7,8 @@ #include #include #include +#include +#include static int kstack_depth_to_print = 8*20; @@ -176,6 +178,33 @@ void __init doublefault_init(void) idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */ } +asmlinkage void hypercall(void); +void __init percpu_traps_init(void) +{ + char *stack_top = (char *)get_stack_top(); + char *stack = (char *)((unsigned long)stack_top & ~(STACK_SIZE - 1)); + + /* movq %rsp, saversp(%rip) */ + stack[0] = 0x48; + stack[1] = 0x89; + stack[2] = 0x25; + *(u32 *)&stack[3] = (stack_top - &stack[7]) - 16; + + /* leaq saversp(%rip), %rsp */ + stack[7] = 0x48; + stack[8] = 0x8d; + stack[9] = 0x25; + *(u32 *)&stack[10] = (stack_top - &stack[14]) - 16; + + /* jmp hypercall */ + stack[14] = 0xe9; + *(u32 *)&stack[15] = (char *)hypercall - &stack[19]; + + wrmsr(MSR_STAR, 0, (FLAT_RING3_CS64<<16) | __HYPERVISOR_CS); + wrmsr(MSR_LSTAR, (unsigned long)stack, ((unsigned long)stack>>32)); + wrmsr(MSR_SYSCALL_MASK, 0xFFFFFFFFU, 0U); +} + void *decode_reg(struct xen_regs *regs, u8 b) { switch ( b ) diff -r 715c644ba9ef -r 8c6281ec8860 xen/include/asm-x86/x86_64/asm_defns.h --- a/xen/include/asm-x86/x86_64/asm_defns.h Fri Feb 04 15:27:09 2005 +0000 +++ b/xen/include/asm-x86/x86_64/asm_defns.h Fri Feb 04 17:35:22 2005 +0000 @@ -22,6 +22,23 @@ "pushq %r14;" \ "pushq %r15;" +#define RESTORE_ALL \ + "popq %r15;" \ + "popq %r14;" \ + "popq %r13;" \ + "popq %r12;" \ + "popq %rbp;" \ + "popq %rbx;" \ + "popq %r11;" \ + "popq %r10;" \ + "popq %r9;" \ + "popq %r8;" \ + "popq %rax;" \ + "popq %rcx;" \ + "popq %rdx;" \ + "popq %rsi;" \ + "popq %rdi;" + #else #define SAVE_ALL \ @@ -42,6 +59,23 @@ pushq %r14; \ pushq %r15; +#define RESTORE_ALL \ + popq %r15; \ + popq %r14; \ + popq %r13; \ + popq %r12; \ + popq %rbp; \ + popq %rbx; \ + popq %r11; \ + popq %r10; \ + popq %r9; \ + popq %r8; \ + popq %rax; \ + popq %rcx; \ + popq %rdx; \ + popq %rsi; \ + popq %rdi; + #endif #define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v)