1 #include <palacios/vmm_intr.h>
2 #include <palacios/vmm.h>
4 #include <palacios/vm_guest.h>
7 void init_interrupt_state(struct guest_info * info) {
8 info->intr_state.excp_pending = 0;
9 info->intr_state.excp_num = 0;
10 info->intr_state.excp_error_code = 0;
12 info->vm_ops.raise_irq = &raise_irq;
15 void set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
16 info->intr_state.controller = ops;
17 info->intr_state.controller_state = state;
28 int hook_irq(struct guest_info * info, int irq) {
29 extern struct vmm_os_hooks * os_hooks;
31 return os_hooks->hook_interrupt(info, irq);
34 int raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t error_code) {
35 struct vm_intr * intr_state = &(info->intr_state);
37 if (intr_state->excp_pending == 0) {
38 intr_state->excp_pending = 1;
39 intr_state->excp_num = excp;
40 intr_state->excp_error_code = error_code;
41 intr_state->excp_error_code_valid = 1;
42 PrintDebug("Raising exception with error code: %x\n", error_code);
44 PrintDebug("exception already pending, currently not implemented\n");
51 int raise_exception(struct guest_info * info, uint_t excp) {
52 struct vm_intr * intr_state = &(info->intr_state);
54 if (intr_state->excp_pending == 0) {
55 intr_state->excp_pending = 1;
56 intr_state->excp_num = excp;
57 intr_state->excp_error_code = 0;
58 intr_state->excp_error_code_valid = 0;
60 PrintDebug("exception already pending, currently not implemented\n");
68 int raise_irq(struct guest_info * info, int irq) {
69 // Look up PIC and resend
71 V3_ASSERT(info->intr_state.controller);
72 V3_ASSERT(info->intr_state.controller->raise_intr);
74 // if ((info->intr_state.controller) &&
75 // (info->intr_state.controller->raise_intr)) {
76 info->intr_state.controller->raise_intr(info->intr_state.controller_state, irq);
78 // PrintDebug("There is no registered Interrupt Controller... (NULL POINTER)\n");
94 int intr_pending(struct guest_info * info) {
95 struct vm_intr * intr_state = &(info->intr_state);
97 if (intr_state->excp_pending == 1) {
99 } else if (intr_state->controller->intr_pending(intr_state->controller_state) == 1) {
109 uint_t get_intr_number(struct guest_info * info) {
110 struct vm_intr * intr_state = &(info->intr_state);
112 if (intr_state->excp_pending == 1) {
113 return intr_state->excp_num;
114 } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
115 return intr_state->controller->get_intr_number(intr_state->controller_state);
118 /* someway to get the [A]PIC intr */
124 intr_type_t get_intr_type(struct guest_info * info) {
125 struct vm_intr * intr_state = &(info->intr_state);
127 if (intr_state->excp_pending) {
129 } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
141 int injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type) {
142 struct vm_intr * intr_state = &(info->intr_state);
144 if (type == EXCEPTION) {
146 intr_state->excp_pending = 0;
147 intr_state->excp_num = 0;
148 intr_state->excp_error_code = 0;
149 intr_state->excp_error_code_valid = 0;
151 } else if (type == EXTERNAL_IRQ) {
152 return intr_state->controller->begin_irq(intr_state->controller_state, intr_num);