LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
gdt.c File Reference

Initializes and holds the GDT for the kernel. More...

#include <arch/x86_64/gdt.h>
#include <lib/kstring.h>
#include <stdbool.h>
#include <kernel/tools.h>
#include <kernel/log.h>
#include <stdint.h>
Include dependency graph for gdt.c:

Go to the source code of this file.

Functions

static uint8_t ist1_stack[16384] __attribute__ ((aligned(16)))
void init_gdt (void)
 Initializes the gdt and loads it.
void gdt_set_entry (int index, uint8_t access, uint8_t flags)
 Sets an entry of the gdt with the correct access and flags.
uint8_t get_access_byte (bool rw, bool exec, bool type, uint8_t dpl)
 Generates the access byte for the GDT.
uint8_t get_flag_byte (bool granularity, bool size, bool long_mode)
 Generates the flag byte for the GDT.

Variables

struct gdt_entry gdt [7]
struct gdtr _gdtr
struct tss tss_data

Detailed Description

Initializes and holds the GDT for the kernel.

Author
Matheus Boscariol
Since
15/11/2026

Definition in file gdt.c.

Function Documentation

◆ gdt_set_entry()

void gdt_set_entry ( int index,
uint8_t access,
uint8_t flags )

Sets an entry of the gdt with the correct access and flags.

Parameters
indexThe GDT entry index
accessThe access byte
flagsThe flag and limit byte

Definition at line 110 of file gdt.c.

◆ get_access_byte()

uint8_t get_access_byte ( bool rw,
bool exec,
bool type,
uint8_t dpl )

Generates the access byte for the GDT.

Parameters
rwIs the entry readable or writable (data or code)
execIs the entry executable (code or data)
typeDescriptor type (code/data or system)
dplPrivilege level (0 = kernel, 3 = user)
Returns
The full access byte

Definition at line 120 of file gdt.c.

◆ get_flag_byte()

uint8_t get_flag_byte ( bool granularity,
bool size,
bool long_mode )

Generates the flag byte for the GDT.

Parameters
granularityLimit counts bytes or 4kib pages
size16-bit segments or 32-bit segments
long_modeIs a long mode segment
Returns
The full flag byte with limit = 0

Definition at line 128 of file gdt.c.

◆ init_gdt()

void init_gdt ( void )

Initializes the gdt and loads it.

Definition at line 29 of file gdt.c.

Here is the call graph for this function:

Variable Documentation

◆ _gdtr

struct gdtr _gdtr

Definition at line 17 of file gdt.c.

◆ gdt

struct gdt_entry gdt[7]

Definition at line 16 of file gdt.c.

◆ tss_data

struct tss tss_data

Definition at line 18 of file gdt.c.