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/>.
19 #include "qemu/osdep.h"
21 #include "exec/helper-proto.h"
22 #include "exec/exec-all.h"
23 #include "exec/cpu_ldst.h"
24 #include "exec/semihost.h"
26 #if defined(CONFIG_USER_ONLY)
28 void m68k_cpu_do_interrupt(CPUState
*cs
)
30 cs
->exception_index
= -1;
33 static inline void do_interrupt_m68k_hardirq(CPUM68KState
*env
)
39 /* Try to fill the TLB and return an exception if error. If retaddr is
40 NULL, it means that the function was called in C code (i.e. not
41 from generated code or from helper.c) */
42 void tlb_fill(CPUState
*cs
, target_ulong addr
, MMUAccessType access_type
,
43 int mmu_idx
, uintptr_t retaddr
)
47 ret
= m68k_cpu_handle_mmu_fault(cs
, addr
, access_type
, mmu_idx
);
50 /* now we have a real cpu fault */
51 cpu_restore_state(cs
, retaddr
);
57 static void do_rte(CPUM68KState
*env
)
63 fmt
= cpu_ldl_kernel(env
, sp
);
64 env
->pc
= cpu_ldl_kernel(env
, sp
+ 4);
65 sp
|= (fmt
>> 28) & 3;
66 env
->sr
= fmt
& 0xffff;
67 env
->aregs
[7] = sp
+ 8;
71 static void do_interrupt_all(CPUM68KState
*env
, int is_hw
)
73 CPUState
*cs
= CPU(m68k_env_get_cpu(env
));
83 switch (cs
->exception_index
) {
85 /* Return from an exception. */
89 if (semihosting_enabled()
90 && (env
->sr
& SR_S
) != 0
92 && cpu_lduw_code(env
, env
->pc
- 4) == 0x4e71
93 && cpu_ldl_code(env
, env
->pc
) == 0x4e7bf000) {
95 do_m68k_semihosting(env
, env
->dregs
[0]);
99 cs
->exception_index
= EXCP_HLT
;
103 if (cs
->exception_index
>= EXCP_TRAP0
104 && cs
->exception_index
<= EXCP_TRAP15
) {
105 /* Move the PC after the trap instruction. */
110 vector
= cs
->exception_index
<< 2;
118 env
->sr
= (env
->sr
& ~SR_I
) | (env
->pending_level
<< SR_I_SHIFT
);
123 fmt
|= (sp
& 3) << 28;
125 /* ??? This could cause MMU faults. */
128 cpu_stl_kernel(env
, sp
, retaddr
);
130 cpu_stl_kernel(env
, sp
, fmt
);
132 /* Jump to vector. */
133 env
->pc
= cpu_ldl_kernel(env
, env
->vbr
+ vector
);
136 void m68k_cpu_do_interrupt(CPUState
*cs
)
138 M68kCPU
*cpu
= M68K_CPU(cs
);
139 CPUM68KState
*env
= &cpu
->env
;
141 do_interrupt_all(env
, 0);
144 static inline void do_interrupt_m68k_hardirq(CPUM68KState
*env
)
146 do_interrupt_all(env
, 1);
150 bool m68k_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
152 M68kCPU
*cpu
= M68K_CPU(cs
);
153 CPUM68KState
*env
= &cpu
->env
;
155 if (interrupt_request
& CPU_INTERRUPT_HARD
156 && ((env
->sr
& SR_I
) >> SR_I_SHIFT
) < env
->pending_level
) {
157 /* Real hardware gets the interrupt vector via an IACK cycle
158 at this point. Current emulated hardware doesn't rely on
159 this, so we provide/save the vector when the interrupt is
161 cs
->exception_index
= env
->pending_vector
;
162 do_interrupt_m68k_hardirq(env
);
168 static void raise_exception(CPUM68KState
*env
, int tt
)
170 CPUState
*cs
= CPU(m68k_env_get_cpu(env
));
172 cs
->exception_index
= tt
;
176 void HELPER(raise_exception
)(CPUM68KState
*env
, uint32_t tt
)
178 raise_exception(env
, tt
);
181 void HELPER(divu
)(CPUM68KState
*env
, uint32_t word
)
191 /* ??? This needs to make sure the throwing location is accurate. */
193 raise_exception(env
, EXCP_DIV0
);
198 if (word
&& quot
> 0xffff)
202 else if ((int32_t)quot
< 0)
206 env
->cc_dest
= flags
;
209 void HELPER(divs
)(CPUM68KState
*env
, uint32_t word
)
220 raise_exception(env
, EXCP_DIV0
);
225 if (word
&& quot
!= (int16_t)quot
)
233 env
->cc_dest
= flags
;