aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-06-05 07:56:16 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:17:13 +0200
commitd6815a5903716c058c4f8bee89bfa745ee752c9d (patch)
tree1f3027cf3b98571b7a5fe24b80cf0382209bc69a
parente35e9f4c88be4ca7bf08970109c1ff8d90018b02 (diff)
proc: interrupt: define context and trap frame
Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
-rw-r--r--src/arch/x86_64/arch_regs.rs43
-rw-r--r--src/arch/x86_64/context.rs28
-rw-r--r--src/arch/x86_64/mod.rs2
3 files changed, 44 insertions, 29 deletions
diff --git a/src/arch/x86_64/arch_regs.rs b/src/arch/x86_64/arch_regs.rs
new file mode 100644
index 0000000..a49926e
--- /dev/null
+++ b/src/arch/x86_64/arch_regs.rs
@@ -0,0 +1,43 @@
+use core::arch::asm;
+
+/// arch specific registers
+#[repr(C)]
+#[repr(packed)]
+#[derive(Debug)]
+pub struct Context64 {
+ pub rbx: u64,
+ pub r12: u64,
+ pub r13: u64,
+ pub r14: u64,
+ pub r15: u64,
+ pub rbp: u64,
+ pub rsp: u64,
+ pub fpu: [u8; 108],
+}
+
+/// arch specific registers
+#[repr(C)]
+#[repr(packed)]
+#[derive(Debug)]
+pub struct TrapFrame {
+ pub r11: u64,
+ pub r10: u64,
+ pub r9: u64,
+ pub r8: u64,
+ pub rsi: u64,
+ pub rdi: u64,
+ pub rdx: u64,
+ pub rcx: u64,
+ pub rax: u64,
+ pub err_code: u64,
+}
+
+// this will get the current (kernel) stack pointer
+#[inline]
+pub fn get_sp() -> u64 {
+ let sp: u64;
+ unsafe {
+ asm!("mov {}, rsp", out(reg) sp);
+ }
+ return sp;
+}
diff --git a/src/arch/x86_64/context.rs b/src/arch/x86_64/context.rs
deleted file mode 100644
index 6c46271..0000000
--- a/src/arch/x86_64/context.rs
+++ /dev/null
@@ -1,28 +0,0 @@
-/// high level representation of the callee saved registers for thread context. The caller
-/// saved registers will is pushed into the stack already upon the interrupt entry
-/// fpstate is NOT saved here
-#[repr(C)]
-pub struct Context {
- rbx: u64,
- r12: u64,
- r13: u64,
- r14: u64,
- r15: u64,
- rbp: u64,
- rsp: u64,
-}
-
-/// prepare the thread (coroutine) for the first execution
-pub unsafe fn settle() {
- todo!()
- // it will be something like this...
- // void **sp = (void**)tos;
- // *(--sp) = object; // 7th parameter for kickoff
- // *(--sp) = (void*)0; // return address
- // *(--sp) = kickoff; // address
- // regs->rsp = sp;
-}
-
-pub unsafe fn switch(_ctx_curr: usize, _ctx_next: usize) {
- todo!()
-}
diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs
index 888cafd..ee51338 100644
--- a/src/arch/x86_64/mod.rs
+++ b/src/arch/x86_64/mod.rs
@@ -1,4 +1,4 @@
-pub mod context;
+pub mod arch_regs;
pub mod interrupt;
pub mod io_port;
pub mod mem;