syscall #17

Merged
xamidev merged 17 commits from syscall into main 2026-04-02 19:16:35 +02:00
17 changed files with 59 additions and 59 deletions
Showing only changes of commit e9b57f70b1 - Show all commits
+2 -2
View File
@@ -36,7 +36,7 @@ struct idtr {
// All general-purpose registers (except rsp) as stored on the stack,
// plus the values we pushed (vector number, error code) and the iret frame
// In reverse order because the stack grows downwards.
struct cpu_status_t {
struct cpu_status {
uint64_t r15;
uint64_t r14;
uint64_t r13;
@@ -63,6 +63,6 @@ struct cpu_status_t {
uint64_t iret_ss;
};
struct cpu_status_t* syscall_handler(struct cpu_status_t* regs);
struct cpu_status* syscall_handler(struct cpu_status* regs);
#endif
+1 -1
View File
@@ -35,7 +35,7 @@ extern volatile uint64_t ticks;
// printf("debug: [%s]: " log "\n", __FILE__, ##__VA_ARGS__);
void panic(struct cpu_status_t* ctx, const char* str);
void panic(struct cpu_status* ctx, const char* str);
void hcf(void);
void idle(void);
+2 -2
View File
@@ -16,11 +16,11 @@
#include <stddef.h>
#include <stdint.h>
struct heap_block_t {
struct heap_block {
size_t size;
bool free; // 1byte
uint8_t reserved[7]; // (7+1 = 8 bytes)
struct heap_block_t* next;
struct heap_block* next;
} __attribute__((aligned(16)));
void kheap_init(void);
+1 -1
View File
@@ -34,7 +34,7 @@ extern uint64_t hhdm_off;
#define PAGE_ALIGN_DOWN(x) ((x) & PTE_ADDR_MASK)
#define ALIGN(size) ALIGN_UP(size, 16)
#define BLOCK_MIN_SIZE (sizeof(struct heap_block_t) + 16)
#define BLOCK_MIN_SIZE (sizeof(struct heap_block) + 16)
#define PML4_INDEX(x) (((x) >> 39) & 0x1FF)
#define PDPT_INDEX(x) (((x) >> 30) & 0x1FF)
+8 -8
View File
@@ -17,23 +17,23 @@ typedef enum {
DEAD
} status_t;
struct process_t {
struct process {
size_t pid;
char name[PROCESS_NAME_MAX];
status_t status;
struct cpu_status_t* context;
struct cpu_status* context;
void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511]
struct process_t* next;
struct process* next;
};
void process_init(void);
struct process_t* process_create(char* name, void(*function)(void*), void* arg);
void process_add(struct process_t** processes_list, struct process_t* process);
void process_delete(struct process_t** processes_list, struct process_t* process);
struct process_t* process_get_next(struct process_t* process);
struct process* process_create(char* name, void(*function)(void*), void* arg);
void process_add(struct process** processes_list, struct process* process);
void process_delete(struct process** processes_list, struct process* process);
struct process* process_get_next(struct process* process);
void process_exit(void);
void process_display_list(struct process_t* processes_list);
void process_display_list(struct process* processes_list);
#endif
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef SCHEDULER_H
#define SCHEDULER_H
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context);
struct cpu_status* scheduler_schedule(struct cpu_status* context);
void scheduler_init(void);
#endif
+3 -3
View File
@@ -10,13 +10,13 @@
#include <stdbool.h>
#include <stdint.h>
struct spinlock_t
struct spinlock
{
bool locked;
uint64_t rflags;
};
void spinlock_acquire(struct spinlock_t* lock);
void spinlock_release(struct spinlock_t* lock);
void spinlock_acquire(struct spinlock* lock);
void spinlock_release(struct spinlock* lock);
#endif
+3 -3
View File
@@ -108,7 +108,7 @@ static inline uint64_t read_cr2(void)
* Also displays an interpretation of the thrown error code.
* Then halts the system. We could implement demand paging later.
*/
static void page_fault_handler(struct cpu_status_t* ctx)
static void page_fault_handler(struct cpu_status* ctx)
{
// It could be used to remap pages etc. to fix the fault, but right now what I'm more
// interested in is getting more info out of those numbers cause i'm lost each time i have
@@ -149,7 +149,7 @@ static void page_fault_handler(struct cpu_status_t* ctx)
* Shows detail about a General Protection Fault,
* and what may have caused it. Halts the system.
*/
static void gp_fault_handler(struct cpu_status_t* ctx)
static void gp_fault_handler(struct cpu_status* ctx)
{
DEBUG("\x1b[38;5;231mGeneral Protection Fault at rip=0x%p, err=%u (%s)\x1b[0m",
ctx->iret_rip,
@@ -185,7 +185,7 @@ static void gp_fault_handler(struct cpu_status_t* ctx)
* Return:
* <context> - CPU context after interrupt
*/
struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
struct cpu_status* interrupt_dispatch(struct cpu_status* context)
{
if (context == NULL) {
panic(NULL, "Interrupt dispatch recieved NULL context!");
+1 -1
View File
@@ -7,7 +7,7 @@
#include <arch/x86.h>
#include <kernel.h>
struct cpu_status_t* syscall_handler(struct cpu_status_t* regs)
struct cpu_status* syscall_handler(struct cpu_status* regs)
{
DEBUG("Syscall %lx with argument %lx", regs->rdi, regs->rsi);
+1 -1
View File
@@ -47,7 +47,7 @@ void read_rflags(uint64_t rflags)
* Will display to terminal if it is initialized, otherwise serial only.
* Can be called with or without a CPU context.
*/
void panic(struct cpu_status_t* ctx, const char* str)
void panic(struct cpu_status* ctx, const char* str)
{
CLEAR_INTERRUPTS;
panic_count += 1;
+1 -1
View File
@@ -11,7 +11,7 @@
extern struct init_status init;
extern int panic_count;
struct spinlock_t serial_lock = {0};
struct spinlock serial_lock = {0};
/*
* outb - Writes a byte to a CPU port
+2 -2
View File
@@ -29,8 +29,8 @@ because this shitty implementation will be replaced one day by Flanterm
extern struct flanterm_context* ft_ctx;
extern struct init_status init;
struct spinlock_t term_lock = {0};
struct spinlock_t printf_lock = {0};
struct spinlock term_lock = {0};
struct spinlock printf_lock = {0};
extern int panic_count;
+3 -3
View File
@@ -63,9 +63,9 @@ extern volatile struct limine_hhdm_request hhdm_request;
extern volatile struct limine_kernel_address_request kerneladdr_request;
extern volatile struct limine_boot_time_request date_request;
extern struct process_t* processes_list;
extern struct process_t* current_process;
struct process_t* idle_proc;
extern struct process* processes_list;
extern struct process* current_process;
struct process* idle_proc;
void idle_main(void* arg)
{
+11 -11
View File
@@ -17,7 +17,7 @@ extern uint64_t kernel_virt_base;
uintptr_t kheap_start;
static struct heap_block_t* head = NULL;
static struct heap_block* head = NULL;
static uintptr_t end;
// Kernel root table (level 4)
@@ -55,8 +55,8 @@ void kheap_init()
end = current_addr;
// Give linked list head its properties
head = (struct heap_block_t*)kheap_start;
head->size = (end-kheap_start) - sizeof(struct heap_block_t);
head = (struct heap_block*)kheap_start;
head->size = (end-kheap_start) - sizeof(struct heap_block);
head->free = true;
head->next = NULL;
DEBUG("Kernel heap initialized, head=0x%p, size=%u bytes", head, head->size);
@@ -80,16 +80,16 @@ void* kmalloc(size_t size)
if (!size) return NULL;
size = ALIGN(size);
struct heap_block_t* curr = head;
struct heap_block* curr = head;
while (curr) {
// Is block free and big enough for us?
if (curr->free && curr->size >= size) {
// We split the block if it is big enough
if (curr->size >= size + sizeof(struct heap_block_t) + 16) {
struct heap_block_t* split = (struct heap_block_t*)((uintptr_t)curr + sizeof(struct heap_block_t) + size);
if (curr->size >= size + sizeof(struct heap_block) + 16) {
struct heap_block* split = (struct heap_block*)((uintptr_t)curr + sizeof(struct heap_block) + size);
split->size = curr->size - size - sizeof(struct heap_block_t);
split->size = curr->size - size - sizeof(struct heap_block);
split->free = true;
split->next = curr->next;
@@ -99,7 +99,7 @@ void* kmalloc(size_t size)
// Found a good block, we return it
curr->free = false;
return (void*)((uintptr_t)curr + sizeof(struct heap_block_t));
return (void*)((uintptr_t)curr + sizeof(struct heap_block));
}
// Continue browsing the list if nothing good was found yet
curr = curr->next;
@@ -127,11 +127,11 @@ void kfree(void* ptr)
if (!ptr) return;
// Set it free!
struct heap_block_t* block = (struct heap_block_t*)((uintptr_t)ptr - sizeof(struct heap_block_t));
struct heap_block* block = (struct heap_block*)((uintptr_t)ptr - sizeof(struct heap_block));
block->free = true;
// merge adjacent free blocks (coalescing)
struct heap_block_t* curr = head;
struct heap_block* curr = head;
while (curr && curr->next) {
if (curr->free && curr->next->free) {
curr->size += sizeof(*curr) + curr->next->size;
@@ -169,7 +169,7 @@ void* kalloc_stack()
void kheap_info()
{
uint64_t free_bytes = 0;
struct heap_block_t* curr = (struct heap_block_t*)kheap_start;
struct heap_block* curr = (struct heap_block*)kheap_start;
while (curr) {
if (curr->free == true) {
+12 -12
View File
@@ -16,8 +16,8 @@
extern struct flanterm_context* ft_ctx;
struct process_t* processes_list;
struct process_t* current_process;
struct process* processes_list;
struct process* current_process;
extern uint64_t *kernel_pml4;
@@ -39,10 +39,10 @@ void process_init()
* This function prints the linked list of processes
* to the DEBUG output.
*/
void process_display_list(struct process_t* processes_list)
void process_display_list(struct process* processes_list)
{
int process_view_id = 0;
struct process_t* tmp = processes_list;
struct process* tmp = processes_list;
while (tmp != NULL) {
DEBUG("{%d: %p} -> ", process_view_id, tmp);
tmp = tmp->next;
@@ -64,11 +64,11 @@ void process_display_list(struct process_t* processes_list)
* Return:
* <proc> - pointer to created process
*/
struct process_t* process_create(char* name, void(*function)(void*), void* arg)
struct process* process_create(char* name, void(*function)(void*), void* arg)
{
CLEAR_INTERRUPTS;
struct process_t* proc = (struct process_t*)kmalloc(sizeof(struct process_t));
struct cpu_status_t* ctx = (struct cpu_status_t*)kmalloc(sizeof(struct cpu_status_t));
struct process* proc = (struct process*)kmalloc(sizeof(struct process));
struct cpu_status* ctx = (struct cpu_status*)kmalloc(sizeof(struct cpu_status));
// No more memory?
if (!proc) return NULL;
@@ -108,7 +108,7 @@ struct process_t* process_create(char* name, void(*function)(void*), void* arg)
* @processes_list: pointer to the head of the linked list
* @process: process to add at the end of the linked list
*/
void process_add(struct process_t** processes_list, struct process_t* process)
void process_add(struct process** processes_list, struct process* process)
{
if (!process) return;
process->next = NULL;
@@ -119,7 +119,7 @@ void process_add(struct process_t** processes_list, struct process_t* process)
return;
}
struct process_t* tmp = *processes_list;
struct process* tmp = *processes_list;
while (tmp->next != NULL) {
tmp = tmp->next;
}
@@ -132,7 +132,7 @@ void process_add(struct process_t** processes_list, struct process_t* process)
* @processes_list: pointer to head of linked list
* @process: the process to delete from the list
*/
void process_delete(struct process_t** processes_list, struct process_t* process)
void process_delete(struct process** processes_list, struct process* process)
{
if (!processes_list || !*processes_list || !process) return;
@@ -144,7 +144,7 @@ void process_delete(struct process_t** processes_list, struct process_t* process
return;
}
struct process_t* tmp = *processes_list;
struct process* tmp = *processes_list;
while (tmp->next && tmp->next != process) {
tmp = tmp->next;
}
@@ -167,7 +167,7 @@ void process_delete(struct process_t** processes_list, struct process_t* process
* Return:
* <process->next> - process right after the one specified
*/
struct process_t* process_get_next(struct process_t* process)
struct process* process_get_next(struct process* process)
{
if (!process) return NULL;
return process->next;
+5 -5
View File
@@ -10,9 +10,9 @@
#include <stdint.h>
#include <io/serial/serial.h>
extern struct process_t* processes_list;
extern struct process_t* current_process;
extern struct process_t* idle_proc;
extern struct process* processes_list;
extern struct process* current_process;
extern struct process* idle_proc;
/*
* scheduler_init - Choose the first process
@@ -32,7 +32,7 @@ void scheduler_init()
* Return:
* <context> - CPU context for next process
*/
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
struct cpu_status* scheduler_schedule(struct cpu_status* context)
{
if (context == NULL) {
panic(NULL, "Scheduler called with NULL context");
@@ -51,7 +51,7 @@ struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
current_process->context = context;
for (;;) {
struct process_t* prev_process = current_process;
struct process* prev_process = current_process;
if (current_process->next != NULL) {
current_process = current_process->next;
} else {
+2 -2
View File
@@ -16,7 +16,7 @@
* Saves the RFLAGS register, then acquires a lock.
* Pause instruction is used to ease the CPU.
*/
void spinlock_acquire(struct spinlock_t* lock)
void spinlock_acquire(struct spinlock* lock)
{
uint64_t rflags;
asm volatile("pushfq ; pop %0 ; cli" : "=rm"(rflags) : : "memory");
@@ -36,7 +36,7 @@ void spinlock_acquire(struct spinlock_t* lock)
* unlocks it (clears locked state).
* RFLAGS is then restored.
*/
void spinlock_release(struct spinlock_t* lock)
void spinlock_release(struct spinlock* lock)
{
uint64_t rflags = lock->rflags;
__atomic_clear(&lock->locked, __ATOMIC_RELEASE);