forked from PoliEcho-holding-org/kern
Made fonts not have to be assembled every time and made open file table
This commit is contained in:
@@ -51,8 +51,7 @@ $(C_FILES):
|
|||||||
|
|
||||||
# This target builds all fonts inside src/fonts
|
# This target builds all fonts inside src/fonts
|
||||||
$(FONTS):
|
$(FONTS):
|
||||||
@echo "Assembling $(SRC)/fonts/$@.asm..."
|
@cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
||||||
@$(AS) -fbin -o $(BIN)/$@.fnt $(SRC)/fonts/$@.asm
|
|
||||||
|
|
||||||
# Run QEMU
|
# Run QEMU
|
||||||
run:
|
run:
|
||||||
|
|||||||
+5
-4
@@ -7,10 +7,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
// Nobody should have to interface with the internals of this structure
|
// Nobody should have to interface with the internals of this structure
|
||||||
typedef struct _iobuf {
|
typedef struct _iobuf { // 16B
|
||||||
char* _ptr;
|
char* _ptr; // Virtual address of file base
|
||||||
int _file;
|
int _offset; // Offset into file; Seek()
|
||||||
int _oflag;
|
int _file; // File descriptor
|
||||||
|
int _oflag; // Flags used to open file
|
||||||
} FILE;
|
} FILE;
|
||||||
|
|
||||||
FILE* stdin;
|
FILE* stdin;
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -87,6 +87,8 @@ void sys_open() {
|
|||||||
uint32_t oflag = 0;
|
uint32_t oflag = 0;
|
||||||
|
|
||||||
__asm__ volatile ("nop" : "=b"(path), "=c"(oflag));
|
__asm__ volatile ("nop" : "=b"(path), "=c"(oflag));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__asm__ volatile ("movl %0, %%eax" : : "a"(fd));
|
__asm__ volatile ("movl %0, %%eax" : : "a"(fd));
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+32
-12
@@ -26,13 +26,18 @@
|
|||||||
|
|
||||||
#define PROMPT "#>"
|
#define PROMPT "#>"
|
||||||
|
|
||||||
|
// FS things
|
||||||
|
char* cwd;
|
||||||
|
|
||||||
|
FILE* openFileTable;
|
||||||
|
uint32_t maxOpenFiles;
|
||||||
|
uint32_t openFiles;
|
||||||
|
|
||||||
// Function declarations
|
// Function declarations
|
||||||
void listFiles();
|
void listFiles();
|
||||||
void printRegs();
|
void printRegs();
|
||||||
void printPhysicalMemmap();
|
void printPhysicalMemmap();
|
||||||
|
void initOpenFileTable();
|
||||||
// FS things
|
|
||||||
char* cwd;
|
|
||||||
|
|
||||||
__attribute__ ((section("entry")))
|
__attribute__ ((section("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
@@ -74,16 +79,9 @@ void main() {
|
|||||||
mallocVirtualAddr = kernelMallocVirtualAddr;
|
mallocVirtualAddr = kernelMallocVirtualAddr;
|
||||||
mallocPhysicalAddr = kernelMallocPhysicalAddr;
|
mallocPhysicalAddr = kernelMallocPhysicalAddr;
|
||||||
mallocPages = kernelMallocPages;
|
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
|
// FS Setup
|
||||||
|
initOpenFileTable();
|
||||||
cwd = malloc(1024);
|
cwd = malloc(1024);
|
||||||
strcpy(cwd, "/");
|
strcpy(cwd, "/");
|
||||||
|
|
||||||
@@ -345,3 +343,25 @@ void printPhysicalMemmap() {
|
|||||||
printf("Free blocks: %d\n\n", maxBlocks - usedBlocks);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user