Refactor & stuff

master
E. Almqvist 3 years ago
parent d3e8ff9d1c
commit 82e3a85517
  1. 4
      Makefile
  2. 2
      bootloader/bios/disk.asm
  3. 3
      bootloader/bootloader.asm
  4. 23
      kernel/idt.c
  5. 4
      kernel/io.c
  6. 17
      kernel/isr.asm
  7. 32
      kernel/kernel.c
  8. 4
      kernel/paging.c
  9. 4
      kernel/pic.c

@ -1,6 +1,6 @@
# Compiler/assembler settings
CC = gcc
CFLAGS = -fno-pie -m32 -Os -ffreestanding
CFLAGS = -fno-pie -m32 -Os -ffreestanding -g3
AA = nasm
AFLAGS =
@ -10,7 +10,7 @@ LDFLAGS = -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -
# VM/Debug settings
VM = qemu-system-x86_64
VMFLAGS = -serial stdio -no-reboot -no-shutdown -d int
VMFLAGS = -serial stdio -no-reboot -no-shutdown #-d int
# Do not touch these.

@ -40,6 +40,6 @@ read_error:
jmp $
read_error_string: db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "ERROR! Disk read failed.", ASCII_END
read_error_string: db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "Disk read failed.", ASCII_END
error_code_string: db "Error code: ", ASCII_END
sector_error_string: db "Invalid number of sectors read!", ASCII_END

@ -66,6 +66,9 @@ pm_init:
call BEGIN_PM
BEGIN_PM:
mov [0xee88], byte GDT_CODE_SEG ; save code seg
mov [0xee89], byte GDT_DATA_SEG ; save data seg
; Call the kernel
call KERNEL_OFFSET
jmp $

@ -18,23 +18,26 @@ static idt_entry IDT[IDT_MAX_DESCS];
static idtr IDTR;
void exception_handler() {
uint* irq_ptr = 0xe222;
uint8 irq = *irq_ptr;
uint* exc_ptr = 0xe222;
uint8 exc = *exc_ptr;
pic_send_eoi(exc);
pic_send_eoi(irq);
char* buf;
set_cursor_pos(0, 0);
print("[exc] ", EXC_COLOR);
buf = itoa(irq, buf, 10);
buf = itoa(exc, buf, 10);
print(buf, 0x0c);
new_line();
}
void idt_set_desc(uint8 idx, void* isr, uint8 flags) {
idt_entry* desc = &IDT[idx]; // get descriptor
uint* gdt_code_ptr = 0xee88;
uint8 gdt_code = *gdt_code_ptr;
desc->offset_1 = (uint) isr & 0xffff;
desc->selector = 0x08; // kernel code selector for the GDT
desc->selector = gdt_code; // kernel code selector for the GDT
desc->reserved = 0;
desc->type_attr = flags;
desc->offset_2 = (uint) isr >> 16;
@ -48,6 +51,10 @@ void idt_init() {
for (uint8 idx = 0; idx < 32; idx++)
idt_set_desc(idx, isr_stub_table[idx], 0x8e);
outb_w(PIC1, 0xfd);
outb_w(PIC2, 0xfd);
__asm__ __volatile__("lidt %0" : : "m"(IDTR));
__asm__ __volatile__("sti");
//__asm__ __volatile__("sti");
}

@ -26,9 +26,7 @@ void outw(unsigned short port, unsigned short data) {
}
static inline void io_wait() {
outb(0x80, 0);
}
static inline void io_wait() { outb(0x80, 0); }
unsigned char inb_w(unsigned short port) {
inb(port);

@ -3,43 +3,36 @@ isr_debug_ptr equ 0xe222
%macro isr_err_stub 1
isr_stub_%+%1:
mov [isr_debug_ptr], byte %1
pusha
call exception_handler
sti
hlt
cli
;hlt
popa
iret
%endmacro
%macro isr_no_err_stub 1
isr_stub_%+%1:
mov [isr_debug_ptr], byte %1
pusha
call exception_handler
sti
hlt
cli
;hlt
popa
iret
%endmacro
extern exception_handler
isr_no_err_stub 0
; TODO: make keeb drivers
isr_err_stub 0
isr_err_stub 1
isr_no_err_stub 2
isr_no_err_stub 3
isr_no_err_stub 4
isr_no_err_stub 5
isr_no_err_stub 6
isr_err_stub 6
isr_no_err_stub 7
isr_err_stub 8 ; err
isr_no_err_stub 9 ; keyboard?
isr_err_stub 10
isr_err_stub 11
isr_err_stub 12
isr_err_stub 13
isr_no_err_stub 13
isr_err_stub 14
isr_no_err_stub 15
isr_no_err_stub 16

@ -8,21 +8,37 @@ void print_kernel_motd() {
printalign("| __/ |_| |___) | A x86 operating system,", BANNER_COLOR, MIDDLE);
printalign(" \\___|\\___/|____/ licenced under GPL-2.0", BANNER_COLOR, MIDDLE);
println("");
printalign("Fun fact: e = lim[h->0] (1+h)^(1/h)", DEFAULT_COLOR, MIDDLE);
new_line();
printalign("e = lim[h->0] (1+h)^(1/h)", DEFAULT_COLOR, MIDDLE);
printalign("Created by E. Almqvist", DEFAULT_COLOR, MIDDLE);
println("");
new_line();
}
void print_kernel_stats() {
char* buf;
set_cursor_pos(0, 12);
// GDT stuff
print("GDT Code Seg: ", 0x0f);
uint* code_ptr = 0xee88;
uint8 code = *code_ptr;
buf = itoa(code, buf, 16);
println(buf, DEFAULT_COLOR);
print("GDT Data Seg: ", 0x0f);
uint* data_ptr = 0xee89;
uint8 data = *data_ptr;
buf = itoa(data, buf, 16);
println(buf, DEFAULT_COLOR);
new_line();
// Memory stats
print("MEMORY BITMAP: ", 0x0f);
buf = itoa(get_bitmap(), buf, 2);
println(buf, DEFAULT_COLOR);
println("");
new_line();
println("BIOS E820", 0x0f);
print("Loaded Entries: ", DEFAULT_COLOR);
@ -33,7 +49,7 @@ void print_kernel_stats() {
print("Physical Memory Size: ");
println("?", DEFAULT_COLOR);
println("");
new_line();
// VGA stats
println("Display (VGA)", 0x0f);
@ -56,17 +72,18 @@ void print_kernel_stats() {
void kernel_init() {
pic_init(); // Init the PIC and remap it
idt_init(); // Enable interupts
//enable_paging();
vga_init(); // Initialize the screen
// Allocate VGA memory range
pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
// ENABLE PAGING
// TODO: make this work
//enable_paging();
clear_screen();
print_kernel_motd();
/*
print_kernel_stats();
char* buf;
@ -79,7 +96,6 @@ void kernel_init() {
printalign(buf, 0x0f, MIDDLE);
++i;
}
*/
while(true) { __asm__("hlt"); } // never escape this function
}

@ -4,8 +4,8 @@
void enable_paging() {
println("Enabling paging...", DEFAULT_COLOR);
// extern int enable_paging_registers(); // Call the assembly SR
// enable_paging_registers(); // and enable paging
extern int enable_paging_registers(); // Call the assembly SR
enable_paging_registers(); // and enable paging
return;
}

@ -17,8 +17,8 @@ void pic_remap(uint offset_1, uint offset_2) {
outb_w(PIC2_CMD, ICW_INIT_MASK);
outb_w(PIC1_DATA, offset_1); // ICW2 master offset
outb_w(PIC2_DATA, offset_2); // ICW2 slave offset
outb_w(PIC1_DATA, offset_1);
outb_w(PIC2_DATA, offset_2);
outb_w(PIC1_DATA, 0x4);
outb_w(PIC2_DATA, 0x2);

Loading…
Cancel
Save