mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
[ BIG CHANGE ] Properly Implemented IDT
- New include files: idt.h, pic.h, syscall.h and exceptions.h - Proper exception handling (still could be improved - PIC properly initiated and irqs all masked - BREAKS Keyboard - The keyboard IRQ is not handled anymore - convertColor() is kinda broken :/ (More in README.md)
This commit is contained in:
-345
@@ -3,9 +3,6 @@
|
||||
[global driveNum]
|
||||
|
||||
[extern main]
|
||||
[extern idtp]
|
||||
[extern faultHandler]
|
||||
[extern irqHandler]
|
||||
|
||||
;; Calls the main function in 'main.c'
|
||||
_start:
|
||||
@@ -23,345 +20,3 @@ _start:
|
||||
|
||||
driveNum: db 0
|
||||
|
||||
;;
|
||||
;; --- IDT ---
|
||||
;;
|
||||
[global idtLoad]
|
||||
idtLoad:
|
||||
lidt [idtp]
|
||||
ret
|
||||
|
||||
;; Isrs (exceptions)
|
||||
[global isr0]
|
||||
isr0:
|
||||
cli
|
||||
push 0
|
||||
push 0
|
||||
jmp isrCommon
|
||||
[global isr1]
|
||||
isr1:
|
||||
cli
|
||||
push 0
|
||||
push 1
|
||||
jmp isrCommon
|
||||
[global isr2]
|
||||
isr2:
|
||||
cli
|
||||
push 0
|
||||
push 2
|
||||
jmp isrCommon
|
||||
[global isr3]
|
||||
isr3:
|
||||
cli
|
||||
push 0
|
||||
push 3
|
||||
jmp isrCommon
|
||||
[global isr4]
|
||||
isr4:
|
||||
cli
|
||||
push 0
|
||||
push 4
|
||||
jmp isrCommon
|
||||
[global isr5]
|
||||
isr5:
|
||||
cli
|
||||
push 0
|
||||
push 5
|
||||
jmp isrCommon
|
||||
[global isr6]
|
||||
isr6:
|
||||
cli
|
||||
push 0
|
||||
push 6
|
||||
jmp isrCommon
|
||||
[global isr7]
|
||||
isr7:
|
||||
cli
|
||||
push 0
|
||||
push 7
|
||||
jmp isrCommon
|
||||
[global isr8]
|
||||
isr8:
|
||||
cli
|
||||
push 8
|
||||
jmp isrCommon
|
||||
[global isr9]
|
||||
isr9:
|
||||
cli
|
||||
push 0
|
||||
push 9
|
||||
jmp isrCommon
|
||||
[global isr10]
|
||||
isr10:
|
||||
cli
|
||||
push 10
|
||||
jmp isrCommon
|
||||
[global isr11]
|
||||
isr11:
|
||||
cli
|
||||
push 11
|
||||
jmp isrCommon
|
||||
[global isr12]
|
||||
isr12:
|
||||
cli
|
||||
push 12
|
||||
jmp isrCommon
|
||||
[global isr13]
|
||||
isr13:
|
||||
cli
|
||||
push 13
|
||||
jmp isrCommon
|
||||
[global isr14]
|
||||
isr14:
|
||||
cli
|
||||
push 14
|
||||
jmp isrCommon
|
||||
[global isr15]
|
||||
isr15:
|
||||
cli
|
||||
push 0
|
||||
push 15
|
||||
jmp isrCommon
|
||||
[global isr16]
|
||||
isr16:
|
||||
cli
|
||||
push 0
|
||||
push 16
|
||||
jmp isrCommon
|
||||
[global isr17]
|
||||
isr17:
|
||||
cli
|
||||
push 0
|
||||
push 17
|
||||
jmp isrCommon
|
||||
[global isr18]
|
||||
isr18:
|
||||
cli
|
||||
push 0
|
||||
push 18
|
||||
jmp isrCommon
|
||||
[global isr19]
|
||||
isr19:
|
||||
cli
|
||||
push 0
|
||||
push 19
|
||||
jmp isrCommon
|
||||
[global isr20]
|
||||
isr20:
|
||||
cli
|
||||
push 0
|
||||
push 20
|
||||
jmp isrCommon
|
||||
[global isr21]
|
||||
isr21:
|
||||
cli
|
||||
push 0
|
||||
push 21
|
||||
jmp isrCommon
|
||||
[global isr22]
|
||||
isr22:
|
||||
cli
|
||||
push 0
|
||||
push 22
|
||||
jmp isrCommon
|
||||
[global isr23]
|
||||
isr23:
|
||||
cli
|
||||
push 0
|
||||
push 23
|
||||
jmp isrCommon
|
||||
[global isr24]
|
||||
isr24:
|
||||
cli
|
||||
push 0
|
||||
push 24
|
||||
jmp isrCommon
|
||||
[global isr25]
|
||||
isr25:
|
||||
cli
|
||||
push 0
|
||||
push 25
|
||||
jmp isrCommon
|
||||
[global isr26]
|
||||
isr26:
|
||||
cli
|
||||
push 0
|
||||
push 26
|
||||
jmp isrCommon
|
||||
[global isr27]
|
||||
isr27:
|
||||
cli
|
||||
push 0
|
||||
push 27
|
||||
jmp isrCommon
|
||||
[global isr28]
|
||||
isr28:
|
||||
cli
|
||||
push 0
|
||||
push 28
|
||||
jmp isrCommon
|
||||
[global isr29]
|
||||
isr29:
|
||||
cli
|
||||
push 0
|
||||
push 29
|
||||
jmp isrCommon
|
||||
[global isr30]
|
||||
isr30:
|
||||
cli
|
||||
push 0
|
||||
push 30
|
||||
jmp isrCommon
|
||||
[global isr31]
|
||||
isr31:
|
||||
cli
|
||||
push 0
|
||||
push 31
|
||||
jmp isrCommon
|
||||
|
||||
isrCommon: ; No clue how this works, i'm pretty sure it calls the C function and has to push the registers or something idk
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp
|
||||
push eax
|
||||
mov eax, faultHandler
|
||||
call eax
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
;; IRQs
|
||||
[global irq0]
|
||||
irq0:
|
||||
cli
|
||||
push 0
|
||||
push 32
|
||||
jmp irqCommon
|
||||
[global irq1]
|
||||
irq1:
|
||||
cli
|
||||
push 0
|
||||
push 33
|
||||
jmp irqCommon
|
||||
[global irq2]
|
||||
irq2:
|
||||
cli
|
||||
push 0
|
||||
push 34
|
||||
jmp irqCommon
|
||||
[global irq3]
|
||||
irq3:
|
||||
cli
|
||||
push 0
|
||||
push 35
|
||||
jmp irqCommon
|
||||
[global irq4]
|
||||
irq4:
|
||||
cli
|
||||
push 0
|
||||
push 36
|
||||
jmp irqCommon
|
||||
[global irq5]
|
||||
irq5:
|
||||
cli
|
||||
push 0
|
||||
push 37
|
||||
jmp irqCommon
|
||||
[global irq6]
|
||||
irq6:
|
||||
cli
|
||||
push 0
|
||||
push 38
|
||||
jmp irqCommon
|
||||
[global irq7]
|
||||
irq7:
|
||||
cli
|
||||
push 0
|
||||
push 39
|
||||
jmp irqCommon
|
||||
[global irq8]
|
||||
irq8:
|
||||
cli
|
||||
push 0
|
||||
push 40
|
||||
jmp irqCommon
|
||||
[global irq9]
|
||||
irq9:
|
||||
cli
|
||||
push 0
|
||||
push 41
|
||||
jmp irqCommon
|
||||
[global irq10]
|
||||
irq10:
|
||||
cli
|
||||
push 0
|
||||
push 42
|
||||
jmp irqCommon
|
||||
[global irq11]
|
||||
irq11:
|
||||
cli
|
||||
push 0
|
||||
push 43
|
||||
jmp irqCommon
|
||||
[global irq12]
|
||||
irq12:
|
||||
cli
|
||||
push 0
|
||||
push 44
|
||||
jmp irqCommon
|
||||
[global irq13]
|
||||
irq13:
|
||||
cli
|
||||
push 0
|
||||
push 45
|
||||
jmp irqCommon
|
||||
[global irq14]
|
||||
irq14:
|
||||
cli
|
||||
push 0
|
||||
push 46
|
||||
jmp irqCommon
|
||||
[global irq15]
|
||||
irq15:
|
||||
cli
|
||||
push 0
|
||||
push 47
|
||||
jmp irqCommon
|
||||
|
||||
irqCommon: ; Simular to isrCommon, probaly calls the C function
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp
|
||||
push eax
|
||||
mov eax, irqHandler
|
||||
call eax
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
|
||||
+22
-19
@@ -1,14 +1,14 @@
|
||||
#include "physicalMemManager.h" // TODO: Name this better
|
||||
#include "disk.h"
|
||||
#include "screen.h"
|
||||
#include "idt.h"
|
||||
#include "isrs.h"
|
||||
#include "irq.h"
|
||||
#include "keyboard.h"
|
||||
#include "timer.h"
|
||||
#include "exceptions.h"
|
||||
#include "syscall.h"
|
||||
#include "pic.h"
|
||||
#include "system.h"
|
||||
#include "disk.h"
|
||||
#include "string.h"
|
||||
#include "graphics.h"
|
||||
#include "physicalMemManager.h" // TODO: Name this better
|
||||
#include "keyboard.h"
|
||||
|
||||
#define PROMPT "#> "
|
||||
|
||||
@@ -20,16 +20,6 @@ void printFiletable(char* ft);
|
||||
void printPhysicalMemmap();
|
||||
|
||||
void main() {
|
||||
// Interrupts
|
||||
setupIdt();
|
||||
setupIsrs();
|
||||
setupIrqs();
|
||||
sti();
|
||||
|
||||
setupKeyboard();
|
||||
setupTimer();
|
||||
timerPhase(1000); // 1 tick per ~1ms
|
||||
|
||||
// Memory manager setup
|
||||
uint32_t smapEntryCount = *(uint32_t*)0x8500;
|
||||
smapEntry_t* smapEntries = (smapEntry_t*)0x8504;
|
||||
@@ -46,14 +36,27 @@ void main() {
|
||||
deinitMemoryRegion(0x1000, 0x9000); // Reserve kernel memory (under 0xa000)
|
||||
deinitMemoryRegion(memmapAddr, maxBlocks / BLOCKS_PER_BYTE);
|
||||
|
||||
// Screen setup
|
||||
// TODO: Find font in filetable
|
||||
diskRead(36, 4, font); // Read font from disk
|
||||
|
||||
|
||||
clear();
|
||||
print("kern.\n\n");
|
||||
|
||||
diskRead(5, 1, filetable); // Read the filetable and store it in memory
|
||||
|
||||
// Interrupts
|
||||
setupIdt();
|
||||
setupExceptions();
|
||||
idtSetGate(0x80, syscallHandler, USR_INT_GAME_FLAGS); // Setup Syscall handler in IDT for int 0x80
|
||||
disableIrqs();
|
||||
remapPic();
|
||||
__asm__ volatile ("sti");
|
||||
|
||||
// Syscall Test!
|
||||
__asm__ volatile ("movl $0, %eax; int $0x80"); // Syscall(0);
|
||||
__asm__ volatile ("movl $1, %eax; int $0x80"); // Syscall(1);
|
||||
|
||||
//setupKeyboard();
|
||||
|
||||
// Run Interactive Shell Program
|
||||
// TODO: Make it in another file
|
||||
@@ -164,7 +167,7 @@ void main() {
|
||||
drawCircle(1500, 600, 300, WHITE);
|
||||
fillCircle(950, 750, 75, rgb(0xa2, 0xd6, 0xf9));
|
||||
|
||||
read('q'); // Wait until we get a 'q'
|
||||
//read('q'); // Wait until we get a 'q'
|
||||
clear();
|
||||
} else if (strcmp(input, "help") == 0) {
|
||||
print("Available Commands:\n");
|
||||
|
||||
+3
-3
@@ -372,9 +372,9 @@ DATA_SEG equ GDT.dataDescriptor - GDT.start
|
||||
|
||||
;; VBE Stuff
|
||||
;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !!
|
||||
width: dw 0
|
||||
height: dw 0
|
||||
bpp: db 0
|
||||
width: dw 1920
|
||||
height: dw 1080
|
||||
bpp: db 32
|
||||
|
||||
offset: dw 0
|
||||
_segment: dw 0 ; segment is a keyword
|
||||
|
||||
Reference in New Issue
Block a user