summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenji Dial <benji3.141@gmail.com>2020-05-25 15:35:45 -0400
committerBenji Dial <benji3.141@gmail.com>2020-05-25 15:35:45 -0400
commit44c0352f0d4124d7c367352e4de746a51b9db42b (patch)
tree65ad0862c92c4e2d134585b48fbfcc5bead165ea
parentc99a319d3405d4ac76881cae288c29624fa34a44 (diff)
downloadportland-os-44c0352f0d4124d7c367352e4de746a51b9db42b.tar.gz
got file loading working properly
-rw-r--r--doc/internal/mem.txt13
-rw-r--r--fs/bleh.txt1
-rw-r--r--makefile8
-rw-r--r--qemu-debug.gdb3
-rw-r--r--src/kernel/fat.c48
-rw-r--r--src/kernel/main.c14
6 files changed, 67 insertions, 20 deletions
diff --git a/doc/internal/mem.txt b/doc/internal/mem.txt
index ea96d13..d8b9913 100644
--- a/doc/internal/mem.txt
+++ b/doc/internal/mem.txt
@@ -1,7 +1,6 @@
-0x0001.0000 - 0x0001.ffff: unused
-0x0002.0000 - 0x0002.7fff: fat
-0x0002.8000 - 0x0002.bfff: unused
-0x0002.c000 - 0x0002.ffff: file buffers
-0x0003.0000 - 0x0003.7fff: kernel
-0x0003.8000 - 0x0003.ffff: stack
-0x0004.0000 - 0x000f.ffff: unused \ No newline at end of file
+0x0001.0000 - 0x0001.ffff (64k): unused
+0x0002.0000 - 0x0002.7fff (32k): fat
+0x0002.8000 - 0x0002.bfff (16k): unused
+0x0002.c000 - 0x0002.ffff (16k): 32 file buffers
+0x0003.0000 - 0x0003.7fff (32k): kernel
+0x0003.8000 - 0x0003.ffff (32k): kernel stack \ No newline at end of file
diff --git a/fs/bleh.txt b/fs/bleh.txt
new file mode 100644
index 0000000..d6d9d34
--- /dev/null
+++ b/fs/bleh.txt
@@ -0,0 +1 @@
+blah \ No newline at end of file
diff --git a/makefile b/makefile
index afac808..bc4bdd7 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,4 @@
-disk: kernel boot
+disk: kernel boot fs-
mkdir -p obj out
/sbin/mkfs.fat -C -f 1 -F 16 -n "PORTLAND OS" -R 17 -s 1 -S 512 obj/shadow.img 8192
echo -n -e '\xeb\x3c' > obj/jmp.bin
@@ -6,13 +6,17 @@ disk: kernel boot
dd if=out/boot.bin of=obj/shadow.img obs=1 seek=62 conv=notrunc
dd if=out/kernel.bin of=obj/shadow.img seek=1 conv=notrunc
mv obj/shadow.img out/disk.img
+ mcopy -i out/disk.img -s out/fs/bleh.txt ::/
vdi-file: disk
VBoxManage convertfromraw out/disk.img out/disk.vdi --uuid a61929ed-3bf2-45ff-b98a-44f87c616dba
-debug: vdi-file
+debug: disk
gdb -x qemu-debug.gdb
+fs-:
+ cp -r fs out/fs
+
kgccargs = -m32 -ffreestanding -fno-asynchronous-unwind-tables
kernel:
mkdir -p obj/kernel out
diff --git a/qemu-debug.gdb b/qemu-debug.gdb
index de29caa..f8f541f 100644
--- a/qemu-debug.gdb
+++ b/qemu-debug.gdb
@@ -2,5 +2,6 @@ target remote | qemu-system-i386 -S -gdb stdio out/disk.img
add-symbol-file obj/kernel.elf
set disassembly-flavor intel
layout reg
-break *0x30000
+break main
+break panic
cont
diff --git a/src/kernel/fat.c b/src/kernel/fat.c
index e574da5..b8d1c3b 100644
--- a/src/kernel/fat.c
+++ b/src/kernel/fat.c
@@ -7,8 +7,28 @@ void load_fat() {
read_sectors(FAT_INFO->reserved_sectors, FAT_INFO->sectors_per_fat, FAT);
}
-bool check_fat_name(uint8_t *fname, uint8_t *sname) {
- panic("Not implemented (check_fat_name)");
+bool to_fat_name(uint8_t *sname, uint8_t *fname) {
+ uint8_t *sp = sname, *fp = fname;
+ while (*sp != '.') {
+ if (!*sp) {
+ while (fp != fname + 11)
+ *(fp++) = ' ';
+ return false;
+ }
+ if (sp == sname + 8)
+ return true;
+ *(fp++) = *(sp++);
+ }
+ while (fp != fname + 8)
+ *(fp++) = ' ';
+ while (*++sp) {
+ if (fp == fname + 11)
+ return true;
+ *(fp++) = *sp;
+ }
+ while (fp != fname + 11)
+ *(fp++) = ' ';
+ return false;
}
bool check_fat_names(uint8_t *lname, uint8_t *rname) {
@@ -27,27 +47,35 @@ void load_root() {
}
struct directory_entry *load_subentry(uint8_t *name) {
+ uint8_t fname[11];
+ if (to_fat_name(name, fname))
+ return 0;
struct directory_entry *ptr = buffer;
uint16_t dir_current = dir_start;
- do
- if (((ptr == buffer + 16) && !read_sectors(buffer_from = dir_current++, 1, ptr = buffer)) || !ptr->name[0])
- return 0;
- while (!check_fat_name(ptr->name, name));
- return ptr;
+ read_sectors(buffer_from = dir_current, 1, buffer);
+ while (*(uint8_t *)ptr) {
+ if (check_fat_names(ptr->name, fname))
+ return ptr;
+ if (++ptr == buffer + 16) {
+ read_sectors(buffer_from = ++dir_current, 1, buffer);
+ ptr = buffer;
+ }
+ };
+ return 0;
}
bool load_subdir(uint8_t *name) {
struct directory_entry *e = load_subentry(name);
if (!e)
return true;
- dir_start = e->first_cluster;
+ dir_start = CTOS(e->first_cluster);
return false;
}
struct directory_entry *load_entry(uint8_t *path) {
load_root();
- for (uint8_t *ptr = path; ptr; ++ptr)
- if (*ptr = '/') {
+ for (uint8_t *ptr = path; *ptr; ++ptr)
+ if (*ptr == '/') {
*ptr = 0;
if (load_subdir(path))
return 0;
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 194ce93..92e778c 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -54,5 +54,19 @@ void main() {
u32_dec(e.length, nbuf);
vga_printsz(nbuf);
}
+ fs_close(root);
+ if (root = fs_open("BLEH.TXT")) {
+ vga_printsz("\n\nContents of BLEH.TXT:");
+ uint8_t l;
+ uint8_t line[82];
+ line[0] = '\n';
+ line[1] = ' ';
+ line[2] = ' ';
+ while (l = fs_read(root, 78, line + 3)) {
+ line[l + 3] = 0;
+ vga_printsz(line);
+ }
+ fs_close(root);
+ }
halt();
} \ No newline at end of file