fix (gdt): NoxOS now loads its own GDT instead of using limines

This commit is contained in:
antifallobst 2023-03-05 15:40:15 +01:00
parent fc148378f7
commit e078840aef
4 changed files with 98 additions and 23 deletions

View File

@ -28,8 +28,39 @@
typedef enum {
GDT_SELECTOR_NULL = 0x00,
GDT_SELECTOR_KERNEL_CODE = 0x28,
GDT_SELECTOR_KERNEL_DATA = 0x30,
GDT_SELECTOR_KERNEL_CODE = 0x08,
GDT_SELECTOR_KERNEL_DATA = 0x10,
GDT_SELECTOR_USER_NULL = 0x18,
GDT_SELECTOR_USER_CODE = 0x20,
GDT_SELECTOR_USER_DATA = 0x28
} gdt_selector_E;
typedef struct {
uint16_t size;
uint64_t offset;
}__attribute__((packed)) gdt_descriptor_T;
typedef struct {
uint16_t limit0;
uint16_t base0;
uint8_t base1;
uint8_t access;
uint8_t limit1_flags;
uint8_t base2;
}__attribute__((packed)) gdt_entry_T;
typedef struct {
gdt_entry_T null; // 0x00
gdt_entry_T kernel_code; // 0x08
gdt_entry_T kernel_data; // 0x10
gdt_entry_T user_null; // 0x18
gdt_entry_T user_code; // 0x20
gdt_entry_T user_data; // 0x28
}__attribute__((packed)) __attribute__((aligned(0x1000))) gdt_T;
extern gdt_T g_default_gdt;
void gdt_init();
#endif //NOX_GDT_H

View File

@ -26,6 +26,7 @@
#include "utils/memory.h"
#include "boot/boot_info.h"
#include "platform/interrupts.h"
#include "platform/gdt.h"
#include "mm/page_frame.h"
#include "mm/page_map.h"
#include "mm/region.h"
@ -39,42 +40,25 @@ void limine_terminal_print(boot_info_T* boot_info, string_t string) {
}
void kernel_init(boot_info_T* boot_info) {
limine_terminal_print(boot_info, " Initializing page frame manager...");
pframe_manager_init(boot_info);
limine_terminal_print(boot_info, " ok\n");
CORE_INTERRUPTS_DISABLE
limine_terminal_print(boot_info, " Initializing idt...");
gdt_init();
idt_init();
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing pic...");
pic_init();
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing pit...");
pit_set_divisor(PIT_DIVISOR);
limine_terminal_print(boot_info, " ok\n");
CORE_INTERRUPTS_ENABLE
limine_terminal_print(boot_info, " Initializing paging...");
paging_init();
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing heap...");
memory_allocator_init((void*)MEM_REGION_KERNEL_HEAP);
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing graphics renderer...");
graphics_renderer_init(boot_info);
graphical_log_init();
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing virtual file system...");
vfs_init(boot_info);
limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing scheduler...");
scheduler_init(boot_info);
limine_terminal_print(boot_info, " ok\n");
}
void kmain(boot_info_T boot_info) {
@ -84,7 +68,6 @@ void kmain(boot_info_T boot_info) {
kernel_init(&boot_info);
limine_terminal_print(&boot_info, "Kernel initialized\n");
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
page_map_dump_info(g_kernel_page_map);

47
kernel/src/platform/gdt.c Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "platform/gdt.h"
#include "utils/logger.h"
extern void gdt_load(gdt_descriptor_T* gdt_descriptor);
__attribute__((aligned(0x1000)))
gdt_T g_default_gdt = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x9A, 0xA0, 0x00},
{0x00, 0x00, 0x00, 0x92, 0xA0, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x9A, 0xA0, 0x00},
{0x00, 0x00, 0x00, 0x92, 0xA0, 0x00}
};
void gdt_init() {
gdt_descriptor_T descriptor;
descriptor.size = sizeof(gdt_T) - 1;
descriptor.offset = (uint64_t)&g_default_gdt;
gdt_load(&descriptor);
log(LOG_INFO, "GDT loaded");
}

View File

@ -20,6 +20,20 @@
; OTHER DEALINGS IN THE SOFTWARE.
gdt_load:
lgdt [rax]
ret
lgdt [rdi]
push 0x08
lea rax, [rel .reload_data_segment_registers]
push rax
retfq
.reload_data_segment_registers:
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
ret
GLOBAL gdt_load