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

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

#include <lib/kstring.h>
#include <stdbool.h>
#include <kernel/tools.h>
#include <kernel/log.h>
#include <stdint.h>
Include dependency graph for gdt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CODE_DATA_SEGMENT   true
#define LIMIT_BYTES   false
#define LIMIT_4KIB_PAGES   true
#define SEGMENT_32_BIT   true
#define SEGMENT_16_BIT   false

Functions

struct __attribute__ ((packed)) gdt_entry
 Entry to be passed to the gdt.
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.

Detailed Description

Initializes and holds the GDT for the kernel.

Author
Matheus Boscariol
Since
15/11/2026

Definition in file gdt.h.

Macro Definition Documentation

◆ CODE_DATA_SEGMENT

#define CODE_DATA_SEGMENT   true

Definition at line 18 of file gdt.h.

◆ LIMIT_4KIB_PAGES

#define LIMIT_4KIB_PAGES   true

Definition at line 20 of file gdt.h.

◆ LIMIT_BYTES

#define LIMIT_BYTES   false

Definition at line 19 of file gdt.h.

◆ SEGMENT_16_BIT

#define SEGMENT_16_BIT   false

Definition at line 22 of file gdt.h.

◆ SEGMENT_32_BIT

#define SEGMENT_32_BIT   true

Definition at line 21 of file gdt.h.

Function Documentation

◆ __attribute__()

struct __attribute__ ( (packed) )

Entry to be passed to the gdt.

The idtr register holding information about the idt.

Struct to be passed to the cpu holding information about the gdt.

TSS Entry (Equivalent to 2 gdt entries).

Generate access byte with get_access_byte()

Generate flag byte with get_flag_byte()

IST stack addresses

Size of the gdt

Address of the first gdt entry

Definition at line 1 of file gdt.h.

◆ 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: