4 * Copyright (c) 2007 AXIS Communications
5 * Written by Edgar E. Iglesias
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.
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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define MMUSUFFIX _mmu
28 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
30 # define GETPC() (__builtin_return_address(0))
34 #include "softmmu_template.h"
37 #include "softmmu_template.h"
40 #include "softmmu_template.h"
43 #include "softmmu_template.h"
47 /* Try to fill the TLB and return an exception if error. If retaddr is
48 NULL, it means that the function was called in C code (i.e. not
49 from generated code or from helper.c) */
50 /* XXX: fix it to restore all registers */
51 void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
58 /* XXX: hack to restore env in all cases, even if not called from
63 D(fprintf(logfile, "%s pc=%x tpc=%x ra=%x\n", __func__,
64 env->pc, env->debug1, retaddr));
65 ret = cpu_cris_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
66 if (__builtin_expect(ret, 0)) {
68 /* now we have a real cpu fault */
69 pc = (unsigned long)retaddr;
72 /* the PC is inside the translated code. It means that we have
73 a virtual CPU fault */
74 cpu_restore_state(tb, env, pc, NULL);
82 void helper_tlb_update(uint32_t T0)
84 #if !defined(CONFIG_USER_ONLY)
86 uint32_t srs = env->pregs[PR_SRS];
88 if (srs != 1 && srs != 2)
91 vaddr = cris_mmu_tlb_latest_update(env, T0);
92 D(fprintf(logfile, "flush old_vaddr=%x vaddr=%x T0=%x\n", vaddr,
93 env->sregs[SFR_R_MM_CAUSE] & TARGET_PAGE_MASK, T0));
94 tlb_flush_page(env, vaddr);
98 void helper_tlb_flush(void)
103 void helper_dump(uint32_t a0, uint32_t a1)
105 (fprintf(logfile, "%s: a0=%x a1=%x\n", __func__, a0, a1));
108 void helper_dummy(void)
113 /* Only used for debugging at the moment. */
114 void helper_rfe(void)
116 D(fprintf(logfile, "rfe: erp=%x pid=%x ccs=%x btarget=%x\n",
117 env->pregs[PR_ERP], env->pregs[PR_PID],
122 void helper_store(uint32_t a0)
124 if (env->pregs[PR_CCS] & P_FLAG )
126 cpu_abort(env, "cond_store_failed! pc=%x a0=%x\n",
131 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
134 D(printf("%s addr=%x w=%d ex=%d asi=%d\n",
135 __func__, addr, is_write, is_exec, is_asi));
138 static void evaluate_flags_writeback(uint32_t flags)
142 /* Extended arithmetics, leave the z flag alone. */
143 env->debug3 = env->pregs[PR_CCS];
148 x = env->pregs[PR_CCS] & X_FLAG;
150 if ((x || env->cc_op == CC_OP_ADDC)
152 env->cc_mask &= ~Z_FLAG;
154 /* all insn clear the x-flag except setf or clrf. */
155 env->pregs[PR_CCS] &= ~(env->cc_mask | X_FLAG);
156 flags &= env->cc_mask;
157 env->pregs[PR_CCS] |= flags;
161 void helper_evaluate_flags_muls(void)
167 /* were gonna have to redo the muls. */
174 res = env->cc_result;
177 /* cast into signed values to make GCC sign extend. */
180 dneg = ((int32_t)res) < 0;
188 if ((dneg && mof != -1)
189 || (!dneg && mof != 0))
191 evaluate_flags_writeback(flags);
194 void helper_evaluate_flags_mulu(void)
200 /* were gonna have to redo the muls. */
201 uint64_t tmp, t0 ,t1;
206 res = env->cc_result;
209 /* cast into signed values to make GCC sign extend. */
222 evaluate_flags_writeback(flags);
225 void helper_evaluate_flags_mcp(void)
234 res = env->cc_result;
236 if ((res & 0x80000000L) != 0L)
239 if (((src & 0x80000000L) == 0L)
240 && ((dst & 0x80000000L) == 0L))
244 else if (((src & 0x80000000L) != 0L) &&
245 ((dst & 0x80000000L) != 0L))
254 if (((src & 0x80000000L) != 0L)
255 && ((dst & 0x80000000L) != 0L))
257 if ((dst & 0x80000000L) != 0L
258 || (src & 0x80000000L) != 0L)
262 evaluate_flags_writeback(flags);
265 void helper_evaluate_flags_alu_4(void)
274 res = env->cc_result;
276 if ((res & 0x80000000L) != 0L)
279 if (((src & 0x80000000L) == 0L)
280 && ((dst & 0x80000000L) == 0L))
284 else if (((src & 0x80000000L) != 0L) &&
285 ((dst & 0x80000000L) != 0L))
294 if (((src & 0x80000000L) != 0L)
295 && ((dst & 0x80000000L) != 0L))
297 if ((dst & 0x80000000L) != 0L
298 || (src & 0x80000000L) != 0L)
302 if (env->cc_op == CC_OP_SUB
303 || env->cc_op == CC_OP_CMP) {
306 evaluate_flags_writeback(flags);
309 void helper_evaluate_flags_move_4 (void)
316 res = env->cc_result;
318 if ((int32_t)res < 0)
323 evaluate_flags_writeback(flags);
325 void helper_evaluate_flags_move_2 (void)
332 res = env->cc_result;
334 if ((int16_t)res < 0L)
339 evaluate_flags_writeback(flags);
342 /* TODO: This is expensive. We could split things up and only evaluate part of
343 CCR on a need to know basis. For now, we simply re-evaluate everything. */
344 void helper_evaluate_flags (void)
353 res = env->cc_result;
356 /* Now, evaluate the flags. This stuff is based on
357 Per Zander's CRISv10 simulator. */
358 switch (env->cc_size)
361 if ((res & 0x80L) != 0L)
364 if (((src & 0x80L) == 0L)
365 && ((dst & 0x80L) == 0L))
369 else if (((src & 0x80L) != 0L)
370 && ((dst & 0x80L) != 0L))
377 if ((res & 0xFFL) == 0L)
381 if (((src & 0x80L) != 0L)
382 && ((dst & 0x80L) != 0L))
386 if ((dst & 0x80L) != 0L
387 || (src & 0x80L) != 0L)
394 if ((res & 0x8000L) != 0L)
397 if (((src & 0x8000L) == 0L)
398 && ((dst & 0x8000L) == 0L))
402 else if (((src & 0x8000L) != 0L)
403 && ((dst & 0x8000L) != 0L))
410 if ((res & 0xFFFFL) == 0L)
414 if (((src & 0x8000L) != 0L)
415 && ((dst & 0x8000L) != 0L))
419 if ((dst & 0x8000L) != 0L
420 || (src & 0x8000L) != 0L)
427 if ((res & 0x80000000L) != 0L)
430 if (((src & 0x80000000L) == 0L)
431 && ((dst & 0x80000000L) == 0L))
435 else if (((src & 0x80000000L) != 0L) &&
436 ((dst & 0x80000000L) != 0L))
445 if (((src & 0x80000000L) != 0L)
446 && ((dst & 0x80000000L) != 0L))
448 if ((dst & 0x80000000L) != 0L
449 || (src & 0x80000000L) != 0L)
457 if (env->cc_op == CC_OP_SUB
458 || env->cc_op == CC_OP_CMP) {
461 evaluate_flags_writeback(flags);