commit
62caa89f48
File diff suppressed because it is too large
Load Diff
@ -1,93 +0,0 @@
|
||||
// Copyright 2012 Michael Kang, 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/arm/dyncom/arm_dyncom_run.h"
|
||||
#include "core/arm/skyeye_common/armstate.h"
|
||||
|
||||
void switch_mode(ARMul_State* core, uint32_t mode) {
|
||||
if (core->Mode == mode)
|
||||
return;
|
||||
|
||||
if (mode != USERBANK) {
|
||||
switch (core->Mode) {
|
||||
case SYSTEM32MODE: // Shares registers with user mode
|
||||
case USER32MODE:
|
||||
core->Reg_usr[0] = core->Reg[13];
|
||||
core->Reg_usr[1] = core->Reg[14];
|
||||
break;
|
||||
case IRQ32MODE:
|
||||
core->Reg_irq[0] = core->Reg[13];
|
||||
core->Reg_irq[1] = core->Reg[14];
|
||||
core->Spsr[IRQBANK] = core->Spsr_copy;
|
||||
break;
|
||||
case SVC32MODE:
|
||||
core->Reg_svc[0] = core->Reg[13];
|
||||
core->Reg_svc[1] = core->Reg[14];
|
||||
core->Spsr[SVCBANK] = core->Spsr_copy;
|
||||
break;
|
||||
case ABORT32MODE:
|
||||
core->Reg_abort[0] = core->Reg[13];
|
||||
core->Reg_abort[1] = core->Reg[14];
|
||||
core->Spsr[ABORTBANK] = core->Spsr_copy;
|
||||
break;
|
||||
case UNDEF32MODE:
|
||||
core->Reg_undef[0] = core->Reg[13];
|
||||
core->Reg_undef[1] = core->Reg[14];
|
||||
core->Spsr[UNDEFBANK] = core->Spsr_copy;
|
||||
break;
|
||||
case FIQ32MODE:
|
||||
core->Reg_firq[0] = core->Reg[13];
|
||||
core->Reg_firq[1] = core->Reg[14];
|
||||
core->Spsr[FIQBANK] = core->Spsr_copy;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case USER32MODE:
|
||||
core->Reg[13] = core->Reg_usr[0];
|
||||
core->Reg[14] = core->Reg_usr[1];
|
||||
core->Bank = USERBANK;
|
||||
break;
|
||||
case IRQ32MODE:
|
||||
core->Reg[13] = core->Reg_irq[0];
|
||||
core->Reg[14] = core->Reg_irq[1];
|
||||
core->Spsr_copy = core->Spsr[IRQBANK];
|
||||
core->Bank = IRQBANK;
|
||||
break;
|
||||
case SVC32MODE:
|
||||
core->Reg[13] = core->Reg_svc[0];
|
||||
core->Reg[14] = core->Reg_svc[1];
|
||||
core->Spsr_copy = core->Spsr[SVCBANK];
|
||||
core->Bank = SVCBANK;
|
||||
break;
|
||||
case ABORT32MODE:
|
||||
core->Reg[13] = core->Reg_abort[0];
|
||||
core->Reg[14] = core->Reg_abort[1];
|
||||
core->Spsr_copy = core->Spsr[ABORTBANK];
|
||||
core->Bank = ABORTBANK;
|
||||
break;
|
||||
case UNDEF32MODE:
|
||||
core->Reg[13] = core->Reg_undef[0];
|
||||
core->Reg[14] = core->Reg_undef[1];
|
||||
core->Spsr_copy = core->Spsr[UNDEFBANK];
|
||||
core->Bank = UNDEFBANK;
|
||||
break;
|
||||
case FIQ32MODE:
|
||||
core->Reg[13] = core->Reg_firq[0];
|
||||
core->Reg[14] = core->Reg_firq[1];
|
||||
core->Spsr_copy = core->Spsr[FIQBANK];
|
||||
core->Bank = FIQBANK;
|
||||
break;
|
||||
case SYSTEM32MODE: // Shares registers with user mode.
|
||||
core->Reg[13] = core->Reg_usr[0];
|
||||
core->Reg[14] = core->Reg_usr[1];
|
||||
core->Bank = SYSTEMBANK;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set the mode bits in the APSR
|
||||
core->Cpsr = (core->Cpsr & ~core->Mode) | mode;
|
||||
core->Mode = mode;
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
/* arminit.c -- ARMulator initialization: ARM6 Instruction Emulator.
|
||||
Copyright (C) 1994 Advanced RISC Machines Ltd.
|
||||
|
||||
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; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <cstring>
|
||||
#include "core/arm/skyeye_common/armstate.h"
|
||||
#include "core/arm/skyeye_common/vfp/vfp.h"
|
||||
|
||||
// Resets certain MPCore CP15 values to their ARM-defined reset values.
|
||||
static void ResetMPCoreCP15Registers(ARMul_State* cpu)
|
||||
{
|
||||
// c0
|
||||
cpu->CP15[CP15_MAIN_ID] = 0x410FB024;
|
||||
cpu->CP15[CP15_TLB_TYPE] = 0x00000800;
|
||||
cpu->CP15[CP15_PROCESSOR_FEATURE_0] = 0x00000111;
|
||||
cpu->CP15[CP15_PROCESSOR_FEATURE_1] = 0x00000001;
|
||||
cpu->CP15[CP15_DEBUG_FEATURE_0] = 0x00000002;
|
||||
cpu->CP15[CP15_MEMORY_MODEL_FEATURE_0] = 0x01100103;
|
||||
cpu->CP15[CP15_MEMORY_MODEL_FEATURE_1] = 0x10020302;
|
||||
cpu->CP15[CP15_MEMORY_MODEL_FEATURE_2] = 0x01222000;
|
||||
cpu->CP15[CP15_MEMORY_MODEL_FEATURE_3] = 0x00000000;
|
||||
cpu->CP15[CP15_ISA_FEATURE_0] = 0x00100011;
|
||||
cpu->CP15[CP15_ISA_FEATURE_1] = 0x12002111;
|
||||
cpu->CP15[CP15_ISA_FEATURE_2] = 0x11221011;
|
||||
cpu->CP15[CP15_ISA_FEATURE_3] = 0x01102131;
|
||||
cpu->CP15[CP15_ISA_FEATURE_4] = 0x00000141;
|
||||
|
||||
// c1
|
||||
cpu->CP15[CP15_CONTROL] = 0x00054078;
|
||||
cpu->CP15[CP15_AUXILIARY_CONTROL] = 0x0000000F;
|
||||
cpu->CP15[CP15_COPROCESSOR_ACCESS_CONTROL] = 0x00000000;
|
||||
|
||||
// c2
|
||||
cpu->CP15[CP15_TRANSLATION_BASE_TABLE_0] = 0x00000000;
|
||||
cpu->CP15[CP15_TRANSLATION_BASE_TABLE_1] = 0x00000000;
|
||||
cpu->CP15[CP15_TRANSLATION_BASE_CONTROL] = 0x00000000;
|
||||
|
||||
// c3
|
||||
cpu->CP15[CP15_DOMAIN_ACCESS_CONTROL] = 0x00000000;
|
||||
|
||||
// c7
|
||||
cpu->CP15[CP15_PHYS_ADDRESS] = 0x00000000;
|
||||
|
||||
// c9
|
||||
cpu->CP15[CP15_DATA_CACHE_LOCKDOWN] = 0xFFFFFFF0;
|
||||
|
||||
// c10
|
||||
cpu->CP15[CP15_TLB_LOCKDOWN] = 0x00000000;
|
||||
cpu->CP15[CP15_PRIMARY_REGION_REMAP] = 0x00098AA4;
|
||||
cpu->CP15[CP15_NORMAL_REGION_REMAP] = 0x44E048E0;
|
||||
|
||||
// c13
|
||||
cpu->CP15[CP15_PID] = 0x00000000;
|
||||
cpu->CP15[CP15_CONTEXT_ID] = 0x00000000;
|
||||
cpu->CP15[CP15_THREAD_UPRW] = 0x00000000;
|
||||
cpu->CP15[CP15_THREAD_URO] = 0x00000000;
|
||||
cpu->CP15[CP15_THREAD_PRW] = 0x00000000;
|
||||
|
||||
// c15
|
||||
cpu->CP15[CP15_PERFORMANCE_MONITOR_CONTROL] = 0x00000000;
|
||||
cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS] = 0x00000000;
|
||||
cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS] = 0x00000000;
|
||||
cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE] = 0x00000000;
|
||||
cpu->CP15[CP15_TLB_DEBUG_CONTROL] = 0x00000000;
|
||||
}
|
||||
|
||||
// Performs a reset
|
||||
void ARMul_Reset(ARMul_State* state)
|
||||
{
|
||||
VFPInit(state);
|
||||
|
||||
state->Reg[15] = 0;
|
||||
state->Cpsr = INTBITS | SVC32MODE;
|
||||
state->Mode = SVC32MODE;
|
||||
state->Bank = SVCBANK;
|
||||
|
||||
ResetMPCoreCP15Registers(state);
|
||||
|
||||
state->NresetSig = HIGH;
|
||||
state->NfiqSig = HIGH;
|
||||
state->NirqSig = HIGH;
|
||||
state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
|
||||
state->abortSig = LOW;
|
||||
|
||||
state->NumInstrs = 0;
|
||||
state->Emulate = RUN;
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
armmmu.c - Memory Management Unit emulation.
|
||||
ARMulator extensions for the ARM7100 family.
|
||||
Copyright (C) 1999 Ben Williamson
|
||||
|
||||
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; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/swap.h"
|
||||
|
||||
#include "core/memory.h"
|
||||
#include "core/arm/skyeye_common/armstate.h"
|
||||
#include "core/arm/skyeye_common/armsupp.h"
|
||||
|
||||
// Register numbers in the MMU
|
||||
enum
|
||||
{
|
||||
MMU_ID = 0,
|
||||
MMU_CONTROL = 1,
|
||||
MMU_TRANSLATION_TABLE_BASE = 2,
|
||||
MMU_DOMAIN_ACCESS_CONTROL = 3,
|
||||
MMU_FAULT_STATUS = 5,
|
||||
MMU_FAULT_ADDRESS = 6,
|
||||
MMU_CACHE_OPS = 7,
|
||||
MMU_TLB_OPS = 8,
|
||||
MMU_CACHE_LOCKDOWN = 9,
|
||||
MMU_TLB_LOCKDOWN = 10,
|
||||
MMU_PID = 13,
|
||||
|
||||
// MMU_V4
|
||||
MMU_V4_CACHE_OPS = 7,
|
||||
MMU_V4_TLB_OPS = 8,
|
||||
|
||||
// MMU_V3
|
||||
MMU_V3_FLUSH_TLB = 5,
|
||||
MMU_V3_FLUSH_TLB_ENTRY = 6,
|
||||
MMU_V3_FLUSH_CACHE = 7,
|
||||
};
|
||||
|
||||
// Reads data in big/little endian format based on the
|
||||
// state of the E (endian) bit in the emulated CPU's APSR.
|
||||
inline u16 ReadMemory16(ARMul_State* cpu, u32 address) {
|
||||
u16 data = Memory::Read16(address);
|
||||
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap16(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
inline u32 ReadMemory32(ARMul_State* cpu, u32 address) {
|
||||
u32 data = Memory::Read32(address);
|
||||
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap32(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
inline u64 ReadMemory64(ARMul_State* cpu, u32 address) {
|
||||
u64 data = Memory::Read64(address);
|
||||
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap64(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Writes data in big/little endian format based on the
|
||||
// state of the E (endian) bit in the emulated CPU's APSR.
|
||||
inline void WriteMemory16(ARMul_State* cpu, u32 address, u16 data) {
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap16(data);
|
||||
|
||||
Memory::Write16(address, data);
|
||||
}
|
||||
|
||||
inline void WriteMemory32(ARMul_State* cpu, u32 address, u32 data) {
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap32(data);
|
||||
|
||||
Memory::Write32(address, data);
|
||||
}
|
||||
|
||||
inline void WriteMemory64(ARMul_State* cpu, u32 address, u64 data) {
|
||||
if (InBigEndianMode(cpu))
|
||||
data = Common::swap64(data);
|
||||
|
||||
Memory::Write64(address, data);
|
||||
}
|
@ -0,0 +1,657 @@
|
||||
// Copyright 2015 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/swap.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/mem_map.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/arm/skyeye_common/armstate.h"
|
||||
#include "core/arm/skyeye_common/vfp/vfp.h"
|
||||
|
||||
ARMul_State::ARMul_State(PrivilegeMode initial_mode)
|
||||
{
|
||||
Reset();
|
||||
ChangePrivilegeMode(initial_mode);
|
||||
}
|
||||
|
||||
void ARMul_State::ChangePrivilegeMode(u32 new_mode)
|
||||
{
|
||||
if (Mode == new_mode)
|
||||
return;
|
||||
|
||||
if (new_mode != USERBANK) {
|
||||
switch (Mode) {
|
||||
case SYSTEM32MODE: // Shares registers with user mode
|
||||
case USER32MODE:
|
||||
Reg_usr[0] = Reg[13];
|
||||
Reg_usr[1] = Reg[14];
|
||||
break;
|
||||
case IRQ32MODE:
|
||||
Reg_irq[0] = Reg[13];
|
||||
Reg_irq[1] = Reg[14];
|
||||
Spsr[IRQBANK] = Spsr_copy;
|
||||
break;
|
||||
case SVC32MODE:
|
||||
Reg_svc[0] = Reg[13];
|
||||
Reg_svc[1] = Reg[14];
|
||||
Spsr[SVCBANK] = Spsr_copy;
|
||||
break;
|
||||
case ABORT32MODE:
|
||||
Reg_abort[0] = Reg[13];
|
||||
Reg_abort[1] = Reg[14];
|
||||
Spsr[ABORTBANK] = Spsr_copy;
|
||||
break;
|
||||
case UNDEF32MODE:
|
||||
Reg_undef[0] = Reg[13];
|
||||
Reg_undef[1] = Reg[14];
|
||||
Spsr[UNDEFBANK] = Spsr_copy;
|
||||
break;
|
||||
case FIQ32MODE:
|
||||
Reg_firq[0] = Reg[13];
|
||||
Reg_firq[1] = Reg[14];
|
||||
Spsr[FIQBANK] = Spsr_copy;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (new_mode) {
|
||||
case USER32MODE:
|
||||
Reg[13] = Reg_usr[0];
|
||||
Reg[14] = Reg_usr[1];
|
||||
Bank = USERBANK;
|
||||
break;
|
||||
case IRQ32MODE:
|
||||
Reg[13] = Reg_irq[0];
|
||||
Reg[14] = Reg_irq[1];
|
||||
Spsr_copy = Spsr[IRQBANK];
|
||||
Bank = IRQBANK;
|
||||
break;
|
||||
case SVC32MODE:
|
||||
Reg[13] = Reg_svc[0];
|
||||
Reg[14] = Reg_svc[1];
|
||||
Spsr_copy = Spsr[SVCBANK];
|
||||
Bank = SVCBANK;
|
||||
break;
|
||||
case ABORT32MODE:
|
||||
Reg[13] = Reg_abort[0];
|
||||
Reg[14] = Reg_abort[1];
|
||||
Spsr_copy = Spsr[ABORTBANK];
|
||||
Bank = ABORTBANK;
|
||||
break;
|
||||
case UNDEF32MODE:
|
||||
Reg[13] = Reg_undef[0];
|
||||
Reg[14] = Reg_undef[1];
|
||||
Spsr_copy = Spsr[UNDEFBANK];
|
||||
Bank = UNDEFBANK;
|
||||
break;
|
||||
case FIQ32MODE:
|
||||
Reg[13] = Reg_firq[0];
|
||||
Reg[14] = Reg_firq[1];
|
||||
Spsr_copy = Spsr[FIQBANK];
|
||||
Bank = FIQBANK;
|
||||
break;
|
||||
case SYSTEM32MODE: // Shares registers with user mode.
|
||||
Reg[13] = Reg_usr[0];
|
||||
Reg[14] = Reg_usr[1];
|
||||
Bank = SYSTEMBANK;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set the mode bits in the APSR
|
||||
Cpsr = (Cpsr & ~Mode) | new_mode;
|
||||
Mode = new_mode;
|
||||
}
|
||||
}
|
||||
|
||||
// Performs a reset
|
||||
void ARMul_State::Reset()
|
||||
{
|
||||
VFPInit(this);
|
||||
|
||||
// Set stack pointer to the top of the stack
|
||||
Reg[13] = 0x10000000;
|
||||
Reg[15] = 0;
|
||||
|
||||
Cpsr = INTBITS | SVC32MODE;
|
||||
Mode = SVC32MODE;
|
||||
Bank = SVCBANK;
|
||||
|
||||
ResetMPCoreCP15Registers();
|
||||
|
||||
NresetSig = HIGH;
|
||||
NfiqSig = HIGH;
|
||||
NirqSig = HIGH;
|
||||
NtransSig = (Mode & 3) ? HIGH : LOW;
|
||||
abortSig = LOW;
|
||||
|
||||
NumInstrs = 0;
|
||||
Emulate = RUN;
|
||||
}
|
||||
|
||||
// Resets certain MPCore CP15 values to their ARM-defined reset values.
|
||||
void ARMul_State::ResetMPCoreCP15Registers()
|
||||
{
|
||||
// c0
|
||||
CP15[CP15_MAIN_ID] = 0x410FB024;
|
||||
CP15[CP15_TLB_TYPE] = 0x00000800;
|
||||
CP15[CP15_PROCESSOR_FEATURE_0] = 0x00000111;
|
||||
CP15[CP15_PROCESSOR_FEATURE_1] = 0x00000001;
|
||||
CP15[CP15_DEBUG_FEATURE_0] = 0x00000002;
|
||||
CP15[CP15_MEMORY_MODEL_FEATURE_0] = 0x01100103;
|
||||
CP15[CP15_MEMORY_MODEL_FEATURE_1] = 0x10020302;
|
||||
CP15[CP15_MEMORY_MODEL_FEATURE_2] = 0x01222000;
|
||||
CP15[CP15_MEMORY_MODEL_FEATURE_3] = 0x00000000;
|
||||
CP15[CP15_ISA_FEATURE_0] = 0x00100011;
|
||||
CP15[CP15_ISA_FEATURE_1] = 0x12002111;
|
||||
CP15[CP15_ISA_FEATURE_2] = 0x11221011;
|
||||
CP15[CP15_ISA_FEATURE_3] = 0x01102131;
|
||||
CP15[CP15_ISA_FEATURE_4] = 0x00000141;
|
||||
|
||||
// c1
|
||||
CP15[CP15_CONTROL] = 0x00054078;
|
||||
CP15[CP15_AUXILIARY_CONTROL] = 0x0000000F;
|
||||
CP15[CP15_COPROCESSOR_ACCESS_CONTROL] = 0x00000000;
|
||||
|
||||
// c2
|
||||
CP15[CP15_TRANSLATION_BASE_TABLE_0] = 0x00000000;
|
||||
CP15[CP15_TRANSLATION_BASE_TABLE_1] = 0x00000000;
|
||||
CP15[CP15_TRANSLATION_BASE_CONTROL] = 0x00000000;
|
||||
|
||||
// c3
|
||||
CP15[CP15_DOMAIN_ACCESS_CONTROL] = 0x00000000;
|
||||
|
||||
// c7
|
||||
CP15[CP15_PHYS_ADDRESS] = 0x00000000;
|
||||
|
||||
// c9
|
||||
CP15[CP15_DATA_CACHE_LOCKDOWN] = 0xFFFFFFF0;
|
||||
|
||||
// c10
|
||||
CP15[CP15_TLB_LOCKDOWN] = 0x00000000;
|
||||
CP15[CP15_PRIMARY_REGION_REMAP] = 0x00098AA4;
|
||||
CP15[CP15_NORMAL_REGION_REMAP] = 0x44E048E0;
|
||||
|
||||
// c13
|
||||
CP15[CP15_PID] = 0x00000000;
|
||||
CP15[CP15_CONTEXT_ID] = 0x00000000;
|
||||
CP15[CP15_THREAD_UPRW] = 0x00000000;
|
||||
CP15[CP15_THREAD_URO] = 0x00000000;
|
||||
CP15[CP15_THREAD_PRW] = 0x00000000;
|
||||
|
||||
// c15
|
||||
CP15[CP15_PERFORMANCE_MONITOR_CONTROL] = 0x00000000;
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS] = 0x00000000;
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS] = 0x00000000;
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE] = 0x00000000;
|
||||
CP15[CP15_TLB_DEBUG_CONTROL] = 0x00000000;
|
||||
}
|
||||
|
||||
u16 ARMul_State::ReadMemory16(u32 address) const
|
||||
{
|
||||
u16 data = Memory::Read16(address);
|
||||
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap16(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
u32 ARMul_State::ReadMemory32(u32 address) const
|
||||
{
|
||||
u32 data = Memory::Read32(address);
|
||||
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap32(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
u64 ARMul_State::ReadMemory64(u32 address) const
|
||||
{
|
||||
u64 data = Memory::Read64(address);
|
||||
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap64(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void ARMul_State::WriteMemory16(u32 address, u16 data)
|
||||
{
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap16(data);
|
||||
|
||||
Memory::Write16(address, data);
|
||||
}
|
||||
|
||||
void ARMul_State::WriteMemory32(u32 address, u32 data)
|
||||
{
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap32(data);
|
||||
|
||||
Memory::Write32(address, data);
|
||||
}
|
||||
|
||||
void ARMul_State::WriteMemory64(u32 address, u64 data)
|
||||
{
|
||||
if (InBigEndianMode())
|
||||
data = Common::swap64(data);
|
||||
|
||||
Memory::Write64(address, data);
|
||||
}
|
||||
|
||||
|
||||
// Reads from the CP15 registers. Used with implementation of the MRC instruction.
|
||||
// Note that since the 3DS does not have the hypervisor extensions, these registers
|
||||
// are not implemented.
|
||||
u32 ARMul_State::ReadCP15Register(u32 crn, u32 opcode_1, u32 crm, u32 opcode_2) const
|
||||
{
|
||||
// Unprivileged registers
|
||||
if (crn == 13 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_THREAD_UPRW];
|
||||
|
||||
if (opcode_2 == 3)
|
||||
return CP15[CP15_THREAD_URO];
|
||||
}
|
||||
|
||||
if (InAPrivilegedMode())
|
||||
{
|
||||
if (crn == 0 && opcode_1 == 0)
|
||||
{
|
||||
if (crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_MAIN_ID];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_CACHE_TYPE];
|
||||
|
||||
if (opcode_2 == 3)
|
||||
return CP15[CP15_TLB_TYPE];
|
||||
|
||||
if (opcode_2 == 5)
|
||||
return CP15[CP15_CPU_ID];
|
||||
}
|
||||
else if (crm == 1)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_PROCESSOR_FEATURE_0];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_PROCESSOR_FEATURE_1];
|
||||
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_DEBUG_FEATURE_0];
|
||||
|
||||
if (opcode_2 == 4)
|
||||
return CP15[CP15_MEMORY_MODEL_FEATURE_0];
|
||||
|
||||
if (opcode_2 == 5)
|
||||
return CP15[CP15_MEMORY_MODEL_FEATURE_1];
|
||||
|
||||
if (opcode_2 == 6)
|
||||
return CP15[CP15_MEMORY_MODEL_FEATURE_2];
|
||||
|
||||
if (opcode_2 == 7)
|
||||
return CP15[CP15_MEMORY_MODEL_FEATURE_3];
|
||||
}
|
||||
else if (crm == 2)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_ISA_FEATURE_0];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_ISA_FEATURE_1];
|
||||
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_ISA_FEATURE_2];
|
||||
|
||||
if (opcode_2 == 3)
|
||||
return CP15[CP15_ISA_FEATURE_3];
|
||||
|
||||
if (opcode_2 == 4)
|
||||
return CP15[CP15_ISA_FEATURE_4];
|
||||
}
|
||||
}
|
||||
|
||||
if (crn == 1 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_CONTROL];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_AUXILIARY_CONTROL];
|
||||
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_COPROCESSOR_ACCESS_CONTROL];
|
||||
}
|
||||
|
||||
if (crn == 2 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_TRANSLATION_BASE_TABLE_0];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_TRANSLATION_BASE_TABLE_1];
|
||||
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_TRANSLATION_BASE_CONTROL];
|
||||
}
|
||||
|
||||
if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
|
||||
return CP15[CP15_DOMAIN_ACCESS_CONTROL];
|
||||
|
||||
if (crn == 5 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_FAULT_STATUS];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_INSTR_FAULT_STATUS];
|
||||
}
|
||||
|
||||
if (crn == 6 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_FAULT_ADDRESS];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_WFAR];
|
||||
}
|
||||
|
||||
if (crn == 7 && opcode_1 == 0 && crm == 4 && opcode_2 == 0)
|
||||
return CP15[CP15_PHYS_ADDRESS];
|
||||
|
||||
if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
|
||||
return CP15[CP15_DATA_CACHE_LOCKDOWN];
|
||||
|
||||
if (crn == 10 && opcode_1 == 0)
|
||||
{
|
||||
if (crm == 0 && opcode_2 == 0)
|
||||
return CP15[CP15_TLB_LOCKDOWN];
|
||||
|
||||
if (crm == 2)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_PRIMARY_REGION_REMAP];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_NORMAL_REGION_REMAP];
|
||||
}
|
||||
}
|
||||
|
||||
if (crn == 13 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_PID];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_CONTEXT_ID];
|
||||
|
||||
if (opcode_2 == 4)
|
||||
return CP15[CP15_THREAD_PRW];
|
||||
}
|
||||
|
||||
if (crn == 15)
|
||||
{
|
||||
if (opcode_1 == 0 && crm == 12)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
return CP15[CP15_PERFORMANCE_MONITOR_CONTROL];
|
||||
|
||||
if (opcode_2 == 1)
|
||||
return CP15[CP15_CYCLE_COUNTER];
|
||||
|
||||
if (opcode_2 == 2)
|
||||
return CP15[CP15_COUNT_0];
|
||||
|
||||
if (opcode_2 == 3)
|
||||
return CP15[CP15_COUNT_1];
|
||||
}
|
||||
|
||||
if (opcode_1 == 5 && opcode_2 == 2)
|
||||
{
|
||||
if (crm == 5)
|
||||
return CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS];
|
||||
|
||||
if (crm == 6)
|
||||
return CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS];
|
||||
|
||||
if (crm == 7)
|
||||
return CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE];
|
||||
}
|
||||
|
||||
if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
|
||||
return CP15[CP15_TLB_DEBUG_CONTROL];
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Write to the CP15 registers. Used with implementation of the MCR instruction.
|
||||
// Note that since the 3DS does not have the hypervisor extensions, these registers
|
||||
// are not implemented.
|
||||
void ARMul_State::WriteCP15Register(u32 value, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
|
||||
{
|
||||
if (InAPrivilegedMode())
|
||||
{
|
||||
if (crn == 1 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_CONTROL] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_AUXILIARY_CONTROL] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_COPROCESSOR_ACCESS_CONTROL] = value;
|
||||
}
|
||||
else if (crn == 2 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_TRANSLATION_BASE_TABLE_0] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_TRANSLATION_BASE_TABLE_1] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_TRANSLATION_BASE_CONTROL] = value;
|
||||
}
|
||||
else if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
|
||||
{
|
||||
CP15[CP15_DOMAIN_ACCESS_CONTROL] = value;
|
||||
}
|
||||
else if (crn == 5 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_FAULT_STATUS] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INSTR_FAULT_STATUS] = value;
|
||||
}
|
||||
else if (crn == 6 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_FAULT_ADDRESS] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_WFAR] = value;
|
||||
}
|
||||
else if (crn == 7 && opcode_1 == 0)
|
||||
{
|
||||
if (crm == 0 && opcode_2 == 4)
|
||||
{
|
||||
CP15[CP15_WAIT_FOR_INTERRUPT] = value;
|
||||
}
|
||||
else if (crm == 4 && opcode_2 == 0)
|
||||
{
|
||||
// NOTE: Not entirely accurate. This should do permission checks.
|
||||
CP15[CP15_PHYS_ADDRESS] = Memory::VirtualToPhysicalAddress(value);
|
||||
}
|
||||
else if (crm == 5)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_INVALIDATE_INSTR_CACHE] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INVALIDATE_INSTR_CACHE_USING_MVA] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_INVALIDATE_INSTR_CACHE_USING_INDEX] = value;
|
||||
else if (opcode_2 == 6)
|
||||
CP15[CP15_FLUSH_BRANCH_TARGET_CACHE] = value;
|
||||
else if (opcode_2 == 7)
|
||||
CP15[CP15_FLUSH_BRANCH_TARGET_CACHE_ENTRY] = value;
|
||||
}
|
||||
else if (crm == 6)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_INVALIDATE_DATA_CACHE] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INVALIDATE_DATA_CACHE_LINE_USING_MVA] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_INVALIDATE_DATA_CACHE_LINE_USING_INDEX] = value;
|
||||
}
|
||||
else if (crm == 7 && opcode_2 == 0)
|
||||
{
|
||||
CP15[CP15_INVALIDATE_DATA_AND_INSTR_CACHE] = value;
|
||||
}
|
||||
else if (crm == 10)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_CLEAN_DATA_CACHE] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_CLEAN_DATA_CACHE_LINE_USING_MVA] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_CLEAN_DATA_CACHE_LINE_USING_INDEX] = value;
|
||||
}
|
||||
else if (crm == 14)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_MVA] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_INDEX] = value;
|
||||
}
|
||||
}
|
||||
else if (crn == 8 && opcode_1 == 0)
|
||||
{
|
||||
if (crm == 5)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_INVALIDATE_ITLB] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INVALIDATE_ITLB_SINGLE_ENTRY] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_INVALIDATE_ITLB_ENTRY_ON_ASID_MATCH] = value;
|
||||
else if (opcode_2 == 3)
|
||||
CP15[CP15_INVALIDATE_ITLB_ENTRY_ON_MVA] = value;
|
||||
}
|
||||
else if (crm == 6)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_INVALIDATE_DTLB] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INVALIDATE_DTLB_SINGLE_ENTRY] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_INVALIDATE_DTLB_ENTRY_ON_ASID_MATCH] = value;
|
||||
else if (opcode_2 == 3)
|
||||
CP15[CP15_INVALIDATE_DTLB_ENTRY_ON_MVA] = value;
|
||||
}
|
||||
else if (crm == 7)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_INVALIDATE_UTLB] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_INVALIDATE_UTLB_SINGLE_ENTRY] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_INVALIDATE_UTLB_ENTRY_ON_ASID_MATCH] = value;
|
||||
else if (opcode_2 == 3)
|
||||
CP15[CP15_INVALIDATE_UTLB_ENTRY_ON_MVA] = value;
|
||||
}
|
||||
}
|
||||
else if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
|
||||
{
|
||||
CP15[CP15_DATA_CACHE_LOCKDOWN] = value;
|
||||
}
|
||||
else if (crn == 10 && opcode_1 == 0)
|
||||
{
|
||||
if (crm == 0 && opcode_2 == 0)
|
||||
{
|
||||
CP15[CP15_TLB_LOCKDOWN] = value;
|
||||
}
|
||||
else if (crm == 2)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_PRIMARY_REGION_REMAP] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_NORMAL_REGION_REMAP] = value;
|
||||
}
|
||||
}
|
||||
else if (crn == 13 && opcode_1 == 0 && crm == 0)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_PID] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_CONTEXT_ID] = value;
|
||||
else if (opcode_2 == 3)
|
||||
CP15[CP15_THREAD_URO] = value;
|
||||
else if (opcode_2 == 4)
|
||||
CP15[CP15_THREAD_PRW] = value;
|
||||
}
|
||||
else if (crn == 15)
|
||||
{
|
||||
if (opcode_1 == 0 && crm == 12)
|
||||
{
|
||||
if (opcode_2 == 0)
|
||||
CP15[CP15_PERFORMANCE_MONITOR_CONTROL] = value;
|
||||
else if (opcode_2 == 1)
|
||||
CP15[CP15_CYCLE_COUNTER] = value;
|
||||
else if (opcode_2 == 2)
|
||||
CP15[CP15_COUNT_0] = value;
|
||||
else if (opcode_2 == 3)
|
||||
CP15[CP15_COUNT_1] = value;
|
||||
}
|
||||
else if (opcode_1 == 5)
|
||||
{
|
||||
if (crm == 4)
|
||||
{
|
||||
if (opcode_2 == 2)
|
||||
CP15[CP15_READ_MAIN_TLB_LOCKDOWN_ENTRY] = value;
|
||||
else if (opcode_2 == 4)
|
||||
CP15[CP15_WRITE_MAIN_TLB_LOCKDOWN_ENTRY] = value;
|
||||
}
|
||||
else if (crm == 5 && opcode_2 == 2)
|
||||
{
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS] = value;
|
||||
}
|
||||
else if (crm == 6 && opcode_2 == 2)
|
||||
{
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS] = value;
|
||||
}
|
||||
else if (crm == 7 && opcode_2 == 2)
|
||||
{
|
||||
CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE] = value;
|
||||
}
|
||||
}
|
||||
else if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
|
||||
{
|
||||
CP15[CP15_TLB_DEBUG_CONTROL] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unprivileged registers
|
||||
if (crn == 7 && opcode_1 == 0 && crm == 5 && opcode_2 == 4)
|
||||
{
|
||||
CP15[CP15_FLUSH_PREFETCH_BUFFER] = value;
|
||||
}
|
||||
else if (crn == 7 && opcode_1 == 0 && crm == 10)
|
||||
{
|
||||
if (opcode_2 == 4)
|
||||
CP15[CP15_DATA_SYNC_BARRIER] = value;
|
||||
else if (opcode_2 == 5)
|
||||
CP15[CP15_DATA_MEMORY_BARRIER] = value;
|
||||
}
|
||||
else if (crn == 13 && opcode_1 == 0 && crm == 0 && opcode_2 == 2)
|
||||
{
|
||||
CP15[CP15_THREAD_UPRW] = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue