Finished custom filesystem and got it to boot normally

This commit is contained in:
2024-08-14 10:43:12 +02:00
parent d37abb7b65
commit 40e84e5b70
6 changed files with 39 additions and 57 deletions
+5 -4
View File
@@ -5,18 +5,20 @@ Idk why i called it that it was 3am and i needed sleep
## About ## About
Kern is a 32-bit OS based on the x86 architecture written in NASM Assembly and C. 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) 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). Since there's always more to do, here are the [todos](todo.txt).
### Features ### Features
- Filesystem (filetable) - Filesystem
- Interactive Shell - Interactive Shell
- Disk I/O - Disk I/O
- Font support (funky format) - Font support (funky format)
- 1920x1080 Resolution, 32bpp - 1920x1080 Resolution, 32bpp
- Physical memory manager - Physical memory manager
- Virtual memory manager
- Syscalls
## Building & Running ## Building & Running
If you want to try kern for some reason, you can. If you want to try kern for some reason, you can.
@@ -53,10 +55,9 @@ Graphics test: \
_These images may be outdated, Idk_ _These images may be outdated, Idk_
## Known issues ## 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) - 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 :( - 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 - Not really an issue, bit QEMU's PIT is really slow and inacurate
## [Old Version](https://github.com/Tom-on64/old-kern) ## [Old Version](https://github.com/Tom-on64/old-kern)
+7 -9
View File
@@ -6,20 +6,18 @@
#include <disk/disk.h> #include <disk/disk.h>
#include <stdint.h> #include <stdint.h>
char* currentDir; superblock_t* impl_superblock = (superblock_t*)SUPERBLOCK_LOC;
inode_t* getInode(char* path) { inode_t* getInode(char* path, dirEntry_t* dentries) {
dirEntry_t* dentry = (dirEntry_t*)SCRATCH_BLOCK_LOC; while (dentries->name[0] != '\0') {
if (strcmp(dentries->name, path) == 0) break;
while (dentry->name[0] != '\0') { dentries++;
if (strcmp(dentry->name, path)) break;
dentry++;
} }
if (dentry->name[0] == '\0') return NULL; if (dentries->name[0] == '\0') return NULL;
inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC; inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC;
while (inode->id != dentry->id) { inode++; } while (inode->id != dentries->id) { inode++; }
return inode; return inode;
} }
BIN
View File
Binary file not shown.
+7 -30
View File
@@ -26,19 +26,13 @@
#define PROMPT "#>" #define PROMPT "#>"
//openFileTable_t* openFileTable;
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 // Function declarations
void listFiles(); void listFiles();
void printRegs(); void printRegs();
void printPhysicalMemmap(); void printPhysicalMemmap();
void initOpenFileTable();
void initOpenINodeTable(); // FS things
char* cwd;
__attribute__ ((section("entry"))) __attribute__ ((section("entry")))
void main() { void main() {
@@ -81,16 +75,9 @@ void main() {
mallocPhysicalAddr = kernelMallocPhysicalAddr; mallocPhysicalAddr = kernelMallocPhysicalAddr;
mallocPages = kernelMallocPages; mallocPages = kernelMallocPages;
// Setup filesystem // FS Setup
currentDir = malloc(1024); cwd = malloc(1024);
strcpy(currentDir, "/"); // Start at root strcpy(cwd, "/");
// Setup kernel open file table and open inode table
initOpenFileTable();
initOpenINodeTable();
currentDir = malloc(1024);
strcpy(currentDir, "/");
// Terminal setup // Terminal setup
terminal->fg = FG_COLOR; terminal->fg = FG_COLOR;
@@ -101,7 +88,7 @@ void main() {
// Run Interactive Shell Program // Run Interactive Shell Program
// TODO: Make it in another file // TODO: Make it in another file
while (1) { while (1) {
printf("%s %s ", currentDir, PROMPT); printf("%s %s ", cwd, PROMPT);
char input[256]; char input[256];
char* inputPtr = input; char* inputPtr = input;
@@ -396,13 +383,3 @@ void printPhysicalMemmap() {
printf("Free blocks: %d\n\n", maxBlocks - usedBlocks); 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 };
}
+3 -3
View File
@@ -36,14 +36,14 @@ void main() {
diskRead(root->extent[0].block * 8, root->extent[0].length * 8, (void*)SCRATCH_BLOCK_LOC); diskRead(root->extent[0].block * 8, root->extent[0].length * 8, (void*)SCRATCH_BLOCK_LOC);
inode_t* inode; 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 // kernel.bin doesn't exist??? very bad -> error
bigError(0xDEAD); bigError(0xDEAD);
} else { loadFile(inode, (void*)KERNEL_LOC); } } 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); 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); loadFile(inode, (void*)FONT_LOC);
} else { } else {
// No font found, bad. // No font found, bad.
+17 -11
View File
@@ -8,9 +8,9 @@ Legend:
- [?] Optional - [?] Optional
- [x] Multistage Bootloader - [x] Multistage Bootloader
- [ ] Bootloader reads filetable to find files - [x] Bootloader reads filesystem to find files
- [x] The almighty 'printf()' - [x] The almighty 'printf()'
- [!] Makefile refactorin' - [_] Makefile refactorin'
- [x] Write down where stuff is in memory (in notes.txt) - [x] Write down where stuff is in memory (in notes.txt)
- [ ] "Text" mode (not actually) - [ ] "Text" mode (not actually)
- [x] Scrolling - [x] Scrolling
@@ -76,16 +76,17 @@ Legend:
- [x] PI - [x] PI
- [ ] Floating point macros/functions - [ ] Floating point macros/functions
- [ ] Filesystem - [ ] Filesystem
- [!] Utility for filesystem building (not just an assembly file) - [x] Utility for filesystem building (not just an assembly file)
- [x] Better header for file i/o (disk/filesys.h) - [_] Better header for file i/o (disk/filesys.h)
- [x] Filetable - [x] Filetable
- [ ] A better filesystem using INodes etc. - [x] A better filesystem using INodes etc.
- [ ] Files - [x] Files
- [x] Larger than one sector (512B) - [x] Larger than one sector (512B)
- [ ] Any file size (Not multiples of 512B) - [x] Any file size (Not multiples of 512B)
- [ ] Filetypes - [x] Filetypes
- [ ] Directories - [ ] Directories
- [ ] File tree - [x] File tree
- [x] Dir Entries
- [ ] cd command - [ ] cd command
- [ ] Links?? - [ ] Links??
- [ ] Symbolic - [ ] Symbolic
@@ -103,6 +104,11 @@ Legend:
- [ ] Separate file/program - [ ] Separate file/program
- [ ] ';' separated commands - [ ] ';' separated commands
- [ ] I/O Redirection with '<' '>' - [ ] I/O Redirection with '<' '>'
- [x] Display directory in prompt
- [ ] Custom prompts
- [ ] Variables
- [ ] Enviromental/Global
- [ ] Normal
- [ ] Commands - [ ] Commands
- [x] echo - [x] echo
- [x] clear - [x] clear
@@ -130,10 +136,10 @@ Legend:
- [x] Exit back to kernel/shell - [x] Exit back to kernel/shell
- [x] Let them use libs - [x] Let them use libs
- [ ] Proper include files (LibC?) - [ ] Proper include files (LibC?)
- [ ] argc, argv[] - [x] argc, argv[]
- [ ] Standalone shell program - [ ] Standalone shell program
- [ ] Userspace programs - [ ] Userspace programs
- [ ] Calculator - [x] Calculator
- [ ] Calendar - [ ] Calendar
- [ ] Code Editor - [ ] Code Editor
- [ ] Text editor - [ ] Text editor