Made fonts not have to be assembled every time and made open file table

This commit is contained in:
2024-08-16 18:42:42 +02:00
parent f0edcb0459
commit 6d9b807fe6
8 changed files with 40 additions and 203 deletions
+1 -2
View File
@@ -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:
+5 -4
View File
@@ -7,10 +7,11 @@
#include <stdint.h>
// 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;
-185
View File
@@ -1,185 +0,0 @@
#ifndef ISRS_H
#define ISRS_H
#include <interrupt/idt.h>
#include <screen/text.h>
// 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
+2
View File
@@ -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));
}
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+32 -12
View File
@@ -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;
}