diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-09 15:33:12 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-09 15:33:12 -0700 |
commit | cd85da118c61e91a4e70407ee52725d799d3994b (patch) | |
tree | 91886f17c49c2536646f118774931913082fa7cd /src/lib.rs | |
parent | 1453ffed396ad5f86fc7c3647378301be09206dd (diff) |
Remove old elfloader test
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 80 |
1 files changed, 0 insertions, 80 deletions
@@ -27,86 +27,6 @@ pub mod trap; pub use elfloader_lib as elfloader; -#[test] -fn test_elfloader() { - use std::io::prelude::*; - use std::fs::File; - use std::rc::Rc; - use std::cell::RefCell; - - use memory::MemoryInterface; - - struct SyscallHandler<'a> { - memory: memory::SharedMemory<'a>, - } - - impl<'a> syscall::SyscallHandler for SyscallHandler<'a> { - fn syscall(&mut self, registers: &mut register_file::RegisterFile) -> Option<trap::Trap> { - println!("Syscall number {}", registers.read_word(isa::Register::X10)); - let mut base = registers.read_word(isa::Register::X11); - let mut string = vec![]; - - loop { - let c = self.memory.borrow_mut().read_byte(base); - - if let Ok(0x00) = c { - break; - } - else if let Ok(c) = c { - string.push(c); - } - - base += 1; - } - - let result = std::str::from_utf8(&string); - if let Ok(string) = result { - println!("{}", string); - } - else { - println!("Error printing string: {:?}", result); - } - None - } - } - - let mut f = File::open("../riscv/kernel").unwrap(); - let mut buffer = Vec::new(); - - f.read_to_end(&mut buffer).unwrap(); - - let elf = elfloader::ElfBinary::new("test", &buffer).unwrap(); - let start = elf.file_header().entry as isa::Address; - - let mmu = memory::IdentityMmu::new(); - let mmu2 = memory::ReverseMmu::new(0x8000); - let mut memory = memory::Memory::new(0x10000); - - for p in elf.section_headers() { - let name = elf.section_name(p); - if name == ".text" || name == ".sdata" || name == ".rodata" { - println!("Loading {} section", name); - memory.write_segment(&mmu, elf.section_data(p), p.addr as usize); - memory.write_segment(&mmu2, elf.section_data(p), p.addr as usize); - } - } - - let memory_ref = Rc::new(RefCell::new(memory)); - let cache = memory::DirectMappedCache::new(4, 4, memory_ref.clone()); - let cache_ref = Rc::new(RefCell::new(cache)); - let core = simulator::Core::new( - start, 0x1000, - cache_ref.clone(), Box::new(mmu)); - let core2 = simulator::Core::new( - start, 0x3000, - cache_ref.clone(), Box::new(mmu2)); - let cores = vec![core, core2]; - - let system = SyscallHandler { memory: memory_ref.clone(), }; - let mut simulator = simulator::Simulator::new(cores, memory_ref.clone(), system); - simulator.run(); -} - #[cfg(test)] mod tests { #[test] |