root / target-m68k / op_helper.c @ c596defd
History | View | Annotate | Download (5.4 kB)
1 | 0633879f | pbrook | /*
|
---|---|---|---|
2 | 0633879f | pbrook | * M68K helper routines
|
3 | 5fafdf24 | ths | *
|
4 | 0633879f | pbrook | * Copyright (c) 2007 CodeSourcery
|
5 | 0633879f | pbrook | *
|
6 | 0633879f | pbrook | * This library is free software; you can redistribute it and/or
|
7 | 0633879f | pbrook | * modify it under the terms of the GNU Lesser General Public
|
8 | 0633879f | pbrook | * License as published by the Free Software Foundation; either
|
9 | 0633879f | pbrook | * version 2 of the License, or (at your option) any later version.
|
10 | 0633879f | pbrook | *
|
11 | 0633879f | pbrook | * This library is distributed in the hope that it will be useful,
|
12 | 0633879f | pbrook | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 0633879f | pbrook | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 0633879f | pbrook | * Lesser General Public License for more details.
|
15 | 0633879f | pbrook | *
|
16 | 0633879f | pbrook | * You should have received a copy of the GNU Lesser General Public
|
17 | 0633879f | pbrook | * License along with this library; if not, write to the Free Software
|
18 | 0633879f | pbrook | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 0633879f | pbrook | */
|
20 | 0633879f | pbrook | #include "exec.h" |
21 | e1f3808e | pbrook | #include "helpers.h" |
22 | 0633879f | pbrook | |
23 | 0633879f | pbrook | #if defined(CONFIG_USER_ONLY)
|
24 | 0633879f | pbrook | |
25 | 0633879f | pbrook | void do_interrupt(int is_hw) |
26 | 0633879f | pbrook | { |
27 | 0633879f | pbrook | env->exception_index = -1;
|
28 | 0633879f | pbrook | } |
29 | 0633879f | pbrook | |
30 | 0633879f | pbrook | #else
|
31 | 0633879f | pbrook | |
32 | a87295e8 | pbrook | extern int semihosting_enabled; |
33 | a87295e8 | pbrook | |
34 | 0633879f | pbrook | #define MMUSUFFIX _mmu
|
35 | 0633879f | pbrook | |
36 | 0633879f | pbrook | #define SHIFT 0 |
37 | 0633879f | pbrook | #include "softmmu_template.h" |
38 | 0633879f | pbrook | |
39 | 0633879f | pbrook | #define SHIFT 1 |
40 | 0633879f | pbrook | #include "softmmu_template.h" |
41 | 0633879f | pbrook | |
42 | 0633879f | pbrook | #define SHIFT 2 |
43 | 0633879f | pbrook | #include "softmmu_template.h" |
44 | 0633879f | pbrook | |
45 | 0633879f | pbrook | #define SHIFT 3 |
46 | 0633879f | pbrook | #include "softmmu_template.h" |
47 | 0633879f | pbrook | |
48 | 0633879f | pbrook | /* Try to fill the TLB and return an exception if error. If retaddr is
|
49 | 0633879f | pbrook | NULL, it means that the function was called in C code (i.e. not
|
50 | 0633879f | pbrook | from generated code or from helper.c) */
|
51 | 0633879f | pbrook | /* XXX: fix it to restore all registers */
|
52 | 6ebbf390 | j_mayer | void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr) |
53 | 0633879f | pbrook | { |
54 | 0633879f | pbrook | TranslationBlock *tb; |
55 | 0633879f | pbrook | CPUState *saved_env; |
56 | 44f8625d | bellard | unsigned long pc; |
57 | 0633879f | pbrook | int ret;
|
58 | 0633879f | pbrook | |
59 | 0633879f | pbrook | /* XXX: hack to restore env in all cases, even if not called from
|
60 | 0633879f | pbrook | generated code */
|
61 | 0633879f | pbrook | saved_env = env; |
62 | 0633879f | pbrook | env = cpu_single_env; |
63 | 6ebbf390 | j_mayer | ret = cpu_m68k_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
|
64 | 0633879f | pbrook | if (__builtin_expect(ret, 0)) { |
65 | 0633879f | pbrook | if (retaddr) {
|
66 | 0633879f | pbrook | /* now we have a real cpu fault */
|
67 | 44f8625d | bellard | pc = (unsigned long)retaddr; |
68 | 0633879f | pbrook | tb = tb_find_pc(pc); |
69 | 0633879f | pbrook | if (tb) {
|
70 | 0633879f | pbrook | /* the PC is inside the translated code. It means that we have
|
71 | 0633879f | pbrook | a virtual CPU fault */
|
72 | 0633879f | pbrook | cpu_restore_state(tb, env, pc, NULL);
|
73 | 0633879f | pbrook | } |
74 | 0633879f | pbrook | } |
75 | 0633879f | pbrook | cpu_loop_exit(); |
76 | 0633879f | pbrook | } |
77 | 0633879f | pbrook | env = saved_env; |
78 | 0633879f | pbrook | } |
79 | 0633879f | pbrook | |
80 | 0633879f | pbrook | static void do_rte(void) |
81 | 0633879f | pbrook | { |
82 | 0633879f | pbrook | uint32_t sp; |
83 | 0633879f | pbrook | uint32_t fmt; |
84 | 0633879f | pbrook | |
85 | 0633879f | pbrook | sp = env->aregs[7];
|
86 | 0633879f | pbrook | fmt = ldl_kernel(sp); |
87 | 0633879f | pbrook | env->pc = ldl_kernel(sp + 4);
|
88 | 0633879f | pbrook | sp |= (fmt >> 28) & 3; |
89 | 0633879f | pbrook | env->sr = fmt & 0xffff;
|
90 | 20dcee94 | pbrook | m68k_switch_sp(env); |
91 | 0633879f | pbrook | env->aregs[7] = sp + 8; |
92 | 0633879f | pbrook | } |
93 | 0633879f | pbrook | |
94 | 0633879f | pbrook | void do_interrupt(int is_hw) |
95 | 0633879f | pbrook | { |
96 | 0633879f | pbrook | uint32_t sp; |
97 | 0633879f | pbrook | uint32_t fmt; |
98 | 0633879f | pbrook | uint32_t retaddr; |
99 | 0633879f | pbrook | uint32_t vector; |
100 | 0633879f | pbrook | |
101 | 0633879f | pbrook | fmt = 0;
|
102 | 0633879f | pbrook | retaddr = env->pc; |
103 | 0633879f | pbrook | |
104 | 0633879f | pbrook | if (!is_hw) {
|
105 | 0633879f | pbrook | switch (env->exception_index) {
|
106 | 0633879f | pbrook | case EXCP_RTE:
|
107 | 0633879f | pbrook | /* Return from an exception. */
|
108 | 0633879f | pbrook | do_rte(); |
109 | 0633879f | pbrook | return;
|
110 | a87295e8 | pbrook | case EXCP_HALT_INSN:
|
111 | a87295e8 | pbrook | if (semihosting_enabled
|
112 | a87295e8 | pbrook | && (env->sr & SR_S) != 0
|
113 | a87295e8 | pbrook | && (env->pc & 3) == 0 |
114 | a87295e8 | pbrook | && lduw_code(env->pc - 4) == 0x4e71 |
115 | a87295e8 | pbrook | && ldl_code(env->pc) == 0x4e7bf000) {
|
116 | a87295e8 | pbrook | env->pc += 4;
|
117 | a87295e8 | pbrook | do_m68k_semihosting(env, env->dregs[0]);
|
118 | a87295e8 | pbrook | return;
|
119 | a87295e8 | pbrook | } |
120 | a87295e8 | pbrook | env->halted = 1;
|
121 | a87295e8 | pbrook | env->exception_index = EXCP_HLT; |
122 | a87295e8 | pbrook | cpu_loop_exit(); |
123 | a87295e8 | pbrook | return;
|
124 | 0633879f | pbrook | } |
125 | 0633879f | pbrook | if (env->exception_index >= EXCP_TRAP0
|
126 | 0633879f | pbrook | && env->exception_index <= EXCP_TRAP15) { |
127 | 0633879f | pbrook | /* Move the PC after the trap instruction. */
|
128 | 0633879f | pbrook | retaddr += 2;
|
129 | 0633879f | pbrook | } |
130 | 0633879f | pbrook | } |
131 | 0633879f | pbrook | |
132 | 0633879f | pbrook | vector = env->exception_index << 2;
|
133 | 0633879f | pbrook | |
134 | 0cf5c677 | pbrook | sp = env->aregs[7];
|
135 | 0cf5c677 | pbrook | |
136 | 0633879f | pbrook | fmt |= 0x40000000;
|
137 | 0633879f | pbrook | fmt |= (sp & 3) << 28; |
138 | 0633879f | pbrook | fmt |= vector << 16;
|
139 | 0633879f | pbrook | fmt |= env->sr; |
140 | 0633879f | pbrook | |
141 | 20dcee94 | pbrook | env->sr |= SR_S; |
142 | 20dcee94 | pbrook | if (is_hw) {
|
143 | 20dcee94 | pbrook | env->sr = (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT); |
144 | 20dcee94 | pbrook | env->sr &= ~SR_M; |
145 | 20dcee94 | pbrook | } |
146 | 20dcee94 | pbrook | m68k_switch_sp(env); |
147 | 20dcee94 | pbrook | |
148 | 0633879f | pbrook | /* ??? This could cause MMU faults. */
|
149 | 0633879f | pbrook | sp &= ~3;
|
150 | 0633879f | pbrook | sp -= 4;
|
151 | 0633879f | pbrook | stl_kernel(sp, retaddr); |
152 | 0633879f | pbrook | sp -= 4;
|
153 | 0633879f | pbrook | stl_kernel(sp, fmt); |
154 | 0633879f | pbrook | env->aregs[7] = sp;
|
155 | 0633879f | pbrook | /* Jump to vector. */
|
156 | 0633879f | pbrook | env->pc = ldl_kernel(env->vbr + vector); |
157 | 0633879f | pbrook | } |
158 | 0633879f | pbrook | |
159 | 0633879f | pbrook | #endif
|
160 | e1f3808e | pbrook | |
161 | e1f3808e | pbrook | static void raise_exception(int tt) |
162 | e1f3808e | pbrook | { |
163 | e1f3808e | pbrook | env->exception_index = tt; |
164 | e1f3808e | pbrook | cpu_loop_exit(); |
165 | e1f3808e | pbrook | } |
166 | e1f3808e | pbrook | |
167 | e1f3808e | pbrook | void HELPER(raise_exception)(uint32_t tt)
|
168 | e1f3808e | pbrook | { |
169 | e1f3808e | pbrook | raise_exception(tt); |
170 | e1f3808e | pbrook | } |
171 | e1f3808e | pbrook | |
172 | e1f3808e | pbrook | void HELPER(divu)(CPUState *env, uint32_t word)
|
173 | e1f3808e | pbrook | { |
174 | e1f3808e | pbrook | uint32_t num; |
175 | e1f3808e | pbrook | uint32_t den; |
176 | e1f3808e | pbrook | uint32_t quot; |
177 | e1f3808e | pbrook | uint32_t rem; |
178 | e1f3808e | pbrook | uint32_t flags; |
179 | e1f3808e | pbrook | |
180 | e1f3808e | pbrook | num = env->div1; |
181 | e1f3808e | pbrook | den = env->div2; |
182 | e1f3808e | pbrook | /* ??? This needs to make sure the throwing location is accurate. */
|
183 | e1f3808e | pbrook | if (den == 0) |
184 | e1f3808e | pbrook | raise_exception(EXCP_DIV0); |
185 | e1f3808e | pbrook | quot = num / den; |
186 | e1f3808e | pbrook | rem = num % den; |
187 | e1f3808e | pbrook | flags = 0;
|
188 | e1f3808e | pbrook | /* Avoid using a PARAM1 of zero. This breaks dyngen because it uses
|
189 | e1f3808e | pbrook | the address of a symbol, and gcc knows symbols can't have address
|
190 | e1f3808e | pbrook | zero. */
|
191 | e1f3808e | pbrook | if (word && quot > 0xffff) |
192 | e1f3808e | pbrook | flags |= CCF_V; |
193 | e1f3808e | pbrook | if (quot == 0) |
194 | e1f3808e | pbrook | flags |= CCF_Z; |
195 | e1f3808e | pbrook | else if ((int32_t)quot < 0) |
196 | e1f3808e | pbrook | flags |= CCF_N; |
197 | e1f3808e | pbrook | env->div1 = quot; |
198 | e1f3808e | pbrook | env->div2 = rem; |
199 | e1f3808e | pbrook | env->cc_dest = flags; |
200 | e1f3808e | pbrook | } |
201 | e1f3808e | pbrook | |
202 | e1f3808e | pbrook | void HELPER(divs)(CPUState *env, uint32_t word)
|
203 | e1f3808e | pbrook | { |
204 | e1f3808e | pbrook | int32_t num; |
205 | e1f3808e | pbrook | int32_t den; |
206 | e1f3808e | pbrook | int32_t quot; |
207 | e1f3808e | pbrook | int32_t rem; |
208 | e1f3808e | pbrook | int32_t flags; |
209 | e1f3808e | pbrook | |
210 | e1f3808e | pbrook | num = env->div1; |
211 | e1f3808e | pbrook | den = env->div2; |
212 | e1f3808e | pbrook | if (den == 0) |
213 | e1f3808e | pbrook | raise_exception(EXCP_DIV0); |
214 | e1f3808e | pbrook | quot = num / den; |
215 | e1f3808e | pbrook | rem = num % den; |
216 | e1f3808e | pbrook | flags = 0;
|
217 | e1f3808e | pbrook | if (word && quot != (int16_t)quot)
|
218 | e1f3808e | pbrook | flags |= CCF_V; |
219 | e1f3808e | pbrook | if (quot == 0) |
220 | e1f3808e | pbrook | flags |= CCF_Z; |
221 | e1f3808e | pbrook | else if (quot < 0) |
222 | e1f3808e | pbrook | flags |= CCF_N; |
223 | e1f3808e | pbrook | env->div1 = quot; |
224 | e1f3808e | pbrook | env->div2 = rem; |
225 | e1f3808e | pbrook | env->cc_dest = flags; |
226 | e1f3808e | pbrook | } |