2016-12-05 10:02:29 -07:00
|
|
|
/*
|
2023-11-03 17:21:46 -06:00
|
|
|
Copyright 2016-2023 melonDS team
|
2016-12-05 10:02:29 -07:00
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS 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, either version 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS 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 for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
2016-11-02 18:38:58 -06:00
|
|
|
|
|
|
|
#ifndef ARM_H
|
|
|
|
#define ARM_H
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-11-02 18:38:58 -06:00
|
|
|
#include "types.h"
|
|
|
|
#include "NDS.h"
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
#ifdef GDBSTUB_ENABLED
|
|
|
|
#include "debug/GdbStub.h"
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 12:37:14 -06:00
|
|
|
inline u32 ROR(u32 x, u32 n)
|
|
|
|
{
|
|
|
|
return (x >> (n&0x1F)) | (x << ((32-n)&0x1F));
|
|
|
|
}
|
2016-11-24 10:31:49 -07:00
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RWFlags_Nonseq = (1<<5),
|
|
|
|
RWFlags_ForceUser = (1<<21),
|
|
|
|
};
|
|
|
|
|
2020-06-14 13:04:25 -06:00
|
|
|
const u32 ITCMPhysicalSize = 0x8000;
|
|
|
|
const u32 DTCMPhysicalSize = 0x4000;
|
|
|
|
|
2016-11-02 18:38:58 -06:00
|
|
|
class ARM
|
2023-10-22 07:35:31 -06:00
|
|
|
#ifdef GDBSTUB_ENABLED
|
|
|
|
: public Gdb::StubCallbacks
|
|
|
|
#endif
|
2016-11-02 18:38:58 -06:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARM(u32 num);
|
2020-06-14 13:04:25 -06:00
|
|
|
virtual ~ARM(); // destroy shit
|
2016-11-02 18:38:58 -06:00
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
virtual void Reset();
|
|
|
|
|
|
|
|
virtual void DoSavestate(Savestate* file);
|
2016-11-24 10:31:49 -07:00
|
|
|
|
2019-08-17 08:50:48 -06:00
|
|
|
virtual void FillPipeline() = 0;
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
virtual void JumpTo(u32 addr, bool restorecpsr = false) = 0;
|
2016-11-24 16:08:53 -07:00
|
|
|
void RestoreCPSR();
|
|
|
|
|
2016-12-05 15:17:03 -07:00
|
|
|
void Halt(u32 halt)
|
|
|
|
{
|
2017-04-12 20:16:57 -06:00
|
|
|
if (halt==2 && Halted==1) return;
|
2016-12-05 15:17:03 -07:00
|
|
|
Halted = halt;
|
|
|
|
}
|
|
|
|
|
2019-01-04 21:28:58 -07:00
|
|
|
virtual void Execute() = 0;
|
2020-07-25 12:59:53 -06:00
|
|
|
#ifdef JIT_ENABLED
|
2019-07-13 20:33:36 -06:00
|
|
|
virtual void ExecuteJIT() = 0;
|
2019-07-14 11:24:00 -06:00
|
|
|
#endif
|
2016-11-02 18:38:58 -06:00
|
|
|
|
2016-11-24 16:08:53 -07:00
|
|
|
bool CheckCondition(u32 code)
|
|
|
|
{
|
|
|
|
if (code == 0xE) return true;
|
|
|
|
if (ConditionTable[code] & (1 << (CPSR>>28))) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetC(bool c)
|
|
|
|
{
|
|
|
|
if (c) CPSR |= 0x20000000;
|
|
|
|
else CPSR &= ~0x20000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNZ(bool n, bool z)
|
|
|
|
{
|
|
|
|
CPSR &= ~0xC0000000;
|
|
|
|
if (n) CPSR |= 0x80000000;
|
|
|
|
if (z) CPSR |= 0x40000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNZCV(bool n, bool z, bool c, bool v)
|
|
|
|
{
|
|
|
|
CPSR &= ~0xF0000000;
|
|
|
|
if (n) CPSR |= 0x80000000;
|
|
|
|
if (z) CPSR |= 0x40000000;
|
|
|
|
if (c) CPSR |= 0x20000000;
|
|
|
|
if (v) CPSR |= 0x10000000;
|
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
inline bool ModeIs(u32 mode)
|
|
|
|
{
|
|
|
|
u32 cm = CPSR & 0x1f;
|
|
|
|
mode &= 0x1f;
|
|
|
|
|
|
|
|
if (mode == cm) return true;
|
|
|
|
if (mode == 0x17) return cm >= 0x14 && cm <= 0x17; // abt
|
|
|
|
if (mode == 0x1b) return cm >= 0x18 && cm <= 0x1b; // und
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-28 13:15:12 -06:00
|
|
|
void UpdateMode(u32 oldmode, u32 newmode, bool phony = false);
|
2016-12-02 20:41:10 -07:00
|
|
|
|
2016-12-03 19:20:50 -07:00
|
|
|
void TriggerIRQ();
|
|
|
|
|
2018-11-04 15:21:58 -07:00
|
|
|
void SetupCodeMem(u32 addr);
|
|
|
|
|
2016-12-02 17:31:33 -07:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
virtual void DataRead8(u32 addr, u32* val) = 0;
|
|
|
|
virtual void DataRead16(u32 addr, u32* val) = 0;
|
|
|
|
virtual void DataRead32(u32 addr, u32* val) = 0;
|
|
|
|
virtual void DataRead32S(u32 addr, u32* val) = 0;
|
|
|
|
virtual void DataWrite8(u32 addr, u8 val) = 0;
|
|
|
|
virtual void DataWrite16(u32 addr, u16 val) = 0;
|
|
|
|
virtual void DataWrite32(u32 addr, u32 val) = 0;
|
|
|
|
virtual void DataWrite32S(u32 addr, u32 val) = 0;
|
2018-11-04 15:21:58 -07:00
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
virtual void AddCycles_C() = 0;
|
2018-12-08 17:17:05 -07:00
|
|
|
virtual void AddCycles_CI(s32 numI) = 0;
|
2018-12-04 09:54:10 -07:00
|
|
|
virtual void AddCycles_CDI() = 0;
|
|
|
|
virtual void AddCycles_CD() = 0;
|
2018-11-04 15:21:58 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void CheckGdbIncoming();
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
u32 Num;
|
|
|
|
|
|
|
|
s32 Cycles;
|
2019-10-18 05:29:17 -06:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u8 Halted;
|
|
|
|
u8 IRQ; // nonzero to trigger IRQ
|
|
|
|
u8 IdleLoop;
|
|
|
|
};
|
|
|
|
u32 StopExecution;
|
|
|
|
};
|
2019-06-08 14:16:51 -06:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
u32 CodeRegion;
|
|
|
|
s32 CodeCycles;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
u32 DataRegion;
|
2018-12-04 09:54:10 -07:00
|
|
|
s32 DataCycles;
|
|
|
|
|
|
|
|
u32 R[16]; // heh
|
|
|
|
u32 CPSR;
|
|
|
|
u32 R_FIQ[8]; // holding SPSR too
|
|
|
|
u32 R_SVC[3];
|
|
|
|
u32 R_ABT[3];
|
|
|
|
u32 R_IRQ[3];
|
|
|
|
u32 R_UND[3];
|
|
|
|
u32 CurInstr;
|
|
|
|
u32 NextInstr[2];
|
|
|
|
|
|
|
|
u32 ExceptionBase;
|
|
|
|
|
|
|
|
NDS::MemRegion CodeMem;
|
|
|
|
|
2020-06-14 13:04:25 -06:00
|
|
|
#ifdef JIT_ENABLED
|
2020-06-30 15:50:41 -06:00
|
|
|
u32 FastBlockLookupStart, FastBlockLookupSize;
|
2020-06-14 13:04:25 -06:00
|
|
|
u64* FastBlockLookup;
|
|
|
|
#endif
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
static u32 ConditionTable[16];
|
2023-10-22 07:35:31 -06:00
|
|
|
#ifdef GDBSTUB_ENABLED
|
|
|
|
Gdb::GdbStub GdbStub;
|
|
|
|
#endif
|
2020-06-01 12:36:30 -06:00
|
|
|
|
|
|
|
protected:
|
|
|
|
u8 (*BusRead8)(u32 addr);
|
|
|
|
u16 (*BusRead16)(u32 addr);
|
|
|
|
u32 (*BusRead32)(u32 addr);
|
|
|
|
void (*BusWrite8)(u32 addr, u8 val);
|
|
|
|
void (*BusWrite16)(u32 addr, u16 val);
|
|
|
|
void (*BusWrite32)(u32 addr, u32 val);
|
2023-10-22 07:35:31 -06:00
|
|
|
|
|
|
|
#ifdef GDBSTUB_ENABLED
|
|
|
|
bool IsSingleStep;
|
|
|
|
bool BreakReq;
|
|
|
|
bool BreakOnStartup;
|
|
|
|
|
|
|
|
public:
|
|
|
|
int GetCPU() const override { return Num ? 7 : 9; }
|
|
|
|
|
|
|
|
u32 ReadReg(Gdb::Register reg) override;
|
|
|
|
void WriteReg(Gdb::Register reg, u32 v) override;
|
|
|
|
u32 ReadMem(u32 addr, int size) override;
|
|
|
|
void WriteMem(u32 addr, int size, u32 v) override;
|
|
|
|
|
|
|
|
void ResetGdb() override;
|
|
|
|
int RemoteCmd(const u8* cmd, size_t len) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void GdbCheckA();
|
|
|
|
void GdbCheckB();
|
|
|
|
void GdbCheckC();
|
2018-12-04 09:54:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class ARMv5 : public ARM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARMv5();
|
2020-06-14 13:04:25 -06:00
|
|
|
~ARMv5();
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void Reset() override;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DoSavestate(Savestate* file) override;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
void UpdateRegionTimings(u32 addrstart, u32 addrend);
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void FillPipeline() override;
|
2019-08-17 08:50:48 -06:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void JumpTo(u32 addr, bool restorecpsr = false) override;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2018-12-07 06:20:38 -07:00
|
|
|
void PrefetchAbort();
|
|
|
|
void DataAbort();
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void Execute() override;
|
2019-07-14 11:24:00 -06:00
|
|
|
#ifdef JIT_ENABLED
|
2023-10-22 07:35:31 -06:00
|
|
|
void ExecuteJIT() override;
|
2019-07-14 11:24:00 -06:00
|
|
|
#endif
|
2018-12-04 09:54:10 -07:00
|
|
|
|
|
|
|
// all code accesses are forced nonseq 32bit
|
2019-01-04 13:47:06 -07:00
|
|
|
u32 CodeRead32(u32 addr, bool branch);
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataRead8(u32 addr, u32* val) override;
|
|
|
|
void DataRead16(u32 addr, u32* val) override;
|
|
|
|
void DataRead32(u32 addr, u32* val) override;
|
|
|
|
void DataRead32S(u32 addr, u32* val) override;
|
|
|
|
void DataWrite8(u32 addr, u8 val) override;
|
|
|
|
void DataWrite16(u32 addr, u16 val) override;
|
|
|
|
void DataWrite32(u32 addr, u32 val) override;
|
|
|
|
void DataWrite32S(u32 addr, u32 val) override;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_C() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// code only. always nonseq 32-bit for ARM9.
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = (R[15] & 0x2) ? 0 : CodeCycles;
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC;
|
2016-12-02 17:31:33 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CI(s32 numI) override
|
2016-11-02 18:38:58 -06:00
|
|
|
{
|
2018-12-04 09:54:10 -07:00
|
|
|
// code+internal
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = (R[15] & 0x2) ? 0 : CodeCycles;
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC + numI;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
2018-11-04 15:21:58 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CDI() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// LDR/LDM cycles. ARM9 seems to skip the internal cycle there.
|
|
|
|
// TODO: ITCM data fetches shouldn't be parallelized, they say
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = (R[15] & 0x2) ? 0 : CodeCycles;
|
2018-12-04 09:54:10 -07:00
|
|
|
s32 numD = DataCycles;
|
2018-11-04 15:21:58 -07:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
//if (DataRegion != CodeRegion)
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 6, std::max(numC, numD));
|
2018-12-08 17:17:05 -07:00
|
|
|
//else
|
2020-07-27 15:14:23 -06:00
|
|
|
// Cycles += numC + numD;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CD() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// TODO: ITCM data fetches shouldn't be parallelized, they say
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = (R[15] & 0x2) ? 0 : CodeCycles;
|
2018-12-04 09:54:10 -07:00
|
|
|
s32 numD = DataCycles;
|
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
//if (DataRegion != CodeRegion)
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 6, std::max(numC, numD));
|
2018-12-08 17:17:05 -07:00
|
|
|
//else
|
2020-07-27 15:14:23 -06:00
|
|
|
// Cycles += numC + numD;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCodeMemRegion(u32 addr, NDS::MemRegion* region);
|
|
|
|
|
|
|
|
void CP15Reset();
|
|
|
|
void CP15DoSavestate(Savestate* file);
|
|
|
|
|
|
|
|
void UpdateDTCMSetting();
|
|
|
|
void UpdateITCMSetting();
|
|
|
|
|
2019-10-21 15:14:34 -06:00
|
|
|
void UpdatePURegion(u32 n);
|
|
|
|
void UpdatePURegions(bool update_all);
|
2018-12-07 06:20:38 -07:00
|
|
|
|
2019-01-04 13:47:06 -07:00
|
|
|
u32 RandomLineIndex();
|
|
|
|
|
|
|
|
void ICacheLookup(u32 addr);
|
|
|
|
void ICacheInvalidateByAddr(u32 addr);
|
|
|
|
void ICacheInvalidateAll();
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
void CP15Write(u32 id, u32 val);
|
|
|
|
u32 CP15Read(u32 id);
|
|
|
|
|
|
|
|
u32 CP15Control;
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2019-01-04 13:47:06 -07:00
|
|
|
u32 RNGSeed;
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
u32 DTCMSetting, ITCMSetting;
|
|
|
|
|
2020-02-04 10:29:52 -07:00
|
|
|
// for aarch64 JIT they need to go up here
|
|
|
|
// to be addressable by a 12-bit immediate
|
2018-12-04 09:54:10 -07:00
|
|
|
u32 ITCMSize;
|
2021-10-28 17:35:22 -06:00
|
|
|
u32 DTCMBase, DTCMMask;
|
2020-02-04 10:29:52 -07:00
|
|
|
s32 RegionCodeCycles;
|
|
|
|
|
2020-06-14 13:04:25 -06:00
|
|
|
u8 ITCM[ITCMPhysicalSize];
|
|
|
|
u8* DTCM;
|
2018-12-04 10:32:19 -07:00
|
|
|
|
2019-01-04 13:47:06 -07:00
|
|
|
u8 ICache[0x2000];
|
|
|
|
u32 ICacheTags[64*4];
|
|
|
|
u8 ICacheCount[64];
|
|
|
|
|
2018-12-04 10:32:19 -07:00
|
|
|
u32 PU_CodeCacheable;
|
|
|
|
u32 PU_DataCacheable;
|
|
|
|
u32 PU_DataCacheWrite;
|
|
|
|
|
|
|
|
u32 PU_CodeRW;
|
|
|
|
u32 PU_DataRW;
|
|
|
|
|
|
|
|
u32 PU_Region[8];
|
2018-12-07 06:20:38 -07:00
|
|
|
|
|
|
|
// 0=dataR 1=dataW 2=codeR 4=datacache 5=datawrite 6=codecache
|
|
|
|
u8 PU_PrivMap[0x100000];
|
2018-12-08 17:17:05 -07:00
|
|
|
u8 PU_UserMap[0x100000];
|
|
|
|
|
|
|
|
// games operate under system mode, generally
|
2021-10-28 13:24:39 -06:00
|
|
|
//#define PU_Map PU_PrivMap
|
|
|
|
u8* PU_Map;
|
2018-12-07 06:20:38 -07:00
|
|
|
|
2018-12-08 17:17:05 -07:00
|
|
|
// code/16N/32N/32S
|
|
|
|
u8 MemTimings[0x100000][4];
|
2018-12-11 09:59:52 -07:00
|
|
|
|
2019-01-04 13:47:06 -07:00
|
|
|
u8* CurICacheLine;
|
2020-06-01 12:36:30 -06:00
|
|
|
|
|
|
|
bool (*GetMemRegion)(u32 addr, bool write, NDS::MemRegion* region);
|
2023-10-22 07:35:31 -06:00
|
|
|
|
|
|
|
#ifdef GDBSTUB_ENABLED
|
|
|
|
u32 ReadMem(u32 addr, int size) override;
|
|
|
|
void WriteMem(u32 addr, int size, u32 v) override;
|
|
|
|
#endif
|
2018-12-04 09:54:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class ARMv4 : public ARM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARMv4();
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void Reset() override;
|
2020-06-01 12:36:30 -06:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void FillPipeline() override;
|
2019-08-17 08:50:48 -06:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void JumpTo(u32 addr, bool restorecpsr = false) override;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void Execute() override;
|
2019-07-14 11:24:00 -06:00
|
|
|
#ifdef JIT_ENABLED
|
2023-10-22 07:35:31 -06:00
|
|
|
void ExecuteJIT() override;
|
2019-07-14 11:24:00 -06:00
|
|
|
#endif
|
2018-12-04 09:54:10 -07:00
|
|
|
|
|
|
|
u16 CodeRead16(u32 addr)
|
|
|
|
{
|
2020-06-01 12:36:30 -06:00
|
|
|
return BusRead16(addr);
|
2017-01-30 10:36:11 -07:00
|
|
|
}
|
|
|
|
|
2018-12-04 09:54:10 -07:00
|
|
|
u32 CodeRead32(u32 addr)
|
|
|
|
{
|
2020-06-01 12:36:30 -06:00
|
|
|
return BusRead32(addr);
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataRead8(u32 addr, u32* val) override
|
2017-01-30 10:36:11 -07:00
|
|
|
{
|
2020-06-01 12:36:30 -06:00
|
|
|
*val = BusRead8(addr);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][0];
|
2017-01-30 10:36:11 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataRead16(u32 addr, u32* val) override
|
2017-01-30 10:36:11 -07:00
|
|
|
{
|
2016-12-02 17:31:33 -07:00
|
|
|
addr &= ~1;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
*val = BusRead16(addr);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][0];
|
2016-12-02 17:31:33 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataRead32(u32 addr, u32* val) override
|
2016-12-02 17:31:33 -07:00
|
|
|
{
|
|
|
|
addr &= ~3;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
*val = BusRead32(addr);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][2];
|
2016-12-02 17:31:33 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataRead32S(u32 addr, u32* val) override
|
2016-12-02 17:31:33 -07:00
|
|
|
{
|
2018-12-08 17:17:05 -07:00
|
|
|
addr &= ~3;
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
*val = BusRead32(addr);
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles += NDS::ARM7MemTimings[addr >> 15][3];
|
2016-12-02 17:31:33 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataWrite8(u32 addr, u8 val) override
|
2016-12-02 17:31:33 -07:00
|
|
|
{
|
2020-06-01 12:36:30 -06:00
|
|
|
BusWrite8(addr, val);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][0];
|
2018-12-08 17:17:05 -07:00
|
|
|
}
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataWrite16(u32 addr, u16 val) override
|
2018-12-08 17:17:05 -07:00
|
|
|
{
|
|
|
|
addr &= ~1;
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
BusWrite16(addr, val);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][0];
|
2016-12-02 17:31:33 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataWrite32(u32 addr, u32 val) override
|
2016-12-02 17:31:33 -07:00
|
|
|
{
|
|
|
|
addr &= ~3;
|
2018-12-04 09:54:10 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
BusWrite32(addr, val);
|
2020-05-08 16:45:05 -06:00
|
|
|
DataRegion = addr;
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles = NDS::ARM7MemTimings[addr >> 15][2];
|
2018-12-08 17:17:05 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void DataWrite32S(u32 addr, u32 val) override
|
2018-12-08 17:17:05 -07:00
|
|
|
{
|
|
|
|
addr &= ~3;
|
2016-12-02 17:31:33 -07:00
|
|
|
|
2020-06-01 12:36:30 -06:00
|
|
|
BusWrite32(addr, val);
|
2019-10-02 17:10:59 -06:00
|
|
|
DataCycles += NDS::ARM7MemTimings[addr >> 15][3];
|
2016-11-02 18:38:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_C() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// code only. this code fetch is sequential.
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?1:3];
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
2017-01-30 10:36:11 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CI(s32 num) override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// code+internal. results in a nonseq code fetch.
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2] + num;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
2016-12-05 09:08:24 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CDI() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// LDR/LDM cycles.
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2];
|
2018-12-04 09:54:10 -07:00
|
|
|
s32 numD = DataCycles;
|
2016-11-02 18:38:58 -06:00
|
|
|
|
2020-05-08 16:45:05 -06:00
|
|
|
if ((DataRegion >> 24) == 0x02) // mainRAM
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
2018-12-08 17:17:05 -07:00
|
|
|
if (CodeRegion == 0x02)
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC + numD;
|
2018-12-04 09:54:10 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
numC++;
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 3, std::max(numC, numD));
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 17:17:05 -07:00
|
|
|
else if (CodeRegion == 0x02)
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
numD++;
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 3, std::max(numC, numD));
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC + numD + 1;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 16:08:53 -07:00
|
|
|
|
2023-10-22 07:35:31 -06:00
|
|
|
void AddCycles_CD() override
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
|
|
|
// TODO: max gain should be 5c when writing to mainRAM
|
2018-12-08 17:17:05 -07:00
|
|
|
s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2];
|
2018-12-04 09:54:10 -07:00
|
|
|
s32 numD = DataCycles;
|
2016-12-23 13:22:22 -07:00
|
|
|
|
2020-05-08 16:45:05 -06:00
|
|
|
if ((DataRegion >> 24) == 0x02)
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
2018-12-08 17:17:05 -07:00
|
|
|
if (CodeRegion == 0x02)
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC + numD;
|
2018-12-04 09:54:10 -07:00
|
|
|
else
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 3, std::max(numC, numD));
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
2018-12-08 17:17:05 -07:00
|
|
|
else if (CodeRegion == 0x02)
|
2018-12-04 09:54:10 -07:00
|
|
|
{
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += std::max(numC + numD - 3, std::max(numC, numD));
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-27 15:14:23 -06:00
|
|
|
Cycles += numC + numD;
|
2018-12-04 09:54:10 -07:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 18:38:58 -06:00
|
|
|
};
|
|
|
|
|
2017-06-13 03:17:22 -06:00
|
|
|
namespace ARMInterpreter
|
|
|
|
{
|
|
|
|
|
|
|
|
void A_UNK(ARM* cpu);
|
|
|
|
void T_UNK(ARM* cpu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:45:05 -06:00
|
|
|
namespace NDS
|
|
|
|
{
|
|
|
|
|
|
|
|
extern ARMv5* ARM9;
|
|
|
|
extern ARMv4* ARM7;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:38:58 -06:00
|
|
|
#endif // ARM_H
|