Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZR233 committed Jan 20, 2025
1 parent 3126b88 commit b113eca
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 90 deletions.
1 change: 1 addition & 0 deletions crates/sparreal-kernel/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod schedule;
mod tcb;

pub use schedule::suspend;
pub use tcb::current;

#[derive(Debug, Clone)]
pub enum TaskError {
Expand Down
2 changes: 2 additions & 0 deletions crates/sparreal-kernel/src/task/schedule.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::collections::vec_deque::VecDeque;
use log::debug;
use spin::Mutex;

use crate::platform_if::PlatformImpl;
Expand All @@ -19,6 +20,7 @@ pub fn schedule() {

cu.switch_to(&idle);
} else {
debug!("No task idle");
loop {
PlatformImpl::wait_for_interrupt();
}
Expand Down
6 changes: 6 additions & 0 deletions crates/sparreal-kernel/src/task/tcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ impl Pid {
}
}

impl Default for Pid {
fn default() -> Self {
Self::new()
}
}

impl Debug for Pid {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
writeln!(f, "{:?}", self.0)
Expand Down
3 changes: 3 additions & 0 deletions crates/sparreal-kernel/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
},
globals::{cpu_global, cpu_global_meybeuninit, cpu_global_mut, global_val},
irq::{IrqHandleResult, IrqParam},
task,
};

use driver_interface::{interrupt_controller::IrqId, timer::*};
Expand Down Expand Up @@ -88,3 +89,5 @@ pub fn spin_delay(duration: Duration) {
}
}
}

pub fn sleep(duration: Duration) {}
72 changes: 72 additions & 0 deletions crates/sparreal-macros/src/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#![allow(unused)]

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 reg_op_pair(
op: &str,
reg: &str,
range: std::ops::Range<usize>,
after: &str,
reverse: bool,
) -> String {
let mut ls = range
.step_by(2)
.map(|p0| {
format!(
"{op} {:>3},{:>3}, {after}",
format!("{reg}{p0}"),
format!("{reg}{}", p0 + 1)
)
})
.collect::<Vec<_>>();

if reverse {
ls.reverse();
}

ls.join("\n")
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_reg_op_pair() {
let want = "
ldp X1, X2, [sp], #0x10
ldp X3, X4, [sp], #0x10
ldp X5, X6, [sp], #0x10
ldp X7, X8, [sp], #0x10
ldp X9,X10, [sp], #0x10
ldp X11,X12, [sp], #0x10
ldp X13,X14, [sp], #0x10
ldp X15,X16, [sp], #0x10
ldp X17,X18, [sp], #0x10
ldp X19,X20, [sp], #0x10
ldp X21,X22, [sp], #0x10
ldp X23,X24, [sp], #0x10
ldp X25,X26, [sp], #0x10
ldp X27,X28, [sp], #0x10
ldp X29,X30, [sp], #0x10
";

let a_str = reg_op_pair("ldp", "X", 1..31, "[sp], #0x10", false);

println!("{a_str}");

assert_eq!(a_str.trim(), want.trim());
}
}
1 change: 1 addition & 0 deletions crates/sparreal-macros/src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod aarch64;
1 change: 1 addition & 0 deletions crates/sparreal-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate proc_macro2;
extern crate syn;

mod api_trait;
mod arch;

use proc_macro::TokenStream;
use proc_macro2::Span;
Expand Down
91 changes: 1 addition & 90 deletions crates/sparreal-rt/src/arch/aarch64/trap.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use aarch64_cpu::registers::*;
use core::{
arch::{asm, global_asm, naked_asm},
fmt::{self, Debug},
};

use aarch64_cpu::registers::*;
use log::*;

#[unsafe(no_mangle)]
Expand Down Expand Up @@ -425,7 +424,6 @@ macro_rules! restore_task_lr {
ret"
};
}

#[cfg(hard_float)]
#[naked]
unsafe extern "C" fn context_switch(_current_task: &mut Context, _next_task: &Context) {
Expand Down Expand Up @@ -459,90 +457,3 @@ unsafe extern "C" fn context_switch(_current_task: &mut Context, _next_task: &Co
)
}
}

// #[naked]
// unsafe extern "C" fn context_switch(_current_task: &mut Context, _next_task: &Context) {
// unsafe {
// naked_asm!(
// //x0
// "
// add x0, x0, {size}
// stp X29,X30, [x0,#-0x10]!
// stp X27,X28, [x0,#-0x10]!
// stp X25,X26, [x0,#-0x10]!
// stp X23,X24, [x0,#-0x10]!
// stp X21,X22, [x0,#-0x10]!
// stp X19,X20, [x0,#-0x10]!
// sub x0, x0, #0x90
// mrs x9, SPSR_EL1
// stp x9, x10, [x0,#-0x10]!
// ",
// #[cfg(hard_float)]
// "
// stp q30, q31, [x0,#-0x20]!
// stp q28, q29, [x0,#-0x20]!
// stp q26, q27, [x0,#-0x20]!
// stp q24, q25, [x0,#-0x20]!
// stp q22, q23, [x0,#-0x20]!
// stp q20, q21, [x0,#-0x20]!
// stp q18, q19, [x0,#-0x20]!
// stp q16, q17, [x0,#-0x20]!
// stp q14, q15, [x0,#-0x20]!
// stp q12, q13, [x0,#-0x20]!
// stp q10, q11, [x0,#-0x20]!
// stp q8, q9, [x0,#-0x20]!
// stp q6, q7, [x0,#-0x20]!
// stp q4, q5, [x0,#-0x20]!
// stp q2, q3, [x0,#-0x20]!
// stp q0, q1, [x0,#-0x20]!
// mrs x9, fpcr
// mrs x10, fpsr
// stp x9, x10, [x0,#-0x10]!
// ",
// "
// mov x9, sp
// stp x9, lr, [x0,#-0x10]!
// ",
// //x1
// "
// add x1, x1, {size}
// ldp X29,X30, [x1,#-0x10]!
// ldp X27,X28, [x1,#-0x10]!
// ldp X25,X26, [x1,#-0x10]!
// ldp X23,X24, [x1,#-0x10]!
// ldp X21,X22, [x1,#-0x10]!
// ldp X19,X20, [x1,#-0x10]!
// sub x1, x1, #0x90
// ldp x9, x10, [x1,#-0x10]!
// msr SPSR_EL1, x9
// ",
// #[cfg(hard_float)]
// "
// ldp q30, q31, [x1,#-0x20]!
// ldp q28, q29, [x1,#-0x20]!
// ldp q26, q27, [x1,#-0x20]!
// ldp q24, q25, [x1,#-0x20]!
// ldp q22, q23, [x1,#-0x20]!
// ldp q20, q21, [x1,#-0x20]!
// ldp q18, q19, [x1,#-0x20]!
// ldp q16, q17, [x1,#-0x20]!
// ldp q14, q15, [x1,#-0x20]!
// ldp q12, q13, [x1,#-0x20]!
// ldp q10, q11, [x1,#-0x20]!
// ldp q8, q9, [x1,#-0x20]!
// ldp q6, q7, [x1,#-0x20]!
// ldp q4, q5, [x1,#-0x20]!
// ldp q2, q3, [x1,#-0x20]!
// ldp q0, q1, [x1,#-0x20]!
// ldp x9, x10, [x1,#-0x10]!
// msr fpcr, x9
// msr fpsr, x10
// ",
// "
// ldp x9, lr, [x1,#-0x10]!
// mov sp, x9
// ret",
// size = const size_of::<Context>()
// )
// }
// }

0 comments on commit b113eca

Please sign in to comment.