123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701 |
- /* 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 3 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, see <http://www.gnu.org/licenses/>. */
- #include "armdefs.h"
- #include "armemu.h"
- #include "ansidecl.h"
- #include <math.h>
- /* Definitions for the support routines. */
- static ARMword ModeToBank (ARMword);
- static void EnvokeList (ARMul_State *, unsigned long, unsigned long);
- struct EventNode
- { /* An event list node. */
- unsigned (*func) (ARMul_State *); /* The function to call. */
- struct EventNode *next;
- };
- /* 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] + isize;
- else
- return (state->Reg[15] + isize) & 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)
- {
- return (CPSR | state->Cpsr);
- }
- /* 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);
- 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;
- ASSIGNS ((state->Cpsr & SBIT) != 0);
- state->Cpsr &= ~SBIT;
- #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;
- oldbank = ModeToBank (oldmode);
- newbank = state->Bank = ModeToBank (newmode);
- /* Do we really need to do it? */
- if (oldbank != newbank)
- {
- /* 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);
- }
- /* 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;
- }
- }
- /* Compute whether an addition of A and B, giving RESULT, overflowed. */
- int
- AddOverflow (ARMword a, ARMword b, ARMword result)
- {
- return ((NEG (a) && NEG (b) && POS (result))
- || (POS (a) && POS (b) && NEG (result)));
- }
- /* Compute whether a subtraction of A and B, giving RESULT, overflowed. */
- int
- SubOverflow (ARMword a, ARMword b, ARMword result)
- {
- return ((NEG (a) && POS (b) && POS (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));
- }
- /* 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));
- }
- static void
- handle_VFP_xfer (ARMul_State * state, ARMword instr)
- {
- if (TOPBITS (28) == NV)
- {
- fprintf (stderr, "SIM: UNDEFINED VFP instruction\n");
- return;
- }
- if (BITS (25, 27) != 0x6)
- {
- fprintf (stderr, "SIM: ISE: VFP handler called incorrectly\n");
- return;
- }
-
- switch (BITS (20, 24))
- {
- case 0x04:
- case 0x05:
- {
- /* VMOV double precision to/from two ARM registers. */
- int vm = BITS (0, 3);
- int rt1 = BITS (12, 15);
- int rt2 = BITS (16, 19);
- /* FIXME: UNPREDICTABLE if rt1 == 15 or rt2 == 15. */
- if (BIT (20))
- {
- /* Transfer to ARM. */
- /* FIXME: UPPREDICTABLE if rt1 == rt2. */
- state->Reg[rt1] = VFP_dword (vm) & 0xffffffff;
- state->Reg[rt2] = VFP_dword (vm) >> 32;
- }
- else
- {
- VFP_dword (vm) = state->Reg[rt2];
- VFP_dword (vm) <<= 32;
- VFP_dword (vm) |= (state->Reg[rt1] & 0xffffffff);
- }
- return;
- }
- case 0x08:
- case 0x0A:
- case 0x0C:
- case 0x0E:
- {
- /* VSTM with PUW=011 or PUW=010. */
- int n = BITS (16, 19);
- int imm8 = BITS (0, 7);
- ARMword address = state->Reg[n];
- if (BIT (21))
- state->Reg[n] = address + (imm8 << 2);
- if (BIT (8))
- {
- int src = (BIT (22) << 4) | BITS (12, 15);
- imm8 >>= 1;
- while (imm8--)
- {
- if (state->bigendSig)
- {
- ARMul_StoreWordN (state, address, VFP_dword (src) >> 32);
- ARMul_StoreWordN (state, address + 4, VFP_dword (src));
- }
- else
- {
- ARMul_StoreWordN (state, address, VFP_dword (src));
- ARMul_StoreWordN (state, address + 4, VFP_dword (src) >> 32);
- }
- address += 8;
- src += 1;
- }
- }
- else
- {
- int src = (BITS (12, 15) << 1) | BIT (22);
- while (imm8--)
- {
- ARMul_StoreWordN (state, address, VFP_uword (src));
- address += 4;
- src += 1;
- }
- }
- }
- return;
- case 0x10:
- case 0x14:
- case 0x18:
- case 0x1C:
- {
- /* VSTR */
- ARMword imm32 = BITS (0, 7) << 2;
- int base = state->Reg[LHSReg];
- ARMword address;
- int dest;
- if (LHSReg == 15)
- base = (base + 3) & ~3;
- address = base + (BIT (23) ? imm32 : - imm32);
- if (CPNum == 10)
- {
- dest = (DESTReg << 1) + BIT (22);
- ARMul_StoreWordN (state, address, VFP_uword (dest));
- }
- else
- {
- dest = (BIT (22) << 4) + DESTReg;
- if (state->bigendSig)
- {
- ARMul_StoreWordN (state, address, VFP_dword (dest) >> 32);
- ARMul_StoreWordN (state, address + 4, VFP_dword (dest));
- }
- else
- {
- ARMul_StoreWordN (state, address, VFP_dword (dest));
- ARMul_StoreWordN (state, address + 4, VFP_dword (dest) >> 32);
- }
- }
- }
- return;
- case 0x12:
- case 0x16:
- if (BITS (16, 19) == 13)
- {
- /* VPUSH */
- ARMword address = state->Reg[13] - (BITS (0, 7) << 2);
- state->Reg[13] = address;
- if (BIT (8))
- {
- int dreg = (BIT (22) << 4) | BITS (12, 15);
- int num = BITS (0, 7) >> 1;
- while (num--)
- {
- if (state->bigendSig)
- {
- ARMul_StoreWordN (state, address, VFP_dword (dreg) >> 32);
- ARMul_StoreWordN (state, address + 4, VFP_dword (dreg));
- }
- else
- {
- ARMul_StoreWordN (state, address, VFP_dword (dreg));
- ARMul_StoreWordN (state, address + 4, VFP_dword (dreg) >> 32);
- }
- address += 8;
- dreg += 1;
- }
- }
- else
- {
- int sreg = (BITS (12, 15) << 1) | BIT (22);
- int num = BITS (0, 7);
- while (num--)
- {
- ARMul_StoreWordN (state, address, VFP_uword (sreg));
- address += 4;
- sreg += 1;
- }
- }
- }
- else if (BITS (9, 11) != 0x5)
- break;
- else
- {
- /* VSTM PUW=101 */
- int n = BITS (16, 19);
- int imm8 = BITS (0, 7);
- ARMword address = state->Reg[n] - (imm8 << 2);
- state->Reg[n] = address;
- if (BIT (8))
- {
- int src = (BIT (22) << 4) | BITS (12, 15);
- imm8 >>= 1;
- while (imm8--)
- {
- if (state->bigendSig)
- {
- ARMul_StoreWordN (state, address, VFP_dword (src) >> 32);
- ARMul_StoreWordN (state, address + 4, VFP_dword (src));
- }
- else
- {
- ARMul_StoreWordN (state, address, VFP_dword (src));
- ARMul_StoreWordN (state, address + 4, VFP_dword (src) >> 32);
- }
- address += 8;
- src += 1;
- }
- }
- else
- {
- int src = (BITS (12, 15) << 1) | BIT (22);
- while (imm8--)
- {
- ARMul_StoreWordN (state, address, VFP_uword (src));
- address += 4;
- src += 1;
- }
- }
- }
- return;
- case 0x13:
- case 0x17:
- /* VLDM PUW=101 */
- case 0x09:
- case 0x0D:
- /* VLDM PUW=010 */
- {
- int n = BITS (16, 19);
- int imm8 = BITS (0, 7);
- ARMword address = state->Reg[n];
- if (BIT (23) == 0)
- address -= imm8 << 2;
- if (BIT (21))
- state->Reg[n] = BIT (23) ? address + (imm8 << 2) : address;
- if (BIT (8))
- {
- int dest = (BIT (22) << 4) | BITS (12, 15);
- imm8 >>= 1;
- while (imm8--)
- {
- if (state->bigendSig)
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address + 4);
- }
- else
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address + 4);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address);
- }
- if (trace)
- fprintf (stderr, " VFP: VLDM: D%d = %g\n", dest, VFP_dval (dest));
- address += 8;
- dest += 1;
- }
- }
- else
- {
- int dest = (BITS (12, 15) << 1) | BIT (22);
- while (imm8--)
- {
- VFP_uword (dest) = ARMul_LoadWordN (state, address);
- address += 4;
- dest += 1;
- }
- }
- }
- return;
- case 0x0B:
- case 0x0F:
- if (BITS (16, 19) == 13)
- {
- /* VPOP */
- ARMword address = state->Reg[13];
- state->Reg[13] = address + (BITS (0, 7) << 2);
- if (BIT (8))
- {
- int dest = (BIT (22) << 4) | BITS (12, 15);
- int num = BITS (0, 7) >> 1;
- while (num--)
- {
- if (state->bigendSig)
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address + 4);
- }
- else
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address + 4);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address);
- }
- if (trace)
- fprintf (stderr, " VFP: VPOP: D%d = %g\n", dest, VFP_dval (dest));
- address += 8;
- dest += 1;
- }
- }
- else
- {
- int sreg = (BITS (12, 15) << 1) | BIT (22);
- int num = BITS (0, 7);
- while (num--)
- {
- VFP_uword (sreg) = ARMul_LoadWordN (state, address);
- address += 4;
- sreg += 1;
- }
- }
- }
- else if (BITS (9, 11) != 0x5)
- break;
- else
- {
- /* VLDM PUW=011 */
- int n = BITS (16, 19);
- int imm8 = BITS (0, 7);
- ARMword address = state->Reg[n];
- state->Reg[n] += imm8 << 2;
- if (BIT (8))
- {
- int dest = (BIT (22) << 4) | BITS (12, 15);
- imm8 >>= 1;
- while (imm8--)
- {
- if (state->bigendSig)
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address + 4);
- }
- else
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address + 4);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address);
- }
- if (trace)
- fprintf (stderr, " VFP: VLDM: D%d = %g\n", dest, VFP_dval (dest));
- address += 8;
- dest += 1;
- }
- }
- else
- {
- int dest = (BITS (12, 15) << 1) | BIT (22);
- while (imm8--)
- {
- VFP_uword (dest) = ARMul_LoadWordN (state, address);
- address += 4;
- dest += 1;
- }
- }
- }
- return;
- case 0x11:
- case 0x15:
- case 0x19:
- case 0x1D:
- {
- /* VLDR */
- ARMword imm32 = BITS (0, 7) << 2;
- int base = state->Reg[LHSReg];
- ARMword address;
- int dest;
- if (LHSReg == 15)
- base = (base + 3) & ~3;
- address = base + (BIT (23) ? imm32 : - imm32);
- if (CPNum == 10)
- {
- dest = (DESTReg << 1) + BIT (22);
- VFP_uword (dest) = ARMul_LoadWordN (state, address);
- }
- else
- {
- dest = (BIT (22) << 4) + DESTReg;
- if (state->bigendSig)
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address + 4);
- }
- else
- {
- VFP_dword (dest) = ARMul_LoadWordN (state, address + 4);
- VFP_dword (dest) <<= 32;
- VFP_dword (dest) |= ARMul_LoadWordN (state, address);
- }
- if (trace)
- fprintf (stderr, " VFP: VLDR: D%d = %g\n", dest, VFP_dval (dest));
- }
- }
- return;
- }
- fprintf (stderr, "SIM: VFP: Unimplemented: %0x\n", BITS (20, 24));
- }
- /* 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;
- if (CPNum == 10 || CPNum == 11)
- {
- handle_VFP_xfer (state, instr);
- return;
- }
- UNDEF_LSCPCBaseWb;
- if (! CP_ACCESS_ALLOWED (state, CPNum))
- {
- 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)
- {
- CPTAKEABORT;
- return;
- }
- cpab = (state->LDC[CPNum]) (state, ARMul_TRANSFER, instr, 0);
- data = ARMul_LoadWordN (state, address);
- BUSUSEDINCPCN;
- 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);
- cpab = (state->LDC[CPNum]) (state, ARMul_DATA, instr, data);
- }
- 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;
- if (CPNum == 10 || CPNum == 11)
- {
- handle_VFP_xfer (state, instr);
- return;
- }
- UNDEF_LSCPCBaseWb;
- if (! CP_ACCESS_ALLOWED (state, CPNum))
- {
- 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)
- {
- CPTAKEABORT;
- return;
- }
- #ifndef MODE32
- if (ADDREXCEPT (address) || VECTORACCESS (address))
- INTERNALABORT (address);
- #endif
- BUSUSEDINCPCN;
- if (BIT (21))
- LSBase = state->Base;
- cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
- ARMul_StoreWordN (state, address, data);
- while (cpab == ARMul_INC)
- {
- address += 4;
- cpab = (state->STC[CPNum]) (state, ARMul_DATA, instr, &data);
- ARMul_StoreWordN (state, address, data);
- }
- 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;
- if (! CP_ACCESS_ALLOWED (state, CPNum))
- {
- ARMul_UndefInstr (state, instr);
- 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)
- 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)
- {
- unsigned cpab;
- ARMword result = 0;
- if (! CP_ACCESS_ALLOWED (state, CPNum))
- {
- ARMul_UndefInstr (state, instr);
- return result;
- }
- 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)
- {
- 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;
- }
- static void
- handle_VFP_op (ARMul_State * state, ARMword instr)
- {
- int dest;
- int srcN;
- int srcM;
- if (BITS (9, 11) != 0x5 || BIT (4) != 0)
- {
- fprintf (stderr, "SIM: VFP: Unimplemented: Float op: %08x\n", BITS (0,31));
- return;
- }
- if (BIT (8))
- {
- dest = BITS(12,15) + (BIT (22) << 4);
- srcN = LHSReg + (BIT (7) << 4);
- srcM = BITS (0,3) + (BIT (5) << 4);
- }
- else
- {
- dest = (BITS(12,15) << 1) + BIT (22);
- srcN = (LHSReg << 1) + BIT (7);
- srcM = (BITS (0,3) << 1) + BIT (5);
- }
- switch (BITS (20, 27))
- {
- case 0xE0:
- case 0xE4:
- /* VMLA VMLS */
- if (BIT (8))
- {
- ARMdval val = VFP_dval (srcN) * VFP_dval (srcM);
- if (BIT (6))
- {
- if (trace)
- fprintf (stderr, " VFP: VMLS: %g = %g - %g * %g\n",
- VFP_dval (dest) - val,
- VFP_dval (dest), VFP_dval (srcN), VFP_dval (srcM));
- VFP_dval (dest) -= val;
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: VMLA: %g = %g + %g * %g\n",
- VFP_dval (dest) + val,
- VFP_dval (dest), VFP_dval (srcN), VFP_dval (srcM));
- VFP_dval (dest) += val;
- }
- }
- else
- {
- ARMfval val = VFP_fval (srcN) * VFP_fval (srcM);
- if (BIT (6))
- {
- if (trace)
- fprintf (stderr, " VFP: VMLS: %g = %g - %g * %g\n",
- VFP_fval (dest) - val,
- VFP_fval (dest), VFP_fval (srcN), VFP_fval (srcM));
- VFP_fval (dest) -= val;
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: VMLA: %g = %g + %g * %g\n",
- VFP_fval (dest) + val,
- VFP_fval (dest), VFP_fval (srcN), VFP_fval (srcM));
- VFP_fval (dest) += val;
- }
- }
- return;
- case 0xE1:
- case 0xE5:
- if (BIT (8))
- {
- ARMdval product = VFP_dval (srcN) * VFP_dval (srcM);
- if (BIT (6))
- {
- /* VNMLA */
- if (trace)
- fprintf (stderr, " VFP: VNMLA: %g = -(%g + (%g * %g))\n",
- -(VFP_dval (dest) + product),
- VFP_dval (dest), VFP_dval (srcN), VFP_dval (srcM));
- VFP_dval (dest) = -(product + VFP_dval (dest));
- }
- else
- {
- /* VNMLS */
- if (trace)
- fprintf (stderr, " VFP: VNMLS: %g = -(%g + (%g * %g))\n",
- -(VFP_dval (dest) + product),
- VFP_dval (dest), VFP_dval (srcN), VFP_dval (srcM));
- VFP_dval (dest) = product - VFP_dval (dest);
- }
- }
- else
- {
- ARMfval product = VFP_fval (srcN) * VFP_fval (srcM);
- if (BIT (6))
- /* VNMLA */
- VFP_fval (dest) = -(product + VFP_fval (dest));
- else
- /* VNMLS */
- VFP_fval (dest) = product - VFP_fval (dest);
- }
- return;
- case 0xE2:
- case 0xE6:
- if (BIT (8))
- {
- ARMdval product = VFP_dval (srcN) * VFP_dval (srcM);
- if (BIT (6))
- {
- if (trace)
- fprintf (stderr, " VFP: VMUL: %g = %g * %g\n",
- - product, VFP_dval (srcN), VFP_dval (srcM));
- /* VNMUL */
- VFP_dval (dest) = - product;
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: VMUL: %g = %g * %g\n",
- product, VFP_dval (srcN), VFP_dval (srcM));
- /* VMUL */
- VFP_dval (dest) = product;
- }
- }
- else
- {
- ARMfval product = VFP_fval (srcN) * VFP_fval (srcM);
- if (BIT (6))
- {
- if (trace)
- fprintf (stderr, " VFP: VNMUL: %g = %g * %g\n",
- - product, VFP_fval (srcN), VFP_fval (srcM));
- VFP_fval (dest) = - product;
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: VMUL: %g = %g * %g\n",
- product, VFP_fval (srcN), VFP_fval (srcM));
- VFP_fval (dest) = product;
- }
- }
- return;
-
- case 0xE3:
- case 0xE7:
- if (BIT (6) == 0)
- {
- /* VADD */
- if (BIT(8))
- {
- if (trace)
- fprintf (stderr, " VFP: VADD %g = %g + %g\n",
- VFP_dval (srcN) + VFP_dval (srcM),
- VFP_dval (srcN),
- VFP_dval (srcM));
- VFP_dval (dest) = VFP_dval (srcN) + VFP_dval (srcM);
- }
- else
- VFP_fval (dest) = VFP_fval (srcN) + VFP_fval (srcM);
- }
- else
- {
- /* VSUB */
- if (BIT(8))
- {
- if (trace)
- fprintf (stderr, " VFP: VSUB %g = %g - %g\n",
- VFP_dval (srcN) - VFP_dval (srcM),
- VFP_dval (srcN),
- VFP_dval (srcM));
- VFP_dval (dest) = VFP_dval (srcN) - VFP_dval (srcM);
- }
- else
- VFP_fval (dest) = VFP_fval (srcN) - VFP_fval (srcM);
- }
- return;
- case 0xE8:
- case 0xEC:
- if (BIT (6) == 1)
- break;
- /* VDIV */
- if (BIT (8))
- {
- ARMdval res = VFP_dval (srcN) / VFP_dval (srcM);
- if (trace)
- fprintf (stderr, " VFP: VDIV (64bit): %g = %g / %g\n",
- res, VFP_dval (srcN), VFP_dval (srcM));
- VFP_dval (dest) = res;
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: VDIV: %g = %g / %g\n",
- VFP_fval (srcN) / VFP_fval (srcM),
- VFP_fval (srcN), VFP_fval (srcM));
- VFP_fval (dest) = VFP_fval (srcN) / VFP_fval (srcM);
- }
- return;
- case 0xEB:
- case 0xEF:
- if (BIT (6) != 1)
- break;
- switch (BITS (16, 19))
- {
- case 0x0:
- if (BIT (7) == 0)
- {
- if (BIT (8))
- {
- /* VMOV.F64 <Dd>, <Dm>. */
- VFP_dval (dest) = VFP_dval (srcM);
- if (trace)
- fprintf (stderr, " VFP: VMOV d%d, d%d: %g\n", dest, srcM, VFP_dval (srcM));
- }
- else
- {
- /* VMOV.F32 <Sd>, <Sm>. */
- VFP_fval (dest) = VFP_fval (srcM);
- if (trace)
- fprintf (stderr, " VFP: VMOV s%d, s%d: %g\n", dest, srcM, VFP_fval (srcM));
- }
- }
- else
- {
- /* VABS */
- if (BIT (8))
- {
- ARMdval src = VFP_dval (srcM);
- VFP_dval (dest) = fabs (src);
- if (trace)
- fprintf (stderr, " VFP: VABS (%g) = %g\n", src, VFP_dval (dest));
- }
- else
- {
- ARMfval src = VFP_fval (srcM);
- VFP_fval (dest) = fabsf (src);
- if (trace)
- fprintf (stderr, " VFP: VABS (%g) = %g\n", src, VFP_fval (dest));
- }
- }
- return;
- case 0x1:
- if (BIT (7) == 0)
- {
- /* VNEG */
- if (BIT (8))
- VFP_dval (dest) = - VFP_dval (srcM);
- else
- VFP_fval (dest) = - VFP_fval (srcM);
- }
- else
- {
- /* VSQRT */
- if (BIT (8))
- {
- if (trace)
- fprintf (stderr, " VFP: %g = root(%g)\n",
- sqrt (VFP_dval (srcM)), VFP_dval (srcM));
- VFP_dval (dest) = sqrt (VFP_dval (srcM));
- }
- else
- {
- if (trace)
- fprintf (stderr, " VFP: %g = root(%g)\n",
- sqrtf (VFP_fval (srcM)), VFP_fval (srcM));
- VFP_fval (dest) = sqrtf (VFP_fval (srcM));
- }
- }
- return;
- case 0x4:
- case 0x5:
- /* VCMP, VCMPE */
- if (BIT(8))
- {
- ARMdval res = VFP_dval (dest);
- if (BIT (16) == 0)
- {
- ARMdval src = VFP_dval (srcM);
- if (isinf (res) && isinf (src))
- {
- if (res > 0.0 && src > 0.0)
- res = 0.0;
- else if (res < 0.0 && src < 0.0)
- res = 0.0;
- /* else leave res alone. */
- }
- else
- res -= src;
- }
- /* FIXME: Add handling of signalling NaNs and the E bit. */
- state->FPSCR &= 0x0FFFFFFF;
- if (res < 0.0)
- state->FPSCR |= NBIT;
- else
- state->FPSCR |= CBIT;
- if (res == 0.0)
- state->FPSCR |= ZBIT;
- if (isnan (res))
- state->FPSCR |= VBIT;
- if (trace)
- fprintf (stderr, " VFP: VCMP (64bit) %g vs %g res %g, flags: %c%c%c%c\n",
- VFP_dval (dest), BIT (16) ? 0.0 : VFP_dval (srcM), res,
- state->FPSCR & NBIT ? 'N' : '-',
- state->FPSCR & ZBIT ? 'Z' : '-',
- state->FPSCR & CBIT ? 'C' : '-',
- state->FPSCR & VBIT ? 'V' : '-');
- }
- else
- {
- ARMfval res = VFP_fval (dest);
- if (BIT (16) == 0)
- {
- ARMfval src = VFP_fval (srcM);
- if (isinf (res) && isinf (src))
- {
- if (res > 0.0 && src > 0.0)
- res = 0.0;
- else if (res < 0.0 && src < 0.0)
- res = 0.0;
- /* else leave res alone. */
- }
- else
- res -= src;
- }
- /* FIXME: Add handling of signalling NaNs and the E bit. */
- state->FPSCR &= 0x0FFFFFFF;
- if (res < 0.0)
- state->FPSCR |= NBIT;
- else
- state->FPSCR |= CBIT;
- if (res == 0.0)
- state->FPSCR |= ZBIT;
- if (isnan (res))
- state->FPSCR |= VBIT;
- if (trace)
- fprintf (stderr, " VFP: VCMP (32bit) %g vs %g res %g, flags: %c%c%c%c\n",
- VFP_fval (dest), BIT (16) ? 0.0 : VFP_fval (srcM), res,
- state->FPSCR & NBIT ? 'N' : '-',
- state->FPSCR & ZBIT ? 'Z' : '-',
- state->FPSCR & CBIT ? 'C' : '-',
- state->FPSCR & VBIT ? 'V' : '-');
- }
- return;
- case 0x7:
- if (BIT (8))
- {
- dest = (DESTReg << 1) + BIT (22);
- VFP_fval (dest) = VFP_dval (srcM);
- }
- else
- {
- dest = DESTReg + (BIT (22) << 4);
- VFP_dval (dest) = VFP_fval (srcM);
- }
- return;
- case 0x8:
- case 0xC:
- case 0xD:
- /* VCVT integer <-> FP */
- if (BIT (18))
- {
- /* To integer. */
- if (BIT (8))
- {
- dest = (BITS(12,15) << 1) + BIT (22);
- if (BIT (16))
- VFP_sword (dest) = VFP_dval (srcM);
- else
- VFP_uword (dest) = VFP_dval (srcM);
- }
- else
- {
- if (BIT (16))
- VFP_sword (dest) = VFP_fval (srcM);
- else
- VFP_uword (dest) = VFP_fval (srcM);
- }
- }
- else
- {
- /* From integer. */
- if (BIT (8))
- {
- srcM = (BITS (0,3) << 1) + BIT (5);
- if (BIT (7))
- VFP_dval (dest) = VFP_sword (srcM);
- else
- VFP_dval (dest) = VFP_uword (srcM);
- }
- else
- {
- if (BIT (7))
- VFP_fval (dest) = VFP_sword (srcM);
- else
- VFP_fval (dest) = VFP_uword (srcM);
- }
- }
- return;
- }
- fprintf (stderr, "SIM: VFP: Unimplemented: Float op3: %03x\n", BITS (16,27));
- return;
- }
- fprintf (stderr, "SIM: VFP: Unimplemented: Float op2: %02x\n", BITS (20, 27));
- return;
- }
- /* This function does the Busy-Waiting for an CDP instruction. */
- void
- ARMul_CDP (ARMul_State * state, ARMword instr)
- {
- unsigned cpab;
- if (CPNum == 10 || CPNum == 11)
- {
- handle_VFP_op (state, instr);
- return;
- }
- if (! CP_ACCESS_ALLOWED (state, 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 ATTRIBUTE_UNUSED)
- {
- ARMul_Abort (state, ARMul_UndefinedInstrV);
- }
- /* Return TRUE if an interrupt is pending, FALSE otherwise. */
- unsigned
- IntPending (ARMul_State * state)
- {
- if (state->Exception)
- {
- /* 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 ATTRIBUTE_UNUSED, 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 */
- }
- /* 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. */
- void
- ARMul_ScheduleEvent (ARMul_State * state, unsigned long delay,
- unsigned (*what) (ARMul_State *))
- {
- 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;
- }
- /* This routine is called at the beginning of
- every cycle, to envoke scheduled events. */
- void
- ARMul_EnvokeEvent (ARMul_State * state)
- {
- static unsigned long then;
- then = state->Now;
- state->Now = ARMul_Time (state) % EVENTLISTSIZE;
- if (then < state->Now)
- /* Schedule events. */
- EnvokeList (state, then, state->Now);
- else if (then > state->Now)
- {
- /* Need to wrap around the list. */
- EnvokeList (state, then, EVENTLISTSIZE - 1L);
- EnvokeList (state, 0L, state->Now);
- }
- }
- /* Envokes all the entries in a range. */
- static void
- EnvokeList (ARMul_State * state, unsigned long from, unsigned long to)
- {
- for (; from <= to; from++)
- {
- struct EventNode *anevent;
- anevent = *(state->EventPtr + from);
- while (anevent)
- {
- (anevent->func) (state);
- state->EventSet--;
- anevent = anevent->next;
- }
- *(state->EventPtr + from) = NULL;
- }
- }
- /* This routine is returns the number of clock ticks since the last reset. */
- unsigned long
- ARMul_Time (ARMul_State * state)
- {
- return (state->NumScycles + state->NumNcycles +
- state->NumIcycles + state->NumCcycles + state->NumFcycles);
- }
|