Implement exec
Implement brk
This commit is contained in:
		
							parent
							
								
									f2ca411cd6
								
							
						
					
					
						commit
						44e8b99b46
					
				
					 11 changed files with 122 additions and 59 deletions
				
			
		|  | @ -116,14 +116,14 @@ pub mod syscall; | |||
| #[cfg(test)] | ||||
| pub mod tests; | ||||
| 
 | ||||
| pub extern fn context_test() { | ||||
|     print!("Test\n"); | ||||
|     unsafe { context::switch(); } | ||||
| pub extern fn userspace_init() { | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(0)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(1)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(2)); | ||||
| 
 | ||||
|     print!("Test halt\n"); | ||||
|     loop { | ||||
|         unsafe { interrupt::enable_and_halt(); } | ||||
|     } | ||||
|     syscall::exec(b"initfs:bin/init", &[]).expect("failed to execute initfs:init"); | ||||
| 
 | ||||
|     panic!("initfs:init returned") | ||||
| } | ||||
| 
 | ||||
| #[no_mangle] | ||||
|  | @ -133,36 +133,10 @@ pub extern fn kmain() { | |||
|     let pid = syscall::getpid(); | ||||
|     println!("BSP: {:?}", pid); | ||||
| 
 | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(0)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(1)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(2)); | ||||
|     context::contexts_mut().spawn(userspace_init).expect("failed to spawn userspace_init"); | ||||
| 
 | ||||
|     let init_file = syscall::open(b"initfs:init", 0).expect("failed to open initfs:init"); | ||||
|     let mut init_data = collections::Vec::new(); | ||||
|     loop { | ||||
|         let mut buf = [0; 65536]; | ||||
|         let count = syscall::read(init_file, &mut buf).expect("failed to read initfs:init"); | ||||
|         if count > 0 { | ||||
|             init_data.extend_from_slice(&buf[..count]); | ||||
|         } else { | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     let elf = elf::Elf::from(&init_data).expect("could not load elf"); | ||||
|     elf.run(); | ||||
| 
 | ||||
|     /* | ||||
|     if let Ok(_context_lock) = context::contexts_mut().spawn(context_test) { | ||||
|         print!("Spawned context\n"); | ||||
|     } | ||||
| 
 | ||||
|     print!("Main\n"); | ||||
|     unsafe { context::switch(); } | ||||
| 
 | ||||
|     print!("Main halt\n"); | ||||
|     */ | ||||
| 
 | ||||
|     loop { | ||||
|         unsafe { interrupt::enable_and_halt(); } | ||||
|     } | ||||
|  | @ -175,10 +149,6 @@ pub extern fn kmain_ap(id: usize) { | |||
|     let pid = syscall::getpid(); | ||||
|     println!("AP {}: {:?}", id, pid); | ||||
| 
 | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(0)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(1)); | ||||
|     assert_eq!(syscall::open(b"debug:", 0), Ok(2)); | ||||
| 
 | ||||
|     loop { | ||||
|         unsafe { interrupt::enable_and_halt() } | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Soller
						Jeremy Soller