mirror of
https://github.com/Creased/RCM-Emulator.git
synced 2026-12-06 02:48:11 +01:00
Model the CPU complex's reset view and per-core clock stop
RST_CPU_CMPLX_SET/CLR (0x340/0x344) and CLK_CPUG_CMPLX_SET/CLR (0x460/0x464) read back the last value written, like plain registers. - RST_CPU_CMPLX_SET has RST_CPUG_CMPLX's fields and reset value (TRM 5.2.113): it is the active cluster's view, and the Switch runs the G cluster. It and its CLR partner now act on the same reset state as the CPUG pair, releasing and stopping CPU0 alike, and read it back. - CLK_CPUG_CMPLX (0x378, TRM 5.2.122) and its SET/CLR strobes track CPUGn_CLK_STP, and all three read the register. A stopped CPU0 keeps its state and executes nothing while emulated time passes; clearing the stop resumes it where it was. The CCPLEX test now releases CPU0 with its clock stopped, checks it does not run and that the registers read back, then clears the stop. Against the previous binary those three checks fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
This commit is contained in:
4 files changed
+63
-2
No files matched your search
@@ -659,6 +659,14 @@ cannot run: <reason>` and the core stays dark, which is what silicon does,
|
||||
minus the explanation. Asserting a reset bit, gating a partition or dropping
|
||||
the rail stops a running core.
|
||||
|
||||
`RST_CPU_CMPLX_SET` (0x340, TRM 5.2.113) carries `RST_CPUG_CMPLX`'s fields and
|
||||
reset value: it is the active cluster's view, and the Switch runs the G
|
||||
cluster, so it and its CLR partner at 0x344 act on the same reset state.
|
||||
`CLK_CPUG_CMPLX` (0x378, TRM 5.2.122) and its SET/CLR strobes (0x460/0x464)
|
||||
stop a core's clock with `CPUGn_CLK_STP`; all three read the register back.
|
||||
CPU0 with its clock stopped keeps its state and executes nothing while
|
||||
emulated time passes, and carries on where it was once the stop is cleared.
|
||||
|
||||
**Entry at EL3.** A real A57 leaves reset at EL3, AArch64, MMU off. Unicorn
|
||||
builds its ARM64 core at EL1 and cannot be moved: a PSTATE write does not
|
||||
rebuild the translator's cached `hflags`, and Unicorn never delivers guest
|
||||
@@ -703,7 +711,8 @@ final `for(;;) wfe;` would otherwise spin through a billion instructions per
|
||||
emulated second.
|
||||
|
||||
`make test` runs `tests/ccplex/`, a self-contained payload that checks the
|
||||
refusal, the EL3 entry, the mailbox, WFE parking and the reset;
|
||||
refusal, the EL3 entry, a core released with its clock stopped, the
|
||||
mailbox, WFE parking and the reset;
|
||||
`tests/se/`, which runs the SE's RSA, SHA-256, AES and RNG against vectors
|
||||
computed in Python (`gen_vectors.py` writes `vectors.h`); and
|
||||
`tests/display/`, one payload built per scenario that drives the display
|
||||
|
||||
+32
-1
@@ -30,6 +30,18 @@
|
||||
#define CLK_V_MSELECT 3
|
||||
#define CAR_RST_CPUG_CMPLX_SET 0x450
|
||||
#define CAR_RST_CPUG_CMPLX_CLR 0x454
|
||||
// RST_CPU_CMPLX_SET (TRM 5.2.113) has RST_CPUG_CMPLX's fields and reset value:
|
||||
// it is the active cluster's view, and the Switch runs the G cluster. Its
|
||||
// CLR partner at 0x344 is not in the TRM; it pairs the way every SET does.
|
||||
#define CAR_RST_CPU_CMPLX_SET 0x340
|
||||
#define CAR_RST_CPU_CMPLX_CLR 0x344
|
||||
// CLK_CPUG_CMPLX (TRM 5.2.122, reset 0) and its SET/CLR strobes (5.2.154/155):
|
||||
// CPUGn_CLK_STP (bits 11:8) stops core n's clock. Like the peripheral banks,
|
||||
// all three read back the register.
|
||||
#define CAR_CLK_CPUG_CMPLX 0x378
|
||||
#define CAR_CLK_CPUG_CMPLX_SET 0x460
|
||||
#define CAR_CLK_CPUG_CMPLX_CLR 0x464
|
||||
#define CPU0_CLK_STP (1u << 8)
|
||||
// RST_CPUG_CMPLX (TRM 5.2.152, reset 0x2000feef). CPU0 runs once nCPUPORESET
|
||||
// (CPURESET0, bit 0), nCORERESET (CORERESET0, bit 16), nL2RESET (bit 24) and
|
||||
// the nonCPU region's reset (NONCPURESET, bit 29) are all released.
|
||||
@@ -102,6 +114,7 @@ enum class Cpu0 { Off, Running, Hung };
|
||||
|
||||
struct Model {
|
||||
uint32_t rst_cpug = RST_CPUG_CMPLX_RESET;
|
||||
uint32_t clk_cpug = 0;
|
||||
uint32_t clk_enb_v = 0;
|
||||
uint32_t cclk_burst = 0;
|
||||
uint32_t pllx_base = 0;
|
||||
@@ -457,11 +470,16 @@ void ccplex_car_write(EmuState *state, uint32_t offset, uint32_t val) {
|
||||
}
|
||||
break;
|
||||
case CAR_RST_CPUG_CMPLX_SET:
|
||||
case CAR_RST_CPU_CMPLX_SET:
|
||||
m.rst_cpug |= val;
|
||||
if (val & (RST_CPU0_MASK | RST_NONCPU))
|
||||
stop_cpu0("held in reset");
|
||||
break;
|
||||
case CAR_RST_CPUG_CMPLX_CLR: {
|
||||
case CAR_CLK_CPUG_CMPLX: m.clk_cpug = val; break;
|
||||
case CAR_CLK_CPUG_CMPLX_SET: m.clk_cpug |= val; break;
|
||||
case CAR_CLK_CPUG_CMPLX_CLR: m.clk_cpug &= ~val; break;
|
||||
case CAR_RST_CPUG_CMPLX_CLR:
|
||||
case CAR_RST_CPU_CMPLX_CLR: {
|
||||
bool was_held = held();
|
||||
m.rst_cpug &= ~val;
|
||||
if (was_held && !held() && m.cpu0 == Cpu0::Off)
|
||||
@@ -480,8 +498,15 @@ bool ccplex_car_read(uint32_t offset, uint32_t *out) {
|
||||
return true;
|
||||
case CAR_RST_CPUG_CMPLX_SET:
|
||||
case CAR_RST_CPUG_CMPLX_CLR:
|
||||
case CAR_RST_CPU_CMPLX_SET:
|
||||
case CAR_RST_CPU_CMPLX_CLR:
|
||||
*out = m.rst_cpug;
|
||||
return true;
|
||||
case CAR_CLK_CPUG_CMPLX:
|
||||
case CAR_CLK_CPUG_CMPLX_SET:
|
||||
case CAR_CLK_CPUG_CMPLX_CLR:
|
||||
*out = m.clk_cpug;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -544,6 +569,12 @@ void ccplex_run(EmuState *state, uint64_t until_us) {
|
||||
uint64_t target = until_us * 1000;
|
||||
if (m.ns >= target)
|
||||
return;
|
||||
// CPU0's clock stopped: the core keeps its state, time passes, nothing
|
||||
// executes. Clearing CPU0_CLK_STP resumes it where it was.
|
||||
if (m.clk_cpug & CPU0_CLK_STP) {
|
||||
m.ns = target;
|
||||
return;
|
||||
}
|
||||
|
||||
// While CPU0 runs, it is the bus master and "now" is its clock: every
|
||||
// register model reads state->emu_usec, and must see CPU0's time - a
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* of reset, PLLX, RAM repair, SB_AA64_RESET_LOW - then release it. An
|
||||
* AArch64 blob copied to DRAM records CurrentEL and a TIMERUS delta in
|
||||
* a mailbox, writes a magic word last, and parks in WFE.
|
||||
* Released first with its clock stopped (CLK_CPUG_CMPLX), it must
|
||||
* stay still until the stop is cleared.
|
||||
* 3. Put CPU0 back into reset and power the console off.
|
||||
*
|
||||
* Built by `make test` with arm-none-eabi-gcc; no other toolchain needed, as
|
||||
@@ -139,7 +141,23 @@ void _start(void) {
|
||||
while (!(REG(FLOW + 0x40) & 2))
|
||||
;
|
||||
REG(CAR + 0x434) = 1u << 3; /* RST_DEV_V_CLR: MSELECT */
|
||||
|
||||
/* Released with its clock stopped, CPU0 must not run until the stop is
|
||||
* cleared; the strobes and the active-cluster reset view read back. */
|
||||
REG(CAR + 0x460) = 1u << 8; /* CLK_CPUG_CMPLX_SET: CPU0 */
|
||||
release_cpu0();
|
||||
udelay(5000);
|
||||
puts_(mb[0] == PCIE_MAGIC ? "clock stopped: CPU0 RAN (wrong)\n"
|
||||
: "clock stopped: CPU0 held still\n");
|
||||
puts_("clock stop reads ");
|
||||
puthex(REG(CAR + 0x378)); /* CLK_CPUG_CMPLX */
|
||||
putc_(' ');
|
||||
puthex(REG(CAR + 0x464)); /* CLK_CPUG_CMPLX_CLR */
|
||||
putc_('\n');
|
||||
puts_(REG(CAR + 0x340) == REG(CAR + 0x450) /* RST_CPU(G)_CMPLX_SET */
|
||||
? "reset view: RST_CPU_CMPLX matches RST_CPUG_CMPLX\n"
|
||||
: "reset view: RST_CPU_CMPLX differs\n");
|
||||
REG(CAR + 0x464) = 1u << 8; /* CLK_CPUG_CMPLX_CLR */
|
||||
|
||||
u32 start = REG(TIMERUS);
|
||||
while (mb[0] != PCIE_MAGIC && REG(TIMERUS) - start < 100000)
|
||||
|
||||
@@ -23,6 +23,9 @@ echo "ccplex test (emulator exit $status):"
|
||||
expect 'cannot run: CPU rail off' 'an unpowered release is refused, with the reason'
|
||||
expect 'unpowered: CPU0 stayed dark' 'and the core really did not execute'
|
||||
expect 'CPU0 released: AArch64 EL3, MMU off, entry 0xA0000000' 'a powered release boots CPU0 at the SB vector'
|
||||
expect 'clock stopped: CPU0 held still' 'a core released with its clock stopped does not run'
|
||||
expect 'clock stop reads 00000100 00000100' 'CLK_CPUG_CMPLX and its CLR strobe read back the stop'
|
||||
expect 'RST_CPU_CMPLX matches RST_CPUG_CMPLX' 'the active-cluster reset register reads the G cluster'
|
||||
expect 'powered: magic=50434945' 'CPU0 ran the blob and wrote the mailbox'
|
||||
expect 'el=0000000C' 'CPU0 came up at EL3'
|
||||
expect 'CPU0 stopped (held in reset)' 'RST_CPUG_CMPLX_SET stops the core'
|
||||
|
||||
Reference in new issue
Block a user