cpu.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* cpu.h --- declarations for the RX core.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. Contributed by Red Hat, Inc.
  4. This file is part of the GNU simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include <stdint.h>
  16. #include <setjmp.h>
  17. extern int verbose;
  18. extern int trace;
  19. extern int enable_counting;
  20. typedef uint8_t QI;
  21. typedef uint16_t HI;
  22. typedef uint32_t SI;
  23. typedef uint64_t DI;
  24. extern int rx_in_gdb;
  25. extern int rx_big_endian;
  26. typedef struct
  27. {
  28. SI r[16];
  29. SI r_psw;
  30. SI r_pc;
  31. SI r_usp;
  32. SI r_fpsw;
  33. SI r__reserved_cr_4;
  34. SI r__reserved_cr_5;
  35. SI r__reserved_cr_6;
  36. SI r__reserved_cr_7;
  37. SI r_bpsw;
  38. SI r_bpc;
  39. SI r_isp;
  40. SI r_fintv;
  41. SI r_intb;
  42. SI r__reserved_cr_13;
  43. SI r__reserved_cr_14;
  44. SI r__reserved_cr_15;
  45. SI r__reserved_cr_16;
  46. SI r__reserved_cr_17;
  47. SI r__reserved_cr_18;
  48. SI r__reserved_cr_19;
  49. SI r__reserved_cr_20;
  50. SI r__reserved_cr_21;
  51. SI r__reserved_cr_22;
  52. SI r__reserved_cr_23;
  53. SI r__reserved_cr_24;
  54. SI r__reserved_cr_25;
  55. SI r__reserved_cr_26;
  56. SI r__reserved_cr_27;
  57. SI r__reserved_cr_28;
  58. SI r__reserved_cr_29;
  59. SI r__reserved_cr_30;
  60. SI r__reserved_cr_31;
  61. SI r_temp;
  62. DI r_acc;
  63. #ifdef CYCLE_ACCURATE
  64. /* If set, RTS/RTSD take 2 fewer cycles. */
  65. char fast_return;
  66. SI link_register;
  67. unsigned long long cycle_count;
  68. /* Bits saying what kind of memory operands the previous insn had. */
  69. int m2m;
  70. /* Target register for load. */
  71. int rt;
  72. #endif
  73. } regs_type;
  74. #define M2M_SRC 0x01
  75. #define M2M_DST 0x02
  76. #define M2M_BOTH 0x03
  77. #define sp 0
  78. #define psw 16
  79. #define pc 17
  80. #define usp 18
  81. #define fpsw 19
  82. #define bpsw 24
  83. #define bpc 25
  84. #define isp 26
  85. #define fintv 27
  86. #define intb 28
  87. #define r_temp_idx 48
  88. #define acc64 49
  89. #define acchi 50
  90. #define accmi 51
  91. #define acclo 52
  92. extern regs_type regs;
  93. #define FLAGBIT_C 0x00000001
  94. #define FLAGBIT_Z 0x00000002
  95. #define FLAGBIT_S 0x00000004
  96. #define FLAGBIT_O 0x00000008
  97. #define FLAGBIT_I 0x00010000
  98. #define FLAGBIT_U 0x00020000
  99. #define FLAGBIT_PM 0x00100000
  100. #define FLAGBITS_IPL 0x0f000000
  101. #define FLAGSHIFT_IPL 24
  102. #define FPSWBITS_RM 0x00000003
  103. #define FPSWBITS_CV 0x00000004 /* invalid operation */
  104. #define FPSWBITS_CO 0x00000008 /* overflow */
  105. #define FPSWBITS_CZ 0x00000010 /* divide-by-zero */
  106. #define FPSWBITS_CU 0x00000020 /* underflow */
  107. #define FPSWBITS_CX 0x00000040 /* inexact */
  108. #define FPSWBITS_CE 0x00000080 /* unimplemented processing */
  109. #define FPSWBITS_CMASK 0x000000fc /* all the above */
  110. #define FPSWBITS_DN 0x00000100
  111. #define FPSW_CESH 8
  112. #define FPSWBITS_EV 0x00000400
  113. #define FPSWBITS_EO 0x00000800
  114. #define FPSWBITS_EZ 0x00001000
  115. #define FPSWBITS_EU 0x00002000
  116. #define FPSWBITS_EX 0x00004000
  117. #define FPSW_EFSH 16
  118. #define FPSW_CFSH 24
  119. #define FPSWBITS_FV 0x04000000
  120. #define FPSWBITS_FO 0x08000000
  121. #define FPSWBITS_FZ 0x10000000
  122. #define FPSWBITS_FU 0x20000000
  123. #define FPSWBITS_FX 0x40000000
  124. #define FPSWBITS_FSUM 0x80000000
  125. #define FPSWBITS_FMASK 0x7c000000
  126. #define FPSWBITS_CLEAR 0xffffff03 /* masked at start of any FP opcode */
  127. #define FPRM_NEAREST 0
  128. #define FPRM_ZERO 1
  129. #define FPRM_PINF 2
  130. #define FPRM_NINF 3
  131. extern char *reg_names[];
  132. extern int rx_flagmask;
  133. extern int rx_flagand;
  134. extern int rx_flagor;
  135. extern unsigned int b2mask[];
  136. extern unsigned int b2signbit[];
  137. extern int b2maxsigned[];
  138. extern int b2minsigned[];
  139. void init_regs (void);
  140. void stack_heap_stats (void);
  141. void set_pointer_width (int bytes);
  142. unsigned int get_reg (int id);
  143. unsigned long long get_reg64 (int id);
  144. void put_reg (int id, unsigned int value);
  145. void put_reg64 (int id, unsigned long long value);
  146. void set_flags (int mask, int newbits);
  147. void set_oszc (long long value, int bytes, int c);
  148. void set_szc (long long value, int bytes, int c);
  149. void set_osz (long long value, int bytes);
  150. void set_sz (long long value, int bytes);
  151. void set_zc (int z, int c);
  152. void set_c (int c);
  153. const char *bits (int v, int b);
  154. int condition_true (int cond_id);
  155. #define FLAG(f) ((regs.r_psw & f) ? 1 : 0)
  156. #define FLAG_C FLAG(FLAGBIT_C)
  157. #define FLAG_D FLAG(FLAGBIT_D)
  158. #define FLAG_Z FLAG(FLAGBIT_Z)
  159. #define FLAG_S FLAG(FLAGBIT_S)
  160. #define FLAG_B FLAG(FLAGBIT_B)
  161. #define FLAG_O FLAG(FLAGBIT_O)
  162. #define FLAG_I FLAG(FLAGBIT_I)
  163. #define FLAG_U FLAG(FLAGBIT_U)
  164. #define FLAG_PM FLAG(FLAGBIT_PM)
  165. /* Instruction step return codes.
  166. Suppose one of the decode_* functions below returns a value R:
  167. - If RX_STEPPED (R), then the single-step completed normally.
  168. - If RX_HIT_BREAK (R), then the program hit a breakpoint.
  169. - If RX_EXITED (R), then the program has done an 'exit' system
  170. call, and the exit code is RX_EXIT_STATUS (R).
  171. - If RX_STOPPED (R), then a signal (number RX_STOP_SIG (R)) was
  172. generated.
  173. For building step return codes:
  174. - RX_MAKE_STEPPED is the return code for finishing a normal step.
  175. - RX_MAKE_HIT_BREAK is the return code for hitting a breakpoint.
  176. - RX_MAKE_EXITED (C) is the return code for exiting with status C.
  177. - RX_MAKE_STOPPED (S) is the return code for stopping on signal S. */
  178. #define RX_MAKE_STEPPED() (1)
  179. #define RX_MAKE_HIT_BREAK() (2)
  180. #define RX_MAKE_EXITED(c) (((int) (c) << 8) + 3)
  181. #define RX_MAKE_STOPPED(s) (((int) (s) << 8) + 4)
  182. #define RX_STEPPED(r) ((r) == RX_MAKE_STEPPED ())
  183. #define RX_HIT_BREAK(r) ((r) == RX_MAKE_HIT_BREAK ())
  184. #define RX_EXITED(r) (((r) & 0xff) == 3)
  185. #define RX_EXIT_STATUS(r) ((r) >> 8)
  186. #define RX_STOPPED(r) (((r) & 0xff) == 4)
  187. #define RX_STOP_SIG(r) ((r) >> 8)
  188. /* The step result for the current step. Global to allow
  189. communication between the stepping function and the system
  190. calls. */
  191. extern int step_result;
  192. extern unsigned int rx_cycles;
  193. /* Used to detect heap/stack collisions. */
  194. extern unsigned int heaptop;
  195. extern unsigned int heapbottom;
  196. extern int decode_opcode (void);
  197. extern void reset_decoder (void);
  198. extern void reset_pipeline_stats (void);
  199. extern void halt_pipeline_stats (void);
  200. extern void pipeline_stats (void);
  201. extern void trace_register_changes (void);
  202. extern void generate_access_exception (void);
  203. extern jmp_buf decode_jmp_buf;