WKern
Loading...
Searching...
No Matches
gdt.c
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#include <idt/idtirq.h>
21struct GdtEntry gdt[3];
22
24struct GdtPtr gp;
25
35void GdtSetGate(int num, u32 base, u32 limit, u8 access, u8 gran) {
36 gdt[num].base_low = (base & 0xFFFF);
37 gdt[num].base_middle = (base >> 16) & 0xFF;
38 gdt[num].base_high = (base >> 24) & 0xFF;
39
40 gdt[num].limit_low = (limit & 0xFFFF);
41 gdt[num].granularity = ((limit >> 16) & 0x0F);
42
43 gdt[num].granularity |= (gran & 0xF0);
44 gdt[num].access = access;
45}
46
56void GdtInstall() {
57 gp.limit = (sizeof(struct GdtEntry) * 3) - 1;
58 gp.base = (uptr)&gdt;
59
60 GdtSetGate(0, 0, 0, 0, 0);
61 GdtSetGate(1, 0, 0xFFFFF, 0x9A, 0xCF);
62 GdtSetGate(2, 0, 0xFFFFF, 0x92, 0xCF);
63
64 GdtFlush((uptr)&gp);
65}
void GdtSetGate(int num, u32 base, u32 limit, u8 access, u8 gran)
Set a GDT entry (descriptor)
Definition gdt.c:35
void GdtInstall()
Initialize and load the Global Descriptor Table (GDT)
Definition gdt.c:56
struct GdtEntry gdt[3]
Definition gdt.c:21
struct GdtPtr gp
Definition gdt.c:24
void GdtFlush(u32)
unsigned int u32
32-Bit Unsigned Int
Definition nums.h:30
unsigned long uptr
Long Unsigned Int.
Definition nums.h:34
unsigned char u8
8-Bit Unsigned Int
Definition nums.h:32
Definition idtirq.h:58
u32 base
Definition idtirq.h:69
u16 limit
Definition idtirq.h:68