Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZR233 committed Jan 21, 2025
1 parent 433b2d9 commit 3846708
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/sparreal-macros/src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
use proc_macro::TokenStream;
use syn::parse;

pub fn store_cpu_context(input: TokenStream) -> Result<TokenStream, parse::Error> {
// let reg = syn::parse::<syn::LitStr>(input)?;

// let after = format!("[{},#-0x20]!", reg.value());

let after = format!("[{},#-0x20]!", "sp");
let asm_str = reg_op_pair("stp", "q", 0..32, &after, true);

Ok(asm_str.parse().unwrap())
fn ctx_store_x_q() -> String {
let mut out = reg_op_pair("stp", "x", 1..32, "[sp,#-0x10]!", true);
out = format!(
"{out}\r\n mrs x9, SPSR_EL1
stp x9, x0, [sp,#-0x10]!"
);
out
}

fn reg_op_pair(
Expand Down
15 changes: 15 additions & 0 deletions crates/sparreal-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,18 @@ pub fn module_driver(input: TokenStream) -> TokenStream {
}
.into()
}

#[proc_macro]
pub fn define_tcb_switch(input: TokenStream) -> TokenStream {
let s = "mov sp, x0";

quote! {
#[naked]
pub unsafe extern "C" fn __tcb_switch(prev: *mut u8, next: *mut u8) {
core::arch::naked_asm!(
#s
)
}
}
.into()
}
5 changes: 5 additions & 0 deletions crates/sparreal-rt/src/arch/aarch64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::{
};

use sparreal_kernel::task::TaskControlBlock;
use sparreal_macros::define_tcb_switch;

#[repr(C, align(0x10))]
#[derive(Clone)]
Expand Down Expand Up @@ -230,3 +231,7 @@ pub fn tcb_switch(prev_ptr: *mut u8, next_ptr: *mut u8) {

restore_pc_is_lr();
}



define_tcb_switch!();

0 comments on commit 3846708

Please sign in to comment.