2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <lwk/palacios.h>
21 #include <lwk/types.h>
23 #include <lwk/string.h>
24 #include <lwk/cpuinfo.h>
25 #include <lwk/kernel.h>
26 #include <arch/page.h>
27 #include <arch/ptrace.h>
28 #include <arch/apic.h>
30 struct guest_info * g_vm_guest = NULL;
31 struct guest_info * irq_to_guest_map[256];
36 v3vee_init_stubs( void )
38 memset(irq_to_guest_map, 0, sizeof(irq_to_guest_map) );
43 kitten_pa_to_va(void *ptr)
45 return (void*) __va(ptr);
54 return (void*) __pa(ptr);
63 struct pmem_region result;
65 int rc = pmem_alloc_umem( num_pages*PAGE_SIZE,PAGE_SIZE, &result );
69 return (void*) result.start;
77 struct pmem_region query;
78 struct pmem_region result;
80 pmem_region_unset_all(&query);
82 query.start = (uintptr_t)( page );
83 query.end = (uintptr_t)( page + PAGE_SIZE );
85 int rc = pmem_query(&query,&result);
89 panic( "Asked to free non-allocated page %p! rc=%d",
104 unsigned char status,
105 unsigned char scancode
111 struct v3_keyboard_event evt = {
113 .scan_code = scancode,
116 v3_deliver_keyboard_event( g_vm_guest, &evt );
122 unsigned char packet[3]
128 struct v3_mouse_event evt;
129 memcpy(evt.data, packet, 3);
131 v3_deliver_mouse_event(g_vm_guest, &evt);
137 unsigned int period_us
143 struct v3_timer_event evt = {
144 .period_us = period_us,
147 v3_deliver_timer_event( g_vm_guest, &evt );
152 translate_intr_handler(
153 struct pt_regs * regs,
157 struct v3_interrupt intr = {
159 .error = regs->orig_rax,
163 // PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
164 printk( "%s: irq %d\n", __func__, vector );
165 v3_deliver_irq( irq_to_guest_map[intr.irq], &intr );
170 kitten_hook_interrupt(
171 struct guest_info * vm,
175 if( irq_to_guest_map[irq] ) {
176 //PrintBoth("Attempt to hook interrupt that is already hooked\n");
180 //PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm);
181 printk( "%s: hook irq %d to %p\n", __func__, irq, vm );
182 irq_to_guest_map[irq] = vm;
184 set_idtvec_handler( irq, translate_intr_handler );
194 lapic_ack_interrupt();
202 return cpu_info[0].arch.cur_cpu_khz;
210 return kmem_alloc( size );
219 return kmem_free( addr );
236 struct v3_os_hooks v3vee_os_hooks = {
237 .print_debug = v3vee_printk, // serial print ideally
238 .print_info = v3vee_printk, // serial print ideally
239 .print_trace = v3vee_printk, // serial print ideally
240 .allocate_pages = Allocate_VMM_Pages, // defined in vmm_stubs
241 .free_page = Free_VMM_Page, // defined in vmm_stubs
242 .malloc = v3vee_alloc,
244 .vaddr_to_paddr = kitten_va_to_pa,
245 .paddr_to_vaddr = kitten_pa_to_va,
246 .hook_interrupt = kitten_hook_interrupt,
248 .get_cpu_khz = get_cpu_khz,