diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-02 10:16:53 -0500 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-02 10:16:53 -0500 |
| commit | 2846b53653736b2df2a81935bc68c6db2c69408a (patch) | |
| tree | b37e3cc4ea7934e56e90f8b34d93ecabd80b23c5 /kernel/boot/gdt/gdt.c | |
| parent | 88a43d6088195abc6610339098303a3f56e00035 (diff) | |
kernel: Move gdt to its own subdirectory
Diffstat (limited to 'kernel/boot/gdt/gdt.c')
| -rw-r--r-- | kernel/boot/gdt/gdt.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/kernel/boot/gdt/gdt.c b/kernel/boot/gdt/gdt.c new file mode 100644 index 0000000..4644b3d --- /dev/null +++ b/kernel/boot/gdt/gdt.c @@ -0,0 +1,51 @@ +/* + * CMOS + * Copyright (C) 2024-2025 Raghuram Subramani <raghus2247@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdint.h> + +#include <kernel/io.h> + +#include <boot/gdt.h> + +GDT_entry GDT[] = { + /* NULL Descriptor */ + GDT_ENTRY(0, 0, 0, 0), + + /* Kernel Mode Code Segment */ + GDT_ENTRY(0, 0xfffff, KERNEL_CODE_SEGMENT_ACCESS_FLAGS, FLAGS), + + /* Kernel Mode Data Segment */ + GDT_ENTRY(0, 0xfffff, KERNEL_DATA_SEGMENT_ACCESS_FLAGS, FLAGS), + + /* User Mode Code Segment */ + GDT_ENTRY(0, 0xfffff, USER_CODE_SEGMENT_ACCESS_FLAGS, FLAGS), + + /* User Mode Data Segment */ + GDT_ENTRY(0, 0xfffff, USER_DATA_SEGMENT_ACCESS_FLAGS, FLAGS) + + /* TODO: TSS? */ + /* TODO: LDT? */ +}; + +GDT_descriptor g_GDT_descriptor = { sizeof(GDT_entry) * 5 - 1, &GDT[0] }; + +void +GDT_load(void) +{ + _GDT_flush(&g_GDT_descriptor); +} |
