aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rwxr-xr-xrun4
-rw-r--r--src/drivers/cpu.c3
-rw-r--r--src/features/fs.c16
4 files changed, 16 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 314c894..4b97fcc 100644
--- a/Makefile
+++ b/Makefile
@@ -22,17 +22,17 @@ LD = cross/opt/bin/i686-elf-ld
AS = nasm
# Flags to make the binary smaller TODO: Remove after indirect pointer support!
-CSFLAGS = -fno-stack-protector -fomit-frame-pointer -ffunction-sections -fdata-sections -Wl,--gc-sections -mpreferred-stack-boundary=2 -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-math-errno -fno-unroll-loops -fmerge-all-constants -fno-ident -ffast-math
+CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
# TODO: Use lib as external library
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-pic -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Isrc/lib/inc/ -Isrc/inc/ -c
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-pic -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Isrc/lib/inc/ -Isrc/inc/
ASFLAGS = -f elf32
all: compile clean
%.o: %.c
- @$(CC) $(CFLAGS) $< -o $@
+ @$(CC) -c $(CFLAGS) $< -o $@
%_asm.o: %.asm
@$(AS) $(ASFLAGS) $< -o $@
@@ -43,6 +43,7 @@ compile: kernel
@mkdir -p build/
@$(AS) -f bin src/entry.asm -o build/boot.bin
@$(LD) -N -emain -Ttext 0x00050000 -o build/kernel.bin $(COBJS) --oformat binary
+ @$(CC) $(CFLAGS) -emain -o build/debug.o $(COBJS)
clean:
@find src/ -name "*.o" -type f -delete
diff --git a/run b/run
index 687ac46..3774f4d 100755
--- a/run
+++ b/run
@@ -112,8 +112,8 @@ make_debug() {
}
make_disasm() {
- objdump -drwC -Mintel build/melvix.bin --visualize-jumps=color | less -R
- #hexdump -C build/melvix.bin | less -R
+ objdump -drwC -Mintel build/debug.o --visualize-jumps=color | less -R
+ #hexdump -C build/kernel.bin | less -R
}
make_sync() {
diff --git a/src/drivers/cpu.c b/src/drivers/cpu.c
index d6a1760..945dc4a 100644
--- a/src/drivers/cpu.c
+++ b/src/drivers/cpu.c
@@ -24,7 +24,8 @@ u32 inl(u16 port)
return value;
}
-void insl(u16 port, void *addr, int n)
+// TODO: Fix optimization issues with insl
+void __attribute__((optimize("O0"))) insl(u16 port, void *addr, int n)
{
__asm__("cld; rep insl"
: "=D"(addr), "=c"(n)
diff --git a/src/features/fs.c b/src/features/fs.c
index 7795210..1eec30e 100644
--- a/src/features/fs.c
+++ b/src/features/fs.c
@@ -1,6 +1,7 @@
// MIT License, Copyright (c) 2020 Marvin Borner
// EXT2 based filesystem
+#include <assert.h>
#include <def.h>
#include <fs.h>
#include <ide.h>
@@ -29,7 +30,9 @@ struct bgd *get_bgd()
struct inode *get_inode(int i)
{
struct superblock *s = get_superblock();
+ assert(s);
struct bgd *b = get_bgd();
+ assert(b);
int block_group = (i - 1) / s->inodes_per_group;
int index = (i - 1) % s->inodes_per_group;
@@ -50,28 +53,23 @@ u32 read_indirect(u32 indirect, u32 block_num)
void *read_inode(struct inode *in)
{
- //assert(in);
+ assert(in);
if (!in)
return NULL;
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);
+ assert(buf != NULL);
int indirect;
- // Singly indirect pointer
- // TODO: Support doubly and triply pointers
- if (num_blocks > 12)
- indirect = in->block[12];
-
int blocknum = 0;
char *data;
for (int i = 0; i < num_blocks; i++) {
@@ -80,6 +78,8 @@ void *read_inode(struct inode *in)
data = buffer_read(blocknum);
memcpy((u32 *)((u32)buf + i * BLOCK_SIZE), data, BLOCK_SIZE);
} else {
+ // TODO: Support doubly and triply pointers
+ indirect = in->block[12];
blocknum = read_indirect(indirect, i - 12);
data = buffer_read(blocknum);
memcpy((u32 *)((u32)buf + (i - 1) * BLOCK_SIZE), data, BLOCK_SIZE);