mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +00:00 
			
		
		
		
	UserspaceEmulator: Load the target executable ELF semi-properly :^)
This patch adds a basic ELF program loader to the UserspaceEmulator and creates MMU regions for each PT_LOAD header. (Note that we don't yet respect the R/W/X flags etc.) We also turn the SoftCPU into an X86::InstructionStream and give it an EIP register so we can actually execute code by fetching memory through our MMU abstraction.
This commit is contained in:
		
							parent
							
								
									0eab5659f8
								
							
						
					
					
						commit
						ae1d14bc7a
					
				
					 5 changed files with 68 additions and 22 deletions
				
			
		|  | @ -30,7 +30,6 @@ | |||
| #include <AK/MappedFile.h> | ||||
| #include <LibCore/ArgsParser.h> | ||||
| #include <LibELF/Loader.h> | ||||
| #include <LibX86/Instruction.h> | ||||
| 
 | ||||
| int main(int argc, char** argv) | ||||
| { | ||||
|  | @ -48,15 +47,9 @@ int main(int argc, char** argv) | |||
| 
 | ||||
|     auto elf = ELF::Loader::create((const u8*)mapped_file.data(), mapped_file.size()); | ||||
| 
 | ||||
|     auto _start_symbol = elf->find_demangled_function("_start"); | ||||
|     if (!_start_symbol.has_value()) { | ||||
|         warn() << "Could not find '_start' symbol in executable"; | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     auto main_code = _start_symbol.value().raw_data(); | ||||
|     X86::SimpleInstructionStream stream((const u8*)main_code.characters_without_null_termination(), main_code.length()); | ||||
| 
 | ||||
|     UserspaceEmulator::Emulator emulator; | ||||
|     return emulator.exec(stream, _start_symbol.value().value()); | ||||
|     if (!emulator.load_elf(*elf)) | ||||
|         return 1; | ||||
| 
 | ||||
|     return emulator.exec(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling