|
|
|
@ -130,17 +130,21 @@ struct ContextData {
|
|
|
|
|
ra: usize,
|
|
|
|
|
/// Page table token
|
|
|
|
|
satp: usize,
|
|
|
|
|
/// Callee-saved registers
|
|
|
|
|
/// s[0] = TLS
|
|
|
|
|
/// s[1] = reserved
|
|
|
|
|
/// s[2..11] = Callee-saved registers
|
|
|
|
|
s: [usize; 12],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ContextData {
|
|
|
|
|
fn new(satp: usize) -> Self {
|
|
|
|
|
ContextData {
|
|
|
|
|
fn new(satp: usize, tls: usize) -> Self {
|
|
|
|
|
let mut context = ContextData {
|
|
|
|
|
ra: trap_return as usize,
|
|
|
|
|
satp,
|
|
|
|
|
satp: satp,
|
|
|
|
|
..ContextData::default()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
context.s[0] = tls;
|
|
|
|
|
context
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -191,7 +195,7 @@ impl Context {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
InitStack {
|
|
|
|
|
context: ContextData::new(satp),
|
|
|
|
|
context: ContextData::new(satp, 0),
|
|
|
|
|
tf: TrapFrame::new_kernel_thread(entry, arg, kstack_top),
|
|
|
|
|
}
|
|
|
|
|
.push_at(kstack_top)
|
|
|
|
@ -215,7 +219,7 @@ impl Context {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
InitStack {
|
|
|
|
|
context: ContextData::new(satp),
|
|
|
|
|
context: ContextData::new(satp, 0),
|
|
|
|
|
tf: TrapFrame::new_user_thread(entry_addr, ustack_top),
|
|
|
|
|
}
|
|
|
|
|
.push_at(kstack_top)
|
|
|
|
@ -228,7 +232,7 @@ impl Context {
|
|
|
|
|
/// All the other registers are same as the original.
|
|
|
|
|
pub unsafe fn new_fork(tf: &TrapFrame, kstack_top: usize, satp: usize) -> Self {
|
|
|
|
|
InitStack {
|
|
|
|
|
context: ContextData::new(satp),
|
|
|
|
|
context: ContextData::new(satp, 0),
|
|
|
|
|
tf: {
|
|
|
|
|
let mut tf = tf.clone();
|
|
|
|
|
// fork function's ret value, the new process is 0
|
|
|
|
@ -254,11 +258,10 @@ impl Context {
|
|
|
|
|
tls: usize,
|
|
|
|
|
) -> Self {
|
|
|
|
|
InitStack {
|
|
|
|
|
context: ContextData::new(satp),
|
|
|
|
|
context: ContextData::new(satp, tls),
|
|
|
|
|
tf: {
|
|
|
|
|
let mut tf = tf.clone();
|
|
|
|
|
tf.sp = ustack_top; // sp
|
|
|
|
|
tf.v1 = tls;
|
|
|
|
|
tf.v0 = 0; // return value
|
|
|
|
|
tf
|
|
|
|
|
},
|
|
|
|
|