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