]> git.proxmox.com Git - mirror_qemu.git/blob - target-lm32/op_helper.c
Merge remote-tracking branch 'remotes/mwalle/tags/lm32-fixes/20140204' into staging
[mirror_qemu.git] / target-lm32 / op_helper.c
1 #include <assert.h>
2 #include "cpu.h"
3 #include "helper.h"
4 #include "qemu/host-utils.h"
5
6 #include "hw/lm32/lm32_pic.h"
7 #include "hw/char/lm32_juart.h"
8
9 #include "exec/softmmu_exec.h"
10
11 #ifndef CONFIG_USER_ONLY
12 #include "sysemu/sysemu.h"
13 #endif
14
15 #if !defined(CONFIG_USER_ONLY)
16 #define MMUSUFFIX _mmu
17 #define SHIFT 0
18 #include "exec/softmmu_template.h"
19 #define SHIFT 1
20 #include "exec/softmmu_template.h"
21 #define SHIFT 2
22 #include "exec/softmmu_template.h"
23 #define SHIFT 3
24 #include "exec/softmmu_template.h"
25
26 void raise_exception(CPULM32State *env, int index)
27 {
28 env->exception_index = index;
29 cpu_loop_exit(env);
30 }
31
32 void HELPER(raise_exception)(CPULM32State *env, uint32_t index)
33 {
34 raise_exception(env, index);
35 }
36
37 void HELPER(hlt)(CPULM32State *env)
38 {
39 CPUState *cs = CPU(lm32_env_get_cpu(env));
40
41 cs->halted = 1;
42 env->exception_index = EXCP_HLT;
43 cpu_loop_exit(env);
44 }
45
46 void HELPER(ill)(CPULM32State *env)
47 {
48 #ifndef CONFIG_USER_ONLY
49 CPUState *cs = CPU(lm32_env_get_cpu(env));
50 fprintf(stderr, "VM paused due to illegal instruction. "
51 "Connect a debugger or switch to the monitor console "
52 "to find out more.\n");
53 qemu_system_vmstop_request(RUN_STATE_PAUSED);
54 cs->halted = 1;
55 raise_exception(env, EXCP_HALTED);
56 #endif
57 }
58
59 void HELPER(wcsr_bp)(CPULM32State *env, uint32_t bp, uint32_t idx)
60 {
61 uint32_t addr = bp & ~1;
62
63 assert(idx < 4);
64
65 env->bp[idx] = bp;
66 lm32_breakpoint_remove(env, idx);
67 if (bp & 1) {
68 lm32_breakpoint_insert(env, idx, addr);
69 }
70 }
71
72 void HELPER(wcsr_wp)(CPULM32State *env, uint32_t wp, uint32_t idx)
73 {
74 lm32_wp_t wp_type;
75
76 assert(idx < 4);
77
78 env->wp[idx] = wp;
79
80 wp_type = lm32_wp_type(env->dc, idx);
81 lm32_watchpoint_remove(env, idx);
82 if (wp_type != LM32_WP_DISABLED) {
83 lm32_watchpoint_insert(env, idx, wp, wp_type);
84 }
85 }
86
87 void HELPER(wcsr_dc)(CPULM32State *env, uint32_t dc)
88 {
89 uint32_t old_dc;
90 int i;
91 lm32_wp_t old_type;
92 lm32_wp_t new_type;
93
94 old_dc = env->dc;
95 env->dc = dc;
96
97 for (i = 0; i < 4; i++) {
98 old_type = lm32_wp_type(old_dc, i);
99 new_type = lm32_wp_type(dc, i);
100
101 if (old_type != new_type) {
102 lm32_watchpoint_remove(env, i);
103 if (new_type != LM32_WP_DISABLED) {
104 lm32_watchpoint_insert(env, i, env->wp[i], new_type);
105 }
106 }
107 }
108 }
109
110 void HELPER(wcsr_im)(CPULM32State *env, uint32_t im)
111 {
112 lm32_pic_set_im(env->pic_state, im);
113 }
114
115 void HELPER(wcsr_ip)(CPULM32State *env, uint32_t im)
116 {
117 lm32_pic_set_ip(env->pic_state, im);
118 }
119
120 void HELPER(wcsr_jtx)(CPULM32State *env, uint32_t jtx)
121 {
122 lm32_juart_set_jtx(env->juart_state, jtx);
123 }
124
125 void HELPER(wcsr_jrx)(CPULM32State *env, uint32_t jrx)
126 {
127 lm32_juart_set_jrx(env->juart_state, jrx);
128 }
129
130 uint32_t HELPER(rcsr_im)(CPULM32State *env)
131 {
132 return lm32_pic_get_im(env->pic_state);
133 }
134
135 uint32_t HELPER(rcsr_ip)(CPULM32State *env)
136 {
137 return lm32_pic_get_ip(env->pic_state);
138 }
139
140 uint32_t HELPER(rcsr_jtx)(CPULM32State *env)
141 {
142 return lm32_juart_get_jtx(env->juart_state);
143 }
144
145 uint32_t HELPER(rcsr_jrx)(CPULM32State *env)
146 {
147 return lm32_juart_get_jrx(env->juart_state);
148 }
149
150 /* Try to fill the TLB and return an exception if error. If retaddr is
151 NULL, it means that the function was called in C code (i.e. not
152 from generated code or from helper.c) */
153 void tlb_fill(CPULM32State *env, target_ulong addr, int is_write, int mmu_idx,
154 uintptr_t retaddr)
155 {
156 int ret;
157
158 ret = cpu_lm32_handle_mmu_fault(env, addr, is_write, mmu_idx);
159 if (unlikely(ret)) {
160 if (retaddr) {
161 /* now we have a real cpu fault */
162 cpu_restore_state(env, retaddr);
163 }
164 cpu_loop_exit(env);
165 }
166 }
167 #endif
168