Home | History | Annotate | Line # | Download | only in arm
armemu.h revision 1.5
      1  1.1  christos /*  armemu.h -- ARMulator emulation macros:  ARM6 Instruction Emulator.
      2  1.1  christos     Copyright (C) 1994 Advanced RISC Machines Ltd.
      3  1.1  christos 
      4  1.1  christos     This program is free software; you can redistribute it and/or modify
      5  1.1  christos     it under the terms of the GNU General Public License as published by
      6  1.1  christos     the Free Software Foundation; either version 3 of the License, or
      7  1.1  christos     (at your option) any later version.
      8  1.1  christos 
      9  1.1  christos     This program is distributed in the hope that it will be useful,
     10  1.1  christos     but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  1.1  christos     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  1.1  christos     GNU General Public License for more details.
     13  1.1  christos 
     14  1.1  christos     You should have received a copy of the GNU General Public License
     15  1.1  christos     along with this program; if not, see <http://www.gnu.org/licenses/>. */
     16  1.1  christos 
     17  1.1  christos extern ARMword isize;
     18  1.3  christos extern int trace;
     19  1.3  christos extern int disas;
     20  1.3  christos extern int trace_funcs;
     21  1.3  christos extern void print_insn (ARMword);
     22  1.1  christos 
     23  1.1  christos /* Condition code values.  */
     24  1.1  christos #define EQ 0
     25  1.1  christos #define NE 1
     26  1.1  christos #define CS 2
     27  1.1  christos #define CC 3
     28  1.1  christos #define MI 4
     29  1.1  christos #define PL 5
     30  1.1  christos #define VS 6
     31  1.1  christos #define VC 7
     32  1.1  christos #define HI 8
     33  1.1  christos #define LS 9
     34  1.1  christos #define GE 10
     35  1.1  christos #define LT 11
     36  1.1  christos #define GT 12
     37  1.1  christos #define LE 13
     38  1.1  christos #define AL 14
     39  1.1  christos #define NV 15
     40  1.1  christos 
     41  1.1  christos /* Shift Opcodes.  */
     42  1.1  christos #define LSL 0
     43  1.1  christos #define LSR 1
     44  1.1  christos #define ASR 2
     45  1.1  christos #define ROR 3
     46  1.1  christos 
     47  1.1  christos /* Macros to twiddle the status flags and mode.  */
     48  1.1  christos #define NBIT ((unsigned)1L << 31)
     49  1.1  christos #define ZBIT (1L << 30)
     50  1.1  christos #define CBIT (1L << 29)
     51  1.1  christos #define VBIT (1L << 28)
     52  1.1  christos #define SBIT (1L << 27)
     53  1.3  christos #define GE0 (1L << 16)
     54  1.3  christos #define GE1 (1L << 17)
     55  1.3  christos #define GE2 (1L << 18)
     56  1.3  christos #define GE3 (1L << 19)
     57  1.1  christos #define IBIT (1L << 7)
     58  1.1  christos #define FBIT (1L << 6)
     59  1.1  christos #define IFBITS (3L << 6)
     60  1.1  christos #define R15IBIT (1L << 27)
     61  1.1  christos #define R15FBIT (1L << 26)
     62  1.1  christos #define R15IFBITS (3L << 26)
     63  1.1  christos 
     64  1.1  christos #define POS(i) ( (~(i)) >> 31 )
     65  1.1  christos #define NEG(i) ( (i) >> 31 )
     66  1.1  christos 
     67  1.1  christos #ifdef MODET			/* Thumb support.  */
     68  1.1  christos /* ??? This bit is actually in the low order bit of the PC in the hardware.
     69  1.1  christos    It isn't clear if the simulator needs to model that or not.  */
     70  1.1  christos #define TBIT (1L << 5)
     71  1.1  christos #define TFLAG state->TFlag
     72  1.1  christos #define SETT state->TFlag = 1
     73  1.1  christos #define CLEART state->TFlag = 0
     74  1.1  christos #define ASSIGNT(res) state->TFlag = res
     75  1.1  christos #define INSN_SIZE (TFLAG ? 2 : 4)
     76  1.1  christos #else
     77  1.1  christos #define INSN_SIZE 4
     78  1.1  christos #endif
     79  1.1  christos 
     80  1.1  christos #define NFLAG state->NFlag
     81  1.1  christos #define SETN state->NFlag = 1
     82  1.1  christos #define CLEARN state->NFlag = 0
     83  1.1  christos #define ASSIGNN(res) state->NFlag = res
     84  1.1  christos 
     85  1.1  christos #define ZFLAG state->ZFlag
     86  1.1  christos #define SETZ state->ZFlag = 1
     87  1.1  christos #define CLEARZ state->ZFlag = 0
     88  1.1  christos #define ASSIGNZ(res) state->ZFlag = res
     89  1.1  christos 
     90  1.1  christos #define CFLAG state->CFlag
     91  1.1  christos #define SETC state->CFlag = 1
     92  1.1  christos #define CLEARC state->CFlag = 0
     93  1.1  christos #define ASSIGNC(res) state->CFlag = res
     94  1.1  christos 
     95  1.1  christos #define VFLAG state->VFlag
     96  1.1  christos #define SETV state->VFlag = 1
     97  1.1  christos #define CLEARV state->VFlag = 0
     98  1.1  christos #define ASSIGNV(res) state->VFlag = res
     99  1.1  christos 
    100  1.1  christos #define SFLAG state->SFlag
    101  1.1  christos #define SETS state->SFlag = 1
    102  1.1  christos #define CLEARS state->SFlag = 0
    103  1.1  christos #define ASSIGNS(res) state->SFlag = res
    104  1.1  christos 
    105  1.1  christos #define IFLAG (state->IFFlags >> 1)
    106  1.1  christos #define FFLAG (state->IFFlags & 1)
    107  1.1  christos #define IFFLAGS state->IFFlags
    108  1.1  christos #define ASSIGNINT(res) state->IFFlags = (((res) >> 6) & 3)
    109  1.1  christos #define ASSIGNR15INT(res) state->IFFlags = (((res) >> 26) & 3) ;
    110  1.1  christos 
    111  1.1  christos #define PSR_FBITS (0xff000000L)
    112  1.1  christos #define PSR_SBITS (0x00ff0000L)
    113  1.1  christos #define PSR_XBITS (0x0000ff00L)
    114  1.1  christos #define PSR_CBITS (0x000000ffL)
    115  1.1  christos 
    116  1.1  christos #if defined MODE32 || defined MODET
    117  1.1  christos #define CCBITS (0xf8000000L)
    118  1.1  christos #else
    119  1.1  christos #define CCBITS (0xf0000000L)
    120  1.1  christos #endif
    121  1.1  christos 
    122  1.1  christos #define INTBITS (0xc0L)
    123  1.1  christos 
    124  1.1  christos #if defined MODET && defined MODE32
    125  1.1  christos #define PCBITS (0xffffffffL)
    126  1.1  christos #else
    127  1.1  christos #define PCBITS (0xfffffffcL)
    128  1.1  christos #endif
    129  1.1  christos 
    130  1.1  christos #define MODEBITS (0x1fL)
    131  1.1  christos #define R15INTBITS (3L << 26)
    132  1.1  christos 
    133  1.1  christos #if defined MODET && defined MODE32
    134  1.1  christos #define R15PCBITS (0x03ffffffL)
    135  1.1  christos #else
    136  1.1  christos #define R15PCBITS (0x03fffffcL)
    137  1.1  christos #endif
    138  1.1  christos 
    139  1.1  christos #define R15PCMODEBITS (0x03ffffffL)
    140  1.1  christos #define R15MODEBITS (0x3L)
    141  1.1  christos 
    142  1.1  christos #ifdef MODE32
    143  1.1  christos #define PCMASK PCBITS
    144  1.1  christos #define PCWRAP(pc) (pc)
    145  1.1  christos #else
    146  1.1  christos #define PCMASK R15PCBITS
    147  1.1  christos #define PCWRAP(pc) ((pc) & R15PCBITS)
    148  1.1  christos #endif
    149  1.1  christos 
    150  1.1  christos #define PC (state->Reg[15] & PCMASK)
    151  1.1  christos #define R15CCINTMODE (state->Reg[15] & (CCBITS | R15INTBITS | R15MODEBITS))
    152  1.1  christos #define R15INT (state->Reg[15] & R15INTBITS)
    153  1.1  christos #define R15INTPC (state->Reg[15] & (R15INTBITS | R15PCBITS))
    154  1.1  christos #define R15INTPCMODE (state->Reg[15] & (R15INTBITS | R15PCBITS | R15MODEBITS))
    155  1.1  christos #define R15INTMODE (state->Reg[15] & (R15INTBITS | R15MODEBITS))
    156  1.1  christos #define R15PC (state->Reg[15] & R15PCBITS)
    157  1.1  christos #define R15PCMODE (state->Reg[15] & (R15PCBITS | R15MODEBITS))
    158  1.1  christos #define R15MODE (state->Reg[15] & R15MODEBITS)
    159  1.1  christos 
    160  1.1  christos #define ECC ((NFLAG << 31) | (ZFLAG << 30) | (CFLAG << 29) | (VFLAG << 28) | (SFLAG << 27))
    161  1.1  christos #define EINT (IFFLAGS << 6)
    162  1.1  christos #define ER15INT (IFFLAGS << 26)
    163  1.1  christos #define EMODE (state->Mode)
    164  1.1  christos 
    165  1.1  christos #ifdef MODET
    166  1.1  christos #define CPSR (ECC | EINT | EMODE | (TFLAG << 5))
    167  1.1  christos #else
    168  1.1  christos #define CPSR (ECC | EINT | EMODE)
    169  1.1  christos #endif
    170  1.1  christos 
    171  1.1  christos #ifdef MODE32
    172  1.1  christos #define PATCHR15
    173  1.1  christos #else
    174  1.1  christos #define PATCHR15 state->Reg[15] = ECC | ER15INT | EMODE | R15PC
    175  1.1  christos #endif
    176  1.1  christos 
    177  1.1  christos #define GETSPSR(bank) (ARMul_GetSPSR (state, EMODE))
    178  1.1  christos #define SETPSR_F(d,s) d = ((d) & ~PSR_FBITS) | ((s) & PSR_FBITS)
    179  1.1  christos #define SETPSR_S(d,s) d = ((d) & ~PSR_SBITS) | ((s) & PSR_SBITS)
    180  1.1  christos #define SETPSR_X(d,s) d = ((d) & ~PSR_XBITS) | ((s) & PSR_XBITS)
    181  1.1  christos #define SETPSR_C(d,s) d = ((d) & ~PSR_CBITS) | ((s) & PSR_CBITS)
    182  1.1  christos 
    183  1.1  christos #define SETR15PSR(s) 								\
    184  1.1  christos   do										\
    185  1.1  christos     {										\
    186  1.1  christos       if (state->Mode == USER26MODE)						\
    187  1.1  christos         {									\
    188  1.1  christos           state->Reg[15] = ((s) & CCBITS) | R15PC | ER15INT | EMODE;		\
    189  1.1  christos           ASSIGNN ((state->Reg[15] & NBIT) != 0);				\
    190  1.1  christos           ASSIGNZ ((state->Reg[15] & ZBIT) != 0);				\
    191  1.1  christos           ASSIGNC ((state->Reg[15] & CBIT) != 0);				\
    192  1.1  christos           ASSIGNV ((state->Reg[15] & VBIT) != 0);				\
    193  1.1  christos         }									\
    194  1.1  christos       else									\
    195  1.1  christos         {									\
    196  1.1  christos           state->Reg[15] = R15PC | ((s) & (CCBITS | R15INTBITS | R15MODEBITS));	\
    197  1.1  christos           ARMul_R15Altered (state);						\
    198  1.1  christos        }									\
    199  1.1  christos     }										\
    200  1.1  christos   while (0)
    201  1.1  christos 
    202  1.1  christos #define SETABORT(i, m, d)						\
    203  1.1  christos   do									\
    204  1.1  christos     { 									\
    205  1.1  christos       int SETABORT_mode = (m);						\
    206  1.1  christos 									\
    207  1.1  christos       ARMul_SetSPSR (state, SETABORT_mode, ARMul_GetCPSR (state));	\
    208  1.1  christos       ARMul_SetCPSR (state, ((ARMul_GetCPSR (state) & ~(EMODE | TBIT))	\
    209  1.1  christos 			     | (i) | SETABORT_mode));			\
    210  1.1  christos       state->Reg[14] = temp - (d);					\
    211  1.1  christos     }									\
    212  1.1  christos   while (0)
    213  1.1  christos 
    214  1.1  christos #ifndef MODE32
    215  1.1  christos #define VECTORS 0x20
    216  1.1  christos #define LEGALADDR 0x03ffffff
    217  1.1  christos #define VECTORACCESS(address) (address < VECTORS && ARMul_MODE26BIT && state->prog32Sig)
    218  1.1  christos #define ADDREXCEPT(address)   (address > LEGALADDR && !state->data32Sig)
    219  1.1  christos #endif
    220  1.1  christos 
    221  1.1  christos #define INTERNALABORT(address)			\
    222  1.1  christos   do						\
    223  1.1  christos     {						\
    224  1.1  christos       if (address < VECTORS)			\
    225  1.1  christos 	state->Aborted = ARMul_DataAbortV;	\
    226  1.1  christos       else					\
    227  1.1  christos 	state->Aborted = ARMul_AddrExceptnV;	\
    228  1.1  christos     }						\
    229  1.1  christos   while (0)
    230  1.1  christos 
    231  1.1  christos #ifdef MODE32
    232  1.1  christos #define TAKEABORT ARMul_Abort (state, ARMul_DataAbortV)
    233  1.1  christos #else
    234  1.1  christos #define TAKEABORT 					\
    235  1.1  christos   do							\
    236  1.1  christos     {							\
    237  1.1  christos       if (state->Aborted == ARMul_AddrExceptnV) 	\
    238  1.1  christos 	ARMul_Abort (state, ARMul_AddrExceptnV); 	\
    239  1.1  christos       else 						\
    240  1.1  christos 	ARMul_Abort (state, ARMul_DataAbortV);		\
    241  1.1  christos     }							\
    242  1.1  christos   while (0)
    243  1.1  christos #endif
    244  1.1  christos 
    245  1.1  christos #define CPTAKEABORT					\
    246  1.1  christos   do							\
    247  1.1  christos     {							\
    248  1.1  christos       if (!state->Aborted)				\
    249  1.1  christos 	ARMul_Abort (state, ARMul_UndefinedInstrV); 	\
    250  1.1  christos       else if (state->Aborted == ARMul_AddrExceptnV) 	\
    251  1.1  christos 	ARMul_Abort (state, ARMul_AddrExceptnV); 	\
    252  1.1  christos       else 						\
    253  1.1  christos 	ARMul_Abort (state, ARMul_DataAbortV);		\
    254  1.1  christos     }							\
    255  1.1  christos   while (0);
    256  1.1  christos 
    257  1.1  christos 
    258  1.1  christos /* Different ways to start the next instruction.  */
    259  1.1  christos #define SEQ           0
    260  1.1  christos #define NONSEQ        1
    261  1.1  christos #define PCINCEDSEQ    2
    262  1.1  christos #define PCINCEDNONSEQ 3
    263  1.1  christos #define PRIMEPIPE     4
    264  1.1  christos #define RESUME        8
    265  1.1  christos 
    266  1.1  christos #define NORMALCYCLE state->NextInstr = 0
    267  1.1  christos #define BUSUSEDN    state->NextInstr |= 1  /* The next fetch will be an N cycle.  */
    268  1.1  christos #define BUSUSEDINCPCS						\
    269  1.1  christos   do								\
    270  1.1  christos     {								\
    271  1.1  christos       if (! state->is_v4)					\
    272  1.1  christos         {							\
    273  1.1  christos 	  /* A standard PC inc and an S cycle.  */		\
    274  1.1  christos 	  state->Reg[15] += isize;				\
    275  1.1  christos 	  state->NextInstr = (state->NextInstr & 0xff) | 2;	\
    276  1.1  christos 	}							\
    277  1.1  christos     }								\
    278  1.1  christos   while (0)
    279  1.1  christos 
    280  1.1  christos #define BUSUSEDINCPCN					\
    281  1.1  christos   do							\
    282  1.1  christos     {							\
    283  1.1  christos       if (state->is_v4)					\
    284  1.1  christos 	BUSUSEDN;					\
    285  1.1  christos       else						\
    286  1.1  christos 	{						\
    287  1.1  christos 	  /* A standard PC inc and an N cycle.  */	\
    288  1.1  christos 	  state->Reg[15] += isize;			\
    289  1.1  christos 	  state->NextInstr |= 3;			\
    290  1.1  christos 	}						\
    291  1.1  christos     }							\
    292  1.1  christos   while (0)
    293  1.1  christos 
    294  1.1  christos #define INCPC 			\
    295  1.1  christos   do				\
    296  1.1  christos     {				\
    297  1.1  christos       /* A standard PC inc.  */	\
    298  1.1  christos       state->Reg[15] += isize;	\
    299  1.1  christos       state->NextInstr |= 2;	\
    300  1.1  christos     }				\
    301  1.1  christos   while (0)
    302  1.1  christos 
    303  1.1  christos #define FLUSHPIPE state->NextInstr |= PRIMEPIPE
    304  1.1  christos 
    305  1.1  christos /* Cycle based emulation.  */
    306  1.1  christos 
    307  1.1  christos #define OUTPUTCP(i,a,b)
    308  1.1  christos #define NCYCLE
    309  1.1  christos #define SCYCLE
    310  1.1  christos #define ICYCLE
    311  1.1  christos #define CCYCLE
    312  1.1  christos #define NEXTCYCLE(c)
    313  1.1  christos 
    314  1.1  christos /* Macros to extract parts of instructions.  */
    315  1.1  christos #define DESTReg (BITS (12, 15))
    316  1.1  christos #define LHSReg  (BITS (16, 19))
    317  1.1  christos #define RHSReg  (BITS ( 0,  3))
    318  1.1  christos 
    319  1.1  christos #define DEST (state->Reg[DESTReg])
    320  1.1  christos 
    321  1.1  christos #ifdef MODE32
    322  1.1  christos #ifdef MODET
    323  1.1  christos #define LHS ((LHSReg == 15) ? (state->Reg[15] & 0xFFFFFFFC): (state->Reg[LHSReg]))
    324  1.1  christos #else
    325  1.1  christos #define LHS (state->Reg[LHSReg])
    326  1.1  christos #endif
    327  1.1  christos #else
    328  1.1  christos #define LHS ((LHSReg == 15) ? R15PC : (state->Reg[LHSReg]))
    329  1.1  christos #endif
    330  1.1  christos 
    331  1.1  christos #define MULDESTReg (BITS (16, 19))
    332  1.1  christos #define MULLHSReg  (BITS ( 0,  3))
    333  1.1  christos #define MULRHSReg  (BITS ( 8, 11))
    334  1.1  christos #define MULACCReg  (BITS (12, 15))
    335  1.1  christos 
    336  1.1  christos #define DPImmRHS (ARMul_ImmedTable[BITS(0, 11)])
    337  1.1  christos #define DPSImmRHS temp = BITS(0,11) ; \
    338  1.1  christos                   rhs = ARMul_ImmedTable[temp] ; \
    339  1.1  christos                   if (temp > 255) /* There was a shift.  */ \
    340  1.1  christos                      ASSIGNC (rhs >> 31) ;
    341  1.1  christos 
    342  1.1  christos #ifdef MODE32
    343  1.1  christos #define DPRegRHS  ((BITS (4,11) == 0) ? state->Reg[RHSReg] \
    344  1.1  christos                                       : GetDPRegRHS (state, instr))
    345  1.1  christos #define DPSRegRHS ((BITS (4,11) == 0) ? state->Reg[RHSReg] \
    346  1.1  christos                                       : GetDPSRegRHS (state, instr))
    347  1.1  christos #else
    348  1.1  christos #define DPRegRHS  ((BITS (0, 11) < 15) ? state->Reg[RHSReg] \
    349  1.1  christos                                        : GetDPRegRHS (state, instr))
    350  1.1  christos #define DPSRegRHS ((BITS (0, 11) < 15) ? state->Reg[RHSReg] \
    351  1.1  christos                                        : GetDPSRegRHS (state, instr))
    352  1.1  christos #endif
    353  1.1  christos 
    354  1.1  christos #define LSBase state->Reg[LHSReg]
    355  1.1  christos #define LSImmRHS (BITS(0,11))
    356  1.1  christos 
    357  1.1  christos #ifdef MODE32
    358  1.1  christos #define LSRegRHS ((BITS (4, 11) == 0) ? state->Reg[RHSReg] \
    359  1.1  christos                                       : GetLSRegRHS (state, instr))
    360  1.1  christos #else
    361  1.1  christos #define LSRegRHS ((BITS (0, 11) < 15) ? state->Reg[RHSReg] \
    362  1.1  christos                                       : GetLSRegRHS (state, instr))
    363  1.1  christos #endif
    364  1.1  christos 
    365  1.1  christos #define LSMNumRegs ((ARMword) ARMul_BitList[BITS (0, 7)] + \
    366  1.1  christos                     (ARMword) ARMul_BitList[BITS (8, 15)] )
    367  1.1  christos #define LSMBaseFirst ((LHSReg == 0 && BIT (0)) || \
    368  1.1  christos                       (BIT (LHSReg) && BITS (0, LHSReg - 1) == 0))
    369  1.1  christos 
    370  1.1  christos #define SWAPSRC (state->Reg[RHSReg])
    371  1.1  christos 
    372  1.1  christos #define LSCOff (BITS (0, 7) << 2)
    373  1.1  christos #define CPNum   BITS (8, 11)
    374  1.1  christos 
    375  1.1  christos /* Determine if access to coprocessor CP is permitted.
    376  1.1  christos    The XScale has a register in CP15 which controls access to CP0 - CP13.  */
    377  1.1  christos #define CP_ACCESS_ALLOWED(STATE, CP)			\
    378  1.1  christos     (   ((CP) >= 14)					\
    379  1.1  christos      || (! (STATE)->is_XScale)				\
    380  1.1  christos      || (read_cp15_reg (15, 0, 1) & (1 << (CP))))
    381  1.1  christos 
    382  1.1  christos /* Macro to rotate n right by b bits.  */
    383  1.1  christos #define ROTATER(n, b) (((n) >> (b)) | ((n) << (32 - (b))))
    384  1.1  christos 
    385  1.1  christos /* Macros to store results of instructions.  */
    386  1.1  christos #define WRITEDEST(d)				\
    387  1.1  christos   do						\
    388  1.1  christos     {						\
    389  1.1  christos       if (DESTReg == 15) 			\
    390  1.1  christos 	WriteR15 (state, d); 			\
    391  1.1  christos       else 					\
    392  1.1  christos 	DEST = d;				\
    393  1.1  christos     }						\
    394  1.1  christos   while (0)
    395  1.1  christos 
    396  1.1  christos #define WRITESDEST(d)				\
    397  1.1  christos   do						\
    398  1.1  christos     {						\
    399  1.1  christos       if (DESTReg == 15)			\
    400  1.1  christos 	WriteSR15 (state, d);			\
    401  1.1  christos       else					\
    402  1.1  christos 	{					\
    403  1.1  christos 	  DEST = d;				\
    404  1.1  christos 	  ARMul_NegZero (state, d);		\
    405  1.1  christos 	}					\
    406  1.1  christos     }						\
    407  1.1  christos   while (0)
    408  1.1  christos 
    409  1.1  christos #define WRITEDESTB(d)				\
    410  1.1  christos   do						\
    411  1.1  christos     {						\
    412  1.1  christos       if (DESTReg == 15)			\
    413  1.3  christos 	WriteR15Load (state, d);		\
    414  1.1  christos       else					\
    415  1.1  christos 	DEST = d;				\
    416  1.1  christos     }						\
    417  1.1  christos   while (0)
    418  1.1  christos 
    419  1.1  christos #define BYTETOBUS(data) ((data & 0xff) | \
    420  1.1  christos                         ((data & 0xff) << 8) | \
    421  1.1  christos                         ((data & 0xff) << 16) | \
    422  1.1  christos                         ((data & 0xff) << 24))
    423  1.1  christos 
    424  1.1  christos #define BUSTOBYTE(address, data)				\
    425  1.1  christos   do								\
    426  1.1  christos     {								\
    427  1.1  christos       if (state->bigendSig) 					\
    428  1.1  christos 	temp = (data >> (((address ^ 3) & 3) << 3)) & 0xff;	\
    429  1.1  christos       else							\
    430  1.1  christos 	temp = (data >> ((address & 3) << 3)) & 0xff;		\
    431  1.1  christos     }								\
    432  1.1  christos   while (0)
    433  1.1  christos 
    434  1.1  christos #define LOADMULT(instr,   address, wb)  LoadMult   (state, instr, address, wb)
    435  1.1  christos #define LOADSMULT(instr,  address, wb)  LoadSMult  (state, instr, address, wb)
    436  1.1  christos #define STOREMULT(instr,  address, wb)  StoreMult  (state, instr, address, wb)
    437  1.1  christos #define STORESMULT(instr, address, wb)  StoreSMult (state, instr, address, wb)
    438  1.1  christos 
    439  1.1  christos #define POSBRANCH ((instr & 0x7fffff) << 2)
    440  1.1  christos #define NEGBRANCH ((0xff000000 |(instr & 0xffffff)) << 2)
    441  1.1  christos 
    442  1.1  christos 
    443  1.1  christos /* Values for Emulate.  */
    444  1.1  christos #define STOP            0	/* stop */
    445  1.1  christos #define CHANGEMODE      1	/* change mode */
    446  1.1  christos #define ONCE            2	/* execute just one interation */
    447  1.1  christos #define RUN             3	/* continuous execution */
    448  1.1  christos 
    449  1.1  christos /* Stuff that is shared across modes.  */
    450  1.1  christos extern unsigned ARMul_MultTable[];	/* Number of I cycles for a mult.  */
    451  1.1  christos extern ARMword  ARMul_ImmedTable[];	/* Immediate DP LHS values.  */
    452  1.1  christos extern char     ARMul_BitList[];	/* Number of bits in a byte table.  */
    453  1.1  christos 
    454  1.1  christos #define EVENTLISTSIZE 1024L
    455  1.1  christos 
    456  1.1  christos /* Thumb support.  */
    457  1.1  christos typedef enum
    458  1.1  christos {
    459  1.1  christos   t_undefined,		/* Undefined Thumb instruction.  */
    460  1.1  christos   t_decoded,		/* Instruction decoded to ARM equivalent.  */
    461  1.1  christos   t_branch		/* Thumb branch (already processed).  */
    462  1.1  christos }
    463  1.1  christos tdstate;
    464  1.1  christos 
    465  1.5  christos #define t_resolved t_branch
    466  1.5  christos 
    467  1.5  christos /* Macros to scrutinize instructions.  The dummy do loop is to keep the compiler
    468  1.5  christos    happy when the statement is used in an otherwise empty else statement.  */
    469  1.5  christos #define UNDEF_Test		do { ; } while (0)
    470  1.5  christos #define UNDEF_Shift		do { ; } while (0)
    471  1.5  christos #define UNDEF_MSRPC		do { ; } while (0)
    472  1.5  christos #define UNDEF_MRSPC		do { ; } while (0)
    473  1.5  christos #define UNDEF_MULPCDest		do { ; } while (0)
    474  1.5  christos #define UNDEF_MULDestEQOp1	do { ; } while (0)
    475  1.5  christos #define UNDEF_LSRBPC		do { ; } while (0)
    476  1.5  christos #define UNDEF_LSRBaseEQOffWb	do { ; } while (0)
    477  1.5  christos #define UNDEF_LSRBaseEQDestWb	do { ; } while (0)
    478  1.5  christos #define UNDEF_LSRPCBaseWb	do { ; } while (0)
    479  1.5  christos #define UNDEF_LSRPCOffWb	do { ; } while (0)
    480  1.5  christos #define UNDEF_LSMNoRegs		do { ; } while (0)
    481  1.5  christos #define UNDEF_LSMPCBase		do { ; } while (0)
    482  1.5  christos #define UNDEF_LSMUserBankWb	do { ; } while (0)
    483  1.5  christos #define UNDEF_LSMBaseInListWb	do { ; } while (0)
    484  1.5  christos #define UNDEF_SWPPC		do { ; } while (0)
    485  1.5  christos #define UNDEF_CoProHS		do { ; } while (0)
    486  1.5  christos #define UNDEF_MCRPC		do { ; } while (0)
    487  1.5  christos #define UNDEF_LSCPCBaseWb	do { ; } while (0)
    488  1.5  christos #define UNDEF_UndefNotBounced	do { ; } while (0)
    489  1.5  christos #define UNDEF_ShortInt		do { ; } while (0)
    490  1.5  christos #define UNDEF_IllegalMode	do { ; } while (0)
    491  1.5  christos #define UNDEF_Prog32SigChange	do { ; } while (0)
    492  1.5  christos #define UNDEF_Data32SigChange	do { ; } while (0)
    493  1.1  christos 
    494  1.1  christos /* Prototypes for exported functions.  */
    495  1.1  christos extern unsigned ARMul_NthReg        (ARMword, unsigned);
    496  1.1  christos extern int      AddOverflow         (ARMword, ARMword, ARMword);
    497  1.1  christos extern int      SubOverflow         (ARMword, ARMword, ARMword);
    498  1.1  christos extern ARMword  ARMul_Emulate26     (ARMul_State *);
    499  1.1  christos extern ARMword  ARMul_Emulate32     (ARMul_State *);
    500  1.1  christos extern unsigned IntPending          (ARMul_State *);
    501  1.1  christos extern void     ARMul_CPSRAltered   (ARMul_State *);
    502  1.1  christos extern void     ARMul_R15Altered    (ARMul_State *);
    503  1.1  christos extern ARMword  ARMul_GetPC         (ARMul_State *);
    504  1.1  christos extern ARMword  ARMul_GetNextPC     (ARMul_State *);
    505  1.1  christos extern ARMword  ARMul_GetR15        (ARMul_State *);
    506  1.1  christos extern ARMword  ARMul_GetCPSR       (ARMul_State *);
    507  1.1  christos extern void     ARMul_EnvokeEvent   (ARMul_State *);
    508  1.1  christos extern unsigned long ARMul_Time     (ARMul_State *);
    509  1.1  christos extern void     ARMul_NegZero       (ARMul_State *, ARMword);
    510  1.1  christos extern void     ARMul_SetPC         (ARMul_State *, ARMword);
    511  1.1  christos extern void     ARMul_SetR15        (ARMul_State *, ARMword);
    512  1.1  christos extern void     ARMul_SetCPSR       (ARMul_State *, ARMword);
    513  1.1  christos extern ARMword  ARMul_GetSPSR       (ARMul_State *, ARMword);
    514  1.1  christos extern void     ARMul_Abort26       (ARMul_State *, ARMword);
    515  1.1  christos extern void     ARMul_Abort32       (ARMul_State *, ARMword);
    516  1.1  christos extern ARMword  ARMul_MRC           (ARMul_State *, ARMword);
    517  1.1  christos extern void     ARMul_CDP           (ARMul_State *, ARMword);
    518  1.1  christos extern void     ARMul_LDC           (ARMul_State *, ARMword, ARMword);
    519  1.1  christos extern void     ARMul_STC           (ARMul_State *, ARMword, ARMword);
    520  1.1  christos extern void     ARMul_MCR           (ARMul_State *, ARMword, ARMword);
    521  1.1  christos extern void     ARMul_SetSPSR       (ARMul_State *, ARMword, ARMword);
    522  1.1  christos extern ARMword  ARMul_SwitchMode    (ARMul_State *, ARMword, ARMword);
    523  1.1  christos extern ARMword  ARMul_Align         (ARMul_State *, ARMword, ARMword);
    524  1.1  christos extern ARMword  ARMul_SwitchMode    (ARMul_State *, ARMword, ARMword);
    525  1.1  christos extern void     ARMul_MSRCpsr       (ARMul_State *, ARMword, ARMword);
    526  1.1  christos extern void     ARMul_SubOverflow   (ARMul_State *, ARMword, ARMword, ARMword);
    527  1.1  christos extern void     ARMul_AddOverflow   (ARMul_State *, ARMword, ARMword, ARMword);
    528  1.1  christos extern void     ARMul_SubCarry      (ARMul_State *, ARMword, ARMword, ARMword);
    529  1.1  christos extern void     ARMul_AddCarry      (ARMul_State *, ARMword, ARMword, ARMword);
    530  1.1  christos extern tdstate  ARMul_ThumbDecode   (ARMul_State *, ARMword, ARMword, ARMword *);
    531  1.1  christos extern ARMword  ARMul_GetReg        (ARMul_State *, unsigned, unsigned);
    532  1.1  christos extern void     ARMul_SetReg        (ARMul_State *, unsigned, unsigned, ARMword);
    533  1.1  christos extern void     ARMul_ScheduleEvent (ARMul_State *, unsigned long, unsigned (*) (ARMul_State *));
    534  1.1  christos /* Coprocessor support functions.  */
    535  1.1  christos extern unsigned ARMul_CoProInit     (ARMul_State *);
    536  1.1  christos extern void     ARMul_CoProExit     (ARMul_State *);
    537  1.1  christos extern void     ARMul_CoProAttach   (ARMul_State *, unsigned, ARMul_CPInits *, ARMul_CPExits *,
    538  1.1  christos 				     ARMul_LDCs *, ARMul_STCs *, ARMul_MRCs *, ARMul_MCRs *,
    539  1.1  christos 				     ARMul_CDPs *, ARMul_CPReads *, ARMul_CPWrites *);
    540  1.1  christos extern void     ARMul_CoProDetach   (ARMul_State *, unsigned);
    541  1.1  christos extern ARMword  read_cp15_reg       (unsigned, unsigned, unsigned);
    542  1.1  christos 
    543  1.1  christos extern unsigned DSPLDC4 (ARMul_State *, unsigned, ARMword, ARMword);
    544  1.1  christos extern unsigned DSPMCR4 (ARMul_State *, unsigned, ARMword, ARMword);
    545  1.1  christos extern unsigned DSPMRC4 (ARMul_State *, unsigned, ARMword, ARMword *);
    546  1.1  christos extern unsigned	DSPSTC4 (ARMul_State *, unsigned, ARMword, ARMword *);
    547  1.1  christos extern unsigned	DSPCDP4 (ARMul_State *, unsigned, ARMword);
    548  1.1  christos extern unsigned DSPMCR5 (ARMul_State *, unsigned, ARMword, ARMword);
    549  1.1  christos extern unsigned DSPMRC5 (ARMul_State *, unsigned, ARMword, ARMword *);
    550  1.1  christos extern unsigned DSPLDC5 (ARMul_State *, unsigned, ARMword, ARMword);
    551  1.1  christos extern unsigned	DSPSTC5 (ARMul_State *, unsigned, ARMword, ARMword *);
    552  1.1  christos extern unsigned	DSPCDP5 (ARMul_State *, unsigned, ARMword);
    553  1.1  christos extern unsigned DSPMCR6 (ARMul_State *, unsigned, ARMword, ARMword);
    554  1.1  christos extern unsigned DSPMRC6 (ARMul_State *, unsigned, ARMword, ARMword *);
    555  1.1  christos extern unsigned	DSPCDP6 (ARMul_State *, unsigned, ARMword);
    556