rust-armv6k

ARMv6K emulator for Rust. Uses Dynarmic.

Coprocessors or page tables aren't supported.

Usage Example

```rust use armv6k;

static mut MEMORY: [u8; 2048] = [0; 2048]; static mut TICKS_LEFT: u64 = 0;

unsafe extern fn read_8(vaddr: usize) -> u8 { if vaddr >= MEMORY.len() { panic!("Invalid address: {:08X}", vaddr); } MEMORY[vaddr] }

unsafe extern fn read16(vaddr: usize) -> u16 { (read8(vaddr) as u16) | (read_8(vaddr + 1) as u16) << 8 }

unsafe extern fn read32(vaddr: usize) -> u32 { (read16(vaddr) as u32) | (read_16(vaddr + 2) as u32) << 16 }

unsafe extern fn read64(vaddr: usize) -> u64 { (read32(vaddr) as u64) | (read_16(vaddr + 4) as u64) << 32 }

unsafe extern fn write_8(vaddr: usize, value: u8) { if vaddr >= MEMORY.len() { panic!("Invalid address: {:08X}", vaddr); } MEMORY[vaddr] = value; }

unsafe extern fn write16(vaddr: usize, value: u16) { write8(vaddr, value as u8); write_8(vaddr + 1, (value >> 8) as u8); }

unsafe extern fn write32(vaddr: usize, value: u32) { write16(vaddr, value as u16); write_16(vaddr + 2, (value >> 16) as u16); }

unsafe extern fn write64(vaddr: usize, value: u64) { write32(vaddr, value as u32); write_32(vaddr + 4, (value >> 32) as u32); }

unsafe extern fn addticks(ticks: u64) { if ticks > TICKSLEFT { TICKSLEFT = 0; return; } TICKSLEFT -= ticks; }

unsafe extern fn callsvc(swi: u32) {}

unsafe extern fn exceptionraised(pc: u32, _exception: i32) {}

unsafe extern fn getticksremaining() -> u64 { return TICKS_LEFT }

unsafe extern fn interpreterfallback(pc: u32, numinstructions: usize) {}

fn main() { unsafe { armv6k::Initialize(true, true); write16(0, 0x0088); write16(2, 0xE7FE); armv6k::SetRegister(0, 1); armv6k::SetRegister(1, 2); armv6k::SetRegister(15, 0); armv6k::SetCpsr(0x00000030); armv6k::SetAddTicks(addticks); armv6k::SetCallSVC(callsvc); armv6k::SetExceptionRaised(exceptionraised); armv6k::SetMemoryRead8(read8); armv6k::SetMemoryRead16(read16); armv6k::SetMemoryRead32(read32); armv6k::SetMemoryRead64(read64); armv6k::SetMemoryWrite8(write8); armv6k::SetMemoryWrite16(write16); armv6k::SetMemoryWrite32(write32); armv6k::SetMemoryWrite64(write64); armv6k::SetGetTicksRemaining(getticksremaining); armv6k::SetInterpreterFallback(interpreterfallback); armv6k::Run(); println!("R0: {}", armv6k::GetRegister(0)); } } ```