mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-22 18:59:04 +02:00
Sysreg (0xBC100000) gets the ME's reset bit (0x4C bit 2), the soft interrupt (0x44, which interrupts the other CPU: the ME's controller from the main CPU, PSP_MECODEC_INTR from the ME), the hardware mutex (0x48, each CPU sets its own bit only while the other's is clear) and the clock and config registers it writes. The ME's interrupt controller (0xBC300000, write-1-to-clear, mask at 8) answers the ME only. All of it is the ME's state and stays unhandled without an ME. On the ME: interrupts to EBase with EPC and EXL, halt sleeping until an unmasked interrupt, and Count, which doesn't run: it stays 0 across 10ms with ERL set after reset and with Status cleared, and reads back what was written. Reset keeps the GPRs and sets Status ERL/BEV/SR, which homebrew relies on: mcidclan's samples run C on the stack Sony's ME code left. The values are from a kernel probe on a PSP-1000 (sp 0x801FFFE0, COP0 22 = 1, Status 0x20500404, mfic 0, which doesn't gate interrupts). The main CPU runs base interrupt handlers the way interruptman calls them (a0 intno, a1 arg, a2 interrupted pc; -2 disables), and interrupt 31 has a stand-in for me_wrapper's handler, which homebrew releases first. While the ME is emulated, any main CPU code may access hardware registers: homebrew calls its own code in kernel mode through a kcall module. This is a stopgap (g_kernelModeAnywhere, marked HACK): kernel mode should be part of the CPU's state, switched on while a kernel module's export runs. The memcpy/memmove replacements copy through MMIO when an end is a register address, for code copied to the boot page. mcidclan's me-soft-interrupt sample now runs, counting each interrupt in both directions. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
182 lines
4.3 KiB
C++
182 lines
4.3 KiB
C++
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official git repository and contact information can be found at
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
#include "Common/Log.h"
|
|
#include "Core/HW/MMIO.h"
|
|
#include "Core/HW/MeMMIO.h"
|
|
#include "Core/MemMap.h"
|
|
#include "Core/MIPS/MeCore.h"
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
namespace MeMMIO {
|
|
|
|
using MeCore::g_meState;
|
|
|
|
static bool IsME(const MIPSState *mips) {
|
|
return mips && mips->IsMediaEngine();
|
|
}
|
|
|
|
class MeSysregDevice : public MMIODevice {
|
|
public:
|
|
MeSysregDevice() : MMIODevice("ME sysreg", 0xBC100000, 0x100) {}
|
|
|
|
bool Read(MIPSState *mips, u32 offset, int size, u32 *value) override {
|
|
u32 *reg = Register(offset);
|
|
if (!reg) {
|
|
return false;
|
|
}
|
|
*value = *reg;
|
|
return true;
|
|
}
|
|
|
|
bool Write(MIPSState *mips, u32 offset, int size, u32 value) override {
|
|
if (!g_meState) {
|
|
return false;
|
|
}
|
|
switch (offset) {
|
|
case 0x44:
|
|
// Interrupts the other CPU.
|
|
if (value & 1) {
|
|
if (IsME(mips)) {
|
|
MeCore::InterruptMainCPU();
|
|
} else {
|
|
MeCore::RaiseInterrupt(MeCore::ME_INTR_SOFT);
|
|
}
|
|
}
|
|
return true;
|
|
case 0x48:
|
|
{
|
|
// Each CPU sets or clears its own bit, and can only set it while the other's is clear.
|
|
const u32 own = IsME(mips) ? 2 : 1;
|
|
const u32 other = own ^ 3;
|
|
if (!(value & own)) {
|
|
g_meState->mutex &= ~own;
|
|
} else if (!(g_meState->mutex & other)) {
|
|
g_meState->mutex |= own;
|
|
}
|
|
return true;
|
|
}
|
|
case 0x4C:
|
|
g_meState->resetFlags = value;
|
|
MeCore::SetReset((value & 4) != 0);
|
|
return true;
|
|
default:
|
|
if (u32 *reg = Register(offset)) {
|
|
*reg = value;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void Reset() override {}
|
|
void DoState(PointerWrap &p) override {}
|
|
|
|
private:
|
|
static u32 *Register(u32 offset) {
|
|
if (!g_meState) {
|
|
return nullptr;
|
|
}
|
|
switch (offset) {
|
|
case 0x04: return &g_meState->nmiFlags;
|
|
case 0x40: return &g_meState->ramConfig;
|
|
case 0x48: return &g_meState->mutex;
|
|
case 0x4C: return &g_meState->resetFlags;
|
|
case 0x50: return &g_meState->busClock;
|
|
default: return nullptr;
|
|
}
|
|
}
|
|
};
|
|
|
|
class MeInterruptDevice : public MMIODevice {
|
|
public:
|
|
MeInterruptDevice() : MMIODevice("ME interrupts", 0xBC300000, 0x10) {}
|
|
|
|
bool Read(MIPSState *mips, u32 offset, int size, u32 *value) override {
|
|
if (!g_meState || !IsME(mips)) {
|
|
return false;
|
|
}
|
|
switch (offset) {
|
|
case 0x0: *value = g_meState->intcRaised; return true;
|
|
case 0x8: *value = g_meState->intcEnabled; return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
bool Write(MIPSState *mips, u32 offset, int size, u32 value) override {
|
|
if (!g_meState || !IsME(mips)) {
|
|
return false;
|
|
}
|
|
switch (offset) {
|
|
case 0x0:
|
|
// Writing a source's bit clears it.
|
|
g_meState->intcRaised &= ~value;
|
|
return true;
|
|
case 0x8:
|
|
g_meState->intcEnabled = value;
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void Reset() override {}
|
|
void DoState(PointerWrap &p) override {}
|
|
};
|
|
|
|
class MeMemProtectDevice : public MMIODevice {
|
|
public:
|
|
MeMemProtectDevice() : MMIODevice("ME memory protection", 0xBC000000, 0x50) {}
|
|
|
|
bool Read(MIPSState *mips, u32 offset, int size, u32 *value) override {
|
|
if (!g_meState || (offset & 3)) {
|
|
return false;
|
|
}
|
|
*value = g_meState->memProtect[offset / 4];
|
|
return true;
|
|
}
|
|
|
|
bool Write(MIPSState *mips, u32 offset, int size, u32 value) override {
|
|
if (!g_meState || (offset & 3)) {
|
|
return false;
|
|
}
|
|
g_meState->memProtect[offset / 4] = value;
|
|
return true;
|
|
}
|
|
|
|
void Reset() override {}
|
|
void DoState(PointerWrap &p) override {}
|
|
};
|
|
|
|
static MeSysregDevice g_sysreg;
|
|
static MeInterruptDevice g_interrupts;
|
|
static MeMemProtectDevice g_memProtect;
|
|
|
|
MMIODevice *SysregDevice() {
|
|
return &g_sysreg;
|
|
}
|
|
|
|
MMIODevice *InterruptDevice() {
|
|
return &g_interrupts;
|
|
}
|
|
|
|
MMIODevice *MemProtectDevice() {
|
|
return &g_memProtect;
|
|
}
|
|
|
|
} // namespace MeMMIO
|