Added IPC skeleton

This commit is contained in:
2025-05-07 18:53:41 +02:00
parent 2cd84b5e89
commit 2b4beae3c5
10 changed files with 182 additions and 35 deletions
+51
View File
@@ -0,0 +1,51 @@
#ifndef _IPC_H
#define _IPC_H
#include <kernel.h>
/*
* Message contents
*/
// Basic data
struct msg_uint8 { uint8_t data[56]; };
struct msg_uint16 { uint16_t data[28]; };
struct msg_uint32 { uint32_t data[14]; };
struct msg_uint64 { uint64_t data[7]; };
/*
* Message content types
*/
enum {
MSG_UINT8,
MSG_UINT16,
MSG_UINT32,
MSG_UINT64,
};
/*
* Message struct
*/
typedef struct {
pid_t sender;
uint32_t type;
union {
struct msg_uint8 m_uint8;
struct msg_uint16 m_uint16;
struct msg_uint32 m_uint32;
struct msg_uint64 m_uint64;
// Makes sure that ipc_msg_t is at least 64 bytes
uint8_t size[56];
};
} ipc_msg_t __align(16);
// Compile time check that ipc_msg_t is 64 bytes
typedef int __ASSERT_ipc_msg_t[(sizeof(ipc_msg_t) == 64) ? 1 : -1];
/*
* IPC handlers
*/
int ipc_send(pid_t dst, ipc_msg_t* msg);
int ipc_recv(pid_t src, ipc_msg_t* msg);
#endif
+8
View File
@@ -30,6 +30,9 @@ typedef char* va_list;
/*
* Utility macros
*/
#define STATIC_ASSERT(_cond, _msg)\
typedef int static_assert_##_msg[(_cond) ? 1 : -1]
#define ARRAY_SIZE(_a) (sizeof((_a)) / sizeof((_a)[0]))
#define BIT(_n) (1UL << (_n))
#define BIT_MASK(_n) (BIT(_n) - 1)
@@ -84,6 +87,11 @@ typedef int32_t intptr_t;
#define true 1
#define false 0
/*
* System types
*/
typedef uint32_t pid_t;
/*
* Linker defined values
*/
+10 -3
View File
@@ -2,14 +2,21 @@
#define _SYSCALL_H
#include <kernel.h>
#include <ipc.h>
#include <isr.h>
#define SYSCALL_MAX 2
#define SYS_EXIT 0
#define SYS_TEST 1
#define SYSCALL_MAX 16
enum {
SYS_SEND,
SYS_RECV,
};
int syscall_init(void);
void syscall_register(size_t idx, void* handler);
void syscall_handler(struct isr_int_frame* iframe);
// Syscall handlers
int sys_send(pid_t dst, ipc_msg_t* msg);
int sys_recv(pid_t src, ipc_msg_t* msg);
#endif
+9 -8
View File
@@ -9,6 +9,7 @@ enum {
TASK_STATE_DEAD,
TASK_STATE_IDLE,
TASK_STATE_READY,
TASK_STATE_RECV,
};
/*
@@ -30,7 +31,7 @@ enum {
* task.s which uses hardcoded offsets.
*/
struct task {
size_t id;
pid_t id;
size_t kstack_pointer;
size_t kstack_bottom;
@@ -58,13 +59,13 @@ extern struct task* task_first;
extern struct task* task_current;
int task_init(void);
void task_create(size_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, int argc, char** argv);
void task_kill(size_t id);
void task_set_user_heap(struct task* task, size_t heap_end);
struct task* task_get(size_t id);
uint8_t task_get_state(size_t id);
void task_set_state(size_t id, uint8_t state);
size_t task_create_id(void);
void task_create(pid_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, int argc, char** argv);
void task_kill(pid_t id);
void task_set_user_heap(pid_t id, size_t heap_end);
struct task* task_get(pid_t id);
uint8_t task_get_state(pid_t id);
void task_set_state(pid_t id, uint8_t state);
pid_t task_create_id(void);
// Defined in task.s
extern void task_switch(struct task* old, struct task* new);