diff --git a/boot/stage3.c b/boot/stage3.c index 580a297..11be2a7 100644 --- a/boot/stage3.c +++ b/boot/stage3.c @@ -3,11 +3,12 @@ #include #include #include -#include -#include -#include +#include +#include #include +void bigError(uint32_t err); + __attribute__ ((section("entry"))) void main() { // Physical memory manager setup @@ -80,3 +81,58 @@ void main() { bigError(0xffffffff); } +void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { + uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; + uint8_t bytesPerPx = gfxMode->bpp / 8; + uint32_t convColor = convertColor(c); + + for (uint32_t dx = 0; dx < w; dx++) { + for (uint32_t dy = 0; dy < h; dy++) { + uint32_t offset = (((y + dy) * gfxMode->xRes) + (x + dx)) * bytesPerPx; + + for (uint8_t i = 0; i < gfxMode->bpp; i++) { + vidmem[offset + i] = (uint8_t)(convColor >> (i*8)); + } + } + } +} + +void bigError(uint32_t err) { + // Red BG + rect(0x00ff0000, 0, 0, gfxMode->xRes, gfxMode->yRes); + // E + rect(0x00ffffff, 20, 10, 10, 50); + rect(0x00ffffff, 30, 10, 30, 10); + rect(0x00ffffff, 30, 30, 30, 10); + rect(0x00ffffff, 30, 50, 30, 10); + // R + rect(0x00ffffff, 70, 10, 10, 50); + rect(0x00ffffff, 70, 10, 30, 10); + rect(0x00ffffff, 70, 30, 30, 10); + rect(0x00ffffff, 90, 10, 10, 30); + rect(0x00ffffff, 80, 40, 10, 10); + rect(0x00ffffff, 90, 50, 10, 10); + // R + rect(0x00ffffff, 110, 10, 10, 50); + rect(0x00ffffff, 110, 10, 30, 10); + rect(0x00ffffff, 110, 30, 30, 10); + rect(0x00ffffff, 130, 10, 10, 30); + rect(0x00ffffff, 120, 40, 10, 10); + rect(0x00ffffff, 130, 50, 10, 10); + // O + rect(0x00ffffff, 150, 10, 10, 50); + rect(0x00ffffff, 170, 10, 10, 50); + rect(0x00ffffff, 150, 10, 30, 10); + rect(0x00ffffff, 150, 50, 30, 10); + // R + rect(0x00ffffff, 190, 10, 10, 50); + rect(0x00ffffff, 190, 10, 30, 10); + rect(0x00ffffff, 190, 30, 30, 10); + rect(0x00ffffff, 210, 10, 10, 30); + rect(0x00ffffff, 200, 40, 10, 10); + rect(0x00ffffff, 210, 50, 10, 10); + + __asm__ volatile ("cli; hlt" :: "a"(err)); +} + + diff --git a/kern.img b/kern.img index 1f5f9d1..7ab2777 100644 Binary files a/kern.img and b/kern.img differ diff --git a/kernel/kernel.c b/kernel/kernel.c index 9aa01bf..eba4285 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,29 +1,29 @@ -#include -#include -#include #include -#include +#include #include #include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include #include -#include -#include /* Little teaser #include @@ -64,8 +64,8 @@ void main() { // Setup serial output for debugf() if (setupSerial(PORT_COM1) != 0) { printf("\x1b[1MFailed to initialize serial interface\x1b[8M\n"); } else { - serialPrint(PORT_COM1, "\x1b[H\x1b[J"); // Clear - serialPrint(PORT_COM1, "kern. \x1b[36m(Serial console)\x1b[0m\n\n"); + debugf("\x1b[H\x1b[J"); // Clear + debugf("kern. \x1b[36m(Serial console)\x1b[0m\n\n"); } // Interrupt setup diff --git a/libk/include/sound/notes.h b/libc/include/sys/notes.h similarity index 100% rename from libk/include/sound/notes.h rename to libc/include/sys/notes.h diff --git a/libk/interrupt/idt.c b/libk/cpu/idt.c similarity index 91% rename from libk/interrupt/idt.c rename to libk/cpu/idt.c index 913712e..6547961 100644 --- a/libk/interrupt/idt.c +++ b/libk/cpu/idt.c @@ -1,8 +1,6 @@ -#include +#include #include -#define IDT_ENTRIES 256 - __attribute__ ((aligned(0x10))) // For performance idtEntry_t idt[IDT_ENTRIES] = { 0 }; idtp_t idtp; diff --git a/libk/interrupt/isr.c b/libk/cpu/isr.c similarity index 92% rename from libk/interrupt/isr.c rename to libk/cpu/isr.c index 67ae969..deeea7d 100644 --- a/libk/interrupt/isr.c +++ b/libk/cpu/isr.c @@ -1,11 +1,10 @@ -#include -#include #include -#include -#include -#include +#include +#include +#include +#include -const char* format = "\x1b[31mPanic: %s!\n"; +const char* format = "\x1b[31m[kernel] %s!\n\x1b[0m"; const char* exceptions[] = { "Division By Zero", "Debug", diff --git a/libk/interrupt/isr.s b/libk/cpu/isr.s similarity index 100% rename from libk/interrupt/isr.s rename to libk/cpu/isr.s diff --git a/libk/cpu/system.c b/libk/cpu/system.c new file mode 100644 index 0000000..fc201f8 --- /dev/null +++ b/libk/cpu/system.c @@ -0,0 +1,49 @@ +#include +#include +#include + +void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { + __asm__ volatile ( + "cpuid" + : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) + : "a"(*eax) + ); +} + +uint8_t inb(uint16_t port) { + uint8_t result; + __asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port)); + return result; +} +void outb(uint16_t port, uint8_t data) { + __asm__ volatile("outb %0, %1" :: "a"(data), "Nd"(port)); +} + +uint16_t inw(uint16_t port) { + uint16_t result; + __asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port)); + return result; +} +void outw(uint16_t port, uint16_t data) { + __asm__ volatile("outw %0, %1" :: "a"(data), "Nd"(port)); +} + +uint32_t inl(uint16_t port) { + uint32_t result; + __asm__ volatile("inl %1, %0" : "=a"(result) : "Nd"(port)); + return result; +} +void outl(uint16_t port, uint32_t data) { + __asm__ volatile("outl %0, %1" :: "a"(data), "Nd"(port)); +} + +void ioWait() { + // Waits ~1 I/O Cycle (Linux uses this so it should be good) + __asm__ volatile("outb %%al, $0x80" : : "a"(0)); +} + +void panic() { + debugf("\x1b[31m[kernel] Kern panic!\x1b[0m\n"); + while (1) { __asm__ volatile ("cli; hlt"); } +} + diff --git a/libk/disk/disk.c b/libk/drivers/disk.c similarity index 97% rename from libk/disk/disk.c rename to libk/drivers/disk.c index 9a67b8f..ea1f892 100644 --- a/libk/disk/disk.c +++ b/libk/drivers/disk.c @@ -1,6 +1,6 @@ -#include +#include +#include #include -#include void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst) { outb(PIO_PORT + 6, ((lbaAddress >> 24) & 0x0f) | 0xe0); // 6 - Use LBA; 4 - Drive number; 3-0 - Highest lba address nibble diff --git a/libk/keyboard/keyboard.c b/libk/drivers/keyboard.c similarity index 53% rename from libk/keyboard/keyboard.c rename to libk/drivers/keyboard.c index 173afc3..e8b5ed9 100644 --- a/libk/keyboard/keyboard.c +++ b/libk/drivers/keyboard.c @@ -1,27 +1,23 @@ -#include -#include -#include +#include #include -#include -#include -#include +#include +#include static const uint8_t US_Keyboard[2][128] = US_KEYBOARD; keyboardState_t* keyboard = (keyboardState_t*)KEYBOARD_STATE_LOC; -void keyboardHandler(intFrame_t*) { // TODO: Make this better and be able to read multi-byte scancode +// TODO: Make this better and be able to read multi-byte scancode +void keyboardHandler(intFrame_t*) { uint8_t scancode = inb(0x60); char c = US_Keyboard[keyboard->shift][scancode]; if (scancode == LEFT_SHIFT_PRESS || scancode == RIGHT_SHIFT_PRESS) { - keyboard->shift = true; + keyboard->shift = 1; } else if (scancode == LEFT_SHIFT_RELEASE || scancode == RIGHT_SHIFT_RELEASE) { - keyboard->shift = false; + keyboard->shift = 0; } if (scancode & 0x80) { // Keyup - } else if (c != '\0') { - keyboard->character = c; - } + } else if (c != '\0') { keyboard->character = c; } } diff --git a/libk/sound/pcspk.c b/libk/drivers/pcspk.c similarity index 81% rename from libk/sound/pcspk.c rename to libk/drivers/pcspk.c index d46bea9..c0a3e32 100644 --- a/libk/sound/pcspk.c +++ b/libk/drivers/pcspk.c @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/libk/interrupt/rtc.c b/libk/drivers/rtc.c similarity index 95% rename from libk/interrupt/rtc.c rename to libk/drivers/rtc.c index 5c7ce64..617f277 100644 --- a/libk/interrupt/rtc.c +++ b/libk/drivers/rtc.c @@ -1,15 +1,14 @@ -#include -#include -#include +#include #include -#include -#include -#include +#include +#include +#include +#include #include static datetime_t* datetime = (datetime_t*)DATETIME_LOC; -bool cmosUpdateProgress() { +int cmosUpdateProgress() { outb(CMOS_ADDRESS, 0x8a); // Read status reg A, disable NMI return inb(CMOS_DATA) & 0x80; } @@ -97,7 +96,7 @@ void rtcHandler(intFrame_t* iframe) { datetime->month = newDatetime.month; datetime->year = newDatetime.year; - if (true) { // TODO: Probably get rid of this idk + if (1) { // TODO: Probably get rid of this idk char buf[20] = { 0 }; // "12/12 2012 12:12:12" - Max string 20 chars with null byte strcat(buf, itoa(datetime->day, 10)); diff --git a/libk/drivers/serial.c b/libk/drivers/serial.c new file mode 100644 index 0000000..a5847f7 --- /dev/null +++ b/libk/drivers/serial.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +int serialEnable(int port) { + outb(port + 1, 0x00); // Disable all interrupts + outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor) + outb(port + 0, 0x03); // Set divisor to 3 (low byte) 38400 baud + outb(port + 1, 0x00); // (high byte) + outb(port + 3, 0x03); // 8 bits, no parity, one stop bit + outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14 byte threshold + outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set + outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip + outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if it returns) + + if (inb(port + 0) != 0xAE) return 1; + outb(port + 4, 0x0F); // non-loopback, IRQs enabled, OUT#1 and OUT#2 bits enabled + + return 0; +} + +int setupSerial() { + if (serialEnable(PORT_COM1) != 0) { return 1; } + outb(PORT_COM1 + 1, 0x01); + + return 0; +} + +static int serialTransimitEmpty(int port) { return inb(port + 5) & 0x20; } +static int serialRecieved(int port) { return inb(port + 5) & 0x01; } + +void serialWrite(int port, char c) { while (!serialTransimitEmpty(port)); outb(port, c); } +char serialRead(int port) { while (!serialRecieved(port)); return inb(port); } +char serialReadAsync(int port) { return inb(port); } + +void _dbgPutc(char c, void* arg) { + (void)arg; + serialWrite(PORT_COM1, c); + if (c == '\n') serialWrite(PORT_COM1, '\r'); +} +int vdebugf(const char* fmt, va_list va) { return vpprintf(_dbgPutc, NULL, fmt, va); } +int debugf(const char* fmt, ...) { + va_list va; + va_start(va, fmt); + int ret = vdebugf(fmt, va); + va_end(va); + return ret; +} + diff --git a/libk/interrupt/pit.c b/libk/drivers/timer.c similarity index 90% rename from libk/interrupt/pit.c rename to libk/drivers/timer.c index f6c24cd..9d7a2db 100644 --- a/libk/interrupt/pit.c +++ b/libk/drivers/timer.c @@ -1,8 +1,8 @@ -#include -#include -#include +#include #include -#include +#include +#include +#include #include void timerHandler(intFrame_t*) { diff --git a/libk/error/bigerr.c b/libk/error/bigerr.c deleted file mode 100644 index 99a5e2e..0000000 --- a/libk/error/bigerr.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { - uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; - uint8_t bytesPerPx = gfxMode->bpp / 8; - uint32_t convColor = convertColor(c); - - for (uint32_t dx = 0; dx < w; dx++) { - for (uint32_t dy = 0; dy < h; dy++) { - uint32_t offset = (((y + dy) * gfxMode->xRes) + (x + dx)) * bytesPerPx; - - for (uint8_t i = 0; i < gfxMode->bpp; i++) { - vidmem[offset + i] = (uint8_t)(convColor >> (i*8)); - } - } - } -} - -void bigError(uint32_t err) { - // Red BG - rect(0x00ff0000, 0, 0, gfxMode->xRes, gfxMode->yRes); - // E - rect(0x00ffffff, 20, 10, 10, 50); - rect(0x00ffffff, 30, 10, 30, 10); - rect(0x00ffffff, 30, 30, 30, 10); - rect(0x00ffffff, 30, 50, 30, 10); - // R - rect(0x00ffffff, 70, 10, 10, 50); - rect(0x00ffffff, 70, 10, 30, 10); - rect(0x00ffffff, 70, 30, 30, 10); - rect(0x00ffffff, 90, 10, 10, 30); - rect(0x00ffffff, 80, 40, 10, 10); - rect(0x00ffffff, 90, 50, 10, 10); - // R - rect(0x00ffffff, 110, 10, 10, 50); - rect(0x00ffffff, 110, 10, 30, 10); - rect(0x00ffffff, 110, 30, 30, 10); - rect(0x00ffffff, 130, 10, 10, 30); - rect(0x00ffffff, 120, 40, 10, 10); - rect(0x00ffffff, 130, 50, 10, 10); - // O - rect(0x00ffffff, 150, 10, 10, 50); - rect(0x00ffffff, 170, 10, 10, 50); - rect(0x00ffffff, 150, 10, 30, 10); - rect(0x00ffffff, 150, 50, 30, 10); - // R - rect(0x00ffffff, 190, 10, 10, 50); - rect(0x00ffffff, 190, 10, 30, 10); - rect(0x00ffffff, 190, 30, 30, 10); - rect(0x00ffffff, 210, 10, 10, 30); - rect(0x00ffffff, 200, 40, 10, 10); - rect(0x00ffffff, 210, 50, 10, 10); - - __asm__ volatile ("cli; hlt" :: "a"(err)); -} - diff --git a/libk/error/debug.c b/libk/error/debug.c deleted file mode 100644 index 4b6fd3e..0000000 --- a/libk/error/debug.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -static void _dbgPutc(char c, void* arg) { - (void)arg; - serialWrite(PORT_COM1, c); - if (c == '\n') { serialWrite(PORT_COM1, '\r'); } -} - -int debugf(const char* fmt, ...) { - va_list va; - va_start(va, fmt); - int res = vpprintf(_dbgPutc, NULL, fmt, va); - va_end(va); - return res; -} - diff --git a/libk/error/panic.c b/libk/error/panic.c deleted file mode 100644 index 5c6ddb8..0000000 --- a/libk/error/panic.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void panic() { - // TODO: print a message - while (1) { __asm__ volatile ("cli; hlt"); } -} - diff --git a/libk/fs/impl.c b/libk/fs/kernfs.c similarity index 97% rename from libk/fs/impl.c rename to libk/fs/kernfs.c index be4e342..c9d7819 100644 --- a/libk/fs/impl.c +++ b/libk/fs/kernfs.c @@ -1,7 +1,7 @@ -#include -#include +#include #include -#include +#include +#include #include #include #include diff --git a/libk/include/interrupt/idt.h b/libk/include/cpu/idt.h similarity index 91% rename from libk/include/interrupt/idt.h rename to libk/include/cpu/idt.h index 8cbb013..a86499a 100644 --- a/libk/include/interrupt/idt.h +++ b/libk/include/cpu/idt.h @@ -1,8 +1,10 @@ -#ifndef INTERRUPT_IDT_H -#define INTERRUPT_IDT_H +#ifndef _CPU_IDT_H +#define _CPU_IDT_H #include +#define IDT_ENTRIES 256 + #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) #define USR_INT_GATE_FLAGS 0xee // P = 1, DPL = 11, S = 0, Type = 1110 (32-bit Int gate) @@ -24,4 +26,3 @@ void idtSetGate(uint8_t i, void* handler, uint8_t flags); void setupIdt(); #endif - diff --git a/libk/include/interrupt/isr.h b/libk/include/cpu/isr.h similarity index 91% rename from libk/include/interrupt/isr.h rename to libk/include/cpu/isr.h index e8503ac..ef85b2d 100644 --- a/libk/include/interrupt/isr.h +++ b/libk/include/cpu/isr.h @@ -1,5 +1,5 @@ -#ifndef INTERRUPT_ISR_H -#define INTERRUPT_ISR_H +#ifndef _CPU_ISR_H +#define _CPU_ISR_H #include @@ -15,8 +15,8 @@ typedef struct { typedef void (*HandlerPtr)(intFrame_t* iframe); void setupIsrs(); -int handleInterrupt(intFrame_t iframe); void registerIrq(uint8_t id, HandlerPtr handler); +int handleInterrupt(intFrame_t iframe); // ISR Table extern void* asm_isrRedirectTable[48]; diff --git a/libk/include/cpu/system.h b/libk/include/cpu/system.h new file mode 100644 index 0000000..af64db4 --- /dev/null +++ b/libk/include/cpu/system.h @@ -0,0 +1,19 @@ +#ifndef _CPU_SYSTEM_H +#define _CPU_SYSTEM_H + +#include + +void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx); + +void outb(uint16_t port, uint8_t data); +void outw(uint16_t port, uint16_t data); +void outl(uint16_t port, uint32_t data); + +uint8_t inb(uint16_t port); +uint16_t inw(uint16_t port); +uint32_t inl(uint16_t port); + +void ioWait(); +void panic(); + +#endif diff --git a/libk/include/disk/disk.h b/libk/include/drivers/disk.h similarity index 84% rename from libk/include/disk/disk.h rename to libk/include/drivers/disk.h index dc35039..dc1bc89 100644 --- a/libk/include/disk/disk.h +++ b/libk/include/drivers/disk.h @@ -1,5 +1,5 @@ -#ifndef DISK_DISK_H -#define DISK_DISK_H +#ifndef _DRIVERS_DISK_H +#define _DRIVERS_DISK_H #include diff --git a/libk/include/keyboard/keys.h b/libk/include/drivers/keyboard.h similarity index 88% rename from libk/include/keyboard/keys.h rename to libk/include/drivers/keyboard.h index a488a8e..f50f82e 100644 --- a/libk/include/keyboard/keys.h +++ b/libk/include/drivers/keyboard.h @@ -1,6 +1,9 @@ -#ifndef KEYBOARD_KEYS_H -#define KEYBOARD_KEYS_H +#ifndef _DRIVERS_KEYBOARD_H +#define _DRIVERS_KEYBOARD_H +#include + +// Special keys #define LEFT_SHIFT_PRESS 0x2a #define LEFT_SHIFT_RELEASE (LEFT_SHIFT_PRESS | 0x80) #define RIGHT_SHIFT_PRESS 0x36 @@ -35,4 +38,11 @@ }\ } +typedef struct { + char character; + int shift; +} keyboardState_t; + +void keyboardHandler(intFrame_t*); + #endif diff --git a/libk/include/sound/pcspk.h b/libk/include/drivers/pcspk.h similarity index 69% rename from libk/include/sound/pcspk.h rename to libk/include/drivers/pcspk.h index f5bfc6d..2fece6f 100644 --- a/libk/include/sound/pcspk.h +++ b/libk/include/drivers/pcspk.h @@ -1,7 +1,7 @@ -#ifndef SOUND_PCSPK_H -#define SOUND_PCSPK_H +#ifndef _DRIVERS_PCSPK_H +#define _DRIVERS_PCSPK_H -#include +#include #include #define PC_SPEAKER 0x61 diff --git a/libk/include/interrupt/rtc.h b/libk/include/drivers/rtc.h similarity index 74% rename from libk/include/interrupt/rtc.h rename to libk/include/drivers/rtc.h index 77195e5..d8f6b49 100644 --- a/libk/include/interrupt/rtc.h +++ b/libk/include/drivers/rtc.h @@ -1,9 +1,8 @@ -#ifndef INTERRUPT_RTC_H -#define INTERRUPT_RTC_H +#ifndef _DRIVERS_RTC_H +#define _DRIVERS_RTC_H -#include +#include #include -#include #define CMOS_ADDRESS 0x70 #define CMOS_DATA 0x71 @@ -18,7 +17,7 @@ typedef struct { } __attribute__ ((packed)) datetime_t; void rtcHandler(intFrame_t*); -bool cmosUpdateProgress(); +int cmosUpdateProgress(); uint8_t getRtcRegister(uint8_t reg); void enableRtc(); void disableRtc(); diff --git a/libk/include/drivers/serial.h b/libk/include/drivers/serial.h new file mode 100644 index 0000000..19a053f --- /dev/null +++ b/libk/include/drivers/serial.h @@ -0,0 +1,23 @@ +#ifndef _DRIVERS_SERIAL_H +#define _DRIVERS_SERIAL_H + +#include + +#define PORT_COM1 0x3f8 +#define PORT_COM2 0x2f8 +#define PORT_COM3 0x3e8 +#define PORT_COM4 0x2e8 + +// IRQ4 -> COM1, IRQ3 -> COM2 +#define SERIAL_IRQ 4 + +int serialEnable(int port); +int setupSerial(); +void serialWrite(int port, char c); +char serialRead(int port); +char serialReadAsync(int port); + +int debugf(const char* fmt, ...); +int vdebugf(const char* fmt, va_list va); + +#endif diff --git a/libk/include/interrupt/pit.h b/libk/include/drivers/timer.h similarity index 76% rename from libk/include/interrupt/pit.h rename to libk/include/drivers/timer.h index fd39e73..e944f64 100644 --- a/libk/include/interrupt/pit.h +++ b/libk/include/drivers/timer.h @@ -1,7 +1,7 @@ -#ifndef INTERRUPT_PIT_H -#define INTERRUPT_PIT_H +#ifndef _DRIVERS_TIMER_H +#define _DRIVERS_TIMER_H -#include +#include #include #define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2 diff --git a/libk/include/error/bigerr.h b/libk/include/error/bigerr.h deleted file mode 100644 index ef390c5..0000000 --- a/libk/include/error/bigerr.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef ERROR_BIGERR_H -#define ERROR_BIGERR_H - -/* - * Something went VERY wrong. - * Eg. kernel.bin is missing, no filesystem, Virtual Memory failed, etc. - */ - -#include - -void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h); -void bigError(uint32_t err); - -#endif diff --git a/libk/include/error/debug.h b/libk/include/error/debug.h deleted file mode 100644 index 1d7ae85..0000000 --- a/libk/include/error/debug.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef ERROR_DEBUG_H -#define ERROR_DEBUG_H - -int debugf(const char* fmt, ...); - -#endif diff --git a/libk/include/error/panic.h b/libk/include/error/panic.h deleted file mode 100644 index 2cea8ab..0000000 --- a/libk/include/error/panic.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef ERROR_PANIC_H -#define ERROR_PANIC_H - -void panic(); - -#endif diff --git a/libk/include/fs/fs.h b/libk/include/fs/fs.h index 9f165df..ad2fc94 100644 --- a/libk/include/fs/fs.h +++ b/libk/include/fs/fs.h @@ -1,5 +1,5 @@ -#ifndef FS_FS_H -#define FS_FS_H +#ifndef _FS_FS_H +#define _FS_FS_H /* * For info, read the fs-spec.txt document inside of docs/ diff --git a/libk/include/fs/impl.h b/libk/include/fs/kernfs.h similarity index 83% rename from libk/include/fs/impl.h rename to libk/include/fs/kernfs.h index c7d07c0..94c4312 100644 --- a/libk/include/fs/impl.h +++ b/libk/include/fs/kernfs.h @@ -1,5 +1,5 @@ -#ifndef FS_IMPL_H -#define FS_IMPL_H +#ifndef _FS_KERNFS_H +#define _FS_KERNFS_H #include #include @@ -17,5 +17,6 @@ extern fsInfo_t* fsInfo; inode_t* getInode(char* path, dirEntry_t* dentries); uint8_t loadFile(inode_t* inode, void* dest); +void initOpenFileTable(); #endif diff --git a/libk/include/interrupt/exceptions.h b/libk/include/interrupt/exceptions.h deleted file mode 100644 index a5ea882..0000000 --- a/libk/include/interrupt/exceptions.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef INTERRUPT_EXCEPTIONS_H -#define INTERRUPT_EXCEPTIONS_H - -void setupExceptions(); - -#endif diff --git a/libk/include/keyboard/keyboard.h b/libk/include/keyboard/keyboard.h deleted file mode 100644 index f688e10..0000000 --- a/libk/include/keyboard/keyboard.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef KEYBOARD_KEYBOARD_H -#define KEYBOARD_KEYBOARD_H - -#include -#include - -typedef struct { - char character; - bool shift; -} keyboardState_t; - -void keyboardHandler(intFrame_t*); - -#endif diff --git a/libk/include/memory/addresses.h b/libk/include/memory/addresses.h index 6b01b81..fb3208d 100644 --- a/libk/include/memory/addresses.h +++ b/libk/include/memory/addresses.h @@ -1,5 +1,5 @@ -#ifndef MEMORY_ADDRESSES_H -#define MEMORY_ADDRESSES_H +#ifndef _MEMORY_ADDRESSES_H +#define _MEMORY_ADDRESSES_H /* * Memory layout of addresses 0x0000 - 0x12000 @@ -25,7 +25,7 @@ #define PHYS_MEM_USED_BLOCKS 0x180C // Some structs 0x2000-0x2fff -#define TERMINAL_INFO_LOC 0x2000 +#define CONSOLE_INFO_LOC 0x2000 #define KEYBOARD_STATE_LOC 0x2100 #define DATETIME_LOC 0x2200 diff --git a/libk/include/memory/malloc.h b/libk/include/memory/malloc.h index c305403..a081411 100644 --- a/libk/include/memory/malloc.h +++ b/libk/include/memory/malloc.h @@ -1,5 +1,5 @@ -#ifndef MEMORY_MALLOC_H -#define MEMORY_MALLOC_H +#ifndef _MEMORY_MALLOC_H +#define _MEMORY_MALLOC_H #include #include diff --git a/libk/include/memory/physical.h b/libk/include/memory/physical.h index 4fac758..2a4a222 100644 --- a/libk/include/memory/physical.h +++ b/libk/include/memory/physical.h @@ -1,5 +1,5 @@ -#ifndef MEMORY_PHYSICAL_H -#define MEMORY_PHYSICAL_H +#ifndef _MEMORY_PHYSICAL_H +#define _MEMORY_PHYSICAL_H #include #include diff --git a/libk/include/memory/virtual.h b/libk/include/memory/virtual.h index 50a8e99..f875629 100644 --- a/libk/include/memory/virtual.h +++ b/libk/include/memory/virtual.h @@ -1,8 +1,8 @@ -#ifndef MEMORY_VIRTUAL_H -#define MEMORY_VIRTUAL_H +#ifndef _MEMORY_VIRTUAL_H +#define _MEMORY_VIRTUAL_H -#include #include +#include #define PAGES_PER_TABLE 1024 #define TABLES_PER_DIRECTORY 1024 diff --git a/libk/include/ports/io.h b/libk/include/ports/io.h deleted file mode 100644 index ba0dbd4..0000000 --- a/libk/include/ports/io.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PORTS_IO_H -#define PORTS_IO_H - -#include - -// Port functions -uint8_t inb(uint16_t port); -void outb(uint16_t port, uint8_t data); -uint16_t inw(uint16_t port); -void outw(uint16_t port, uint16_t data); -void ioWait(); - -#endif diff --git a/libk/include/ports/serial.h b/libk/include/ports/serial.h deleted file mode 100644 index 21d4040..0000000 --- a/libk/include/ports/serial.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef PORTS_SERIAL_H -#define PORTS_SERIAL_H - -#include - -#define PORT_COM1 0x3f8 -#define PORT_COM2 0x2f8 -#define PORT_COM3 0x3e8 -#define PORT_COM4 0x2e8 -#define PORT_COM5 0x5f8 -#define PORT_COM6 0x4f8 -#define PORT_COM7 0x5e8 -#define PORT_COM8 0x4e8 - -int setupSerial(uint32_t port); - -int serialTransmitEmpty(uint32_t port); -int serialRecieved(uint32_t port); - -void serialWrite(uint32_t port, char c); -void serialPrint(uint32_t port, const char* s); -char serialRead(uint32_t port); - -#endif diff --git a/libk/include/screen/gfxmode.h b/libk/include/screen/gfxmode.h index edfd384..6699246 100644 --- a/libk/include/screen/gfxmode.h +++ b/libk/include/screen/gfxmode.h @@ -1,5 +1,5 @@ -#ifndef SCREEN_GFXMODE_H -#define SCREEN_GFXMODE_H +#ifndef _SCREEN_GFXMODE_H +#define _SCREEN_GFXMODE_H #include #include diff --git a/libk/include/screen/graphics.h b/libk/include/screen/graphics.h index 7de1e7c..21fe9af 100644 --- a/libk/include/screen/graphics.h +++ b/libk/include/screen/graphics.h @@ -1,9 +1,9 @@ -#ifndef SCREEN_GRAPHICS_H -#define SCREEN_GRAPHICS_H +#ifndef _SCREEN_GRAPHICS_H +#define _SCREEN_GRAPHICS_H #include -#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff ) +#define rgb(_r,_g,_b) ( ((_r) << 16 | (_g) << 8 | (_b)) & 0x00ffffff ) void drawPixel(int32_t x, int32_t y, uint32_t color); void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color); diff --git a/libk/include/screen/text.h b/libk/include/screen/text.h index bddfc9d..92d17c4 100644 --- a/libk/include/screen/text.h +++ b/libk/include/screen/text.h @@ -1,5 +1,5 @@ -#ifndef SCREEN_TEXT_H -#define SCREEN_TEXT_H +#ifndef _SCREEN_TEXT_H +#define _SCREEN_TEXT_H #include diff --git a/libk/include/tty/tty.h b/libk/include/screen/tty.h similarity index 91% rename from libk/include/tty/tty.h rename to libk/include/screen/tty.h index 0d32ed5..0eb289a 100644 --- a/libk/include/tty/tty.h +++ b/libk/include/screen/tty.h @@ -1,5 +1,5 @@ -#ifndef TERMINAL_TERMINAL_H -#define TERMINAL_TERMINAL_H +#ifndef _SCREEN_TTY_H +#define _SCREEN_TTY_H #include #include diff --git a/libk/include/syscalls/syscalls.h b/libk/include/syscalls/syscalls.h index 615dbbe..8b1a471 100644 --- a/libk/include/syscalls/syscalls.h +++ b/libk/include/syscalls/syscalls.h @@ -1,7 +1,7 @@ -#ifndef INTERRUPT_SYSCALLS_H -#define INTERRUPT_SYSCALLS_H +#ifndef _SYSCALLS_SYSCALLS_H +#define _SYSCALLS_SYSCALLS_H -#include +#include int sys_exit (intFrame_t* iframe); int sys_read (intFrame_t* iframe); diff --git a/libk/makefile b/libk/makefile index 93bcdd9..ebc1b84 100644 --- a/libk/makefile +++ b/libk/makefile @@ -4,7 +4,7 @@ include make.defaults -LIBK_ASM=$(LIBK_DIR)/interrupt/isr.s +LIBK_ASM=$(LIBK_DIR)/cpu/isr.s $(LIBK): $(LIBK_SRC) $(LIBK_ASM) $(LIBC) @echo "Building $(LIBK)..." diff --git a/libk/ports/io.c b/libk/ports/io.c deleted file mode 100644 index fd70921..0000000 --- a/libk/ports/io.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -// Port functions -uint8_t inb(uint16_t port) { - uint8_t result; - __asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port)); - return result; -} - -void outb(uint16_t port, uint8_t data) { - __asm__ volatile("outb %0, %1" :: "a"(data), "Nd"(port)); -} - -uint16_t inw(uint16_t port) { - uint16_t result; - __asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port)); - return result; -} - -void outw(uint16_t port, uint16_t data) { - __asm__ volatile("outw %0, %1" :: "a"(data), "Nd"(port)); -} - -void ioWait() { - // Waits ~1 I/O Cycle (Linux uses this so it should be good) - __asm__ volatile("outb %%al, $0x80" : : "a"(0)); -} - diff --git a/libk/ports/serial.c b/libk/ports/serial.c deleted file mode 100644 index af3bf8a..0000000 --- a/libk/ports/serial.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -int setupSerial(uint32_t port) { - outb(port + 1, 0x00); // Disable all interrupts - outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor) - outb(port + 0, 0x03); // Set divisor to 3 (low byte) 38400 baud - outb(port + 1, 0x00); // (high byte) - outb(port + 3, 0x03); // 8 bits, no parity, one stop bit - outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14 byte threshold - outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set - outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip - outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if it returns) - - if (inb(port + 0) != 0xAE) return 1; - outb(port + 4, 0x0F); // non-loopback, IRQs enabled, OUT#1 and OUT#2 bits enabled - - return 0; -} - -int serialTransmitEmpty(uint32_t port) { - return inb(port + 5) & 0x20; -} - -int serialRecieved(uint32_t port) { - return inb(port + 5) & 0x01; -} - -void serialWrite(uint32_t port, char c) { - while (serialTransmitEmpty(port) == 0); - outb(port, c); -} - -void serialPrint(uint32_t port, const char* s) { - while (*s != '\0') { - if (*s == '\n') serialWrite(port, '\r'); - serialWrite(port, *s++); - } -} - -char serialRead(uint32_t port) { - while (serialRecieved(port)); - return inb(port); -} - diff --git a/libk/screen/text.c b/libk/screen/text.c index a7c4082..6cb55ad 100644 --- a/libk/screen/text.c +++ b/libk/screen/text.c @@ -1,7 +1,7 @@ #include -#include -#include #include +#include +#include #include #include diff --git a/libk/tty/tty.c b/libk/screen/tty.c similarity index 98% rename from libk/tty/tty.c rename to libk/screen/tty.c index cce0ad8..501b960 100644 --- a/libk/tty/tty.c +++ b/libk/screen/tty.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -7,7 +7,7 @@ #include #include -console_t* console = (console_t*)TERMINAL_INFO_LOC; +console_t* console = (console_t*)CONSOLE_INFO_LOC; int32_t consoleWrite(const void* buf, uint32_t len) { // TODO fix font size console->width = gfxMode->xRes / 8;//*(uint8_t*)(FONT_LOC); diff --git a/libk/syscalls/sys_close.c b/libk/syscalls/sys_close.c index 77894c9..4321fd7 100644 --- a/libk/syscalls/sys_close.c +++ b/libk/syscalls/sys_close.c @@ -1,5 +1,5 @@ #include -#include +#include #include int sys_close(intFrame_t* iframe) { diff --git a/libk/syscalls/sys_exit.c b/libk/syscalls/sys_exit.c index 38ec0ff..af48010 100644 --- a/libk/syscalls/sys_exit.c +++ b/libk/syscalls/sys_exit.c @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include int sys_exit(intFrame_t* iframe) { debugf("Tried to exit with %d", iframe->eax); diff --git a/libk/syscalls/sys_free.c b/libk/syscalls/sys_free.c index 6a9ab40..e1081c4 100644 --- a/libk/syscalls/sys_free.c +++ b/libk/syscalls/sys_free.c @@ -1,6 +1,6 @@ #include -#include #include +#include int sys_free(intFrame_t* iframe) { void* ptr = (void*)iframe->ebx; diff --git a/libk/syscalls/sys_malloc.c b/libk/syscalls/sys_malloc.c index 0178e0c..a32f774 100644 --- a/libk/syscalls/sys_malloc.c +++ b/libk/syscalls/sys_malloc.c @@ -1,6 +1,6 @@ #include -#include #include +#include #include int sys_malloc(intFrame_t* iframe) { diff --git a/libk/syscalls/sys_open.c b/libk/syscalls/sys_open.c index 3b7c330..69b3f32 100644 --- a/libk/syscalls/sys_open.c +++ b/libk/syscalls/sys_open.c @@ -1,5 +1,5 @@ #include -#include +#include #include int sys_open(intFrame_t* iframe) { diff --git a/libk/syscalls/sys_read.c b/libk/syscalls/sys_read.c index 3b9ab83..e5d554c 100644 --- a/libk/syscalls/sys_read.c +++ b/libk/syscalls/sys_read.c @@ -1,5 +1,5 @@ #include -#include +#include #include int sys_read(intFrame_t* iframe) { diff --git a/libk/syscalls/sys_seek.c b/libk/syscalls/sys_seek.c index 841927d..ccc5c7e 100644 --- a/libk/syscalls/sys_seek.c +++ b/libk/syscalls/sys_seek.c @@ -1,5 +1,5 @@ #include -#include +#include int sys_seek(intFrame_t* iframe) { // TODO diff --git a/libk/syscalls/sys_sleep.c b/libk/syscalls/sys_sleep.c index da2e16f..4b9b686 100644 --- a/libk/syscalls/sys_sleep.c +++ b/libk/syscalls/sys_sleep.c @@ -1,6 +1,6 @@ #include -#include #include +#include #include int sys_sleep(intFrame_t* iframe) { diff --git a/libk/syscalls/sys_write.c b/libk/syscalls/sys_write.c index afbc52a..afa3e8a 100644 --- a/libk/syscalls/sys_write.c +++ b/libk/syscalls/sys_write.c @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include int sys_write(intFrame_t* iframe) { diff --git a/libk/syscalls/syscalls.c b/libk/syscalls/syscalls.c index d39946a..07659d8 100644 --- a/libk/syscalls/syscalls.c +++ b/libk/syscalls/syscalls.c @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include // System call table diff --git a/makefile b/makefile index e71c4e7..4ed952b 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ # Main kern makefile # -export VERSION = 0.2.1 +export VERSION = 0.2.2 # Configurable variables (eg. CC, CFLAGS, ...) include make.defaults diff --git a/todo.txt b/todo.txt index fcd21d6..dd27e2d 100644 --- a/todo.txt +++ b/todo.txt @@ -58,18 +58,14 @@ Legend: - [ ] types.h (syscall types) - [ ] gfx.h (basic graphics lib) -- [ ] LIBK - - [x] disk - disk r/w - - [ ] error - error handling (bigerr is not enough :( ) - - [ ] fs - filesystem +- [x] LIBK + - [x] drivers - everything that works with hardware + - [x] error - error handling (bigerr is not enough :( ) + - [x] fs - filesystem - [x] interrupt - handling and registering interupts - - [ ] input - handle ALL input devices (currently implemented as the keyboard dir) - [x] memory - memory managing (physical and virtual) - - [x] ports - handles IO ports (eg. serial console) - [x] screen - everything that displays on the screen - - [x] sound - handles everything related to sound - [x] syscall - system calls - - [x] tty - handles terminal output - [x] Multistage Bootloader - [x] Bootloader reads filesystem to find files