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