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 <geekos/vmm_stubs.h>
21 #include <geekos/serial.h>
22 #include <geekos/debug.h>
23 #include <palacios/vmm.h>
24 #include <palacios/vmm_host_events.h>
27 struct guest_info * g_vm_guest = NULL;
30 // This is the function the interface code should call to deliver
31 // the interrupt to the vmm for handling
32 //extern int v3_deliver_interrupt(struct guest_info * vm, struct v3_interrupt *intr);
35 struct guest_info * irq_to_guest_map[256];
40 static inline void VM_Out_Byte(ushort_t port, uchar_t value)
42 __asm__ __volatile__ (
45 : "a" (value), "Nd" (port)
50 * Read a byte from an I/O port.
52 static inline uchar_t VM_In_Byte(ushort_t port)
56 __asm__ __volatile__ (
67 void Init_Stubs(struct guest_info * info) {
68 memset(irq_to_guest_map, 0, sizeof(struct guest_info *) * 256);
74 void * Identity(void *addr) { return addr; };
76 void * Allocate_VMM_Pages(int num_pages) {
77 void * start_page = Alloc_Page();
78 //SerialPrint("Starting by Allocating Page: %x (%d of %d)\n",start_page, 1, num_pages);
81 while (i < num_pages) {
82 void * tmp_page = Alloc_Page();
83 //SerialPrint("Allocating Page: %x (%d of %d)\n",tmp_page, i+1, num_pages);
85 if (tmp_page != start_page + (PAGE_SIZE * i)) {
86 //we have to start over...;
88 Free_Page(start_page + (PAGE_SIZE * i));
91 start_page = Alloc_Page();
92 //SerialPrint("Starting over by Allocating Page: %x (%d of %d)\n",start_page, 1, num_pages);
102 void Free_VMM_Page(void * page) {
107 void * VMM_Malloc(unsigned int size) {
108 return Malloc((unsigned long) size);
112 void VMM_Free(void * addr) {
118 void send_key_to_vmm(unsigned char status, unsigned char scancode) {
119 struct v3_keyboard_event evt;
122 evt.scan_code = scancode;
125 v3_deliver_keyboard_event(g_vm_guest, &evt);
130 void send_mouse_to_vmm(unsigned char packet[3]) {
131 struct v3_mouse_event evt;
133 memcpy(evt.data, packet, 3);
136 v3_deliver_mouse_event(g_vm_guest, &evt);
140 void send_tick_to_vmm(unsigned int period_us) {
141 struct v3_timer_event evt;
143 evt.period_us = period_us;
146 v3_deliver_timer_event(g_vm_guest, &evt);
151 void translate_intr_handler(struct Interrupt_State *state) {
152 struct v3_interrupt intr;
154 intr.irq = state->intNum - 32;
155 intr.error = state->errorCode;
158 // PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
160 v3_deliver_irq(irq_to_guest_map[intr.irq], &intr);
168 int geekos_hook_interrupt(struct guest_info * vm, unsigned int irq)
170 if (irq_to_guest_map[irq]) {
171 PrintBoth("Attempt to hook interrupt that is already hooked\n");
174 PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm);
175 irq_to_guest_map[irq] = vm;
179 Install_IRQ(irq, translate_intr_handler);
185 int ack_irq(int irq) {
193 unsigned int get_cpu_khz() {
194 extern uint_t cpu_khz_freq;
196 unsigned long print_khz = (unsigned long)(cpu_khz_freq & 0xffffffff);
198 PrintBoth("Detected %lu.%lu MHz CPU\n", print_khz / 1000, print_khz % 1000);