summaryrefslogtreecommitdiffhomepage
path: root/src/loader/inc/int.h
blob: 8336cd84c41f9a31eae4986784444103b8c4bbb0 (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
// MIT License, Copyright (c) 2021 Marvin Borner

#ifndef INT_H
#define INT_H

#include <def.h>

#define INT_GATE 0x8e
#define INT_TRAP 0xef
#define INT_USER 0x60
#define IDT_ENTRY(offset, selector, type)                                                          \
	(struct idt_entry)                                                                         \
	{                                                                                          \
		.base_low = (u16)((offset)&0xffff), .sel = (selector), .zero = 0, .flags = (type), \
		.base_high = (u16)(((offset) >> 16) & 0xffff),                                     \
	}

struct int_frame {
	u32 gs, fs, es, ds;
	u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
	u32 int_no, err_code;
	u32 eip, cs, eflags;
} PACKED;

struct int_frame_user {
	u32 gs, fs, es, ds;
	u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
	u32 int_no, err_code;
	u32 eip, cs, eflags;
	u32 useresp, ss;
} PACKED;

struct idt_entry {
	u16 base_low;
	u16 sel; // Kernel segment
	u8 zero; // Always 0
	u8 flags;
	u16 base_high;
} PACKED;

struct idt_ptr {
	u16 size;
	void *base;
} PACKED;

extern struct idt_ptr idt;

void idt_install(void);
void int_event_handler_add(u32 int_no, void (*handler)(void));

#endif