aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/apos/caps.h15
-rw-r--r--include/apos/sizes.h30
-rw-r--r--include/apos/tcb.h29
-rw-r--r--include/arch/proc.h8
4 files changed, 58 insertions, 24 deletions
diff --git a/include/apos/caps.h b/include/apos/caps.h
index e8ef76b..be64663 100644
--- a/include/apos/caps.h
+++ b/include/apos/caps.h
@@ -6,6 +6,9 @@
* Capabilities of threads.
* \todo The list of capabilities should maybe be placed in some other file so
* as to easier extract it into userspace programs.
+ *
+ * @todo is it realistic to assume we will never need more than 32 capabilities?
+ * If so, we can remove the offset nonsense.
*/
#include <apos/bits.h>
@@ -22,6 +25,9 @@ enum {
/** Thread is allowed to force interrupt to callback in other thread. */
CAP_CALL = (1 << 2),
+
+ /** Thread is allowed to shut down system. */
+ CAP_POWER = (1 << 3),
};
/**
@@ -67,4 +73,13 @@ enum {
*/
#define get_caps(x, o) (x)
+/**
+ * Check if something has capability.
+ *
+ * @param x Capabilities to check in.
+ * @param c Capability to check for.
+ * @return \ref true if \p x has \p c, \ref false otherwise.
+ */
+#define has_cap(x, c) (x & c)
+
#endif /* APOS_CAPS_H */
diff --git a/include/apos/sizes.h b/include/apos/sizes.h
index 2eafa2e..40c3590 100644
--- a/include/apos/sizes.h
+++ b/include/apos/sizes.h
@@ -122,46 +122,40 @@
#define SZ_32G 0x000800000000UL
/** 64GiB. */
-#define SZ_64G 0x000400000000UL
+#define SZ_64G 0x001000000000UL
/** 128GiB. */
-#define SZ_128G 0x000800000000UL
+#define SZ_128G 0x002000000000UL
/** 256GiB. */
-#define SZ_256G 0x001000000000UL
+#define SZ_256G 0x004000000000UL
/** 512GiB. */
-#define SZ_512G 0x002000000000UL
+#define SZ_512G 0x008000000000UL
/** 1TiB. */
-#define SZ_1T 0x004000000000UL
+#define SZ_1T 0x010000000000UL
/** 2TiB. */
-#define SZ_2T 0x008000000000UL
+#define SZ_2T 0x020000000000UL
/** 4TiB. */
-#define SZ_4T 0x010000000000UL
+#define SZ_4T 0x040000000000UL
/** 8TiB. */
-#define SZ_8T 0x020000000000UL
+#define SZ_8T 0x080000000000UL
/** 16TiB. */
-#define SZ_16T 0x040000000000UL
+#define SZ_16T 0x100000000000UL
/** 32TiB. */
-#define SZ_32T 0x080000000000UL
+#define SZ_32T 0x200000000000UL
/** 64TiB. */
-#define SZ_64T 0x100000000000UL
+#define SZ_64T 0x400000000000UL
/** 128TiB. */
-#define SZ_128T 0x200000000000UL
-
-/** 256TiB. */
-#define SZ_256T 0x400000000000UL
-
-/** 512TiB. */
-#define SZ_512T 0x800000000000UL
+#define SZ_128T 0x8000000000000UL
#else
diff --git a/include/apos/tcb.h b/include/apos/tcb.h
index 0368957..9ed916f 100644
--- a/include/apos/tcb.h
+++ b/include/apos/tcb.h
@@ -28,7 +28,7 @@
* @param t Thread to check.
* @return \c true if thread is in RPC, \c false otherwise.
*/
-#define is_rpc(t) (t->rid == t->pid)
+#define is_rpc(t) (t->rid != t->pid)
/**
* Get the process thread of current thread.
@@ -63,14 +63,14 @@ struct tcb_ctx {
/** Enum for notification states. */
enum tcb_notify {
+ /** Thread is free to be notified. */
+ NOTIFY_WAITING = 0,
+
/** Thread has notifcations queued. */
NOTIFY_QUEUED,
/** Thread is running notification handler. */
NOTIFY_RUNNING,
-
- /** Thread is free to be notified. */
- NOTIFY_WAITING
};
/** Thread control block. Main way to handle threads. */
@@ -133,6 +133,9 @@ struct tcb {
/** Address of this thread's stack top. */
vm_t thread_stack_top;
+ /** Current address of usable rpc stack. */
+ vm_t rpc_stack;
+
/** \todo Check if each thread should be allowed more than just one
* region of thread local storage. */
/** Possible thread local storage. */
@@ -171,7 +174,7 @@ void destroy_tcbs();
* and the \ref tcb structure itself with a unique thread ID. If in a new
* process context, a new process address space is created as well.
*
- * Userspace stack is allocated with \ref alloc_stacks().
+ * Userspace stack is allocated with \ref alloc_stack().
*
* \todo Thread local storage?
*
@@ -338,7 +341,7 @@ stat_t clone_rpc_maps(struct tcb *r);
* @param t Thread whose stacks to allocate.
* @return \ref OK on success, \ref ERR_OOMEM if out of memory.
*/
-stat_t alloc_stacks(struct tcb *t);
+stat_t alloc_stack(struct tcb *t);
/**
* Set address to jump to when returning to userspace.
@@ -356,4 +359,18 @@ void set_return(struct tcb *t, vm_t r);
*/
bool running(struct tcb *t);
+/**
+ * Save thread context for rpc call.
+ *
+ * @param t Thread whose context to save.
+ */
+void save_context(struct tcb *t);
+
+/**
+ * Load thread context from rpc call.
+ *
+ * @param t Thread whose context to restore.
+ */
+void load_context(struct tcb *t);
+
#endif /* APOS_TCB_H */
diff --git a/include/arch/proc.h b/include/arch/proc.h
index e2b99ea..6a2c036 100644
--- a/include/arch/proc.h
+++ b/include/arch/proc.h
@@ -49,6 +49,14 @@ struct sys_ret get_args(struct tcb *t);
void set_thread(struct tcb *t);
/**
+ * Get current userspace stack.
+ *
+ * @param t Thread whose stack to query.
+ * @return Current stack address.
+ */
+vm_t get_stack(struct tcb *t);
+
+/**
* Copy registers from tcb save area to address \p p.
* Intended to be used for copying thread state to rpc stack.
*