annotate src/xsf/desmume/armcpu.c @ 2961:70b0973e7b70

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