sim-main.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. #ifndef SIM_MAIN_H
  2. #define SIM_MAIN_H
  3. /* General config options */
  4. #define WITH_CORE
  5. #define WITH_MODULO_MEMORY 1
  6. #define WITH_WATCHPOINTS 1
  7. /* The v850 has 32bit words, numbered 31 (MSB) to 0 (LSB) */
  8. #define WITH_TARGET_WORD_MSB 31
  9. #include "config.h"
  10. #include "sim-basics.h"
  11. #include "sim-signal.h"
  12. #include "sim-fpu.h"
  13. #include "sim-base.h"
  14. #include "simops.h"
  15. #include "bfd.h"
  16. typedef signed8 int8;
  17. typedef unsigned8 uint8;
  18. typedef signed16 int16;
  19. typedef unsigned16 uint16;
  20. typedef signed32 int32;
  21. typedef unsigned32 uint32;
  22. typedef unsigned32 reg_t;
  23. typedef unsigned64 reg64_t;
  24. /* The current state of the processor; registers, memory, etc. */
  25. typedef struct _v850_regs {
  26. reg_t regs[32]; /* general-purpose registers */
  27. reg_t sregs[32]; /* system registers, including psw */
  28. reg_t pc;
  29. int dummy_mem; /* where invalid accesses go */
  30. reg_t mpu0_sregs[28]; /* mpu0 system registers */
  31. reg_t mpu1_sregs[28]; /* mpu1 system registers */
  32. reg_t fpu_sregs[28]; /* fpu system registers */
  33. reg_t selID_sregs[7][32]; /* system registers, selID 1 thru selID 7 */
  34. reg64_t vregs[32]; /* vector registers. */
  35. } v850_regs;
  36. struct _sim_cpu
  37. {
  38. /* ... simulator specific members ... */
  39. v850_regs reg;
  40. reg_t psw_mask; /* only allow non-reserved bits to be set */
  41. sim_event *pending_nmi;
  42. /* ... base type ... */
  43. sim_cpu_base base;
  44. };
  45. struct sim_state {
  46. sim_cpu *cpu[MAX_NR_PROCESSORS];
  47. #if 0
  48. SIM_ADDR rom_size;
  49. SIM_ADDR low_end;
  50. SIM_ADDR high_start;
  51. SIM_ADDR high_base;
  52. void *mem;
  53. #endif
  54. sim_state_base base;
  55. };
  56. /* For compatibility, until all functions converted to passing
  57. SIM_DESC as an argument */
  58. extern SIM_DESC simulator;
  59. #define V850_ROM_SIZE 0x8000
  60. #define V850_LOW_END 0x200000
  61. #define V850_HIGH_START 0xffe000
  62. /* Because we are still using the old semantic table, provide compat
  63. macro's that store the instruction where the old simops expects
  64. it. */
  65. extern uint32 OP[4];
  66. #if 0
  67. OP[0] = inst & 0x1f; /* RRRRR -> reg1 */
  68. OP[1] = (inst >> 11) & 0x1f; /* rrrrr -> reg2 */
  69. OP[2] = (inst >> 16) & 0xffff; /* wwwww -> reg3 OR imm16 */
  70. OP[3] = inst;
  71. #endif
  72. #define SAVE_1 \
  73. PC = cia; \
  74. OP[0] = instruction_0 & 0x1f; \
  75. OP[1] = (instruction_0 >> 11) & 0x1f; \
  76. OP[2] = 0; \
  77. OP[3] = instruction_0
  78. #define COMPAT_1(CALL) \
  79. SAVE_1; \
  80. PC += (CALL); \
  81. nia = PC
  82. #define SAVE_2 \
  83. PC = cia; \
  84. OP[0] = instruction_0 & 0x1f; \
  85. OP[1] = (instruction_0 >> 11) & 0x1f; \
  86. OP[2] = instruction_1; \
  87. OP[3] = (instruction_1 << 16) | instruction_0
  88. #define COMPAT_2(CALL) \
  89. SAVE_2; \
  90. PC += (CALL); \
  91. nia = PC
  92. /* new */
  93. #define GR ((CPU)->reg.regs)
  94. #define SR ((CPU)->reg.sregs)
  95. #define VR ((CPU)->reg.vregs)
  96. #define MPU0_SR ((STATE_CPU (sd, 0))->reg.mpu0_sregs)
  97. #define MPU1_SR ((STATE_CPU (sd, 0))->reg.mpu1_sregs)
  98. #define FPU_SR ((STATE_CPU (sd, 0))->reg.fpu_sregs)
  99. /* old */
  100. #define State (STATE_CPU (simulator, 0)->reg)
  101. #define PC (State.pc)
  102. #define SP_REGNO 3
  103. #define SP (State.regs[SP_REGNO])
  104. #define EP (State.regs[30])
  105. #define EIPC (State.sregs[0])
  106. #define EIPSW (State.sregs[1])
  107. #define FEPC (State.sregs[2])
  108. #define FEPSW (State.sregs[3])
  109. #define ECR (State.sregs[4])
  110. #define PSW (State.sregs[5])
  111. #define PSW_REGNO 5
  112. #define EIIC (State.sregs[13])
  113. #define FEIC (State.sregs[14])
  114. #define DBIC (SR[15])
  115. #define CTPC (SR[16])
  116. #define CTPSW (SR[17])
  117. #define DBPC (State.sregs[18])
  118. #define DBPSW (State.sregs[19])
  119. #define CTBP (State.sregs[20])
  120. #define DIR (SR[21])
  121. #define EIWR (SR[28])
  122. #define FEWR (SR[29])
  123. #define DBWR (SR[30])
  124. #define BSEL (SR[31])
  125. #define PSW_US BIT32 (8)
  126. #define PSW_NP 0x80
  127. #define PSW_EP 0x40
  128. #define PSW_ID 0x20
  129. #define PSW_SAT 0x10
  130. #define PSW_CY 0x8
  131. #define PSW_OV 0x4
  132. #define PSW_S 0x2
  133. #define PSW_Z 0x1
  134. #define PSW_NPV (1<<18)
  135. #define PSW_DMP (1<<17)
  136. #define PSW_IMP (1<<16)
  137. #define ECR_EICC 0x0000ffff
  138. #define ECR_FECC 0xffff0000
  139. /* FPU */
  140. #define FPSR (FPU_SR[6])
  141. #define FPSR_REGNO 6
  142. #define FPEPC (FPU_SR[7])
  143. #define FPST (FPU_SR[8])
  144. #define FPST_REGNO 8
  145. #define FPCC (FPU_SR[9])
  146. #define FPCFG (FPU_SR[10])
  147. #define FPCFG_REGNO 10
  148. #define FPSR_DEM 0x00200000
  149. #define FPSR_SEM 0x00100000
  150. #define FPSR_RM 0x000c0000
  151. #define FPSR_RN 0x00000000
  152. #define FPSR_FS 0x00020000
  153. #define FPSR_PR 0x00010000
  154. #define FPSR_XC 0x0000fc00
  155. #define FPSR_XCE 0x00008000
  156. #define FPSR_XCV 0x00004000
  157. #define FPSR_XCZ 0x00002000
  158. #define FPSR_XCO 0x00001000
  159. #define FPSR_XCU 0x00000800
  160. #define FPSR_XCI 0x00000400
  161. #define FPSR_XE 0x000003e0
  162. #define FPSR_XEV 0x00000200
  163. #define FPSR_XEZ 0x00000100
  164. #define FPSR_XEO 0x00000080
  165. #define FPSR_XEU 0x00000040
  166. #define FPSR_XEI 0x00000020
  167. #define FPSR_XP 0x0000001f
  168. #define FPSR_XPV 0x00000010
  169. #define FPSR_XPZ 0x00000008
  170. #define FPSR_XPO 0x00000004
  171. #define FPSR_XPU 0x00000002
  172. #define FPSR_XPI 0x00000001
  173. #define FPST_PR 0x00008000
  174. #define FPST_XCE 0x00002000
  175. #define FPST_XCV 0x00001000
  176. #define FPST_XCZ 0x00000800
  177. #define FPST_XCO 0x00000400
  178. #define FPST_XCU 0x00000200
  179. #define FPST_XCI 0x00000100
  180. #define FPST_XPV 0x00000010
  181. #define FPST_XPZ 0x00000008
  182. #define FPST_XPO 0x00000004
  183. #define FPST_XPU 0x00000002
  184. #define FPST_XPI 0x00000001
  185. #define FPCFG_RM 0x00000180
  186. #define FPCFG_XEV 0x00000010
  187. #define FPCFG_XEZ 0x00000008
  188. #define FPCFG_XEO 0x00000004
  189. #define FPCFG_XEU 0x00000002
  190. #define FPCFG_XEI 0x00000001
  191. #define GET_FPCC()\
  192. ((FPSR >> 24) &0xf)
  193. #define CLEAR_FPCC(bbb)\
  194. (FPSR &= ~(1 << (bbb+24)))
  195. #define SET_FPCC(bbb)\
  196. (FPSR |= 1 << (bbb+24))
  197. #define TEST_FPCC(bbb)\
  198. ((FPSR & (1 << (bbb+24))) != 0)
  199. #define FPSR_GET_ROUND() \
  200. (((FPSR & FPSR_RM) == FPSR_RN) ? sim_fpu_round_near \
  201. : ((FPSR & FPSR_RM) == 0x00040000) ? sim_fpu_round_up \
  202. : ((FPSR & FPSR_RM) == 0x00080000) ? sim_fpu_round_down \
  203. : sim_fpu_round_zero)
  204. enum FPU_COMPARE {
  205. FPU_CMP_F = 0,
  206. FPU_CMP_UN,
  207. FPU_CMP_EQ,
  208. FPU_CMP_UEQ,
  209. FPU_CMP_OLT,
  210. FPU_CMP_ULT,
  211. FPU_CMP_OLE,
  212. FPU_CMP_ULE,
  213. FPU_CMP_SF,
  214. FPU_CMP_NGLE,
  215. FPU_CMP_SEQ,
  216. FPU_CMP_NGL,
  217. FPU_CMP_LT,
  218. FPU_CMP_NGE,
  219. FPU_CMP_LE,
  220. FPU_CMP_NGT
  221. };
  222. /* MPU */
  223. #define MPM (MPU1_SR[0])
  224. #define MPC (MPU1_SR[1])
  225. #define MPC_REGNO 1
  226. #define TID (MPU1_SR[2])
  227. #define PPA (MPU1_SR[3])
  228. #define PPM (MPU1_SR[4])
  229. #define PPC (MPU1_SR[5])
  230. #define DCC (MPU1_SR[6])
  231. #define DCV0 (MPU1_SR[7])
  232. #define DCV1 (MPU1_SR[8])
  233. #define SPAL (MPU1_SR[10])
  234. #define SPAU (MPU1_SR[11])
  235. #define IPA0L (MPU1_SR[12])
  236. #define IPA0U (MPU1_SR[13])
  237. #define IPA1L (MPU1_SR[14])
  238. #define IPA1U (MPU1_SR[15])
  239. #define IPA2L (MPU1_SR[16])
  240. #define IPA2U (MPU1_SR[17])
  241. #define IPA3L (MPU1_SR[18])
  242. #define IPA3U (MPU1_SR[19])
  243. #define DPA0L (MPU1_SR[20])
  244. #define DPA0U (MPU1_SR[21])
  245. #define DPA1L (MPU1_SR[22])
  246. #define DPA1U (MPU1_SR[23])
  247. #define DPA2L (MPU1_SR[24])
  248. #define DPA2U (MPU1_SR[25])
  249. #define DPA3L (MPU1_SR[26])
  250. #define DPA3U (MPU1_SR[27])
  251. #define PPC_PPE 0x1
  252. #define SPAL_SPE 0x1
  253. #define SPAL_SPS 0x10
  254. #define VIP (MPU0_SR[0])
  255. #define VMECR (MPU0_SR[4])
  256. #define VMTID (MPU0_SR[5])
  257. #define VMADR (MPU0_SR[6])
  258. #define VPECR (MPU0_SR[8])
  259. #define VPTID (MPU0_SR[9])
  260. #define VPADR (MPU0_SR[10])
  261. #define VDECR (MPU0_SR[12])
  262. #define VDTID (MPU0_SR[13])
  263. #define MPM_AUE 0x2
  264. #define MPM_MPE 0x1
  265. #define VMECR_VMX 0x2
  266. #define VMECR_VMR 0x4
  267. #define VMECR_VMW 0x8
  268. #define VMECR_VMS 0x10
  269. #define VMECR_VMRMW 0x20
  270. #define VMECR_VMMS 0x40
  271. #define IPA2ADDR(IPA) ((IPA) & 0x1fffff80)
  272. #define IPA_IPE 0x1
  273. #define IPA_IPX 0x2
  274. #define IPA_IPR 0x4
  275. #define IPE0 (IPA0L & IPA_IPE)
  276. #define IPE1 (IPA1L & IPA_IPE)
  277. #define IPE2 (IPA2L & IPA_IPE)
  278. #define IPE3 (IPA3L & IPA_IPE)
  279. #define IPX0 (IPA0L & IPA_IPX)
  280. #define IPX1 (IPA1L & IPA_IPX)
  281. #define IPX2 (IPA2L & IPA_IPX)
  282. #define IPX3 (IPA3L & IPA_IPX)
  283. #define IPR0 (IPA0L & IPA_IPR)
  284. #define IPR1 (IPA1L & IPA_IPR)
  285. #define IPR2 (IPA2L & IPA_IPR)
  286. #define IPR3 (IPA3L & IPA_IPR)
  287. #define DPA2ADDR(DPA) ((DPA) & 0x1fffff80)
  288. #define DPA_DPE 0x1
  289. #define DPA_DPR 0x4
  290. #define DPA_DPW 0x8
  291. #define DPE0 (DPA0L & DPA_DPE)
  292. #define DPE1 (DPA1L & DPA_DPE)
  293. #define DPE2 (DPA2L & DPA_DPE)
  294. #define DPE3 (DPA3L & DPA_DPE)
  295. #define DPR0 (DPA0L & DPA_DPR)
  296. #define DPR1 (DPA1L & DPA_DPR)
  297. #define DPR2 (DPA2L & DPA_DPR)
  298. #define DPR3 (DPA3L & DPA_DPR)
  299. #define DPW0 (DPA0L & DPA_DPW)
  300. #define DPW1 (DPA1L & DPA_DPW)
  301. #define DPW2 (DPA2L & DPA_DPW)
  302. #define DPW3 (DPA3L & DPA_DPW)
  303. #define DCC_DCE0 0x1
  304. #define DCC_DCE1 0x10000
  305. #define PPA2ADDR(PPA) ((PPA) & 0x1fffff80)
  306. #define PPC_PPC 0xfffffffe
  307. #define PPC_PPE 0x1
  308. #define PPC_PPM 0x0000fff8
  309. #define SEXT3(x) ((((x)&0x7)^(~0x3))+0x4)
  310. /* sign-extend a 4-bit number */
  311. #define SEXT4(x) ((((x)&0xf)^(~0x7))+0x8)
  312. /* sign-extend a 5-bit number */
  313. #define SEXT5(x) ((((x)&0x1f)^(~0xf))+0x10)
  314. /* sign-extend a 9-bit number */
  315. #define SEXT9(x) ((((x)&0x1ff)^(~0xff))+0x100)
  316. /* sign-extend a 22-bit number */
  317. #define SEXT22(x) ((((x)&0x3fffff)^(~0x1fffff))+0x200000)
  318. /* sign extend a 40 bit number */
  319. #define SEXT40(x) ((((x) & UNSIGNED64 (0xffffffffff)) \
  320. ^ (~UNSIGNED64 (0x7fffffffff))) \
  321. + UNSIGNED64 (0x8000000000))
  322. /* sign extend a 44 bit number */
  323. #define SEXT44(x) ((((x) & UNSIGNED64 (0xfffffffffff)) \
  324. ^ (~ UNSIGNED64 (0x7ffffffffff))) \
  325. + UNSIGNED64 (0x80000000000))
  326. /* sign extend a 60 bit number */
  327. #define SEXT60(x) ((((x) & UNSIGNED64 (0xfffffffffffffff)) \
  328. ^ (~ UNSIGNED64 (0x7ffffffffffffff))) \
  329. + UNSIGNED64 (0x800000000000000))
  330. /* No sign extension */
  331. #define NOP(x) (x)
  332. #define INC_ADDR(x,i) x = ((State.MD && x == MOD_E) ? MOD_S : (x)+(i))
  333. #define RLW(x) load_mem (x, 4)
  334. /* Function declarations. */
  335. #define IMEM16(EA) \
  336. sim_core_read_aligned_2 (CPU, PC, exec_map, (EA))
  337. #define IMEM16_IMMED(EA,N) \
  338. sim_core_read_aligned_2 (STATE_CPU (sd, 0), \
  339. PC, exec_map, (EA) + (N) * 2)
  340. #define load_mem(ADDR,LEN) \
  341. sim_core_read_unaligned_##LEN (STATE_CPU (simulator, 0), \
  342. PC, read_map, (ADDR))
  343. #define store_mem(ADDR,LEN,DATA) \
  344. sim_core_write_unaligned_##LEN (STATE_CPU (simulator, 0), \
  345. PC, write_map, (ADDR), (DATA))
  346. /* compare cccc field against PSW */
  347. int condition_met (unsigned code);
  348. /* Debug/tracing calls */
  349. enum op_types
  350. {
  351. OP_UNKNOWN,
  352. OP_NONE,
  353. OP_TRAP,
  354. OP_REG,
  355. OP_REG_REG,
  356. OP_REG_REG_CMP,
  357. OP_REG_REG_MOVE,
  358. OP_IMM_REG,
  359. OP_IMM_REG_CMP,
  360. OP_IMM_REG_MOVE,
  361. OP_COND_BR,
  362. OP_LOAD16,
  363. OP_STORE16,
  364. OP_LOAD32,
  365. OP_STORE32,
  366. OP_JUMP,
  367. OP_IMM_REG_REG,
  368. OP_UIMM_REG_REG,
  369. OP_IMM16_REG_REG,
  370. OP_UIMM16_REG_REG,
  371. OP_BIT,
  372. OP_EX1,
  373. OP_EX2,
  374. OP_LDSR,
  375. OP_STSR,
  376. OP_BIT_CHANGE,
  377. OP_REG_REG_REG,
  378. OP_REG_REG3,
  379. OP_IMM_REG_REG_REG,
  380. OP_PUSHPOP1,
  381. OP_PUSHPOP2,
  382. OP_PUSHPOP3,
  383. };
  384. #ifdef DEBUG
  385. void trace_input (char *name, enum op_types type, int size);
  386. void trace_output (enum op_types result);
  387. void trace_result (int has_result, unsigned32 result);
  388. extern int trace_num_values;
  389. extern unsigned32 trace_values[];
  390. extern unsigned32 trace_pc;
  391. extern const char *trace_name;
  392. extern int trace_module;
  393. #define TRACE_BRANCH0() \
  394. do { \
  395. if (TRACE_BRANCH_P (CPU)) { \
  396. trace_module = TRACE_BRANCH_IDX; \
  397. trace_pc = cia; \
  398. trace_name = itable[MY_INDEX].name; \
  399. trace_num_values = 0; \
  400. trace_result (1, (nia)); \
  401. } \
  402. } while (0)
  403. #define TRACE_BRANCH1(IN1) \
  404. do { \
  405. if (TRACE_BRANCH_P (CPU)) { \
  406. trace_module = TRACE_BRANCH_IDX; \
  407. trace_pc = cia; \
  408. trace_name = itable[MY_INDEX].name; \
  409. trace_values[0] = (IN1); \
  410. trace_num_values = 1; \
  411. trace_result (1, (nia)); \
  412. } \
  413. } while (0)
  414. #define TRACE_BRANCH2(IN1, IN2) \
  415. do { \
  416. if (TRACE_BRANCH_P (CPU)) { \
  417. trace_module = TRACE_BRANCH_IDX; \
  418. trace_pc = cia; \
  419. trace_name = itable[MY_INDEX].name; \
  420. trace_values[0] = (IN1); \
  421. trace_values[1] = (IN2); \
  422. trace_num_values = 2; \
  423. trace_result (1, (nia)); \
  424. } \
  425. } while (0)
  426. #define TRACE_BRANCH3(IN1, IN2, IN3) \
  427. do { \
  428. if (TRACE_BRANCH_P (CPU)) { \
  429. trace_module = TRACE_BRANCH_IDX; \
  430. trace_pc = cia; \
  431. trace_name = itable[MY_INDEX].name; \
  432. trace_values[0] = (IN1); \
  433. trace_values[1] = (IN2); \
  434. trace_values[2] = (IN3); \
  435. trace_num_values = 3; \
  436. trace_result (1, (nia)); \
  437. } \
  438. } while (0)
  439. #define TRACE_LD(ADDR,RESULT) \
  440. do { \
  441. if (TRACE_MEMORY_P (CPU)) { \
  442. trace_module = TRACE_MEMORY_IDX; \
  443. trace_pc = cia; \
  444. trace_name = itable[MY_INDEX].name; \
  445. trace_values[0] = (ADDR); \
  446. trace_num_values = 1; \
  447. trace_result (1, (RESULT)); \
  448. } \
  449. } while (0)
  450. #define TRACE_LD_NAME(NAME, ADDR,RESULT) \
  451. do { \
  452. if (TRACE_MEMORY_P (CPU)) { \
  453. trace_module = TRACE_MEMORY_IDX; \
  454. trace_pc = cia; \
  455. trace_name = (NAME); \
  456. trace_values[0] = (ADDR); \
  457. trace_num_values = 1; \
  458. trace_result (1, (RESULT)); \
  459. } \
  460. } while (0)
  461. #define TRACE_ST(ADDR,RESULT) \
  462. do { \
  463. if (TRACE_MEMORY_P (CPU)) { \
  464. trace_module = TRACE_MEMORY_IDX; \
  465. trace_pc = cia; \
  466. trace_name = itable[MY_INDEX].name; \
  467. trace_values[0] = (ADDR); \
  468. trace_num_values = 1; \
  469. trace_result (1, (RESULT)); \
  470. } \
  471. } while (0)
  472. #define TRACE_FP_INPUT_FPU1(V0) \
  473. do { \
  474. if (TRACE_FPU_P (CPU)) \
  475. { \
  476. unsigned64 f0; \
  477. sim_fpu_to64 (&f0, (V0)); \
  478. trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, f0); \
  479. } \
  480. } while (0)
  481. #define TRACE_FP_INPUT_FPU2(V0, V1) \
  482. do { \
  483. if (TRACE_FPU_P (CPU)) \
  484. { \
  485. unsigned64 f0, f1; \
  486. sim_fpu_to64 (&f0, (V0)); \
  487. sim_fpu_to64 (&f1, (V1)); \
  488. trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, f0, f1); \
  489. } \
  490. } while (0)
  491. #define TRACE_FP_INPUT_FPU3(V0, V1, V2) \
  492. do { \
  493. if (TRACE_FPU_P (CPU)) \
  494. { \
  495. unsigned64 f0, f1, f2; \
  496. sim_fpu_to64 (&f0, (V0)); \
  497. sim_fpu_to64 (&f1, (V1)); \
  498. sim_fpu_to64 (&f2, (V2)); \
  499. trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, f0, f1, f2); \
  500. } \
  501. } while (0)
  502. #define TRACE_FP_INPUT_BOOL1_FPU2(V0, V1, V2) \
  503. do { \
  504. if (TRACE_FPU_P (CPU)) \
  505. { \
  506. int d0 = (V0); \
  507. unsigned64 f1, f2; \
  508. TRACE_DATA *data = CPU_TRACE_DATA (CPU); \
  509. TRACE_IDX (data) = TRACE_FPU_IDX; \
  510. sim_fpu_to64 (&f1, (V1)); \
  511. sim_fpu_to64 (&f2, (V2)); \
  512. save_data (SD, data, trace_fmt_bool, sizeof (d0), &d0); \
  513. save_data (SD, data, trace_fmt_fp, sizeof (fp_word), &f1); \
  514. save_data (SD, data, trace_fmt_fp, sizeof (fp_word), &f2); \
  515. } \
  516. } while (0)
  517. #define TRACE_FP_INPUT_WORD2(V0, V1) \
  518. do { \
  519. if (TRACE_FPU_P (CPU)) \
  520. trace_input_word2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
  521. } while (0)
  522. #define TRACE_FP_RESULT_FPU1(R0) \
  523. do { \
  524. if (TRACE_FPU_P (CPU)) \
  525. { \
  526. unsigned64 f0; \
  527. sim_fpu_to64 (&f0, (R0)); \
  528. trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, f0); \
  529. } \
  530. } while (0)
  531. #define TRACE_FP_RESULT_WORD1(R0) TRACE_FP_RESULT_WORD(R0)
  532. #define TRACE_FP_RESULT_WORD2(R0, R1) \
  533. do { \
  534. if (TRACE_FPU_P (CPU)) \
  535. trace_result_word2 (SD, CPU, TRACE_FPU_IDX, (R0), (R1)); \
  536. } while (0)
  537. #else
  538. #define trace_input(NAME, IN1, IN2)
  539. #define trace_output(RESULT)
  540. #define trace_result(HAS_RESULT, RESULT)
  541. #define TRACE_ALU_INPUT0()
  542. #define TRACE_ALU_INPUT1(IN0)
  543. #define TRACE_ALU_INPUT2(IN0, IN1)
  544. #define TRACE_ALU_INPUT2(IN0, IN1)
  545. #define TRACE_ALU_INPUT2(IN0, IN1 INS2)
  546. #define TRACE_ALU_RESULT(RESULT)
  547. #define TRACE_BRANCH0()
  548. #define TRACE_BRANCH1(IN1)
  549. #define TRACE_BRANCH2(IN1, IN2)
  550. #define TRACE_BRANCH2(IN1, IN2, IN3)
  551. #define TRACE_LD(ADDR,RESULT)
  552. #define TRACE_ST(ADDR,RESULT)
  553. #endif
  554. #define GPR_SET(N, VAL) (State.regs[(N)] = (VAL))
  555. #define GPR_CLEAR(N) (State.regs[(N)] = 0)
  556. extern void divun ( unsigned int N,
  557. unsigned long int als,
  558. unsigned long int sfi,
  559. unsigned32 /*unsigned long int*/ * quotient_ptr,
  560. unsigned32 /*unsigned long int*/ * remainder_ptr,
  561. int *overflow_ptr
  562. );
  563. extern void divn ( unsigned int N,
  564. unsigned long int als,
  565. unsigned long int sfi,
  566. signed32 /*signed long int*/ * quotient_ptr,
  567. signed32 /*signed long int*/ * remainder_ptr,
  568. int *overflow_ptr
  569. );
  570. extern int type1_regs[];
  571. extern int type2_regs[];
  572. extern int type3_regs[];
  573. #define SESR_OV (1 << 0)
  574. #define SESR_SOV (1 << 1)
  575. #define SESR (State.sregs[12])
  576. #define ROUND_Q62_Q31(X) ((((X) + (1 << 30)) >> 31) & 0xffffffff)
  577. #define ROUND_Q62_Q15(X) ((((X) + (1 << 30)) >> 47) & 0xffff)
  578. #define ROUND_Q31_Q15(X) ((((X) + (1 << 15)) >> 15) & 0xffff)
  579. #define ROUND_Q30_Q15(X) ((((X) + (1 << 14)) >> 15) & 0xffff)
  580. #define SAT16(X) \
  581. do \
  582. { \
  583. signed64 z = (X); \
  584. if (z > 0x7fff) \
  585. { \
  586. SESR |= SESR_OV | SESR_SOV; \
  587. z = 0x7fff; \
  588. } \
  589. else if (z < -0x8000) \
  590. { \
  591. SESR |= SESR_OV | SESR_SOV; \
  592. z = - 0x8000; \
  593. } \
  594. (X) = z; \
  595. } \
  596. while (0)
  597. #define SAT32(X) \
  598. do \
  599. { \
  600. signed64 z = (X); \
  601. if (z > 0x7fffffff) \
  602. { \
  603. SESR |= SESR_OV | SESR_SOV; \
  604. z = 0x7fffffff; \
  605. } \
  606. else if (z < -0x80000000) \
  607. { \
  608. SESR |= SESR_OV | SESR_SOV; \
  609. z = - 0x80000000; \
  610. } \
  611. (X) = z; \
  612. } \
  613. while (0)
  614. #define ABS16(X) \
  615. do \
  616. { \
  617. signed64 z = (X) & 0xffff; \
  618. if (z == 0x8000) \
  619. { \
  620. SESR |= SESR_OV | SESR_SOV; \
  621. z = 0x7fff; \
  622. } \
  623. else if (z & 0x8000) \
  624. { \
  625. z = (- z) & 0xffff; \
  626. } \
  627. (X) = z; \
  628. } \
  629. while (0)
  630. #define ABS32(X) \
  631. do \
  632. { \
  633. signed64 z = (X) & 0xffffffff; \
  634. if (z == 0x80000000) \
  635. { \
  636. SESR |= SESR_OV | SESR_SOV; \
  637. z = 0x7fffffff; \
  638. } \
  639. else if (z & 0x80000000) \
  640. { \
  641. z = (- z) & 0xffffffff; \
  642. } \
  643. (X) = z; \
  644. } \
  645. while (0)
  646. #endif