WKern
Loading...
Searching...
No Matches
gdt.c
Go to the documentation of this file.
1
/*
2
WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3
Copyright (C) 2025 Wdboyes13
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <https://www.gnu.org/licenses/>.
17
*/
18
19
#include <
idt/idtirq.h
>
21
struct
GdtEntry
gdt
[3];
22
24
struct
GdtPtr
gp
;
25
35
void
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
56
void
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
}
GdtSetGate
void GdtSetGate(int num, u32 base, u32 limit, u8 access, u8 gran)
Set a GDT entry (descriptor)
Definition
gdt.c:35
GdtInstall
void GdtInstall()
Initialize and load the Global Descriptor Table (GDT)
Definition
gdt.c:56
gdt
struct GdtEntry gdt[3]
Definition
gdt.c:21
gp
struct GdtPtr gp
Definition
gdt.c:24
idtirq.h
GdtFlush
void GdtFlush(u32)
u32
unsigned int u32
32-Bit Unsigned Int
Definition
nums.h:30
uptr
unsigned long uptr
Long Unsigned Int.
Definition
nums.h:34
u8
unsigned char u8
8-Bit Unsigned Int
Definition
nums.h:32
GdtEntry
Definition
idtirq.h:58
GdtPtr
Definition
idtirq.h:67
GdtPtr::base
u32 base
Definition
idtirq.h:69
GdtPtr::limit
u16 limit
Definition
idtirq.h:68
src
idt
gdt.c
Generated on
for WKern by
1.14.0