WKern
Loading...
Searching...
No Matches
idtirq.h
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am making (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <global.h>
22#include <types/nums.h> // put includes at the top
23
24#define KERNEL_CODE_SEGMENT 0x08 // Usually your GDT code segment
25
26/*
27===================
28-- IDT FUNCTIONS --
29===================
30*/
31void SetupIdt(void);
32void IdtInit(void);
33void IdtSetGate(u8 num, u32 base, u16 sel, u8 flags);
34void MaskAllIrqs(void);
35void UnmaskIrq(u8 irq);
37
38void AllIdt();
39
40// PIC remap
41extern void _picr(void);
42
43/*
44==================
45---- STRUCTS -----
46==================
47*/
48
49// IDT Entry structure (packed to prevent compiler padding)
50struct IdtEntry {
52 u16 sel; // Kernel code segment selector
54 u8 flags; // Flags (present, ring level, type)
57
58struct GdtEntry {
59 u16 limit_low; // Lower 16 bits of limit
60 u16 base_low; // Lower 16 bits of base
61 u8 base_middle; // Next 8 bits of base
62 u8 access; // Access flags
63 u8 granularity; // Granularity flags + upper 4 bits of limit
64 u8 base_high; // Last 8 bits of base
65} PKG;
66
67struct GdtPtr {
70} PKG;
71
72struct PKG IdtPtr {
75};
76
77/*
78===================
79-- GDT FUNCTIONS --
80===================
81*/
82void GdtInstall();
83extern void GdtFlush(u32);
84void GdtSetGate(int num, u32 base, u32 limit, u8 access, u8 gran);
85
86/*
87============
88-- OTHERS --
89============
90*/
91extern struct IdtPtr idt_ptrn;
92#define IDT_ENTRIES 256
93extern struct IdtEntry idt[IDT_ENTRIES];
94void MsSleep(unsigned int milliseconds);
95void PitInit(u32 freq);
96
97// ----- HANDLERS ----- //
98
99void Irq0HandlerC(void); // C handler called from asm IRQ0 stub
100extern void Irq0Handler(void); // Assembly IRQ0 stub (global in asm)
101extern void GoodHandler(void);
102extern void Irq1Handler(void);
103void VirtnetIrqHandler();
104extern void VirtnetHandler(void);
105
106// MACROS
107#define PIT_FREQ 119
108#define SendEOI Outb(0x20, 0x20)
#define PKG
Add attribute packed.
Definition global.h:35
struct IdtEntry idt[IDT_ENTRIES]
Definition idt.c:27
void GdtSetGate(int num, u32 base, u32 limit, u8 access, u8 gran)
Set a GDT entry (descriptor)
Definition gdt.c:35
void IdtInit(void)
#define IDT_ENTRIES
Definition idtirq.h:92
void GdtFlush(u32)
void GdtInstall()
Initialize and load the Global Descriptor Table (GDT)
Definition gdt.c:56
void _picr(void)
struct IdtEntry PKG
void DebugPrintIdtEntry(int i)
void VirtnetHandler(void)
void GoodHandler(void)
struct IdtPtr idt_ptrn
void SetupIdt(void)
void Irq0Handler(void)
void VirtnetIrqHandler()
Definition virtnetirq.c:11
void UnmaskIrq(u8 irq)
Unmask an IRQ.
Definition masker.c:34
void MsSleep(unsigned int milliseconds)
Definition irq0.c:29
void IdtSetGate(u8 num, u32 base, u16 sel, u8 flags)
Set an IDT gate (entry) at given index.
Definition idt.c:40
void Irq1Handler(void)
void Irq0HandlerC(void)
Definition irq0.c:24
void AllIdt()
Initialize and load the Interrupt Descriptor Table (IDT)
Definition idt.c:73
void PitInit(u32 freq)
Definition pit.c:32
void MaskAllIrqs(void)
Mask all IRQs.
Definition masker.c:26
unsigned int u32
32-Bit Unsigned Int
Definition nums.h:30
unsigned short u16
16-Bit Unsigned Int
Definition nums.h:36
unsigned char u8
8-Bit Unsigned Int
Definition nums.h:32
Definition idtirq.h:58
u8 base_high
Definition idtirq.h:64
u8 base_middle
Definition idtirq.h:61
u8 granularity
Definition idtirq.h:63
u8 access
Definition idtirq.h:62
u16 limit_low
Definition idtirq.h:59
u16 base_low
Definition idtirq.h:60
u32 base
Definition idtirq.h:69
u16 limit
Definition idtirq.h:68
Definition idtirq.h:50
u16 sel
Definition idtirq.h:52
u8 always0
Definition idtirq.h:53
u16 base_lo
Definition idtirq.h:51
u8 flags
Definition idtirq.h:54
u16 base_hi
Definition idtirq.h:55
u16 limit
Definition idtirq.h:73
u32 base
Definition idtirq.h:74