arm: Adios armemu
This commit is contained in:
parent
73a7a379d6
commit
f44781fd7b
19 changed files with 166 additions and 8603 deletions
|
@ -1,114 +0,0 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/arm/interpreter/arm_interpreter.h"
|
||||
|
||||
#include "core/core.h"
|
||||
|
||||
const static cpu_config_t arm11_cpu_info = {
|
||||
"armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
|
||||
};
|
||||
|
||||
ARM_Interpreter::ARM_Interpreter() {
|
||||
state = new ARMul_State;
|
||||
|
||||
ARMul_EmulateInit();
|
||||
memset(state, 0, sizeof(ARMul_State));
|
||||
|
||||
ARMul_NewState(state);
|
||||
|
||||
state->abort_model = 0;
|
||||
state->cpu = (cpu_config_t*)&arm11_cpu_info;
|
||||
state->bigendSig = LOW;
|
||||
|
||||
ARMul_SelectProcessor(state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
|
||||
state->lateabtSig = LOW;
|
||||
|
||||
// Reset the core to initial state
|
||||
ARMul_CoProInit(state);
|
||||
ARMul_Reset(state);
|
||||
state->NextInstr = RESUME; // NOTE: This will be overwritten by LoadContext
|
||||
state->Emulate = 3;
|
||||
|
||||
state->pc = state->Reg[15] = 0x00000000;
|
||||
state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
|
||||
state->servaddr = 0xFFFF0000;
|
||||
}
|
||||
|
||||
ARM_Interpreter::~ARM_Interpreter() {
|
||||
delete state;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::SetPC(u32 pc) {
|
||||
state->pc = state->Reg[15] = pc;
|
||||
}
|
||||
|
||||
u32 ARM_Interpreter::GetPC() const {
|
||||
return state->pc;
|
||||
}
|
||||
|
||||
u32 ARM_Interpreter::GetReg(int index) const {
|
||||
return state->Reg[index];
|
||||
}
|
||||
|
||||
void ARM_Interpreter::SetReg(int index, u32 value) {
|
||||
state->Reg[index] = value;
|
||||
}
|
||||
|
||||
u32 ARM_Interpreter::GetCPSR() const {
|
||||
return state->Cpsr;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::SetCPSR(u32 cpsr) {
|
||||
state->Cpsr = cpsr;
|
||||
}
|
||||
|
||||
u64 ARM_Interpreter::GetTicks() const {
|
||||
return state->NumInstrs;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::AddTicks(u64 ticks) {
|
||||
state->NumInstrs += ticks;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::ExecuteInstructions(int num_instructions) {
|
||||
state->NumInstrsToExecute = num_instructions - 1;
|
||||
ARMul_Emulate32(state);
|
||||
}
|
||||
|
||||
void ARM_Interpreter::SaveContext(Core::ThreadContext& ctx) {
|
||||
memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));
|
||||
memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));
|
||||
|
||||
ctx.sp = state->Reg[13];
|
||||
ctx.lr = state->Reg[14];
|
||||
ctx.pc = state->pc;
|
||||
ctx.cpsr = state->Cpsr;
|
||||
|
||||
ctx.fpscr = state->VFP[1];
|
||||
ctx.fpexc = state->VFP[2];
|
||||
|
||||
ctx.reg_15 = state->Reg[15];
|
||||
ctx.mode = state->NextInstr;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::LoadContext(const Core::ThreadContext& ctx) {
|
||||
memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));
|
||||
memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));
|
||||
|
||||
state->Reg[13] = ctx.sp;
|
||||
state->Reg[14] = ctx.lr;
|
||||
state->pc = ctx.pc;
|
||||
state->Cpsr = ctx.cpsr;
|
||||
|
||||
state->VFP[1] = ctx.fpscr;
|
||||
state->VFP[2] = ctx.fpexc;
|
||||
|
||||
state->Reg[15] = ctx.reg_15;
|
||||
state->NextInstr = ctx.mode;
|
||||
}
|
||||
|
||||
void ARM_Interpreter::PrepareReschedule() {
|
||||
state->NumInstrsToExecute = 0;
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common.h"
|
||||
|
||||
#include "core/arm/arm_interface.h"
|
||||
#include "core/arm/skyeye_common/armdefs.h"
|
||||
#include "core/arm/skyeye_common/armemu.h"
|
||||
|
||||
class ARM_Interpreter final : virtual public ARM_Interface {
|
||||
public:
|
||||
|
||||
ARM_Interpreter();
|
||||
~ARM_Interpreter();
|
||||
|
||||
/**
|
||||
* Set the Program Counter to an address
|
||||
* @param pc Address to set PC to
|
||||
*/
|
||||
void SetPC(u32 pc) override;
|
||||
|
||||
/*
|
||||
* Get the current Program Counter
|
||||
* @return Returns current PC
|
||||
*/
|
||||
u32 GetPC() const override;
|
||||
|
||||
/**
|
||||
* Get an ARM register
|
||||
* @param index Register index (0-15)
|
||||
* @return Returns the value in the register
|
||||
*/
|
||||
u32 GetReg(int index) const override;
|
||||
|
||||
/**
|
||||
* Set an ARM register
|
||||
* @param index Register index (0-15)
|
||||
* @param value Value to set register to
|
||||
*/
|
||||
void SetReg(int index, u32 value) override;
|
||||
|
||||
/**
|
||||
* Get the current CPSR register
|
||||
* @return Returns the value of the CPSR register
|
||||
*/
|
||||
u32 GetCPSR() const override;
|
||||
|
||||
/**
|
||||
* Set the current CPSR register
|
||||
* @param cpsr Value to set CPSR to
|
||||
*/
|
||||
void SetCPSR(u32 cpsr) override;
|
||||
|
||||
/**
|
||||
* Returns the number of clock ticks since the last reset
|
||||
* @return Returns number of clock ticks
|
||||
*/
|
||||
u64 GetTicks() const override;
|
||||
|
||||
/**
|
||||
* Advance the CPU core by the specified number of ticks (e.g. to simulate CPU execution time)
|
||||
* @param ticks Number of ticks to advance the CPU core
|
||||
*/
|
||||
void AddTicks(u64 ticks) override;
|
||||
|
||||
/**
|
||||
* Saves the current CPU context
|
||||
* @param ctx Thread context to save
|
||||
*/
|
||||
void SaveContext(Core::ThreadContext& ctx) override;
|
||||
|
||||
/**
|
||||
* Loads a CPU context
|
||||
* @param ctx Thread context to load
|
||||
*/
|
||||
void LoadContext(const Core::ThreadContext& ctx) override;
|
||||
|
||||
/// Prepare core for thread reschedule (if needed to correctly handle state)
|
||||
void PrepareReschedule() override;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Executes the given number of instructions
|
||||
* @param num_instructions Number of instructions to executes
|
||||
*/
|
||||
void ExecuteInstructions(int num_instructions) override;
|
||||
|
||||
private:
|
||||
|
||||
ARMul_State* state;
|
||||
|
||||
};
|
|
@ -19,213 +19,45 @@
|
|||
#include "core/arm/skyeye_common/armemu.h"
|
||||
#include "core/arm/skyeye_common/vfp/vfp.h"
|
||||
|
||||
//chy 2005-07-08
|
||||
//#include "ansidecl.h"
|
||||
//chy -------
|
||||
//#include "iwmmxt.h"
|
||||
// Dummy Co-processors.
|
||||
|
||||
/* Dummy Co-processors. */
|
||||
|
||||
static unsigned
|
||||
NoCoPro3R(ARMul_State * state,
|
||||
unsigned a, ARMword b)
|
||||
static unsigned int NoCoPro3R(ARMul_State* state, unsigned int a, ARMword b)
|
||||
{
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
NoCoPro4R(ARMul_State * state,
|
||||
unsigned a,
|
||||
ARMword b, ARMword c)
|
||||
static unsigned int NoCoPro4R(ARMul_State* state, unsigned int a, ARMword b, ARMword c)
|
||||
{
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
NoCoPro4W(ARMul_State * state,
|
||||
unsigned a,
|
||||
ARMword b, ARMword * c)
|
||||
static unsigned int NoCoPro4W(ARMul_State* state, unsigned int a, ARMword b, ARMword* c)
|
||||
{
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
NoCoPro5R(ARMul_State * state,
|
||||
unsigned a,
|
||||
ARMword b,
|
||||
ARMword c, ARMword d)
|
||||
static unsigned int NoCoPro5R(ARMul_State* state, unsigned int a, ARMword b, ARMword c, ARMword d)
|
||||
{
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
NoCoPro5W(ARMul_State * state,
|
||||
unsigned a,
|
||||
ARMword b,
|
||||
ARMword * c, ARMword * d)
|
||||
static unsigned int NoCoPro5W(ARMul_State* state, unsigned int a, ARMword b, ARMword* c, ARMword* d)
|
||||
{
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
/* The XScale Co-processors. */
|
||||
|
||||
/* Coprocessor 15: System Control. */
|
||||
static void write_cp14_reg(unsigned, ARMword);
|
||||
static ARMword read_cp14_reg(unsigned);
|
||||
|
||||
/* Check an access to a register. */
|
||||
|
||||
static unsigned
|
||||
check_cp15_access(ARMul_State * state,
|
||||
unsigned reg,
|
||||
unsigned CRm, unsigned opcode_1, unsigned opcode_2)
|
||||
// Install co-processor instruction handlers in this routine.
|
||||
unsigned int ARMul_CoProInit(ARMul_State* state)
|
||||
{
|
||||
/* Do not allow access to these register in USER mode. */
|
||||
//chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
|
||||
if (state->Mode == USER26MODE || state->Mode == USER32MODE)
|
||||
return ARMul_CANT;
|
||||
|
||||
/* Opcode_1should be zero. */
|
||||
if (opcode_1 != 0)
|
||||
return ARMul_CANT;
|
||||
|
||||
/* Different register have different access requirements. */
|
||||
switch (reg) {
|
||||
case 0:
|
||||
case 1:
|
||||
/* CRm must be 0. Opcode_2 can be anything. */
|
||||
if (CRm != 0)
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
/* CRm must be 0. Opcode_2 must be zero. */
|
||||
if ((CRm != 0) || (opcode_2 != 0))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 4:
|
||||
/* Access not allowed. */
|
||||
return ARMul_CANT;
|
||||
case 5:
|
||||
case 6:
|
||||
/* Opcode_2 must be zero. CRm must be 0. */
|
||||
if ((CRm != 0) || (opcode_2 != 0))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 7:
|
||||
/* Permissable combinations:
|
||||
Opcode_2 CRm
|
||||
0 5
|
||||
0 6
|
||||
0 7
|
||||
1 5
|
||||
1 6
|
||||
1 10
|
||||
4 10
|
||||
5 2
|
||||
6 5 */
|
||||
switch (opcode_2) {
|
||||
default:
|
||||
return ARMul_CANT;
|
||||
case 6:
|
||||
if (CRm != 5)
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 5:
|
||||
if (CRm != 2)
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 4:
|
||||
if (CRm != 10)
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 1:
|
||||
if ((CRm != 5) && (CRm != 6) && (CRm != 10))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 0:
|
||||
if ((CRm < 5) || (CRm > 7))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 8:
|
||||
/* Permissable combinations:
|
||||
Opcode_2 CRm
|
||||
0 5
|
||||
0 6
|
||||
0 7
|
||||
1 5
|
||||
1 6 */
|
||||
if (opcode_2 > 1)
|
||||
return ARMul_CANT;
|
||||
if ((CRm < 5) || (CRm > 7))
|
||||
return ARMul_CANT;
|
||||
if (opcode_2 == 1 && CRm == 7)
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 9:
|
||||
/* Opcode_2 must be zero or one. CRm must be 1 or 2. */
|
||||
if (((CRm != 0) && (CRm != 1))
|
||||
|| ((opcode_2 != 1) && (opcode_2 != 2)))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 10:
|
||||
/* Opcode_2 must be zero or one. CRm must be 4 or 8. */
|
||||
if (((CRm != 0) && (CRm != 1))
|
||||
|| ((opcode_2 != 4) && (opcode_2 != 8)))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 11:
|
||||
/* Access not allowed. */
|
||||
return ARMul_CANT;
|
||||
case 12:
|
||||
/* Access not allowed. */
|
||||
return ARMul_CANT;
|
||||
case 13:
|
||||
/* Opcode_2 must be zero. CRm must be 0. */
|
||||
if ((CRm != 0) || (opcode_2 != 0))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 14:
|
||||
/* Opcode_2 must be 0. CRm must be 0, 3, 4, 8 or 9. */
|
||||
if (opcode_2 != 0)
|
||||
return ARMul_CANT;
|
||||
|
||||
if ((CRm != 0) && (CRm != 3) && (CRm != 4) && (CRm != 8)
|
||||
&& (CRm != 9))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
case 15:
|
||||
/* Opcode_2 must be zero. CRm must be 1. */
|
||||
if ((CRm != 1) || (opcode_2 != 0))
|
||||
return ARMul_CANT;
|
||||
break;
|
||||
default:
|
||||
/* Should never happen. */
|
||||
return ARMul_CANT;
|
||||
}
|
||||
|
||||
return ARMul_DONE;
|
||||
}
|
||||
|
||||
/* Install co-processor instruction handlers in this routine. */
|
||||
|
||||
unsigned
|
||||
ARMul_CoProInit(ARMul_State * state)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/* Initialise tham all first. */
|
||||
for (i = 0; i < 16; i++)
|
||||
// Initialise tham all first.
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
ARMul_CoProDetach(state, i);
|
||||
|
||||
/* Install CoPro Instruction handlers here.
|
||||
The format is:
|
||||
ARMul_CoProAttach (state, CP Number, Init routine, Exit routine
|
||||
LDC routine, STC routine, MRC routine, MCR routine,
|
||||
CDP routine, Read Reg routine, Write Reg routine). */
|
||||
// Install CoPro Instruction handlers here.
|
||||
// The format is:
|
||||
// ARMul_CoProAttach (state, CP Number, Init routine, Exit routine
|
||||
// LDC routine, STC routine, MRC routine, MCR routine,
|
||||
// CDP routine, Read Reg routine, Write Reg routine).
|
||||
if (state->is_v6) {
|
||||
ARMul_CoProAttach(state, 10, VFPInit, NULL, VFPLDC, VFPSTC,
|
||||
VFPMRC, VFPMCR, VFPMRRC, VFPMCRR, VFPCDP, NULL, NULL);
|
||||
|
@ -235,57 +67,44 @@ ARMul_CoProInit(ARMul_State * state)
|
|||
/*ARMul_CoProAttach (state, 15, MMUInit, NULL, NULL, NULL,
|
||||
MMUMRC, MMUMCR, NULL, NULL, NULL, NULL, NULL);*/
|
||||
}
|
||||
//chy 2003-09-03 do it in future!!!!????
|
||||
#if 0
|
||||
if (state->is_iWMMXt) {
|
||||
ARMul_CoProAttach(state, 0, NULL, NULL, IwmmxtLDC, IwmmxtSTC,
|
||||
NULL, NULL, IwmmxtCDP, NULL, NULL);
|
||||
|
||||
ARMul_CoProAttach(state, 1, NULL, NULL, NULL, NULL,
|
||||
IwmmxtMRC, IwmmxtMCR, IwmmxtCDP, NULL,
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
/* No handlers below here. */
|
||||
// No handlers below here.
|
||||
|
||||
/* Call all the initialisation routines. */
|
||||
for (i = 0; i < 16; i++)
|
||||
// Call all the initialisation routines.
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
if (state->CPInit[i])
|
||||
(state->CPInit[i]) (state);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Install co-processor finalisation routines in this routine. */
|
||||
|
||||
void
|
||||
ARMul_CoProExit(ARMul_State * state)
|
||||
// Install co-processor finalisation routines in this routine.
|
||||
void ARMul_CoProExit(ARMul_State * state)
|
||||
{
|
||||
register unsigned i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
if (state->CPExit[i])
|
||||
(state->CPExit[i]) (state);
|
||||
|
||||
for (i = 0; i < 16; i++) /* Detach all handlers. */
|
||||
// Detach all handlers.
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
ARMul_CoProDetach(state, i);
|
||||
}
|
||||
|
||||
/* Routines to hook Co-processors into ARMulator. */
|
||||
// Routines to hook Co-processors into ARMulator.
|
||||
|
||||
void
|
||||
ARMul_CoProAttach(ARMul_State * state,
|
||||
ARMul_CoProAttach(ARMul_State* state,
|
||||
unsigned number,
|
||||
ARMul_CPInits * init,
|
||||
ARMul_CPExits * exit,
|
||||
ARMul_LDCs * ldc,
|
||||
ARMul_STCs * stc,
|
||||
ARMul_MRCs * mrc,
|
||||
ARMul_MCRs * mcr,
|
||||
ARMul_MRRCs * mrrc,
|
||||
ARMul_MCRRs * mcrr,
|
||||
ARMul_CDPs * cdp,
|
||||
ARMul_CPReads * read, ARMul_CPWrites * write)
|
||||
ARMul_CPInits* init,
|
||||
ARMul_CPExits* exit,
|
||||
ARMul_LDCs* ldc,
|
||||
ARMul_STCs* stc,
|
||||
ARMul_MRCs* mrc,
|
||||
ARMul_MCRs* mcr,
|
||||
ARMul_MRRCs* mrrc,
|
||||
ARMul_MCRRs* mcrr,
|
||||
ARMul_CDPs* cdp,
|
||||
ARMul_CPReads* read, ARMul_CPWrites* write)
|
||||
{
|
||||
if (init != NULL)
|
||||
state->CPInit[number] = init;
|
||||
|
@ -311,8 +130,7 @@ ARMul_CPReads * read, ARMul_CPWrites * write)
|
|||
state->CPWrite[number] = write;
|
||||
}
|
||||
|
||||
void
|
||||
ARMul_CoProDetach(ARMul_State * state, unsigned number)
|
||||
void ARMul_CoProDetach(ARMul_State* state, unsigned number)
|
||||
{
|
||||
ARMul_CoProAttach(state, number, NULL, NULL,
|
||||
NoCoPro4R, NoCoPro4W, NoCoPro4W, NoCoPro4R,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,24 +25,13 @@
|
|||
void ARMul_EmulateInit();
|
||||
ARMul_State* ARMul_NewState(ARMul_State* state);
|
||||
void ARMul_Reset (ARMul_State* state);
|
||||
ARMword ARMul_DoCycle(ARMul_State* state);
|
||||
unsigned ARMul_DoCoPro(ARMul_State* state);
|
||||
ARMword ARMul_DoProg(ARMul_State* state);
|
||||
ARMword ARMul_DoInstr(ARMul_State* state);
|
||||
void ARMul_Abort(ARMul_State* state, ARMword address);
|
||||
|
||||
unsigned ARMul_MultTable[32] = {
|
||||
1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
||||
10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16
|
||||
};
|
||||
ARMword ARMul_ImmedTable[4096]; /* immediate DP LHS values */
|
||||
char ARMul_BitList[256]; /* number of bits in a byte table */
|
||||
|
||||
void arm_dyncom_Abort(ARMul_State * state, ARMword vector)
|
||||
{
|
||||
ARMul_Abort(state, vector);
|
||||
}
|
||||
|
||||
ARMword ARMul_ImmedTable[4096]; // immediate DP LHS values
|
||||
char ARMul_BitList[256]; // number of bits in a byte table
|
||||
|
||||
/***************************************************************************\
|
||||
* Call this routine once to set up the emulator's tables. *
|
||||
|
@ -51,18 +40,21 @@ void ARMul_EmulateInit()
|
|||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0; i < 4096; i++) { /* the values of 12 bit dp rhs's */
|
||||
// the values of 12 bit dp rhs's
|
||||
for (i = 0; i < 4096; i++) {
|
||||
ARMul_ImmedTable[i] = ROTATER (i & 0xffL, (i >> 7L) & 0x1eL);
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; ARMul_BitList[i++] = 0); /* how many bits in LSM */
|
||||
// how many bits in LSM
|
||||
for (i = 0; i < 256; ARMul_BitList[i++] = 0);
|
||||
for (j = 1; j < 256; j <<= 1)
|
||||
for (i = 0; i < 256; i++)
|
||||
if ((i & j) > 0)
|
||||
ARMul_BitList[i]++;
|
||||
|
||||
// you always need 4 times these values
|
||||
for (i = 0; i < 256; i++)
|
||||
ARMul_BitList[i] *= 4; /* you always need 4 times these values */
|
||||
ARMul_BitList[i] *= 4;
|
||||
|
||||
}
|
||||
|
||||
|
@ -178,115 +170,3 @@ void ARMul_Reset(ARMul_State* state)
|
|||
state->NumCcycles = 0;
|
||||
state->NumFcycles = 0;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************\
|
||||
* Emulate the execution of an entire program. Start the correct emulator *
|
||||
* (Emulate26 for a 26 bit ARM and Emulate32 for a 32 bit ARM), return the *
|
||||
* address of the last instruction that is executed. *
|
||||
\***************************************************************************/
|
||||
ARMword ARMul_DoProg(ARMul_State* state)
|
||||
{
|
||||
ARMword pc = 0;
|
||||
|
||||
state->Emulate = RUN;
|
||||
while (state->Emulate != STOP) {
|
||||
state->Emulate = RUN;
|
||||
|
||||
if (state->prog32Sig && ARMul_MODE32BIT) {
|
||||
pc = ARMul_Emulate32 (state);
|
||||
}
|
||||
else {
|
||||
//pc = ARMul_Emulate26 (state);
|
||||
}
|
||||
}
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
/***************************************************************************\
|
||||
* Emulate the execution of one instruction. Start the correct emulator *
|
||||
* (Emulate26 for a 26 bit ARM and Emulate32 for a 32 bit ARM), return the *
|
||||
* address of the instruction that is executed. *
|
||||
\***************************************************************************/
|
||||
ARMword ARMul_DoInstr(ARMul_State* state)
|
||||
{
|
||||
ARMword pc = 0;
|
||||
|
||||
state->Emulate = ONCE;
|
||||
|
||||
if (state->prog32Sig && ARMul_MODE32BIT) {
|
||||
pc = ARMul_Emulate32 (state);
|
||||
}
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
/***************************************************************************\
|
||||
* This routine causes an Abort to occur, including selecting the correct *
|
||||
* mode, register bank, and the saving of registers. Call with the *
|
||||
* appropriate vector's memory address (0,4,8 ....) *
|
||||
\***************************************************************************/
|
||||
void ARMul_Abort(ARMul_State* state, ARMword vector)
|
||||
{
|
||||
ARMword temp;
|
||||
int isize = INSN_SIZE;
|
||||
int esize = (TFLAG ? 0 : 4);
|
||||
int e2size = (TFLAG ? -4 : 0);
|
||||
|
||||
state->Aborted = FALSE;
|
||||
|
||||
if (state->prog32Sig)
|
||||
if (ARMul_MODE26BIT)
|
||||
temp = R15PC;
|
||||
else
|
||||
temp = state->Reg[15];
|
||||
else
|
||||
temp = R15PC | ECC | ER15INT | EMODE;
|
||||
|
||||
switch (vector) {
|
||||
case ARMul_ResetV: /* RESET */
|
||||
SETABORT (INTBITS, state->prog32Sig ? SVC32MODE : SVC26MODE,
|
||||
0);
|
||||
break;
|
||||
case ARMul_UndefinedInstrV: /* Undefined Instruction */
|
||||
SETABORT (IBIT, state->prog32Sig ? UNDEF32MODE : SVC26MODE,
|
||||
isize);
|
||||
break;
|
||||
case ARMul_SWIV: /* Software Interrupt */
|
||||
SETABORT (IBIT, state->prog32Sig ? SVC32MODE : SVC26MODE,
|
||||
isize);
|
||||
break;
|
||||
case ARMul_PrefetchAbortV: /* Prefetch Abort */
|
||||
state->AbortAddr = 1;
|
||||
SETABORT (IBIT, state->prog32Sig ? ABORT32MODE : SVC26MODE,
|
||||
esize);
|
||||
break;
|
||||
case ARMul_DataAbortV: /* Data Abort */
|
||||
SETABORT (IBIT, state->prog32Sig ? ABORT32MODE : SVC26MODE,
|
||||
e2size);
|
||||
break;
|
||||
case ARMul_AddrExceptnV: /* Address Exception */
|
||||
SETABORT (IBIT, SVC26MODE, isize);
|
||||
break;
|
||||
case ARMul_IRQV: /* IRQ */
|
||||
SETABORT (IBIT,
|
||||
state->prog32Sig ? IRQ32MODE : IRQ26MODE,
|
||||
esize);
|
||||
break;
|
||||
case ARMul_FIQV: /* FIQ */
|
||||
SETABORT (INTBITS,
|
||||
state->prog32Sig ? FIQ32MODE : FIQ26MODE,
|
||||
esize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ARMul_MODE32BIT) {
|
||||
/*if (state->mmu.control & CONTROL_VECTOR)
|
||||
vector += 0xffff0000; //for v4 high exception address*/
|
||||
if (state->vector_remap_flag)
|
||||
vector += state->vector_remap_addr; /* support some remap function in LPC processor */
|
||||
ARMul_SetR15 (state, vector);
|
||||
} else
|
||||
ARMul_SetR15 (state, R15CCINTMODE | vector);
|
||||
}
|
||||
|
|
|
@ -20,395 +20,13 @@
|
|||
#include "core/arm/disassembler/arm_disasm.h"
|
||||
#include "core/mem_map.h"
|
||||
|
||||
|
||||
static ARMword ModeToBank (ARMword);
|
||||
|
||||
/* This routine returns the value of a register from a mode. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetReg (ARMul_State * state, unsigned mode, unsigned reg)
|
||||
{
|
||||
mode &= MODEBITS;
|
||||
if (mode != state->Mode)
|
||||
return (state->RegBank[ModeToBank ((ARMword) mode)][reg]);
|
||||
else
|
||||
return (state->Reg[reg]);
|
||||
}
|
||||
|
||||
/* This routine sets the value of a register for a mode. */
|
||||
|
||||
void
|
||||
ARMul_SetReg (ARMul_State * state, unsigned mode, unsigned reg, ARMword value)
|
||||
{
|
||||
mode &= MODEBITS;
|
||||
if (mode != state->Mode)
|
||||
state->RegBank[ModeToBank ((ARMword) mode)][reg] = value;
|
||||
else
|
||||
state->Reg[reg] = value;
|
||||
}
|
||||
|
||||
/* This routine returns the value of the PC, mode independently. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetPC (ARMul_State * state)
|
||||
{
|
||||
if (state->Mode > SVC26MODE)
|
||||
return state->Reg[15];
|
||||
else
|
||||
return R15PC;
|
||||
}
|
||||
|
||||
/* This routine returns the value of the PC, mode independently. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetNextPC (ARMul_State * state)
|
||||
{
|
||||
if (state->Mode > SVC26MODE)
|
||||
return state->Reg[15] + INSN_SIZE;
|
||||
else
|
||||
return (state->Reg[15] + INSN_SIZE) & R15PCBITS;
|
||||
}
|
||||
|
||||
/* This routine sets the value of the PC. */
|
||||
|
||||
void
|
||||
ARMul_SetPC (ARMul_State * state, ARMword value)
|
||||
{
|
||||
if (ARMul_MODE32BIT)
|
||||
state->Reg[15] = value & PCBITS;
|
||||
else
|
||||
state->Reg[15] = R15CCINTMODE | (value & R15PCBITS);
|
||||
FLUSHPIPE;
|
||||
}
|
||||
|
||||
/* This routine returns the value of register 15, mode independently. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetR15 (ARMul_State * state)
|
||||
{
|
||||
if (state->Mode > SVC26MODE)
|
||||
return (state->Reg[15]);
|
||||
else
|
||||
return (R15PC | ECC | ER15INT | EMODE);
|
||||
}
|
||||
|
||||
/* This routine sets the value of Register 15. */
|
||||
|
||||
void
|
||||
ARMul_SetR15 (ARMul_State * state, ARMword value)
|
||||
{
|
||||
if (ARMul_MODE32BIT)
|
||||
state->Reg[15] = value & PCBITS;
|
||||
else {
|
||||
state->Reg[15] = value;
|
||||
ARMul_R15Altered (state);
|
||||
}
|
||||
FLUSHPIPE;
|
||||
}
|
||||
|
||||
/* This routine returns the value of the CPSR. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetCPSR (ARMul_State * state)
|
||||
{
|
||||
//chy 2003-08-20: below is from gdb20030716, maybe isn't suitable for system simulator
|
||||
//return (CPSR | state->Cpsr); for gdb20030716
|
||||
return (CPSR); //had be tested in old skyeye with gdb5.0-5.3
|
||||
}
|
||||
|
||||
/* This routine sets the value of the CPSR. */
|
||||
|
||||
void
|
||||
ARMul_SetCPSR (ARMul_State * state, ARMword value)
|
||||
{
|
||||
state->Cpsr = value;
|
||||
ARMul_CPSRAltered (state);
|
||||
}
|
||||
|
||||
/* This routine does all the nasty bits involved in a write to the CPSR,
|
||||
including updating the register bank, given a MSR instruction. */
|
||||
|
||||
void
|
||||
ARMul_FixCPSR (ARMul_State * state, ARMword instr, ARMword rhs)
|
||||
{
|
||||
state->Cpsr = ARMul_GetCPSR (state);
|
||||
//chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
|
||||
if (state->Mode != USER26MODE && state->Mode != USER32MODE ) {
|
||||
/* In user mode, only write flags. */
|
||||
if (BIT (16))
|
||||
SETPSR_C (state->Cpsr, rhs);
|
||||
if (BIT (17))
|
||||
SETPSR_X (state->Cpsr, rhs);
|
||||
if (BIT (18))
|
||||
SETPSR_S (state->Cpsr, rhs);
|
||||
}
|
||||
if (BIT (19))
|
||||
SETPSR_F (state->Cpsr, rhs);
|
||||
ARMul_CPSRAltered (state);
|
||||
}
|
||||
|
||||
/* Get an SPSR from the specified mode. */
|
||||
|
||||
ARMword
|
||||
ARMul_GetSPSR (ARMul_State * state, ARMword mode)
|
||||
{
|
||||
ARMword bank = ModeToBank (mode & MODEBITS);
|
||||
|
||||
if (!BANK_CAN_ACCESS_SPSR (bank))
|
||||
return ARMul_GetCPSR (state);
|
||||
|
||||
return state->Spsr[bank];
|
||||
}
|
||||
|
||||
/* This routine does a write to an SPSR. */
|
||||
|
||||
void
|
||||
ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value)
|
||||
{
|
||||
ARMword bank = ModeToBank (mode & MODEBITS);
|
||||
|
||||
if (BANK_CAN_ACCESS_SPSR (bank))
|
||||
state->Spsr[bank] = value;
|
||||
}
|
||||
|
||||
/* This routine does a write to the current SPSR, given an MSR instruction. */
|
||||
|
||||
void
|
||||
ARMul_FixSPSR (ARMul_State * state, ARMword instr, ARMword rhs)
|
||||
{
|
||||
if (BANK_CAN_ACCESS_SPSR (state->Bank)) {
|
||||
if (BIT (16))
|
||||
SETPSR_C (state->Spsr[state->Bank], rhs);
|
||||
if (BIT (17))
|
||||
SETPSR_X (state->Spsr[state->Bank], rhs);
|
||||
if (BIT (18))
|
||||
SETPSR_S (state->Spsr[state->Bank], rhs);
|
||||
if (BIT (19))
|
||||
SETPSR_F (state->Spsr[state->Bank], rhs);
|
||||
}
|
||||
}
|
||||
|
||||
/* This routine updates the state of the emulator after the Cpsr has been
|
||||
changed. Both the processor flags and register bank are updated. */
|
||||
|
||||
void
|
||||
ARMul_CPSRAltered (ARMul_State * state)
|
||||
{
|
||||
ARMword oldmode;
|
||||
|
||||
if (state->prog32Sig == LOW)
|
||||
state->Cpsr &= (CCBITS | INTBITS | R15MODEBITS);
|
||||
|
||||
oldmode = state->Mode;
|
||||
|
||||
/*if (state->Mode != (state->Cpsr & MODEBITS)) {
|
||||
state->Mode =
|
||||
ARMul_SwitchMode (state, state->Mode,
|
||||
state->Cpsr & MODEBITS);
|
||||
|
||||
state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
|
||||
}*/
|
||||
//state->Cpsr &= ~MODEBITS;
|
||||
|
||||
ASSIGNINT (state->Cpsr & INTBITS);
|
||||
//state->Cpsr &= ~INTBITS;
|
||||
ASSIGNN ((state->Cpsr & NBIT) != 0);
|
||||
//state->Cpsr &= ~NBIT;
|
||||
ASSIGNZ ((state->Cpsr & ZBIT) != 0);
|
||||
//state->Cpsr &= ~ZBIT;
|
||||
ASSIGNC ((state->Cpsr & CBIT) != 0);
|
||||
//state->Cpsr &= ~CBIT;
|
||||
ASSIGNV ((state->Cpsr & VBIT) != 0);
|
||||
//state->Cpsr &= ~VBIT;
|
||||
ASSIGNQ ((state->Cpsr & QBIT) != 0);
|
||||
//state->Cpsr &= ~QBIT;
|
||||
state->GEFlag = (state->Cpsr & 0x000F0000);
|
||||
#ifdef MODET
|
||||
ASSIGNT ((state->Cpsr & TBIT) != 0);
|
||||
//state->Cpsr &= ~TBIT;
|
||||
#endif
|
||||
|
||||
if (oldmode > SVC26MODE) {
|
||||
if (state->Mode <= SVC26MODE) {
|
||||
state->Emulate = CHANGEMODE;
|
||||
state->Reg[15] = ECC | ER15INT | EMODE | R15PC;
|
||||
}
|
||||
} else {
|
||||
if (state->Mode > SVC26MODE) {
|
||||
state->Emulate = CHANGEMODE;
|
||||
state->Reg[15] = R15PC;
|
||||
} else
|
||||
state->Reg[15] = ECC | ER15INT | EMODE | R15PC;
|
||||
}
|
||||
}
|
||||
|
||||
/* This routine updates the state of the emulator after register 15 has
|
||||
been changed. Both the processor flags and register bank are updated.
|
||||
This routine should only be called from a 26 bit mode. */
|
||||
|
||||
void
|
||||
ARMul_R15Altered (ARMul_State * state)
|
||||
{
|
||||
if (state->Mode != R15MODE) {
|
||||
state->Mode = ARMul_SwitchMode (state, state->Mode, R15MODE);
|
||||
state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
|
||||
}
|
||||
|
||||
if (state->Mode > SVC26MODE)
|
||||
state->Emulate = CHANGEMODE;
|
||||
|
||||
ASSIGNR15INT (R15INT);
|
||||
|
||||
ASSIGNN ((state->Reg[15] & NBIT) != 0);
|
||||
ASSIGNZ ((state->Reg[15] & ZBIT) != 0);
|
||||
ASSIGNC ((state->Reg[15] & CBIT) != 0);
|
||||
ASSIGNV ((state->Reg[15] & VBIT) != 0);
|
||||
}
|
||||
|
||||
/* This routine controls the saving and restoring of registers across mode
|
||||
changes. The regbank matrix is largely unused, only rows 13 and 14 are
|
||||
used across all modes, 8 to 14 are used for FIQ, all others use the USER
|
||||
column. It's easier this way. old and new parameter are modes numbers.
|
||||
Notice the side effect of changing the Bank variable. */
|
||||
|
||||
ARMword
|
||||
ARMul_SwitchMode (ARMul_State * state, ARMword oldmode, ARMword newmode)
|
||||
{
|
||||
unsigned i;
|
||||
ARMword oldbank;
|
||||
ARMword newbank;
|
||||
static int revision_value = 53;
|
||||
|
||||
oldbank = ModeToBank (oldmode);
|
||||
newbank = state->Bank = ModeToBank (newmode);
|
||||
|
||||
/* Do we really need to do it? */
|
||||
if (oldbank != newbank) {
|
||||
if (oldbank == 3 && newbank == 2) {
|
||||
//printf("icounter is %d PC is %x MODE CHANGED : %d --> %d\n", state->NumInstrs, state->pc, oldbank, newbank);
|
||||
if (state->NumInstrs >= 5832487) {
|
||||
// printf("%d, ", state->NumInstrs + revision_value);
|
||||
// printf("revision_value : %d\n", revision_value);
|
||||
revision_value ++;
|
||||
}
|
||||
}
|
||||
/* Save away the old registers. */
|
||||
switch (oldbank) {
|
||||
case USERBANK:
|
||||
case IRQBANK:
|
||||
case SVCBANK:
|
||||
case ABORTBANK:
|
||||
case UNDEFBANK:
|
||||
if (newbank == FIQBANK)
|
||||
for (i = 8; i < 13; i++)
|
||||
state->RegBank[USERBANK][i] =
|
||||
state->Reg[i];
|
||||
state->RegBank[oldbank][13] = state->Reg[13];
|
||||
state->RegBank[oldbank][14] = state->Reg[14];
|
||||
break;
|
||||
case FIQBANK:
|
||||
for (i = 8; i < 15; i++)
|
||||
state->RegBank[FIQBANK][i] = state->Reg[i];
|
||||
break;
|
||||
case DUMMYBANK:
|
||||
for (i = 8; i < 15; i++)
|
||||
state->RegBank[DUMMYBANK][i] = 0;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
/* Restore the new registers. */
|
||||
switch (newbank) {
|
||||
case USERBANK:
|
||||
case IRQBANK:
|
||||
case SVCBANK:
|
||||
case ABORTBANK:
|
||||
case UNDEFBANK:
|
||||
if (oldbank == FIQBANK)
|
||||
for (i = 8; i < 13; i++)
|
||||
state->Reg[i] =
|
||||
state->RegBank[USERBANK][i];
|
||||
state->Reg[13] = state->RegBank[newbank][13];
|
||||
state->Reg[14] = state->RegBank[newbank][14];
|
||||
break;
|
||||
case FIQBANK:
|
||||
for (i = 8; i < 15; i++)
|
||||
state->Reg[i] = state->RegBank[FIQBANK][i];
|
||||
break;
|
||||
case DUMMYBANK:
|
||||
for (i = 8; i < 15; i++)
|
||||
state->Reg[i] = 0;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
return newmode;
|
||||
}
|
||||
|
||||
/* Given a processor mode, this routine returns the
|
||||
register bank that will be accessed in that mode. */
|
||||
|
||||
static ARMword
|
||||
ModeToBank (ARMword mode)
|
||||
{
|
||||
static ARMword bankofmode[] = {
|
||||
USERBANK, FIQBANK, IRQBANK, SVCBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
||||
USERBANK, FIQBANK, IRQBANK, SVCBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, ABORTBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, UNDEFBANK,
|
||||
DUMMYBANK, DUMMYBANK, DUMMYBANK, SYSTEMBANK
|
||||
};
|
||||
|
||||
if (mode >= (sizeof (bankofmode) / sizeof (bankofmode[0])))
|
||||
return DUMMYBANK;
|
||||
|
||||
return bankofmode[mode];
|
||||
}
|
||||
|
||||
/* Returns the register number of the nth register in a reg list. */
|
||||
|
||||
unsigned
|
||||
ARMul_NthReg (ARMword instr, unsigned number)
|
||||
{
|
||||
unsigned bit, upto;
|
||||
|
||||
for (bit = 0, upto = 0; upto <= number; bit++)
|
||||
if (BIT (bit))
|
||||
upto++;
|
||||
|
||||
return (bit - 1);
|
||||
}
|
||||
|
||||
/* Unsigned sum of absolute difference */
|
||||
// Unsigned sum of absolute difference
|
||||
u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right)
|
||||
{
|
||||
if (left > right)
|
||||
return left - right;
|
||||
if (left > right)
|
||||
return left - right;
|
||||
|
||||
return right - left;
|
||||
}
|
||||
|
||||
/* Assigns the N and Z flags depending on the value of result. */
|
||||
|
||||
void
|
||||
ARMul_NegZero (ARMul_State * state, ARMword result)
|
||||
{
|
||||
if (NEG (result)) {
|
||||
SETN;
|
||||
CLEARZ;
|
||||
} else if (result == 0) {
|
||||
CLEARN;
|
||||
SETZ;
|
||||
} else {
|
||||
CLEARN;
|
||||
CLEARZ;
|
||||
}
|
||||
return right - left;
|
||||
}
|
||||
|
||||
// Add with carry, indicates if a carry-out or signed overflow occurred.
|
||||
|
@ -441,23 +59,6 @@ bool SubOverflow(ARMword a, ARMword b, ARMword result)
|
|||
(POS(a) && NEG(b) && NEG(result)));
|
||||
}
|
||||
|
||||
/* Assigns the C flag after an addition of a and b to give result. */
|
||||
|
||||
void
|
||||
ARMul_AddCarry (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
||||
{
|
||||
ASSIGNC ((NEG (a) && NEG (b)) ||
|
||||
(NEG (a) && POS (result)) || (NEG (b) && POS (result)));
|
||||
}
|
||||
|
||||
/* Assigns the V flag after an addition of a and b to give result. */
|
||||
|
||||
void
|
||||
ARMul_AddOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
||||
{
|
||||
ASSIGNV (AddOverflow (a, b, result));
|
||||
}
|
||||
|
||||
// Returns true if the Q flag should be set as a result of overflow.
|
||||
bool ARMul_AddOverflowQ(ARMword a, ARMword b)
|
||||
{
|
||||
|
@ -468,24 +69,7 @@ bool ARMul_AddOverflowQ(ARMword a, ARMword b)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Assigns the C flag after an subtraction of a and b to give result. */
|
||||
|
||||
void
|
||||
ARMul_SubCarry (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
||||
{
|
||||
ASSIGNC ((NEG (a) && POS (b)) ||
|
||||
(NEG (a) && POS (result)) || (POS (b) && POS (result)));
|
||||
}
|
||||
|
||||
/* Assigns the V flag after an subtraction of a and b to give result. */
|
||||
|
||||
void
|
||||
ARMul_SubOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
||||
{
|
||||
ASSIGNV (SubOverflow (a, b, result));
|
||||
}
|
||||
|
||||
/* 8-bit signed saturated addition */
|
||||
// 8-bit signed saturated addition
|
||||
u8 ARMul_SignedSaturatedAdd8(u8 left, u8 right)
|
||||
{
|
||||
u8 result = left + right;
|
||||
|
@ -500,7 +84,7 @@ u8 ARMul_SignedSaturatedAdd8(u8 left, u8 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 8-bit signed saturated subtraction */
|
||||
// 8-bit signed saturated subtraction
|
||||
u8 ARMul_SignedSaturatedSub8(u8 left, u8 right)
|
||||
{
|
||||
u8 result = left - right;
|
||||
|
@ -515,7 +99,7 @@ u8 ARMul_SignedSaturatedSub8(u8 left, u8 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 16-bit signed saturated addition */
|
||||
// 16-bit signed saturated addition
|
||||
u16 ARMul_SignedSaturatedAdd16(u16 left, u16 right)
|
||||
{
|
||||
u16 result = left + right;
|
||||
|
@ -530,7 +114,7 @@ u16 ARMul_SignedSaturatedAdd16(u16 left, u16 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 16-bit signed saturated subtraction */
|
||||
// 16-bit signed saturated subtraction
|
||||
u16 ARMul_SignedSaturatedSub16(u16 left, u16 right)
|
||||
{
|
||||
u16 result = left - right;
|
||||
|
@ -545,7 +129,7 @@ u16 ARMul_SignedSaturatedSub16(u16 left, u16 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 8-bit unsigned saturated addition */
|
||||
// 8-bit unsigned saturated addition
|
||||
u8 ARMul_UnsignedSaturatedAdd8(u8 left, u8 right)
|
||||
{
|
||||
u8 result = left + right;
|
||||
|
@ -556,7 +140,7 @@ u8 ARMul_UnsignedSaturatedAdd8(u8 left, u8 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 16-bit unsigned saturated addition */
|
||||
// 16-bit unsigned saturated addition
|
||||
u16 ARMul_UnsignedSaturatedAdd16(u16 left, u16 right)
|
||||
{
|
||||
u16 result = left + right;
|
||||
|
@ -567,7 +151,7 @@ u16 ARMul_UnsignedSaturatedAdd16(u16 left, u16 right)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* 8-bit unsigned saturated subtraction */
|
||||
// 8-bit unsigned saturated subtraction
|
||||
u8 ARMul_UnsignedSaturatedSub8(u8 left, u8 right)
|
||||
{
|
||||
if (left <= right)
|
||||
|
@ -576,7 +160,7 @@ u8 ARMul_UnsignedSaturatedSub8(u8 left, u8 right)
|
|||
return left - right;
|
||||
}
|
||||
|
||||
/* 16-bit unsigned saturated subtraction */
|
||||
// 16-bit unsigned saturated subtraction
|
||||
u16 ARMul_UnsignedSaturatedSub16(u16 left, u16 right)
|
||||
{
|
||||
if (left <= right)
|
||||
|
@ -620,444 +204,3 @@ u32 ARMul_UnsignedSatQ(s32 value, u8 shift, bool* saturation_occurred)
|
|||
*saturation_occurred = false;
|
||||
return (u32)value;
|
||||
}
|
||||
|
||||
/* This function does the work of generating the addresses used in an
|
||||
LDC instruction. The code here is always post-indexed, it's up to the
|
||||
caller to get the input address correct and to handle base register
|
||||
modification. It also handles the Busy-Waiting. */
|
||||
|
||||
void
|
||||
ARMul_LDC (ARMul_State * state, ARMword instr, ARMword address)
|
||||
{
|
||||
unsigned cpab;
|
||||
ARMword data;
|
||||
|
||||
UNDEF_LSCPCBaseWb;
|
||||
//printf("SKYEYE ARMul_LDC, CPnum is %x, instr %x, addr %x\n",CPNum, instr, address);
|
||||
/*chy 2004-05-23 should update this function in the future,should concern dataabort*/
|
||||
// chy 2004-05-25 , fix it now,so needn't printf
|
||||
// printf("SKYEYE ARMul_LDC, should update this function!!!!!\n");
|
||||
//exit(-1);
|
||||
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->LDC[CPNum]) {
|
||||
/*
|
||||
printf
|
||||
("SKYEYE ARMul_LDC,NOT ALLOW, underinstr, CPnum is %x, instr %x, addr %x\n",
|
||||
CPNum, instr, address);
|
||||
*/
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (ADDREXCEPT (address))
|
||||
INTERNALABORT (address);*/
|
||||
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_FIRST, instr, 0);
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_BUSY, instr,
|
||||
0);
|
||||
}
|
||||
if (cpab == ARMul_CANT) {
|
||||
/*
|
||||
printf
|
||||
("SKYEYE ARMul_LDC,NOT CAN, underinstr, CPnum is %x, instr %x, addr %x\n",
|
||||
CPNum, instr, address);
|
||||
*/
|
||||
CPTAKEABORT;
|
||||
return;
|
||||
}
|
||||
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_TRANSFER, instr, 0);
|
||||
data = ARMul_LoadWordN (state, address);
|
||||
//chy 2004-05-25
|
||||
if (state->abortSig || state->Aborted)
|
||||
goto L_ldc_takeabort;
|
||||
|
||||
BUSUSEDINCPCN;
|
||||
//chy 2004-05-25
|
||||
/*
|
||||
if (BIT (21))
|
||||
LSBase = state->Base;
|
||||
*/
|
||||
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_DATA, instr, data);
|
||||
|
||||
while (cpab == ARMul_INC) {
|
||||
address += 4;
|
||||
data = ARMul_LoadWordN (state, address);
|
||||
//chy 2004-05-25
|
||||
if (state->abortSig || state->Aborted)
|
||||
goto L_ldc_takeabort;
|
||||
|
||||
cpab = (state->LDC[CPNum]) (state, ARMul_DATA, instr, data);
|
||||
}
|
||||
|
||||
//chy 2004-05-25
|
||||
L_ldc_takeabort:
|
||||
if (BIT (21)) {
|
||||
if (!
|
||||
((state->abortSig || state->Aborted)
|
||||
&& state->lateabtSig == LOW))
|
||||
LSBase = state->Base;
|
||||
}
|
||||
|
||||
if (state->abortSig || state->Aborted)
|
||||
TAKEABORT;
|
||||
}
|
||||
|
||||
/* This function does the work of generating the addresses used in an
|
||||
STC instruction. The code here is always post-indexed, it's up to the
|
||||
caller to get the input address correct and to handle base register
|
||||
modification. It also handles the Busy-Waiting. */
|
||||
|
||||
void
|
||||
ARMul_STC (ARMul_State * state, ARMword instr, ARMword address)
|
||||
{
|
||||
unsigned cpab;
|
||||
ARMword data;
|
||||
|
||||
UNDEF_LSCPCBaseWb;
|
||||
|
||||
//printf("SKYEYE ARMul_STC, CPnum is %x, instr %x, addr %x\n",CPNum, instr, address);
|
||||
/*chy 2004-05-23 should update this function in the future,should concern dataabort */
|
||||
// skyeye_instr_debug=0;printf("SKYEYE debug end!!!!\n");
|
||||
// chy 2004-05-25 , fix it now,so needn't printf
|
||||
// printf("SKYEYE ARMul_STC, should update this function!!!!!\n");
|
||||
|
||||
//exit(-1);
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->STC[CPNum]) {
|
||||
/*
|
||||
printf
|
||||
("SKYEYE ARMul_STC,NOT ALLOW, undefinstr, CPnum is %x, instr %x, addr %x\n",
|
||||
CPNum, instr, address);
|
||||
*/
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (ADDREXCEPT (address) || VECTORACCESS (address))
|
||||
INTERNALABORT (address);*/
|
||||
|
||||
cpab = (state->STC[CPNum]) (state, ARMul_FIRST, instr, &data);
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->STC[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->STC[CPNum]) (state, ARMul_BUSY, instr,
|
||||
&data);
|
||||
}
|
||||
|
||||
if (cpab == ARMul_CANT) {
|
||||
/*
|
||||
printf
|
||||
("SKYEYE ARMul_STC,CANT, undefinstr, CPnum is %x, instr %x, addr %x\n",
|
||||
CPNum, instr, address);
|
||||
*/
|
||||
CPTAKEABORT;
|
||||
return;
|
||||
}
|
||||
/*#ifndef MODE32
|
||||
if (ADDREXCEPT (address) || VECTORACCESS (address))
|
||||
INTERNALABORT (address);
|
||||
#endif*/
|
||||
BUSUSEDINCPCN;
|
||||
//chy 2004-05-25
|
||||
/*
|
||||
if (BIT (21))
|
||||
LSBase = state->Base;
|
||||
*/
|
||||
cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
|
||||
ARMul_StoreWordN (state, address, data);
|
||||
//chy 2004-05-25
|
||||
if (state->abortSig || state->Aborted)
|
||||
goto L_stc_takeabort;
|
||||
|
||||
while (cpab == ARMul_INC) {
|
||||
address += 4;
|
||||
cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
|
||||
ARMul_StoreWordN (state, address, data);
|
||||
//chy 2004-05-25
|
||||
if (state->abortSig || state->Aborted)
|
||||
goto L_stc_takeabort;
|
||||
}
|
||||
//chy 2004-05-25
|
||||
L_stc_takeabort:
|
||||
if (BIT (21)) {
|
||||
if (!
|
||||
((state->abortSig || state->Aborted)
|
||||
&& state->lateabtSig == LOW))
|
||||
LSBase = state->Base;
|
||||
}
|
||||
|
||||
if (state->abortSig || state->Aborted)
|
||||
TAKEABORT;
|
||||
}
|
||||
|
||||
/* This function does the Busy-Waiting for an MCR instruction. */
|
||||
|
||||
void
|
||||
ARMul_MCR (ARMul_State * state, ARMword instr, ARMword source)
|
||||
{
|
||||
unsigned cpab;
|
||||
int cm = BITS(0, 3) & 0xf;
|
||||
int cp = BITS(5, 7) & 0x7;
|
||||
int rd = BITS(12, 15) & 0xf;
|
||||
int cn = BITS(16, 19) & 0xf;
|
||||
int cpopc = BITS(21, 23) & 0x7;
|
||||
|
||||
if (CPNum == 15 && source == 0) //Cache flush
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//printf("SKYEYE ARMul_MCR, CPnum is %x, source %x\n",CPNum, source);
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->MCR[CPNum]) {
|
||||
//chy 2004-07-19 should fix in the future ????!!!!
|
||||
LOG_ERROR(Core_ARM11, "SKYEYE ARMul_MCR, ACCESS_not ALLOWed, UndefinedInstr CPnum is %x, source %x",CPNum, source);
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
|
||||
//DEBUG("SKYEYE ARMul_MCR p%d, %d, r%d, c%d, c%d, %d\n", CPNum, cpopc, rd, cn, cm, cp);
|
||||
//DEBUG("plutoo: MCR not implemented\n");
|
||||
//exit(1);
|
||||
//return;
|
||||
|
||||
cpab = (state->MCR[CPNum]) (state, ARMul_FIRST, instr, source);
|
||||
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->MCR[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->MCR[CPNum]) (state, ARMul_BUSY, instr,
|
||||
source);
|
||||
}
|
||||
|
||||
if (cpab == ARMul_CANT) {
|
||||
LOG_ERROR(Core_ARM11, "SKYEYE ARMul_MCR, CANT, UndefinedInstr %x CPnum is %x, source %x", instr, CPNum, source); //ichfly todo
|
||||
//ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
} else {
|
||||
BUSUSEDINCPCN;
|
||||
ARMul_Ccycles (state, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* This function does the Busy-Waiting for an MCRR instruction. */
|
||||
|
||||
void
|
||||
ARMul_MCRR (ARMul_State * state, ARMword instr, ARMword source1, ARMword source2)
|
||||
{
|
||||
unsigned cpab;
|
||||
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->MCRR[CPNum]) {
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
|
||||
cpab = (state->MCRR[CPNum]) (state, ARMul_FIRST, instr, source1, source2);
|
||||
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->MCRR[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0, 0);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->MCRR[CPNum]) (state, ARMul_BUSY, instr,
|
||||
source1, source2);
|
||||
}
|
||||
if (cpab == ARMul_CANT) {
|
||||
printf ("In %s, CoProcesscor returned CANT, CPnum is %x, instr %x, source %x %x\n", __FUNCTION__, CPNum, instr, source1, source2);
|
||||
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
} else {
|
||||
BUSUSEDINCPCN;
|
||||
ARMul_Ccycles (state, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* This function does the Busy-Waiting for an MRC instruction. */
|
||||
|
||||
ARMword ARMul_MRC (ARMul_State * state, ARMword instr)
|
||||
{
|
||||
int cm = BITS(0, 3) & 0xf;
|
||||
int cp = BITS(5, 7) & 0x7;
|
||||
int rd = BITS(12, 15) & 0xf;
|
||||
int cn = BITS(16, 19) & 0xf;
|
||||
int cpopc = BITS(21, 23) & 0x7;
|
||||
|
||||
if (cn == 13 && cm == 0 && cp == 3) { //c13,c0,3; returns CPU svc buffer
|
||||
ARMword result = Memory::KERNEL_MEMORY_VADDR;
|
||||
|
||||
if (result != -1) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//DEBUG("SKYEYE ARMul_MRC p%d, %d, r%d, c%d, c%d, %d\n", CPNum, cpopc, rd, cn, cm, cp);
|
||||
//DEBUG("plutoo: MRC not implemented\n");
|
||||
//return;
|
||||
|
||||
unsigned cpab;
|
||||
ARMword result = 0;
|
||||
|
||||
//printf("SKYEYE ARMul_MRC, CPnum is %x, instr %x\n",CPNum, instr);
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->MRC[CPNum]) {
|
||||
//chy 2004-07-19 should fix in the future????!!!!
|
||||
LOG_ERROR(Core_ARM11, "SKYEYE ARMul_MRC,NOT ALLOWed UndefInstr CPnum is %x, instr %x", CPNum, instr);
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cpab = (state->MRC[CPNum]) (state, ARMul_FIRST, instr, &result);
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->MRC[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0);
|
||||
return (0);
|
||||
} else
|
||||
cpab = (state->MRC[CPNum]) (state, ARMul_BUSY, instr,
|
||||
&result);
|
||||
}
|
||||
if (cpab == ARMul_CANT) {
|
||||
printf ("SKYEYE ARMul_MRC,CANT UndefInstr CPnum is %x, instr %x\n", CPNum, instr);
|
||||
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
/* Parent will destroy the flags otherwise. */
|
||||
result = ECC;
|
||||
} else {
|
||||
BUSUSEDINCPCN;
|
||||
ARMul_Ccycles (state, 1, 0);
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* This function does the Busy-Waiting for an MRRC instruction. (to verify) */
|
||||
|
||||
void
|
||||
ARMul_MRRC (ARMul_State * state, ARMword instr, ARMword * dest1, ARMword * dest2)
|
||||
{
|
||||
unsigned cpab;
|
||||
ARMword result1 = 0;
|
||||
ARMword result2 = 0;
|
||||
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->MRRC[CPNum]) {
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
|
||||
cpab = (state->MRRC[CPNum]) (state, ARMul_FIRST, instr, &result1, &result2);
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->MRRC[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr, 0, 0);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->MRRC[CPNum]) (state, ARMul_BUSY, instr,
|
||||
&result1, &result2);
|
||||
}
|
||||
if (cpab == ARMul_CANT) {
|
||||
printf ("In %s, CoProcesscor returned CANT, CPnum is %x, instr %x\n", __FUNCTION__, CPNum, instr);
|
||||
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
} else {
|
||||
BUSUSEDINCPCN;
|
||||
ARMul_Ccycles (state, 1, 0);
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
}
|
||||
|
||||
*dest1 = result1;
|
||||
*dest2 = result2;
|
||||
}
|
||||
|
||||
/* This function does the Busy-Waiting for an CDP instruction. */
|
||||
|
||||
void
|
||||
ARMul_CDP (ARMul_State * state, ARMword instr)
|
||||
{
|
||||
unsigned cpab;
|
||||
|
||||
//if (!CP_ACCESS_ALLOWED (state, CPNum)) {
|
||||
if (!state->CDP[CPNum]) {
|
||||
ARMul_UndefInstr (state, instr);
|
||||
return;
|
||||
}
|
||||
cpab = (state->CDP[CPNum]) (state, ARMul_FIRST, instr);
|
||||
while (cpab == ARMul_BUSY) {
|
||||
ARMul_Icycles (state, 1, 0);
|
||||
if (IntPending (state)) {
|
||||
cpab = (state->CDP[CPNum]) (state, ARMul_INTERRUPT,
|
||||
instr);
|
||||
return;
|
||||
} else
|
||||
cpab = (state->CDP[CPNum]) (state, ARMul_BUSY, instr);
|
||||
}
|
||||
if (cpab == ARMul_CANT)
|
||||
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
else
|
||||
BUSUSEDN;
|
||||
}
|
||||
|
||||
/* This function handles Undefined instructions, as CP isntruction. */
|
||||
|
||||
void
|
||||
ARMul_UndefInstr (ARMul_State * state, ARMword instr)
|
||||
{
|
||||
std::string disasm = ARM_Disasm::Disassemble(state->pc, instr);
|
||||
LOG_ERROR(Core_ARM11, "Undefined instruction!! Disasm: %s Opcode: 0x%x", disasm.c_str(), instr);
|
||||
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
||||
}
|
||||
|
||||
/* Return TRUE if an interrupt is pending, FALSE otherwise. */
|
||||
|
||||
unsigned
|
||||
IntPending (ARMul_State * state)
|
||||
{
|
||||
/* Any exceptions. */
|
||||
if (state->NresetSig == LOW) {
|
||||
ARMul_Abort (state, ARMul_ResetV);
|
||||
return TRUE;
|
||||
} else if (!state->NfiqSig && !FFLAG) {
|
||||
ARMul_Abort (state, ARMul_FIQV);
|
||||
return TRUE;
|
||||
} else if (!state->NirqSig && !IFLAG) {
|
||||
ARMul_Abort (state, ARMul_IRQV);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Align a word access to a non word boundary. */
|
||||
|
||||
ARMword
|
||||
ARMul_Align (ARMul_State* state, ARMword address, ARMword data)
|
||||
{
|
||||
/* This code assumes the address is really unaligned,
|
||||
as a shift by 32 is undefined in C. */
|
||||
|
||||
address = (address & 3) << 3; /* Get the word address. */
|
||||
return ((data >> address) | (data << (32 - address))); /* rot right */
|
||||
}
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
/* armvirt.c -- ARMulator virtual memory interace: 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. */
|
||||
|
||||
/* This file contains a complete ARMulator memory model, modelling a
|
||||
"virtual memory" system. A much simpler model can be found in armfast.c,
|
||||
and that model goes faster too, but has a fixed amount of memory. This
|
||||
model's memory has 64K pages, allocated on demand from a 64K entry page
|
||||
table. The routines PutWord and GetWord implement this. Pages are never
|
||||
freed as they might be needed again. A single area of memory may be
|
||||
defined to generate aborts. */
|
||||
|
||||
#include "core/arm/skyeye_common/armdefs.h"
|
||||
#include "core/arm/skyeye_common/armemu.h"
|
||||
|
||||
#include "core/mem_map.h"
|
||||
|
||||
#define dumpstack 1
|
||||
#define dumpstacksize 0x10
|
||||
#define maxdmupaddr 0x0033a850
|
||||
|
||||
/*ARMword ARMul_GetCPSR (ARMul_State * state) {
|
||||
return 0;
|
||||
}
|
||||
ARMword ARMul_GetSPSR (ARMul_State * state, ARMword mode) {
|
||||
return 0;
|
||||
}
|
||||
void ARMul_SetCPSR (ARMul_State * state, ARMword value) {
|
||||
|
||||
}
|
||||
void ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value) {
|
||||
|
||||
}*/
|
||||
|
||||
void ARMul_Icycles(ARMul_State * state, unsigned number, ARMword address) {
|
||||
}
|
||||
|
||||
void ARMul_Ccycles(ARMul_State * state, unsigned number, ARMword address) {
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadInstrS(ARMul_State * state, ARMword address, ARMword isize) {
|
||||
state->NumScycles++;
|
||||
|
||||
#ifdef HOURGLASS
|
||||
if ((state->NumScycles & HOURGLASS_RATE) == 0) {
|
||||
HOURGLASS;
|
||||
}
|
||||
#endif
|
||||
if (isize == 2)
|
||||
return (u16)Memory::Read16(address);
|
||||
else
|
||||
return (u32)Memory::Read32(address);
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadInstrN(ARMul_State * state, ARMword address, ARMword isize) {
|
||||
state->NumNcycles++;
|
||||
|
||||
if (isize == 2)
|
||||
return (u16)Memory::Read16(address);
|
||||
else
|
||||
return (u32)Memory::Read32(address);
|
||||
}
|
||||
|
||||
ARMword ARMul_ReLoadInstr(ARMul_State * state, ARMword address, ARMword isize) {
|
||||
ARMword data;
|
||||
|
||||
if ((isize == 2) && (address & 0x2)) {
|
||||
ARMword lo;
|
||||
lo = (u16)Memory::Read16(address);
|
||||
return lo;
|
||||
}
|
||||
|
||||
data = (u32)Memory::Read32(address);
|
||||
return data;
|
||||
}
|
||||
|
||||
ARMword ARMul_ReadWord(ARMul_State * state, ARMword address) {
|
||||
ARMword data;
|
||||
data = Memory::Read32(address);
|
||||
return data;
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadWordS(ARMul_State * state, ARMword address) {
|
||||
state->NumScycles++;
|
||||
return ARMul_ReadWord(state, address);
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadWordN(ARMul_State * state, ARMword address) {
|
||||
state->NumNcycles++;
|
||||
return ARMul_ReadWord(state, address);
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadHalfWord(ARMul_State * state, ARMword address) {
|
||||
state->NumNcycles++;
|
||||
return (u16)Memory::Read16(address);;
|
||||
}
|
||||
|
||||
ARMword ARMul_ReadByte(ARMul_State * state, ARMword address) {
|
||||
return (u8)Memory::Read8(address);
|
||||
}
|
||||
|
||||
ARMword ARMul_LoadByte(ARMul_State * state, ARMword address) {
|
||||
state->NumNcycles++;
|
||||
return ARMul_ReadByte(state, address);
|
||||
}
|
||||
|
||||
void ARMul_StoreHalfWord(ARMul_State * state, ARMword address, ARMword data) {
|
||||
state->NumNcycles++;
|
||||
Memory::Write16(address, data);
|
||||
}
|
||||
|
||||
void ARMul_StoreByte(ARMul_State * state, ARMword address, ARMword data) {
|
||||
state->NumNcycles++;
|
||||
ARMul_WriteByte(state, address, data);
|
||||
}
|
||||
|
||||
ARMword ARMul_SwapWord(ARMul_State * state, ARMword address, ARMword data) {
|
||||
ARMword temp;
|
||||
state->NumNcycles++;
|
||||
temp = ARMul_ReadWord(state, address);
|
||||
state->NumNcycles++;
|
||||
Memory::Write32(address, data);
|
||||
return temp;
|
||||
}
|
||||
|
||||
ARMword ARMul_SwapByte(ARMul_State * state, ARMword address, ARMword data) {
|
||||
ARMword temp;
|
||||
temp = ARMul_LoadByte(state, address);
|
||||
Memory::Write8(address, data);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void ARMul_WriteWord(ARMul_State * state, ARMword address, ARMword data) {
|
||||
Memory::Write32(address, data);
|
||||
}
|
||||
|
||||
void ARMul_WriteByte(ARMul_State * state, ARMword address, ARMword data)
|
||||
{
|
||||
Memory::Write8(address, data);
|
||||
}
|
||||
|
||||
void ARMul_StoreWordS(ARMul_State * state, ARMword address, ARMword data)
|
||||
{
|
||||
state->NumScycles++;
|
||||
ARMul_WriteWord(state, address, data);
|
||||
}
|
||||
|
||||
void ARMul_StoreWordN(ARMul_State * state, ARMword address, ARMword data)
|
||||
{
|
||||
state->NumNcycles++;
|
||||
ARMul_WriteWord(state, address, data);
|
||||
}
|
|
@ -1,513 +0,0 @@
|
|||
/* thumbemu.c -- Thumb instruction emulation.
|
||||
Copyright (C) 1996, Cygnus Software Technologies 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. */
|
||||
|
||||
/* We can provide simple Thumb simulation by decoding the Thumb
|
||||
instruction into its corresponding ARM instruction, and using the
|
||||
existing ARM simulator. */
|
||||
|
||||
#include "core/arm/skyeye_common/skyeye_defs.h"
|
||||
|
||||
#ifndef MODET /* required for the Thumb instruction support */
|
||||
#if 1
|
||||
#error "MODET needs to be defined for the Thumb world to work"
|
||||
#else
|
||||
#define MODET (1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "core/arm/skyeye_common/armdefs.h"
|
||||
#include "core/arm/skyeye_common/armemu.h"
|
||||
#include "core/arm/skyeye_common/armos.h"
|
||||
|
||||
|
||||
/* Decode a 16bit Thumb instruction. The instruction is in the low
|
||||
16-bits of the tinstr field, with the following Thumb instruction
|
||||
held in the high 16-bits. Passing in two Thumb instructions allows
|
||||
easier simulation of the special dual BL instruction. */
|
||||
|
||||
tdstate
|
||||
ARMul_ThumbDecode (
|
||||
ARMul_State *state,
|
||||
ARMword pc,
|
||||
ARMword tinstr,
|
||||
ARMword *ainstr)
|
||||
{
|
||||
tdstate valid = t_decoded; /* default assumes a valid instruction */
|
||||
ARMword next_instr;
|
||||
|
||||
if (state->bigendSig) {
|
||||
next_instr = tinstr & 0xFFFF;
|
||||
tinstr >>= 16;
|
||||
}
|
||||
else {
|
||||
next_instr = tinstr >> 16;
|
||||
tinstr &= 0xFFFF;
|
||||
}
|
||||
|
||||
#if 1 /* debugging to catch non updates */
|
||||
*ainstr = 0xDEADC0DE;
|
||||
#endif
|
||||
|
||||
switch ((tinstr & 0xF800) >> 11) {
|
||||
case 0: /* LSL */
|
||||
case 1: /* LSR */
|
||||
case 2: /* ASR */
|
||||
/* Format 1 */
|
||||
*ainstr = 0xE1B00000 /* base opcode */
|
||||
| ((tinstr & 0x1800) >> (11 - 5)) /* shift type */
|
||||
|((tinstr & 0x07C0) << (7 - 6)) /* imm5 */
|
||||
|((tinstr & 0x0038) >> 3) /* Rs */
|
||||
|((tinstr & 0x0007) << 12); /* Rd */
|
||||
break;
|
||||
case 3: /* ADD/SUB */
|
||||
/* Format 2 */
|
||||
{
|
||||
ARMword subset[4] = {
|
||||
0xE0900000, /* ADDS Rd,Rs,Rn */
|
||||
0xE0500000, /* SUBS Rd,Rs,Rn */
|
||||
0xE2900000, /* ADDS Rd,Rs,#imm3 */
|
||||
0xE2500000 /* SUBS Rd,Rs,#imm3 */
|
||||
};
|
||||
/* It is quicker indexing into a table, than performing switch
|
||||
or conditionals: */
|
||||
*ainstr = subset[(tinstr & 0x0600) >> 9] /* base opcode */
|
||||
|((tinstr & 0x01C0) >> 6) /* Rn or imm3 */
|
||||
|((tinstr & 0x0038) << (16 - 3)) /* Rs */
|
||||
|((tinstr & 0x0007) << (12 - 0)); /* Rd */
|
||||
}
|
||||
break;
|
||||
case 4: /* MOV */
|
||||
case 5: /* CMP */
|
||||
case 6: /* ADD */
|
||||
case 7: /* SUB */
|
||||
/* Format 3 */
|
||||
{
|
||||
ARMword subset[4] = {
|
||||
0xE3B00000, /* MOVS Rd,#imm8 */
|
||||
0xE3500000, /* CMP Rd,#imm8 */
|
||||
0xE2900000, /* ADDS Rd,Rd,#imm8 */
|
||||
0xE2500000, /* SUBS Rd,Rd,#imm8 */
|
||||
};
|
||||
*ainstr = subset[(tinstr & 0x1800) >> 11] /* base opcode */
|
||||
|((tinstr & 0x00FF) >> 0) /* imm8 */
|
||||
|((tinstr & 0x0700) << (16 - 8)) /* Rn */
|
||||
|((tinstr & 0x0700) << (12 - 8)); /* Rd */
|
||||
}
|
||||
break;
|
||||
case 8: /* Arithmetic and high register transfers */
|
||||
/* TODO: Since the subsets for both Format 4 and Format 5
|
||||
instructions are made up of different ARM encodings, we could
|
||||
save the following conditional, and just have one large
|
||||
subset. */
|
||||
if ((tinstr & (1 << 10)) == 0) {
|
||||
/* Format 4 */
|
||||
enum OpcodeType { t_norm, t_shift, t_neg, t_mul };
|
||||
struct ThumbOpcode {
|
||||
ARMword opcode;
|
||||
OpcodeType otype;
|
||||
};
|
||||
|
||||
ThumbOpcode subset[16] = {
|
||||
{
|
||||
0xE0100000, t_norm}, /* ANDS Rd,Rd,Rs */
|
||||
{
|
||||
0xE0300000, t_norm}, /* EORS Rd,Rd,Rs */
|
||||
{
|
||||
0xE1B00010, t_shift}, /* MOVS Rd,Rd,LSL Rs */
|
||||
{
|
||||
0xE1B00030, t_shift}, /* MOVS Rd,Rd,LSR Rs */
|
||||
{
|
||||
0xE1B00050, t_shift}, /* MOVS Rd,Rd,ASR Rs */
|
||||
{
|
||||
0xE0B00000, t_norm}, /* ADCS Rd,Rd,Rs */
|
||||
{
|
||||
0xE0D00000, t_norm}, /* SBCS Rd,Rd,Rs */
|
||||
{
|
||||
0xE1B00070, t_shift}, /* MOVS Rd,Rd,ROR Rs */
|
||||
{
|
||||
0xE1100000, t_norm}, /* TST Rd,Rs */
|
||||
{
|
||||
0xE2700000, t_neg}, /* RSBS Rd,Rs,#0 */
|
||||
{
|
||||
0xE1500000, t_norm}, /* CMP Rd,Rs */
|
||||
{
|
||||
0xE1700000, t_norm}, /* CMN Rd,Rs */
|
||||
{
|
||||
0xE1900000, t_norm}, /* ORRS Rd,Rd,Rs */
|
||||
{
|
||||
0xE0100090, t_mul}, /* MULS Rd,Rd,Rs */
|
||||
{
|
||||
0xE1D00000, t_norm}, /* BICS Rd,Rd,Rs */
|
||||
{
|
||||
0xE1F00000, t_norm} /* MVNS Rd,Rs */
|
||||
};
|
||||
*ainstr = subset[(tinstr & 0x03C0) >> 6].opcode; /* base */
|
||||
switch (subset[(tinstr & 0x03C0) >> 6].otype) {
|
||||
case t_norm:
|
||||
*ainstr |= ((tinstr & 0x0007) << 16) /* Rn */
|
||||
|((tinstr & 0x0007) << 12) /* Rd */
|
||||
|((tinstr & 0x0038) >> 3); /* Rs */
|
||||
break;
|
||||
case t_shift:
|
||||
*ainstr |= ((tinstr & 0x0007) << 12) /* Rd */
|
||||
|((tinstr & 0x0007) >> 0) /* Rm */
|
||||
|((tinstr & 0x0038) << (8 - 3)); /* Rs */
|
||||
break;
|
||||
case t_neg:
|
||||
*ainstr |= ((tinstr & 0x0007) << 12) /* Rd */
|
||||
|((tinstr & 0x0038) << (16 - 3)); /* Rn */
|
||||
break;
|
||||
case t_mul:
|
||||
*ainstr |= ((tinstr & 0x0007) << 16) /* Rd */
|
||||
|((tinstr & 0x0007) << 8) /* Rs */
|
||||
|((tinstr & 0x0038) >> 3); /* Rm */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Format 5 */
|
||||
ARMword Rd = ((tinstr & 0x0007) >> 0);
|
||||
ARMword Rs = ((tinstr & 0x0038) >> 3);
|
||||
if (tinstr & (1 << 7))
|
||||
Rd += 8;
|
||||
if (tinstr & (1 << 6))
|
||||
Rs += 8;
|
||||
switch ((tinstr & 0x03C0) >> 6) {
|
||||
case 0x1: /* ADD Rd,Rd,Hs */
|
||||
case 0x2: /* ADD Hd,Hd,Rs */
|
||||
case 0x3: /* ADD Hd,Hd,Hs */
|
||||
*ainstr = 0xE0800000 /* base */
|
||||
| (Rd << 16) /* Rn */
|
||||
|(Rd << 12) /* Rd */
|
||||
|(Rs << 0); /* Rm */
|
||||
break;
|
||||
case 0x5: /* CMP Rd,Hs */
|
||||
case 0x6: /* CMP Hd,Rs */
|
||||
case 0x7: /* CMP Hd,Hs */
|
||||
*ainstr = 0xE1500000 /* base */
|
||||
| (Rd << 16) /* Rn */
|
||||
|(Rd << 12) /* Rd */
|
||||
|(Rs << 0); /* Rm */
|
||||
break;
|
||||
case 0x9: /* MOV Rd,Hs */
|
||||
case 0xA: /* MOV Hd,Rs */
|
||||
case 0xB: /* MOV Hd,Hs */
|
||||
*ainstr = 0xE1A00000 /* base */
|
||||
| (Rd << 16) /* Rn */
|
||||
|(Rd << 12) /* Rd */
|
||||
|(Rs << 0); /* Rm */
|
||||
break;
|
||||
case 0xC: /* BX Rs */
|
||||
case 0xD: /* BX Hs */
|
||||
*ainstr = 0xE12FFF10 /* base */
|
||||
| ((tinstr & 0x0078) >> 3); /* Rd */
|
||||
break;
|
||||
case 0x0: /* UNDEFINED */
|
||||
case 0x4: /* UNDEFINED */
|
||||
case 0x8: /* UNDEFINED */
|
||||
valid = t_undefined;
|
||||
break;
|
||||
case 0xE: /* BLX */
|
||||
case 0xF: /* BLX */
|
||||
if (state->is_v5) {
|
||||
*ainstr = 0xE1200030 /* base */
|
||||
|(Rs << 0); /* Rm */
|
||||
} else {
|
||||
valid = t_undefined;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 9: /* LDR Rd,[PC,#imm8] */
|
||||
/* Format 6 */
|
||||
*ainstr = 0xE59F0000 /* base */
|
||||
| ((tinstr & 0x0700) << (12 - 8)) /* Rd */
|
||||
|((tinstr & 0x00FF) << (2 - 0)); /* off8 */
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
/* TODO: Format 7 and Format 8 perform the same ARM encoding, so
|
||||
the following could be merged into a single subset, saving on
|
||||
the following boolean: */
|
||||
if ((tinstr & (1 << 9)) == 0) {
|
||||
/* Format 7 */
|
||||
ARMword subset[4] = {
|
||||
0xE7800000, /* STR Rd,[Rb,Ro] */
|
||||
0xE7C00000, /* STRB Rd,[Rb,Ro] */
|
||||
0xE7900000, /* LDR Rd,[Rb,Ro] */
|
||||
0xE7D00000 /* LDRB Rd,[Rb,Ro] */
|
||||
};
|
||||
*ainstr = subset[(tinstr & 0x0C00) >> 10] /* base */
|
||||
|((tinstr & 0x0007) << (12 - 0)) /* Rd */
|
||||
|((tinstr & 0x0038) << (16 - 3)) /* Rb */
|
||||
|((tinstr & 0x01C0) >> 6); /* Ro */
|
||||
}
|
||||
else {
|
||||
/* Format 8 */
|
||||
ARMword subset[4] = {
|
||||
0xE18000B0, /* STRH Rd,[Rb,Ro] */
|
||||
0xE19000D0, /* LDRSB Rd,[Rb,Ro] */
|
||||
0xE19000B0, /* LDRH Rd,[Rb,Ro] */
|
||||
0xE19000F0 /* LDRSH Rd,[Rb,Ro] */
|
||||
};
|
||||
*ainstr = subset[(tinstr & 0x0C00) >> 10] /* base */
|
||||
|((tinstr & 0x0007) << (12 - 0)) /* Rd */
|
||||
|((tinstr & 0x0038) << (16 - 3)) /* Rb */
|
||||
|((tinstr & 0x01C0) >> 6); /* Ro */
|
||||
}
|
||||
break;
|
||||
case 12: /* STR Rd,[Rb,#imm5] */
|
||||
case 13: /* LDR Rd,[Rb,#imm5] */
|
||||
case 14: /* STRB Rd,[Rb,#imm5] */
|
||||
case 15: /* LDRB Rd,[Rb,#imm5] */
|
||||
/* Format 9 */
|
||||
{
|
||||
ARMword subset[4] = {
|
||||
0xE5800000, /* STR Rd,[Rb,#imm5] */
|
||||
0xE5900000, /* LDR Rd,[Rb,#imm5] */
|
||||
0xE5C00000, /* STRB Rd,[Rb,#imm5] */
|
||||
0xE5D00000 /* LDRB Rd,[Rb,#imm5] */
|
||||
};
|
||||
/* The offset range defends on whether we are transferring a
|
||||
byte or word value: */
|
||||
*ainstr = subset[(tinstr & 0x1800) >> 11] /* base */
|
||||
|((tinstr & 0x0007) << (12 - 0)) /* Rd */
|
||||
|((tinstr & 0x0038) << (16 - 3)) /* Rb */
|
||||
|((tinstr & 0x07C0) >> (6 - ((tinstr & (1 << 12)) ? 0 : 2))); /* off5 */
|
||||
}
|
||||
break;
|
||||
case 16: /* STRH Rd,[Rb,#imm5] */
|
||||
case 17: /* LDRH Rd,[Rb,#imm5] */
|
||||
/* Format 10 */
|
||||
*ainstr = ((tinstr & (1 << 11)) /* base */
|
||||
? 0xE1D000B0 /* LDRH */
|
||||
: 0xE1C000B0) /* STRH */
|
||||
|((tinstr & 0x0007) << (12 - 0)) /* Rd */
|
||||
|((tinstr & 0x0038) << (16 - 3)) /* Rb */
|
||||
|((tinstr & 0x01C0) >> (6 - 1)) /* off5, low nibble */
|
||||
|((tinstr & 0x0600) >> (9 - 8)); /* off5, high nibble */
|
||||
break;
|
||||
case 18: /* STR Rd,[SP,#imm8] */
|
||||
case 19: /* LDR Rd,[SP,#imm8] */
|
||||
/* Format 11 */
|
||||
*ainstr = ((tinstr & (1 << 11)) /* base */
|
||||
? 0xE59D0000 /* LDR */
|
||||
: 0xE58D0000) /* STR */
|
||||
|((tinstr & 0x0700) << (12 - 8)) /* Rd */
|
||||
|((tinstr & 0x00FF) << 2); /* off8 */
|
||||
break;
|
||||
case 20: /* ADD Rd,PC,#imm8 */
|
||||
case 21: /* ADD Rd,SP,#imm8 */
|
||||
/* Format 12 */
|
||||
if ((tinstr & (1 << 11)) == 0) {
|
||||
/* NOTE: The PC value used here should by word aligned */
|
||||
/* We encode shift-left-by-2 in the rotate immediate field,
|
||||
so no shift of off8 is needed. */
|
||||
*ainstr = 0xE28F0F00 /* base */
|
||||
| ((tinstr & 0x0700) << (12 - 8)) /* Rd */
|
||||
|(tinstr & 0x00FF); /* off8 */
|
||||
}
|
||||
else {
|
||||
/* We encode shift-left-by-2 in the rotate immediate field,
|
||||
so no shift of off8 is needed. */
|
||||
*ainstr = 0xE28D0F00 /* base */
|
||||
| ((tinstr & 0x0700) << (12 - 8)) /* Rd */
|
||||
|(tinstr & 0x00FF); /* off8 */
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
case 23:
|
||||
if ((tinstr & 0x0F00) == 0x0000) {
|
||||
/* Format 13 */
|
||||
/* NOTE: The instruction contains a shift left of 2
|
||||
equivalent (implemented as ROR #30): */
|
||||
*ainstr = ((tinstr & (1 << 7)) /* base */
|
||||
? 0xE24DDF00 /* SUB */
|
||||
: 0xE28DDF00) /* ADD */
|
||||
|(tinstr & 0x007F); /* off7 */
|
||||
}
|
||||
else if ((tinstr & 0x0F00) == 0x0e00)
|
||||
*ainstr = 0xEF000000 | SWI_Breakpoint;
|
||||
else {
|
||||
/* Format 14 */
|
||||
ARMword subset[4] = {
|
||||
0xE92D0000, /* STMDB sp!,{rlist} */
|
||||
0xE92D4000, /* STMDB sp!,{rlist,lr} */
|
||||
0xE8BD0000, /* LDMIA sp!,{rlist} */
|
||||
0xE8BD8000 /* LDMIA sp!,{rlist,pc} */
|
||||
};
|
||||
*ainstr = subset[((tinstr & (1 << 11)) >> 10) | ((tinstr & (1 << 8)) >> 8)] /* base */
|
||||
|(tinstr & 0x00FF); /* mask8 */
|
||||
}
|
||||
break;
|
||||
case 24: /* STMIA */
|
||||
case 25: /* LDMIA */
|
||||
/* Format 15 */
|
||||
*ainstr = ((tinstr & (1 << 11)) /* base */
|
||||
? 0xE8B00000 /* LDMIA */
|
||||
: 0xE8A00000) /* STMIA */
|
||||
|((tinstr & 0x0700) << (16 - 8)) /* Rb */
|
||||
|(tinstr & 0x00FF); /* mask8 */
|
||||
break;
|
||||
case 26: /* Bcc */
|
||||
case 27: /* Bcc/SWI */
|
||||
if ((tinstr & 0x0F00) == 0x0F00) {
|
||||
if (tinstr == (ARMul_ABORTWORD & 0xffff) &&
|
||||
state->AbortAddr == pc) {
|
||||
*ainstr = ARMul_ABORTWORD;
|
||||
break;
|
||||
}
|
||||
/* Format 17 : SWI */
|
||||
*ainstr = 0xEF000000;
|
||||
/* Breakpoint must be handled specially. */
|
||||
if ((tinstr & 0x00FF) == 0x18)
|
||||
*ainstr |= ((tinstr & 0x00FF) << 16);
|
||||
/* New breakpoint value. See gdb/arm-tdep.c */
|
||||
else if ((tinstr & 0x00FF) == 0xFE)
|
||||
*ainstr |= SWI_Breakpoint;
|
||||
else
|
||||
*ainstr |= (tinstr & 0x00FF);
|
||||
}
|
||||
else if ((tinstr & 0x0F00) != 0x0E00) {
|
||||
/* Format 16 */
|
||||
int doit = FALSE;
|
||||
/* TODO: Since we are doing a switch here, we could just add
|
||||
the SWI and undefined instruction checks into this
|
||||
switch to same on a couple of conditionals: */
|
||||
switch ((tinstr & 0x0F00) >> 8) {
|
||||
case EQ:
|
||||
doit = ZFLAG;
|
||||
break;
|
||||
case NE:
|
||||
doit = !ZFLAG;
|
||||
break;
|
||||
case VS:
|
||||
doit = VFLAG;
|
||||
break;
|
||||
case VC:
|
||||
doit = !VFLAG;
|
||||
break;
|
||||
case MI:
|
||||
doit = NFLAG;
|
||||
break;
|
||||
case PL:
|
||||
doit = !NFLAG;
|
||||
break;
|
||||
case CS:
|
||||
doit = CFLAG;
|
||||
break;
|
||||
case CC:
|
||||
doit = !CFLAG;
|
||||
break;
|
||||
case HI:
|
||||
doit = (CFLAG && !ZFLAG);
|
||||
break;
|
||||
case LS:
|
||||
doit = (!CFLAG || ZFLAG);
|
||||
break;
|
||||
case GE:
|
||||
doit = ((!NFLAG && !VFLAG)
|
||||
|| (NFLAG && VFLAG));
|
||||
break;
|
||||
case LT:
|
||||
doit = ((NFLAG && !VFLAG)
|
||||
|| (!NFLAG && VFLAG));
|
||||
break;
|
||||
case GT:
|
||||
doit = ((!NFLAG && !VFLAG && !ZFLAG)
|
||||
|| (NFLAG && VFLAG && !ZFLAG));
|
||||
break;
|
||||
case LE:
|
||||
doit = ((NFLAG && !VFLAG)
|
||||
|| (!NFLAG && VFLAG)) || ZFLAG;
|
||||
break;
|
||||
}
|
||||
if (doit) {
|
||||
state->Reg[15] = (pc + 4
|
||||
+ (((tinstr & 0x7F) << 1)
|
||||
| ((tinstr & (1 << 7)) ?
|
||||
0xFFFFFF00 : 0)));
|
||||
FLUSHPIPE;
|
||||
}
|
||||
valid = t_branch;
|
||||
}
|
||||
else /* UNDEFINED : cc=1110(AL) uses different format */
|
||||
valid = t_undefined;
|
||||
break;
|
||||
case 28: /* B */
|
||||
/* Format 18 */
|
||||
state->Reg[15] = (pc + 4 + (((tinstr & 0x3FF) << 1)
|
||||
| ((tinstr & (1 << 10)) ?
|
||||
0xFFFFF800 : 0)));
|
||||
FLUSHPIPE;
|
||||
valid = t_branch;
|
||||
break;
|
||||
case 29:
|
||||
if(tinstr & 0x1)
|
||||
valid = t_undefined;
|
||||
else{
|
||||
/* BLX 1 for armv5t and above */
|
||||
ARMword tmp = (pc + 2);
|
||||
state->Reg[15] =
|
||||
(state->Reg[14] + ((tinstr & 0x07FF) << 1)) & 0xFFFFFFFC;
|
||||
state->Reg[14] = (tmp | 1);
|
||||
CLEART;
|
||||
LOG_DEBUG(Core_ARM11, "After BLX(1),LR=0x%x,PC=0x%x, offset=0x%x", state->Reg[14], state->Reg[15], (tinstr &0x7FF) << 1);
|
||||
valid = t_branch;
|
||||
FLUSHPIPE;
|
||||
}
|
||||
break;
|
||||
case 30: /* BL instruction 1 */
|
||||
/* Format 19 */
|
||||
/* There is no single ARM instruction equivalent for this Thumb
|
||||
instruction. To keep the simulation simple (from the user
|
||||
perspective) we check if the following instruction is the
|
||||
second half of this BL, and if it is we simulate it
|
||||
immediately. */
|
||||
state->Reg[14] = state->Reg[15]
|
||||
+ (((tinstr & 0x07FF) << 12)
|
||||
| ((tinstr & (1 << 10)) ? 0xFF800000 : 0));
|
||||
valid = t_branch; /* in-case we don't have the 2nd half */
|
||||
//tinstr = next_instr; /* move the instruction down */
|
||||
//if (((tinstr & 0xF800) >> 11) != 31)
|
||||
// break; /* exit, since not correct instruction */
|
||||
/* else we fall through to process the second half of the BL */
|
||||
//pc += 2; /* point the pc at the 2nd half */
|
||||
state->Reg[15] = pc + 2;
|
||||
FLUSHPIPE;
|
||||
break;
|
||||
case 31: /* BL instruction 2 */
|
||||
/* Format 19 */
|
||||
/* There is no single ARM instruction equivalent for this
|
||||
instruction. Also, it should only ever be matched with the
|
||||
fmt19 "BL instruction 1" instruction. However, we do allow
|
||||
the simulation of it on its own, with undefined results if
|
||||
r14 is not suitably initialised. */
|
||||
{
|
||||
ARMword tmp = (pc + 2);
|
||||
state->Reg[15] =
|
||||
(state->Reg[14] + ((tinstr & 0x07FF) << 1));
|
||||
state->Reg[14] = (tmp | 1);
|
||||
valid = t_branch;
|
||||
FLUSHPIPE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue