trying out a new version of gdt initialization

This commit is contained in:
shockrah 2019-10-14 00:45:40 -07:00
parent c94252c3f2
commit d68f4b5264
4 changed files with 14 additions and 12 deletions

10
gdt.c
View File

@ -28,12 +28,16 @@ void gdt_configure() {
// Granularity: 4KB
// 32-bit opcodes
// Code segment selector
gdt_configure_entry(1, 0, 0xffffffff, 0x9a, 0xcf);
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);
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();
load_gdt(&gdt_ptr);
}

4
gdt.h
View File

@ -1,7 +1,7 @@
#include "types.h"
#define NO_GDT_ENTRIES 3
#define NO_GDT_ENTRIES 5
struct GDT_Entry {
u16 low_limit;
@ -22,7 +22,7 @@ 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();
extern void load_gdt(struct GDT_PTR* ptr);
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran);

View File

@ -2,16 +2,16 @@ global load_gdt
extern gdt_ptr
load_gdt:
lgdt [gdt_ptr]
lgdt [esp+4]
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
jmp 0x08:.flush_cs ; far jump to the code segment
flush_cs:
ret ; here we go back to the caller code but with our segments configured
.flush_cs:
ret

View File

@ -23,9 +23,7 @@ align 4
; sets up our gdt and segment selectors for later use
loader:
; load the gdt that I setup
call load_gdt
;call gdt_configure
call gdt_configure
call test_dispatcher
.loop: