Created small static library to wrap system call ABI

This commit is contained in:
2023-09-07 00:58:57 -05:00
parent 112b4204a7
commit a5ce86147d
9 changed files with 275 additions and 119 deletions

View File

@@ -1 +1,2 @@
nobase_include_HEADERS = types/status.h types/syscallid.h types/physaddr.h types/syscallarg.h
nobase_include_HEADERS = types/status.h types/syscallid.h types/physaddr.h \
types/syscallarg.h sys/syscalls.h types/pid.h types/oid.h

View File

@@ -7,11 +7,13 @@
#include "syscalls.h"
#include "types/syscallid.h"
#include "types/status.h"
#include "types/pid.h"
#include "types/oid.h"
#include <libmalloc/memmap.h>
#include <stddef.h>
#define MAX_SYSCALL_ID 256
#define module_limit 8
#define MODULE_LIMIT 8
#define IO_OP 1 << 0
#define IO_SYNC 0 << 0
@@ -40,95 +42,48 @@ struct boot_info_t
size_t memory_size;
memory_map_t map;
size_t module_count;
struct module_t modules[module_limit];
struct module_t modules[MODULE_LIMIT];
};
struct message_t
{
unsigned long sender;
pid_t sender;
unsigned long code;
unsigned long args[6];
};
enum process_state_t
{
PROCESS_ACTIVE,
PROCESS_REQUESTING,
PROCESS_SENDING
};
struct process_t
{
unsigned long pid;
int priority;
physaddr_t page_table;
enum process_state_t state;
struct queue_t sending_queue;
struct queue_t message_queue;
struct message_t *message_buffer;
struct process_context_t *ctx;
};
struct port_t
{
unsigned long id;
unsigned long owner_pid;
};
struct signal_action_t
{
unsigned long pid;
signal_handler_t func_ptr;
void (*trampoline_ptr)();
void *userdata;
};
struct signal_context_t
{
unsigned long signal_id;
};
struct kernel_t
{
struct syscall_t syscall_table[MAX_SYSCALL_ID];
struct priority_queue_t priority_queue;
struct avltree_t *interrupt_handlers;
struct avltree_t *port_table;
struct avltree_t *process_table;
struct process_t *active_process;
int next_pid;
};
void kernel_initialize(struct boot_info_t *boot_info);
error_t set_syscall(int id, int arg_count, int pid, void *func_ptr);
error_t kernel_set_syscall(int id, int arg_count, pid_t pid, void *func_ptr);
size_t do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, void *pc, void *stack, unsigned long flags);
size_t kernel_do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, void *pc, void *stack, unsigned long flags);
error_t kernel_load_module(struct module_t *module);
unsigned long kernel_current_pid();
pid_t kernel_current_pid();
struct process_context_t *kernel_current_context();
error_t kernel_store_active_context(struct process_context_t *context);
unsigned long kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space);
pid_t kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space);
struct process_context_t *kernel_advance_scheduler();
error_t kernel_terminate_process(size_t process_id);
error_t kernel_terminate_process(pid_t process_id);
error_t kernel_create_port(unsigned long id);
error_t kernel_remove_port(unsigned long id);
unsigned long kernel_get_port_owner(unsigned long id);
pid_t kernel_get_port_owner(unsigned long id);
error_t kernel_send_message(unsigned long recipient, struct message_t *message);
error_t kernel_queue_message(unsigned long recipient, struct message_t *message);
int kernel_receive_message(struct message_t *buffer, int flags);
error_t kernel_register_interrupt_handler(unsigned long interrupt, signal_handler_t handler, void *userdata);
error_t kernel_remove_interrupt_handler(unsigned long interrupt);
@@ -137,6 +92,10 @@ error_t kernel_execute_interrupt_handler(unsigned long interrupt);
error_t kernel_signal_return();
int receive_message(struct message_t *buffer, int flags);
error_t kernel_create_object(size_t size, unsigned long flags, oid_t *id);
void panic(const char *message) __attribute__ ((noreturn));
error_t kernel_attach_object(oid_t id, void *virt_addr);
error_t kernel_release_object(oid_t id);
void kernel_panic(const char *message) __attribute__ ((noreturn));

65
include/sys/syscalls.h Normal file
View File

@@ -0,0 +1,65 @@
#ifndef _QUARK_SYSCALLS_H
#define _QUARK_SYSCALLS_S
#include <types/syscallarg.h>
#include <types/syscallid.h>
#include <types/physaddr.h>
unsigned long _do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3);
static inline int kprint(const char *s)
{
syscall_arg_t arg1;
syscall_arg_t arg2;
syscall_arg_t arg3;
arg1.ptr = (void*)s;
arg2.unsigned_int = 0UL;
arg3.signed_int = 0UL;
return (int) _do_syscall(SYSCALL_TEST, arg1, arg2, arg3);
}
static inline int mmap(void *addr, unsigned long length, long flags)
{
syscall_arg_t arg1;
syscall_arg_t arg2;
syscall_arg_t arg3;
arg1.ptr = addr;
arg2.unsigned_int = length;
arg3.signed_int = flags;
return (int) _do_syscall(SYSCALL_MMAP, arg1, arg2, arg3);
}
static inline int munmap(void *addr, unsigned long length)
{
syscall_arg_t arg1;
syscall_arg_t arg2;
syscall_arg_t arg3;
arg1.ptr = addr;
arg2.unsigned_int = length;
arg3.unsigned_int = 0UL;
return (int) _do_syscall(SYSCALL_MUNMAP, arg1, arg2, arg3);
}
static inline int map_physical(void *addr, physaddr_t phys_addr, unsigned long length)
{
syscall_arg_t arg1;
syscall_arg_t arg2;
syscall_arg_t arg3;
arg1.ptr = addr;
arg2.unsigned_int = phys_addr;
arg3.unsigned_int = length;
return (int) _do_syscall(SYSCALL_MAP_PHYS, arg1, arg2, arg3);
}
static inline int unmap_physical(void *addr, unsigned long length)
{
syscall_arg_t arg1;
syscall_arg_t arg2;
syscall_arg_t arg3;
arg1.ptr = addr;
arg2.unsigned_int = length;
arg3.unsigned_int = 0UL;
return (int) _do_syscall(SYSCALL_UNMAP_PHYS, arg1, arg2, arg3);
}
#endif

View File

@@ -28,20 +28,26 @@ struct syscall_t
size_t test_syscall(syscall_arg_t str);
size_t mmap(syscall_arg_t location, syscall_arg_t length, syscall_arg_t flags);
size_t syscall_mmap(syscall_arg_t location, syscall_arg_t length, syscall_arg_t flags);
size_t munmap(syscall_arg_t location, syscall_arg_t length);
size_t syscall_munmap(syscall_arg_t location, syscall_arg_t length);
size_t map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length);
size_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length);
size_t unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length);
size_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length);
size_t terminate_self();
size_t syscall_terminate_self();
size_t send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
size_t syscall_create_object();
size_t receive(syscall_arg_t buffer, syscall_arg_t flags);
size_t syscall_aquire_object();
size_t open_port(syscall_arg_t id);
size_t syscall_release_object();
size_t close_port(syscall_arg_t id);
size_t syscall_send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
size_t syscall_receive(syscall_arg_t buffer, syscall_arg_t flags);
size_t syscall_open_port(syscall_arg_t id);
size_t syscall_close_port(syscall_arg_t id);