From 990a74798cfc9f8cedb1f8ff16765e4012924da8 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sun, 5 Mar 2023 15:57:56 +0100 Subject: [PATCH] docs: documented GDT changes --- .wiki/Kernel-documentation.md | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.wiki/Kernel-documentation.md b/.wiki/Kernel-documentation.md index 1380b7f..fca17ef 100644 --- a/.wiki/Kernel-documentation.md +++ b/.wiki/Kernel-documentation.md @@ -1068,8 +1068,44 @@ OSDev Wiki: [Global Descriptor Table](https://wiki.osdev.org/GDT) - **Null** - **Kernel Code** - Readable - **Kernel Data** - Readable + Writable +- **User Null** +- **User Code** - Readable +- **User Data** - Readable + Writable -NoxOS uses the GDT loaded by limine, because in 64 bit mode a GDT is only needed for backwards compatability. +#### `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). ### interrupts.h This header contains all the stuff, needed to init and handle Interrupts.