cpu.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * CRIS virtual CPU header
  3. *
  4. * Copyright (c) 2007 AXIS Communications AB
  5. * Written by Edgar E. Iglesias
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef CPU_CRIS_H
  21. #define CPU_CRIS_H
  22. #include "config.h"
  23. #include "qemu-common.h"
  24. #define TARGET_LONG_BITS 32
  25. #define CPUArchState struct CPUCRISState
  26. #include "exec/cpu-defs.h"
  27. #define EXCP_NMI 1
  28. #define EXCP_GURU 2
  29. #define EXCP_BUSFAULT 3
  30. #define EXCP_IRQ 4
  31. #define EXCP_BREAK 5
  32. /* CRIS-specific interrupt pending bits. */
  33. #define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_3
  34. /* CRUS CPU device objects interrupt lines. */
  35. #define CRIS_CPU_IRQ 0
  36. #define CRIS_CPU_NMI 1
  37. /* Register aliases. R0 - R15 */
  38. #define R_FP 8
  39. #define R_SP 14
  40. #define R_ACR 15
  41. /* Support regs, P0 - P15 */
  42. #define PR_BZ 0
  43. #define PR_VR 1
  44. #define PR_PID 2
  45. #define PR_SRS 3
  46. #define PR_WZ 4
  47. #define PR_EXS 5
  48. #define PR_EDA 6
  49. #define PR_PREFIX 6 /* On CRISv10 P6 is reserved, we use it as prefix. */
  50. #define PR_MOF 7
  51. #define PR_DZ 8
  52. #define PR_EBP 9
  53. #define PR_ERP 10
  54. #define PR_SRP 11
  55. #define PR_NRP 12
  56. #define PR_CCS 13
  57. #define PR_USP 14
  58. #define PRV10_BRP 14
  59. #define PR_SPC 15
  60. /* CPU flags. */
  61. #define Q_FLAG 0x80000000
  62. #define M_FLAG_V32 0x40000000
  63. #define PFIX_FLAG 0x800 /* CRISv10 Only. */
  64. #define F_FLAG_V10 0x400
  65. #define P_FLAG_V10 0x200
  66. #define S_FLAG 0x200
  67. #define R_FLAG 0x100
  68. #define P_FLAG 0x80
  69. #define M_FLAG_V10 0x80
  70. #define U_FLAG 0x40
  71. #define I_FLAG 0x20
  72. #define X_FLAG 0x10
  73. #define N_FLAG 0x08
  74. #define Z_FLAG 0x04
  75. #define V_FLAG 0x02
  76. #define C_FLAG 0x01
  77. #define ALU_FLAGS 0x1F
  78. /* Condition codes. */
  79. #define CC_CC 0
  80. #define CC_CS 1
  81. #define CC_NE 2
  82. #define CC_EQ 3
  83. #define CC_VC 4
  84. #define CC_VS 5
  85. #define CC_PL 6
  86. #define CC_MI 7
  87. #define CC_LS 8
  88. #define CC_HI 9
  89. #define CC_GE 10
  90. #define CC_LT 11
  91. #define CC_GT 12
  92. #define CC_LE 13
  93. #define CC_A 14
  94. #define CC_P 15
  95. #define NB_MMU_MODES 2
  96. typedef struct {
  97. uint32_t hi;
  98. uint32_t lo;
  99. } TLBSet;
  100. typedef struct CPUCRISState {
  101. uint32_t regs[16];
  102. /* P0 - P15 are referred to as special registers in the docs. */
  103. uint32_t pregs[16];
  104. /* Pseudo register for the PC. Not directly accessible on CRIS. */
  105. uint32_t pc;
  106. /* Pseudo register for the kernel stack. */
  107. uint32_t ksp;
  108. /* Branch. */
  109. int dslot;
  110. int btaken;
  111. uint32_t btarget;
  112. /* Condition flag tracking. */
  113. uint32_t cc_op;
  114. uint32_t cc_mask;
  115. uint32_t cc_dest;
  116. uint32_t cc_src;
  117. uint32_t cc_result;
  118. /* size of the operation, 1 = byte, 2 = word, 4 = dword. */
  119. int cc_size;
  120. /* X flag at the time of cc snapshot. */
  121. int cc_x;
  122. /* CRIS has certain insns that lockout interrupts. */
  123. int locked_irq;
  124. int interrupt_vector;
  125. int fault_vector;
  126. int trap_vector;
  127. /* FIXME: add a check in the translator to avoid writing to support
  128. register sets beyond the 4th. The ISA allows up to 256! but in
  129. practice there is no core that implements more than 4.
  130. Support function registers are used to control units close to the
  131. core. Accesses do not pass down the normal hierarchy.
  132. */
  133. uint32_t sregs[4][16];
  134. /* Linear feedback shift reg in the mmu. Used to provide pseudo
  135. randomness for the 'hint' the mmu gives to sw for choosing valid
  136. sets on TLB refills. */
  137. uint32_t mmu_rand_lfsr;
  138. /*
  139. * We just store the stores to the tlbset here for later evaluation
  140. * when the hw needs access to them.
  141. *
  142. * One for I and another for D.
  143. */
  144. TLBSet tlbsets[2][4][16];
  145. CPU_COMMON
  146. /* Members from load_info on are preserved across resets. */
  147. void *load_info;
  148. } CPUCRISState;
  149. #include "cpu-qom.h"
  150. CRISCPU *cpu_cris_init(const char *cpu_model);
  151. int cpu_cris_exec(CPUState *cpu);
  152. /* you can call this signal handler from your SIGBUS and SIGSEGV
  153. signal handlers to inform the virtual CPU of exceptions. non zero
  154. is returned if the signal was handled by the virtual CPU. */
  155. int cpu_cris_signal_handler(int host_signum, void *pinfo,
  156. void *puc);
  157. void cris_initialize_tcg(void);
  158. void cris_initialize_crisv10_tcg(void);
  159. enum {
  160. CC_OP_DYNAMIC, /* Use env->cc_op */
  161. CC_OP_FLAGS,
  162. CC_OP_CMP,
  163. CC_OP_MOVE,
  164. CC_OP_ADD,
  165. CC_OP_ADDC,
  166. CC_OP_MCP,
  167. CC_OP_ADDU,
  168. CC_OP_SUB,
  169. CC_OP_SUBU,
  170. CC_OP_NEG,
  171. CC_OP_BTST,
  172. CC_OP_MULS,
  173. CC_OP_MULU,
  174. CC_OP_DSTEP,
  175. CC_OP_MSTEP,
  176. CC_OP_BOUND,
  177. CC_OP_OR,
  178. CC_OP_AND,
  179. CC_OP_XOR,
  180. CC_OP_LSL,
  181. CC_OP_LSR,
  182. CC_OP_ASR,
  183. CC_OP_LZ
  184. };
  185. /* CRIS uses 8k pages. */
  186. #define TARGET_PAGE_BITS 13
  187. #define MMAP_SHIFT TARGET_PAGE_BITS
  188. #define TARGET_PHYS_ADDR_SPACE_BITS 32
  189. #define TARGET_VIRT_ADDR_SPACE_BITS 32
  190. #define cpu_init(cpu_model) CPU(cpu_cris_init(cpu_model))
  191. #define cpu_exec cpu_cris_exec
  192. #define cpu_signal_handler cpu_cris_signal_handler
  193. /* MMU modes definitions */
  194. #define MMU_MODE0_SUFFIX _kernel
  195. #define MMU_MODE1_SUFFIX _user
  196. #define MMU_USER_IDX 1
  197. static inline int cpu_mmu_index (CPUCRISState *env, bool ifetch)
  198. {
  199. return !!(env->pregs[PR_CCS] & U_FLAG);
  200. }
  201. int cris_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
  202. int mmu_idx);
  203. /* Support function regs. */
  204. #define SFR_RW_GC_CFG 0][0
  205. #define SFR_RW_MM_CFG env->pregs[PR_SRS]][0
  206. #define SFR_RW_MM_KBASE_LO env->pregs[PR_SRS]][1
  207. #define SFR_RW_MM_KBASE_HI env->pregs[PR_SRS]][2
  208. #define SFR_R_MM_CAUSE env->pregs[PR_SRS]][3
  209. #define SFR_RW_MM_TLB_SEL env->pregs[PR_SRS]][4
  210. #define SFR_RW_MM_TLB_LO env->pregs[PR_SRS]][5
  211. #define SFR_RW_MM_TLB_HI env->pregs[PR_SRS]][6
  212. #include "exec/cpu-all.h"
  213. static inline void cpu_get_tb_cpu_state(CPUCRISState *env, target_ulong *pc,
  214. target_ulong *cs_base, int *flags)
  215. {
  216. *pc = env->pc;
  217. *cs_base = 0;
  218. *flags = env->dslot |
  219. (env->pregs[PR_CCS] & (S_FLAG | P_FLAG | U_FLAG
  220. | X_FLAG | PFIX_FLAG));
  221. }
  222. #define cpu_list cris_cpu_list
  223. void cris_cpu_list(FILE *f, fprintf_function cpu_fprintf);
  224. #include "exec/exec-all.h"
  225. #endif