minor fixes

This commit is contained in:
xamidev
2024-09-16 14:38:39 +02:00
parent e6f119236b
commit af716cb2ec
9 changed files with 38 additions and 8 deletions

View File

@@ -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;
}

View File

@@ -6,6 +6,7 @@
#include "kheap.h"
#include <stdint.h>
#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)

View File

@@ -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);

View File

@@ -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;

20
src/kernel/syscall.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdarg.h>
#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;
}

8
src/kernel/syscall.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef SYSCALL_H
#define SYSCALL_H
#define SYSCALL_PRINTF 0
typedef void (*syscall_t)();
#endif

View File

@@ -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;
}