4 #include <lunaix/mm/vmm.h>
5 #include <lunaix/process.h>
6 #include <lunaix/sched.h>
7 #include <lunaix/syslog.h>
8 #include <lunaix/failsafe.h>
15 intr_routine_page_fault(const struct hart_state* state);
18 syscall_hndlr(const struct hart_state* hstate);
21 apic_ack_interrupt(irq_t irq);
24 __set_panic(const char* msg, const struct hart_state* state)
26 ERROR("panic: %s", msg);
27 failsafe_diagnostic();
31 update_thread_context(struct hart_state* state)
33 if (!current_thread) {
37 struct hart_state* parent = current_thread->hstate;
38 hart_push_state(parent, state);
39 current_thread->hstate = state;
42 state->depth = parent->depth + 1;
48 __handle_internal_vectors(const struct hart_state* state)
50 switch (hart_vector_stamp(state))
52 case FAULT_DIVISION_ERROR:
53 __set_panic("div zero", state);
56 case FAULT_GENERAL_PROTECTION:
57 __set_panic("general protection", state);
60 case FAULT_PAGE_FAULT:
61 intr_routine_page_fault(state);
64 case FAULT_INVALID_OPCODE:
65 __set_panic("invalid opcode", state);;
69 apic_ack_interrupt(NULL);
77 __set_panic("apic error", state);;
92 __handle_external_irq(const struct hart_state* state)
97 ex_iv = hart_vector_stamp(state);
98 irq = irq_find(irq_get_default_domain(), ex_iv);
100 if (unlikely(!irq)) {
104 irq_serve(irq, state);
105 apic_ack_interrupt(irq);
110 intr_handler(struct hart_state* state)
112 update_thread_context(state);
114 volatile struct exec_param* execp = state->execp;
116 if (__handle_internal_vectors(state)) {
120 if (__handle_external_irq(state)) {
124 __set_panic("unknown interrupt", state);