root / target-microblaze / op_helper.c @ 658788c5
History | View | Annotate | Download (6.8 kB)
1 | 4acb54ba | Edgar E. Iglesias | /*
|
---|---|---|---|
2 | 4acb54ba | Edgar E. Iglesias | * Microblaze helper routines.
|
3 | 4acb54ba | Edgar E. Iglesias | *
|
4 | 4acb54ba | Edgar E. Iglesias | * Copyright (c) 2009 Edgar E. Iglesias <edgar.iglesias@gmail.com>.
|
5 | 4acb54ba | Edgar E. Iglesias | *
|
6 | 4acb54ba | Edgar E. Iglesias | * This library is free software; you can redistribute it and/or
|
7 | 4acb54ba | Edgar E. Iglesias | * modify it under the terms of the GNU Lesser General Public
|
8 | 4acb54ba | Edgar E. Iglesias | * License as published by the Free Software Foundation; either
|
9 | 4acb54ba | Edgar E. Iglesias | * version 2 of the License, or (at your option) any later version.
|
10 | 4acb54ba | Edgar E. Iglesias | *
|
11 | 4acb54ba | Edgar E. Iglesias | * This library is distributed in the hope that it will be useful,
|
12 | 4acb54ba | Edgar E. Iglesias | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 4acb54ba | Edgar E. Iglesias | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 4acb54ba | Edgar E. Iglesias | * Lesser General Public License for more details.
|
15 | 4acb54ba | Edgar E. Iglesias | *
|
16 | 4acb54ba | Edgar E. Iglesias | * You should have received a copy of the GNU Lesser General Public
|
17 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 4acb54ba | Edgar E. Iglesias | */
|
19 | 4acb54ba | Edgar E. Iglesias | |
20 | 4acb54ba | Edgar E. Iglesias | #include <assert.h> |
21 | 4acb54ba | Edgar E. Iglesias | #include "exec.h" |
22 | 4acb54ba | Edgar E. Iglesias | #include "helper.h" |
23 | 4acb54ba | Edgar E. Iglesias | #include "host-utils.h" |
24 | 4acb54ba | Edgar E. Iglesias | |
25 | 4acb54ba | Edgar E. Iglesias | #define D(x)
|
26 | 4acb54ba | Edgar E. Iglesias | |
27 | 4acb54ba | Edgar E. Iglesias | #if !defined(CONFIG_USER_ONLY)
|
28 | 4acb54ba | Edgar E. Iglesias | #define MMUSUFFIX _mmu
|
29 | 4acb54ba | Edgar E. Iglesias | #define SHIFT 0 |
30 | 4acb54ba | Edgar E. Iglesias | #include "softmmu_template.h" |
31 | 4acb54ba | Edgar E. Iglesias | #define SHIFT 1 |
32 | 4acb54ba | Edgar E. Iglesias | #include "softmmu_template.h" |
33 | 4acb54ba | Edgar E. Iglesias | #define SHIFT 2 |
34 | 4acb54ba | Edgar E. Iglesias | #include "softmmu_template.h" |
35 | 4acb54ba | Edgar E. Iglesias | #define SHIFT 3 |
36 | 4acb54ba | Edgar E. Iglesias | #include "softmmu_template.h" |
37 | 4acb54ba | Edgar E. Iglesias | |
38 | 4acb54ba | Edgar E. Iglesias | /* Try to fill the TLB and return an exception if error. If retaddr is
|
39 | 4acb54ba | Edgar E. Iglesias | NULL, it means that the function was called in C code (i.e. not
|
40 | 4acb54ba | Edgar E. Iglesias | from generated code or from helper.c) */
|
41 | 4acb54ba | Edgar E. Iglesias | /* XXX: fix it to restore all registers */
|
42 | 4acb54ba | Edgar E. Iglesias | void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr) |
43 | 4acb54ba | Edgar E. Iglesias | { |
44 | 4acb54ba | Edgar E. Iglesias | TranslationBlock *tb; |
45 | 4acb54ba | Edgar E. Iglesias | CPUState *saved_env; |
46 | 4acb54ba | Edgar E. Iglesias | unsigned long pc; |
47 | 4acb54ba | Edgar E. Iglesias | int ret;
|
48 | 4acb54ba | Edgar E. Iglesias | |
49 | 4acb54ba | Edgar E. Iglesias | /* XXX: hack to restore env in all cases, even if not called from
|
50 | 4acb54ba | Edgar E. Iglesias | generated code */
|
51 | 4acb54ba | Edgar E. Iglesias | saved_env = env; |
52 | 4acb54ba | Edgar E. Iglesias | env = cpu_single_env; |
53 | 4acb54ba | Edgar E. Iglesias | |
54 | 4acb54ba | Edgar E. Iglesias | ret = cpu_mb_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
|
55 | 4acb54ba | Edgar E. Iglesias | if (unlikely(ret)) {
|
56 | 4acb54ba | Edgar E. Iglesias | if (retaddr) {
|
57 | 4acb54ba | Edgar E. Iglesias | /* now we have a real cpu fault */
|
58 | 4acb54ba | Edgar E. Iglesias | pc = (unsigned long)retaddr; |
59 | 4acb54ba | Edgar E. Iglesias | tb = tb_find_pc(pc); |
60 | 4acb54ba | Edgar E. Iglesias | if (tb) {
|
61 | 4acb54ba | Edgar E. Iglesias | /* the PC is inside the translated code. It means that we have
|
62 | 4acb54ba | Edgar E. Iglesias | a virtual CPU fault */
|
63 | 4acb54ba | Edgar E. Iglesias | cpu_restore_state(tb, env, pc, NULL);
|
64 | 4acb54ba | Edgar E. Iglesias | } |
65 | 4acb54ba | Edgar E. Iglesias | } |
66 | 4acb54ba | Edgar E. Iglesias | cpu_loop_exit(); |
67 | 4acb54ba | Edgar E. Iglesias | } |
68 | 4acb54ba | Edgar E. Iglesias | env = saved_env; |
69 | 4acb54ba | Edgar E. Iglesias | } |
70 | 4acb54ba | Edgar E. Iglesias | #endif
|
71 | 4acb54ba | Edgar E. Iglesias | |
72 | 4acb54ba | Edgar E. Iglesias | void helper_raise_exception(uint32_t index)
|
73 | 4acb54ba | Edgar E. Iglesias | { |
74 | 4acb54ba | Edgar E. Iglesias | env->exception_index = index; |
75 | 4acb54ba | Edgar E. Iglesias | cpu_loop_exit(); |
76 | 4acb54ba | Edgar E. Iglesias | } |
77 | 4acb54ba | Edgar E. Iglesias | |
78 | 4acb54ba | Edgar E. Iglesias | void helper_debug(void) |
79 | 4acb54ba | Edgar E. Iglesias | { |
80 | 4acb54ba | Edgar E. Iglesias | int i;
|
81 | 4acb54ba | Edgar E. Iglesias | |
82 | 4acb54ba | Edgar E. Iglesias | qemu_log("PC=%8.8x\n", env->sregs[SR_PC]);
|
83 | 4acb54ba | Edgar E. Iglesias | for (i = 0; i < 32; i++) { |
84 | 4acb54ba | Edgar E. Iglesias | qemu_log("r%2.2d=%8.8x ", i, env->regs[i]);
|
85 | 4acb54ba | Edgar E. Iglesias | if ((i + 1) % 4 == 0) |
86 | 4acb54ba | Edgar E. Iglesias | qemu_log("\n");
|
87 | 4acb54ba | Edgar E. Iglesias | } |
88 | 4acb54ba | Edgar E. Iglesias | qemu_log("\n\n");
|
89 | 4acb54ba | Edgar E. Iglesias | } |
90 | 4acb54ba | Edgar E. Iglesias | |
91 | 4acb54ba | Edgar E. Iglesias | static inline uint32_t compute_carry(uint32_t a, uint32_t b, uint32_t cin) |
92 | 4acb54ba | Edgar E. Iglesias | { |
93 | 4acb54ba | Edgar E. Iglesias | uint32_t cout = 0;
|
94 | 4acb54ba | Edgar E. Iglesias | |
95 | 4acb54ba | Edgar E. Iglesias | if ((b == ~0) && cin) |
96 | 4acb54ba | Edgar E. Iglesias | cout = 1;
|
97 | 4acb54ba | Edgar E. Iglesias | else if ((~0 - a) < (b + cin)) |
98 | 4acb54ba | Edgar E. Iglesias | cout = 1;
|
99 | 4acb54ba | Edgar E. Iglesias | return cout;
|
100 | 4acb54ba | Edgar E. Iglesias | } |
101 | 4acb54ba | Edgar E. Iglesias | |
102 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_cmp(uint32_t a, uint32_t b) |
103 | 4acb54ba | Edgar E. Iglesias | { |
104 | 4acb54ba | Edgar E. Iglesias | uint32_t t; |
105 | 4acb54ba | Edgar E. Iglesias | |
106 | 4acb54ba | Edgar E. Iglesias | t = b + ~a + 1;
|
107 | 4acb54ba | Edgar E. Iglesias | if ((b & 0x80000000) ^ (a & 0x80000000)) |
108 | 4acb54ba | Edgar E. Iglesias | t = (t & 0x7fffffff) | (b & 0x80000000); |
109 | 4acb54ba | Edgar E. Iglesias | return t;
|
110 | 4acb54ba | Edgar E. Iglesias | } |
111 | 4acb54ba | Edgar E. Iglesias | |
112 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_cmpu(uint32_t a, uint32_t b) |
113 | 4acb54ba | Edgar E. Iglesias | { |
114 | 4acb54ba | Edgar E. Iglesias | uint32_t t; |
115 | 4acb54ba | Edgar E. Iglesias | |
116 | 4acb54ba | Edgar E. Iglesias | t = b + ~a + 1;
|
117 | 4acb54ba | Edgar E. Iglesias | if ((b & 0x80000000) ^ (a & 0x80000000)) |
118 | 4acb54ba | Edgar E. Iglesias | t = (t & 0x7fffffff) | (a & 0x80000000); |
119 | 4acb54ba | Edgar E. Iglesias | return t;
|
120 | 4acb54ba | Edgar E. Iglesias | } |
121 | 4acb54ba | Edgar E. Iglesias | |
122 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_addkc(uint32_t a, uint32_t b, uint32_t k, uint32_t c) |
123 | 4acb54ba | Edgar E. Iglesias | { |
124 | 4acb54ba | Edgar E. Iglesias | uint32_t d, cf = 0, ncf;
|
125 | 4acb54ba | Edgar E. Iglesias | |
126 | 4acb54ba | Edgar E. Iglesias | if (c)
|
127 | 4acb54ba | Edgar E. Iglesias | cf = env->sregs[SR_MSR] >> 31;
|
128 | 4acb54ba | Edgar E. Iglesias | assert(cf == 0 || cf == 1); |
129 | 4acb54ba | Edgar E. Iglesias | d = a + b + cf; |
130 | 4acb54ba | Edgar E. Iglesias | |
131 | 4acb54ba | Edgar E. Iglesias | if (!k) {
|
132 | 4acb54ba | Edgar E. Iglesias | ncf = compute_carry(a, b, cf); |
133 | 4acb54ba | Edgar E. Iglesias | assert(ncf == 0 || ncf == 1); |
134 | 4acb54ba | Edgar E. Iglesias | if (ncf)
|
135 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] |= MSR_C | MSR_CC; |
136 | 4acb54ba | Edgar E. Iglesias | else
|
137 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] &= ~(MSR_C | MSR_CC); |
138 | 4acb54ba | Edgar E. Iglesias | } |
139 | 4acb54ba | Edgar E. Iglesias | D(qemu_log("%x = %x + %x cf=%d ncf=%d k=%d c=%d\n",
|
140 | 4acb54ba | Edgar E. Iglesias | d, a, b, cf, ncf, k, c)); |
141 | 4acb54ba | Edgar E. Iglesias | return d;
|
142 | 4acb54ba | Edgar E. Iglesias | } |
143 | 4acb54ba | Edgar E. Iglesias | |
144 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_subkc(uint32_t a, uint32_t b, uint32_t k, uint32_t c) |
145 | 4acb54ba | Edgar E. Iglesias | { |
146 | 4acb54ba | Edgar E. Iglesias | uint32_t d, cf = 1, ncf;
|
147 | 4acb54ba | Edgar E. Iglesias | |
148 | 4acb54ba | Edgar E. Iglesias | if (c)
|
149 | 4acb54ba | Edgar E. Iglesias | cf = env->sregs[SR_MSR] >> 31;
|
150 | 4acb54ba | Edgar E. Iglesias | assert(cf == 0 || cf == 1); |
151 | 4acb54ba | Edgar E. Iglesias | d = b + ~a + cf; |
152 | 4acb54ba | Edgar E. Iglesias | |
153 | 4acb54ba | Edgar E. Iglesias | if (!k) {
|
154 | 4acb54ba | Edgar E. Iglesias | ncf = compute_carry(b, ~a, cf); |
155 | 4acb54ba | Edgar E. Iglesias | assert(ncf == 0 || ncf == 1); |
156 | 4acb54ba | Edgar E. Iglesias | if (ncf)
|
157 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] |= MSR_C | MSR_CC; |
158 | 4acb54ba | Edgar E. Iglesias | else
|
159 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] &= ~(MSR_C | MSR_CC); |
160 | 4acb54ba | Edgar E. Iglesias | } |
161 | 4acb54ba | Edgar E. Iglesias | D(qemu_log("%x = %x + %x cf=%d ncf=%d k=%d c=%d\n",
|
162 | 4acb54ba | Edgar E. Iglesias | d, a, b, cf, ncf, k, c)); |
163 | 4acb54ba | Edgar E. Iglesias | return d;
|
164 | 4acb54ba | Edgar E. Iglesias | } |
165 | 4acb54ba | Edgar E. Iglesias | |
166 | 4acb54ba | Edgar E. Iglesias | static inline int div_prepare(uint32_t a, uint32_t b) |
167 | 4acb54ba | Edgar E. Iglesias | { |
168 | 4acb54ba | Edgar E. Iglesias | if (b == 0) { |
169 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] |= MSR_DZ; |
170 | 821ebb33 | Edgar E. Iglesias | |
171 | 821ebb33 | Edgar E. Iglesias | if ((env->sregs[SR_MSR] & MSR_EE)
|
172 | 821ebb33 | Edgar E. Iglesias | && !(env->pvr.regs[2] & PVR2_DIV_ZERO_EXC_MASK)) {
|
173 | 821ebb33 | Edgar E. Iglesias | env->sregs[SR_ESR] = ESR_EC_DIVZERO; |
174 | 821ebb33 | Edgar E. Iglesias | helper_raise_exception(EXCP_HW_EXCP); |
175 | 821ebb33 | Edgar E. Iglesias | } |
176 | 4acb54ba | Edgar E. Iglesias | return 0; |
177 | 4acb54ba | Edgar E. Iglesias | } |
178 | 4acb54ba | Edgar E. Iglesias | env->sregs[SR_MSR] &= ~MSR_DZ; |
179 | 4acb54ba | Edgar E. Iglesias | return 1; |
180 | 4acb54ba | Edgar E. Iglesias | } |
181 | 4acb54ba | Edgar E. Iglesias | |
182 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_divs(uint32_t a, uint32_t b) |
183 | 4acb54ba | Edgar E. Iglesias | { |
184 | 4acb54ba | Edgar E. Iglesias | if (!div_prepare(a, b))
|
185 | 4acb54ba | Edgar E. Iglesias | return 0; |
186 | 4acb54ba | Edgar E. Iglesias | return (int32_t)a / (int32_t)b;
|
187 | 4acb54ba | Edgar E. Iglesias | } |
188 | 4acb54ba | Edgar E. Iglesias | |
189 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_divu(uint32_t a, uint32_t b) |
190 | 4acb54ba | Edgar E. Iglesias | { |
191 | 4acb54ba | Edgar E. Iglesias | if (!div_prepare(a, b))
|
192 | 4acb54ba | Edgar E. Iglesias | return 0; |
193 | 4acb54ba | Edgar E. Iglesias | return a / b;
|
194 | 4acb54ba | Edgar E. Iglesias | } |
195 | 4acb54ba | Edgar E. Iglesias | |
196 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_pcmpbf(uint32_t a, uint32_t b) |
197 | 4acb54ba | Edgar E. Iglesias | { |
198 | 4acb54ba | Edgar E. Iglesias | unsigned int i; |
199 | 4acb54ba | Edgar E. Iglesias | uint32_t mask = 0xff000000;
|
200 | 4acb54ba | Edgar E. Iglesias | |
201 | 4acb54ba | Edgar E. Iglesias | for (i = 0; i < 4; i++) { |
202 | 4acb54ba | Edgar E. Iglesias | if ((a & mask) == (b & mask))
|
203 | 4acb54ba | Edgar E. Iglesias | return i + 1; |
204 | 4acb54ba | Edgar E. Iglesias | mask >>= 8;
|
205 | 4acb54ba | Edgar E. Iglesias | } |
206 | 4acb54ba | Edgar E. Iglesias | return 0; |
207 | 4acb54ba | Edgar E. Iglesias | } |
208 | 4acb54ba | Edgar E. Iglesias | |
209 | 3aa80988 | Edgar E. Iglesias | void helper_memalign(uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)
|
210 | 968a40f6 | Edgar E. Iglesias | { |
211 | 968a40f6 | Edgar E. Iglesias | if (addr & mask) {
|
212 | 97f90cbf | Edgar E. Iglesias | qemu_log_mask(CPU_LOG_INT, |
213 | 97f90cbf | Edgar E. Iglesias | "unaligned access addr=%x mask=%x, wr=%d dr=r%d\n",
|
214 | 97f90cbf | Edgar E. Iglesias | addr, mask, wr, dr); |
215 | 97f90cbf | Edgar E. Iglesias | env->sregs[SR_EAR] = addr; |
216 | 968a40f6 | Edgar E. Iglesias | env->sregs[SR_ESR] = ESR_EC_UNALIGNED_DATA | (wr << 10) \
|
217 | 968a40f6 | Edgar E. Iglesias | | (dr & 31) << 5; |
218 | 3aa80988 | Edgar E. Iglesias | if (mask == 3) { |
219 | 968a40f6 | Edgar E. Iglesias | env->sregs[SR_ESR] |= 1 << 11; |
220 | 968a40f6 | Edgar E. Iglesias | } |
221 | 97f90cbf | Edgar E. Iglesias | if (!(env->sregs[SR_MSR] & MSR_EE)) {
|
222 | 97f90cbf | Edgar E. Iglesias | return;
|
223 | 97f90cbf | Edgar E. Iglesias | } |
224 | 968a40f6 | Edgar E. Iglesias | helper_raise_exception(EXCP_HW_EXCP); |
225 | 968a40f6 | Edgar E. Iglesias | } |
226 | 968a40f6 | Edgar E. Iglesias | } |
227 | 968a40f6 | Edgar E. Iglesias | |
228 | 4acb54ba | Edgar E. Iglesias | #if !defined(CONFIG_USER_ONLY)
|
229 | 4acb54ba | Edgar E. Iglesias | /* Writes/reads to the MMU's special regs end up here. */
|
230 | 4acb54ba | Edgar E. Iglesias | uint32_t helper_mmu_read(uint32_t rn) |
231 | 4acb54ba | Edgar E. Iglesias | { |
232 | 4acb54ba | Edgar E. Iglesias | return mmu_read(env, rn);
|
233 | 4acb54ba | Edgar E. Iglesias | } |
234 | 4acb54ba | Edgar E. Iglesias | |
235 | 4acb54ba | Edgar E. Iglesias | void helper_mmu_write(uint32_t rn, uint32_t v)
|
236 | 4acb54ba | Edgar E. Iglesias | { |
237 | 4acb54ba | Edgar E. Iglesias | mmu_write(env, rn, v); |
238 | 4acb54ba | Edgar E. Iglesias | } |
239 | 4acb54ba | Edgar E. Iglesias | #endif
|
240 | faed1c2a | Edgar E. Iglesias | |
241 | c227f099 | Anthony Liguori | void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec, |
242 | faed1c2a | Edgar E. Iglesias | int is_asi, int size) |
243 | faed1c2a | Edgar E. Iglesias | { |
244 | faed1c2a | Edgar E. Iglesias | CPUState *saved_env; |
245 | faed1c2a | Edgar E. Iglesias | /* XXX: hack to restore env in all cases, even if not called from
|
246 | faed1c2a | Edgar E. Iglesias | generated code */
|
247 | faed1c2a | Edgar E. Iglesias | saved_env = env; |
248 | faed1c2a | Edgar E. Iglesias | env = cpu_single_env; |
249 | 97f90cbf | Edgar E. Iglesias | qemu_log_mask(CPU_LOG_INT, "Unassigned " TARGET_FMT_plx " wr=%d exe=%d\n", |
250 | faed1c2a | Edgar E. Iglesias | addr, is_write, is_exec); |
251 | faed1c2a | Edgar E. Iglesias | if (!(env->sregs[SR_MSR] & MSR_EE)) {
|
252 | 95b279de | Edgar E. Iglesias | env = saved_env; |
253 | faed1c2a | Edgar E. Iglesias | return;
|
254 | faed1c2a | Edgar E. Iglesias | } |
255 | faed1c2a | Edgar E. Iglesias | |
256 | 97f90cbf | Edgar E. Iglesias | env->sregs[SR_EAR] = addr; |
257 | faed1c2a | Edgar E. Iglesias | if (is_exec) {
|
258 | 97f90cbf | Edgar E. Iglesias | if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) { |
259 | faed1c2a | Edgar E. Iglesias | env->sregs[SR_ESR] = ESR_EC_INSN_BUS; |
260 | faed1c2a | Edgar E. Iglesias | helper_raise_exception(EXCP_HW_EXCP); |
261 | faed1c2a | Edgar E. Iglesias | } |
262 | faed1c2a | Edgar E. Iglesias | } else {
|
263 | 97f90cbf | Edgar E. Iglesias | if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) { |
264 | faed1c2a | Edgar E. Iglesias | env->sregs[SR_ESR] = ESR_EC_DATA_BUS; |
265 | faed1c2a | Edgar E. Iglesias | helper_raise_exception(EXCP_HW_EXCP); |
266 | faed1c2a | Edgar E. Iglesias | } |
267 | faed1c2a | Edgar E. Iglesias | } |
268 | 95b279de | Edgar E. Iglesias | env = saved_env; |
269 | faed1c2a | Edgar E. Iglesias | } |