mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-05 20:34:27 +01:00
56 lines
2.0 KiB
C
56 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
|
/* Model the delayed bus fault generated by holding core 1, including locked debug registers. */
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
static uint32_t con, enable, message, unlocked, traps, illegal;
|
|
static int delayed;
|
|
static uint32_t read_reg(uint32_t a)
|
|
{
|
|
switch (a) {
|
|
case 0x1EEE004u: return con;
|
|
case 0x1EEE240u: return unlocked;
|
|
case 0x1EEE340u: return enable;
|
|
default: abort();
|
|
}
|
|
}
|
|
static void write_reg(uint32_t a, uint32_t v)
|
|
{
|
|
if (a == 0x1EEE240u) { if (v != 0xE7u) abort(); unlocked ^= 1u; return; }
|
|
if (a == 0x1EEE004u) { con = v; delayed = 1; return; }
|
|
if (!unlocked) illegal++;
|
|
if (a == 0x1EEE340u) enable = v;
|
|
else if (a == 0x1EEE248u) message &= ~v;
|
|
else abort();
|
|
}
|
|
static void sync_reg(void)
|
|
{
|
|
if (delayed && (con & 2u)) { message |= 1u << 21; delayed = 0; }
|
|
if (message & enable & (1u << 21)) traps++;
|
|
}
|
|
#define FM1_STOP_READ(a) read_reg(a)
|
|
#define FM1_STOP_WRITE(a, v) write_reg(a, v)
|
|
#define FM1_STOP_SYNC() sync_reg()
|
|
#define FM1_STOP_MASK(v) ((void)(v))
|
|
#include "../firmware/hal/fm1_core1_stop.h"
|
|
int main(void)
|
|
{
|
|
uint32_t lock, running, en, cases = 0;
|
|
for (lock = 0; lock < 2; lock++)
|
|
for (running = 0; running < 2; running++)
|
|
for (en = 0; en < 2; en++) {
|
|
uint32_t original = en ? 0xFFFFFFFFu : 0x4000u;
|
|
con = running ? 8u : 2u; enable = original; message = 0x400u;
|
|
unlocked = lock; traps = illegal = 0; delayed = 0;
|
|
fm1_core1_stop();
|
|
if (traps || illegal || (con & 10u) != 2u || enable != original || unlocked != lock || !(message & 0x400u)) {
|
|
printf("core1 stop: FAIL lock=%u run=%u en=%u traps=%u illegal=%u\n", lock, running, en, traps, illegal);
|
|
return 1;
|
|
}
|
|
cases++;
|
|
}
|
|
printf("core1 stop: %u protection / running-state cases PASS\n", cases);
|
|
return 0;
|
|
}
|