bundled all types into ktypes.h and added optionals

master
Anton Lydike 3 years ago
parent b6d967262a
commit c8c19f298a

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

@ -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() {
{

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

@ -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";
@ -61,3 +54,14 @@ char* itoa (int value, char* str, int base)
return str;
}
#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

@ -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;
return (optional_voidptr) { .value = stack_top };
}

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

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

Loading…
Cancel
Save