diff --git a/runtime/include/arch/arch_context_variant_t.h b/runtime/include/arch/arch_context_variant_t.h new file mode 100644 index 0000000..ce40b76 --- /dev/null +++ b/runtime/include/arch/arch_context_variant_t.h @@ -0,0 +1,29 @@ +#pragma once + +#include "panic.h" + +/* The enum is compared directly in assembly, so maintain integral values! */ +typedef enum +{ + ARCH_CONTEXT_VARIANT_UNUSED = 0, /* Has not have saved a context */ + ARCH_CONTEXT_VARIANT_FAST = 1, /* Saved a fastpath context */ + ARCH_CONTEXT_VARIANT_SLOW = 2, /* Saved a slowpath context */ + ARCH_CONTEXT_VARIANT_RUNNING = 3 /* Context is executing and content is out of date */ +} arch_context_variant_t; + +static inline char * +arch_context_variant_print(arch_context_variant_t context) +{ + switch (context) { + case ARCH_CONTEXT_VARIANT_UNUSED: + return "Unused"; + case ARCH_CONTEXT_VARIANT_FAST: + return "Fast"; + case ARCH_CONTEXT_VARIANT_SLOW: + return "Slow"; + case ARCH_CONTEXT_VARIANT_RUNNING: + return "Running"; + default: + panic("Encountered unexpected arch_context variant: %u\n", context); + } +} diff --git a/runtime/include/arch/common.h b/runtime/include/arch/common.h index 46ac0d5..95ed123 100644 --- a/runtime/include/arch/common.h +++ b/runtime/include/arch/common.h @@ -1,11 +1,16 @@ #pragma once #include +#include #include #include #include #include +#include "arch/arch_context_t.h" +#include "arch/arch_context_variant_t.h" +#include "arch/reg_t.h" +#include "arch/ureg_t.h" #include "software_interrupt.h" /* @@ -17,48 +22,6 @@ * can be walked to resolve all symbols when the file is active */ -typedef uint64_t reg_t; - -/* Register context saved and restored on user-level, direct context switches. */ -typedef enum -{ - UREG_SP = 0, - UREG_IP = 1, - UREG_COUNT -} ureg_t; - -/* The enum is compared directly in assembly, so maintain integral values! */ -typedef enum -{ - ARCH_CONTEXT_VARIANT_UNUSED = 0, /* Has not have saved a context */ - ARCH_CONTEXT_VARIANT_FAST = 1, /* Saved a fastpath context */ - ARCH_CONTEXT_VARIANT_SLOW = 2, /* Saved a slowpath context */ - ARCH_CONTEXT_VARIANT_RUNNING = 3 /* Context is executing and content is out of date */ -} arch_context_variant_t; - -static inline char * -arch_context_variant_print(arch_context_variant_t context) -{ - switch (context) { - case ARCH_CONTEXT_VARIANT_UNUSED: - return "Unused"; - case ARCH_CONTEXT_VARIANT_FAST: - return "Fast"; - case ARCH_CONTEXT_VARIANT_SLOW: - return "Slow"; - case ARCH_CONTEXT_VARIANT_RUNNING: - return "Running"; - default: - panic("Encountered unexpected arch_context variant: %u\n", context); - } -} - - -struct arch_context { - arch_context_variant_t variant; - reg_t regs[UREG_COUNT]; - mcontext_t mctx; -}; /* * This is the slowpath switch to a preempted sandbox! diff --git a/runtime/include/arch/reg_t.h b/runtime/include/arch/reg_t.h new file mode 100644 index 0000000..2830e67 --- /dev/null +++ b/runtime/include/arch/reg_t.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +typedef uint64_t reg_t; diff --git a/runtime/include/arch/ureg_t.h b/runtime/include/arch/ureg_t.h new file mode 100644 index 0000000..f3ed683 --- /dev/null +++ b/runtime/include/arch/ureg_t.h @@ -0,0 +1,9 @@ +#pragma once + +/* Register context saved and restored on user-level, direct context switches. */ +typedef enum +{ + UREG_SP = 0, + UREG_IP = 1, + UREG_COUNT +} ureg_t;