4 * Copyright (c) 2007 CodeSourcery
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #if defined(CONFIG_USER_ONLY)
24 void m68k_cpu_do_interrupt(CPUState *cs)
26 M68kCPU *cpu = M68K_CPU(cs);
27 CPUM68KState *env = &cpu->env;
29 env->exception_index = -1;
32 void do_interrupt_m68k_hardirq(CPUM68KState *env)
38 extern int semihosting_enabled;
40 #include "exec/softmmu_exec.h"
42 #define MMUSUFFIX _mmu
45 #include "exec/softmmu_template.h"
48 #include "exec/softmmu_template.h"
51 #include "exec/softmmu_template.h"
54 #include "exec/softmmu_template.h"
56 /* Try to fill the TLB and return an exception if error. If retaddr is
57 NULL, it means that the function was called in C code (i.e. not
58 from generated code or from helper.c) */
59 void tlb_fill(CPUM68KState *env, target_ulong addr, int is_write, int mmu_idx,
64 ret = cpu_m68k_handle_mmu_fault(env, addr, is_write, mmu_idx);
67 /* now we have a real cpu fault */
68 cpu_restore_state(env, retaddr);
74 static void do_rte(CPUM68KState *env)
80 fmt = cpu_ldl_kernel(env, sp);
81 env->pc = cpu_ldl_kernel(env, sp + 4);
82 sp |= (fmt >> 28) & 3;
83 env->sr = fmt & 0xffff;
85 env->aregs[7] = sp + 8;
88 static void do_interrupt_all(CPUM68KState *env, int is_hw)
100 switch (env->exception_index) {
102 /* Return from an exception. */
106 if (semihosting_enabled
107 && (env->sr & SR_S) != 0
108 && (env->pc & 3) == 0
109 && cpu_lduw_code(env, env->pc - 4) == 0x4e71
110 && cpu_ldl_code(env, env->pc) == 0x4e7bf000) {
112 do_m68k_semihosting(env, env->dregs[0]);
115 cs = CPU(m68k_env_get_cpu(env));
117 env->exception_index = EXCP_HLT;
121 if (env->exception_index >= EXCP_TRAP0
122 && env->exception_index <= EXCP_TRAP15) {
123 /* Move the PC after the trap instruction. */
128 vector = env->exception_index << 2;
133 fmt |= (sp & 3) << 28;
139 env->sr = (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT);
144 /* ??? This could cause MMU faults. */
147 cpu_stl_kernel(env, sp, retaddr);
149 cpu_stl_kernel(env, sp, fmt);
151 /* Jump to vector. */
152 env->pc = cpu_ldl_kernel(env, env->vbr + vector);
155 void m68k_cpu_do_interrupt(CPUState *cs)
157 M68kCPU *cpu = M68K_CPU(cs);
158 CPUM68KState *env = &cpu->env;
160 do_interrupt_all(env, 0);
163 void do_interrupt_m68k_hardirq(CPUM68KState *env)
165 do_interrupt_all(env, 1);
169 static void raise_exception(CPUM68KState *env, int tt)
171 env->exception_index = tt;
175 void HELPER(raise_exception)(CPUM68KState *env, uint32_t tt)
177 raise_exception(env, tt);
180 void HELPER(divu)(CPUM68KState *env, uint32_t word)
190 /* ??? This needs to make sure the throwing location is accurate. */
192 raise_exception(env, EXCP_DIV0);
197 if (word && quot > 0xffff)
201 else if ((int32_t)quot < 0)
205 env->cc_dest = flags;
208 void HELPER(divs)(CPUM68KState *env, uint32_t word)
219 raise_exception(env, EXCP_DIV0);
224 if (word && quot != (int16_t)quot)
232 env->cc_dest = flags;