diff --git a/Makefile b/Makefile index 77fe38f..58970c0 100644 --- a/Makefile +++ b/Makefile @@ -51,8 +51,7 @@ $(C_FILES): # This target builds all fonts inside src/fonts $(FONTS): - @echo "Assembling $(SRC)/fonts/$@.asm..." - @$(AS) -fbin -o $(BIN)/$@.fnt $(SRC)/fonts/$@.asm + @cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt # Run QEMU run: diff --git a/include/c/stdio.h b/include/c/stdio.h index d219cd5..c7f1aaf 100644 --- a/include/c/stdio.h +++ b/include/c/stdio.h @@ -7,10 +7,11 @@ #include // Nobody should have to interface with the internals of this structure -typedef struct _iobuf { - char* _ptr; - int _file; - int _oflag; +typedef struct _iobuf { // 16B + char* _ptr; // Virtual address of file base + int _offset; // Offset into file; Seek() + int _file; // File descriptor + int _oflag; // Flags used to open file } FILE; FILE* stdin; diff --git a/include/interrupt/exceptions.h.bak b/include/interrupt/exceptions.h.bak deleted file mode 100644 index 3a118b3..0000000 --- a/include/interrupt/exceptions.h.bak +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef ISRS_H -#define ISRS_H - -#include -#include - -// Exception handlers -__attribute__ ((interrupt)) -void excp_divideErr(intFrame_t* iframe) { // ISR 0 - fgColor = RED; - print("[ Division Error ]\n"); - __asm__ volatile ("cli; hlt"); // Halt system -} - -__attribute__ ((interrupt)) -void excp_debugErr(intFrame_t* iframe) { // ISR 1 - fgColor = RED; - print("[ Debug Exception ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_nmiInterrupt(intFrame_t* iframe) { // ISR 2 - fgColor = RED; - print("[ Non-maskable Interrupt ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_breakpoint(intFrame_t* iframe) { // ISR 3 - fgColor = RED; - print("[ Breakpoint ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_overflow(intFrame_t* iframe) { // ISR 4 - fgColor = RED; - print("[ Overflow Error ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_boundRangeExceed(intFrame_t* iframe) { // ISR 5 - fgColor = RED; - print("[ Bound Range Exceeded ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_invalidOpcode(intFrame_t* iframe) { // ISR 6 - fgColor = RED; - print("[ Invalid OpCode ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_deviceNA(intFrame_t* iframe) { // ISR 7 - fgColor = RED; - print("[ Device Not Available ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_doubleFault(intFrame_t* iframe, uint32_t errCode) { // ISR 8 - fgColor = RED; - print("[ Double Fault : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_coprocOverrun(intFrame_t* iframe) { // ISR 9 - fgColor = RED; - print("[ Coprocessor Segment Overrun ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_invalidTss(intFrame_t* iframe, uint32_t errCode) { // ISR 10 - fgColor = RED; - print("[ Invalid TSS : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_noSegment(intFrame_t* iframe, uint32_t errCode) { // ISR 11 - fgColor = RED; - print("[ Segment Not Present : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_stackSegmentFault(intFrame_t* iframe, uint32_t errCode) { // ISR 12 - fgColor = RED; - print("[ Stack-Segment Fault : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_generalProtectionFault(intFrame_t* iframe, uint32_t errCode) { // ISR 13 - fgColor = RED; - print("[ General Protection Fault : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_pageFault(intFrame_t* iframe, uint32_t errCode) { // ISR 14 - fgColor = RED; - print("[ Page Fault : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_reserved(intFrame_t* iframe) { // ISR 15 - fgColor = RED; - print("[ Reserved Exception ]\n"); // Shouldn't get this one - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_floatingPointErr(intFrame_t* iframe) { // ISR 16 - fgColor = RED; - print("[ x87 FPU Floating-Point Error ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_alignCheck(intFrame_t* iframe, uint32_t errCode) { // ISR 17 - fgColor = RED; - print("[ Alignment Check : 0x"); - print(itoa(errCode, 16)); - print(" ]\n"); - __asm__ volatile ("cli; hlt"); -} - -__attribute__ ((interrupt)) -void excp_machineCheck(intFrame_t* iframe) { // ISR 18 - fgColor = RED; - print("[ Machine Check ]\n"); - __asm__ volatile ("cli; hlt"); -} - -// TODO: Add more (because there's always more) - -// Repetative isr definitions -void setupExceptions() { - for (uint8_t i = 0; i < 32; i++) { - idtSetGate(i, excp_reserved, TRAP_GATE_FLAGS); - } - - idtSetGate(0, excp_divideErr, TRAP_GATE_FLAGS); - idtSetGate(1, excp_debugErr, TRAP_GATE_FLAGS); - idtSetGate(2, excp_nmiInterrupt, TRAP_GATE_FLAGS); - idtSetGate(3, excp_breakpoint, TRAP_GATE_FLAGS); - idtSetGate(4, excp_overflow, TRAP_GATE_FLAGS); - idtSetGate(5, excp_boundRangeExceed, TRAP_GATE_FLAGS); - idtSetGate(6, excp_invalidOpcode, TRAP_GATE_FLAGS); - idtSetGate(7, excp_deviceNA, TRAP_GATE_FLAGS); - idtSetGate(8, excp_doubleFault, TRAP_GATE_FLAGS); - idtSetGate(9, excp_coprocOverrun, TRAP_GATE_FLAGS); - idtSetGate(10, excp_invalidTss, TRAP_GATE_FLAGS); - idtSetGate(11, excp_noSegment, TRAP_GATE_FLAGS); - idtSetGate(12, excp_stackSegmentFault, TRAP_GATE_FLAGS); - idtSetGate(13, excp_generalProtectionFault, TRAP_GATE_FLAGS); - idtSetGate(14, excp_pageFault, TRAP_GATE_FLAGS); - idtSetGate(15, excp_reserved, TRAP_GATE_FLAGS); - idtSetGate(16, excp_floatingPointErr, TRAP_GATE_FLAGS); - idtSetGate(17, excp_alignCheck, TRAP_GATE_FLAGS); - idtSetGate(18, excp_machineCheck, TRAP_GATE_FLAGS); - // Other are reserved -} - -#endif diff --git a/include/interrupt/syscalls.h b/include/interrupt/syscalls.h index 5d2d6d7..5623b5a 100644 --- a/include/interrupt/syscalls.h +++ b/include/interrupt/syscalls.h @@ -87,6 +87,8 @@ void sys_open() { uint32_t oflag = 0; __asm__ volatile ("nop" : "=b"(path), "=c"(oflag)); + + __asm__ volatile ("movl %0, %%eax" : : "a"(fd)); } diff --git a/kern.iso b/kern.iso index 68bb134..45d6e28 100644 Binary files a/kern.iso and b/kern.iso differ diff --git a/src/fonts/term16n.fnt b/src/fonts/term16n.fnt new file mode 100644 index 0000000..bb89ed4 Binary files /dev/null and b/src/fonts/term16n.fnt differ diff --git a/src/fonts/testfont.fnt b/src/fonts/testfont.fnt new file mode 100644 index 0000000..6417666 Binary files /dev/null and b/src/fonts/testfont.fnt differ diff --git a/src/kernel.c b/src/kernel.c index 1ab101e..2f3fc38 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -26,13 +26,18 @@ #define PROMPT "#>" +// FS things +char* cwd; + +FILE* openFileTable; +uint32_t maxOpenFiles; +uint32_t openFiles; + // Function declarations void listFiles(); void printRegs(); void printPhysicalMemmap(); - -// FS things -char* cwd; +void initOpenFileTable(); __attribute__ ((section("entry"))) void main() { @@ -74,16 +79,9 @@ void main() { mallocVirtualAddr = kernelMallocVirtualAddr; mallocPhysicalAddr = kernelMallocPhysicalAddr; mallocPages = kernelMallocPages; - - // Setup stdio FILE* - stdin->_file = 0; - stdin->_oflag = O_RDONLY; - stdout->_file = 1; - stdout->_oflag = O_WRONLY | O_APPEND; - stderr->_file = 2; - stderr->_oflag = O_WRONLY | O_APPEND; - + // FS Setup + initOpenFileTable(); cwd = malloc(1024); strcpy(cwd, "/"); @@ -345,3 +343,25 @@ void printPhysicalMemmap() { printf("Free blocks: %d\n\n", maxBlocks - usedBlocks); } +void initOpenFileTable() { + maxOpenFiles = 256; + + openFileTable = malloc(sizeof(FILE) * maxOpenFiles); + memset(openFileTable, 0, sizeof(FILE) * maxOpenFiles); + + // offset and ptr are unused in these + stdin = openFileTable + 0; + stdin->_file = 0; + stdin->_oflag = O_RDONLY; + + stdout = openFileTable + 1; + stdout->_file = 1; + stdout->_oflag = O_WRONLY | O_APPEND; + + stderr = openFileTable + 2; + stderr->_file = 2; + stderr->_oflag = O_WRONLY | O_APPEND; + + openFiles = 3; +} +