From: Trammell Hudson Date: Wed, 22 Oct 2008 15:36:02 +0000 (-0500) Subject: Wired up keyboard interrupt to v3vee (and it works!). X-Git-Tag: 1.0^2~14 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios-OLD.git;a=commitdiff_plain;h=f31fa47b9cc6f4aaa8d082cc18c0c97f016825e2 Wired up keyboard interrupt to v3vee (and it works!). Silenced all warnings in kitten build. Removed dead prototypes in palacios.h. Fixed race in delivering keyboard interrupt to v3vee before guest was started. Depends on having IOAPIC configured to generate keyboard interrupts. --- diff --git a/kitten/arch/x86_64/kernel/interrupts.c b/kitten/arch/x86_64/kernel/interrupts.c index 19ba726..ff55da3 100644 --- a/kitten/arch/x86_64/kernel/interrupts.c +++ b/kitten/arch/x86_64/kernel/interrupts.c @@ -4,11 +4,13 @@ #include #include #include +#include #include #include #include #include #include +#include idtvec_handler_t idtvec_table[NUM_IDT_ENTRIES]; static DEFINE_SPINLOCK(idtvec_table_lock); @@ -225,6 +227,25 @@ do_apic_spurious(struct pt_regs *regs, unsigned int vector) } void +do_keyboard_interrupt(struct pt_regs *regs, unsigned int vector) +{ + const uint8_t KB_OUTPUT_FULL = 0x01; + const uint8_t KB_STATUS_PORT = 0x64; + const uint8_t KB_DATA_PORT = 0x60; + + uint8_t status = inb( KB_STATUS_PORT ); + + if( (status & KB_OUTPUT_FULL) == 0 ) + return; + + uint8_t key = inb( KB_DATA_PORT ); +#ifdef CONFIG_V3VEE + send_key_to_vmm( status, key ); +#endif +} + + +void set_idtvec_handler(unsigned int vector, idtvec_handler_t handler) { char namebuf[KSYM_NAME_LEN+1]; @@ -263,7 +284,7 @@ interrupts_init(void) */ for (vector = 0; vector < NUM_IDT_ENTRIES; vector++) { void *asm_handler = (void *) ( - (unsigned long)(&asm_idtvec_table) + (vector * 16) + (uintptr_t)(&asm_idtvec_table) + (vector * 16) ); set_intr_gate(vector, asm_handler); set_idtvec_handler(vector, &do_unhandled_idt_vector); @@ -291,6 +312,7 @@ interrupts_init(void) set_idtvec_handler( ALIGNMENT_CHECK_VECTOR, &do_alignment_check ); set_idtvec_handler( MACHINE_CHECK_VECTOR, &do_machine_check ); set_idtvec_handler( SIMD_COPROCESSOR_ERROR_VECTOR, &do_simd_coprocessor_error ); + set_idtvec_handler( IRQ1_VECTOR, &do_keyboard_interrupt ); /* * Register handlers for all of the local APIC vectors. diff --git a/kitten/boot-kitten2 b/kitten/boot-kitten2 index 5135c32..cf5dfe4 100755 --- a/kitten/boot-kitten2 +++ b/kitten/boot-kitten2 @@ -1,6 +1,7 @@ #!/bin/sh exec /usr/local/qemu/bin/qemu-system-x86_64 \ + -smp 1 \ -m 1024 \ -serial file:./serial.out \ -cdrom ./arch/x86_64/boot/image.iso \ diff --git a/kitten/include/lwk/palacios.h b/kitten/include/lwk/palacios.h index fecaac3..270b538 100644 --- a/kitten/include/lwk/palacios.h +++ b/kitten/include/lwk/palacios.h @@ -9,12 +9,17 @@ #include #include +extern struct guest_info * g_vm_guest; + + +extern void +v3vee_init_stubs( void ); -extern void v3vee_init_stubs( struct guest_info * info ); extern int v3vee_run_vmm( void ); + extern struct v3_os_hooks v3vee_os_hooks; /**** @@ -33,79 +38,6 @@ extern uint8_t vgabios_start, vgabios_end; extern paddr_t initrd_start, initrd_end; -/* - * OS Hooks required to interface with the V3VEE library - */ -extern void -v3vee_print_config( - const char * fmt, - ... -) __attribute__((format(printf,1,2))); - - -extern void -v3vee_print_debug( - const char * fmt, - ... -) __attribute__((format(printf,1,2))); - - -extern void -v3vee_print_trace( - const char * fmt, - ... -) __attribute__((format(printf,1,2))); - - -extern void * -v3vee_allocate_pages( int num_pages ); - - -extern void -v3vee_free_page( void * page ); - - -extern void * -v3vee_malloc( unsigned int size ); - - -extern void -v3vee_free( void * addr ); - - -extern void * -v3vee_paddr_to_vaddr( void * addr ); - - -extern void * -v3vee_vaddr_to_paddr( void * addr ); - - -extern int -v3vee_hook_interrupt( - struct guest_info * vm, - unsigned int irq -); - - -extern int -v3vee_ack_irq( - int irq -); - - -unsigned int -v3vee_get_cpu_khz( void ); - - -void -v3vee_start_kernel_thread( void ); - - -void -v3vee_yield_cpu( void ); - - #endif // CONFIG_V3VEE #endif diff --git a/kitten/palacios-glue/vm.c b/kitten/palacios-glue/vm.c index 3ba421c..1d3e322 100644 --- a/kitten/palacios-glue/vm.c +++ b/kitten/palacios-glue/vm.c @@ -31,9 +31,6 @@ v3vee_run_vmm( void ) { struct v3_ctrl_ops v3_ops = {}; - void * ramdiskImage=initrd_start; - uintptr_t ramdiskSize=initrd_end-initrd_start; - Init_V3( &v3vee_os_hooks, &v3_ops ); struct v3_vm_config vm_config = { @@ -41,17 +38,19 @@ v3vee_run_vmm( void ) .rombios_size = (&rombios_end)-(&rombios_start), .vgabios = &vgabios_start, .vgabios_size = (&vgabios_end)-(&vgabios_start), - .use_ramdisk = ramdiskImage != NULL, - .ramdisk = ramdiskImage, - .ramdisk_size = ramdiskSize, + .use_ramdisk = 1, + .ramdisk = (void*) initrd_start, + .ramdisk_size = initrd_end - initrd_start, }; - struct guest_info * vm_info = (v3_ops).allocate_guest(); - v3vee_init_stubs(vm_info); + struct guest_info * vm_info = v3_ops.allocate_guest(); + v3vee_init_stubs(); v3_ops.config_guest(vm_info, &vm_config); v3_ops.init_guest(vm_info); + g_vm_guest = vm_info; + printk("Starting Guest\n"); v3_ops.start_guest(vm_info); diff --git a/kitten/palacios-glue/vmm_stubs.c b/kitten/palacios-glue/vmm_stubs.c index 672ca6c..0721a1e 100644 --- a/kitten/palacios-glue/vmm_stubs.c +++ b/kitten/palacios-glue/vmm_stubs.c @@ -28,26 +28,14 @@ #include struct guest_info * g_vm_guest = NULL; - - -// This is the function the interface code should call to deliver -// the interrupt to the vmm for handling -//extern int v3_deliver_interrupt(struct guest_info * vm, struct v3_interrupt *intr); - - struct guest_info * irq_to_guest_map[256]; - - void -v3vee_init_stubs( - struct guest_info * info -) +v3vee_init_stubs( void ) { - memset(irq_to_guest_map, 0, sizeof(struct guest_info *) * 256); - g_vm_guest = info; + memset(irq_to_guest_map, 0, sizeof(irq_to_guest_map) ); } @@ -78,7 +66,7 @@ Allocate_VMM_Pages( if( rc ) return 0; - return result.start; + return (void*) result.start; } static void @@ -91,8 +79,8 @@ Free_VMM_Page( pmem_region_unset_all(&query); - query.start = page; - query.end = page+PAGE_SIZE; + query.start = (uintptr_t)( page ); + query.end = (uintptr_t)( page + PAGE_SIZE ); int rc = pmem_query(&query,&result); @@ -167,6 +155,7 @@ translate_intr_handler( }; // PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque); + printk( "%s: irq %d\n", __func__, vector ); v3_deliver_irq( irq_to_guest_map[intr.irq], &intr ); } @@ -183,6 +172,7 @@ kitten_hook_interrupt( } //PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm); + printk( "%s: hook irq %d to %p\n", __func__, irq, vm ); irq_to_guest_map[irq] = vm; set_idtvec_handler( irq, translate_intr_handler ); @@ -206,15 +196,45 @@ get_cpu_khz( void ) return cpu_info[0].arch.cur_cpu_khz; } +static void * +v3vee_alloc( + unsigned int size +) +{ + return kmem_alloc( size ); +} + + +static void +v3vee_free( + void * addr +) +{ + return kmem_free( addr ); +} + + +static void +v3vee_printk( + const char * fmt, + ... +) +{ + va_list ap; + va_start( ap, fmt ); + vprintk( fmt, ap ); + va_end( ap ); +} + struct v3_os_hooks v3vee_os_hooks = { - .print_debug = printk, // serial print ideally - .print_info = printk, // serial print ideally - .print_trace = printk, // serial print ideally + .print_debug = 0, // printk, // serial print ideally + .print_info = v3vee_printk, // serial print ideally + .print_trace = v3vee_printk, // serial print ideally .allocate_pages = Allocate_VMM_Pages, // defined in vmm_stubs .free_page = Free_VMM_Page, // defined in vmm_stubs - .malloc = kmem_alloc, - .free = kmem_free, + .malloc = v3vee_alloc, + .free = v3vee_free, .vaddr_to_paddr = kitten_va_to_pa, .paddr_to_vaddr = kitten_pa_to_va, .hook_interrupt = kitten_hook_interrupt,