aboutsummaryrefslogtreecommitdiff
path: root/include/apos
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-18 21:10:57 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-21 12:12:38 +0300
commit7967a9ab13214543041e4408086668b4db8d3e62 (patch)
tree4dab7b89bd9d5b5b8280877f9d8eb23a1edf1230 /include/apos
parent1ceed7525272b82c1028ebd353e65c3a63bd2714 (diff)
downloadkmi-7967a9ab13214543041e4408086668b4db8d3e62.tar.gz
kmi-7967a9ab13214543041e4408086668b4db8d3e62.zip
start working on timer subsys
Diffstat (limited to 'include/apos')
-rw-r--r--include/apos/sp_tree.h10
-rw-r--r--include/apos/syscalls.h6
-rw-r--r--include/apos/timer.h47
-rw-r--r--include/apos/uapi.h91
4 files changed, 132 insertions, 22 deletions
diff --git a/include/apos/sp_tree.h b/include/apos/sp_tree.h
index 1c1525f..fe02e91 100644
--- a/include/apos/sp_tree.h
+++ b/include/apos/sp_tree.h
@@ -1,13 +1,13 @@
#ifndef SP_TREE_H
#define SP_TREE_H
-#define sp_root(r) (r.sp_r)
-#define sp_left(n) (n->left)
-#define sp_right(n) (n->right)
+#define sp_root(r) ((r)->sp_r)
+#define sp_left(n) ((n)->left)
+#define sp_right(n) ((n)->right)
#define sp_rparen(n) (sp_right(n)->parent)
#define sp_lparen(n) (sp_left(n)->parent)
-#define sp_paren(n) (n->parent)
-#define sp_gparen(n) (n->parent->parent)
+#define sp_paren(n) ((n)->parent)
+#define sp_gparen(n) ((n)->parent->parent)
#define sp_has_gparen(n) (sp_paren(n) && sp_gparen(n))
struct sp_node {
diff --git a/include/apos/syscalls.h b/include/apos/syscalls.h
index d2427cf..d9df89b 100644
--- a/include/apos/syscalls.h
+++ b/include/apos/syscalls.h
@@ -10,6 +10,10 @@ enum {
SYS_REQ_FIXMEM, /* request memory at fixed address */
SYS_FREE_MEM, /* free memory */
+ /* timers */
+ SYS_REQ_TIMER,
+ SYS_FREE_TIMER,
+
/* IPC */
/* I really should try to find my notes about the server/client
* structure of the OS, but these following syscalls are probably
@@ -28,7 +32,7 @@ enum {
/* kernel management */
SYS_CONF, /* config system parameters (stack size etc.) */
SYS_POWEROFF, /* shutdown/reboot etc. */
-}
+};
/* function declarations should be somewhere else, this file could be used in
* userspace applications as well */
diff --git a/include/apos/timer.h b/include/apos/timer.h
new file mode 100644
index 0000000..ea5bd03
--- /dev/null
+++ b/include/apos/timer.h
@@ -0,0 +1,47 @@
+#ifndef APOS_TIMER_H
+#define APOS_TIMER_H
+
+#include <apos/types.h>
+
+typedef size_t ticks_t;
+/* whichever time unit we're dealing with */
+typedef size_t tunit_t;
+
+struct timer {
+ id_t tid;
+ id_t cid;
+
+ ticks_t ticks;
+};
+
+void init_timer();
+
+/* set up timer interrupt ticks from now */
+id_t new_rel_timer(id_t tid, ticks_t ticks);
+/* set up timer interrupt at ticks (from startup I suppose) */
+id_t new_abs_timer(id_t tid, ticks_t ticks);
+
+struct timer *newest_timer();
+struct timer *find_timer(id_t cid);
+void remove_timer(struct timer *);
+
+ticks_t nsecs_to_ticks(tunit_t nsecs);
+
+static inline ticks_t usecs_to_ticks(tunit_t usecs)
+{
+ return nsecs_to_ticks(usecs * 1000);
+}
+
+static inline ticks_t msecs_to_ticks(tunit_t msecs)
+{
+ return usecs_to_ticks(msecs * 1000);
+}
+
+/* TODO: likely not a problem on 64bit systems, not sure how to handle situation on
+ * 32bit */
+static inline ticks_t secs_to_ticks(tunit_t secs)
+{
+ return msecs_to_ticks(secs * 1000);
+}
+
+#endif /* APOS_TIMER_H */
diff --git a/include/apos/uapi.h b/include/apos/uapi.h
index 74fd846..fb7dff7 100644
--- a/include/apos/uapi.h
+++ b/include/apos/uapi.h
@@ -1,29 +1,88 @@
#ifndef APOS_UAPI_H
#define APOS_UAPI_H
+#include <apos/syscalls.h>
#include <apos/vmem.h>
/* syscall function type, let's start with four arguments and see where that
* goes */
-typedef vm_t (*sys_t)(vm_t a0, vm_t a1, vm_t a2, vm_t a3);
+typedef vm_t (*sys_t)(vm_t, vm_t, vm_t, vm_t);
-vm_t sys_req_mem(vm_t size, vm_t flags, vm_t u0, vm_t u1);
-vm_t sys_req_pmem(vm_t paddr, vm_t size, vm_t flags, vm_t u0);
-vm_t sys_req_fixmem(vm_t start, vm_t size, vm_t flags, vm_t u0);
-vm_t sys_req_sharedmem(vm_t pid, vm_t start, vm_t size, vm_t flags);
-vm_t sys_free_mem(vm_t start, vm_t u0, vm_t u1, vm_t u2);
+#define SYSCALL_DECLARE(name)\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d);
-vm_t sys_ipc_server(vm_t callback, vm_t u0, vm_t u1, vm_t u2);
-vm_t sys_ipc_req(vm_t tgt_pid, vm_t d0, vm_t d1, vm_t d2);
-vm_t sys_ipc_resp(vm_t tgt_pid, vm_t ret, vm_t u0, vm_t u1);
+#define SYSCALL_DEFINE0(name)\
+ static vm_t __##name();\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \
+ UNUSED(a);\
+ UNUSED(b);\
+ UNUSED(c);\
+ UNUSED(d);\
+ return __##name();\
+ }\
+ static vm_t __##name
-vm_t sys_fork(vm_t pid, vm_t u1, vm_t u2, vm_t u3);
-vm_t sys_exec(vm_t pid, vm_t bin, vm_t argc, vm_t argv);
-vm_t sys_signal(vm_t pid, vm_t signal, vm_t u0, vm_t u1);
-vm_t sys_switch(vm_t pid, vm_t u0, vm_t u1, vm_t u2);
-vm_t sys_sync(vm_t buf, vm_t size, vm_t u1, vm_t u2);
+#define SYSCALL_DEFINE1(name)\
+ static vm_t __##name(vm_t);\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \
+ UNUSED(b);\
+ UNUSED(c);\
+ UNUSED(d);\
+ return __##name(a);\
+ }\
+ static vm_t __##name
-vm_t sys_conf(vm_t param, vm_t val, vm_t u0, vm_t u1);
-vm_t sys_poweroff(vm_t type, vm_t u0, vm_t u1, vm_t u2);
+#define SYSCALL_DEFINE2(name)\
+ static vm_t __##name(vm_t, vm_t);\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \
+ UNUSED(c);\
+ UNUSED(d);\
+ return __##name(a, b);\
+ }\
+ static vm_t __##name
+
+#define SYSCALL_DEFINE3(name)\
+ static vm_t __##name(vm_t, vm_t, vm_t);\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \
+ UNUSED(d);\
+ return __##name(a, b, c);\
+ }\
+ static vm_t __##name
+
+#define SYSCALL_DEFINE4(name)\
+ static vm_t __##name(vm_t, vm_t, vm_t, vm_t);\
+ vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \
+ return __##name(a, b, c, d);\
+ }\
+ static vm_t __##name
+
+/* memory */
+SYSCALL_DECLARE(req_mem);
+SYSCALL_DECLARE(req_pmem);
+SYSCALL_DECLARE(req_fixmem);
+SYSCALL_DECLARE(req_sharedmem);
+SYSCALL_DECLARE(free_mem);
+
+/* timers */
+SYSCALL_DECLARE(req_timer);
+SYSCALL_DECLARE(free_timer);
+
+/* ipc */
+SYSCALL_DECLARE(ipc_server);
+SYSCALL_DECLARE(ipc_req);
+SYSCALL_DECLARE(ipc_resp);
+
+/* proc */
+SYSCALL_DECLARE(fork);
+SYSCALL_DECLARE(exec);
+SYSCALL_DECLARE(signal);
+SYSCALL_DECLARE(switch);
+SYSCALL_DECLARE(sync);
+
+/* conf */
+SYSCALL_DECLARE(conf);
+SYSCALL_DECLARE(poweroff);
+
+vm_t syscall_dispatch(vm_t syscall, vm_t a, vm_t b, vm_t c, vm_t d);
#endif /* APOS_UAPI_H */