1999-04-16 01:35:26 +00:00
|
|
|
/* armsupp.c -- ARMulator support code: 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 "armdefs.h"
|
|
|
|
#include "armemu.h"
|
2000-02-08 20:54:27 +00:00
|
|
|
#include "ansidecl.h"
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Definitions for the support routines. */
|
|
|
|
|
|
|
|
static ARMword ModeToBank (ARMword);
|
|
|
|
static void EnvokeList (ARMul_State *, unsigned long, unsigned long);
|
2000-02-05 07:30:26 +00:00
|
|
|
|
|
|
|
struct EventNode
|
2001-10-18 12:20:49 +00:00
|
|
|
{ /* An event list node. */
|
|
|
|
unsigned (*func) (ARMul_State *); /* The function to call. */
|
2000-02-05 07:30:26 +00:00
|
|
|
struct EventNode *next;
|
|
|
|
};
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine returns the value of a register from a mode. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetReg (ARMul_State * state, unsigned mode, unsigned reg)
|
|
|
|
{
|
|
|
|
mode &= MODEBITS;
|
|
|
|
if (mode != state->Mode)
|
2000-05-30 17:13:37 +00:00
|
|
|
return (state->RegBank[ModeToBank ((ARMword) mode)][reg]);
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
|
|
|
return (state->Reg[reg]);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine sets the value of a register for a mode. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SetReg (ARMul_State * state, unsigned mode, unsigned reg, ARMword value)
|
|
|
|
{
|
|
|
|
mode &= MODEBITS;
|
|
|
|
if (mode != state->Mode)
|
2000-05-30 17:13:37 +00:00
|
|
|
state->RegBank[ModeToBank ((ARMword) mode)][reg] = value;
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
|
|
|
state->Reg[reg] = value;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine returns the value of the PC, mode independently. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetPC (ARMul_State * state)
|
|
|
|
{
|
|
|
|
if (state->Mode > SVC26MODE)
|
2001-10-18 12:20:49 +00:00
|
|
|
return state->Reg[15];
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
2001-10-18 12:20:49 +00:00
|
|
|
return R15PC;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine returns the value of the PC, mode independently. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetNextPC (ARMul_State * state)
|
|
|
|
{
|
|
|
|
if (state->Mode > SVC26MODE)
|
2001-10-18 12:20:49 +00:00
|
|
|
return state->Reg[15] + isize;
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
2001-10-18 12:20:49 +00:00
|
|
|
return (state->Reg[15] + isize) & R15PCBITS;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine sets the value of the PC. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SetPC (ARMul_State * state, ARMword value)
|
|
|
|
{
|
|
|
|
if (ARMul_MODE32BIT)
|
|
|
|
state->Reg[15] = value & PCBITS;
|
|
|
|
else
|
|
|
|
state->Reg[15] = R15CCINTMODE | (value & R15PCBITS);
|
|
|
|
FLUSHPIPE;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine returns the value of register 15, mode independently. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetR15 (ARMul_State * state)
|
|
|
|
{
|
|
|
|
if (state->Mode > SVC26MODE)
|
|
|
|
return (state->Reg[15]);
|
|
|
|
else
|
|
|
|
return (R15PC | ECC | ER15INT | EMODE);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine sets the value of Register 15. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SetR15 (ARMul_State * state, ARMword value)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
if (ARMul_MODE32BIT)
|
|
|
|
state->Reg[15] = value & PCBITS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->Reg[15] = value;
|
|
|
|
ARMul_R15Altered (state);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
FLUSHPIPE;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine returns the value of the CPSR. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetCPSR (ARMul_State * state)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-07-04 06:19:29 +00:00
|
|
|
return (CPSR | state->Cpsr);
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine sets the value of the CPSR. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SetCPSR (ARMul_State * state, ARMword value)
|
|
|
|
{
|
* armemu.h (PSR_FBITS, PSR_SBITS, PSR_XBITS, PSR_CBITS): New.
(SETPSR_F, SETPSR_S, SETPSR_X, SETPSR_C): New macros.
(SETPSR, SET_INTMODE, SETCC): Removed.
* armsupp.c (ARMul_FixCPSR, ARMul_FixSPSR): Do not test bit
mask. Use SETPSR_* to modify PSR.
(ARMul_SetCPSR): Load all bits from value.
* armemu.c (ARMul_Emulate, msr): Do not test bit mask.
2000-07-04 06:06:30 +00:00
|
|
|
state->Cpsr = value;
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMul_CPSRAltered (state);
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine does all the nasty bits involved in a write to the CPSR,
|
|
|
|
including updating the register bank, given a MSR instruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_FixCPSR (ARMul_State * state, ARMword instr, ARMword rhs)
|
|
|
|
{
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr = ARMul_GetCPSR (state);
|
2002-05-27 14:12:00 +00:00
|
|
|
|
2001-05-08 08:28:28 +00:00
|
|
|
if (state->Mode != USER26MODE
|
|
|
|
&& state->Mode != USER32MODE)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
|
|
|
/* In user mode, only write flags. */
|
* armemu.h (PSR_FBITS, PSR_SBITS, PSR_XBITS, PSR_CBITS): New.
(SETPSR_F, SETPSR_S, SETPSR_X, SETPSR_C): New macros.
(SETPSR, SET_INTMODE, SETCC): Removed.
* armsupp.c (ARMul_FixCPSR, ARMul_FixSPSR): Do not test bit
mask. Use SETPSR_* to modify PSR.
(ARMul_SetCPSR): Load all bits from value.
* armemu.c (ARMul_Emulate, msr): Do not test bit mask.
2000-07-04 06:06:30 +00:00
|
|
|
if (BIT (16))
|
|
|
|
SETPSR_C (state->Cpsr, rhs);
|
|
|
|
if (BIT (17))
|
|
|
|
SETPSR_X (state->Cpsr, rhs);
|
|
|
|
if (BIT (18))
|
|
|
|
SETPSR_S (state->Cpsr, rhs);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
* armemu.h (PSR_FBITS, PSR_SBITS, PSR_XBITS, PSR_CBITS): New.
(SETPSR_F, SETPSR_S, SETPSR_X, SETPSR_C): New macros.
(SETPSR, SET_INTMODE, SETCC): Removed.
* armsupp.c (ARMul_FixCPSR, ARMul_FixSPSR): Do not test bit
mask. Use SETPSR_* to modify PSR.
(ARMul_SetCPSR): Load all bits from value.
* armemu.c (ARMul_Emulate, msr): Do not test bit mask.
2000-07-04 06:06:30 +00:00
|
|
|
if (BIT (19))
|
|
|
|
SETPSR_F (state->Cpsr, rhs);
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMul_CPSRAltered (state);
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Get an SPSR from the specified mode. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_GetSPSR (ARMul_State * state, ARMword mode)
|
|
|
|
{
|
2000-05-30 17:13:37 +00:00
|
|
|
ARMword bank = ModeToBank (mode & MODEBITS);
|
|
|
|
|
|
|
|
if (! BANK_CAN_ACCESS_SPSR (bank))
|
2000-07-04 06:19:29 +00:00
|
|
|
return ARMul_GetCPSR (state);
|
2000-05-30 17:13:37 +00:00
|
|
|
|
|
|
|
return state->Spsr[bank];
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine does a write to an SPSR. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value)
|
|
|
|
{
|
2000-05-30 17:13:37 +00:00
|
|
|
ARMword bank = ModeToBank (mode & MODEBITS);
|
|
|
|
|
|
|
|
if (BANK_CAN_ACCESS_SPSR (bank))
|
2000-02-05 07:30:26 +00:00
|
|
|
state->Spsr[bank] = value;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine does a write to the current SPSR, given an MSR instruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_FixSPSR (ARMul_State * state, ARMword instr, ARMword rhs)
|
|
|
|
{
|
2000-05-30 17:13:37 +00:00
|
|
|
if (BANK_CAN_ACCESS_SPSR (state->Bank))
|
2000-02-05 07:30:26 +00:00
|
|
|
{
|
* armemu.h (PSR_FBITS, PSR_SBITS, PSR_XBITS, PSR_CBITS): New.
(SETPSR_F, SETPSR_S, SETPSR_X, SETPSR_C): New macros.
(SETPSR, SET_INTMODE, SETCC): Removed.
* armsupp.c (ARMul_FixCPSR, ARMul_FixSPSR): Do not test bit
mask. Use SETPSR_* to modify PSR.
(ARMul_SetCPSR): Load all bits from value.
* armemu.c (ARMul_Emulate, msr): Do not test bit mask.
2000-07-04 06:06:30 +00:00
|
|
|
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);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine updates the state of the emulator after the Cpsr has been
|
|
|
|
changed. Both the processor flags and register bank are updated. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_CPSRAltered (ARMul_State * state)
|
|
|
|
{
|
|
|
|
ARMword oldmode;
|
|
|
|
|
|
|
|
if (state->prog32Sig == LOW)
|
|
|
|
state->Cpsr &= (CCBITS | INTBITS | R15MODEBITS);
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
oldmode = state->Mode;
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->Mode != (state->Cpsr & MODEBITS))
|
|
|
|
{
|
|
|
|
state->Mode =
|
|
|
|
ARMul_SwitchMode (state, state->Mode, state->Cpsr & MODEBITS);
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~MODEBITS;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNINT (state->Cpsr & INTBITS);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~INTBITS;
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNN ((state->Cpsr & NBIT) != 0);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~NBIT;
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNZ ((state->Cpsr & ZBIT) != 0);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~ZBIT;
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNC ((state->Cpsr & CBIT) != 0);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~CBIT;
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNV ((state->Cpsr & VBIT) != 0);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~VBIT;
|
2000-11-30 01:55:12 +00:00
|
|
|
ASSIGNS ((state->Cpsr & SBIT) != 0);
|
|
|
|
state->Cpsr &= ~SBIT;
|
1999-04-16 01:35:26 +00:00
|
|
|
#ifdef MODET
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNT ((state->Cpsr & TBIT) != 0);
|
2000-07-04 06:19:29 +00:00
|
|
|
state->Cpsr &= ~TBIT;
|
1999-04-16 01:35:26 +00:00
|
|
|
#endif
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (oldmode > SVC26MODE)
|
|
|
|
{
|
|
|
|
if (state->Mode <= SVC26MODE)
|
|
|
|
{
|
|
|
|
state->Emulate = CHANGEMODE;
|
|
|
|
state->Reg[15] = ECC | ER15INT | EMODE | R15PC;
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (state->Mode > SVC26MODE)
|
|
|
|
{
|
|
|
|
state->Emulate = CHANGEMODE;
|
|
|
|
state->Reg[15] = R15PC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
state->Reg[15] = ECC | ER15INT | EMODE | R15PC;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* 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. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_R15Altered (ARMul_State * state)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->Mode != R15MODE)
|
|
|
|
{
|
|
|
|
state->Mode = ARMul_SwitchMode (state, state->Mode, R15MODE);
|
|
|
|
state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->Mode > SVC26MODE)
|
|
|
|
state->Emulate = CHANGEMODE;
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNR15INT (R15INT);
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNN ((state->Reg[15] & NBIT) != 0);
|
|
|
|
ASSIGNZ ((state->Reg[15] & ZBIT) != 0);
|
|
|
|
ASSIGNC ((state->Reg[15] & CBIT) != 0);
|
|
|
|
ASSIGNV ((state->Reg[15] & VBIT) != 0);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* 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. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_SwitchMode (ARMul_State * state, ARMword oldmode, ARMword newmode)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2000-05-30 17:13:37 +00:00
|
|
|
ARMword oldbank;
|
|
|
|
ARMword newbank;
|
|
|
|
|
|
|
|
oldbank = ModeToBank (oldmode);
|
|
|
|
newbank = state->Bank = ModeToBank (newmode);
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Do we really need to do it? */
|
2000-05-30 17:13:37 +00:00
|
|
|
if (oldbank != newbank)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
|
|
|
/* Save away the old registers. */
|
2000-05-30 17:13:37 +00:00
|
|
|
switch (oldbank)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
case USERBANK:
|
|
|
|
case IRQBANK:
|
|
|
|
case SVCBANK:
|
|
|
|
case ABORTBANK:
|
|
|
|
case UNDEFBANK:
|
2000-05-30 17:13:37 +00:00
|
|
|
if (newbank == FIQBANK)
|
2000-02-05 07:30:26 +00:00
|
|
|
for (i = 8; i < 13; i++)
|
|
|
|
state->RegBank[USERBANK][i] = state->Reg[i];
|
2000-05-30 17:13:37 +00:00
|
|
|
state->RegBank[oldbank][13] = state->Reg[13];
|
|
|
|
state->RegBank[oldbank][14] = state->Reg[14];
|
2000-02-05 07:30:26 +00:00
|
|
|
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;
|
2000-05-30 17:13:37 +00:00
|
|
|
default:
|
|
|
|
abort ();
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Restore the new registers. */
|
2000-05-30 17:13:37 +00:00
|
|
|
switch (newbank)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
case USERBANK:
|
|
|
|
case IRQBANK:
|
|
|
|
case SVCBANK:
|
|
|
|
case ABORTBANK:
|
|
|
|
case UNDEFBANK:
|
2000-05-30 17:13:37 +00:00
|
|
|
if (oldbank == FIQBANK)
|
2000-02-05 07:30:26 +00:00
|
|
|
for (i = 8; i < 13; i++)
|
|
|
|
state->Reg[i] = state->RegBank[USERBANK][i];
|
2000-05-30 17:13:37 +00:00
|
|
|
state->Reg[13] = state->RegBank[newbank][13];
|
|
|
|
state->Reg[14] = state->RegBank[newbank][14];
|
2000-02-05 07:30:26 +00:00
|
|
|
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;
|
2000-05-30 17:13:37 +00:00
|
|
|
default:
|
|
|
|
abort ();
|
2001-10-18 12:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-30 17:13:37 +00:00
|
|
|
|
|
|
|
return newmode;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Given a processor mode, this routine returns the
|
|
|
|
register bank that will be accessed in that mode. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
static ARMword
|
2000-05-30 17:13:37 +00:00
|
|
|
ModeToBank (ARMword mode)
|
2000-02-05 07:30:26 +00:00
|
|
|
{
|
2000-05-30 17:13:37 +00:00
|
|
|
static ARMword bankofmode[] =
|
|
|
|
{
|
|
|
|
USERBANK, FIQBANK, IRQBANK, SVCBANK,
|
2000-02-05 07:30:26 +00:00
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, DUMMYBANK,
|
2000-05-30 17:13:37 +00:00
|
|
|
USERBANK, FIQBANK, IRQBANK, SVCBANK,
|
2000-02-05 07:30:26 +00:00
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, ABORTBANK,
|
2000-05-30 17:13:37 +00:00
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, UNDEFBANK,
|
|
|
|
DUMMYBANK, DUMMYBANK, DUMMYBANK, SYSTEMBANK
|
2000-02-05 07:30:26 +00:00
|
|
|
};
|
|
|
|
|
2000-05-30 17:13:37 +00:00
|
|
|
if (mode >= (sizeof (bankofmode) / sizeof (bankofmode[0])))
|
|
|
|
return DUMMYBANK;
|
|
|
|
|
|
|
|
return bankofmode[mode];
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Returns the register number of the nth register in a reg list. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
unsigned
|
|
|
|
ARMul_NthReg (ARMword instr, unsigned number)
|
|
|
|
{
|
|
|
|
unsigned bit, upto;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
for (bit = 0, upto = 0; upto <= number; bit ++)
|
2000-02-05 07:30:26 +00:00
|
|
|
if (BIT (bit))
|
2001-10-18 12:20:49 +00:00
|
|
|
upto ++;
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
return (bit - 1);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Assigns the N and Z flags depending on the value of result. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_NegZero (ARMul_State * state, ARMword result)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
if (NEG (result))
|
|
|
|
{
|
|
|
|
SETN;
|
|
|
|
CLEARZ;
|
|
|
|
}
|
|
|
|
else if (result == 0)
|
|
|
|
{
|
|
|
|
CLEARN;
|
|
|
|
SETZ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLEARN;
|
|
|
|
CLEARZ;
|
2001-10-18 12:20:49 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-01-26 21:49:14 +00:00
|
|
|
/* Compute whether an addition of A and B, giving RESULT, overflowed. */
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
int
|
|
|
|
AddOverflow (ARMword a, ARMword b, ARMword result)
|
2000-01-26 21:49:14 +00:00
|
|
|
{
|
|
|
|
return ((NEG (a) && NEG (b) && POS (result))
|
|
|
|
|| (POS (a) && POS (b) && NEG (result)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute whether a subtraction of A and B, giving RESULT, overflowed. */
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
int
|
|
|
|
SubOverflow (ARMword a, ARMword b, ARMword result)
|
2000-01-26 21:49:14 +00:00
|
|
|
{
|
|
|
|
return ((NEG (a) && POS (b) && POS (result))
|
|
|
|
|| (POS (a) && NEG (b) && NEG (result)));
|
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Assigns the C flag after an addition of a and b to give result. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_AddCarry (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNC ((NEG (a) && NEG (b)) ||
|
|
|
|
(NEG (a) && POS (result)) || (NEG (b) && POS (result)));
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Assigns the V flag after an addition of a and b to give result. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_AddOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-01-26 21:49:14 +00:00
|
|
|
ASSIGNV (AddOverflow (a, b, result));
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Assigns the C flag after an subtraction of a and b to give result. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SubCarry (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
ASSIGNC ((NEG (a) && POS (b)) ||
|
|
|
|
(NEG (a) && POS (result)) || (POS (b) && POS (result)));
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Assigns the V flag after an subtraction of a and b to give result. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_SubOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-01-26 21:49:14 +00:00
|
|
|
ASSIGNV (SubOverflow (a, b, result));
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* 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. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_LDC (ARMul_State * state, ARMword instr, ARMword address)
|
|
|
|
{
|
|
|
|
unsigned cpab;
|
|
|
|
ARMword data;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
UNDEF_LSCPCBaseWb;
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
if (! CP_ACCESS_ALLOWED (state, CPNum))
|
2000-02-05 07:30:26 +00:00
|
|
|
{
|
2001-10-18 12:20:49 +00:00
|
|
|
ARMul_UndefInstr (state, instr);
|
|
|
|
return;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
if (ADDREXCEPT (address))
|
|
|
|
INTERNALABORT (address);
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_FIRST, instr, 0);
|
|
|
|
while (cpab == ARMul_BUSY)
|
|
|
|
{
|
|
|
|
ARMul_Icycles (state, 1, 0);
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (IntPending (state))
|
|
|
|
{
|
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_INTERRUPT, instr, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_BUSY, instr, 0);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
if (cpab == ARMul_CANT)
|
|
|
|
{
|
|
|
|
CPTAKEABORT;
|
|
|
|
return;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_TRANSFER, instr, 0);
|
|
|
|
data = ARMul_LoadWordN (state, address);
|
|
|
|
BUSUSEDINCPCN;
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (BIT (21))
|
|
|
|
LSBase = state->Base;
|
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_DATA, instr, data);
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
while (cpab == ARMul_INC)
|
|
|
|
{
|
|
|
|
address += 4;
|
|
|
|
data = ARMul_LoadWordN (state, address);
|
|
|
|
cpab = (state->LDC[CPNum]) (state, ARMul_DATA, instr, data);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->abortSig || state->Aborted)
|
2001-10-18 12:20:49 +00:00
|
|
|
TAKEABORT;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* 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. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_STC (ARMul_State * state, ARMword instr, ARMword address)
|
|
|
|
{
|
|
|
|
unsigned cpab;
|
|
|
|
ARMword data;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
UNDEF_LSCPCBaseWb;
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
if (! CP_ACCESS_ALLOWED (state, CPNum))
|
2000-02-05 07:30:26 +00:00
|
|
|
{
|
2001-10-18 12:20:49 +00:00
|
|
|
ARMul_UndefInstr (state, instr);
|
|
|
|
return;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
if (ADDREXCEPT (address) || VECTORACCESS (address))
|
|
|
|
INTERNALABORT (address);
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
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);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (cpab == ARMul_CANT)
|
|
|
|
{
|
|
|
|
CPTAKEABORT;
|
|
|
|
return;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
#ifndef MODE32
|
2000-02-05 07:30:26 +00:00
|
|
|
if (ADDREXCEPT (address) || VECTORACCESS (address))
|
2001-10-18 12:20:49 +00:00
|
|
|
INTERNALABORT (address);
|
1999-04-16 01:35:26 +00:00
|
|
|
#endif
|
2000-02-05 07:30:26 +00:00
|
|
|
BUSUSEDINCPCN;
|
|
|
|
if (BIT (21))
|
|
|
|
LSBase = state->Base;
|
|
|
|
cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
|
|
|
|
ARMul_StoreWordN (state, address, data);
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
while (cpab == ARMul_INC)
|
|
|
|
{
|
|
|
|
address += 4;
|
|
|
|
cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
|
|
|
|
ARMul_StoreWordN (state, address, data);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->abortSig || state->Aborted)
|
2001-10-18 12:20:49 +00:00
|
|
|
TAKEABORT;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This function does the Busy-Waiting for an MCR instruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_MCR (ARMul_State * state, ARMword instr, ARMword source)
|
|
|
|
{
|
|
|
|
unsigned cpab;
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
if (! CP_ACCESS_ALLOWED (state, CPNum))
|
|
|
|
{
|
|
|
|
ARMul_UndefInstr (state, instr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
cpab = (state->MCR[CPNum]) (state, ARMul_FIRST, instr, source);
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
while (cpab == ARMul_BUSY)
|
|
|
|
{
|
|
|
|
ARMul_Icycles (state, 1, 0);
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (IntPending (state))
|
|
|
|
{
|
|
|
|
cpab = (state->MCR[CPNum]) (state, ARMul_INTERRUPT, instr, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cpab = (state->MCR[CPNum]) (state, ARMul_BUSY, instr, source);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-05-30 17:13:37 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
if (cpab == ARMul_CANT)
|
|
|
|
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BUSUSEDINCPCN;
|
|
|
|
ARMul_Ccycles (state, 1, 0);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This function does the Busy-Waiting for an MRC instruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
|
|
|
ARMul_MRC (ARMul_State * state, ARMword instr)
|
|
|
|
{
|
|
|
|
unsigned cpab;
|
|
|
|
ARMword result = 0;
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
if (! CP_ACCESS_ALLOWED (state, CPNum))
|
|
|
|
{
|
|
|
|
ARMul_UndefInstr (state, instr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
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);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
if (cpab == ARMul_CANT)
|
|
|
|
{
|
|
|
|
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Parent will destroy the flags otherwise. */
|
|
|
|
result = ECC;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BUSUSEDINCPCN;
|
|
|
|
ARMul_Ccycles (state, 1, 0);
|
|
|
|
ARMul_Icycles (state, 1, 0);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
return result;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This function does the Busy-Waiting for an CDP instruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_CDP (ARMul_State * state, ARMword instr)
|
|
|
|
{
|
|
|
|
unsigned cpab;
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
if (! CP_ACCESS_ALLOWED (state, CPNum))
|
|
|
|
{
|
|
|
|
ARMul_UndefInstr (state, instr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
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);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
if (cpab == ARMul_CANT)
|
|
|
|
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
|
|
|
else
|
|
|
|
BUSUSEDN;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This function handles Undefined instructions, as CP isntruction. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
2000-02-08 20:54:27 +00:00
|
|
|
ARMul_UndefInstr (ARMul_State * state, ARMword instr ATTRIBUTE_UNUSED)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMul_Abort (state, ARMul_UndefinedInstrV);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Return TRUE if an interrupt is pending, FALSE otherwise. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
unsigned
|
|
|
|
IntPending (ARMul_State * state)
|
|
|
|
{
|
|
|
|
if (state->Exception)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
|
|
|
/* Any exceptions. */
|
2000-02-05 07:30:26 +00:00
|
|
|
if (state->NresetSig == LOW)
|
|
|
|
{
|
|
|
|
ARMul_Abort (state, ARMul_ResetV);
|
2001-10-18 12:20:49 +00:00
|
|
|
return TRUE;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
|
|
|
else if (!state->NfiqSig && !FFLAG)
|
|
|
|
{
|
|
|
|
ARMul_Abort (state, ARMul_FIQV);
|
2001-10-18 12:20:49 +00:00
|
|
|
return TRUE;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
|
|
|
else if (!state->NirqSig && !IFLAG)
|
|
|
|
{
|
|
|
|
ARMul_Abort (state, ARMul_IRQV);
|
2001-10-18 12:20:49 +00:00
|
|
|
return TRUE;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2001-10-18 12:20:49 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Align a word access to a non word boundary. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
ARMword
|
2000-02-08 20:54:27 +00:00
|
|
|
ARMul_Align (state, address, data)
|
|
|
|
ARMul_State * state ATTRIBUTE_UNUSED;
|
|
|
|
ARMword address;
|
|
|
|
ARMword data;
|
|
|
|
{
|
|
|
|
/* This code assumes the address is really unaligned,
|
|
|
|
as a shift by 32 is undefined in C. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
address = (address & 3) << 3; /* Get the word address. */
|
2000-02-05 07:30:26 +00:00
|
|
|
return ((data >> address) | (data << (32 - address))); /* rot right */
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine is used to call another routine after a certain number of
|
|
|
|
cycles have been executed. The first parameter is the number of cycles
|
|
|
|
delay before the function is called, the second argument is a pointer
|
|
|
|
to the function. A delay of zero doesn't work, just call the function. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_ScheduleEvent (ARMul_State * state, unsigned long delay,
|
2001-10-18 12:20:49 +00:00
|
|
|
unsigned (*what) (ARMul_State *))
|
2000-02-05 07:30:26 +00:00
|
|
|
{
|
|
|
|
unsigned long when;
|
|
|
|
struct EventNode *event;
|
|
|
|
|
|
|
|
if (state->EventSet++ == 0)
|
|
|
|
state->Now = ARMul_Time (state);
|
|
|
|
when = (state->Now + delay) % EVENTLISTSIZE;
|
|
|
|
event = (struct EventNode *) malloc (sizeof (struct EventNode));
|
|
|
|
event->func = what;
|
|
|
|
event->next = *(state->EventPtr + when);
|
|
|
|
*(state->EventPtr + when) = event;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine is called at the beginning of
|
|
|
|
every cycle, to envoke scheduled events. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
void
|
|
|
|
ARMul_EnvokeEvent (ARMul_State * state)
|
|
|
|
{
|
|
|
|
static unsigned long then;
|
|
|
|
|
|
|
|
then = state->Now;
|
|
|
|
state->Now = ARMul_Time (state) % EVENTLISTSIZE;
|
2001-10-18 12:20:49 +00:00
|
|
|
if (then < state->Now)
|
|
|
|
/* Schedule events. */
|
2000-02-05 07:30:26 +00:00
|
|
|
EnvokeList (state, then, state->Now);
|
|
|
|
else if (then > state->Now)
|
2001-10-18 12:20:49 +00:00
|
|
|
{
|
|
|
|
/* Need to wrap around the list. */
|
2000-02-05 07:30:26 +00:00
|
|
|
EnvokeList (state, then, EVENTLISTSIZE - 1L);
|
|
|
|
EnvokeList (state, 0L, state->Now);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* Envokes all the entries in a range. */
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
static void
|
|
|
|
EnvokeList (ARMul_State * state, unsigned long from, unsigned long to)
|
|
|
|
{
|
|
|
|
for (; from <= to; from++)
|
|
|
|
{
|
2001-10-18 12:20:49 +00:00
|
|
|
struct EventNode *anevent;
|
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
anevent = *(state->EventPtr + from);
|
|
|
|
while (anevent)
|
|
|
|
{
|
|
|
|
(anevent->func) (state);
|
|
|
|
state->EventSet--;
|
|
|
|
anevent = anevent->next;
|
|
|
|
}
|
|
|
|
*(state->EventPtr + from) = NULL;
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
2000-02-05 07:30:26 +00:00
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-10-18 12:20:49 +00:00
|
|
|
/* This routine is returns the number of clock ticks since the last reset. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2000-02-05 07:30:26 +00:00
|
|
|
unsigned long
|
|
|
|
ARMul_Time (ARMul_State * state)
|
|
|
|
{
|
|
|
|
return (state->NumScycles + state->NumNcycles +
|
|
|
|
state->NumIcycles + state->NumCcycles + state->NumFcycles);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|