1 /* arminit.c -- ARMulator initialization: ARM6 Instruction Emulator.
2 Copyright (C) 1994 Advanced RISC Machines Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /***************************************************************************\
22 * Definitions for the emulator architecture *
23 \***************************************************************************/
25 void ARMul_EmulateInit (void);
26 ARMul_State
*ARMul_NewState (void);
27 void ARMul_Reset (ARMul_State
* state
);
28 ARMword
ARMul_DoCycle (ARMul_State
* state
);
29 unsigned ARMul_DoCoPro (ARMul_State
* state
);
30 ARMword
ARMul_DoProg (ARMul_State
* state
);
31 ARMword
ARMul_DoInstr (ARMul_State
* state
);
32 void ARMul_Abort (ARMul_State
* state
, ARMword address
);
34 unsigned ARMul_MultTable
[32] =
35 { 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
36 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16
38 ARMword ARMul_ImmedTable
[4096]; /* immediate DP LHS values */
39 char ARMul_BitList
[256]; /* number of bits in a byte table */
41 /***************************************************************************\
42 * Call this routine once to set up the emulator's tables. *
43 \***************************************************************************/
46 ARMul_EmulateInit (void)
50 for (i
= 0; i
< 4096; i
++)
51 { /* the values of 12 bit dp rhs's */
52 ARMul_ImmedTable
[i
] = ROTATER (i
& 0xffL
, (i
>> 7L) & 0x1eL
);
55 for (i
= 0; i
< 256; ARMul_BitList
[i
++] = 0); /* how many bits in LSM */
56 for (j
= 1; j
< 256; j
<<= 1)
57 for (i
= 0; i
< 256; i
++)
61 for (i
= 0; i
< 256; i
++)
62 ARMul_BitList
[i
] *= 4; /* you always need 4 times these values */
66 /***************************************************************************\
67 * Returns a new instantiation of the ARMulator's state *
68 \***************************************************************************/
76 state
= (ARMul_State
*) malloc (sizeof (ARMul_State
));
77 memset (state
, 0, sizeof (ARMul_State
));
80 for (i
= 0; i
< 16; i
++)
83 for (j
= 0; j
< 7; j
++)
84 state
->RegBank
[j
][i
] = 0;
86 for (i
= 0; i
< 7; i
++)
89 state
->Mode
= USER26MODE
;
91 state
->CallDebug
= FALSE
;
93 state
->VectorCatch
= 0;
94 state
->Aborted
= FALSE
;
95 state
->Reseted
= FALSE
;
99 state
->MemDataPtr
= NULL
;
100 state
->MemInPtr
= NULL
;
101 state
->MemOutPtr
= NULL
;
102 state
->MemSparePtr
= NULL
;
106 state
->CommandLine
= NULL
;
110 state
->EventPtr
= (struct EventNode
**) malloc ((unsigned) EVENTLISTSIZE
*
111 sizeof (struct EventNode
113 for (i
= 0; i
< EVENTLISTSIZE
; i
++)
114 *(state
->EventPtr
+ i
) = NULL
;
117 state
->prog32Sig
= LOW
;
118 state
->data32Sig
= LOW
;
120 state
->prog32Sig
= HIGH
;
121 state
->data32Sig
= HIGH
;
124 state
->lateabtSig
= LOW
;
125 state
->bigendSig
= LOW
;
135 /***************************************************************************\
136 Call this routine to set ARMulator to model certain processor properities
137 \***************************************************************************/
140 ARMul_SelectProcessor (ARMul_State
* state
, unsigned properties
)
142 if (properties
& ARM_Fix26_Prop
)
144 state
->prog32Sig
= LOW
;
145 state
->data32Sig
= LOW
;
149 state
->prog32Sig
= HIGH
;
150 state
->data32Sig
= HIGH
;
153 state
->lateabtSig
= LOW
;
155 state
->is_v4
= (properties
& (ARM_v4_Prop
| ARM_v5_Prop
)) ? HIGH
: LOW
;
156 state
->is_v5
= (properties
& ARM_v5_Prop
) ? HIGH
: LOW
;
159 /***************************************************************************\
160 * Call this routine to set up the initial machine state (or perform a RESET *
161 \***************************************************************************/
164 ARMul_Reset (ARMul_State
* state
)
166 state
->NextInstr
= 0;
168 if (state
->prog32Sig
)
171 state
->Cpsr
= INTBITS
| SVC32MODE
;
172 state
->Mode
= SVC32MODE
;
176 state
->Reg
[15] = R15INTBITS
| SVC26MODE
;
177 state
->Cpsr
= INTBITS
| SVC26MODE
;
178 state
->Mode
= SVC26MODE
;
181 ARMul_CPSRAltered (state
);
182 state
->Bank
= SVCBANK
;
186 state
->EndCondition
= 0;
187 state
->ErrorCode
= 0;
189 state
->Exception
= FALSE
;
190 state
->NresetSig
= HIGH
;
191 state
->NfiqSig
= HIGH
;
192 state
->NirqSig
= HIGH
;
193 state
->NtransSig
= (state
->Mode
& 3) ? HIGH
: LOW
;
194 state
->abortSig
= LOW
;
195 state
->AbortAddr
= 1;
197 state
->NumInstrs
= 0;
198 state
->NumNcycles
= 0;
199 state
->NumScycles
= 0;
200 state
->NumIcycles
= 0;
201 state
->NumCcycles
= 0;
202 state
->NumFcycles
= 0;
204 (void) ARMul_MemoryInit ();
205 ARMul_OSInit (state
);
210 /***************************************************************************\
211 * Emulate the execution of an entire program. Start the correct emulator *
212 * (Emulate26 for a 26 bit ARM and Emulate32 for a 32 bit ARM), return the *
213 * address of the last instruction that is executed. *
214 \***************************************************************************/
217 ARMul_DoProg (ARMul_State
* state
)
221 state
->Emulate
= RUN
;
222 while (state
->Emulate
!= STOP
)
224 state
->Emulate
= RUN
;
225 if (state
->prog32Sig
&& ARMul_MODE32BIT
)
226 pc
= ARMul_Emulate32 (state
);
228 pc
= ARMul_Emulate26 (state
);
233 /***************************************************************************\
234 * Emulate the execution of one instruction. Start the correct emulator *
235 * (Emulate26 for a 26 bit ARM and Emulate32 for a 32 bit ARM), return the *
236 * address of the instruction that is executed. *
237 \***************************************************************************/
240 ARMul_DoInstr (ARMul_State
* state
)
244 state
->Emulate
= ONCE
;
245 if (state
->prog32Sig
&& ARMul_MODE32BIT
)
246 pc
= ARMul_Emulate32 (state
);
248 pc
= ARMul_Emulate26 (state
);
253 /***************************************************************************\
254 * This routine causes an Abort to occur, including selecting the correct *
255 * mode, register bank, and the saving of registers. Call with the *
256 * appropriate vector's memory address (0,4,8 ....) *
257 \***************************************************************************/
260 ARMul_Abort (ARMul_State
* state
, ARMword vector
)
263 int isize
= INSN_SIZE
;
265 state
->Aborted
= FALSE
;
267 if (ARMul_OSException (state
, vector
, ARMul_GetPC (state
)))
270 if (state
->prog32Sig
)
274 temp
= state
->Reg
[15];
276 temp
= R15PC
| ECC
| ER15INT
| EMODE
;
280 case ARMul_ResetV
: /* RESET */
281 SETABORT (INTBITS
, state
->prog32Sig
? SVC32MODE
: SVC26MODE
, 0);
283 case ARMul_UndefinedInstrV
: /* Undefined Instruction */
284 SETABORT (IBIT
, state
->prog32Sig
? UNDEF32MODE
: SVC26MODE
, isize
);
286 case ARMul_SWIV
: /* Software Interrupt */
287 SETABORT (IBIT
, state
->prog32Sig
? SVC32MODE
: SVC26MODE
, isize
);
289 case ARMul_PrefetchAbortV
: /* Prefetch Abort */
290 state
->AbortAddr
= 1;
291 SETABORT (IBIT
, state
->prog32Sig
? ABORT32MODE
: SVC26MODE
, isize
);
293 case ARMul_DataAbortV
: /* Data Abort */
294 SETABORT (IBIT
, state
->prog32Sig
? ABORT32MODE
: SVC26MODE
, isize
);
296 case ARMul_AddrExceptnV
: /* Address Exception */
297 SETABORT (IBIT
, SVC26MODE
, isize
);
299 case ARMul_IRQV
: /* IRQ */
300 SETABORT (IBIT
, state
->prog32Sig
? IRQ32MODE
: IRQ26MODE
, isize
);
302 case ARMul_FIQV
: /* FIQ */
303 SETABORT (INTBITS
, state
->prog32Sig
? FIQ32MODE
: FIQ26MODE
, isize
);
307 ARMul_SetR15 (state
, vector
);
309 ARMul_SetR15 (state
, R15CCINTMODE
| vector
);
This page took 0.048552 seconds and 4 git commands to generate.