base working kernel with a gdt that doesn't restart emulator(no idea why this works yet)
This commit is contained in:
parent
535f88a908
commit
a417a74731
2
gdt.c
2
gdt.c
@ -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
2
gdt.h
@ -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);
|
||||
|
||||
|
@ -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
15
kernel.c
Normal 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
|
||||
}
|
12
loader.s
12
loader.s
@ -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
|
||||
|
2
makefile
2
makefile
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user