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".
21 #include <devices/apic.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vmm_msr.h>
25 #define BASE_ADDR_MSR 0x0000001B
29 v3_msr_t base_addr_reg;
34 static int read_base_addr(uint_t msr, v3_msr_t * dst, void * priv_data) {
35 struct vm_device * dev = (struct vm_device *)priv_data;
36 struct apic_state * apic = (struct apic_state *)dev->private_data;
37 PrintDebug("READING APIC BASE ADDR: HI=%x LO=%x\n", apic->base_addr_reg.hi, apic->base_addr_reg.lo);
43 static int write_base_addr(uint_t msr, v3_msr_t src, void * priv_data) {
44 // struct vm_device * dev = (struct vm_device *)priv_data;
45 // struct apic_state * apic = (struct apic_state *)dev->private_data;
47 PrintDebug("WRITING APIC BASE ADDR: HI=%x LO=%x\n", src.hi, src.lo);
53 static int apic_deinit(struct vm_device * dev) {
54 struct guest_info * info = dev->vm;
56 v3_unhook_msr(info, BASE_ADDR_MSR);
62 static int apic_init(struct vm_device * dev) {
63 struct guest_info * info = dev->vm;
65 v3_hook_msr(info, BASE_ADDR_MSR, read_base_addr, write_base_addr, dev);
72 static struct vm_device_ops dev_ops = {
74 .deinit = apic_deinit,
81 struct vm_device * v3_create_apic() {
82 PrintDebug("Creating APIC\n");
84 struct apic_state * apic = (struct apic_state *)V3_Malloc(sizeof(struct apic_state));
86 struct vm_device * device = v3_create_device("APIC", &dev_ops, apic);