cpu.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * LatticeMico32 virtual CPU header.
  3. *
  4. * Copyright (c) 2010 Michael Walle <michael@walle.cc>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef CPU_LM32_H
  20. #define CPU_LM32_H
  21. #define TARGET_LONG_BITS 32
  22. #define CPUState struct CPULM32State
  23. #include "qemu-common.h"
  24. #include "cpu-defs.h"
  25. struct CPULM32State;
  26. #define TARGET_HAS_ICE 1
  27. #define ELF_MACHINE EM_LATTICEMICO32
  28. #define NB_MMU_MODES 1
  29. #define TARGET_PAGE_BITS 12
  30. static inline int cpu_mmu_index(CPUState *env)
  31. {
  32. return 0;
  33. }
  34. #define TARGET_PHYS_ADDR_SPACE_BITS 32
  35. #define TARGET_VIRT_ADDR_SPACE_BITS 32
  36. /* Exceptions indices */
  37. enum {
  38. EXCP_RESET = 0,
  39. EXCP_BREAKPOINT,
  40. EXCP_INSN_BUS_ERROR,
  41. EXCP_WATCHPOINT,
  42. EXCP_DATA_BUS_ERROR,
  43. EXCP_DIVIDE_BY_ZERO,
  44. EXCP_IRQ,
  45. EXCP_SYSTEMCALL
  46. };
  47. /* Registers */
  48. enum {
  49. R_R0 = 0, R_R1, R_R2, R_R3, R_R4, R_R5, R_R6, R_R7, R_R8, R_R9, R_R10,
  50. R_R11, R_R12, R_R13, R_R14, R_R15, R_R16, R_R17, R_R18, R_R19, R_R20,
  51. R_R21, R_R22, R_R23, R_R24, R_R25, R_R26, R_R27, R_R28, R_R29, R_R30,
  52. R_R31
  53. };
  54. /* Register aliases */
  55. enum {
  56. R_GP = R_R26,
  57. R_FP = R_R27,
  58. R_SP = R_R28,
  59. R_RA = R_R29,
  60. R_EA = R_R30,
  61. R_BA = R_R31
  62. };
  63. /* IE flags */
  64. enum {
  65. IE_IE = (1<<0),
  66. IE_EIE = (1<<1),
  67. IE_BIE = (1<<2),
  68. };
  69. /* DC flags */
  70. enum {
  71. DC_SS = (1<<0),
  72. DC_RE = (1<<1),
  73. DC_C0 = (1<<2),
  74. DC_C1 = (1<<3),
  75. DC_C2 = (1<<4),
  76. DC_C3 = (1<<5),
  77. };
  78. /* CFG mask */
  79. enum {
  80. CFG_M = (1<<0),
  81. CFG_D = (1<<1),
  82. CFG_S = (1<<2),
  83. CFG_U = (1<<3),
  84. CFG_X = (1<<4),
  85. CFG_CC = (1<<5),
  86. CFG_IC = (1<<6),
  87. CFG_DC = (1<<7),
  88. CFG_G = (1<<8),
  89. CFG_H = (1<<9),
  90. CFG_R = (1<<10),
  91. CFG_J = (1<<11),
  92. CFG_INT_SHIFT = 12,
  93. CFG_BP_SHIFT = 18,
  94. CFG_WP_SHIFT = 22,
  95. CFG_REV_SHIFT = 26,
  96. };
  97. /* CSRs */
  98. enum {
  99. CSR_IE = 0x00,
  100. CSR_IM = 0x01,
  101. CSR_IP = 0x02,
  102. CSR_ICC = 0x03,
  103. CSR_DCC = 0x04,
  104. CSR_CC = 0x05,
  105. CSR_CFG = 0x06,
  106. CSR_EBA = 0x07,
  107. CSR_DC = 0x08,
  108. CSR_DEBA = 0x09,
  109. CSR_JTX = 0x0e,
  110. CSR_JRX = 0x0f,
  111. CSR_BP0 = 0x10,
  112. CSR_BP1 = 0x11,
  113. CSR_BP2 = 0x12,
  114. CSR_BP3 = 0x13,
  115. CSR_WP0 = 0x18,
  116. CSR_WP1 = 0x19,
  117. CSR_WP2 = 0x1a,
  118. CSR_WP3 = 0x1b,
  119. };
  120. enum {
  121. LM32_FEATURE_MULTIPLY = 1,
  122. LM32_FEATURE_DIVIDE = 2,
  123. LM32_FEATURE_SHIFT = 4,
  124. LM32_FEATURE_SIGN_EXTEND = 8,
  125. LM32_FEATURE_I_CACHE = 16,
  126. LM32_FEATURE_D_CACHE = 32,
  127. LM32_FEATURE_CYCLE_COUNT = 64,
  128. };
  129. enum {
  130. LM32_FLAG_IGNORE_MSB = 1,
  131. };
  132. typedef struct CPULM32State {
  133. /* general registers */
  134. uint32_t regs[32];
  135. /* special registers */
  136. uint32_t pc; /* program counter */
  137. uint32_t ie; /* interrupt enable */
  138. uint32_t icc; /* instruction cache control */
  139. uint32_t dcc; /* data cache control */
  140. uint32_t cc; /* cycle counter */
  141. uint32_t cfg; /* configuration */
  142. /* debug registers */
  143. uint32_t dc; /* debug control */
  144. uint32_t bp[4]; /* breakpoint addresses */
  145. uint32_t wp[4]; /* watchpoint addresses */
  146. CPU_COMMON
  147. uint32_t eba; /* exception base address */
  148. uint32_t deba; /* debug exception base address */
  149. /* interrupt controller handle for callbacks */
  150. DeviceState *pic_state;
  151. /* JTAG UART handle for callbacks */
  152. DeviceState *juart_state;
  153. /* processor core features */
  154. uint32_t features;
  155. uint32_t flags;
  156. uint8_t num_bps;
  157. uint8_t num_wps;
  158. } CPULM32State;
  159. CPUState *cpu_lm32_init(const char *cpu_model);
  160. void cpu_lm32_list(FILE *f, fprintf_function cpu_fprintf);
  161. int cpu_lm32_exec(CPUState *s);
  162. void cpu_lm32_close(CPUState *s);
  163. void do_interrupt(CPUState *env);
  164. /* you can call this signal handler from your SIGBUS and SIGSEGV
  165. signal handlers to inform the virtual CPU of exceptions. non zero
  166. is returned if the signal was handled by the virtual CPU. */
  167. int cpu_lm32_signal_handler(int host_signum, void *pinfo,
  168. void *puc);
  169. void lm32_translate_init(void);
  170. void cpu_lm32_set_phys_msb_ignore(CPUState *env, int value);
  171. #define cpu_list cpu_lm32_list
  172. #define cpu_init cpu_lm32_init
  173. #define cpu_exec cpu_lm32_exec
  174. #define cpu_gen_code cpu_lm32_gen_code
  175. #define cpu_signal_handler cpu_lm32_signal_handler
  176. #define CPU_SAVE_VERSION 1
  177. int cpu_lm32_handle_mmu_fault(CPUState *env, target_ulong address, int rw,
  178. int mmu_idx);
  179. #define cpu_handle_mmu_fault cpu_lm32_handle_mmu_fault
  180. #if defined(CONFIG_USER_ONLY)
  181. static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
  182. {
  183. if (newsp) {
  184. env->regs[R_SP] = newsp;
  185. }
  186. env->regs[R_R1] = 0;
  187. }
  188. #endif
  189. static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
  190. {
  191. }
  192. static inline int cpu_interrupts_enabled(CPUState *env)
  193. {
  194. return env->ie & IE_IE;
  195. }
  196. #include "cpu-all.h"
  197. static inline target_ulong cpu_get_pc(CPUState *env)
  198. {
  199. return env->pc;
  200. }
  201. static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
  202. target_ulong *cs_base, int *flags)
  203. {
  204. *pc = env->pc;
  205. *cs_base = 0;
  206. *flags = 0;
  207. }
  208. static inline bool cpu_has_work(CPUState *env)
  209. {
  210. return env->interrupt_request & CPU_INTERRUPT_HARD;
  211. }
  212. #include "exec-all.h"
  213. static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
  214. {
  215. env->pc = tb->pc;
  216. }
  217. #endif