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);
99 unsigned char scancode
105 struct v3_keyboard_event evt = {
107 .scan_code = scancode,
110 v3_deliver_keyboard_event( g_vm_guest, &evt );
116 unsigned char packet[3]
122 struct v3_mouse_event evt;
123 memcpy(evt.data, packet, 3);
125 v3_deliver_mouse_event(g_vm_guest, &evt);
131 unsigned int period_us
137 struct v3_timer_event evt = {
138 .period_us = period_us,
141 v3_deliver_timer_event( g_vm_guest, &evt );
146 translate_intr_handler(
147 struct pt_regs * regs,
151 struct v3_interrupt intr = {
153 .error = regs->orig_rax,
157 // PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
158 printk( "%s: irq %d\n", __func__, vector );
159 v3_deliver_irq( irq_to_guest_map[intr.irq], &intr );
164 kitten_hook_interrupt(
165 struct guest_info * vm,
169 if( irq_to_guest_map[irq] ) {
170 //PrintBoth("Attempt to hook interrupt that is already hooked\n");
174 //PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm);
175 printk( "%s: hook irq %d to %p\n", __func__, irq, vm );
176 irq_to_guest_map[irq] = vm;
178 set_idtvec_handler( irq, translate_intr_handler );
188 lapic_ack_interrupt();
196 return cpu_info[0].arch.cur_cpu_khz;
204 return kmem_alloc( size );
213 return kmem_free( addr );
230 struct v3_os_hooks v3vee_os_hooks = {
231 .print_debug = 0, // printk, // serial print ideally
232 .print_info = v3vee_printk, // serial print ideally
233 .print_trace = v3vee_printk, // serial print ideally
234 .allocate_pages = Allocate_VMM_Pages, // defined in vmm_stubs
235 .free_page = Free_VMM_Page, // defined in vmm_stubs
236 .malloc = v3vee_alloc,
238 .vaddr_to_paddr = kitten_va_to_pa,
239 .paddr_to_vaddr = kitten_pa_to_va,
240 .hook_interrupt = kitten_hook_interrupt,
242 .get_cpu_khz = get_cpu_khz,