]>
Commit | Line | Data |
---|---|---|
aa49c64f | 1 | #include "config.h" |
2934d1c9 MH |
2 | #include <stdio.h> |
3 | #include <ctype.h> | |
7eebfc62 | 4 | #include <limits.h> |
2934d1c9 | 5 | #include "ansidecl.h" |
87178dbd | 6 | #include "callback.h" |
2934d1c9 | 7 | #include "opcode/d10v.h" |
b30cdd35 | 8 | #include "bfd.h" |
2934d1c9 | 9 | |
7eebfc62 MM |
10 | #define DEBUG_TRACE 0x00000001 |
11 | #define DEBUG_VALUES 0x00000002 | |
5c255669 MM |
12 | #define DEBUG_LINE_NUMBER 0x00000004 |
13 | #define DEBUG_MEMSIZE 0x00000008 | |
14 | #define DEBUG_INSTRUCTION 0x00000010 | |
15 | ||
16 | #ifndef DEBUG | |
17 | #define DEBUG (DEBUG_TRACE | DEBUG_VALUES | DEBUG_LINE_NUMBER) | |
18 | #endif | |
87178dbd | 19 | |
7eebfc62 | 20 | extern int d10v_debug; |
87178dbd | 21 | |
aa49c64f AC |
22 | #include "sim-types.h" |
23 | typedef unsigned8 uint8; | |
24 | typedef unsigned16 uint16; | |
25 | typedef signed16 int16; | |
26 | typedef unsigned32 uint32; | |
27 | typedef signed32 int32; | |
28 | typedef unsigned64 uint64; | |
29 | typedef signed64 int64; | |
7eebfc62 | 30 | |
2934d1c9 MH |
31 | /* FIXME: D10V defines */ |
32 | typedef uint16 reg_t; | |
33 | ||
34 | struct simops | |
35 | { | |
36 | long opcode; | |
aa49c64f | 37 | int is_long; |
2934d1c9 MH |
38 | long mask; |
39 | int format; | |
40 | int cycles; | |
41 | int unit; | |
42 | int exec_type; | |
43 | void (*func)(); | |
44 | int numops; | |
45 | int operands[9]; | |
46 | }; | |
47 | ||
87178dbd MM |
48 | enum _ins_type |
49 | { | |
aeb1f26b | 50 | INS_UNKNOWN, /* unknown instruction */ |
aeb1f26b MM |
51 | INS_COND_TRUE, /* # times EXExxx executed other instruction */ |
52 | INS_COND_FALSE, /* # times EXExxx did not execute other instruction */ | |
c422ecc7 | 53 | INS_COND_JUMP, /* # times JUMP skipped other instruction */ |
aeb1f26b | 54 | INS_CYCLES, /* # cycles */ |
c422ecc7 MH |
55 | INS_LONG, /* long instruction (both containers, ie FM == 11) */ |
56 | INS_LEFTRIGHT, /* # times instruction encoded as L -> R (ie, FM == 01) */ | |
57 | INS_RIGHTLEFT, /* # times instruction encoded as L <- R (ie, FM == 10) */ | |
58 | INS_PARALLEL, /* # times instruction encoded as L || R (ie, RM == 00) */ | |
aeb1f26b MM |
59 | |
60 | INS_LEFT, /* normal left instructions */ | |
61 | INS_LEFT_PARALLEL, /* left side of || */ | |
62 | INS_LEFT_COND_TEST, /* EXExx test on left side */ | |
63 | INS_LEFT_COND_EXE, /* execution after EXExxx test on right side succeeded */ | |
64 | INS_LEFT_NOPS, /* NOP on left side */ | |
65 | ||
66 | INS_RIGHT, /* normal right instructions */ | |
67 | INS_RIGHT_PARALLEL, /* right side of || */ | |
68 | INS_RIGHT_COND_TEST, /* EXExx test on right side */ | |
69 | INS_RIGHT_COND_EXE, /* execution after EXExxx test on left side succeeded */ | |
70 | INS_RIGHT_NOPS, /* NOP on right side */ | |
71 | ||
7eebfc62 | 72 | INS_MAX |
87178dbd MM |
73 | }; |
74 | ||
aeb1f26b | 75 | extern unsigned long ins_type_counters[ (int)INS_MAX ]; |
7eebfc62 | 76 | |
2934d1c9 MH |
77 | struct _state |
78 | { | |
79 | reg_t regs[16]; /* general-purpose registers */ | |
5c255669 MM |
80 | reg_t cregs[16]; /* control registers */ |
81 | int64 a[2]; /* accumulators */ | |
2934d1c9 MH |
82 | uint8 SM; |
83 | uint8 EA; | |
84 | uint8 DB; | |
7f48c9fe | 85 | uint8 DM; |
2934d1c9 MH |
86 | uint8 IE; |
87 | uint8 RP; | |
88 | uint8 MD; | |
89 | uint8 FX; | |
90 | uint8 ST; | |
91 | uint8 F0; | |
92 | uint8 F1; | |
93 | uint8 C; | |
94 | uint8 exe; | |
aa49c64f AC |
95 | int exception; |
96 | int pc_changed; | |
c422ecc7 | 97 | /* everything below this line is not reset by sim_create_inferior() */ |
2934d1c9 MH |
98 | uint8 *imem; |
99 | uint8 *dmem; | |
c422ecc7 | 100 | uint8 *umem[128]; |
87178dbd | 101 | enum _ins_type ins_type; |
2934d1c9 MH |
102 | } State; |
103 | ||
87178dbd | 104 | extern host_callback *d10v_callback; |
2934d1c9 MH |
105 | extern uint16 OP[4]; |
106 | extern struct simops Simops[]; | |
b30cdd35 MM |
107 | extern asection *text; |
108 | extern bfd_vma text_start; | |
109 | extern bfd_vma text_end; | |
aa49c64f | 110 | extern bfd *prog_bfd; |
2934d1c9 | 111 | |
bc6df23d AC |
112 | enum |
113 | { | |
114 | PSW_CR = 0, | |
115 | BPSW_CR = 1, | |
116 | PC_CR = 2, | |
117 | BPC_CR = 3, | |
118 | RPT_C_CR = 7, | |
119 | RPT_S_CR = 8, | |
120 | RPT_E_CR = 9, | |
121 | MOD_S_CR = 10, | |
122 | MOD_E_CR = 11, | |
123 | IBA_CR = 14, | |
124 | }; | |
125 | ||
126 | enum | |
127 | { | |
128 | PSW_SM_BIT = 0x8000, | |
129 | PSW_EA_BIT = 0x2000, | |
130 | PSW_DB_BIT = 0x1000, | |
131 | PSW_DM_BIT = 0x0800, | |
132 | PSW_IE_BIT = 0x0400, | |
133 | PSW_RP_BIT = 0x0200, | |
134 | PSW_MD_BIT = 0x0100, | |
135 | PSW_FX_BIT = 0x0080, | |
136 | PSW_ST_BIT = 0x0040, | |
137 | PSW_F0_BIT = 0x0008, | |
138 | PSW_F1_BIT = 0x0004, | |
139 | PSW_C_BIT = 0x0001, | |
140 | }; | |
141 | ||
142 | /* See simopsc.:move_to_cr() for registers that can not be read-from | |
143 | or assigned-to directly */ | |
144 | #define PC (State.cregs[PC_CR]) | |
145 | #define PSW (move_from_cr (PSW_CR)) | |
146 | #define BPSW (0 + State.cregs[PSW_CR]) | |
147 | #define BPC (State.cregs[BPC_CR]) | |
148 | #define RPT_C (State.cregs[RPT_C_CR]) | |
149 | #define RPT_S (State.cregs[RPT_E_CR]) | |
150 | #define RPT_E (State.cregs[RPT_E_CR]) | |
151 | #define MOD_S (0 + State.cregs[MOD_S_CR]) | |
152 | #define MOD_E (0 + State.cregs[MOD_E_CR]) | |
153 | #define IBA (State.cregs[IBA_CR]) | |
2934d1c9 | 154 | |
5c255669 MM |
155 | #define SIG_D10V_STOP -1 |
156 | #define SIG_D10V_EXIT -2 | |
157 | ||
2934d1c9 MH |
158 | #define SEXT3(x) ((((x)&0x7)^(~3))+4) |
159 | ||
160 | /* sign-extend a 4-bit number */ | |
161 | #define SEXT4(x) ((((x)&0xf)^(~7))+8) | |
162 | ||
163 | /* sign-extend an 8-bit number */ | |
164 | #define SEXT8(x) ((((x)&0xff)^(~0x7f))+0x80) | |
165 | ||
166 | /* sign-extend a 16-bit number */ | |
167 | #define SEXT16(x) ((((x)&0xffff)^(~0x7fff))+0x8000) | |
168 | ||
4f425a32 | 169 | /* sign-extend a 32-bit number */ |
aa49c64f | 170 | #define SEXT32(x) ((((x)&SIGNED64(0xffffffff))^(~SIGNED64(0x7fffffff)))+SIGNED64(0x80000000)) |
4f425a32 | 171 | |
4c38885c | 172 | /* sign extend a 40 bit number */ |
aa49c64f | 173 | #define SEXT40(x) ((((x)&SIGNED64(0xffffffffff))^(~SIGNED64(0x7fffffffff)))+SIGNED64(0x8000000000)) |
4c38885c | 174 | |
d70b4d42 | 175 | /* sign extend a 44 bit number */ |
aa49c64f AC |
176 | #define SEXT44(x) ((((x)&SIGNED64(0xfffffffffff))^(~SIGNED64(0x7ffffffffff)))+SIGNED64(0x80000000000)) |
177 | ||
178 | /* sign extend a 56 bit number */ | |
179 | #define SEXT56(x) ((((x)&SIGNED64(0xffffffffffffff))^(~SIGNED64(0x7fffffffffffff)))+SIGNED64(0x80000000000000)) | |
d70b4d42 MH |
180 | |
181 | /* sign extend a 60 bit number */ | |
aa49c64f | 182 | #define SEXT60(x) ((((x)&SIGNED64(0xfffffffffffffff))^(~SIGNED64(0x7ffffffffffffff)))+SIGNED64(0x800000000000000)) |
d70b4d42 | 183 | |
aa49c64f AC |
184 | #define MAX32 SIGNED64(0x7fffffff) |
185 | #define MIN32 SIGNED64(0xff80000000) | |
186 | #define MASK32 SIGNED64(0xffffffff) | |
187 | #define MASK40 SIGNED64(0xffffffffff) | |
2934d1c9 | 188 | |
aa49c64f AC |
189 | /* The alignment of MOD_E in the following macro depends upon "i" always being a power of 2. */ |
190 | #define INC_ADDR(x,i) x = ((State.MD && x == (MOD_E & ~((i)-1))) ? MOD_S : (x)+(i)) | |
4f425a32 | 191 | |
c422ecc7 | 192 | extern uint8 *dmem_addr PARAMS ((uint32)); |
b30cdd35 | 193 | extern bfd_vma decode_pc PARAMS ((void)); |
c422ecc7 MH |
194 | |
195 | #define RB(x) (*(dmem_addr(x))) | |
4c38885c | 196 | #define SB(addr,data) ( RB(addr) = (data & 0xff)) |
2934d1c9 | 197 | |
5c255669 MM |
198 | #if defined(__GNUC__) && defined(__OPTIMIZE__) && !defined(NO_ENDIAN_INLINE) |
199 | #define ENDIAN_INLINE static __inline__ | |
200 | #include "endian.c" | |
201 | #undef ENDIAN_INLINE | |
2934d1c9 MH |
202 | |
203 | #else | |
d6fe5ca5 MM |
204 | extern uint32 get_longword PARAMS ((uint8 *)); |
205 | extern uint16 get_word PARAMS ((uint8 *)); | |
206 | extern int64 get_longlong PARAMS ((uint8 *)); | |
207 | extern void write_word PARAMS ((uint8 *addr, uint16 data)); | |
208 | extern void write_longword PARAMS ((uint8 *addr, uint32 data)); | |
209 | extern void write_longlong PARAMS ((uint8 *addr, int64 data)); | |
5c255669 | 210 | #endif |
d70b4d42 | 211 | |
c422ecc7 MH |
212 | #define SW(addr,data) write_word(dmem_addr(addr),data) |
213 | #define RW(x) get_word(dmem_addr(x)) | |
214 | #define SLW(addr,data) write_longword(dmem_addr(addr),data) | |
215 | #define RLW(x) get_longword(dmem_addr(x)) | |
d70b4d42 MH |
216 | #define READ_16(x) get_word(x) |
217 | #define WRITE_16(addr,data) write_word(addr,data) | |
218 | #define READ_64(x) get_longlong(x) | |
219 | #define WRITE_64(addr,data) write_longlong(addr,data) | |
c422ecc7 MH |
220 | |
221 | #define IMAP0 RW(0xff00) | |
222 | #define IMAP1 RW(0xff02) | |
223 | #define DMAP RW(0xff04) | |
224 | #define SET_IMAP0(x) SW(0xff00,x) | |
225 | #define SET_IMAP1(x) SW(0xff02,x) | |
226 | #define SET_DMAP(x) SW(0xff04,x) | |
aa49c64f AC |
227 | |
228 | #define JMP(x) { PC = (x); State.pc_changed = 1; } | |
bc6df23d AC |
229 | |
230 | #define AE_VECTOR_START 0xffc3 | |
231 | #define RIE_VECTOR_START 0xffc2 | |
232 | #define SDBT_VECTOR_START 0xffd5 | |
233 | #define TRAP_VECTOR_START 0xffc4 /* vector for trap 0 */ | |
234 | ||
235 | extern void move_to_cr PARAMS ((int cr, reg_t val)); | |
236 | extern reg_t move_from_cr PARAMS ((int cr)); |