5 #include "opcode/mn10300.h"
7 #include "remote-sim.h"
17 extern host_callback *mn10300_callback;
18 extern SIM_DESC simulator;
20 #define DEBUG_TRACE 0x00000001
21 #define DEBUG_VALUES 0x00000002
23 extern int mn10300_debug;
26 typedef unsigned char uint8;
27 typedef signed char int8;
29 #error "Char is not an 8-bit type"
33 typedef unsigned short uint16;
34 typedef signed short int16;
36 #error "Short is not a 16-bit type"
39 #if INT_MAX == 2147483647
41 typedef unsigned int uint32;
42 typedef signed int int32;
45 # if LONG_MAX == 2147483647
47 typedef unsigned long uint32;
48 typedef signed long int32;
51 # error "Neither int nor long is a 32-bit type"
68 /* The current state of the processor; registers, memory, etc. */
72 reg_t regs[15]; /* registers, d0-d3, a0-a3, sp, pc, mdr, psw,
74 uint8 *mem; /* main memory */
80 extern struct simops Simops[];
82 #define PC (State.regs[9])
84 #define PSW (State.regs[11])
101 /* These definitions conflict with similar macros in common. */
103 #define SEXT3(x) ((((x)&0x7)^(~0x3))+0x4)
105 /* sign-extend a 4-bit number */
106 #define SEXT4(x) ((((x)&0xf)^(~0x7))+0x8)
108 /* sign-extend a 5-bit number */
109 #define SEXT5(x) ((((x)&0x1f)^(~0xf))+0x10)
111 /* sign-extend an 8-bit number */
112 #define SEXT8(x) ((((x)&0xff)^(~0x7f))+0x80)
114 /* sign-extend a 9-bit number */
115 #define SEXT9(x) ((((x)&0x1ff)^(~0xff))+0x100)
117 /* sign-extend a 16-bit number */
118 #define SEXT16(x) ((((x)&0xffff)^(~0x7fff))+0x8000)
120 /* sign-extend a 22-bit number */
121 #define SEXT22(x) ((((x)&0x3fffff)^(~0x1fffff))+0x200000)
123 #define MAX32 0x7fffffffLL
124 #define MIN32 0xff80000000LL
125 #define MASK32 0xffffffffLL
126 #define MASK40 0xffffffffffLL
127 #endif /* not WITH_COMMON */
136 #define FETCH32(a,b,c,d) \
137 ((a)+((b)<<8)+((c)<<16)+((d)<<24))
139 #define FETCH16(a,b) ((a)+((b)<<8))
141 #define load_byte(ADDR) \
142 sim_core_read_unaligned_1 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
144 #define load_half(ADDR) \
145 sim_core_read_unaligned_2 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
147 #define load_word(ADDR) \
148 sim_core_read_unaligned_4 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
150 #define store_byte(ADDR, DATA) \
151 sim_core_write_unaligned_1 (STATE_CPU (simulator, 0), \
152 PC, write_map, (ADDR), (DATA))
155 #define store_half(ADDR, DATA) \
156 sim_core_write_unaligned_2 (STATE_CPU (simulator, 0), \
157 PC, write_map, (ADDR), (DATA))
160 #define store_word(ADDR, DATA) \
161 sim_core_write_unaligned_4 (STATE_CPU (simulator, 0), \
162 PC, write_map, (ADDR), (DATA))
163 #endif /* WITH_COMMON */
167 #define load_mem_big(addr,len) \
168 (len == 1 ? *((addr) + State.mem) : \
169 len == 2 ? ((*((addr) + State.mem) << 8) \
170 | *(((addr) + 1) + State.mem)) : \
171 len == 3 ? ((*((addr) + State.mem) << 16) \
172 | (*(((addr) + 1) + State.mem) << 8) \
173 | *(((addr) + 2) + State.mem)) : \
174 ((*((addr) + State.mem) << 24) \
175 | (*(((addr) + 1) + State.mem) << 16) \
176 | (*(((addr) + 2) + State.mem) << 8) \
177 | *(((addr) + 3) + State.mem)))
183 uint8 *p = (addr & 0xffffff) + State.mem;
186 if ((addr & 0xffffff) > max_mem)
197 uint8 *p = (addr & 0xffffff) + State.mem;
200 if ((addr & 0xffffff) > max_mem)
204 return p[1] << 8 | p[0];
211 uint8 *p = (addr & 0xffffff) + State.mem;
214 if ((addr & 0xffffff) > max_mem)
218 return p[2] << 16 | p[1] << 8 | p[0];
225 uint8 *p = (addr & 0xffffff) + State.mem;
228 if ((addr & 0xffffff) > max_mem)
232 return p[3] << 24 | p[2] << 16 | p[1] << 8 | p[0];
240 uint8 *p = (addr & 0xffffff) + State.mem;
243 if ((addr & 0xffffff) > max_mem)
252 return p[1] << 8 | p[0];
254 return p[2] << 16 | p[1] << 8 | p[0];
256 return p[3] << 24 | p[2] << 16 | p[1] << 8 | p[0];
263 store_byte (addr, data)
267 uint8 *p = (addr & 0xffffff) + State.mem;
270 if ((addr & 0xffffff) > max_mem)
278 store_half (addr, data)
282 uint8 *p = (addr & 0xffffff) + State.mem;
285 if ((addr & 0xffffff) > max_mem)
294 store_3_byte (addr, data)
298 uint8 *p = (addr & 0xffffff) + State.mem;
301 if ((addr & 0xffffff) > max_mem)
311 store_word (addr, data)
315 uint8 *p = (addr & 0xffffff) + State.mem;
318 if ((addr & 0xffffff) > max_mem)
327 #endif /* not WITH_COMMON */
329 /* Function declarations. */
331 uint32 get_word PARAMS ((uint8 *));
332 uint16 get_half PARAMS ((uint8 *));
333 uint8 get_byte PARAMS ((uint8 *));
334 void put_word PARAMS ((uint8 *, uint32));
335 void put_half PARAMS ((uint8 *, uint16));
336 void put_byte PARAMS ((uint8 *, uint8));
338 extern uint8 *map PARAMS ((SIM_ADDR addr));