diff --git a/include/disk.h b/include/disk.h index 7a38da2..adf77a3 100644 --- a/include/disk.h +++ b/include/disk.h @@ -1,8 +1,8 @@ #ifndef DRIVE_H #define DRIVE_H -#include "stdint.h" -#include "system.h" +#include +#include #define PIO_PORT 0x1f0 #define READ_COMMAND 0x20 diff --git a/include/exceptions.h b/include/exceptions.h index 77182a0..52727a4 100644 --- a/include/exceptions.h +++ b/include/exceptions.h @@ -1,26 +1,8 @@ #ifndef ISRS_H #define ISRS_H -#include "idt.h" -#include "screen.h" - -/* - Alignment Check - Machine Check - Reserved - ... - Reserved -*/ - -// TODO: Make proper handlers -__attribute__ ((naked)) // Temporary handler -void excpHandler(void) { - __asm__ volatile ( - ".intel_syntax\n" - "iretd\n" - ".att_syntax" - ); -} +#include +#include // Exception handlers __attribute__ ((interrupt)) diff --git a/include/graphics.h b/include/graphics.h index 436d4a9..df182fb 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -1,9 +1,9 @@ #ifndef GRAPHICS_H #define GRAPHICS_H -#include "stdint.h" -#include "screen.h" -#include "math.h" +#include +#include +#include #define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff ) diff --git a/include/idt.h b/include/idt.h index 46872b2..88bf031 100644 --- a/include/idt.h +++ b/include/idt.h @@ -1,8 +1,8 @@ #ifndef IDT_H #define IDT_H -#include "stdint.h" -#include "screen.h" +#include +#include #define TRAP_GATE_FLAGS 0x8f // P = 1, DPL = 00, S = 0, Type = 1111 (32-bit Trap gate) #define INT_GATE_FLAGS 0x8e // P = 1, DPL = 00, S = 0, Type = 1110 (32-bit Int gate) diff --git a/include/keyboard.h b/include/keyboard.h index cb27ff0..bb84382 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -1,12 +1,12 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include "idt.h" -#include "pic.h" -#include "system.h" -#include "screen.h" -#include "stdint.h" -#include "stdbool.h" +#include +#include +#include +#include +#include +#include // Keycodes #define LEFT_SHIFT_PRESS 0x2a @@ -52,7 +52,8 @@ bool echo = false; bool canBackspace = false; // TODO: Refactor this -void keyboardHandler() { +__attribute__ ((interrupt)) +void keyboardHandler(intFrame_t* iframe) { uint8_t scancode; scancode = inb(0x60); @@ -74,6 +75,8 @@ void keyboardHandler() { if (bufferLen > 0) canBackspace = true; else canBackspace = false; } + + sendPicEOI(1); } // TODO: Add a 'char readc();' function that returns a single read character and use it for read() @@ -92,8 +95,8 @@ char* read(char terminator) { } void setupKeyboard() { - idtSetGate(33, keyboardHandler, INT_GATE_FLAGS); - setIrqMask(1); + idtSetGate(0x21, keyboardHandler, INT_GATE_FLAGS); + unsetIrqMask(1); } #endif diff --git a/include/physicalMemManager.h b/include/physicalMemManager.h index 5341e1a..65a322a 100644 --- a/include/physicalMemManager.h +++ b/include/physicalMemManager.h @@ -1,8 +1,8 @@ #ifndef PHYSICAL_MEM_MANAGER_H #define PHYSICAL_MEM_MANAGER_H -#include "string.h" -#include "stdint.h" +#include +#include #define BLOCK_SIZE 4096 // 4kB #define BLOCKS_PER_BYTE 8 diff --git a/include/pic.h b/include/pic.h index f861164..8445351 100644 --- a/include/pic.h +++ b/include/pic.h @@ -1,7 +1,7 @@ #ifndef PIC_H #define PIC_H -#include "system.h" +#include // PIC I/O Ports #define PIC_1_CMD 0x20 diff --git a/include/screen.h b/include/screen.h index 7d2567f..51815b5 100644 --- a/include/screen.h +++ b/include/screen.h @@ -1,8 +1,8 @@ #ifndef SCREEN_H #define SCREEN_H -#include "stdint.h" -#include "string.h" +#include +#include // Basic full saturation colors #define BLACK 0x00000000 // 0 diff --git a/include/string.h b/include/string.h index 79a60d6..cc0dce8 100644 --- a/include/string.h +++ b/include/string.h @@ -1,7 +1,7 @@ #ifndef STRING_H #define STRING_H -#include "stdint.h" +#include // Source: http://www.strudel.org.uk/itoa/ char* itoa(uint32_t val, uint8_t base) { diff --git a/include/syscall.h b/include/syscall.h index b854d96..5eebb1b 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -1,7 +1,7 @@ #ifndef SYSCALL_H #define SYSCALL_H -#include "screen.h" +#include // System call count #define MAX_SYSCALLS 2 diff --git a/include/system.h b/include/system.h index d35faa9..eb07383 100644 --- a/include/system.h +++ b/include/system.h @@ -1,7 +1,7 @@ #ifndef SYSTEM_H #define SYSTEM_H -#include "stdint.h" +#include // Port functions uint8_t inb(uint16_t port) { diff --git a/include/timer.h b/include/timer.h index 633e09b..be75a3b 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,27 +1,30 @@ #ifndef TIMER_H #define TIMER_H -#include "stdint.h" -#include "idt.h" -#include "irq.h" -#include "system.h" - -#include "screen.h" +#include +#include +#include +#include +#include #define INPUT_CLK 1193180 uint32_t timerTicks = 0; -void timerHandler() { +__attribute__ ((interrupt)) +void timerHandler(intFrame_t* iframe) { timerTicks++; // TODO: Improve the cursor rendering if (timerTicks % 500 == 0) putcAt(127, cursor.x, cursor.y); else if (timerTicks % 250 == 0) putcAt(' ', cursor.x, cursor.y); + + sendPicEOI(0); } void setupTimer() { - installIrqHandler(0, timerHandler); + idtSetGate(32, timerHandler, INT_GATE_FLAGS); + unsetIrqMask(0); } // Source: https://en.wikibooks.org/wiki/X86_Assembly/Programmable_Interval_Timer diff --git a/src/kernel.c b/src/kernel.c index 05deb80..d5d6183 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,14 +1,15 @@ -#include "physicalMemManager.h" // TODO: Name this better -#include "disk.h" -#include "screen.h" -#include "idt.h" -#include "exceptions.h" -#include "syscall.h" -#include "pic.h" -#include "system.h" -#include "string.h" -#include "graphics.h" -#include "keyboard.h" +#include // TODO: Name this better +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define PROMPT "#> " @@ -52,18 +53,16 @@ void main() { 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(); + setupTimer(); + timerPhase(1000); // 1 kHz + setupKeyboard(); // Run Interactive Shell Program // TODO: Make it in another file while (1) { print(PROMPT); char* input = read('\n'); - + if (input[0] == '\n') continue; char* args; @@ -207,7 +206,11 @@ void main() { } else { print("[ FAIL ]\n"); } - print("Tests Finished!\n"); + print("Syscall Test:\n"); + __asm__ volatile ("movl $0, %eax; int $0x80"); // Syscall(0); + __asm__ volatile ("movl $1, %eax; int $0x80"); // Syscall(1); + + print("\nTests Finished!\n"); } else { char* ft = filetable; uint8_t found = 0;