diff --git a/hello.bin b/hello.bin deleted file mode 100755 index 2021365..0000000 Binary files a/hello.bin and /dev/null differ diff --git a/makefile b/makefile index ab2aa73..386b5c8 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc -CFLAGS = -ffreestanding -g -Wall -Wextra -Wno-builtin-declaration-mismatch -mno-sse -mno-mmx -mno-avx -march=i386 -c -I src/ +CFLAGS = -ffreestanding -g -Wall -Wextra -mno-sse -mno-mmx -mno-avx -march=i386 -c -I src/ LD = ld LDFLAGS = -T link.ld -melf_i386 AS = nasm diff --git a/src/kernel/initrd.c b/src/kernel/initrd.c index 3183f20..84cccc0 100644 --- a/src/kernel/initrd.c +++ b/src/kernel/initrd.c @@ -232,7 +232,7 @@ void* load_file_from_initrd(uint8_t* initrd, const char* filename) void* file_content = tar_get_file_content(file); memcpy(file_data, file_content, file_size); - printf("Loaded '%s' at 0x%x, size=%u\n", filename, (unsigned int)file_data, file_size); + printf("[initrd] Loaded '%s' at 0x%x, size=%u\n", filename, (unsigned int)file_data, file_size); return file_data; } diff --git a/src/kernel/kheap.c b/src/kernel/kheap.c index d845103..888ed1d 100644 --- a/src/kernel/kheap.c +++ b/src/kernel/kheap.c @@ -6,6 +6,7 @@ #include "kheap.h" #include #include "system.h" +#include "../libc/stdio.h" // Free list allocator @@ -17,6 +18,7 @@ void init_alloc() free_list = (block_t*)heap; free_list->size = HEAP_SIZE-sizeof(block_t); free_list->next = NULL; + printf("[kernel] initialized heap and allocator, start=0x%x\n", heap); } void* malloc(size_t size) diff --git a/src/kernel/kheap.h b/src/kernel/kheap.h index 8aba820..f41fa37 100644 --- a/src/kernel/kheap.h +++ b/src/kernel/kheap.h @@ -17,7 +17,6 @@ typedef struct block #define HEAP_SIZE 1024*1024 // 1MB malloc-able - void init_alloc(); void* malloc(size_t size); void free(void* ptr); diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index ebcaba4..b1e60a8 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -123,9 +123,9 @@ void kmain(multiboot2_info *mb_info) void* binary_file = load_file_from_initrd((uint8_t*)initrd_addr, "./hello.bin"); if (binary_file == NULL) { - printf("NOT LOADED...\n"); + printf("[debug] Failed to load test program!\n"); } else { - printf("LOADED!\n"); + printf("[debug] Test program loaded!\n"); } void (*program_entry)() = (void (*)())binary_file; diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c new file mode 100644 index 0000000..a117fc7 --- /dev/null +++ b/src/kernel/syscall.c @@ -0,0 +1,20 @@ +#include +#include "../libc/stdio.h" +#include "syscall.h" + +syscall_t syscalls[] = { + (syscall_t)printf, +}; + +int syscall_handler(int syscall_num, ...) +{ + if ((unsigned)syscall_num < sizeof(syscalls)/sizeof(syscall_t)) + { + va_list args; + va_start(args, syscall_num); + syscalls[syscall_num](va_arg(args, const char*)); + va_end(args); + return 0; + } + return -1; +} diff --git a/src/kernel/syscall.h b/src/kernel/syscall.h new file mode 100644 index 0000000..4367ba6 --- /dev/null +++ b/src/kernel/syscall.h @@ -0,0 +1,8 @@ +#ifndef SYSCALL_H +#define SYSCALL_H + +#define SYSCALL_PRINTF 0 + +typedef void (*syscall_t)(); + +#endif diff --git a/src/programs/hello.c b/src/programs/hello.c index f4c73e9..09df5fa 100644 --- a/src/programs/hello.c +++ b/src/programs/hello.c @@ -1,8 +1,9 @@ -#include "../libc/stdio.h" -#include "../drivers/serial.h" +void user_printf(const char* format) { + asm volatile ("int $0x80" : : "a"(1), "b"(format)); +} void main() { - serial_printf(3, "Hello, world, from a PROGRAM!\n"); + user_printf("Hello, world, from a PROGRAM!\n"); return; }