blob: 18677ddfca5b02c3ab650cdb28c2f994330c8eb6 [file] [log] [blame]
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +02001/*
2 * Microblaze helper routines.
3 *
4 * Copyright (c) 2009 Edgar E. Iglesias <edgar.iglesias@gmail.com>.
Peter A. G. Crosthwaitedadc1062012-04-12 14:30:30 +10005 * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +02006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000018 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020019 */
20
Peter Maydell8fd9dec2016-01-26 18:05:31 +000021#include "qemu/osdep.h"
Blue Swirl3e457172011-07-13 12:44:15 +000022#include "cpu.h"
Richard Henderson2ef61752014-04-07 22:31:41 -070023#include "exec/helper-proto.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/host-utils.h"
Paolo Bonzini63c91552016-03-15 13:18:37 +010025#include "exec/exec-all.h"
Paolo Bonzinif08b6172014-03-28 19:42:10 +010026#include "exec/cpu_ldst.h"
Alex Bennée24f91e82018-01-19 18:24:22 +000027#include "fpu/softfloat.h"
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020028
29#define D(x)
30
Edgar E. Iglesias6d76d232011-04-12 00:48:33 +020031void helper_put(uint32_t id, uint32_t ctrl, uint32_t data)
32{
33 int test = ctrl & STREAM_TEST;
34 int atomic = ctrl & STREAM_ATOMIC;
35 int control = ctrl & STREAM_CONTROL;
36 int nonblock = ctrl & STREAM_NONBLOCK;
37 int exception = ctrl & STREAM_EXCEPTION;
38
Paolo Bonzini1d512a62015-11-13 13:24:57 +010039 qemu_log_mask(LOG_UNIMP, "Unhandled stream put to stream-id=%d data=%x %s%s%s%s%s\n",
Edgar E. Iglesias6d76d232011-04-12 00:48:33 +020040 id, data,
41 test ? "t" : "",
42 nonblock ? "n" : "",
43 exception ? "e" : "",
44 control ? "c" : "",
45 atomic ? "a" : "");
46}
47
48uint32_t helper_get(uint32_t id, uint32_t ctrl)
49{
50 int test = ctrl & STREAM_TEST;
51 int atomic = ctrl & STREAM_ATOMIC;
52 int control = ctrl & STREAM_CONTROL;
53 int nonblock = ctrl & STREAM_NONBLOCK;
54 int exception = ctrl & STREAM_EXCEPTION;
55
Paolo Bonzini1d512a62015-11-13 13:24:57 +010056 qemu_log_mask(LOG_UNIMP, "Unhandled stream get from stream-id=%d %s%s%s%s%s\n",
Edgar E. Iglesias6d76d232011-04-12 00:48:33 +020057 id,
58 test ? "t" : "",
59 nonblock ? "n" : "",
60 exception ? "e" : "",
61 control ? "c" : "",
62 atomic ? "a" : "");
63 return 0xdead0000 | id;
64}
65
Blue Swirl64254eb2012-09-02 08:39:22 +000066void helper_raise_exception(CPUMBState *env, uint32_t index)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020067{
Richard Hendersonf5c7e932019-03-22 18:27:36 -070068 CPUState *cs = env_cpu(env);
Andreas Färber27103422013-08-26 08:31:06 +020069
70 cs->exception_index = index;
Andreas Färber5638d182013-08-27 17:52:12 +020071 cpu_loop_exit(cs);
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020072}
73
Blue Swirl64254eb2012-09-02 08:39:22 +000074void helper_debug(CPUMBState *env)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020075{
76 int i;
77
Edgar E. Iglesias0a22f8c2018-04-14 17:59:29 +020078 qemu_log("PC=%" PRIx64 "\n", env->sregs[SR_PC]);
79 qemu_log("rmsr=%" PRIx64 " resr=%" PRIx64 " rear=%" PRIx64 " "
80 "debug[%x] imm=%x iflags=%x\n",
Michal Simek4c24aa02009-12-07 14:12:49 +010081 env->sregs[SR_MSR], env->sregs[SR_ESR], env->sregs[SR_EAR],
Edgar E. Iglesias17c52a42009-12-16 12:52:56 +010082 env->debug, env->imm, env->iflags);
Edgar E. Iglesias43d318b2018-05-08 18:31:06 +020083 qemu_log("btaken=%d btarget=%" PRIx64 " mode=%s(saved=%s) eip=%d ie=%d\n",
Edgar E. Iglesias17c52a42009-12-16 12:52:56 +010084 env->btaken, env->btarget,
85 (env->sregs[SR_MSR] & MSR_UM) ? "user" : "kernel",
86 (env->sregs[SR_MSR] & MSR_UMS) ? "user" : "kernel",
Edgar E. Iglesias0a22f8c2018-04-14 17:59:29 +020087 (bool)(env->sregs[SR_MSR] & MSR_EIP),
88 (bool)(env->sregs[SR_MSR] & MSR_IE));
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +020089 for (i = 0; i < 32; i++) {
90 qemu_log("r%2.2d=%8.8x ", i, env->regs[i]);
91 if ((i + 1) % 4 == 0)
92 qemu_log("\n");
93 }
94 qemu_log("\n\n");
95}
96
97static inline uint32_t compute_carry(uint32_t a, uint32_t b, uint32_t cin)
98{
99 uint32_t cout = 0;
100
101 if ((b == ~0) && cin)
102 cout = 1;
103 else if ((~0 - a) < (b + cin))
104 cout = 1;
105 return cout;
106}
107
108uint32_t helper_cmp(uint32_t a, uint32_t b)
109{
110 uint32_t t;
111
112 t = b + ~a + 1;
113 if ((b & 0x80000000) ^ (a & 0x80000000))
114 t = (t & 0x7fffffff) | (b & 0x80000000);
115 return t;
116}
117
118uint32_t helper_cmpu(uint32_t a, uint32_t b)
119{
120 uint32_t t;
121
122 t = b + ~a + 1;
123 if ((b & 0x80000000) ^ (a & 0x80000000))
124 t = (t & 0x7fffffff) | (a & 0x80000000);
125 return t;
126}
127
Edgar E. Iglesias5d0bb822011-01-23 03:52:20 +0100128uint32_t helper_carry(uint32_t a, uint32_t b, uint32_t cf)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200129{
Shraddha Barke738c8b02015-09-25 14:07:56 +0530130 return compute_carry(a, b, cf);
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200131}
132
Blue Swirl64254eb2012-09-02 08:39:22 +0000133static inline int div_prepare(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200134{
135 if (b == 0) {
136 env->sregs[SR_MSR] |= MSR_DZ;
Edgar E. Iglesias821ebb32009-09-03 12:52:01 +0200137
138 if ((env->sregs[SR_MSR] & MSR_EE)
139 && !(env->pvr.regs[2] & PVR2_DIV_ZERO_EXC_MASK)) {
140 env->sregs[SR_ESR] = ESR_EC_DIVZERO;
Blue Swirl64254eb2012-09-02 08:39:22 +0000141 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesias821ebb32009-09-03 12:52:01 +0200142 }
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200143 return 0;
144 }
145 env->sregs[SR_MSR] &= ~MSR_DZ;
146 return 1;
147}
148
Blue Swirl64254eb2012-09-02 08:39:22 +0000149uint32_t helper_divs(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200150{
Blue Swirl64254eb2012-09-02 08:39:22 +0000151 if (!div_prepare(env, a, b)) {
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200152 return 0;
Blue Swirl64254eb2012-09-02 08:39:22 +0000153 }
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200154 return (int32_t)a / (int32_t)b;
155}
156
Blue Swirl64254eb2012-09-02 08:39:22 +0000157uint32_t helper_divu(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200158{
Blue Swirl64254eb2012-09-02 08:39:22 +0000159 if (!div_prepare(env, a, b)) {
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200160 return 0;
Blue Swirl64254eb2012-09-02 08:39:22 +0000161 }
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200162 return a / b;
163}
164
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200165/* raise FPU exception. */
Blue Swirl64254eb2012-09-02 08:39:22 +0000166static void raise_fpu_exception(CPUMBState *env)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200167{
168 env->sregs[SR_ESR] = ESR_EC_FPU;
Blue Swirl64254eb2012-09-02 08:39:22 +0000169 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200170}
171
Blue Swirl64254eb2012-09-02 08:39:22 +0000172static void update_fpu_flags(CPUMBState *env, int flags)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200173{
174 int raise = 0;
175
176 if (flags & float_flag_invalid) {
177 env->sregs[SR_FSR] |= FSR_IO;
178 raise = 1;
179 }
180 if (flags & float_flag_divbyzero) {
181 env->sregs[SR_FSR] |= FSR_DZ;
182 raise = 1;
183 }
184 if (flags & float_flag_overflow) {
185 env->sregs[SR_FSR] |= FSR_OF;
186 raise = 1;
187 }
188 if (flags & float_flag_underflow) {
189 env->sregs[SR_FSR] |= FSR_UF;
190 raise = 1;
191 }
192 if (raise
193 && (env->pvr.regs[2] & PVR2_FPU_EXC_MASK)
194 && (env->sregs[SR_MSR] & MSR_EE)) {
Blue Swirl64254eb2012-09-02 08:39:22 +0000195 raise_fpu_exception(env);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200196 }
197}
198
Blue Swirl64254eb2012-09-02 08:39:22 +0000199uint32_t helper_fadd(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200200{
201 CPU_FloatU fd, fa, fb;
202 int flags;
203
204 set_float_exception_flags(0, &env->fp_status);
205 fa.l = a;
206 fb.l = b;
207 fd.f = float32_add(fa.f, fb.f, &env->fp_status);
208
209 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000210 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200211 return fd.l;
212}
213
Blue Swirl64254eb2012-09-02 08:39:22 +0000214uint32_t helper_frsub(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200215{
216 CPU_FloatU fd, fa, fb;
217 int flags;
218
219 set_float_exception_flags(0, &env->fp_status);
220 fa.l = a;
221 fb.l = b;
222 fd.f = float32_sub(fb.f, fa.f, &env->fp_status);
223 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000224 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200225 return fd.l;
226}
227
Blue Swirl64254eb2012-09-02 08:39:22 +0000228uint32_t helper_fmul(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200229{
230 CPU_FloatU fd, fa, fb;
231 int flags;
232
233 set_float_exception_flags(0, &env->fp_status);
234 fa.l = a;
235 fb.l = b;
236 fd.f = float32_mul(fa.f, fb.f, &env->fp_status);
237 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000238 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200239
240 return fd.l;
241}
242
Blue Swirl64254eb2012-09-02 08:39:22 +0000243uint32_t helper_fdiv(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200244{
245 CPU_FloatU fd, fa, fb;
246 int flags;
247
248 set_float_exception_flags(0, &env->fp_status);
249 fa.l = a;
250 fb.l = b;
251 fd.f = float32_div(fb.f, fa.f, &env->fp_status);
252 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000253 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200254
255 return fd.l;
256}
257
Blue Swirl64254eb2012-09-02 08:39:22 +0000258uint32_t helper_fcmp_un(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200259{
Edgar E. Iglesiasef9d48d2010-09-09 22:05:48 +0200260 CPU_FloatU fa, fb;
261 uint32_t r = 0;
262
263 fa.l = a;
264 fb.l = b;
265
Aleksandar Markovicaf39bc82016-06-10 11:57:28 +0200266 if (float32_is_signaling_nan(fa.f, &env->fp_status) ||
267 float32_is_signaling_nan(fb.f, &env->fp_status)) {
Blue Swirl64254eb2012-09-02 08:39:22 +0000268 update_fpu_flags(env, float_flag_invalid);
Edgar E. Iglesiasef9d48d2010-09-09 22:05:48 +0200269 r = 1;
270 }
271
Aleksandar Markovicaf39bc82016-06-10 11:57:28 +0200272 if (float32_is_quiet_nan(fa.f, &env->fp_status) ||
273 float32_is_quiet_nan(fb.f, &env->fp_status)) {
Edgar E. Iglesiasef9d48d2010-09-09 22:05:48 +0200274 r = 1;
275 }
276
277 return r;
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200278}
279
Blue Swirl64254eb2012-09-02 08:39:22 +0000280uint32_t helper_fcmp_lt(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200281{
282 CPU_FloatU fa, fb;
283 int r;
284 int flags;
285
286 set_float_exception_flags(0, &env->fp_status);
287 fa.l = a;
288 fb.l = b;
289 r = float32_lt(fb.f, fa.f, &env->fp_status);
290 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000291 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200292
293 return r;
294}
295
Blue Swirl64254eb2012-09-02 08:39:22 +0000296uint32_t helper_fcmp_eq(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200297{
298 CPU_FloatU fa, fb;
299 int flags;
300 int r;
301
302 set_float_exception_flags(0, &env->fp_status);
303 fa.l = a;
304 fb.l = b;
Aurelien Jarno211315f2011-04-14 00:49:29 +0200305 r = float32_eq_quiet(fa.f, fb.f, &env->fp_status);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200306 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000307 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200308
309 return r;
310}
311
Blue Swirl64254eb2012-09-02 08:39:22 +0000312uint32_t helper_fcmp_le(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200313{
314 CPU_FloatU fa, fb;
315 int flags;
316 int r;
317
318 fa.l = a;
319 fb.l = b;
320 set_float_exception_flags(0, &env->fp_status);
321 r = float32_le(fa.f, fb.f, &env->fp_status);
322 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000323 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200324
325
326 return r;
327}
328
Blue Swirl64254eb2012-09-02 08:39:22 +0000329uint32_t helper_fcmp_gt(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200330{
331 CPU_FloatU fa, fb;
332 int flags, r;
333
334 fa.l = a;
335 fb.l = b;
336 set_float_exception_flags(0, &env->fp_status);
337 r = float32_lt(fa.f, fb.f, &env->fp_status);
338 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000339 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200340 return r;
341}
342
Blue Swirl64254eb2012-09-02 08:39:22 +0000343uint32_t helper_fcmp_ne(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200344{
345 CPU_FloatU fa, fb;
346 int flags, r;
347
348 fa.l = a;
349 fb.l = b;
350 set_float_exception_flags(0, &env->fp_status);
Aurelien Jarno211315f2011-04-14 00:49:29 +0200351 r = !float32_eq_quiet(fa.f, fb.f, &env->fp_status);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200352 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000353 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200354
355 return r;
356}
357
Blue Swirl64254eb2012-09-02 08:39:22 +0000358uint32_t helper_fcmp_ge(CPUMBState *env, uint32_t a, uint32_t b)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200359{
360 CPU_FloatU fa, fb;
361 int flags, r;
362
363 fa.l = a;
364 fb.l = b;
365 set_float_exception_flags(0, &env->fp_status);
366 r = !float32_lt(fa.f, fb.f, &env->fp_status);
367 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000368 update_fpu_flags(env, flags & float_flag_invalid);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200369
370 return r;
371}
372
Blue Swirl64254eb2012-09-02 08:39:22 +0000373uint32_t helper_flt(CPUMBState *env, uint32_t a)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200374{
375 CPU_FloatU fd, fa;
376
377 fa.l = a;
378 fd.f = int32_to_float32(fa.l, &env->fp_status);
379 return fd.l;
380}
381
Blue Swirl64254eb2012-09-02 08:39:22 +0000382uint32_t helper_fint(CPUMBState *env, uint32_t a)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200383{
384 CPU_FloatU fa;
385 uint32_t r;
386 int flags;
387
388 set_float_exception_flags(0, &env->fp_status);
389 fa.l = a;
390 r = float32_to_int32(fa.f, &env->fp_status);
391 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000392 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200393
394 return r;
395}
396
Blue Swirl64254eb2012-09-02 08:39:22 +0000397uint32_t helper_fsqrt(CPUMBState *env, uint32_t a)
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200398{
399 CPU_FloatU fd, fa;
400 int flags;
401
402 set_float_exception_flags(0, &env->fp_status);
403 fa.l = a;
404 fd.l = float32_sqrt(fa.f, &env->fp_status);
405 flags = get_float_exception_flags(&env->fp_status);
Blue Swirl64254eb2012-09-02 08:39:22 +0000406 update_fpu_flags(env, flags);
Edgar E. Iglesias97694c52010-09-09 10:20:17 +0200407
408 return fd.l;
409}
410
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200411uint32_t helper_pcmpbf(uint32_t a, uint32_t b)
412{
413 unsigned int i;
414 uint32_t mask = 0xff000000;
415
416 for (i = 0; i < 4; i++) {
417 if ((a & mask) == (b & mask))
418 return i + 1;
419 mask >>= 8;
420 }
421 return 0;
422}
423
Edgar E. Iglesias403322e2018-04-13 20:20:25 +0200424void helper_memalign(CPUMBState *env, target_ulong addr,
425 uint32_t dr, uint32_t wr,
Blue Swirl64254eb2012-09-02 08:39:22 +0000426 uint32_t mask)
Edgar E. Iglesias968a40f2009-09-03 12:59:46 +0200427{
Edgar E. Iglesias968a40f2009-09-03 12:59:46 +0200428 if (addr & mask) {
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200429 qemu_log_mask(CPU_LOG_INT,
Edgar E. Iglesias403322e2018-04-13 20:20:25 +0200430 "unaligned access addr=" TARGET_FMT_lx
431 " mask=%x, wr=%d dr=r%d\n",
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200432 addr, mask, wr, dr);
433 env->sregs[SR_EAR] = addr;
Edgar E. Iglesias968a40f2009-09-03 12:59:46 +0200434 env->sregs[SR_ESR] = ESR_EC_UNALIGNED_DATA | (wr << 10) \
435 | (dr & 31) << 5;
Edgar E. Iglesias3aa80982009-09-03 22:28:21 +0200436 if (mask == 3) {
Edgar E. Iglesias968a40f2009-09-03 12:59:46 +0200437 env->sregs[SR_ESR] |= 1 << 11;
438 }
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200439 if (!(env->sregs[SR_MSR] & MSR_EE)) {
440 return;
441 }
Blue Swirl64254eb2012-09-02 08:39:22 +0000442 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesias968a40f2009-09-03 12:59:46 +0200443 }
444}
445
Edgar E. Iglesias403322e2018-04-13 20:20:25 +0200446void helper_stackprot(CPUMBState *env, target_ulong addr)
Edgar E. Iglesias5818dee2012-01-10 10:27:11 +0100447{
448 if (addr < env->slr || addr > env->shr) {
Edgar E. Iglesias403322e2018-04-13 20:20:25 +0200449 qemu_log_mask(CPU_LOG_INT, "Stack protector violation at "
450 TARGET_FMT_lx " %x %x\n",
Paolo Bonzini1d512a62015-11-13 13:24:57 +0100451 addr, env->slr, env->shr);
Alistair Francis53432dc2015-05-29 16:29:28 +1000452 env->sregs[SR_EAR] = addr;
453 env->sregs[SR_ESR] = ESR_EC_STACKPROT;
454 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesias5818dee2012-01-10 10:27:11 +0100455 }
456}
457
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200458#if !defined(CONFIG_USER_ONLY)
459/* Writes/reads to the MMU's special regs end up here. */
Edgar E. Iglesiasf0f7e7f2018-04-16 21:25:01 +0200460uint32_t helper_mmu_read(CPUMBState *env, uint32_t ext, uint32_t rn)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200461{
Edgar E. Iglesiasf0f7e7f2018-04-16 21:25:01 +0200462 return mmu_read(env, ext, rn);
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200463}
464
Edgar E. Iglesiasf0f7e7f2018-04-16 21:25:01 +0200465void helper_mmu_write(CPUMBState *env, uint32_t ext, uint32_t rn, uint32_t v)
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200466{
Edgar E. Iglesiasf0f7e7f2018-04-16 21:25:01 +0200467 mmu_write(env, ext, rn, v);
Edgar E. Iglesias4acb54b2009-05-20 19:37:39 +0200468}
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200469
Peter Maydellbdff8122018-12-10 17:56:30 +0000470void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
471 unsigned size, MMUAccessType access_type,
472 int mmu_idx, MemTxAttrs attrs,
473 MemTxResult response, uintptr_t retaddr)
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200474{
Andreas Färberc658b942013-05-27 06:49:53 +0200475 MicroBlazeCPU *cpu;
476 CPUMBState *env;
Peter Maydellbdff8122018-12-10 17:56:30 +0000477 qemu_log_mask(CPU_LOG_INT, "Transaction failed: vaddr 0x%" VADDR_PRIx
478 " physaddr 0x" TARGET_FMT_plx " size %d access type %s\n",
479 addr, physaddr, size,
480 access_type == MMU_INST_FETCH ? "INST_FETCH" :
481 (access_type == MMU_DATA_LOAD ? "DATA_LOAD" : "DATA_STORE"));
Andreas Färberc658b942013-05-27 06:49:53 +0200482 cpu = MICROBLAZE_CPU(cs);
483 env = &cpu->env;
Peter Maydellbdff8122018-12-10 17:56:30 +0000484
485 cpu_restore_state(cs, retaddr, true);
Andreas Färberc658b942013-05-27 06:49:53 +0200486 if (!(env->sregs[SR_MSR] & MSR_EE)) {
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200487 return;
488 }
489
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200490 env->sregs[SR_EAR] = addr;
Peter Maydellbdff8122018-12-10 17:56:30 +0000491 if (access_type == MMU_INST_FETCH) {
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200492 if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) {
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200493 env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
Blue Swirl64254eb2012-09-02 08:39:22 +0000494 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200495 }
496 } else {
Edgar E. Iglesias97f90cb2009-09-11 10:27:38 +0200497 if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) {
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200498 env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
Blue Swirl64254eb2012-09-02 08:39:22 +0000499 helper_raise_exception(env, EXCP_HW_EXCP);
Edgar E. Iglesiasfaed1c22009-09-03 13:25:09 +0200500 }
501 }
502}
Paul Brook3c7b48b2010-03-01 04:11:28 +0000503#endif