Commited some old changes, idk what they were

This commit is contained in:
2024-07-30 21:07:05 +02:00
parent 8e004221e1
commit 105076a8ce
14 changed files with 238 additions and 222 deletions
+39 -8
View File
@@ -10,8 +10,8 @@
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <memory/malloc.h>
#include <disk/filesys.h>
#include <disk/disk.h>
#include <fs/fs.h>
#include <fs/impl.h>
#include <screen/text.h>
#include <screen/graphics.h>
#include <sound/pcspk.h>
@@ -23,14 +23,22 @@
#include <string.h>
#include <time.h>
#include <color.h>
#include <fs/fs.h>
#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
void listFiles();
void printRegs();
void printPhysicalMemmap();
void initOpenFileTable();
void initOpenINodeTable();
__attribute__ ((section("entry")))
void main() {
@@ -73,6 +81,18 @@ 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, "/");
// Terminal setup
terminal->fg = FG_COLOR;
terminal->bg = BG_COLOR;
clear();
@@ -81,7 +101,7 @@ void main() {
// Run Interactive Shell Program
// TODO: Make it in another file
while (1) {
printf(PROMPT);
printf("%s %s ", currentDir, PROMPT);
char input[256];
char* inputPtr = input;
@@ -223,12 +243,13 @@ void main() {
} else if (strcmp(argv[0], "test") == 0) {
printf("\x1b[1MError: 'test' is not available.\x1b[8M\n");
} else { // TODO: Use new filesystem!
/*
fileEntry_t* file = findFile(argv[0]);
if (file == NULL) {
if (file == NULL) {*/
printf("Command not found: %s\n", argv[0]);
continue;
}
/*}
uint32_t neededPages = (file->length * 512) / PAGE_SIZE;
if ((file->length * 512) % PAGE_SIZE > 0) { neededPages++; }
@@ -291,7 +312,7 @@ void main() {
unmapPage((void*)virtualAddr);
flushTlbEntry(virtualAddr); // Invalidate unused page
}
}
}*/
}
}
@@ -375,3 +396,13 @@ 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 };
}
+3 -3
View File
@@ -369,9 +369,9 @@ DATA_SEG equ GDT.dataDescriptor - GDT.start
;; VBE Stuff
;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !!
width: dw 0
height: dw 0
bpp: db 0
width: dw 1920
height: dw 1080
bpp: db 32
offset: dw 0
_segment: dw 0 ; segment is a keyword
+11 -38
View File
@@ -2,12 +2,9 @@
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <disk/disk.h>
//#include <disk/filesys.h>
#include <screen/gfxmode.h>
#include <fs/impl.h>
#include <fs/fs.h>
uint8_t loadFile(char* filename, void* dest);
#include <screen/gfxmode.h>
__attribute__ ((section("entry")))
void main() {
@@ -31,11 +28,17 @@ void main() {
// Load root dir, find kernel INode and parse it
superBlock_t* superblock = (superBlock_t*)SUPERBLOCK_LOC;
superblock->rootInodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t);
superblock->rootINodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t);
diskRead(superblock->firstDataBlock * 8, 8, (void*)SCRATCH_BLOCK_LOC);
if (loadFile("kernel.bin", (void*)KERNEL_LOC) != 0) __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
if (loadFile("term16n.fnt", (void*)FONT_LOC) != 0) __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
inode_t* inode;
if ((inode = getINode("kernel.bin")) == NULL) {
__asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
} else { loadFile(inode, (void*)KERNEL_LOC); }
if ((inode = getINode("term16n.fnt")) == NULL) {
__asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
} else { loadFile(inode, (void*)FONT_LOC); }
// Virtual memory manager setup
if (setupVirtualMemoryManager() != 0) {
@@ -66,33 +69,3 @@ void main() {
((void(*)(void))0xC0000000)();
}
uint8_t loadFile(char* filename, void* dest) {
dirEntry_t* dirEntry = (dirEntry_t*)SCRATCH_BLOCK_LOC;
while (dirEntry->name[0] != '\0') {
if (strcmp(dirEntry->name, filename) == 0) break;
dirEntry++;
}
if (dirEntry->name[0] == '\0') return 1;
inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC;
while (inode->id != dirEntry->id) {
inode++;
}
uint32_t totalBlocks = bytesToBlocks(inode->sizeBytes);
uint32_t addressOffset = 0;
for (uint8_t i = 0; i < 4 && totalBlocks > 0; i++) {
diskRead(inode->extent[i].firstBlock * 8, inode->extent[i].length * 8, dest + addressOffset);
addressOffset += inode->extent[i].length * FS_BLOCK_SIZE;
totalBlocks -= inode->extent[i].length;
}
if (totalBlocks > 0) {
// TODO: Indirect extents
}
return 0;
}