diff options
author | Marvin Borner | 2020-11-12 21:47:53 +0100 |
---|---|---|
committer | Marvin Borner | 2020-11-12 21:47:53 +0100 |
commit | 8d08b8e80440b310e623c0ae397065bf28d94d1e (patch) | |
tree | 327262179e1b721ea01a8b71121bd0023600f721 | |
parent | bef485ad8159d79b9ea7a31aa41450fc995f5724 (diff) |
Traced some issues; disabled malloc alignment
-rw-r--r-- | .gdbinit | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | libc/mem.c | 53 | ||||
-rw-r--r-- | libc/print.c | 5 | ||||
-rwxr-xr-x | run | 2 |
6 files changed, 32 insertions, 33 deletions
@@ -1,3 +1,2 @@ file build/kernel.elf target remote localhost:1234 -c @@ -1,7 +1,7 @@ # MIT License, Copyright (c) 2020 Marvin Borner # Kernel optimization -OPTIMIZATION = -O0 +OPTIMIZATION = -Ofast # Remove tree optimizations for kernel #CFLAGS_EXTRA = -fno-tree-bit-ccp -fno-tree-builtin-call-dce -fno-tree-ccp -fno-tree-ch -fno-tree-coalesce-vars -fno-tree-copy-prop -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-fre -fno-tree-pta -fno-tree-sink -fno-tree-slsr -fno-tree-sra -fno-tree-ter -fno-tree-loop-vectorize -fno-inline-functions -fno-inline-functions-called-once diff --git a/kernel/Makefile b/kernel/Makefile index 36aa9ee..dd3ce5a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -24,7 +24,7 @@ OC = ccache ../cross/opt/bin/i686-elf-objcopy AS = ccache nasm WARNINGS = -Wall -Wextra -pedantic-errors -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wno-long-long -CFLAGS = $(WARNINGS) -Wno-address-of-packed-member -nostdlib -nostdinc -ffreestanding -fno-builtin -mno-red-zone -mgeneral-regs-only -std=c99 -m32 -Wl,-ekernel_main -I../libc/inc/ -Iinc/ -Dkernel $(CFLAGS_EXTRA) $(OPTIMIZATION) $(DEBUG) +CFLAGS = $(WARNINGS) -Wno-address-of-packed-member -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-profile-generate -mno-red-zone -mgeneral-regs-only -std=c99 -m32 -Wl,-ekernel_main -I../libc/inc/ -Iinc/ -Dkernel $(CFLAGS_EXTRA) $(OPTIMIZATION) $(DEBUG) ASFLAGS = -f elf32 all: compile @@ -58,29 +58,29 @@ int memcmp(const void *s1, const void *s2, u32 n) #ifdef kernel -#define ALIGNMENT 16ul -#define ALIGN_TYPE char -#define ALIGN_INFO sizeof(ALIGN_TYPE) * 16 - -#define ALIGN(ptr) \ - if (ALIGNMENT > 1) { \ - u32 diff; \ - ptr = (void *)((u32)ptr + ALIGN_INFO); \ - diff = (u32)ptr & (ALIGNMENT - 1); \ - if (diff != 0) { \ - diff = ALIGNMENT - diff; \ - ptr = (void *)((u32)ptr + diff); \ - } \ - *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)) = diff + ALIGN_INFO; \ - } - -#define UNALIGN(ptr) \ - if (ALIGNMENT > 1) { \ - u32 diff = *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)); \ - if (diff < (ALIGNMENT + ALIGN_INFO)) { \ - ptr = (void *)((u32)ptr - diff); \ - } \ - } +/* #define ALIGNMENT 1ul */ +/* #define ALIGN_TYPE char */ +/* #define ALIGN_INFO sizeof(ALIGN_TYPE) * 16 */ + +/* #define ALIGN(ptr) \ */ +/* if (ALIGNMENT > 1) { \ */ +/* u32 diff; \ */ +/* ptr = (void *)((u32)ptr + ALIGN_INFO); \ */ +/* diff = (u32)ptr & (ALIGNMENT - 1); \ */ +/* if (diff != 0) { \ */ +/* diff = ALIGNMENT - diff; \ */ +/* ptr = (void *)((u32)ptr + diff); \ */ +/* } \ */ +/* *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)) = diff + ALIGN_INFO; \ */ +/* } */ + +/* #define UNALIGN(ptr) \ */ +/* if (ALIGNMENT > 1) { \ */ +/* u32 diff = *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)); \ */ +/* if (diff < (ALIGNMENT + ALIGN_INFO)) { \ */ +/* ptr = (void *)((u32)ptr - diff); \ */ +/* } \ */ +/* } */ static u32 *heap; static u32 index; @@ -110,13 +110,13 @@ void *malloc(u32 size) if (size < 1) return NULL; - size = size + ALIGNMENT + ALIGN_INFO; + /* size = size + ALIGNMENT + ALIGN_INFO; */ heap[index] = size; index += size + 1; void *p = (void *)(heap + index - size); - ALIGN(p); + /* ALIGN(p); */ return p; } @@ -124,7 +124,8 @@ void *malloc(u32 size) // TODO: Implement free, realloc and find_smallest_hole void free(void *ptr) { - UNALIGN(ptr); + (void)ptr; + /* UNALIGN(ptr); */ } void *realloc(void *ptr, u32 size) diff --git a/libc/print.c b/libc/print.c index 84c4975..629a410 100644 --- a/libc/print.c +++ b/libc/print.c @@ -20,7 +20,7 @@ int vsprintf(char *str, const char *format, va_list ap) int i = 0; char buf = 0; - char format_buffer[20] = "\0"; + char format_buffer[20] = { '\0' }; for (; *format; format++) { if (ready_to_format) { @@ -79,8 +79,7 @@ int vsprintf(char *str, const char *format, va_list ap) int vprintf(const char *format, va_list ap) { - char buf[1024]; - memset(buf, 0, 1024); + char buf[1024] = { 0 }; int len = vsprintf(buf, format, ap); serial_print(buf); // TODO: Remove temporary serial print return len; @@ -183,7 +183,7 @@ make_debug() { } make_disasm() { - objdump -drwC -Mintel build/debug.o | less -R + objdump -drwC -Mintel build/kernel.elf | less -R #hexdump -C build/kernel.bin | less -R } |