Used filesys.h in kernel

This commit is contained in:
2024-05-26 14:13:46 +02:00
parent dd3b5c000f
commit 01323c5874
2 changed files with 93 additions and 150 deletions
+9 -4
View File
@@ -16,13 +16,17 @@ typedef struct {
char* filetable = (char*)FILETABLE_LOC; // Pretty sure we don't have to care about the bootloader at 0x7c00 char* filetable = (char*)FILETABLE_LOC; // Pretty sure we don't have to care about the bootloader at 0x7c00
fileEntry_t* findFile(char* filename) { // TODO: Don't modify the filename string. (maybe make a copy??) fileEntry_t* findFile(const char* filename) {
char* filetype = strchr(filename, '.'); if (strlen(filename) > 14) { return NULL; } // Filename too long
static char filenameBuf[16];
strcpy(filenameBuf, filename);
char* filetype = strchr(filenameBuf, '.');
*filetype++ = '\0'; // Split filename and filetype by a NULL *filetype++ = '\0'; // Split filename and filetype by a NULL
char* ft = filetable; char* ft = filetable;
while (*ft != '\0') { while (*ft != '\0') {
if (strcmp(filename, ft) != 0) { // Filename doesn't match if (strcmp(filenameBuf, ft) != 0) { // Filename doesn't match
ft += 16; // Goto next entry ft += 16; // Goto next entry
continue; continue;
} }
@@ -58,7 +62,8 @@ void writeFile(char* filename, void* buffer) { // TODO: Add length so we don't w
file = (fileEntry_t*)filetable; file = (fileEntry_t*)filetable;
while (*(char*)file != '\0') { file++; } // Find end of the filetable while (*(char*)file != '\0') { file++; } // Find end of the filetable
// strchr(filename, '.'); TODO: We don't have to do this, because findFile() modifies the string like this *strchr(filename, '.') = '\0';
char* filetype = filename + strlen(filename); // + 1? char* filetype = filename + strlen(filename); // + 1?
fileEntry_t* previous = file - 1; fileEntry_t* previous = file - 1;
+31 -93
View File
@@ -1,34 +1,35 @@
#include <memory/physical.h>
#include <disk/disk.h>
#include <screen/text.h>
#include <interrupt/idt.h> #include <interrupt/idt.h>
#include <interrupt/exceptions.h> #include <interrupt/exceptions.h>
#include <interrupt/syscall.h> #include <interrupt/syscall.h>
#include <interrupt/pic.h> #include <interrupt/pic.h>
#include <ports/io.h>
#include <string.h>
#include <screen/graphics.h>
#include <keyboard/keyboard.h>
#include <interrupt/pit.h> #include <interrupt/pit.h>
#include <interrupt/rtc.h> #include <interrupt/rtc.h>
#include <time.h> #include <keyboard/keyboard.h>
#include <sound/pcspk.h>
#include <sound/notes.h> #include <memory/physical.h>
#include <memory/virtual.h> #include <memory/virtual.h>
#include <memory/addresses.h> #include <memory/addresses.h>
#include <memory/malloc.h> #include <memory/malloc.h>
#include <disk/filesys.h>
#include <disk/disk.h>
#include <screen/text.h>
#include <screen/graphics.h>
#include <sound/pcspk.h>
#include <sound/notes.h>
#include <ports/io.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <time.h>
#define PROMPT "#> " #define PROMPT "#> "
char* filetable = (char*)FILETABLE_LOC; // Pretty sure we don't have to care about the bootloader at 0x7c00
// Function declarations // Function declarations
void printFiletable(char* ft);
void printPhysicalMemmap(); void printPhysicalMemmap();
__attribute__ ((section("entry"))) __attribute__ ((section("entry")))
void main() { void main() {
diskRead(5, 1, filetable);
// Interrupt setup // Interrupt setup
setupIdt(); setupIdt();
setupExceptions(); setupExceptions();
@@ -71,12 +72,10 @@ void main() {
deinitMemoryRegion(gfxMode->physicalBasePtr, fbSize * BLOCK_SIZE); deinitMemoryRegion(gfxMode->physicalBasePtr, fbSize * BLOCK_SIZE);
// Screen setup // Screen setup
diskRead(46, 4, font); // TODO: Find font in filetable readFile("term16n.fnt", font);
clear(); clear();
print("kern.\n\n"); print("kern.\n\n");
diskRead(5, 1, filetable); // Read the filetable and store it in memory
// Run Interactive Shell Program // Run Interactive Shell Program
// TODO: Make it in another file // TODO: Make it in another file
@@ -269,31 +268,17 @@ void main() {
print("\nTests Finished!\n"); print("\nTests Finished!\n");
} else { } else {
char* ft = filetable; fileEntry_t* file = findFile(input);
uint8_t found = 0;
while (*ft != '\0') { if (file == NULL) {
char filename[15] = { 0 }; print("Command not found: ");
uint8_t offset = 0; print(input);
for (uint8_t i = 0; i < 14; i++) { putc('\n');
if (i == 9) {
filename[offset++] = '.';
continue; continue;
} }
if (*ft != '\0') { filename[offset++] = *ft; }
ft++;
}
if (strcmp(input, filename) == 0) { uint32_t neededPages = (file->length * 512) / PAGE_SIZE;
ft++; // RESERVED if ((file->length * 512) % PAGE_SIZE > 0) { neededPages++; }
uint8_t sector = *ft++;
uint8_t size = *ft++;
found++; // Set found to 1
char* fileType = strchr(filename, '.') + 1;
uint32_t neededPages = (size * 512) / PAGE_SIZE;
if ((size * 512) % PAGE_SIZE > 0) { neededPages++; }
char* entryPoint = (char*)0x400000; // Right after first 4MB char* entryPoint = (char*)0x400000; // Right after first 4MB
for (uint32_t i = 0; i < neededPages; i++) { for (uint32_t i = 0; i < neededPages; i++) {
@@ -308,9 +293,9 @@ void main() {
} }
} }
diskRead(sector, size, entryPoint); readFile(input, entryPoint);
if (strcmp(fileType, "bin") == 0) { if (strcmp(file->filetype, "bin") == 0) {
// Reset malloc // Reset malloc
mallocListHead = NULL; mallocListHead = NULL;
mallocVirtualAddr = (uint32_t)entryPoint + neededPages * PAGE_SIZE; mallocVirtualAddr = (uint32_t)entryPoint + neededPages * PAGE_SIZE;
@@ -333,16 +318,16 @@ void main() {
mallocVirtualAddr = 0; mallocVirtualAddr = 0;
mallocPhysicalAddr = 0; mallocPhysicalAddr = 0;
mallocPages = 0; mallocPages = 0;
} else if (strcmp(fileType, "tab") == 0) { } else if (strcmp(file->filetype, "tab") == 0) {
printFiletable(entryPoint); printFiletable(entryPoint);
} else if (strcmp(fileType, "fnt") == 0) { } else if (strcmp(file->filetype, "fnt") == 0) {
print("Loading "); print("Loading ");
print(filename); print(file->filename);
print("...\n"); print("...\n");
memcpy(entryPoint, font, size * 512); memcpy(entryPoint, font, file->length * 512);
print("Font loaded\n"); print("Font loaded\n");
} else { } else {
for (size_t i = 0; i < size * 512; i++) { for (size_t i = 0; i < file->length * 512; i++) {
if (entryPoint[i] != '\0') { if (entryPoint[i] != '\0') {
putc(entryPoint[i]); putc(entryPoint[i]);
} }
@@ -358,58 +343,11 @@ void main() {
flushTlbEntry(virtualAddr); // Invalidate unused page flushTlbEntry(virtualAddr); // Invalidate unused page
} }
} }
break;
}
ft += 3;
}
if (!found) {
print("Command not found: ");
print(input);
putc('\n');
}
}
} }
} }
void printFiletable(char* ft) { outw(0x604, 0x2000); // QEMU - Quit emulator
while (*ft != '\0') { while (1); // Just hang
char filename[15] = { 0 };
uint8_t offset = 0;
for (uint8_t i = 0; i < 14; i++) {
if (i == 9) {
filename[offset++] = '.';
continue;
}
if (*ft != '\0') { filename[offset++] = *ft; }
ft++;
}
ft++; // RESERVED
uint8_t sector = *ft++;
uint8_t size = *ft++;
if (sector < 10) putc('0');
if (sector == 0) putc('0');
else print(itoa(sector, 10));
print(": ");
print(filename);
for (uint8_t i = 14 - strlen(filename); i > 0; i--) {
putc(' ');
}
print(" | ");
if (size >> 1) {
print(itoa(size >> 1, 10));
if (size & 0x01) { print(".5"); }
print("kB\n");
} else {
print(itoa(size*512, 10));
print("B\n");
}
}
} }
void printPhysicalMemmap() { void printPhysicalMemmap() {