Implemented a proper libk

This commit is contained in:
2024-10-09 16:45:37 +02:00
parent 9ff817b935
commit 95d32f025a
45 changed files with 1713 additions and 1524 deletions
+5 -27
View File
@@ -5,19 +5,20 @@
#include <interrupt/pit.h>
#include <interrupt/rtc.h>
#include <keyboard/keyboard.h>
#include <memory/physical.h>
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <memory/malloc.h>
#include <fs/fs.h>
#include <fs/impl.h>
#include <disk/disk.h>
#include <screen/text.h>
#include <screen/graphics.h>
#include <screen/gfxmode.h>
#include <terminal/terminal.h>
#include <sound/pcspk.h>
#include <sound/notes.h>
#include <ports/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -29,9 +30,6 @@
// FS things
char* cwd;
FILE* openFileTable = (FILE*)OPEN_FILE_TABLE_LOC;
uint32_t openFiles;
// Function declarations
void listFiles();
void printRegs();
@@ -87,6 +85,7 @@ void main() {
// Terminal setup
terminal->fg = FG_COLOR;
terminal->bg = BG_COLOR;
clear();
printf("kern.\n\n");
@@ -239,7 +238,7 @@ void main() {
printf("Command not found: %s\n", fileName);
continue;
}
FILE* fp = openFileTable + _f->_file;
FILE* fp = fsInfo->openFileTable + _f->_file;
printf("%d: 0x%x Bytes\n", fp->_file, fp->_size);
for (size_t i = 0; i < fp->_size; i++) {
@@ -368,24 +367,3 @@ void printPhysicalMemmap() {
printf("Free blocks: %d\n\n", maxBlocks - usedBlocks);
}
void initOpenFileTable() {
openFileTable = malloc(sizeof(FILE) * MAX_OPEN_FILES);
if (openFileTable == NULL) { printf("\e[1MFailed to init file table! Malloc() error.\e[8M"); }
memset(openFileTable, 0, sizeof(FILE) * MAX_OPEN_FILES);
// offset and ptr are unused in these
stdin = openFileTable + 0;
stdin->_file = 0;
stdin->_flag = O_RDONLY;
stdout = openFileTable + 1;
stdout->_file = 1;
stdout->_flag = O_WRONLY | O_APPEND;
stderr = openFileTable + 2;
stderr->_file = 2;
stderr->_flag = O_WRONLY | O_APPEND;
openFiles = 3;
}
+7 -7
View File
@@ -1,15 +1,14 @@
#include <memory/physical.h>
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <screen/gfxmode.h>
#include <screen/text.h>
#include <error/bigerr.h>
#include <disk/disk.h>
#include <fs/impl.h>
#include <fs/fs.h>
#include <screen/gfxmode.h>
#include <error/bigerr.h>
#include <stdio.h>
void bigError();
__attribute__ ((section("entry")))
void main() {
// Physical memory manager setup
@@ -34,7 +33,7 @@ void main() {
superblock_t* sb = (superblock_t*)SUPERBLOCK_LOC;
sb->rootInodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t);
inode_t* root = (inode_t*)sb->rootInodePtr;
diskRead(root->extent[0].block * 8, root->extent[0].length * 8, (void*)SCRATCH_BLOCK_LOC);
loadFile(root, (void*)SCRATCH_BLOCK_LOC);
inode_t* inode;
if ((inode = getInode("kernel.bin", (dirEntry_t*)SCRATCH_BLOCK_LOC)) == NULL) {
@@ -42,10 +41,11 @@ void main() {
bigError(0xDEAD);
} else { loadFile(inode, (void*)KERNEL_LOC); }
font_t* font = (font_t*)FONT_LOC;
if ((inode = getInode("term16n.fnt", (dirEntry_t*)SCRATCH_BLOCK_LOC)) != NULL) {
loadFile(inode, (void*)FONT_LOC);
loadFile(inode, font);
} else if ((inode = getInode("testfont.fnt", (dirEntry_t*)SCRATCH_BLOCK_LOC)) != NULL) {
loadFile(inode, (void*)FONT_LOC);
loadFile(inode, font);
} else {
// No font found, bad.
bigError(0xBeef);