mn10300_sim.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "ansidecl.h"
  4. #include "sim/callback.h"
  5. #include "opcode/mn10300.h"
  6. #include <limits.h>
  7. #include "sim/sim.h"
  8. #include "bfd.h"
  9. #include "sim-fpu.h"
  10. #include "sim-signal.h"
  11. extern SIM_DESC simulator;
  12. typedef struct
  13. {
  14. uint32_t low, high;
  15. } dword;
  16. typedef uint32_t reg_t;
  17. struct simops
  18. {
  19. long opcode;
  20. long mask;
  21. void (*func)();
  22. int length;
  23. int format;
  24. int numops;
  25. int operands[16];
  26. };
  27. /* The current state of the processor; registers, memory, etc. */
  28. struct _state
  29. {
  30. reg_t regs[32]; /* registers, d0-d3, a0-a3, sp, pc, mdr, psw,
  31. lir, lar, mdrq, plus some room for processor
  32. specific regs. */
  33. union
  34. {
  35. reg_t fs[32]; /* FS0-31 */
  36. dword fd[16]; /* FD0,2,...,30 */
  37. } fpregs;
  38. /* All internal state modified by signal_exception() that may need to be
  39. rolled back for passing moment-of-exception image back to gdb. */
  40. reg_t exc_trigger_regs[32];
  41. reg_t exc_suspend_regs[32];
  42. int exc_suspended;
  43. #define SIM_CPU_EXCEPTION_TRIGGER(SD,CPU,CIA) mn10300_cpu_exception_trigger(SD,CPU,CIA)
  44. #define SIM_CPU_EXCEPTION_SUSPEND(SD,CPU,EXC) mn10300_cpu_exception_suspend(SD,CPU,EXC)
  45. #define SIM_CPU_EXCEPTION_RESUME(SD,CPU,EXC) mn10300_cpu_exception_resume(SD,CPU,EXC)
  46. };
  47. extern struct _state State;
  48. #define PC (State.regs[REG_PC])
  49. #define SP (State.regs[REG_SP])
  50. #define PSW (State.regs[11])
  51. #define PSW_Z 0x1
  52. #define PSW_N 0x2
  53. #define PSW_C 0x4
  54. #define PSW_V 0x8
  55. #define PSW_IE LSBIT (11)
  56. #define PSW_LM LSMASK (10, 8)
  57. #define EXTRACT_PSW_LM LSEXTRACTED16 (PSW, 10, 8)
  58. #define INSERT_PSW_LM(l) LSINSERTED16 ((l), 10, 8)
  59. #define REG_D0 0
  60. #define REG_A0 4
  61. #define REG_SP 8
  62. #define REG_PC 9
  63. #define REG_MDR 10
  64. #define REG_PSW 11
  65. #define REG_LIR 12
  66. #define REG_LAR 13
  67. #define REG_MDRQ 14
  68. #define REG_E0 15
  69. #define REG_SSP 23
  70. #define REG_MSP 24
  71. #define REG_USP 25
  72. #define REG_MCRH 26
  73. #define REG_MCRL 27
  74. #define REG_MCVF 28
  75. #define REG_FPCR 29
  76. #define FPCR (State.regs[REG_FPCR])
  77. #define FCC_MASK LSMASK (21, 18)
  78. #define RM_MASK LSMASK (17, 16) /* Must always be zero. */
  79. #define EC_MASK LSMASK (14, 10)
  80. #define EE_MASK LSMASK ( 9, 5)
  81. #define EF_MASK LSMASK ( 4, 0)
  82. #define FPCR_MASK (FCC_MASK | EC_MASK | EE_MASK | EF_MASK)
  83. #define FCC_L LSBIT (21)
  84. #define FCC_G LSBIT (20)
  85. #define FCC_E LSBIT (19)
  86. #define FCC_U LSBIT (18)
  87. #define EC_V LSBIT (14)
  88. #define EC_Z LSBIT (13)
  89. #define EC_O LSBIT (12)
  90. #define EC_U LSBIT (11)
  91. #define EC_I LSBIT (10)
  92. #define EE_V LSBIT (9)
  93. #define EE_Z LSBIT (8)
  94. #define EE_O LSBIT (7)
  95. #define EE_U LSBIT (6)
  96. #define EE_I LSBIT (5)
  97. #define EF_V LSBIT (4)
  98. #define EF_Z LSBIT (3)
  99. #define EF_O LSBIT (2)
  100. #define EF_U LSBIT (1)
  101. #define EF_I LSBIT (0)
  102. #define PSW_FE LSBIT(20)
  103. #define FPU_DISABLED !(PSW & PSW_FE)
  104. #define XS2FS(X,S) State.fpregs.fs[((X<<4)|(S))]
  105. #define AS2FS(A,S) State.fpregs.fs[((A<<2)|(S))]
  106. #define Xf2FD(X,f) State.fpregs.fd[((X<<3)|(f))]
  107. #define FS2FPU(FS,F) sim_fpu_32to (&(F), (FS))
  108. #define FD2FPU(FD,F) sim_fpu_232to (&(F), ((FD).high), ((FD).low))
  109. #define FPU2FS(F,FS) sim_fpu_to32 (&(FS), &(F))
  110. #define FPU2FD(F,FD) sim_fpu_to232 (&((FD).high), &((FD).low), &(F))
  111. #define FETCH32(a,b,c,d) \
  112. ((a)+((b)<<8)+((c)<<16)+((d)<<24))
  113. #define FETCH24(a,b,c) \
  114. ((a)+((b)<<8)+((c)<<16))
  115. #define FETCH16(a,b) ((a)+((b)<<8))
  116. #define load_byte(ADDR) \
  117. sim_core_read_unaligned_1 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
  118. #define load_half(ADDR) \
  119. sim_core_read_unaligned_2 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
  120. #define load_word(ADDR) \
  121. sim_core_read_unaligned_4 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
  122. #define load_dword(ADDR) \
  123. u642dw (sim_core_read_unaligned_8 (STATE_CPU (simulator, 0), \
  124. PC, read_map, (ADDR)))
  125. static INLINE2 dword
  126. u642dw (uint64_t dw)
  127. {
  128. dword r;
  129. r.low = (uint32_t)dw;
  130. r.high = (uint32_t)(dw >> 32);
  131. return r;
  132. }
  133. #define store_byte(ADDR, DATA) \
  134. sim_core_write_unaligned_1 (STATE_CPU (simulator, 0), \
  135. PC, write_map, (ADDR), (DATA))
  136. #define store_half(ADDR, DATA) \
  137. sim_core_write_unaligned_2 (STATE_CPU (simulator, 0), \
  138. PC, write_map, (ADDR), (DATA))
  139. #define store_word(ADDR, DATA) \
  140. sim_core_write_unaligned_4 (STATE_CPU (simulator, 0), \
  141. PC, write_map, (ADDR), (DATA))
  142. #define store_dword(ADDR, DATA) \
  143. sim_core_write_unaligned_8 (STATE_CPU (simulator, 0), \
  144. PC, write_map, (ADDR), dw2u64 (DATA))
  145. static INLINE2 uint64_t
  146. dw2u64 (dword data)
  147. {
  148. return data.low | (((uint64_t)data.high) << 32);
  149. }
  150. /* Function declarations. */
  151. INLINE_SIM_MAIN (void) genericAdd (uint32_t source, uint32_t destReg);
  152. INLINE_SIM_MAIN (void) genericSub (uint32_t source, uint32_t destReg);
  153. INLINE_SIM_MAIN (void) genericCmp (uint32_t leftOpnd, uint32_t rightOpnd);
  154. INLINE_SIM_MAIN (void) genericOr (uint32_t source, uint32_t destReg);
  155. INLINE_SIM_MAIN (void) genericXor (uint32_t source, uint32_t destReg);
  156. INLINE_SIM_MAIN (void) genericBtst (uint32_t leftOpnd, uint32_t rightOpnd);
  157. INLINE_SIM_MAIN (void) do_syscall (SIM_DESC sd);
  158. void program_interrupt (SIM_DESC sd, sim_cpu *cpu, sim_cia cia, SIM_SIGNAL sig);
  159. void mn10300_cpu_exception_trigger(SIM_DESC sd, sim_cpu* cpu, address_word pc);
  160. void mn10300_cpu_exception_suspend(SIM_DESC sd, sim_cpu* cpu, int exception);
  161. void mn10300_cpu_exception_resume(SIM_DESC sd, sim_cpu* cpu, int exception);
  162. void fpu_disabled_exception (SIM_DESC, sim_cpu *, address_word);
  163. void fpu_unimp_exception (SIM_DESC, sim_cpu *, address_word);
  164. void fpu_check_signal_exception (SIM_DESC, sim_cpu *, address_word);
  165. extern const struct fp_prec_t
  166. {
  167. void (* reg2val) (const void *, sim_fpu *);
  168. int (* round) (sim_fpu *);
  169. void (* val2reg) (const sim_fpu *, void *);
  170. } fp_single_prec, fp_double_prec;
  171. #define FP_SINGLE (&fp_single_prec)
  172. #define FP_DOUBLE (&fp_double_prec)
  173. void fpu_rsqrt (SIM_DESC, sim_cpu *, address_word, const void *, void *, const struct fp_prec_t *);
  174. void fpu_sqrt (SIM_DESC, sim_cpu *, address_word, const void *, void *, const struct fp_prec_t *);
  175. void fpu_cmp (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const struct fp_prec_t *);
  176. void fpu_add (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
  177. void fpu_sub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
  178. void fpu_mul (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
  179. void fpu_div (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
  180. void fpu_fmadd (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
  181. void fpu_fmsub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
  182. void fpu_fnmadd (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
  183. void fpu_fnmsub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);