documentation/kernel/platform/gdt.h.md

50 lines
2.3 KiB
Markdown

# gdt.h
Definitions to handle segments (_Global Descriptor Table_).
Segmentation is deprecated and is only needed for backwards compatibility.
OSDev Wiki: [Global Descriptor Table](https://wiki.osdev.org/GDT)
# `gdt_selector_E` - enum
- **Null**
- **Kernel Code** - Readable
- **Kernel Data** - Readable + Writable
- **User Null**
- **User Code** - Readable
- **User Data** - Readable + Writable
# `gdt_descriptor_T` - struct [packed]
| Name | Type | Description |
|--------|----------|-----------------------------------------------------|
| size | uint16_t | The tables size in bytes (-1) |
| offset | uint64_t | The virtual address, where the table lies in memory |
# `gdt_entry_T` - struct [packed]
| Name | Type | Description |
|--------------|----------|--------------------------------------------------------------|
| limit0 | uint16_t | Can be ignored in long mode |
| base0 | uint16_t | Can be ignored in long mode |
| base1 | uint8_t | Can be ignored in long mode |
| access | uint8_t | Specifies permissions (details in osdev wiki) |
| limit1_flags | uint8_t | The first 4 bits can be ignored and the last 4 specify flags |
| base2 | uint8_t | Can be ignored in long mode |
# `gdt_T` - struct [packed / page aligned]
| Name | Type | Description |
|-------------|-------------|------------------------------------------|
| null | gdt_entry_T | The entry for `GDT_SELECTOR_NULL` |
| kernel_code | gdt_entry_T | The entry for `GDT_SELECTOR_KERNEL_CODE` |
| kernel_data | gdt_entry_T | The entry for `GDT_SELECTOR_KERNEL_DATA` |
| user_null | gdt_entry_T | The entry for `GDT_SELECTOR_USER_NULL` |
| user_code | gdt_entry_T | The entry for `GDT_SELECTOR_USER_CODE` |
| user_data | gdt_entry_T | The entry for `GDT_SELECTOR_USER_DATA` |
# `g_default_gdt` - global variable
The systems GDT.
# `gdt_init` - function (void)
Populates and loads g_default_gdt.
This will also set all the data segment registers to 0x10 (Kernel Data) and `cs` to 0x08 (Kernel Code).