--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+
+
+#include <palacios-glue/vmm_stubs.h>
+#include <palacios-glue/vm.h>
+
+#include <lwk/kernel.h>
+
+#include <lwk/palacios.h>
+
+#include <palacios/vmm.h>
+#include <palacios/vmm_io.h>
+
+
+
+
+int RunVMM() {
+ struct v3_os_hooks os_hooks;
+ struct v3_ctrl_ops v3_ops;
+ struct guest_info * vm_info = 0;
+ struct v3_vm_config vm_config;
+
+ void * ramdiskImage=&initrd_start;
+ ulong_t ramdiskSize=(&initrd_end)-(&initrd_start);
+
+ memset(&os_hooks, 0, sizeof(struct v3_os_hooks));
+ memset(&v3_ops, 0, sizeof(struct v3_ctrl_ops));
+ memset(&vm_config, 0, sizeof(struct v3_vm_config));
+
+
+ os_hooks.print_debug = &printk; // serial print ideally
+ os_hooks.print_info = &printk; // serial print ideally
+ os_hooks.print_trace = &printk; // serial print ideally
+ os_hooks.allocate_pages = &Allocate_VMM_Pages; // defined in vmm_stubs
+ os_hooks.free_page = &Free_VMM_Page; // defined in vmm_stubs
+ os_hooks.malloc = &kmem_alloc;
+ os_hooks.free = &kmem_free;
+ os_hooks.vaddr_to_paddr = &kitten_va_to_pa;
+ os_hooks.paddr_to_vaddr = &kitten_pa_to_va;
+ os_hooks.hook_interrupt = &kitten_hook_interrupt;
+ os_hooks.ack_irq = &ack_irq;
+ os_hooks.get_cpu_khz = &get_cpu_khz;
+
+
+
+ Init_V3(&os_hooks, &v3_ops);
+
+
+ vm_config.rombios = &rombios_start;
+ vm_config.rombios_size = (&rombios_end)-(&rombios_start);
+ vm_config.vgabios = &vgabios_start;
+ vm_config.vgabios_size = (&vgabios_end)-(&vgabios_start);
+
+
+ if (ramdiskImage != NULL) {
+ vm_config.use_ramdisk = 1;
+ vm_config.ramdisk = ramdiskImage;
+ vm_config.ramdisk_size = ramdiskSize;
+ }
+
+
+
+ vm_info = (v3_ops).allocate_guest();
+
+ Init_Stubs(vm_info);
+
+ //PrintBoth("Allocated Guest\n");
+
+ (v3_ops).config_guest(vm_info, &vm_config);
+
+ //PrintBoth("Configured guest\n");
+
+ (v3_ops).init_guest(vm_info);
+ PrintBoth("Starting Guest\n");
+ //Clear_Screen();
+
+ (v3_ops).start_guest(vm_info);
+
+ return 0;
+}
--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#ifndef __VM_H
+#define __VM_H
+
+int RunVMM();
+
+
+#endif
+
--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#include <palacios/vmm.h>
+#include <palacios/vmm_host_events.h>
+
+#include <lwk/pmem.h>
+
+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 Init_Stubs(struct guest_info * info) {
+ memset(irq_to_guest_map, 0, sizeof(struct guest_info *) * 256);
+ g_vm_guest = info;
+}
+
+
+void * kitten_pa_to_va(void *ptr)
+{
+ return __va(ptr);
+}
+
+void * kitten_va_to_pa(void *ptr)
+{
+ return __pa(ptr);
+}
+
+void * Allocate_VMM_Pages(int num_pages)
+{
+ int rc;
+ struct pmem_region result;
+
+ rc=pmem_alloc_umem(num_pages*PAGE_SIZE,PAGE_SIZE,&result);
+
+ if (rc) {
+ return 0;
+ } else {
+ return result.start;
+ }
+}
+
+void Free_VMM_Page(void * page)
+{
+ int rc;
+ struct pmem_region query;
+ struct pmem_region result;
+
+ pmem_region_unset_all(&query);
+
+ query.start=page;
+ query.end=page+PAGE_SIZE;
+
+ rc=pmem_query(&query,&result);
+
+ if (!rc) {
+ result.allocated=FALSE;
+ pmem_update(&result);
+ } else {
+ // BAD
+ }
+}
+
+
+void * VMM_Malloc(unsigned int size) {
+ return Malloc((unsigned long) size);
+}
+
+
+void VMM_Free(void * addr) {
+ Free(addr);
+}
+
+
+
+void send_key_to_vmm(unsigned char status, unsigned char scancode) {
+ struct v3_keyboard_event evt;
+
+ evt.status = status;
+ evt.scan_code = scancode;
+
+ if (g_vm_guest) {
+ v3_deliver_keyboard_event(g_vm_guest, &evt);
+ }
+}
+
+
+void send_mouse_to_vmm(unsigned char packet[3]) {
+ struct v3_mouse_event evt;
+
+ memcpy(evt.data, packet, 3);
+
+ if (g_vm_guest) {
+ v3_deliver_mouse_event(g_vm_guest, &evt);
+ }
+}
+
+void send_tick_to_vmm(unsigned int period_us) {
+ struct v3_timer_event evt;
+
+ evt.period_us = period_us;
+
+ if (g_vm_guest) {
+ v3_deliver_timer_event(g_vm_guest, &evt);
+ }
+}
+
+
+void translate_intr_handler(struct pt_regs *regs, unsigned int vector)
+{
+ struct v3_interrupt intr;
+
+ intr.irq = vector-32;
+ intr.error = regs->orig_rax;
+ intr.should_ack = 0;
+
+ // PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
+
+ v3_deliver_irq(irq_to_guest_map[intr.irq], &intr);
+
+}
+
+
+
+int kitten_hook_interrupt(struct guest_info * vm, unsigned int irq)
+{
+ if (irq_to_guest_map[irq]) {
+ //PrintBoth("Attempt to hook interrupt that is already hooked\n");
+ return -1;
+ } else {
+ //PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm);
+ irq_to_guest_map[irq] = vm;
+ }
+
+ set_idtvec_handler(irq,translate_intr_handler);
+ return 0;
+}
+
+
+int ack_irq(int irq)
+{
+ lapic_ack_interrupt();
+ return 0;
+}
+
+
+
+
+unsigned int get_cpu_khz()
+{
+ return cpu_info[0].arch.cur_cpu_khz;
+}
+
+
--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#ifndef __VMM_STUBS_H
+#define __VMM_STUBS_H
+
+
+//#include <geekos/mem.h>
+//#include <geekos/malloc.h>
+
+
+struct guest_info;
+
+
+
+
+void * Allocate_VMM_Pages(int num_pages);
+void Free_VMM_Page(void * page);
+
+void * VMM_Malloc(unsigned int size);
+void VMM_Free(void * addr);
+
+void * Identity(void *addr);
+
+
+int hook_irq_stub(struct guest_info * info, int irq);
+int ack_irq(int irq);
+
+int geekos_hook_interrupt(struct guest_info * info, uint_t irq);
+
+unsigned int get_cpu_khz();
+
+void Init_Stubs(struct guest_info * info);
+
+
+
+/****
+ *
+ * stubs called by geekos....
+ *
+ ***/
+void send_key_to_vmm(unsigned char status, unsigned char scancode);
+void send_mouse_to_vmm(unsigned char packet[3]);
+void send_tick_to_vmm(unsigned int period_us);
+
+
+#if 0
+
+# define do_div(n,base) ({ \
+ uint32_t __base = (base); \
+ uint32_t __rem; \
+ __rem = ((uint64_t)(n)) % __base; \
+ (n) = ((uint64_t)(n)) / __base; \
+ __rem; \
+ })
+
+#else
+
+/*
+ * do_div() is NOT a C function. It wants to return
+ * two values (the quotient and the remainder), but
+ * since that doesn't work very well in C, what it
+ * does is:
+ *
+ * - modifies the 64-bit dividend _in_place_
+ * - returns the 32-bit remainder
+ *
+ * This ends up being the most efficient "calling
+ * convention" on x86.
+ */
+#define do_div(n,base) ({ \
+ unsigned long __upper, __low, __high, __mod, __base; \
+ __base = (base); \
+ asm("":"=a" (__low), "=d" (__high):"A" (n)); \
+ __upper = __high; \
+ if (__high) { \
+ __upper = __high % (__base); \
+ __high = __high / (__base); \
+ } \
+ asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
+ asm("":"=A" (n):"a" (__low),"d" (__high)); \
+ __mod; \
+ })
+
+#endif
+
+
+
+
+
+
+#endif