Skip to content

Commit

Permalink
evp: Implement execution remap peripheral (EVP)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanthom committed May 26, 2024
1 parent 82a9f1a commit 19c61c1
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
2 changes: 2 additions & 0 deletions clicky-core/src/devices/platform/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod cpuid;
mod devcon;
mod dma;
mod eide;
mod evp;
mod flash;
mod gpio;
mod i2c;
Expand All @@ -27,6 +28,7 @@ pub use cpuid::*;
pub use devcon::*;
pub use dma::*;
pub use eide::*;
pub use evp::*;
pub use flash::*;
pub use gpio::*;
pub use i2c::*;
Expand Down
5 changes: 1 addition & 4 deletions clicky-core/src/devices/platform/pp/cachecon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::devices::prelude::*;
#[derive(Debug)]
pub struct CacheCon {
/// Local exception vector table enable (bit 4)
local_evt: bool,
pub local_evt: bool,
/// Cache control enable (bit 1)
cache_ctrl_enable: bool,
}
Expand Down Expand Up @@ -54,9 +54,6 @@ impl Memory for CacheCon {
match offset {
0x00 => {
self.local_evt = val.get_bit(4);
if self.local_evt {
return Err(Fatal("local exception vector table not implemented".into()));
}
self.cache_ctrl_enable = val.get_bit(1);
Err(StubWrite(Error, ()))
}
Expand Down
81 changes: 81 additions & 0 deletions clicky-core/src/devices/platform/pp/evp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::devices::prelude::*;

/// Returns different value based on which CPU accesses it.
#[derive(Debug)]
pub struct Evp {
reset_vec: u32,
undefined_instr_vec: u32,
soft_irq_vec: u32,
prefetch_abrt_vec: u32,
data_abrt_vec: u32,
reserved_vec: u32,
normal_irq_vec: u32,
high_priority_irq_vec: u32,
}

impl Evp {
pub fn new() -> Evp {
Evp {
reset_vec: 0x0,
undefined_instr_vec: 0x4,
soft_irq_vec: 0x8,
prefetch_abrt_vec: 0xC,
data_abrt_vec: 0x10,
reserved_vec: 0x14,
normal_irq_vec: 0x18,
high_priority_irq_vec: 0x1C,
}
}
}

impl Device for Evp {
fn kind(&self) -> &'static str {
"EVP (Exception Vector ???)"
}

fn probe(&self, offset: u32) -> Probe {
let reg = match offset {
0x0 => "Reset Exception Handler",
0x4 => "Undefined Instruction Handler",
0x8 => "Software Interrupt Handler",
0xC => "Prefetch Abort Handler",
0x10 => "Data Abort Handler",
0x14 => "Reserved Handler",
0x18 => "Normal-priority Interrupt Handler",
0x1C => "High-priority Interrupt Handler",
_ => return Probe::Unmapped,
};

Probe::Register(reg)
}
}

impl Memory for Evp {
fn r32(&mut self, offset: u32) -> MemResult<u32> {
match offset {
0x0 => Err(StubRead(Error, self.reset_vec)),
0x4 => Err(StubRead(Error, self.undefined_instr_vec)),
0x8 => Err(StubRead(Error, self.soft_irq_vec)),
0xC => Err(StubRead(Error, self.prefetch_abrt_vec)),
0x10 => Err(StubRead(Error, self.data_abrt_vec)),
0x14 => Err(StubRead(Error, self.reserved_vec)),
0x18 => Err(StubRead(Error, self.normal_irq_vec)),
0x1C => Err(StubRead(Error, self.high_priority_irq_vec)),
_ => Err(Unexpected),
}
}

fn w32(&mut self, offset: u32, val: u32) -> MemResult<()> {
match offset {
0x0 => Ok(self.reset_vec = val),
0x4 => Ok(self.undefined_instr_vec = val),
0x8 => Ok(self.soft_irq_vec = val),
0xC => Ok(self.prefetch_abrt_vec = val),
0x10 => Ok(self.data_abrt_vec = val),
0x14 => Ok(self.reserved_vec = val),
0x18 => Ok(self.normal_irq_vec = val),
0x1C => Ok(self.high_priority_irq_vec = val),
_ => Err(InvalidAccess),
}
}
}
14 changes: 12 additions & 2 deletions clicky-core/src/sys/ipod4g/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ pub struct Ipod4gBus {
pub dmacon: devices::DmaCon,
pub serial0: devices::Serial,
pub serial1: devices::Serial,
pub evp: devices::Evp,

pub mystery_irq_con: devices::Stub,
pub mystery_lcd_con: devices::Stub,
Expand Down Expand Up @@ -437,6 +438,7 @@ impl Ipod4gBus {
dmacon,
serial0: Serial::new("0"),
serial1: Serial::new("1"),
evp: Evp::new(),

mystery_irq_con: Stub::new("Mystery IRQ Con?"),
mystery_lcd_con: Stub::new("Mystery LCD Con?"),
Expand All @@ -460,7 +462,12 @@ macro_rules! mmap {
macro_rules! impl_mem_r {
($fn:ident, $ret:ty) => {
fn $fn(&mut self, addr: u32) -> MemResult<$ret> {
let (addr, prot) = self.memcon.virt_to_phys(addr);
let mut addr = addr;
if (0x00..0x1F).contains(&addr) && self.cachecon.local_evt {
addr = addr | 0x6000_f100;

Check warning on line 467 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

manual implementation of an assign operation

warning: manual implementation of an assign operation --> clicky-core/src/sys/ipod4g/mod.rs:467:25 | 467 | addr = addr | 0x6000_f100; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `addr |= 0x6000_f100` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 467 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

manual implementation of an assign operation

warning: manual implementation of an assign operation --> clicky-core/src/sys/ipod4g/mod.rs:467:25 | 467 | addr = addr | 0x6000_f100; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `addr |= 0x6000_f100` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 467 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

manual implementation of an assign operation

warning: manual implementation of an assign operation --> clicky-core/src/sys/ipod4g/mod.rs:467:25 | 467 | addr = addr | 0x6000_f100; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `addr |= 0x6000_f100` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern = note: `#[warn(clippy::assign_op_pattern)]` on by default = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)
}

let (mut addr, prot) = self.memcon.virt_to_phys(addr);

Check warning on line 470 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> clicky-core/src/sys/ipod4g/mod.rs:470:26 | 470 | let (mut addr, prot) = self.memcon.virt_to_phys(addr); | ----^^^^ | | | help: remove this `mut` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 470 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> clicky-core/src/sys/ipod4g/mod.rs:470:26 | 470 | let (mut addr, prot) = self.memcon.virt_to_phys(addr); | ----^^^^ | | | help: remove this `mut` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 470 in clicky-core/src/sys/ipod4g/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> clicky-core/src/sys/ipod4g/mod.rs:470:26 | 470 | let (mut addr, prot) = self.memcon.virt_to_phys(addr); | ----^^^^ | | | help: remove this `mut` ... 531 | / mmap! { 532 | | RAM { 533 | | 0x1000_0000..=0x11ff_ffff => sdram, 534 | | 0x4000_0000..=0x4001_7fff => fastram, ... | 588 | | } 589 | | } | |_- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `impl_mem_r` which comes from the expansion of the macro `mmap` (in Nightly builds, run with -Z macro-backtrace for more info)
if !prot.r {
return Err(MemException::MmuViolation)
}
Expand Down Expand Up @@ -559,6 +566,10 @@ mmap! {
0xc300_0000..=0xc300_0fff => eidecon,
0xf000_0000..=0xf000_ffff => memcon,

0x6000_f000..=0x6000_f01f => evp, // Tegra drivers mention 0x6000F1xx but 0x6000F0xx is mentioned in PP5020 RE litterature
0x6000_f100..=0x6000_f11f => evp, // I assume 0x6000F0xx and 0x6000F1xx are mirrored? Maybe one is used for the main CPU,
// the other is used for COP?

// all the stubs

0x6000_1038 => mystery_irq_con,
Expand All @@ -568,7 +579,6 @@ mmap! {
0x6000_3000..=0x6000_30ff => total_mystery,
0x6000_9000..=0x6000_90ff => total_mystery,
// Diagnostics program reads from address, and write back 0x10000000
0x6000_f100..=0x6000_f11f => total_mystery,
0x7000_3800 => total_mystery,
0xc031_b1d8 => mystery_flash_stub,
0xc031_b1e8 => mystery_flash_stub,
Expand Down

0 comments on commit 19c61c1

Please sign in to comment.