The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
isr.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
common/stdint.h
"
4
5
#ifdef __x86_64__
6
7
/**
8
* saved register state on the kernel stack (x86_64). the layout matches
9
* isr_common in asm64/isr.asm:
10
* 1. the general-purpose registers (pushed by isr_common)
11
* 2. interrupt number and error code (pushed by the stub or the CPU)
12
* 3. rip, cs, rflags, rsp, ss (pushed by the CPU on every interrupt)
13
* the syscall entry (asm64/syscall.asm) makes the same frame.
14
*/
15
struct
registers
16
{
17
uintptr_t
r15, r14, r13, r12, r11, r10, r9, r8;
18
uintptr_t
rbp, rdi, rsi, rdx, rcx, rbx, rax;
19
uintptr_t
interrupt
;
// interrupt vector number.
20
uintptr_t
error
;
// error code (or zero for interrupts without one).
21
uintptr_t
rip,
cs
, rflags, rsp,
ss
;
22
}
__attribute__
((packed));
23
24
#define REG_IP(r) ((r)->rip)
25
#define REG_SP(r) ((r)->rsp)
26
#define REG_FP(r) ((r)->rbp)
27
#define REG_FLAGS(r) ((r)->rflags)
28
#define REG_RESULT(r) ((r)->rax)
29
30
#else
31
32
/**
33
* saved register state pushed onto the stack by ISR stubs.
34
* this structure matches the layout created by the assembly ISR common handler:
35
* 1. data segment (pushed by us)
36
* 2. general-purpose registers (pushed by pusha)
37
* 3. interrupt number and error code (pushed by stub / CPU)
38
* 4. eip, cs, eflags, esp, ss (pushed automatically by the CPU)
39
*/
40
struct
registers
41
{
42
uint32_t
ds
;
// data segment selector.
43
uint32_t
edi
,
esi
,
ebp
,
kern_esp
,
ebx
,
edx
,
ecx
,
eax
;
// general-purpose registers from pusha.
44
uint32_t
interrupt
;
// interrupt vector number.
45
uint32_t
error
;
// error code (or zero for interrupts without one).
46
uint32_t
eip
,
cs
,
eflags
,
esp
,
ss
;
// pushed automatically by the CPU on interrupt.
47
}
__attribute__
((packed));
48
49
#define REG_IP(r) ((r)->eip)
50
#define REG_SP(r) ((r)->esp)
51
#define REG_FP(r) ((r)->ebp)
52
#define REG_FLAGS(r) ((r)->eflags)
53
#define REG_RESULT(r) ((r)->eax)
54
55
#endif
56
57
// the interrupt flag in EFLAGS (RFLAGS): set when interrupts are enabled
58
#define EFLAGS_IF 0x200u
59
60
/*
61
* REG_IP, REG_SP, REG_FP, REG_FLAGS and REG_RESULT name the instruction
62
* pointer, the stack pointer, the frame pointer, the flags and the
63
* accumulator (the syscall number in, the result out) of a struct
64
* registers. portable code uses them instead of the register names.
65
*/
66
67
/**
68
* true if the interrupted code ran in user mode (ring 3).
69
*/
70
static
inline
bool
regs_from_user(
const
struct
registers
*regs)
71
{
72
return
(regs->
cs
& 3u) == 3u;
73
}
74
75
/**
76
* interrupt service routine handler function type.
77
* @param regs pointer to the saved register state at the time of the interrupt.
78
*/
79
typedef
void (*
isr_handler_t
)(
struct
registers
*regs);
80
81
/**
82
* initialize the interrupt service routine subsystem.
83
* installs all 256 ISR gates into the IDT and enables them.
84
*/
85
void
isr_initialize
(
void
);
86
87
/**
88
* register a handler function for a specific interrupt vector.
89
* @param vector interrupt vector number (0–255).
90
* @param handler pointer to the handler function to call when this interrupt fires.
91
*/
92
void
isr_register_handler
(
int
vector,
isr_handler_t
handler);
stdint.h
ss
uint32_t ss
Definition
gdt.c:20
cs
uint32_t cs
Definition
gdt.c:19
isr_initialize
void isr_initialize(void)
initialize the interrupt system.
Definition
isr.c:50
isr_register_handler
void isr_register_handler(int vector, isr_handler_t handler)
register a handler for an interrupt vector.
Definition
isr.c:93
interrupt
uint32_t interrupt
Definition
isr.h:2
isr_handler_t
void(*) isr_handler_t(struct registers *regs)
interrupt service routine handler function type.
Definition
isr.h:79
error
uint32_t error
Definition
isr.h:3
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition
stdint.h:19
__attribute__
ELF32 file header.
Definition
elf.h:51
registers
saved register state pushed onto the stack by ISR stubs.
Definition
isr.h:41
registers::ecx
uint32_t ecx
Definition
isr.h:43
registers::ss
uint32_t ss
Definition
isr.h:46
registers::eax
uint32_t eax
Definition
isr.h:43
registers::interrupt
uint32_t interrupt
Definition
isr.h:44
registers::error
uint32_t error
Definition
isr.h:45
registers::cs
uint32_t cs
Definition
isr.h:46
registers::ds
uint32_t ds
Definition
isr.h:42
registers::ebp
uint32_t ebp
Definition
isr.h:43
registers::esi
uint32_t esi
Definition
isr.h:43
registers::esp
uint32_t esp
Definition
isr.h:46
registers::ebx
uint32_t ebx
Definition
isr.h:43
registers::eip
uint32_t eip
Definition
isr.h:46
registers::kern_esp
uint32_t kern_esp
Definition
isr.h:43
registers::edi
uint32_t edi
Definition
isr.h:43
registers::edx
uint32_t edx
Definition
isr.h:43
registers::eflags
uint32_t eflags
Definition
isr.h:46
src
arch
x86
cpu
isr.h
Generated by
1.18.0