diff --git a/Makefile b/Makefile index 083535e..502e94b 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ GCC_PREF=riscv32-unknown-elf- CC=$(GCC_PREF)gcc OBJDUMP=$(GCC_PREF)objdump -CFLAGS=-I$(KLIBDIR) -MD -mcmodel=medany -Wall -Wextra -pedantic-errors +CFLAGS=-I$(KLIBDIR) -MD -mcmodel=medany -Wall -Wextra -pedantic-errors -Wno-builtin-declaration-mismatch KERNEL_CFLAGS=-nostdlib -T linker.ld ARCH = rv32im # here you diff --git a/kinclude/ecall.c b/kinclude/ecall.c index 8af3db2..d01ec4f 100644 --- a/kinclude/ecall.c +++ b/kinclude/ecall.c @@ -1,12 +1,19 @@ +#include "ktypes.h" #include "ecall.h" #include "sched.h" #include "csr.h" #include "io.h" +// this type is only used here, therefore we don't need it in the ktypes header typedef int (*ecall_handler)(int*,ProcessControlBlock*); ecall_handler ecall_table[ECALL_TABLE_LEN] = { 0 }; + +// ignore unused parameter errors only for these functions +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" + int ecall_handle_spawn_thread(int* args_ptr, ProcessControlBlock* pcb) { void* entry = (void*) args_ptr[0]; @@ -55,6 +62,8 @@ int ecall_handle_exit(int* args, ProcessControlBlock* pcb) return 0; } +#pragma GCC diagnostic pop + void trap_handle_ecall() { { diff --git a/kinclude/ecall.h b/kinclude/ecall.h index 242302b..51c1aeb 100644 --- a/kinclude/ecall.h +++ b/kinclude/ecall.h @@ -17,12 +17,6 @@ enum ecall_codes { #define ECALL_TABLE_LEN 16 -enum error_code { - ENOCODE = -1, // invalid syscall code - EINVAL = -2, // invalid argument value - ENOMEM = -3, // not enough memory -}; - // initializer for ecall lookup table void init_ecall_table(); diff --git a/kinclude/io.c b/kinclude/io.c index 590afd2..32f2fd2 100644 --- a/kinclude/io.c +++ b/kinclude/io.c @@ -29,13 +29,6 @@ void dbgln(char* text, int len) *((char*) TEXT_IO_ADDR) = 1; } -#else - -/* if no textIO module loaded, dbgln is a noop :( */ -void dbgln(char*, int){} - -#endif - /* alphabet for itoa */ char alpha[16] = "0123456789abcdef"; @@ -60,4 +53,15 @@ char* itoa (int value, char* str, int base) while (value > 0); return str; -} \ No newline at end of file +} + +#else + +/* if no textIO module loaded, dbgln is a noop :( */ +void dbgln(char* text, int len){} +char* itoa (int value, char* str, int base) { + return str; +} + +#endif + diff --git a/kinclude/malloc.c b/kinclude/malloc.c index 97a0342..cb3226c 100644 --- a/kinclude/malloc.c +++ b/kinclude/malloc.c @@ -11,9 +11,9 @@ void malloc_init(malloc_info* given_info) allocate_memory_end = given_info->allocate_memory_end; } -void* malloc(size_t size) +optional_voidptr malloc(size_t size) { - return (void*) ENOMEM; + return (optional_voidptr) { .error = ENOMEM }; } int free(void* ptr) @@ -22,12 +22,12 @@ int free(void* ptr) } // allocate stack and return a pointer to the *end* of the allocated region -void* malloc_stack(size_t size) +optional_voidptr malloc_stack(size_t size) { void* new_alloc_end = (void*) (((int) allocate_memory_end) - size); if (new_alloc_end < global_malloc_info.allocate_memory_start) - return (void*) ENOMEM; + return (optional_voidptr) { .error = ENOMEM }; void* stack_top = allocate_memory_end; allocate_memory_end = new_alloc_end; - return stack_top; -} \ No newline at end of file + return (optional_voidptr) { .value = stack_top }; +} diff --git a/kinclude/malloc.h b/kinclude/malloc.h index 687efc4..57be51d 100644 --- a/kinclude/malloc.h +++ b/kinclude/malloc.h @@ -1,17 +1,17 @@ #ifndef H_MALLOC #define H_MALLOC -typedef unsigned int size_t; +#include "ktypes.h" typedef struct malloc_info { void* allocate_memory_end; void* allocate_memory_start; } malloc_info; -void* malloc(size_t size); +optional_voidptr malloc(size_t size); // int free(void* ptr); -void* malloc_stack(size_t size); +optional_voidptr malloc_stack(size_t size); void malloc_init(malloc_info* info); diff --git a/kinclude/sched.h b/kinclude/sched.h index 991f95a..a808c7a 100644 --- a/kinclude/sched.h +++ b/kinclude/sched.h @@ -2,26 +2,7 @@ #define H_SCHED #include "../kernel.h" - -enum process_status { - PROC_DEAD = 0, - PROC_RDY = 1, - PROC_WAIT_PROC = 2, - PROC_WAIT_SLEEP = 3, -}; - -// process structure: -typedef struct ProcessControlBlock ProcessControlBlock; -struct ProcessControlBlock { - int pid; - int pc; - int regs[31]; - int exit_code; - // scheduling information - enum process_status status; - ProcessControlBlock *waiting_for_process; - unsigned long long int asleep_until; -}; +#include "ktypes.h" // scheduling data: extern ProcessControlBlock processes[PROCESS_COUNT];