]> Git Repo - qemu.git/blame - target-m68k/op_helper.c
rdma: bug fixes
[qemu.git] / target-m68k / op_helper.c
CommitLineData
0633879f
PB
1/*
2 * M68K helper routines
5fafdf24 3 *
0633879f
PB
4 * Copyright (c) 2007 CodeSourcery
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
8167ee88 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
0633879f 18 */
3e457172 19#include "cpu.h"
2ef6175a 20#include "exec/helper-proto.h"
f08b6170 21#include "exec/cpu_ldst.h"
0633879f
PB
22
23#if defined(CONFIG_USER_ONLY)
24
97a8ea5a 25void m68k_cpu_do_interrupt(CPUState *cs)
3c688828 26{
27103424 27 cs->exception_index = -1;
3c688828
BS
28}
29
31871141 30void do_interrupt_m68k_hardirq(CPUM68KState *env)
0633879f 31{
0633879f
PB
32}
33
34#else
35
a87295e8
PB
36extern int semihosting_enabled;
37
0633879f
PB
38/* Try to fill the TLB and return an exception if error. If retaddr is
39 NULL, it means that the function was called in C code (i.e. not
40 from generated code or from helper.c) */
d5a11fef 41void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx,
20503968 42 uintptr_t retaddr)
0633879f 43{
0633879f
PB
44 int ret;
45
d5a11fef 46 ret = m68k_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx);
551bd27f 47 if (unlikely(ret)) {
0633879f
PB
48 if (retaddr) {
49 /* now we have a real cpu fault */
3f38f309 50 cpu_restore_state(cs, retaddr);
0633879f 51 }
5638d180 52 cpu_loop_exit(cs);
0633879f 53 }
0633879f
PB
54}
55
31871141 56static void do_rte(CPUM68KState *env)
0633879f
PB
57{
58 uint32_t sp;
59 uint32_t fmt;
60
61 sp = env->aregs[7];
31871141
BS
62 fmt = cpu_ldl_kernel(env, sp);
63 env->pc = cpu_ldl_kernel(env, sp + 4);
0633879f
PB
64 sp |= (fmt >> 28) & 3;
65 env->sr = fmt & 0xffff;
20dcee94 66 m68k_switch_sp(env);
0633879f
PB
67 env->aregs[7] = sp + 8;
68}
69
31871141 70static void do_interrupt_all(CPUM68KState *env, int is_hw)
0633879f 71{
27103424 72 CPUState *cs = CPU(m68k_env_get_cpu(env));
0633879f
PB
73 uint32_t sp;
74 uint32_t fmt;
75 uint32_t retaddr;
76 uint32_t vector;
77
78 fmt = 0;
79 retaddr = env->pc;
80
81 if (!is_hw) {
27103424 82 switch (cs->exception_index) {
0633879f
PB
83 case EXCP_RTE:
84 /* Return from an exception. */
31871141 85 do_rte(env);
0633879f 86 return;
a87295e8
PB
87 case EXCP_HALT_INSN:
88 if (semihosting_enabled
89 && (env->sr & SR_S) != 0
90 && (env->pc & 3) == 0
31871141
BS
91 && cpu_lduw_code(env, env->pc - 4) == 0x4e71
92 && cpu_ldl_code(env, env->pc) == 0x4e7bf000) {
a87295e8
PB
93 env->pc += 4;
94 do_m68k_semihosting(env, env->dregs[0]);
95 return;
96 }
259186a7 97 cs->halted = 1;
27103424 98 cs->exception_index = EXCP_HLT;
5638d180 99 cpu_loop_exit(cs);
a87295e8 100 return;
0633879f 101 }
27103424
AF
102 if (cs->exception_index >= EXCP_TRAP0
103 && cs->exception_index <= EXCP_TRAP15) {
0633879f
PB
104 /* Move the PC after the trap instruction. */
105 retaddr += 2;
106 }
107 }
108
27103424 109 vector = cs->exception_index << 2;
0633879f 110
0cf5c677
PB
111 sp = env->aregs[7];
112
0633879f
PB
113 fmt |= 0x40000000;
114 fmt |= (sp & 3) << 28;
115 fmt |= vector << 16;
116 fmt |= env->sr;
117
20dcee94
PB
118 env->sr |= SR_S;
119 if (is_hw) {
120 env->sr = (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT);
121 env->sr &= ~SR_M;
122 }
123 m68k_switch_sp(env);
124
0633879f
PB
125 /* ??? This could cause MMU faults. */
126 sp &= ~3;
127 sp -= 4;
31871141 128 cpu_stl_kernel(env, sp, retaddr);
0633879f 129 sp -= 4;
31871141 130 cpu_stl_kernel(env, sp, fmt);
0633879f 131 env->aregs[7] = sp;
0633879f 132 /* Jump to vector. */
31871141 133 env->pc = cpu_ldl_kernel(env, env->vbr + vector);
0633879f
PB
134}
135
97a8ea5a 136void m68k_cpu_do_interrupt(CPUState *cs)
3c688828 137{
97a8ea5a
AF
138 M68kCPU *cpu = M68K_CPU(cs);
139 CPUM68KState *env = &cpu->env;
140
31871141 141 do_interrupt_all(env, 0);
3c688828
BS
142}
143
31871141 144void do_interrupt_m68k_hardirq(CPUM68KState *env)
3c688828 145{
31871141 146 do_interrupt_all(env, 1);
3c688828 147}
0633879f 148#endif
e1f3808e 149
31871141 150static void raise_exception(CPUM68KState *env, int tt)
e1f3808e 151{
27103424
AF
152 CPUState *cs = CPU(m68k_env_get_cpu(env));
153
154 cs->exception_index = tt;
5638d180 155 cpu_loop_exit(cs);
e1f3808e
PB
156}
157
31871141 158void HELPER(raise_exception)(CPUM68KState *env, uint32_t tt)
e1f3808e 159{
31871141 160 raise_exception(env, tt);
e1f3808e
PB
161}
162
2b3e3cfe 163void HELPER(divu)(CPUM68KState *env, uint32_t word)
e1f3808e
PB
164{
165 uint32_t num;
166 uint32_t den;
167 uint32_t quot;
168 uint32_t rem;
169 uint32_t flags;
170
171 num = env->div1;
172 den = env->div2;
173 /* ??? This needs to make sure the throwing location is accurate. */
31871141
BS
174 if (den == 0) {
175 raise_exception(env, EXCP_DIV0);
176 }
e1f3808e
PB
177 quot = num / den;
178 rem = num % den;
179 flags = 0;
e1f3808e
PB
180 if (word && quot > 0xffff)
181 flags |= CCF_V;
182 if (quot == 0)
183 flags |= CCF_Z;
184 else if ((int32_t)quot < 0)
185 flags |= CCF_N;
186 env->div1 = quot;
187 env->div2 = rem;
188 env->cc_dest = flags;
189}
190
2b3e3cfe 191void HELPER(divs)(CPUM68KState *env, uint32_t word)
e1f3808e
PB
192{
193 int32_t num;
194 int32_t den;
195 int32_t quot;
196 int32_t rem;
197 int32_t flags;
198
199 num = env->div1;
200 den = env->div2;
31871141
BS
201 if (den == 0) {
202 raise_exception(env, EXCP_DIV0);
203 }
e1f3808e
PB
204 quot = num / den;
205 rem = num % den;
206 flags = 0;
207 if (word && quot != (int16_t)quot)
208 flags |= CCF_V;
209 if (quot == 0)
210 flags |= CCF_Z;
211 else if (quot < 0)
212 flags |= CCF_N;
213 env->div1 = quot;
214 env->div2 = rem;
215 env->cc_dest = flags;
216}
This page took 0.733448 seconds and 4 git commands to generate.