base working kernel with a gdt that doesn't restart emulator(no idea why this works yet)

This commit is contained in:
shockrah 2019-10-14 02:06:50 -07:00
parent 535f88a908
commit a417a74731
7 changed files with 29 additions and 14 deletions

2
gdt.c
View File

@ -39,5 +39,5 @@ void gdt_configure() {
gdt_configure_entry(4, 0, 0xffffffff, 0xf2, 0xcf);
// Load in the new changes to the gdt
load_gdt(&gdt_ptr);
load_gdt();
}

2
gdt.h
View File

@ -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(struct GDT_PTR* ptr);
extern void load_gdt();
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 [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:
flush_cs:
lgdt [gdt_ptr]
ret

15
kernel.c Normal file
View File

@ -0,0 +1,15 @@
#include "types.h"
#include "tests.h"
#include "gdt.h"
#include "kernel.h"
void kinit() {
gdt_configure();
test_dispatcher();
}
void kmain() {
kinit();
for(;;); // the most amazing loop
}

4
kernel.h Normal file
View File

@ -0,0 +1,4 @@
#include "types.h"
void kinit();
void kmain();

View File

@ -1,16 +1,13 @@
; since we have no stack we have to create one for the OS
global loader
; this section is partly handled by nasm tolerating some minor bs
; NOTE: these symbols are what we use to represent the "magic bytes" for the whole os
MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
KERNEL_STACK_SIZE equ 4096
; size in bytes of stack
extern gdt_configure
extern test_dispatcher
extern kmain
section .text
; align all instructions to 4 byte boundary by the x86 instruction set law
@ -23,8 +20,7 @@ align 4
; sets up our gdt and segment selectors for later use
loader:
call gdt_configure
call test_dispatcher
call kmain
.loop:
jmp .loop

View File

@ -3,7 +3,7 @@ ASM=nasm
LINK=ld
ISO=genisoimage
OBJECTS=gdt_seg.o gdt.o loader.o serial.o framebuffer.o ports.o stlio.o tests.o
OBJECTS=kernel.o gdt_seg.o gdt.o loader.o serial.o framebuffer.o ports.o stlio.o tests.o
AFLAGS=-f elf32
CFLAGS=-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \
-nodefaultlibs -Wall -Wextra -Werror -c