From 40e84e5b705a3d551dc64aa162777df3ffe1c32a Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Wed, 14 Aug 2024 10:43:12 +0200 Subject: [PATCH] Finished custom filesystem and got it to boot normally --- README.md | 9 +++++---- include/fs/impl.h | 16 +++++++--------- kern.iso | Bin 1470464 -> 1470464 bytes src/kernel.c | 37 +++++++------------------------------ src/stage3.c | 6 +++--- todo.txt | 28 +++++++++++++++++----------- 6 files changed, 39 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index e3d415c..bba856f 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,20 @@ Idk why i called it that it was 3am and i needed sleep ## About Kern is a 32-bit OS based on the x86 architecture written in NASM Assembly and C. -I'm working on a basic command line as well as a custom filesystem (filetable for now). +I'm working on a basic command line as well as a custom unix-esque filesystem. It has a simple shell with some commands. (Use 'help' for a list of available ones) Since there's always more to do, here are the [todos](todo.txt). ### Features -- Filesystem (filetable) +- Filesystem - Interactive Shell - Disk I/O - Font support (funky format) - 1920x1080 Resolution, 32bpp - Physical memory manager +- Virtual memory manager +- Syscalls ## Building & Running If you want to try kern for some reason, you can. @@ -53,10 +55,9 @@ Graphics test: \ _These images may be outdated, Idk_ ## Known issues -- If you run any of the bootloader stages or kernel form the shell, it will most likely break. (Maybe add an executable flag?) - fillCircle() in graphics.h is broken. No idea why, so no filled circles for you (i commented out the boundaryFill call in the function) - convertColor() doesn't work right, because i should be using floating point, but -mgeneral-regs-only doesn't let me :( -- The soundtest command is very likely to get stuck on a note and play it forever. (Maybe a Sleep() bug?) +- The soundtest command and sleep commands cause an unknown exception. Sleep() syscall issue - Not really an issue, bit QEMU's PIT is really slow and inacurate ## [Old Version](https://github.com/Tom-on64/old-kern) diff --git a/include/fs/impl.h b/include/fs/impl.h index 935beb2..3982443 100644 --- a/include/fs/impl.h +++ b/include/fs/impl.h @@ -6,20 +6,18 @@ #include #include -char* currentDir; +superblock_t* impl_superblock = (superblock_t*)SUPERBLOCK_LOC; -inode_t* getInode(char* path) { - dirEntry_t* dentry = (dirEntry_t*)SCRATCH_BLOCK_LOC; - - while (dentry->name[0] != '\0') { - if (strcmp(dentry->name, path)) break; - dentry++; +inode_t* getInode(char* path, dirEntry_t* dentries) { + while (dentries->name[0] != '\0') { + if (strcmp(dentries->name, path) == 0) break; + dentries++; } - if (dentry->name[0] == '\0') return NULL; + if (dentries->name[0] == '\0') return NULL; inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC; - while (inode->id != dentry->id) { inode++; } + while (inode->id != dentries->id) { inode++; } return inode; } diff --git a/kern.iso b/kern.iso index 2af9ee848587a338202a3df2c11cd90a75298071..67e38bac384bcf6babb6528c0a973f10ad56968f 100644 GIT binary patch delta 3312 zcmZWrdsGzH8NU~H!veePiXfmMppqP33MOb&JYwTBHt8a2cofkpI>9ypWR)n$>cYUd zY<=8>rfQT|JoHqOX*X4@uOaf%CdSvX9vdSVAA@TQif@hE@0-yc()@A1`8~dS=ezgL z%pGfYhP69GtVp4Y8J{wR);c>jnG)|$_^v2wMMto$B_N*=Y8jH6>K63? z-J%AfY*+JUxc;4*$`KPK5J3I{WP4JZpO$3h2z{-xr}e z7D9;RJ_)&bZuvBOx_DezEqDnn7+s@<^NFV)+!h{e+!_bGs-~9x=64|)^qiN9XHj4K zTRP!ituC!Su!|j8GMsj?@0LVqy1-`(`A|KsPphmIrr)gVVq=!t{Lv9wTYL3_0X@MW zv9_hjP!!Fb0&!|?xDV>Fff7X4S{bcTz^%%$;2zJ-(pXWqR(+s?pQ=VstMk~hA3Z|s z*?Q|FQWRu1yDhpjdCDWV8@9JXDq@XW*VFOrW%im=$otS!L#hdJhP`)|Zp{xXYZ^+$m2|r-Kz~FafL6BhmwsFT!5R6AZB6+$~rvPV^!YX9Xlzp>qKoIl+&RPR%F} zR3C%zL=FlBxFZ6>R6yWS^xQ)T5sqeNzypu~8QCoxt2l zn9J3%g#}zl69{Q?Gvq7FV=O-eRh!M+XY5izfx!uG?^U=3Je2!bc3}`b$Sj3%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Table; -inode_t* openINodeTable; -uint32_t maxOpenFiles = 256; -uint32_t openFileCount = 3; // First 3 reserved for stdin, stdout, stderr -uint32_t maxOpenINodes = 256; -uint32_t openINodeCount = 0; - // Function declarations void listFiles(); void printRegs(); void printPhysicalMemmap(); -void initOpenFileTable(); -void initOpenINodeTable(); + +// FS things +char* cwd; __attribute__ ((section("entry"))) void main() { @@ -81,16 +75,9 @@ void main() { mallocPhysicalAddr = kernelMallocPhysicalAddr; mallocPages = kernelMallocPages; - // Setup filesystem - currentDir = malloc(1024); - strcpy(currentDir, "/"); // Start at root - - - // Setup kernel open file table and open inode table - initOpenFileTable(); - initOpenINodeTable(); - currentDir = malloc(1024); - strcpy(currentDir, "/"); + // FS Setup + cwd = malloc(1024); + strcpy(cwd, "/"); // Terminal setup terminal->fg = FG_COLOR; @@ -101,7 +88,7 @@ void main() { // Run Interactive Shell Program // TODO: Make it in another file while (1) { - printf("%s %s ", currentDir, PROMPT); + printf("%s %s ", cwd, PROMPT); char input[256]; char* inputPtr = input; @@ -396,13 +383,3 @@ void printPhysicalMemmap() { printf("Free blocks: %d\n\n", maxBlocks - usedBlocks); } -void initOpenFileTable() { - //openFileTable = malloc(sizeof(openFileTable_t) * maxOpenFiles); - //*openFileTable = (openFileTable_t) { 0 }; -} - -void initOpenINodeTable() { - openINodeTable = malloc(sizeof(inode_t) * maxOpenINodes); - *openINodeTable = (inode_t) { 0 }; -} - diff --git a/src/stage3.c b/src/stage3.c index d575d29..dcfcbd7 100644 --- a/src/stage3.c +++ b/src/stage3.c @@ -36,14 +36,14 @@ void main() { diskRead(root->extent[0].block * 8, root->extent[0].length * 8, (void*)SCRATCH_BLOCK_LOC); inode_t* inode; - if ((inode = getInode("kernel.bin")) == NULL) { + if ((inode = getInode("kernel.bin", (dirEntry_t*)SCRATCH_BLOCK_LOC)) == NULL) { // kernel.bin doesn't exist??? very bad -> error bigError(0xDEAD); } else { loadFile(inode, (void*)KERNEL_LOC); } - if ((inode = getInode("term16n.fnt")) != NULL) { + if ((inode = getInode("term16n.fnt", (dirEntry_t*)SCRATCH_BLOCK_LOC)) != NULL) { loadFile(inode, (void*)FONT_LOC); - } else if ((inode = getInode("testfont.fnt")) != NULL) { + } else if ((inode = getInode("testfont.fnt", (dirEntry_t*)SCRATCH_BLOCK_LOC)) != NULL) { loadFile(inode, (void*)FONT_LOC); } else { // No font found, bad. diff --git a/todo.txt b/todo.txt index 9746489..31d652e 100644 --- a/todo.txt +++ b/todo.txt @@ -8,9 +8,9 @@ Legend: - [?] Optional - [x] Multistage Bootloader -- [ ] Bootloader reads filetable to find files +- [x] Bootloader reads filesystem to find files - [x] The almighty 'printf()' -- [!] Makefile refactorin' +- [_] Makefile refactorin' - [x] Write down where stuff is in memory (in notes.txt) - [ ] "Text" mode (not actually) - [x] Scrolling @@ -76,16 +76,17 @@ Legend: - [x] PI - [ ] Floating point macros/functions - [ ] Filesystem - - [!] Utility for filesystem building (not just an assembly file) - - [x] Better header for file i/o (disk/filesys.h) + - [x] Utility for filesystem building (not just an assembly file) + - [_] Better header for file i/o (disk/filesys.h) - [x] Filetable - - [ ] A better filesystem using INodes etc. - - [ ] Files + - [x] A better filesystem using INodes etc. + - [x] Files - [x] Larger than one sector (512B) - - [ ] Any file size (Not multiples of 512B) - - [ ] Filetypes + - [x] Any file size (Not multiples of 512B) + - [x] Filetypes - [ ] Directories - - [ ] File tree + - [x] File tree + - [x] Dir Entries - [ ] cd command - [ ] Links?? - [ ] Symbolic @@ -103,6 +104,11 @@ Legend: - [ ] Separate file/program - [ ] ';' separated commands - [ ] I/O Redirection with '<' '>' + - [x] Display directory in prompt + - [ ] Custom prompts + - [ ] Variables + - [ ] Enviromental/Global + - [ ] Normal - [ ] Commands - [x] echo - [x] clear @@ -130,10 +136,10 @@ Legend: - [x] Exit back to kernel/shell - [x] Let them use libs - [ ] Proper include files (LibC?) - - [ ] argc, argv[] + - [x] argc, argv[] - [ ] Standalone shell program - [ ] Userspace programs - - [ ] Calculator + - [x] Calculator - [ ] Calendar - [ ] Code Editor - [ ] Text editor