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(int is_hw
)
26 env
->exception_index
= -1;
31 extern int semihosting_enabled
;
33 #define MMUSUFFIX _mmu
36 #include "softmmu_template.h"
39 #include "softmmu_template.h"
42 #include "softmmu_template.h"
45 #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
62 ret
= cpu_m68k_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
65 /* now we have a real cpu fault */
66 pc
= (unsigned long)retaddr
;
69 /* the PC is inside the translated code. It means that we have
70 a virtual CPU fault */
71 cpu_restore_state(tb
, env
, pc
, NULL
);
79 static void do_rte(void)
86 env
->pc
= ldl_kernel(sp
+ 4);
87 sp
|= (fmt
>> 28) & 3;
88 env
->sr
= fmt
& 0xffff;
90 env
->aregs
[7] = sp
+ 8;
93 void do_interrupt(int is_hw
)
104 switch (env
->exception_index
) {
106 /* Return from an exception. */
110 if (semihosting_enabled
111 && (env
->sr
& SR_S
) != 0
112 && (env
->pc
& 3) == 0
113 && lduw_code(env
->pc
- 4) == 0x4e71
114 && ldl_code(env
->pc
) == 0x4e7bf000) {
116 do_m68k_semihosting(env
, env
->dregs
[0]);
120 env
->exception_index
= EXCP_HLT
;
124 if (env
->exception_index
>= EXCP_TRAP0
125 && env
->exception_index
<= EXCP_TRAP15
) {
126 /* Move the PC after the trap instruction. */
131 vector
= env
->exception_index
<< 2;
136 fmt
|= (sp
& 3) << 28;
142 env
->sr
= (env
->sr
& ~SR_I
) | (env
->pending_level
<< SR_I_SHIFT
);
147 /* ??? This could cause MMU faults. */
150 stl_kernel(sp
, retaddr
);
154 /* Jump to vector. */
155 env
->pc
= ldl_kernel(env
->vbr
+ vector
);
160 static void raise_exception(int tt
)
162 env
->exception_index
= tt
;
166 void HELPER(raise_exception
)(uint32_t tt
)
171 void HELPER(divu
)(CPUState
*env
, uint32_t word
)
181 /* ??? This needs to make sure the throwing location is accurate. */
183 raise_exception(EXCP_DIV0
);
187 /* Avoid using a PARAM1 of zero. This breaks dyngen because it uses
188 the address of a symbol, and gcc knows symbols can't have address
190 if (word
&& quot
> 0xffff)
194 else if ((int32_t)quot
< 0)
198 env
->cc_dest
= flags
;
201 void HELPER(divs
)(CPUState
*env
, uint32_t word
)
212 raise_exception(EXCP_DIV0
);
216 if (word
&& quot
!= (int16_t)quot
)
224 env
->cc_dest
= flags
;