summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/int_handler.c
blob: 3674d1cc148a2a42ae8efe808ecbef5b4109095d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "arch/x86_64/idt.h"
#include "arch/processor.h"
#include "print.h"
#include "jove.h"
#include "assert.h"
#include <stddef.h>

static int_handler_t s_handlers[48];

int_state_t*
irq_handle(int_state_t *state)
{
    if(__isr_num < 48) {
        if(s_handlers[__isr_num] != NULL) {
            return s_handlers[__isr_num](state);
        }
    }

    klogf("Interrupt %i\nerror code %#016X\n", __isr_num, __isr_err);
    int_state_print(state);
    kpanic("Unhandled exception\n");
    return state;
}

void 
int_handler_set(uint8_t i, int_handler_t handler)
{
    assert(i < 48);
    s_handlers[i] = handler;
}

int_handler_t 
int_handler_get(uint8_t i)
{
    assert(i < 48);
    return s_handlers[i];
}

void 
int_state_print(int_state_t *state)
{
    if(!state) return;
    klogf("IP:  %016p\n", state->ip);
    klogf("AX:  %016p BX:  %016p\n", state->ax, state->bx);
    klogf("CX:  %016p DX:  %016p\n", state->cx, state->dx);
    klogf("SI:  %016p DI:  %016p\n", state->si, state->di);
    klogf("SP:  %016p BP:  %016p\n", state->sp, state->bp);
    klogf("R8:  %016p R9:  %016p\n", state->r8, state->r9);
    klogf("R10: %016p R11: %016p\n", state->r10, state->r11);
    klogf("R12: %016p R13: %016p\n", state->r12, state->r13);
    klogf("R14: %016p R15: %016p\n", state->r14, state->r15);
}