Moving components modules to a more proper directory

This commit is contained in:
2023-03-30 22:40:08 -07:00
parent 044d5a75b5
commit cc1bb63e27
26 changed files with 11 additions and 148 deletions

43
components/gdt/gdt.c Normal file
View File

@@ -0,0 +1,43 @@
#include "gdt.h"
// Congirures a given gdt entry base on the entry index given
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran) {
// base address
gdt_entries[entry].low_base = (base & 0xffff);
gdt_entries[entry].middle_base = (base >> 16) & 0xff;
gdt_entries[entry].high_base = (base >> 24) & 0xff;
// descriptor limits
gdt_entries[entry].low_limit = (limit & 0xffff);
gdt_entries[entry].granular = ((limit >> 16) & 0x0f);
gdt_entries[entry].granular |= (gran & 0xf0);
gdt_entries[entry].access = access;
}
// Configure the gdt pointer desribed in gdt.h as type GDT_PTR
void gdt_configure() {
// gdt_ptr configuration
gdt_ptr.size = (sizeof(struct GDT_Entry) * NO_GDT_ENTRIES) - 1;
// First entry is just the null descriptor and is left along overall
gdt_configure_entry(0, 0, 0, 0, 0);
// Second entry: code segment base adders
// Base address: 0
// limit: 4GB
// Granularity: 4KB
// 32-bit opcodes
// Code segment selector
gdt_configure_entry(1, 0, 0xffffffff, 0x9a, 0xcf); // code segment
// Finally the data segment
// All the same except the desriptor type specifies that its data
gdt_configure_entry(2, 0, 0xffffffff, 0x92, 0xcf); // data segment
// user mode segments
gdt_configure_entry(3, 0, 0xffffffff, 0xfa, 0xcf);
gdt_configure_entry(4, 0, 0xffffffff, 0xf2, 0xcf);
// Load in the new changes to the gdt
load_gdt();
}

32
components/gdt/gdt.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef GDT_H
#define GDT_H
#include "types.h"
#define NO_GDT_ENTRIES 5
struct GDT_Entry {
u16 low_limit;
u16 low_base;
u8 middle_base;
u8 access;
u8 granular;
u8 high_base;
}__attribute__((packed));
// Contains the pointer to the first gdt entry as well as the size(of the whole table(?))
struct GDT_PTR {
u16 size;
u32 address;
}__attribute__((packed));
struct GDT_Entry gdt_entries[NO_GDT_ENTRIES];
struct GDT_PTR gdt_ptr;
// this func is actually taken care of in gdt_seg.s
extern void load_gdt();
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran);
void gdt_configure();
#endif

17
components/gdt/gdt_seg.s Normal file
View File

@@ -0,0 +1,17 @@
global load_gdt
extern gdt_ptr
load_gdt:
mov ax, 0x10 ; offset in the gdt to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush_cs ; far jump to the code segment
flush_cs:
lgdt [gdt_ptr]
ret