op_helper.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <assert.h>
  2. #include "cpu.h"
  3. #include "dyngen-exec.h"
  4. #include "helper.h"
  5. #include "host-utils.h"
  6. #include "hw/lm32_pic.h"
  7. #include "hw/lm32_juart.h"
  8. #if !defined(CONFIG_USER_ONLY)
  9. #define MMUSUFFIX _mmu
  10. #define SHIFT 0
  11. #include "softmmu_template.h"
  12. #define SHIFT 1
  13. #include "softmmu_template.h"
  14. #define SHIFT 2
  15. #include "softmmu_template.h"
  16. #define SHIFT 3
  17. #include "softmmu_template.h"
  18. void helper_raise_exception(uint32_t index)
  19. {
  20. env->exception_index = index;
  21. cpu_loop_exit(env);
  22. }
  23. void helper_hlt(void)
  24. {
  25. env->halted = 1;
  26. env->exception_index = EXCP_HLT;
  27. cpu_loop_exit(env);
  28. }
  29. void helper_wcsr_im(uint32_t im)
  30. {
  31. lm32_pic_set_im(env->pic_state, im);
  32. }
  33. void helper_wcsr_ip(uint32_t im)
  34. {
  35. lm32_pic_set_ip(env->pic_state, im);
  36. }
  37. void helper_wcsr_jtx(uint32_t jtx)
  38. {
  39. lm32_juart_set_jtx(env->juart_state, jtx);
  40. }
  41. void helper_wcsr_jrx(uint32_t jrx)
  42. {
  43. lm32_juart_set_jrx(env->juart_state, jrx);
  44. }
  45. uint32_t helper_rcsr_im(void)
  46. {
  47. return lm32_pic_get_im(env->pic_state);
  48. }
  49. uint32_t helper_rcsr_ip(void)
  50. {
  51. return lm32_pic_get_ip(env->pic_state);
  52. }
  53. uint32_t helper_rcsr_jtx(void)
  54. {
  55. return lm32_juart_get_jtx(env->juart_state);
  56. }
  57. uint32_t helper_rcsr_jrx(void)
  58. {
  59. return lm32_juart_get_jrx(env->juart_state);
  60. }
  61. /* Try to fill the TLB and return an exception if error. If retaddr is
  62. NULL, it means that the function was called in C code (i.e. not
  63. from generated code or from helper.c) */
  64. /* XXX: fix it to restore all registers */
  65. void tlb_fill(CPUState *env1, target_ulong addr, int is_write, int mmu_idx,
  66. void *retaddr)
  67. {
  68. TranslationBlock *tb;
  69. CPUState *saved_env;
  70. unsigned long pc;
  71. int ret;
  72. saved_env = env;
  73. env = env1;
  74. ret = cpu_lm32_handle_mmu_fault(env, addr, is_write, mmu_idx);
  75. if (unlikely(ret)) {
  76. if (retaddr) {
  77. /* now we have a real cpu fault */
  78. pc = (unsigned long)retaddr;
  79. tb = tb_find_pc(pc);
  80. if (tb) {
  81. /* the PC is inside the translated code. It means that we have
  82. a virtual CPU fault */
  83. cpu_restore_state(tb, env, pc);
  84. }
  85. }
  86. cpu_loop_exit(env);
  87. }
  88. env = saved_env;
  89. }
  90. #endif