2961
|
1 /* Copyright (C) 2006 yopyop
|
|
2 yopyop156@ifrance.com
|
|
3 yopyop156.ifrance.com
|
|
4
|
|
5 This file is part of DeSmuME
|
|
6
|
|
7 DeSmuME is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
|
9 the Free Software Foundation; either version 2 of the License, or
|
|
10 (at your option) any later version.
|
|
11
|
|
12 DeSmuME is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with DeSmuME; if not, write to the Free Software
|
|
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include "arm_instructions.h"
|
|
23 #include "thumb_instructions.h"
|
|
24 #include "cp15.h"
|
|
25 #include "bios.h"
|
|
26 #include <stdlib.h>
|
|
27 #include <stdio.h>
|
|
28
|
|
29 const unsigned char arm_cond_table[16*16] = {
|
|
30 /* N=0, Z=0, C=0, V=0 */
|
|
31 0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
|
|
32 0x00,0xFF,0xFF,0x00,0xFF,0x00,0xFF,0x20,
|
|
33 /* N=0, Z=0, C=0, V=1 */
|
|
34 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x00,
|
|
35 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
36 /* N=0, Z=0, C=1, V=0 */
|
|
37 0x00,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,
|
|
38 0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x20,
|
|
39 /* N=0, Z=0, C=1, V=1 */
|
|
40 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,
|
|
41 0xFF,0x00,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
42 /* N=0, Z=1, C=0, V=0 */
|
|
43 0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,
|
|
44 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x20,
|
|
45 /* N=0, Z=1, C=0, V=1 */
|
|
46 0xFF,0x00,0x00,0xFF,0x00,0xFF,0xFF,0x00,
|
|
47 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
48 /* N=0, Z=1, C=1, V=0 */
|
|
49 0xFF,0x00,0xFF,0x00,0x00,0xFF,0x00,0xFF,
|
|
50 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x20,
|
|
51 /* N=0, Z=1, C=1, V=1 */
|
|
52 0xFF,0x00,0xFF,0x00,0x00,0xFF,0xFF,0x00,
|
|
53 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
54 /* N=1, Z=0, C=0, V=0 */
|
|
55 0x00,0xFF,0x00,0xFF,0xFF,0x00,0x00,0xFF,
|
|
56 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
57 /* N=1, Z=0, C=0, V=1 */
|
|
58 0x00,0xFF,0x00,0xFF,0xFF,0x00,0xFF,0x00,
|
|
59 0x00,0xFF,0xFF,0x00,0xFF,0x00,0xFF,0x20,
|
|
60 /* N=1, Z=0, C=1, V=0 */
|
|
61 0x00,0xFF,0xFF,0x00,0xFF,0x00,0x00,0xFF,
|
|
62 0xFF,0x00,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
63 /* N=1, Z=0, C=1, V=1 */
|
|
64 0x00,0xFF,0xFF,0x00,0xFF,0x00,0xFF,0x00,
|
|
65 0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x20,
|
|
66 /* N=1, Z=1, C=0, V=0 */
|
|
67 0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,
|
|
68 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
69 /* N=1, Z=1, C=0, V=1 */
|
|
70 0xFF,0x00,0x00,0xFF,0xFF,0x00,0xFF,0x00,
|
|
71 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x20,
|
|
72 /* N=1, Z=1, C=1, V=0 */
|
|
73 0xFF,0x00,0xFF,0x00,0xFF,0x00,0x00,0xFF,
|
|
74 0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x20,
|
|
75 /* N=1, Z=1, C=1, V=1 */
|
|
76 0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,
|
|
77 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x20,
|
|
78 };
|
|
79
|
|
80 armcpu_t NDS_ARM7;
|
|
81 armcpu_t NDS_ARM9;
|
|
82
|
|
83 #define SWAP(a, b, c) do \
|
|
84 { \
|
|
85 c=a; \
|
|
86 a=b; \
|
|
87 b=c; \
|
|
88 } \
|
|
89 while(0)
|
|
90
|
|
91 #ifdef GDB_STUB
|
|
92
|
|
93 #define STALLED_CYCLE_COUNT 10
|
|
94
|
|
95 static void
|
|
96 stall_cpu( void *instance) {
|
|
97 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
98
|
|
99 armcpu->stalled = 1;
|
|
100 }
|
|
101
|
|
102 static void
|
|
103 unstall_cpu( void *instance) {
|
|
104 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
105
|
|
106 armcpu->stalled = 0;
|
|
107 }
|
|
108
|
|
109 static void
|
|
110 install_post_exec_fn( void *instance,
|
|
111 void (*ex_fn)( void *, u32 adr, int thumb),
|
|
112 void *fn_data) {
|
|
113 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
114
|
|
115 armcpu->post_ex_fn = ex_fn;
|
|
116 armcpu->post_ex_fn_data = fn_data;
|
|
117 }
|
|
118
|
|
119 static void
|
|
120 remove_post_exec_fn( void *instance) {
|
|
121 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
122
|
|
123 armcpu->post_ex_fn = NULL;
|
|
124 }
|
|
125 #endif
|
|
126
|
|
127 static u32
|
|
128 read_cpu_reg( void *instance, u32 reg_num) {
|
|
129 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
130 u32 reg_value = 0;
|
|
131
|
|
132 if ( reg_num <= 14) {
|
|
133 reg_value = armcpu->R[reg_num];
|
|
134 }
|
|
135 else if ( reg_num == 15) {
|
|
136 reg_value = armcpu->next_instruction;
|
|
137 }
|
|
138 else if ( reg_num == 16) {
|
|
139 /* CPSR */
|
|
140 reg_value = armcpu->CPSR.val;
|
|
141 }
|
|
142
|
|
143 return reg_value;
|
|
144 }
|
|
145
|
|
146 static void
|
|
147 set_cpu_reg( void *instance, u32 reg_num, u32 value) {
|
|
148 armcpu_t *armcpu = (armcpu_t *)instance;
|
|
149
|
|
150 if ( reg_num <= 14) {
|
|
151 armcpu->R[reg_num] = value;
|
|
152 }
|
|
153 else if ( reg_num == 15) {
|
|
154 armcpu->next_instruction = value;
|
|
155 }
|
|
156 else if ( reg_num == 16) {
|
|
157 /* FIXME: setting the CPSR */
|
|
158 }
|
|
159 }
|
|
160
|
|
161 #ifdef GDB_STUB
|
|
162 int armcpu_new( armcpu_t *armcpu, u32 id,
|
|
163 struct armcpu_memory_iface *mem_if,
|
|
164 struct armcpu_ctrl_iface **ctrl_iface_ret)
|
|
165 #else
|
|
166 int armcpu_new( armcpu_t *armcpu, u32 id)
|
|
167 #endif
|
|
168 {
|
|
169 armcpu->proc_ID = id;
|
|
170
|
|
171 if(id==0)
|
|
172 armcpu->swi_tab = ARM9_swi_tab;
|
|
173 else
|
|
174 armcpu->swi_tab = ARM7_swi_tab;
|
|
175
|
|
176 #ifdef GDB_STUB
|
|
177 armcpu->mem_if = mem_if;
|
|
178
|
|
179 /* populate the control interface */
|
|
180 armcpu->ctrl_iface.stall = stall_cpu;
|
|
181 armcpu->ctrl_iface.unstall = unstall_cpu;
|
|
182 armcpu->ctrl_iface.read_reg = read_cpu_reg;
|
|
183 armcpu->ctrl_iface.set_reg = set_cpu_reg;
|
|
184 armcpu->ctrl_iface.install_post_ex_fn = install_post_exec_fn;
|
|
185 armcpu->ctrl_iface.remove_post_ex_fn = remove_post_exec_fn;
|
|
186 armcpu->ctrl_iface.data = armcpu;
|
|
187
|
|
188 *ctrl_iface_ret = &armcpu->ctrl_iface;
|
|
189
|
|
190 armcpu->stalled = 0;
|
|
191 armcpu->post_ex_fn = NULL;
|
|
192 #endif
|
|
193
|
|
194 armcpu_init(armcpu, 0);
|
|
195
|
|
196 return 0;
|
|
197 }
|
|
198
|
|
199 void armcpu_init(armcpu_t *armcpu, u32 adr)
|
|
200 {
|
|
201 u32 i;
|
|
202
|
|
203 armcpu->LDTBit = (armcpu->proc_ID==0); //Si ARM9 utiliser le syte v5 pour le load
|
|
204 armcpu->intVector = 0xFFFF0000 * (armcpu->proc_ID==0);
|
|
205 armcpu->waitIRQ = FALSE;
|
|
206 armcpu->wirq = FALSE;
|
|
207
|
|
208 #ifdef GDB_STUB
|
|
209 armcpu->irq_flag = 0;
|
|
210 #endif
|
|
211
|
|
212 if(armcpu->coproc[15]) free(armcpu->coproc[15]);
|
|
213
|
|
214 for(i = 0; i < 15; ++i)
|
|
215 {
|
|
216 armcpu->R[i] = 0;
|
|
217 armcpu->coproc[i] = NULL;
|
|
218 }
|
|
219
|
|
220 armcpu->CPSR.val = armcpu->SPSR.val = SYS;
|
|
221
|
|
222 armcpu->R13_usr = armcpu->R14_usr = 0;
|
|
223 armcpu->R13_svc = armcpu->R14_svc = 0;
|
|
224 armcpu->R13_abt = armcpu->R14_abt = 0;
|
|
225 armcpu->R13_und = armcpu->R14_und = 0;
|
|
226 armcpu->R13_irq = armcpu->R14_irq = 0;
|
|
227 armcpu->R8_fiq = armcpu->R9_fiq = armcpu->R10_fiq = armcpu->R11_fiq = armcpu->R12_fiq = armcpu->R13_fiq = armcpu->R14_fiq = 0;
|
|
228
|
|
229 armcpu->SPSR_svc.val = armcpu->SPSR_abt.val = armcpu->SPSR_und.val = armcpu->SPSR_irq.val = armcpu->SPSR_fiq.val = 0;
|
|
230
|
|
231 #ifdef GDB_STUB
|
|
232 armcpu->instruct_adr = adr;
|
|
233 armcpu->R[15] = adr + 8;
|
|
234 #else
|
|
235 armcpu->R[15] = adr;
|
|
236 #endif
|
|
237
|
|
238 armcpu->next_instruction = adr;
|
|
239
|
|
240 armcpu->coproc[15] = (armcp_t*)armcp15_new(armcpu);
|
|
241
|
|
242 #ifndef GDB_STUB
|
|
243 armcpu_prefetch(armcpu);
|
|
244 #endif
|
|
245 }
|
|
246
|
|
247 u32 armcpu_switchMode(armcpu_t *armcpu, u8 mode)
|
|
248 {
|
|
249 u32 oldmode = armcpu->CPSR.bits.mode;
|
|
250
|
|
251 switch(oldmode)
|
|
252 {
|
|
253 case USR :
|
|
254 case SYS :
|
|
255 armcpu->R13_usr = armcpu->R[13];
|
|
256 armcpu->R14_usr = armcpu->R[14];
|
|
257 break;
|
|
258
|
|
259 case FIQ :
|
|
260 {
|
|
261 u32 tmp;
|
|
262 SWAP(armcpu->R[8], armcpu->R8_fiq, tmp);
|
|
263 SWAP(armcpu->R[9], armcpu->R9_fiq, tmp);
|
|
264 SWAP(armcpu->R[10], armcpu->R10_fiq, tmp);
|
|
265 SWAP(armcpu->R[11], armcpu->R11_fiq, tmp);
|
|
266 SWAP(armcpu->R[12], armcpu->R12_fiq, tmp);
|
|
267 armcpu->R13_fiq = armcpu->R[13];
|
|
268 armcpu->R14_fiq = armcpu->R[14];
|
|
269 armcpu->SPSR_fiq = armcpu->SPSR;
|
|
270 break;
|
|
271 }
|
|
272 case IRQ :
|
|
273 armcpu->R13_irq = armcpu->R[13];
|
|
274 armcpu->R14_irq = armcpu->R[14];
|
|
275 armcpu->SPSR_irq = armcpu->SPSR;
|
|
276 break;
|
|
277
|
|
278 case SVC :
|
|
279 armcpu->R13_svc = armcpu->R[13];
|
|
280 armcpu->R14_svc = armcpu->R[14];
|
|
281 armcpu->SPSR_svc = armcpu->SPSR;
|
|
282 break;
|
|
283
|
|
284 case ABT :
|
|
285 armcpu->R13_abt = armcpu->R[13];
|
|
286 armcpu->R14_abt = armcpu->R[14];
|
|
287 armcpu->SPSR_abt = armcpu->SPSR;
|
|
288 break;
|
|
289
|
|
290 case UND :
|
|
291 armcpu->R13_und = armcpu->R[13];
|
|
292 armcpu->R14_und = armcpu->R[14];
|
|
293 armcpu->SPSR_und = armcpu->SPSR;
|
|
294 break;
|
|
295 default :
|
|
296 break;
|
|
297 }
|
|
298
|
|
299 switch(mode)
|
|
300 {
|
|
301 case USR :
|
|
302 case SYS :
|
|
303 armcpu->R[13] = armcpu->R13_usr;
|
|
304 armcpu->R[14] = armcpu->R14_usr;
|
|
305 //SPSR = CPSR;
|
|
306 break;
|
|
307
|
|
308 case FIQ :
|
|
309 {
|
|
310 u32 tmp;
|
|
311 SWAP(armcpu->R[8], armcpu->R8_fiq, tmp);
|
|
312 SWAP(armcpu->R[9], armcpu->R9_fiq, tmp);
|
|
313 SWAP(armcpu->R[10], armcpu->R10_fiq, tmp);
|
|
314 SWAP(armcpu->R[11], armcpu->R11_fiq, tmp);
|
|
315 SWAP(armcpu->R[12], armcpu->R12_fiq, tmp);
|
|
316 armcpu->R[13] = armcpu->R13_fiq;
|
|
317 armcpu->R[14] = armcpu->R14_fiq;
|
|
318 armcpu->SPSR = armcpu->SPSR_fiq;
|
|
319 break;
|
|
320 }
|
|
321
|
|
322 case IRQ :
|
|
323 armcpu->R[13] = armcpu->R13_irq;
|
|
324 armcpu->R[14] = armcpu->R14_irq;
|
|
325 armcpu->SPSR = armcpu->SPSR_irq;
|
|
326 break;
|
|
327
|
|
328 case SVC :
|
|
329 armcpu->R[13] = armcpu->R13_svc;
|
|
330 armcpu->R[14] = armcpu->R14_svc;
|
|
331 armcpu->SPSR = armcpu->SPSR_svc;
|
|
332 break;
|
|
333
|
|
334 case ABT :
|
|
335 armcpu->R[13] = armcpu->R13_abt;
|
|
336 armcpu->R[14] = armcpu->R14_abt;
|
|
337 armcpu->SPSR = armcpu->SPSR_abt;
|
|
338 break;
|
|
339
|
|
340 case UND :
|
|
341 armcpu->R[13] = armcpu->R13_und;
|
|
342 armcpu->R[14] = armcpu->R14_und;
|
|
343 armcpu->SPSR = armcpu->SPSR_und;
|
|
344 break;
|
|
345
|
|
346 default :
|
|
347 break;
|
|
348 }
|
|
349
|
|
350 armcpu->CPSR.bits.mode = mode & 0x1F;
|
|
351 return oldmode;
|
|
352 }
|
|
353
|
|
354 static u32
|
|
355 armcpu_prefetch(armcpu_t *armcpu)
|
|
356 {
|
|
357 u32 temp_instruction;
|
|
358
|
|
359 if(armcpu->CPSR.bits.T == 0)
|
|
360 {
|
|
361 #ifdef GDB_STUB
|
|
362 temp_instruction =
|
|
363 armcpu->mem_if->prefetch32( armcpu->mem_if->data,
|
|
364 armcpu->next_instruction);
|
|
365
|
|
366 if ( !armcpu->stalled) {
|
|
367 armcpu->instruction = temp_instruction;
|
|
368 armcpu->instruct_adr = armcpu->next_instruction;
|
|
369 armcpu->next_instruction += 4;
|
|
370 armcpu->R[15] = armcpu->next_instruction + 4;
|
|
371 }
|
|
372 #else
|
|
373 armcpu->instruction = MMU_read32_acl(armcpu->proc_ID, armcpu->next_instruction,CP15_ACCESS_EXECUTE);
|
|
374
|
|
375 armcpu->instruct_adr = armcpu->next_instruction;
|
|
376 armcpu->next_instruction += 4;
|
|
377 armcpu->R[15] = armcpu->next_instruction + 4;
|
|
378 #endif
|
|
379
|
|
380 return MMU.MMU_WAIT32[armcpu->proc_ID][(armcpu->instruct_adr>>24)&0xF];
|
|
381 }
|
|
382
|
|
383 #ifdef GDB_STUB
|
|
384 temp_instruction =
|
|
385 armcpu->mem_if->prefetch16( armcpu->mem_if->data,
|
|
386 armcpu->next_instruction);
|
|
387
|
|
388 if ( !armcpu->stalled) {
|
|
389 armcpu->instruction = temp_instruction;
|
|
390 armcpu->instruct_adr = armcpu->next_instruction;
|
|
391 armcpu->next_instruction = armcpu->next_instruction + 2;
|
|
392 armcpu->R[15] = armcpu->next_instruction + 2;
|
|
393 }
|
|
394 #else
|
|
395 armcpu->instruction = MMU_read16_acl(armcpu->proc_ID, armcpu->next_instruction,CP15_ACCESS_EXECUTE);
|
|
396
|
|
397 armcpu->instruct_adr = armcpu->next_instruction;
|
|
398 armcpu->next_instruction += 2;
|
|
399 armcpu->R[15] = armcpu->next_instruction + 2;
|
|
400 #endif
|
|
401
|
|
402 return MMU.MMU_WAIT16[armcpu->proc_ID][(armcpu->instruct_adr>>24)&0xF];
|
|
403 }
|
|
404
|
|
405
|
|
406 static BOOL FASTCALL test_EQ(Status_Reg CPSR) { return ( CPSR.bits.Z); }
|
|
407 static BOOL FASTCALL test_NE(Status_Reg CPSR) { return (!CPSR.bits.Z); }
|
|
408 static BOOL FASTCALL test_CS(Status_Reg CPSR) { return ( CPSR.bits.C); }
|
|
409 static BOOL FASTCALL test_CC(Status_Reg CPSR) { return (!CPSR.bits.C); }
|
|
410 static BOOL FASTCALL test_MI(Status_Reg CPSR) { return ( CPSR.bits.N); }
|
|
411 static BOOL FASTCALL test_PL(Status_Reg CPSR) { return (!CPSR.bits.N); }
|
|
412 static BOOL FASTCALL test_VS(Status_Reg CPSR) { return ( CPSR.bits.V); }
|
|
413 static BOOL FASTCALL test_VC(Status_Reg CPSR) { return (!CPSR.bits.V); }
|
|
414 static BOOL FASTCALL test_HI(Status_Reg CPSR) { return (CPSR.bits.C) && (!CPSR.bits.Z); }
|
|
415 static BOOL FASTCALL test_LS(Status_Reg CPSR) { return (CPSR.bits.Z) || (!CPSR.bits.C); }
|
|
416 static BOOL FASTCALL test_GE(Status_Reg CPSR) { return (CPSR.bits.N==CPSR.bits.V); }
|
|
417 static BOOL FASTCALL test_LT(Status_Reg CPSR) { return (CPSR.bits.N!=CPSR.bits.V); }
|
|
418 static BOOL FASTCALL test_GT(Status_Reg CPSR) { return (!CPSR.bits.Z) && (CPSR.bits.N==CPSR.bits.V); }
|
|
419 static BOOL FASTCALL test_LE(Status_Reg CPSR) { return ( CPSR.bits.Z) || (CPSR.bits.N!=CPSR.bits.V); }
|
|
420 static BOOL FASTCALL test_AL(Status_Reg CPSR) { return 1; }
|
|
421
|
|
422 static BOOL (FASTCALL* test_conditions[])(Status_Reg CPSR)= {
|
|
423 test_EQ , test_NE ,
|
|
424 test_CS , test_CC ,
|
|
425 test_MI , test_PL ,
|
|
426 test_VS , test_VC ,
|
|
427 test_HI , test_LS ,
|
|
428 test_GE , test_LT ,
|
|
429 test_GT , test_LE ,
|
|
430 test_AL
|
|
431 };
|
|
432 #define TEST_COND2(cond, CPSR) \
|
|
433 (cond<15&&test_conditions[cond](CPSR))
|
|
434
|
|
435
|
|
436 BOOL armcpu_irqExeption(armcpu_t *armcpu)
|
|
437 {
|
|
438 Status_Reg tmp;
|
|
439
|
|
440 if(armcpu->CPSR.bits.I) return FALSE;
|
|
441
|
|
442 #ifdef GDB_STUB
|
|
443 armcpu->irq_flag = 0;
|
|
444 #endif
|
|
445
|
|
446 tmp = armcpu->CPSR;
|
|
447 armcpu_switchMode(armcpu, IRQ);
|
|
448
|
|
449 #ifdef GDB_STUB
|
|
450 armcpu->R[14] = armcpu->next_instruction + 4;
|
|
451 #else
|
|
452 armcpu->R[14] = armcpu->instruct_adr + 4;
|
|
453 #endif
|
|
454 armcpu->SPSR = tmp;
|
|
455 armcpu->CPSR.bits.T = 0;
|
|
456 armcpu->CPSR.bits.I = 1;
|
|
457 armcpu->next_instruction = armcpu->intVector + 0x18;
|
|
458 armcpu->waitIRQ = 0;
|
|
459
|
|
460 #ifndef GDB_STUB
|
|
461 armcpu->R[15] = armcpu->next_instruction + 8;
|
|
462 armcpu_prefetch(armcpu);
|
|
463 #endif
|
|
464
|
|
465 return TRUE;
|
|
466 }
|
|
467 /*
|
|
468 static BOOL armcpu_prefetchExeption(armcpu_t *armcpu)
|
|
469 {
|
|
470 Status_Reg tmp;
|
|
471 if(armcpu->CPSR.bits.I) return FALSE;
|
|
472 tmp = armcpu->CPSR;
|
|
473 armcpu_switchMode(armcpu, ABT);
|
|
474 armcpu->R[14] = armcpu->next_instruction + 4;
|
|
475 armcpu->SPSR = tmp;
|
|
476 armcpu->CPSR.bits.T = 0;
|
|
477 armcpu->CPSR.bits.I = 1;
|
|
478 armcpu->next_instruction = armcpu->intVector + 0xC;
|
|
479 armcpu->R[15] = armcpu->next_instruction + 8;
|
|
480 armcpu->waitIRQ = 0;
|
|
481 return TRUE;
|
|
482 }
|
|
483 */
|
|
484
|
|
485 static BOOL armcpu_prefetchExeption(armcpu_t *armcpu)
|
|
486 {
|
|
487 Status_Reg tmp;
|
|
488 if(armcpu->CPSR.bits.I) return FALSE;
|
|
489 tmp = armcpu->CPSR;
|
|
490 armcpu_switchMode(armcpu, ABT);
|
|
491
|
|
492 #ifdef GDB_STUB
|
|
493 armcpu->R[14] = armcpu->next_instruction + 4;
|
|
494 #else
|
|
495 armcpu->R[14] = armcpu->instruct_adr + 4;
|
|
496 #endif
|
|
497
|
|
498 armcpu->SPSR = tmp;
|
|
499 armcpu->CPSR.bits.T = 0;
|
|
500 armcpu->CPSR.bits.I = 1;
|
|
501 armcpu->next_instruction = armcpu->intVector + 0xC;
|
|
502 armcpu->waitIRQ = 0;
|
|
503
|
|
504 #ifdef GDB_STUB
|
|
505 armcpu->R[15] = armcpu->next_instruction + 8;
|
|
506 #else
|
|
507 armcpu->R[15] = armcpu->next_instruction;
|
|
508 armcpu_prefetch(armcpu);
|
|
509 #endif
|
|
510
|
|
511 return TRUE;
|
|
512 }
|
|
513
|
|
514 BOOL
|
|
515 armcpu_flagIrq( armcpu_t *armcpu) {
|
|
516 if(armcpu->CPSR.bits.I) return FALSE;
|
|
517
|
|
518 armcpu->waitIRQ = 0;
|
|
519
|
|
520 #ifdef GDB_STUB
|
|
521 armcpu->irq_flag = 1;
|
|
522 #endif
|
|
523
|
|
524 return TRUE;
|
|
525 }
|
|
526
|
|
527
|
|
528 u32 armcpu_exec(armcpu_t *armcpu)
|
|
529 {
|
|
530 u32 c = 1;
|
|
531
|
|
532 #ifdef GDB_STUB
|
|
533 if ( armcpu->stalled)
|
|
534 return STALLED_CYCLE_COUNT;
|
|
535
|
|
536 /* check for interrupts */
|
|
537 if ( armcpu->irq_flag) {
|
|
538 armcpu_irqExeption( armcpu);
|
|
539 }
|
|
540
|
|
541 c = armcpu_prefetch(armcpu);
|
|
542
|
|
543 if ( armcpu->stalled) {
|
|
544 return c;
|
|
545 }
|
|
546 #endif
|
|
547
|
|
548 if(armcpu->CPSR.bits.T == 0)
|
|
549 {
|
|
550 /* if((TEST_COND(CONDITION(armcpu->instruction), armcpu->CPSR)) || ((CONDITION(armcpu->instruction)==0xF)&&(CODE(armcpu->instruction)==0x5)))*/
|
|
551 if((TEST_COND(CONDITION(armcpu->instruction), CODE(armcpu->instruction), armcpu->CPSR)))
|
|
552 {
|
|
553 c += arm_instructions_set[INSTRUCTION_INDEX(armcpu->instruction)](armcpu);
|
|
554 }
|
|
555 #ifdef GDB_STUB
|
|
556 if ( armcpu->post_ex_fn != NULL) {
|
|
557 /* call the external post execute function */
|
|
558 armcpu->post_ex_fn( armcpu->post_ex_fn_data,
|
|
559 armcpu->instruct_adr, 0);
|
|
560 }
|
|
561 #else
|
|
562 c += armcpu_prefetch(armcpu);
|
|
563 #endif
|
|
564 return c;
|
|
565 }
|
|
566
|
|
567 c += thumb_instructions_set[armcpu->instruction>>6](armcpu);
|
|
568
|
|
569 #ifdef GDB_STUB
|
|
570 if ( armcpu->post_ex_fn != NULL) {
|
|
571 /* call the external post execute function */
|
|
572 armcpu->post_ex_fn( armcpu->post_ex_fn_data, armcpu->instruct_adr, 1);
|
|
573 }
|
|
574 #else
|
|
575 c += armcpu_prefetch(armcpu);
|
|
576 #endif
|
|
577 return c;
|
|
578 }
|
|
579
|