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 do_interrupt(CPUState
*env1
)
26 env1
->exception_index
= -1;
29 void do_interrupt_m68k_hardirq(CPUState
*env1
)
35 extern int semihosting_enabled
;
37 #define MMUSUFFIX _mmu
40 #include "softmmu_template.h"
43 #include "softmmu_template.h"
46 #include "softmmu_template.h"
49 #include "softmmu_template.h"
51 /* Try to fill the TLB and return an exception if error. If retaddr is
52 NULL, it means that the function was called in C code (i.e. not
53 from generated code or from helper.c) */
54 /* XXX: fix it to restore all registers */
55 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
62 /* XXX: hack to restore env in all cases, even if not called from
66 ret
= cpu_m68k_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
69 /* now we have a real cpu fault */
70 pc
= (unsigned long)retaddr
;
73 /* the PC is inside the translated code. It means that we have
74 a virtual CPU fault */
75 cpu_restore_state(tb
, env
, pc
);
83 static void do_rte(void)
90 env
->pc
= ldl_kernel(sp
+ 4);
91 sp
|= (fmt
>> 28) & 3;
92 env
->sr
= fmt
& 0xffff;
94 env
->aregs
[7] = sp
+ 8;
97 static void do_interrupt_all(int is_hw
)
108 switch (env
->exception_index
) {
110 /* Return from an exception. */
114 if (semihosting_enabled
115 && (env
->sr
& SR_S
) != 0
116 && (env
->pc
& 3) == 0
117 && lduw_code(env
->pc
- 4) == 0x4e71
118 && ldl_code(env
->pc
) == 0x4e7bf000) {
120 do_m68k_semihosting(env
, env
->dregs
[0]);
124 env
->exception_index
= EXCP_HLT
;
128 if (env
->exception_index
>= EXCP_TRAP0
129 && env
->exception_index
<= EXCP_TRAP15
) {
130 /* Move the PC after the trap instruction. */
135 vector
= env
->exception_index
<< 2;
140 fmt
|= (sp
& 3) << 28;
146 env
->sr
= (env
->sr
& ~SR_I
) | (env
->pending_level
<< SR_I_SHIFT
);
151 /* ??? This could cause MMU faults. */
154 stl_kernel(sp
, retaddr
);
158 /* Jump to vector. */
159 env
->pc
= ldl_kernel(env
->vbr
+ vector
);
162 void do_interrupt(CPUState
*env1
)
172 void do_interrupt_m68k_hardirq(CPUState
*env1
)
183 static void raise_exception(int tt
)
185 env
->exception_index
= tt
;
189 void HELPER(raise_exception
)(uint32_t tt
)
194 void HELPER(divu
)(CPUState
*env
, uint32_t word
)
204 /* ??? This needs to make sure the throwing location is accurate. */
206 raise_exception(EXCP_DIV0
);
210 /* Avoid using a PARAM1 of zero. This breaks dyngen because it uses
211 the address of a symbol, and gcc knows symbols can't have address
213 if (word
&& quot
> 0xffff)
217 else if ((int32_t)quot
< 0)
221 env
->cc_dest
= flags
;
224 void HELPER(divs
)(CPUState
*env
, uint32_t word
)
235 raise_exception(EXCP_DIV0
);
239 if (word
&& quot
!= (int16_t)quot
)
247 env
->cc_dest
= flags
;