aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-07-24 15:21:36 +0200
committerMarvin Borner2020-07-24 15:21:36 +0200
commitfd73441fe4950c683699fe38ad59e4541b75e5a7 (patch)
tree7f549911388fd3881e52bbf2139aed8170c97481
parent43183fe6b259005174a424828b2fbb06bfeb4a90 (diff)
Bug hunting for file reading (ext2 idp recursion)
-rw-r--r--Makefile2
-rwxr-xr-xrun18
-rw-r--r--src/drivers/interrupts.c5
-rw-r--r--src/drivers/keyboard.c2
-rw-r--r--src/features/fs.c24
-rw-r--r--src/inc/fs.h6
-rw-r--r--src/main.c1
7 files changed, 41 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 31666a7..b0326a0 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ LD = cross/opt/bin/i686-elf-ld
AS = nasm
# TODO: Use lib as external library
-CFLAGS = -Wall -Wextra -nostdlib -nostdinc -ffreestanding -mgeneral-regs-only -std=c99 -pedantic-errors -Isrc/lib/inc/ -Isrc/inc/ -c
+CFLAGS = -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-pic -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Isrc/lib/inc/ -Isrc/inc/ -c
ASFLAGS = -f elf32
diff --git a/run b/run
index 0a41b63..8309eaa 100755
--- a/run
+++ b/run
@@ -62,6 +62,13 @@ make_cross() {
fi
}
+make_disk() {
+ rm -rf disk && mkdir -p disk/
+ cd disk/
+
+ wget "https://raw.githubusercontent.com/fcambus/spleen/master/spleen-12x24.bdf" -O font24.bdf
+}
+
make_build() {
mkdir -p build/
rm -rf build/*
@@ -77,6 +84,15 @@ make_build() {
./ext2util/ext2util -x build/disk.img -wf kernel.bin -i 5 >/dev/null
rm kernel.bin
+ echo "Hello, world!" >disk/test.txt
+
+ mkdir -p mnt/
+ sudo mount build/disk.img mnt/
+ sudo cp disk/* mnt/
+ cat disk/* >/dev/null
+ sudo umount mnt/
+ rm -rf mnt/
+
printf "Build finshed successfully!\n\n"
}
@@ -143,6 +159,8 @@ elif [ "${mode}" = "sync" ]; then
make_sync
elif [ "${mode}" = "tidy" ]; then
make_tidy
+elif [ "${mode}" = "disk" ]; then
+ make_disk
elif [ "${mode}" = "" ]; then # TODO: Prevent code duplication in build script via functions?
make_cross
make_clean
diff --git a/src/drivers/interrupts.c b/src/drivers/interrupts.c
index edf5837..d65490c 100644
--- a/src/drivers/interrupts.c
+++ b/src/drivers/interrupts.c
@@ -4,6 +4,7 @@
#include <cpu.h>
#include <def.h>
#include <interrupts.h>
+#include <mem.h>
#include <serial.h>
/**
@@ -29,8 +30,8 @@ void idt_install()
idt_ptr.limit = (sizeof(struct idt_entry) * 256) - 1;
idt_ptr.base = &idt;
- // Clear IDT by setting memory cells to 0 // TODO
- //memset(&idt, 0, sizeof(struct idt_entry) * 256);
+ // Clear IDT by setting memory cells to 0
+ memset(&idt, 0, sizeof(struct idt_entry) * 256);
__asm__("lidt %0" : : "m"(idt_ptr));
}
diff --git a/src/drivers/keyboard.c b/src/drivers/keyboard.c
index 3bef356..558563e 100644
--- a/src/drivers/keyboard.c
+++ b/src/drivers/keyboard.c
@@ -9,7 +9,7 @@ u8 scancode;
void keyboard_handler()
{
scancode = inb(0x60);
- serial_print("KEY\n");
+ //serial_print("KEY\n");
//struct keyboard_event *event = malloc(sizeof(struct keyboard_event));
//event->scancode = scancode;
//event_trigger(MAP_KEYBOARD, (u8 *)event);
diff --git a/src/features/fs.c b/src/features/fs.c
index a90aaa9..123a178 100644
--- a/src/features/fs.c
+++ b/src/features/fs.c
@@ -56,20 +56,20 @@ void *read_file(struct inode *in)
int num_blocks = in->blocks / (BLOCK_SIZE / SECTOR_SIZE);
- // assert(num_blocks != 0);
+ //assert(num_blocks != 0);
if (!num_blocks)
return NULL;
u32 sz = BLOCK_SIZE * num_blocks;
void *buf = malloc(sz);
+ printf("Loading %dKiB\n", sz >> 10);
//assert(buf != NULL);
- int indirect = 0;
+ int indirect;
// Single indirect pointer
- if (num_blocks > 12) {
+ if (num_blocks > 12)
indirect = in->block[12];
- }
int blocknum = 0;
char *data;
@@ -77,14 +77,15 @@ void *read_file(struct inode *in)
if (i < 12) {
blocknum = in->block[i];
data = buffer_read(blocknum);
- memcpy((void *)((u32)buf + (i * BLOCK_SIZE)), data, BLOCK_SIZE);
- }
- if (i > 12) {
+ memcpy((u32 *)buf + i * BLOCK_SIZE, data, BLOCK_SIZE);
+ } else {
blocknum = read_indirect(indirect, i - 13);
data = buffer_read(blocknum);
- memcpy((void *)((u32)buf + ((i - 1) * BLOCK_SIZE)), data, BLOCK_SIZE);
+ memcpy((u32 *)buf + (i - 1) * BLOCK_SIZE, data, BLOCK_SIZE);
}
}
+
+ // TODO: Fix space between 1024 and 4096
return buf;
}
@@ -100,7 +101,7 @@ int find_inode(const char *name, int dir_inode)
for (u32 q = 0; q < i->blocks / 2; q++) {
char *data = buffer_read(i->block[q]);
- memcpy((void *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE);
+ memcpy((u32 *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE);
}
struct dirent *d = (struct dirent *)buf;
@@ -129,14 +130,14 @@ void ls_root()
for (u32 q = 0; q < i->blocks / 2; q++) {
char *data = buffer_read(i->block[q]);
- memcpy((void *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE);
+ memcpy((u32 *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE);
}
struct dirent *d = (struct dirent *)buf;
int sum = 0;
int calc = 0;
- printf("Root directory:\n");
+ printf("\nRoot directory:\n");
do {
calc = (sizeof(struct dirent) + d->name_len + 4) & ~0x3;
sum += d->total_len;
@@ -147,4 +148,5 @@ void ls_root()
d = (struct dirent *)((u32)d + d->total_len);
} while (sum < 1024);
+ printf("\n");
}
diff --git a/src/inc/fs.h b/src/inc/fs.h
index e5e1ca7..222939b 100644
--- a/src/inc/fs.h
+++ b/src/inc/fs.h
@@ -91,7 +91,9 @@ struct file {
u32 curr_block_pos;
};
-// DEMO ;)
-void ls_root();
+int find_inode(const char *name, int dir_inode);
+struct inode *get_inode(int i);
+void *read_file(struct inode *in);
+void ls_root(); // DEMO ;)
#endif
diff --git a/src/main.c b/src/main.c
index 7e4c083..a5e5409 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@ void main(struct mem_info *mem_info, struct vid_info *vid_info)
printf("hello\n");
ls_root();
+ read_file(get_inode(find_inode("font24.bdf", 2)));
while (1) {
};