]>
Commit | Line | Data |
---|---|---|
48e06fe0 BK |
1 | /* |
2 | * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | #include <stdlib.h> | |
18 | #include "cpu.h" | |
19 | #include "qemu/host-utils.h" | |
20 | #include "exec/helper-proto.h" | |
21 | #include "exec/cpu_ldst.h" | |
22 | ||
3a16ecb0 BK |
23 | /* Addressing mode helper */ |
24 | ||
25 | static uint16_t reverse16(uint16_t val) | |
26 | { | |
27 | uint8_t high = (uint8_t)(val >> 8); | |
28 | uint8_t low = (uint8_t)(val & 0xff); | |
29 | ||
30 | uint16_t rh, rl; | |
31 | ||
32 | rl = (uint16_t)((high * 0x0202020202ULL & 0x010884422010ULL) % 1023); | |
33 | rh = (uint16_t)((low * 0x0202020202ULL & 0x010884422010ULL) % 1023); | |
34 | ||
35 | return (rh << 8) | rl; | |
36 | } | |
37 | ||
38 | uint32_t helper_br_update(uint32_t reg) | |
39 | { | |
40 | uint32_t index = reg & 0xffff; | |
41 | uint32_t incr = reg >> 16; | |
42 | uint32_t new_index = reverse16(reverse16(index) + reverse16(incr)); | |
43 | return reg - index + new_index; | |
44 | } | |
45 | ||
46 | uint32_t helper_circ_update(uint32_t reg, uint32_t off) | |
47 | { | |
48 | uint32_t index = reg & 0xffff; | |
49 | uint32_t length = reg >> 16; | |
50 | int32_t new_index = index + off; | |
51 | if (new_index < 0) { | |
52 | new_index += length; | |
53 | } else { | |
54 | new_index %= length; | |
55 | } | |
56 | return reg - index + new_index; | |
57 | } | |
58 | ||
e4e39176 BK |
59 | static uint32_t ssov32(CPUTriCoreState *env, int64_t arg) |
60 | { | |
61 | uint32_t ret; | |
62 | int64_t max_pos = INT32_MAX; | |
63 | int64_t max_neg = INT32_MIN; | |
64 | if (arg > max_pos) { | |
65 | env->PSW_USB_V = (1 << 31); | |
66 | env->PSW_USB_SV = (1 << 31); | |
67 | ret = (target_ulong)max_pos; | |
68 | } else { | |
69 | if (arg < max_neg) { | |
70 | env->PSW_USB_V = (1 << 31); | |
71 | env->PSW_USB_SV = (1 << 31); | |
72 | ret = (target_ulong)max_neg; | |
73 | } else { | |
74 | env->PSW_USB_V = 0; | |
75 | ret = (target_ulong)arg; | |
76 | } | |
77 | } | |
78 | env->PSW_USB_AV = arg ^ arg * 2u; | |
79 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
80 | return ret; | |
81 | } | |
82 | ||
85d604af | 83 | static uint32_t suov32_pos(CPUTriCoreState *env, uint64_t arg) |
e4e39176 BK |
84 | { |
85 | uint32_t ret; | |
85d604af | 86 | uint64_t max_pos = UINT32_MAX; |
e4e39176 BK |
87 | if (arg > max_pos) { |
88 | env->PSW_USB_V = (1 << 31); | |
89 | env->PSW_USB_SV = (1 << 31); | |
90 | ret = (target_ulong)max_pos; | |
91 | } else { | |
85d604af BK |
92 | env->PSW_USB_V = 0; |
93 | ret = (target_ulong)arg; | |
e4e39176 BK |
94 | } |
95 | env->PSW_USB_AV = arg ^ arg * 2u; | |
96 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
97 | return ret; | |
98 | } | |
0974257e | 99 | |
85d604af BK |
100 | static uint32_t suov32_neg(CPUTriCoreState *env, int64_t arg) |
101 | { | |
102 | uint32_t ret; | |
103 | ||
104 | if (arg < 0) { | |
105 | env->PSW_USB_V = (1 << 31); | |
106 | env->PSW_USB_SV = (1 << 31); | |
107 | ret = 0; | |
108 | } else { | |
109 | env->PSW_USB_V = 0; | |
110 | ret = (target_ulong)arg; | |
111 | } | |
112 | env->PSW_USB_AV = arg ^ arg * 2u; | |
113 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
114 | return ret; | |
115 | } | |
116 | ||
d5de7839 BK |
117 | static uint32_t ssov16(CPUTriCoreState *env, int32_t hw0, int32_t hw1) |
118 | { | |
119 | int32_t max_pos = INT16_MAX; | |
120 | int32_t max_neg = INT16_MIN; | |
121 | int32_t av0, av1; | |
122 | ||
123 | env->PSW_USB_V = 0; | |
124 | av0 = hw0 ^ hw0 * 2u; | |
125 | if (hw0 > max_pos) { | |
126 | env->PSW_USB_V = (1 << 31); | |
127 | hw0 = max_pos; | |
128 | } else if (hw0 < max_neg) { | |
129 | env->PSW_USB_V = (1 << 31); | |
130 | hw0 = max_neg; | |
131 | } | |
132 | ||
133 | av1 = hw1 ^ hw1 * 2u; | |
134 | if (hw1 > max_pos) { | |
135 | env->PSW_USB_V = (1 << 31); | |
136 | hw1 = max_pos; | |
137 | } else if (hw1 < max_neg) { | |
138 | env->PSW_USB_V = (1 << 31); | |
139 | hw1 = max_neg; | |
140 | } | |
141 | ||
142 | env->PSW_USB_SV |= env->PSW_USB_V; | |
143 | env->PSW_USB_AV = (av0 | av1) << 16; | |
144 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
145 | return (hw0 & 0xffff) | (hw1 << 16); | |
146 | } | |
147 | ||
148 | static uint32_t suov16(CPUTriCoreState *env, int32_t hw0, int32_t hw1) | |
149 | { | |
150 | int32_t max_pos = UINT16_MAX; | |
151 | int32_t av0, av1; | |
152 | ||
153 | env->PSW_USB_V = 0; | |
154 | av0 = hw0 ^ hw0 * 2u; | |
155 | if (hw0 > max_pos) { | |
156 | env->PSW_USB_V = (1 << 31); | |
157 | hw0 = max_pos; | |
158 | } else if (hw0 < 0) { | |
159 | env->PSW_USB_V = (1 << 31); | |
160 | hw0 = 0; | |
161 | } | |
162 | ||
163 | av1 = hw1 ^ hw1 * 2u; | |
164 | if (hw1 > max_pos) { | |
165 | env->PSW_USB_V = (1 << 31); | |
166 | hw1 = max_pos; | |
167 | } else if (hw1 < 0) { | |
168 | env->PSW_USB_V = (1 << 31); | |
169 | hw1 = 0; | |
170 | } | |
171 | ||
172 | env->PSW_USB_SV |= env->PSW_USB_V; | |
173 | env->PSW_USB_AV = (av0 | av1) << 16; | |
174 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
175 | return (hw0 & 0xffff) | (hw1 << 16); | |
176 | } | |
0974257e | 177 | |
2692802a BK |
178 | target_ulong helper_add_ssov(CPUTriCoreState *env, target_ulong r1, |
179 | target_ulong r2) | |
180 | { | |
2692802a BK |
181 | int64_t t1 = sextract64(r1, 0, 32); |
182 | int64_t t2 = sextract64(r2, 0, 32); | |
183 | int64_t result = t1 + t2; | |
e4e39176 | 184 | return ssov32(env, result); |
2692802a BK |
185 | } |
186 | ||
d5de7839 BK |
187 | target_ulong helper_add_h_ssov(CPUTriCoreState *env, target_ulong r1, |
188 | target_ulong r2) | |
189 | { | |
190 | int32_t ret_hw0, ret_hw1; | |
191 | ||
192 | ret_hw0 = sextract32(r1, 0, 16) + sextract32(r2, 0, 16); | |
193 | ret_hw1 = sextract32(r1, 16, 16) + sextract32(r2, 16, 16); | |
194 | return ssov16(env, ret_hw0, ret_hw1); | |
195 | } | |
196 | ||
0974257e BK |
197 | target_ulong helper_add_suov(CPUTriCoreState *env, target_ulong r1, |
198 | target_ulong r2) | |
199 | { | |
0974257e BK |
200 | int64_t t1 = extract64(r1, 0, 32); |
201 | int64_t t2 = extract64(r2, 0, 32); | |
202 | int64_t result = t1 + t2; | |
85d604af | 203 | return suov32_pos(env, result); |
0974257e BK |
204 | } |
205 | ||
d5de7839 BK |
206 | target_ulong helper_add_h_suov(CPUTriCoreState *env, target_ulong r1, |
207 | target_ulong r2) | |
208 | { | |
209 | int32_t ret_hw0, ret_hw1; | |
210 | ||
211 | ret_hw0 = extract32(r1, 0, 16) + extract32(r2, 0, 16); | |
212 | ret_hw1 = extract32(r1, 16, 16) + extract32(r2, 16, 16); | |
213 | return suov16(env, ret_hw0, ret_hw1); | |
214 | } | |
215 | ||
2692802a BK |
216 | target_ulong helper_sub_ssov(CPUTriCoreState *env, target_ulong r1, |
217 | target_ulong r2) | |
218 | { | |
2692802a BK |
219 | int64_t t1 = sextract64(r1, 0, 32); |
220 | int64_t t2 = sextract64(r2, 0, 32); | |
221 | int64_t result = t1 - t2; | |
e4e39176 | 222 | return ssov32(env, result); |
2692802a BK |
223 | } |
224 | ||
d5de7839 BK |
225 | target_ulong helper_sub_h_ssov(CPUTriCoreState *env, target_ulong r1, |
226 | target_ulong r2) | |
227 | { | |
228 | int32_t ret_hw0, ret_hw1; | |
229 | ||
230 | ret_hw0 = sextract32(r1, 0, 16) - sextract32(r2, 0, 16); | |
231 | ret_hw1 = sextract32(r1, 16, 16) - sextract32(r2, 16, 16); | |
232 | return ssov16(env, ret_hw0, ret_hw1); | |
233 | } | |
234 | ||
0974257e BK |
235 | target_ulong helper_sub_suov(CPUTriCoreState *env, target_ulong r1, |
236 | target_ulong r2) | |
237 | { | |
0974257e BK |
238 | int64_t t1 = extract64(r1, 0, 32); |
239 | int64_t t2 = extract64(r2, 0, 32); | |
240 | int64_t result = t1 - t2; | |
85d604af | 241 | return suov32_neg(env, result); |
0974257e BK |
242 | } |
243 | ||
d5de7839 BK |
244 | target_ulong helper_sub_h_suov(CPUTriCoreState *env, target_ulong r1, |
245 | target_ulong r2) | |
246 | { | |
247 | int32_t ret_hw0, ret_hw1; | |
248 | ||
249 | ret_hw0 = extract32(r1, 0, 16) - extract32(r2, 0, 16); | |
250 | ret_hw1 = extract32(r1, 16, 16) - extract32(r2, 16, 16); | |
251 | return suov16(env, ret_hw0, ret_hw1); | |
252 | } | |
253 | ||
0974257e BK |
254 | target_ulong helper_mul_ssov(CPUTriCoreState *env, target_ulong r1, |
255 | target_ulong r2) | |
256 | { | |
0974257e BK |
257 | int64_t t1 = sextract64(r1, 0, 32); |
258 | int64_t t2 = sextract64(r2, 0, 32); | |
259 | int64_t result = t1 * t2; | |
e4e39176 | 260 | return ssov32(env, result); |
0974257e BK |
261 | } |
262 | ||
263 | target_ulong helper_mul_suov(CPUTriCoreState *env, target_ulong r1, | |
264 | target_ulong r2) | |
265 | { | |
0974257e BK |
266 | int64_t t1 = extract64(r1, 0, 32); |
267 | int64_t t2 = extract64(r2, 0, 32); | |
268 | int64_t result = t1 * t2; | |
5f30046f | 269 | |
85d604af | 270 | return suov32_pos(env, result); |
0974257e BK |
271 | } |
272 | ||
273 | target_ulong helper_sha_ssov(CPUTriCoreState *env, target_ulong r1, | |
274 | target_ulong r2) | |
275 | { | |
0974257e BK |
276 | int64_t t1 = sextract64(r1, 0, 32); |
277 | int32_t t2 = sextract64(r2, 0, 6); | |
278 | int64_t result; | |
279 | if (t2 == 0) { | |
280 | result = t1; | |
281 | } else if (t2 > 0) { | |
282 | result = t1 << t2; | |
283 | } else { | |
284 | result = t1 >> -t2; | |
285 | } | |
e4e39176 | 286 | return ssov32(env, result); |
0974257e BK |
287 | } |
288 | ||
d5de7839 BK |
289 | uint32_t helper_abs_ssov(CPUTriCoreState *env, target_ulong r1) |
290 | { | |
291 | target_ulong result; | |
292 | result = ((int32_t)r1 >= 0) ? r1 : (0 - r1); | |
293 | return ssov32(env, result); | |
294 | } | |
295 | ||
296 | uint32_t helper_abs_h_ssov(CPUTriCoreState *env, target_ulong r1) | |
297 | { | |
298 | int32_t ret_h0, ret_h1; | |
299 | ||
300 | ret_h0 = sextract32(r1, 0, 16); | |
301 | ret_h0 = (ret_h0 >= 0) ? ret_h0 : (0 - ret_h0); | |
302 | ||
303 | ret_h1 = sextract32(r1, 16, 16); | |
304 | ret_h1 = (ret_h1 >= 0) ? ret_h1 : (0 - ret_h1); | |
305 | ||
306 | return ssov16(env, ret_h0, ret_h1); | |
307 | } | |
308 | ||
0974257e BK |
309 | target_ulong helper_absdif_ssov(CPUTriCoreState *env, target_ulong r1, |
310 | target_ulong r2) | |
311 | { | |
0974257e BK |
312 | int64_t t1 = sextract64(r1, 0, 32); |
313 | int64_t t2 = sextract64(r2, 0, 32); | |
314 | int64_t result; | |
315 | ||
316 | if (t1 > t2) { | |
317 | result = t1 - t2; | |
318 | } else { | |
319 | result = t2 - t1; | |
320 | } | |
e4e39176 | 321 | return ssov32(env, result); |
0974257e | 322 | } |
328f1f0f | 323 | |
d5de7839 BK |
324 | uint32_t helper_absdif_h_ssov(CPUTriCoreState *env, target_ulong r1, |
325 | target_ulong r2) | |
326 | { | |
327 | int32_t t1, t2; | |
328 | int32_t ret_h0, ret_h1; | |
329 | ||
330 | t1 = sextract32(r1, 0, 16); | |
331 | t2 = sextract32(r2, 0, 16); | |
332 | if (t1 > t2) { | |
333 | ret_h0 = t1 - t2; | |
334 | } else { | |
335 | ret_h0 = t2 - t1; | |
336 | } | |
337 | ||
338 | t1 = sextract32(r1, 16, 16); | |
339 | t2 = sextract32(r2, 16, 16); | |
340 | if (t1 > t2) { | |
341 | ret_h1 = t1 - t2; | |
342 | } else { | |
343 | ret_h1 = t2 - t1; | |
344 | } | |
345 | ||
346 | return ssov16(env, ret_h0, ret_h1); | |
347 | } | |
348 | ||
328f1f0f BK |
349 | target_ulong helper_madd32_ssov(CPUTriCoreState *env, target_ulong r1, |
350 | target_ulong r2, target_ulong r3) | |
351 | { | |
328f1f0f BK |
352 | int64_t t1 = sextract64(r1, 0, 32); |
353 | int64_t t2 = sextract64(r2, 0, 32); | |
354 | int64_t t3 = sextract64(r3, 0, 32); | |
355 | int64_t result; | |
356 | ||
357 | result = t2 + (t1 * t3); | |
e4e39176 | 358 | return ssov32(env, result); |
328f1f0f BK |
359 | } |
360 | ||
361 | target_ulong helper_madd32_suov(CPUTriCoreState *env, target_ulong r1, | |
362 | target_ulong r2, target_ulong r3) | |
363 | { | |
328f1f0f BK |
364 | uint64_t t1 = extract64(r1, 0, 32); |
365 | uint64_t t2 = extract64(r2, 0, 32); | |
366 | uint64_t t3 = extract64(r3, 0, 32); | |
367 | int64_t result; | |
368 | ||
369 | result = t2 + (t1 * t3); | |
85d604af | 370 | return suov32_pos(env, result); |
328f1f0f BK |
371 | } |
372 | ||
373 | uint64_t helper_madd64_ssov(CPUTriCoreState *env, target_ulong r1, | |
374 | uint64_t r2, target_ulong r3) | |
375 | { | |
376 | uint64_t ret, ovf; | |
377 | int64_t t1 = sextract64(r1, 0, 32); | |
378 | int64_t t3 = sextract64(r3, 0, 32); | |
379 | int64_t mul; | |
380 | ||
381 | mul = t1 * t3; | |
382 | ret = mul + r2; | |
383 | ovf = (ret ^ mul) & ~(mul ^ r2); | |
384 | ||
811ea608 BK |
385 | t1 = ret >> 32; |
386 | env->PSW_USB_AV = t1 ^ t1 * 2u; | |
387 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
388 | ||
328f1f0f BK |
389 | if ((int64_t)ovf < 0) { |
390 | env->PSW_USB_V = (1 << 31); | |
391 | env->PSW_USB_SV = (1 << 31); | |
392 | /* ext_ret > MAX_INT */ | |
393 | if (mul >= 0) { | |
394 | ret = INT64_MAX; | |
395 | /* ext_ret < MIN_INT */ | |
396 | } else { | |
397 | ret = INT64_MIN; | |
398 | } | |
399 | } else { | |
400 | env->PSW_USB_V = 0; | |
401 | } | |
328f1f0f BK |
402 | |
403 | return ret; | |
404 | } | |
405 | ||
406 | uint64_t helper_madd64_suov(CPUTriCoreState *env, target_ulong r1, | |
407 | uint64_t r2, target_ulong r3) | |
408 | { | |
409 | uint64_t ret, mul; | |
410 | uint64_t t1 = extract64(r1, 0, 32); | |
411 | uint64_t t3 = extract64(r3, 0, 32); | |
412 | ||
413 | mul = t1 * t3; | |
414 | ret = mul + r2; | |
415 | ||
811ea608 BK |
416 | t1 = ret >> 32; |
417 | env->PSW_USB_AV = t1 ^ t1 * 2u; | |
418 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
419 | ||
328f1f0f BK |
420 | if (ret < r2) { |
421 | env->PSW_USB_V = (1 << 31); | |
422 | env->PSW_USB_SV = (1 << 31); | |
423 | /* saturate */ | |
424 | ret = UINT64_MAX; | |
425 | } else { | |
426 | env->PSW_USB_V = 0; | |
427 | } | |
328f1f0f BK |
428 | return ret; |
429 | } | |
430 | ||
431 | target_ulong helper_msub32_ssov(CPUTriCoreState *env, target_ulong r1, | |
432 | target_ulong r2, target_ulong r3) | |
433 | { | |
328f1f0f BK |
434 | int64_t t1 = sextract64(r1, 0, 32); |
435 | int64_t t2 = sextract64(r2, 0, 32); | |
436 | int64_t t3 = sextract64(r3, 0, 32); | |
437 | int64_t result; | |
438 | ||
439 | result = t2 - (t1 * t3); | |
e4e39176 | 440 | return ssov32(env, result); |
328f1f0f BK |
441 | } |
442 | ||
443 | target_ulong helper_msub32_suov(CPUTriCoreState *env, target_ulong r1, | |
444 | target_ulong r2, target_ulong r3) | |
445 | { | |
328f1f0f BK |
446 | int64_t t1 = extract64(r1, 0, 32); |
447 | int64_t t2 = extract64(r2, 0, 32); | |
448 | int64_t t3 = extract64(r3, 0, 32); | |
449 | int64_t result; | |
450 | ||
451 | result = t2 - (t1 * t3); | |
85d604af | 452 | return suov32_neg(env, result); |
328f1f0f BK |
453 | } |
454 | ||
455 | uint64_t helper_msub64_ssov(CPUTriCoreState *env, target_ulong r1, | |
456 | uint64_t r2, target_ulong r3) | |
457 | { | |
458 | uint64_t ret, ovf; | |
459 | int64_t t1 = sextract64(r1, 0, 32); | |
460 | int64_t t3 = sextract64(r3, 0, 32); | |
461 | int64_t mul; | |
462 | ||
463 | mul = t1 * t3; | |
464 | ret = r2 - mul; | |
465 | ovf = (ret ^ r2) & (mul ^ r2); | |
466 | ||
811ea608 BK |
467 | t1 = ret >> 32; |
468 | env->PSW_USB_AV = t1 ^ t1 * 2u; | |
469 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
470 | ||
328f1f0f BK |
471 | if ((int64_t)ovf < 0) { |
472 | env->PSW_USB_V = (1 << 31); | |
473 | env->PSW_USB_SV = (1 << 31); | |
474 | /* ext_ret > MAX_INT */ | |
475 | if (mul < 0) { | |
476 | ret = INT64_MAX; | |
477 | /* ext_ret < MIN_INT */ | |
478 | } else { | |
479 | ret = INT64_MIN; | |
480 | } | |
481 | } else { | |
482 | env->PSW_USB_V = 0; | |
483 | } | |
328f1f0f BK |
484 | return ret; |
485 | } | |
486 | ||
487 | uint64_t helper_msub64_suov(CPUTriCoreState *env, target_ulong r1, | |
488 | uint64_t r2, target_ulong r3) | |
489 | { | |
490 | uint64_t ret, mul; | |
491 | uint64_t t1 = extract64(r1, 0, 32); | |
492 | uint64_t t3 = extract64(r3, 0, 32); | |
493 | ||
494 | mul = t1 * t3; | |
495 | ret = r2 - mul; | |
496 | ||
811ea608 BK |
497 | t1 = ret >> 32; |
498 | env->PSW_USB_AV = t1 ^ t1 * 2u; | |
499 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
500 | ||
328f1f0f BK |
501 | if (ret > r2) { |
502 | env->PSW_USB_V = (1 << 31); | |
503 | env->PSW_USB_SV = (1 << 31); | |
504 | /* saturate */ | |
505 | ret = 0; | |
506 | } else { | |
507 | env->PSW_USB_V = 0; | |
508 | } | |
328f1f0f BK |
509 | return ret; |
510 | } | |
511 | ||
d5de7839 BK |
512 | uint32_t helper_abs_b(CPUTriCoreState *env, target_ulong arg) |
513 | { | |
514 | int32_t b, i; | |
515 | int32_t ovf = 0; | |
516 | int32_t avf = 0; | |
517 | int32_t ret = 0; | |
518 | ||
519 | for (i = 0; i < 4; i++) { | |
520 | b = sextract32(arg, i * 8, 8); | |
521 | b = (b >= 0) ? b : (0 - b); | |
522 | ovf |= (b > 0x7F) || (b < -0x80); | |
523 | avf |= b ^ b * 2u; | |
524 | ret |= (b & 0xff) << (i * 8); | |
525 | } | |
526 | ||
527 | env->PSW_USB_V = ovf << 31; | |
528 | env->PSW_USB_SV |= env->PSW_USB_V; | |
529 | env->PSW_USB_AV = avf << 24; | |
530 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
531 | ||
532 | return ret; | |
533 | } | |
534 | ||
535 | uint32_t helper_abs_h(CPUTriCoreState *env, target_ulong arg) | |
536 | { | |
537 | int32_t h, i; | |
538 | int32_t ovf = 0; | |
539 | int32_t avf = 0; | |
540 | int32_t ret = 0; | |
541 | ||
542 | for (i = 0; i < 2; i++) { | |
543 | h = sextract32(arg, i * 16, 16); | |
544 | h = (h >= 0) ? h : (0 - h); | |
545 | ovf |= (h > 0x7FFF) || (h < -0x8000); | |
546 | avf |= h ^ h * 2u; | |
547 | ret |= (h & 0xffff) << (i * 16); | |
548 | } | |
549 | ||
550 | env->PSW_USB_V = ovf << 31; | |
551 | env->PSW_USB_SV |= env->PSW_USB_V; | |
552 | env->PSW_USB_AV = avf << 16; | |
553 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
554 | ||
555 | return ret; | |
556 | } | |
557 | ||
558 | uint32_t helper_absdif_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
559 | { | |
560 | int32_t b, i; | |
561 | int32_t extr_r2; | |
562 | int32_t ovf = 0; | |
563 | int32_t avf = 0; | |
564 | int32_t ret = 0; | |
565 | ||
566 | for (i = 0; i < 4; i++) { | |
567 | extr_r2 = sextract32(r2, i * 8, 8); | |
568 | b = sextract32(r1, i * 8, 8); | |
569 | b = (b > extr_r2) ? (b - extr_r2) : (extr_r2 - b); | |
570 | ovf |= (b > 0x7F) || (b < -0x80); | |
571 | avf |= b ^ b * 2u; | |
572 | ret |= (b & 0xff) << (i * 8); | |
573 | } | |
574 | ||
575 | env->PSW_USB_V = ovf << 31; | |
576 | env->PSW_USB_SV |= env->PSW_USB_V; | |
577 | env->PSW_USB_AV = avf << 24; | |
578 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
579 | return ret; | |
580 | } | |
581 | ||
582 | uint32_t helper_absdif_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
583 | { | |
584 | int32_t h, i; | |
585 | int32_t extr_r2; | |
586 | int32_t ovf = 0; | |
587 | int32_t avf = 0; | |
588 | int32_t ret = 0; | |
589 | ||
590 | for (i = 0; i < 2; i++) { | |
591 | extr_r2 = sextract32(r2, i * 16, 16); | |
592 | h = sextract32(r1, i * 16, 16); | |
593 | h = (h > extr_r2) ? (h - extr_r2) : (extr_r2 - h); | |
594 | ovf |= (h > 0x7FFF) || (h < -0x8000); | |
595 | avf |= h ^ h * 2u; | |
596 | ret |= (h & 0xffff) << (i * 16); | |
597 | } | |
598 | ||
599 | env->PSW_USB_V = ovf << 31; | |
600 | env->PSW_USB_SV |= env->PSW_USB_V; | |
601 | env->PSW_USB_AV = avf << 16; | |
602 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
603 | ||
604 | return ret; | |
605 | } | |
606 | ||
607 | uint32_t helper_add_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
608 | { | |
609 | int32_t b, i; | |
610 | int32_t extr_r1, extr_r2; | |
611 | int32_t ovf = 0; | |
612 | int32_t avf = 0; | |
613 | uint32_t ret = 0; | |
614 | ||
615 | for (i = 0; i < 4; i++) { | |
616 | extr_r1 = sextract32(r1, i * 8, 8); | |
617 | extr_r2 = sextract32(r2, i * 8, 8); | |
618 | ||
619 | b = extr_r1 + extr_r2; | |
620 | ovf |= ((b > 0x7f) || (b < -0x80)); | |
621 | avf |= b ^ b * 2u; | |
622 | ret |= ((b & 0xff) << (i*8)); | |
623 | } | |
624 | ||
625 | env->PSW_USB_V = (ovf << 31); | |
626 | env->PSW_USB_SV |= env->PSW_USB_V; | |
627 | env->PSW_USB_AV = avf << 24; | |
628 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
629 | ||
630 | return ret; | |
631 | } | |
632 | ||
633 | uint32_t helper_add_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
634 | { | |
635 | int32_t h, i; | |
636 | int32_t extr_r1, extr_r2; | |
637 | int32_t ovf = 0; | |
638 | int32_t avf = 0; | |
639 | int32_t ret = 0; | |
640 | ||
641 | for (i = 0; i < 2; i++) { | |
642 | extr_r1 = sextract32(r1, i * 16, 16); | |
643 | extr_r2 = sextract32(r2, i * 16, 16); | |
644 | h = extr_r1 + extr_r2; | |
645 | ovf |= ((h > 0x7fff) || (h < -0x8000)); | |
646 | avf |= h ^ h * 2u; | |
647 | ret |= (h & 0xffff) << (i * 16); | |
648 | } | |
649 | ||
650 | env->PSW_USB_V = (ovf << 31); | |
651 | env->PSW_USB_SV |= env->PSW_USB_V; | |
652 | env->PSW_USB_AV = (avf << 16); | |
653 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
654 | ||
655 | return ret; | |
656 | } | |
657 | ||
658 | uint32_t helper_sub_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
659 | { | |
660 | int32_t b, i; | |
661 | int32_t extr_r1, extr_r2; | |
662 | int32_t ovf = 0; | |
663 | int32_t avf = 0; | |
664 | uint32_t ret = 0; | |
665 | ||
666 | for (i = 0; i < 4; i++) { | |
667 | extr_r1 = sextract32(r1, i * 8, 8); | |
668 | extr_r2 = sextract32(r2, i * 8, 8); | |
669 | ||
670 | b = extr_r1 - extr_r2; | |
671 | ovf |= ((b > 0x7f) || (b < -0x80)); | |
672 | avf |= b ^ b * 2u; | |
673 | ret |= ((b & 0xff) << (i*8)); | |
674 | } | |
675 | ||
676 | env->PSW_USB_V = (ovf << 31); | |
677 | env->PSW_USB_SV |= env->PSW_USB_V; | |
678 | env->PSW_USB_AV = avf << 24; | |
679 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
680 | ||
681 | return ret; | |
682 | } | |
683 | ||
684 | uint32_t helper_sub_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
685 | { | |
686 | int32_t h, i; | |
687 | int32_t extr_r1, extr_r2; | |
688 | int32_t ovf = 0; | |
689 | int32_t avf = 0; | |
690 | int32_t ret = 0; | |
691 | ||
692 | for (i = 0; i < 2; i++) { | |
693 | extr_r1 = sextract32(r1, i * 16, 16); | |
694 | extr_r2 = sextract32(r2, i * 16, 16); | |
695 | h = extr_r1 - extr_r2; | |
696 | ovf |= ((h > 0x7fff) || (h < -0x8000)); | |
697 | avf |= h ^ h * 2u; | |
698 | ret |= (h & 0xffff) << (i * 16); | |
699 | } | |
700 | ||
701 | env->PSW_USB_V = (ovf << 31); | |
702 | env->PSW_USB_SV |= env->PSW_USB_V; | |
703 | env->PSW_USB_AV = avf << 16; | |
704 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
705 | ||
706 | return ret; | |
707 | } | |
708 | ||
709 | uint32_t helper_eq_b(target_ulong r1, target_ulong r2) | |
710 | { | |
711 | int32_t ret; | |
712 | int32_t i, msk; | |
713 | ||
714 | ret = 0; | |
715 | msk = 0xff; | |
716 | for (i = 0; i < 4; i++) { | |
717 | if ((r1 & msk) == (r2 & msk)) { | |
718 | ret |= msk; | |
719 | } | |
720 | msk = msk << 8; | |
721 | } | |
722 | ||
723 | return ret; | |
724 | } | |
725 | ||
726 | uint32_t helper_eq_h(target_ulong r1, target_ulong r2) | |
727 | { | |
728 | int32_t ret = 0; | |
729 | ||
730 | if ((r1 & 0xffff) == (r2 & 0xffff)) { | |
731 | ret = 0xffff; | |
732 | } | |
733 | ||
734 | if ((r1 & 0xffff0000) == (r2 & 0xffff0000)) { | |
735 | ret |= 0xffff0000; | |
736 | } | |
737 | ||
738 | return ret; | |
739 | } | |
740 | ||
741 | uint32_t helper_eqany_b(target_ulong r1, target_ulong r2) | |
742 | { | |
743 | int32_t i; | |
744 | uint32_t ret = 0; | |
745 | ||
746 | for (i = 0; i < 4; i++) { | |
747 | ret |= (sextract32(r1, i * 8, 8) == sextract32(r2, i * 8, 8)); | |
748 | } | |
749 | ||
750 | return ret; | |
751 | } | |
752 | ||
753 | uint32_t helper_eqany_h(target_ulong r1, target_ulong r2) | |
754 | { | |
755 | uint32_t ret; | |
756 | ||
757 | ret = (sextract32(r1, 0, 16) == sextract32(r2, 0, 16)); | |
758 | ret |= (sextract32(r1, 16, 16) == sextract32(r2, 16, 16)); | |
759 | ||
760 | return ret; | |
761 | } | |
762 | ||
763 | uint32_t helper_lt_b(target_ulong r1, target_ulong r2) | |
764 | { | |
765 | int32_t i; | |
766 | uint32_t ret = 0; | |
767 | ||
768 | for (i = 0; i < 4; i++) { | |
769 | if (sextract32(r1, i * 8, 8) < sextract32(r2, i * 8, 8)) { | |
770 | ret |= (0xff << (i * 8)); | |
771 | } | |
772 | } | |
773 | ||
774 | return ret; | |
775 | } | |
776 | ||
777 | uint32_t helper_lt_bu(target_ulong r1, target_ulong r2) | |
778 | { | |
779 | int32_t i; | |
780 | uint32_t ret = 0; | |
781 | ||
782 | for (i = 0; i < 4; i++) { | |
783 | if (extract32(r1, i * 8, 8) < extract32(r2, i * 8, 8)) { | |
784 | ret |= (0xff << (i * 8)); | |
785 | } | |
786 | } | |
787 | ||
788 | return ret; | |
789 | } | |
790 | ||
791 | uint32_t helper_lt_h(target_ulong r1, target_ulong r2) | |
792 | { | |
793 | uint32_t ret = 0; | |
794 | ||
795 | if (sextract32(r1, 0, 16) < sextract32(r2, 0, 16)) { | |
796 | ret |= 0xffff; | |
797 | } | |
798 | ||
799 | if (sextract32(r1, 16, 16) < sextract32(r2, 16, 16)) { | |
800 | ret |= 0xffff0000; | |
801 | } | |
802 | ||
803 | return ret; | |
804 | } | |
805 | ||
806 | uint32_t helper_lt_hu(target_ulong r1, target_ulong r2) | |
807 | { | |
808 | uint32_t ret = 0; | |
809 | ||
810 | if (extract32(r1, 0, 16) < extract32(r2, 0, 16)) { | |
811 | ret |= 0xffff; | |
812 | } | |
813 | ||
814 | if (extract32(r1, 16, 16) < extract32(r2, 16, 16)) { | |
815 | ret |= 0xffff0000; | |
816 | } | |
817 | ||
818 | return ret; | |
819 | } | |
820 | ||
821 | #define EXTREMA_H_B(name, op) \ | |
822 | uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \ | |
823 | { \ | |
824 | int32_t i, extr_r1, extr_r2; \ | |
825 | uint32_t ret = 0; \ | |
826 | \ | |
827 | for (i = 0; i < 4; i++) { \ | |
828 | extr_r1 = sextract32(r1, i * 8, 8); \ | |
829 | extr_r2 = sextract32(r2, i * 8, 8); \ | |
830 | extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
831 | ret |= (extr_r1 & 0xff) << (i * 8); \ | |
832 | } \ | |
833 | return ret; \ | |
834 | } \ | |
835 | \ | |
836 | uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\ | |
837 | { \ | |
838 | int32_t i; \ | |
839 | uint32_t extr_r1, extr_r2; \ | |
840 | uint32_t ret = 0; \ | |
841 | \ | |
842 | for (i = 0; i < 4; i++) { \ | |
843 | extr_r1 = extract32(r1, i * 8, 8); \ | |
844 | extr_r2 = extract32(r2, i * 8, 8); \ | |
845 | extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
846 | ret |= (extr_r1 & 0xff) << (i * 8); \ | |
847 | } \ | |
848 | return ret; \ | |
849 | } \ | |
850 | \ | |
851 | uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \ | |
852 | { \ | |
853 | int32_t extr_r1, extr_r2; \ | |
854 | uint32_t ret = 0; \ | |
855 | \ | |
856 | extr_r1 = sextract32(r1, 0, 16); \ | |
857 | extr_r2 = sextract32(r2, 0, 16); \ | |
858 | ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
859 | ret = ret & 0xffff; \ | |
860 | \ | |
861 | extr_r1 = sextract32(r1, 16, 16); \ | |
862 | extr_r2 = sextract32(r2, 16, 16); \ | |
863 | extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
864 | ret |= extr_r1 << 16; \ | |
865 | \ | |
866 | return ret; \ | |
867 | } \ | |
868 | \ | |
869 | uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\ | |
870 | { \ | |
871 | uint32_t extr_r1, extr_r2; \ | |
872 | uint32_t ret = 0; \ | |
873 | \ | |
874 | extr_r1 = extract32(r1, 0, 16); \ | |
875 | extr_r2 = extract32(r2, 0, 16); \ | |
876 | ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
877 | ret = ret & 0xffff; \ | |
878 | \ | |
879 | extr_r1 = extract32(r1, 16, 16); \ | |
880 | extr_r2 = extract32(r2, 16, 16); \ | |
881 | extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \ | |
882 | ret |= extr_r1 << (16); \ | |
883 | \ | |
884 | return ret; \ | |
885 | } \ | |
09532255 BK |
886 | \ |
887 | uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \ | |
888 | { \ | |
889 | int64_t r2l, r2h, r1hl; \ | |
890 | uint64_t ret = 0; \ | |
891 | \ | |
892 | ret = ((r1 + 2) & 0xffff); \ | |
893 | r2l = sextract64(r2, 0, 16); \ | |
894 | r2h = sextract64(r2, 16, 16); \ | |
895 | r1hl = sextract64(r1, 32, 16); \ | |
896 | \ | |
897 | if ((r2l op ## = r2h) && (r2l op r1hl)) { \ | |
898 | ret |= (r2l & 0xffff) << 32; \ | |
899 | ret |= extract64(r1, 0, 16) << 16; \ | |
900 | } else if ((r2h op r2l) && (r2h op r1hl)) { \ | |
901 | ret |= extract64(r2, 16, 16) << 32; \ | |
902 | ret |= extract64(r1 + 1, 0, 16) << 16; \ | |
903 | } else { \ | |
904 | ret |= r1 & 0xffffffff0000ull; \ | |
905 | } \ | |
906 | return ret; \ | |
907 | } \ | |
908 | \ | |
909 | uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \ | |
910 | { \ | |
911 | int64_t r2l, r2h, r1hl; \ | |
912 | uint64_t ret = 0; \ | |
913 | \ | |
914 | ret = ((r1 + 2) & 0xffff); \ | |
915 | r2l = extract64(r2, 0, 16); \ | |
916 | r2h = extract64(r2, 16, 16); \ | |
917 | r1hl = extract64(r1, 32, 16); \ | |
918 | \ | |
919 | if ((r2l op ## = r2h) && (r2l op r1hl)) { \ | |
920 | ret |= (r2l & 0xffff) << 32; \ | |
921 | ret |= extract64(r1, 0, 16) << 16; \ | |
922 | } else if ((r2h op r2l) && (r2h op r1hl)) { \ | |
923 | ret |= extract64(r2, 16, 16) << 32; \ | |
924 | ret |= extract64(r1 + 1, 0, 16) << 16; \ | |
925 | } else { \ | |
926 | ret |= r1 & 0xffffffff0000ull; \ | |
927 | } \ | |
928 | return ret; \ | |
929 | } | |
d5de7839 BK |
930 | |
931 | EXTREMA_H_B(max, >) | |
932 | EXTREMA_H_B(min, <) | |
933 | ||
934 | #undef EXTREMA_H_B | |
935 | ||
0b79a781 BK |
936 | uint32_t helper_clo(target_ulong r1) |
937 | { | |
938 | return clo32(r1); | |
939 | } | |
940 | ||
941 | uint32_t helper_clo_h(target_ulong r1) | |
942 | { | |
943 | uint32_t ret_hw0 = extract32(r1, 0, 16); | |
944 | uint32_t ret_hw1 = extract32(r1, 16, 16); | |
945 | ||
946 | ret_hw0 = clo32(ret_hw0 << 16); | |
947 | ret_hw1 = clo32(ret_hw1 << 16); | |
948 | ||
949 | if (ret_hw0 > 16) { | |
950 | ret_hw0 = 16; | |
951 | } | |
952 | if (ret_hw1 > 16) { | |
953 | ret_hw1 = 16; | |
954 | } | |
955 | ||
956 | return ret_hw0 | (ret_hw1 << 16); | |
957 | } | |
958 | ||
959 | uint32_t helper_clz(target_ulong r1) | |
960 | { | |
961 | return clz32(r1); | |
962 | } | |
963 | ||
964 | uint32_t helper_clz_h(target_ulong r1) | |
965 | { | |
966 | uint32_t ret_hw0 = extract32(r1, 0, 16); | |
967 | uint32_t ret_hw1 = extract32(r1, 16, 16); | |
968 | ||
969 | ret_hw0 = clz32(ret_hw0 << 16); | |
970 | ret_hw1 = clz32(ret_hw1 << 16); | |
971 | ||
972 | if (ret_hw0 > 16) { | |
973 | ret_hw0 = 16; | |
974 | } | |
975 | if (ret_hw1 > 16) { | |
976 | ret_hw1 = 16; | |
977 | } | |
978 | ||
979 | return ret_hw0 | (ret_hw1 << 16); | |
980 | } | |
981 | ||
982 | uint32_t helper_cls(target_ulong r1) | |
983 | { | |
984 | return clrsb32(r1); | |
985 | } | |
986 | ||
987 | uint32_t helper_cls_h(target_ulong r1) | |
988 | { | |
989 | uint32_t ret_hw0 = extract32(r1, 0, 16); | |
990 | uint32_t ret_hw1 = extract32(r1, 16, 16); | |
991 | ||
992 | ret_hw0 = clrsb32(ret_hw0 << 16); | |
993 | ret_hw1 = clrsb32(ret_hw1 << 16); | |
994 | ||
995 | if (ret_hw0 > 15) { | |
996 | ret_hw0 = 15; | |
997 | } | |
998 | if (ret_hw1 > 15) { | |
999 | ret_hw1 = 15; | |
1000 | } | |
1001 | ||
1002 | return ret_hw0 | (ret_hw1 << 16); | |
1003 | } | |
1004 | ||
1005 | uint32_t helper_sh(target_ulong r1, target_ulong r2) | |
1006 | { | |
1007 | int32_t shift_count = sextract32(r2, 0, 6); | |
1008 | ||
1009 | if (shift_count == -32) { | |
1010 | return 0; | |
1011 | } else if (shift_count < 0) { | |
1012 | return r1 >> -shift_count; | |
1013 | } else { | |
1014 | return r1 << shift_count; | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | uint32_t helper_sh_h(target_ulong r1, target_ulong r2) | |
1019 | { | |
1020 | int32_t ret_hw0, ret_hw1; | |
1021 | int32_t shift_count; | |
1022 | ||
1023 | shift_count = sextract32(r2, 0, 5); | |
1024 | ||
1025 | if (shift_count == -16) { | |
1026 | return 0; | |
1027 | } else if (shift_count < 0) { | |
1028 | ret_hw0 = extract32(r1, 0, 16) >> -shift_count; | |
1029 | ret_hw1 = extract32(r1, 16, 16) >> -shift_count; | |
1030 | return (ret_hw0 & 0xffff) | (ret_hw1 << 16); | |
1031 | } else { | |
1032 | ret_hw0 = extract32(r1, 0, 16) << shift_count; | |
1033 | ret_hw1 = extract32(r1, 16, 16) << shift_count; | |
1034 | return (ret_hw0 & 0xffff) | (ret_hw1 << 16); | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | uint32_t helper_sha(CPUTriCoreState *env, target_ulong r1, target_ulong r2) | |
1039 | { | |
1040 | int32_t shift_count; | |
1041 | int64_t result, t1; | |
1042 | uint32_t ret; | |
1043 | ||
1044 | shift_count = sextract32(r2, 0, 6); | |
1045 | t1 = sextract32(r1, 0, 32); | |
1046 | ||
1047 | if (shift_count == 0) { | |
1048 | env->PSW_USB_C = env->PSW_USB_V = 0; | |
1049 | ret = r1; | |
1050 | } else if (shift_count == -32) { | |
1051 | env->PSW_USB_C = r1; | |
1052 | env->PSW_USB_V = 0; | |
1053 | ret = t1 >> 31; | |
1054 | } else if (shift_count > 0) { | |
1055 | result = t1 << shift_count; | |
1056 | /* calc carry */ | |
452e3d49 | 1057 | env->PSW_USB_C = ((result & 0xffffffff00000000ULL) != 0); |
0b79a781 BK |
1058 | /* calc v */ |
1059 | env->PSW_USB_V = (((result > 0x7fffffffLL) || | |
1060 | (result < -0x80000000LL)) << 31); | |
1061 | /* calc sv */ | |
1062 | env->PSW_USB_SV |= env->PSW_USB_V; | |
1063 | ret = (uint32_t)result; | |
1064 | } else { | |
1065 | env->PSW_USB_V = 0; | |
1066 | env->PSW_USB_C = (r1 & ((1 << -shift_count) - 1)); | |
1067 | ret = t1 >> -shift_count; | |
1068 | } | |
1069 | ||
1070 | env->PSW_USB_AV = ret ^ ret * 2u; | |
1071 | env->PSW_USB_SAV |= env->PSW_USB_AV; | |
1072 | ||
1073 | return ret; | |
1074 | } | |
1075 | ||
1076 | uint32_t helper_sha_h(target_ulong r1, target_ulong r2) | |
1077 | { | |
1078 | int32_t shift_count; | |
1079 | int32_t ret_hw0, ret_hw1; | |
1080 | ||
1081 | shift_count = sextract32(r2, 0, 5); | |
1082 | ||
1083 | if (shift_count == 0) { | |
1084 | return r1; | |
1085 | } else if (shift_count < 0) { | |
1086 | ret_hw0 = sextract32(r1, 0, 16) >> -shift_count; | |
1087 | ret_hw1 = sextract32(r1, 16, 16) >> -shift_count; | |
1088 | return (ret_hw0 & 0xffff) | (ret_hw1 << 16); | |
1089 | } else { | |
1090 | ret_hw0 = sextract32(r1, 0, 16) << shift_count; | |
1091 | ret_hw1 = sextract32(r1, 16, 16) << shift_count; | |
1092 | return (ret_hw0 & 0xffff) | (ret_hw1 << 16); | |
1093 | } | |
1094 | } | |
1095 | ||
e2bed107 BK |
1096 | uint32_t helper_bmerge(target_ulong r1, target_ulong r2) |
1097 | { | |
1098 | uint32_t i, ret; | |
1099 | ||
1100 | ret = 0; | |
1101 | for (i = 0; i < 16; i++) { | |
1102 | ret |= (r1 & 1) << (2 * i + 1); | |
1103 | ret |= (r2 & 1) << (2 * i); | |
1104 | r1 = r1 >> 1; | |
1105 | r2 = r2 >> 1; | |
1106 | } | |
1107 | return ret; | |
1108 | } | |
1109 | ||
1110 | uint64_t helper_bsplit(uint32_t r1) | |
1111 | { | |
1112 | int32_t i; | |
1113 | uint64_t ret; | |
1114 | ||
1115 | ret = 0; | |
1116 | for (i = 0; i < 32; i = i + 2) { | |
1117 | /* even */ | |
1118 | ret |= (r1 & 1) << (i/2); | |
1119 | r1 = r1 >> 1; | |
1120 | /* odd */ | |
1121 | ret |= (uint64_t)(r1 & 1) << (i/2 + 32); | |
1122 | r1 = r1 >> 1; | |
1123 | } | |
1124 | return ret; | |
1125 | } | |
1126 | ||
1127 | uint32_t helper_parity(target_ulong r1) | |
1128 | { | |
1129 | uint32_t ret; | |
1130 | uint32_t nOnes, i; | |
1131 | ||
1132 | ret = 0; | |
1133 | nOnes = 0; | |
1134 | for (i = 0; i < 8; i++) { | |
1135 | ret ^= (r1 & 1); | |
1136 | r1 = r1 >> 1; | |
1137 | } | |
1138 | /* second byte */ | |
1139 | nOnes = 0; | |
1140 | for (i = 0; i < 8; i++) { | |
1141 | nOnes ^= (r1 & 1); | |
1142 | r1 = r1 >> 1; | |
1143 | } | |
1144 | ret |= nOnes << 8; | |
1145 | /* third byte */ | |
1146 | nOnes = 0; | |
1147 | for (i = 0; i < 8; i++) { | |
1148 | nOnes ^= (r1 & 1); | |
1149 | r1 = r1 >> 1; | |
1150 | } | |
1151 | ret |= nOnes << 16; | |
1152 | /* fourth byte */ | |
1153 | nOnes = 0; | |
1154 | for (i = 0; i < 8; i++) { | |
1155 | nOnes ^= (r1 & 1); | |
1156 | r1 = r1 >> 1; | |
1157 | } | |
1158 | ret |= nOnes << 24; | |
1159 | ||
1160 | return ret; | |
1161 | } | |
1162 | ||
09532255 BK |
1163 | uint32_t helper_pack(uint32_t carry, uint32_t r1_low, uint32_t r1_high, |
1164 | target_ulong r2) | |
1165 | { | |
1166 | uint32_t ret; | |
1167 | int32_t fp_exp, fp_frac, temp_exp, fp_exp_frac; | |
1168 | int32_t int_exp = r1_high; | |
1169 | int32_t int_mant = r1_low; | |
1170 | uint32_t flag_rnd = (int_mant & (1 << 7)) && ( | |
1171 | (int_mant & (1 << 8)) || | |
1172 | (int_mant & 0x7f) || | |
1173 | (carry != 0)); | |
1174 | if (((int_mant & (1<<31)) == 0) && (int_exp == 255)) { | |
1175 | fp_exp = 255; | |
1176 | fp_frac = extract32(int_mant, 8, 23); | |
1177 | } else if ((int_mant & (1<<31)) && (int_exp >= 127)) { | |
1178 | fp_exp = 255; | |
1179 | fp_frac = 0; | |
1180 | } else if ((int_mant & (1<<31)) && (int_exp <= -128)) { | |
1181 | fp_exp = 0; | |
1182 | fp_frac = 0; | |
1183 | } else if (int_mant == 0) { | |
1184 | fp_exp = 0; | |
1185 | fp_frac = 0; | |
1186 | } else { | |
1187 | if (((int_mant & (1 << 31)) == 0)) { | |
1188 | temp_exp = 0; | |
1189 | } else { | |
1190 | temp_exp = int_exp + 128; | |
1191 | } | |
1192 | fp_exp_frac = (((temp_exp & 0xff) << 23) | | |
1193 | extract32(int_mant, 8, 23)) | |
1194 | + flag_rnd; | |
1195 | fp_exp = extract32(fp_exp_frac, 23, 8); | |
1196 | fp_frac = extract32(fp_exp_frac, 0, 23); | |
1197 | } | |
1198 | ret = r2 & (1 << 31); | |
1199 | ret = ret + (fp_exp << 23); | |
1200 | ret = ret + (fp_frac & 0x7fffff); | |
1201 | ||
1202 | return ret; | |
1203 | } | |
1204 | ||
e2bed107 BK |
1205 | uint64_t helper_unpack(target_ulong arg1) |
1206 | { | |
1207 | int32_t fp_exp = extract32(arg1, 23, 8); | |
1208 | int32_t fp_frac = extract32(arg1, 0, 23); | |
1209 | uint64_t ret; | |
1210 | int32_t int_exp, int_mant; | |
1211 | ||
1212 | if (fp_exp == 255) { | |
1213 | int_exp = 255; | |
1214 | int_mant = (fp_frac << 7); | |
1215 | } else if ((fp_exp == 0) && (fp_frac == 0)) { | |
1216 | int_exp = -127; | |
1217 | int_mant = 0; | |
1218 | } else if ((fp_exp == 0) && (fp_frac != 0)) { | |
1219 | int_exp = -126; | |
1220 | int_mant = (fp_frac << 7); | |
1221 | } else { | |
1222 | int_exp = fp_exp - 127; | |
1223 | int_mant = (fp_frac << 7); | |
1224 | int_mant |= (1 << 30); | |
1225 | } | |
1226 | ret = int_exp; | |
1227 | ret = ret << 32; | |
1228 | ret |= int_mant; | |
1229 | ||
1230 | return ret; | |
1231 | } | |
1232 | ||
1233 | uint64_t helper_dvinit_b_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2) | |
1234 | { | |
1235 | uint64_t ret; | |
1236 | int32_t abs_sig_dividend, abs_base_dividend, abs_divisor; | |
1237 | int32_t quotient_sign; | |
1238 | ||
1239 | ret = sextract32(r1, 0, 32); | |
1240 | ret = ret << 24; | |
1241 | quotient_sign = 0; | |
1242 | if (!((r1 & 0x80000000) == (r2 & 0x80000000))) { | |
1243 | ret |= 0xffffff; | |
1244 | quotient_sign = 1; | |
1245 | } | |
1246 | ||
1247 | abs_sig_dividend = abs(r1) >> 7; | |
1248 | abs_base_dividend = abs(r1) & 0x7f; | |
1249 | abs_divisor = abs(r1); | |
1250 | /* calc overflow */ | |
1251 | env->PSW_USB_V = 0; | |
1252 | if ((quotient_sign) && (abs_divisor)) { | |
1253 | env->PSW_USB_V = (((abs_sig_dividend == abs_divisor) && | |
1254 | (abs_base_dividend >= abs_divisor)) || | |
1255 | (abs_sig_dividend > abs_divisor)); | |
1256 | } else { | |
1257 | env->PSW_USB_V = (abs_sig_dividend >= abs_divisor); | |
1258 | } | |
1259 | env->PSW_USB_V = env->PSW_USB_V << 31; | |
1260 | env->PSW_USB_SV |= env->PSW_USB_V; | |
1261 | env->PSW_USB_AV = 0; | |
1262 | ||
1263 | return ret; | |
1264 | } | |
1265 | ||
1266 | uint64_t helper_dvinit_b_131(CPUTriCoreState *env, uint32_t r1, uint32_t r2) | |
1267 | { | |
1268 | uint64_t ret = sextract32(r1, 0, 32); | |
1269 | ||
1270 | ret = ret << 24; | |
1271 | if (!((r1 & 0x80000000) == (r2 & 0x80000000))) { | |
1272 | ret |= 0xffffff; | |
1273 | } | |
1274 | /* calc overflow */ | |
1275 | env->PSW_USB_V = ((r2 == 0) || ((r2 == 0xffffffff) && (r1 == 0xffffff80))); | |
1276 | env->PSW_USB_V = env->PSW_USB_V << 31; | |
1277 | env->PSW_USB_SV |= env->PSW_USB_V; | |
1278 | env->PSW_USB_AV = 0; | |
1279 | ||
1280 | return ret; | |
1281 | } | |
1282 | ||
1283 | uint64_t helper_dvinit_h_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2) | |
1284 | { | |
1285 | uint64_t ret; | |
1286 | int32_t abs_sig_dividend, abs_base_dividend, abs_divisor; | |
1287 | int32_t quotient_sign; | |
1288 | ||
1289 | ret = sextract32(r1, 0, 32); | |
1290 | ret = ret << 16; | |
1291 | quotient_sign = 0; | |
1292 | if (!((r1 & 0x80000000) == (r2 & 0x80000000))) { | |
1293 | ret |= 0xffff; | |
1294 | quotient_sign = 1; | |
1295 | } | |
1296 | ||
1297 | abs_sig_dividend = abs(r1) >> 7; | |
1298 | abs_base_dividend = abs(r1) & 0x7f; | |
1299 | abs_divisor = abs(r1); | |
1300 | /* calc overflow */ | |
1301 | env->PSW_USB_V = 0; | |
1302 | if ((quotient_sign) && (abs_divisor)) { | |
1303 | env->PSW_USB_V = (((abs_sig_dividend == abs_divisor) && | |
1304 | (abs_base_dividend >= abs_divisor)) || | |
1305 | (abs_sig_dividend > abs_divisor)); | |
1306 | } else { | |
1307 | env->PSW_USB_V = (abs_sig_dividend >= abs_divisor); | |
1308 | } | |
1309 | env->PSW_USB_V = env->PSW_USB_V << 31; | |
1310 | env->PSW_USB_SV |= env->PSW_USB_V; | |
1311 | env->PSW_USB_AV = 0; | |
1312 | ||
1313 | return ret; | |
1314 | } | |
1315 | ||
1316 | uint64_t helper_dvinit_h_131(CPUTriCoreState *env, uint32_t r1, uint32_t r2) | |
1317 | { | |
1318 | uint64_t ret = sextract32(r1, 0, 32); | |
1319 | ||
1320 | ret = ret << 16; | |
1321 | if (!((r1 & 0x80000000) == (r2 & 0x80000000))) { | |
1322 | ret |= 0xffff; | |
1323 | } | |
1324 | /* calc overflow */ | |
1325 | env->PSW_USB_V = ((r2 == 0) || ((r2 == 0xffffffff) && (r1 == 0xffff8000))); | |
1326 | env->PSW_USB_V = env->PSW_USB_V << 31; | |
1327 | env->PSW_USB_SV |= env->PSW_USB_V; | |
1328 | env->PSW_USB_AV = 0; | |
1329 | ||
1330 | return ret; | |
1331 | } | |
1332 | ||
09532255 BK |
1333 | uint64_t helper_dvadj(uint64_t r1, uint32_t r2) |
1334 | { | |
1335 | int32_t x_sign = (r1 >> 63); | |
1336 | int32_t q_sign = x_sign ^ (r2 >> 31); | |
1337 | int32_t eq_pos = x_sign & ((r1 >> 32) == r2); | |
1338 | int32_t eq_neg = x_sign & ((r1 >> 32) == -r2); | |
1339 | uint32_t quotient; | |
1340 | uint64_t ret, remainder; | |
1341 | ||
1342 | if ((q_sign & ~eq_neg) | eq_pos) { | |
1343 | quotient = (r1 + 1) & 0xffffffff; | |
1344 | } else { | |
1345 | quotient = r1 & 0xffffffff; | |
1346 | } | |
1347 | ||
1348 | if (eq_pos | eq_neg) { | |
1349 | remainder = 0; | |
1350 | } else { | |
1351 | remainder = (r1 & 0xffffffff00000000ull); | |
1352 | } | |
1353 | ret = remainder|quotient; | |
1354 | return ret; | |
1355 | } | |
1356 | ||
1357 | uint64_t helper_dvstep(uint64_t r1, uint32_t r2) | |
1358 | { | |
1359 | int32_t dividend_sign = extract64(r1, 63, 1); | |
1360 | int32_t divisor_sign = extract32(r2, 31, 1); | |
1361 | int32_t quotient_sign = (dividend_sign != divisor_sign); | |
1362 | int32_t addend, dividend_quotient, remainder; | |
1363 | int32_t i, temp; | |
1364 | ||
1365 | if (quotient_sign) { | |
1366 | addend = r2; | |
1367 | } else { | |
1368 | addend = -r2; | |
1369 | } | |
1370 | dividend_quotient = (int32_t)r1; | |
1371 | remainder = (int32_t)(r1 >> 32); | |
1372 | ||
1373 | for (i = 0; i < 8; i++) { | |
1374 | remainder = (remainder << 1) | extract32(dividend_quotient, 31, 1); | |
1375 | dividend_quotient <<= 1; | |
1376 | temp = remainder + addend; | |
1377 | if ((temp < 0) == dividend_sign) { | |
1378 | remainder = temp; | |
1379 | } | |
1380 | if (((temp < 0) == dividend_sign)) { | |
1381 | dividend_quotient = dividend_quotient | !quotient_sign; | |
1382 | } else { | |
1383 | dividend_quotient = dividend_quotient | quotient_sign; | |
1384 | } | |
1385 | } | |
1386 | return ((uint64_t)remainder << 32) | (uint32_t)dividend_quotient; | |
1387 | } | |
1388 | ||
1389 | uint64_t helper_dvstep_u(uint64_t r1, uint32_t r2) | |
1390 | { | |
1391 | int32_t dividend_quotient = extract64(r1, 0, 32); | |
1392 | int64_t remainder = extract64(r1, 32, 32); | |
1393 | int32_t i; | |
1394 | int64_t temp; | |
1395 | for (i = 0; i < 8; i++) { | |
1396 | remainder = (remainder << 1) | extract32(dividend_quotient, 31, 1); | |
1397 | dividend_quotient <<= 1; | |
1398 | temp = (remainder & 0xffffffff) - r2; | |
1399 | if (temp >= 0) { | |
1400 | remainder = temp; | |
1401 | } | |
1402 | dividend_quotient = dividend_quotient | !(temp < 0); | |
1403 | } | |
1404 | return ((uint64_t)remainder << 32) | (uint32_t)dividend_quotient; | |
1405 | } | |
1406 | ||
9655b932 BK |
1407 | uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01, |
1408 | uint32_t arg10, uint32_t arg11, uint32_t n) | |
1409 | { | |
1410 | uint64_t ret; | |
1411 | uint32_t result0, result1; | |
1412 | ||
1413 | int32_t sc1 = ((arg00 & 0xffff) == 0x8000) && | |
1414 | ((arg10 & 0xffff) == 0x8000) && (n == 1); | |
1415 | int32_t sc0 = ((arg01 & 0xffff) == 0x8000) && | |
1416 | ((arg11 & 0xffff) == 0x8000) && (n == 1); | |
1417 | if (sc1) { | |
1418 | result1 = 0x7fffffff; | |
1419 | } else { | |
1420 | result1 = (((uint32_t)(arg00 * arg10)) << n); | |
1421 | } | |
1422 | if (sc0) { | |
1423 | result0 = 0x7fffffff; | |
1424 | } else { | |
1425 | result0 = (((uint32_t)(arg01 * arg11)) << n); | |
1426 | } | |
1427 | ret = (((uint64_t)result1 << 32)) | result0; | |
1428 | return ret; | |
1429 | } | |
1430 | ||
1431 | uint64_t helper_mulm_h(uint32_t arg00, uint32_t arg01, | |
1432 | uint32_t arg10, uint32_t arg11, uint32_t n) | |
1433 | { | |
1434 | uint64_t ret; | |
1435 | int64_t result0, result1; | |
1436 | ||
1437 | int32_t sc1 = ((arg00 & 0xffff) == 0x8000) && | |
1438 | ((arg10 & 0xffff) == 0x8000) && (n == 1); | |
1439 | int32_t sc0 = ((arg01 & 0xffff) == 0x8000) && | |
1440 | ((arg11 & 0xffff) == 0x8000) && (n == 1); | |
1441 | ||
1442 | if (sc1) { | |
1443 | result1 = 0x7fffffff; | |
1444 | } else { | |
1445 | result1 = (((int32_t)arg00 * (int32_t)arg10) << n); | |
1446 | } | |
1447 | if (sc0) { | |
1448 | result0 = 0x7fffffff; | |
1449 | } else { | |
1450 | result0 = (((int32_t)arg01 * (int32_t)arg11) << n); | |
1451 | } | |
1452 | ret = (result1 + result0); | |
1453 | ret = ret << 16; | |
1454 | return ret; | |
1455 | } | |
1456 | uint32_t helper_mulr_h(uint32_t arg00, uint32_t arg01, | |
1457 | uint32_t arg10, uint32_t arg11, uint32_t n) | |
1458 | { | |
1459 | uint32_t result0, result1; | |
1460 | ||
1461 | int32_t sc1 = ((arg00 & 0xffff) == 0x8000) && | |
1462 | ((arg10 & 0xffff) == 0x8000) && (n == 1); | |
1463 | int32_t sc0 = ((arg01 & 0xffff) == 0x8000) && | |
1464 | ((arg11 & 0xffff) == 0x8000) && (n == 1); | |
1465 | ||
1466 | if (sc1) { | |
1467 | result1 = 0x7fffffff; | |
1468 | } else { | |
1469 | result1 = ((arg00 * arg10) << n) + 0x8000; | |
1470 | } | |
1471 | if (sc0) { | |
1472 | result0 = 0x7fffffff; | |
1473 | } else { | |
1474 | result0 = ((arg01 * arg11) << n) + 0x8000; | |
1475 | } | |
1476 | return (result1 & 0xffff0000) | (result0 >> 16); | |
1477 | } | |
1478 | ||
9a31922b BK |
1479 | /* context save area (CSA) related helpers */ |
1480 | ||
1481 | static int cdc_increment(target_ulong *psw) | |
1482 | { | |
1483 | if ((*psw & MASK_PSW_CDC) == 0x7f) { | |
1484 | return 0; | |
1485 | } | |
1486 | ||
1487 | (*psw)++; | |
1488 | /* check for overflow */ | |
1489 | int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7)); | |
1490 | int mask = (1u << (7 - lo)) - 1; | |
1491 | int count = *psw & mask; | |
1492 | if (count == 0) { | |
1493 | (*psw)--; | |
1494 | return 1; | |
1495 | } | |
1496 | return 0; | |
1497 | } | |
1498 | ||
1499 | static int cdc_decrement(target_ulong *psw) | |
1500 | { | |
1501 | if ((*psw & MASK_PSW_CDC) == 0x7f) { | |
1502 | return 0; | |
1503 | } | |
1504 | /* check for underflow */ | |
1505 | int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7)); | |
1506 | int mask = (1u << (7 - lo)) - 1; | |
1507 | int count = *psw & mask; | |
1508 | if (count == 0) { | |
1509 | return 1; | |
1510 | } | |
1511 | (*psw)--; | |
1512 | return 0; | |
1513 | } | |
1514 | ||
44ea3430 BK |
1515 | static bool cdc_zero(target_ulong *psw) |
1516 | { | |
1517 | int cdc = *psw & MASK_PSW_CDC; | |
1518 | /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC == | |
1519 | 7'b1111111, otherwise returns FALSE. */ | |
1520 | if (cdc == 0x7f) { | |
1521 | return true; | |
1522 | } | |
1523 | /* find CDC.COUNT */ | |
1524 | int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7)); | |
1525 | int mask = (1u << (7 - lo)) - 1; | |
1526 | int count = *psw & mask; | |
1527 | return count == 0; | |
1528 | } | |
1529 | ||
030c58df | 1530 | static void save_context_upper(CPUTriCoreState *env, int ea) |
9a31922b | 1531 | { |
9a31922b BK |
1532 | cpu_stl_data(env, ea, env->PCXI); |
1533 | cpu_stl_data(env, ea+4, env->PSW); | |
1534 | cpu_stl_data(env, ea+8, env->gpr_a[10]); | |
1535 | cpu_stl_data(env, ea+12, env->gpr_a[11]); | |
1536 | cpu_stl_data(env, ea+16, env->gpr_d[8]); | |
1537 | cpu_stl_data(env, ea+20, env->gpr_d[9]); | |
1538 | cpu_stl_data(env, ea+24, env->gpr_d[10]); | |
1539 | cpu_stl_data(env, ea+28, env->gpr_d[11]); | |
1540 | cpu_stl_data(env, ea+32, env->gpr_a[12]); | |
1541 | cpu_stl_data(env, ea+36, env->gpr_a[13]); | |
1542 | cpu_stl_data(env, ea+40, env->gpr_a[14]); | |
1543 | cpu_stl_data(env, ea+44, env->gpr_a[15]); | |
1544 | cpu_stl_data(env, ea+48, env->gpr_d[12]); | |
1545 | cpu_stl_data(env, ea+52, env->gpr_d[13]); | |
1546 | cpu_stl_data(env, ea+56, env->gpr_d[14]); | |
1547 | cpu_stl_data(env, ea+60, env->gpr_d[15]); | |
9a31922b BK |
1548 | } |
1549 | ||
030c58df | 1550 | static void save_context_lower(CPUTriCoreState *env, int ea) |
5de93515 | 1551 | { |
5de93515 | 1552 | cpu_stl_data(env, ea, env->PCXI); |
030c58df | 1553 | cpu_stl_data(env, ea+4, env->gpr_a[11]); |
5de93515 BK |
1554 | cpu_stl_data(env, ea+8, env->gpr_a[2]); |
1555 | cpu_stl_data(env, ea+12, env->gpr_a[3]); | |
1556 | cpu_stl_data(env, ea+16, env->gpr_d[0]); | |
1557 | cpu_stl_data(env, ea+20, env->gpr_d[1]); | |
1558 | cpu_stl_data(env, ea+24, env->gpr_d[2]); | |
1559 | cpu_stl_data(env, ea+28, env->gpr_d[3]); | |
1560 | cpu_stl_data(env, ea+32, env->gpr_a[4]); | |
1561 | cpu_stl_data(env, ea+36, env->gpr_a[5]); | |
1562 | cpu_stl_data(env, ea+40, env->gpr_a[6]); | |
1563 | cpu_stl_data(env, ea+44, env->gpr_a[7]); | |
1564 | cpu_stl_data(env, ea+48, env->gpr_d[4]); | |
1565 | cpu_stl_data(env, ea+52, env->gpr_d[5]); | |
1566 | cpu_stl_data(env, ea+56, env->gpr_d[6]); | |
1567 | cpu_stl_data(env, ea+60, env->gpr_d[7]); | |
1568 | } | |
1569 | ||
9a31922b BK |
1570 | static void restore_context_upper(CPUTriCoreState *env, int ea, |
1571 | target_ulong *new_PCXI, target_ulong *new_PSW) | |
1572 | { | |
1573 | *new_PCXI = cpu_ldl_data(env, ea); | |
1574 | *new_PSW = cpu_ldl_data(env, ea+4); | |
1575 | env->gpr_a[10] = cpu_ldl_data(env, ea+8); | |
1576 | env->gpr_a[11] = cpu_ldl_data(env, ea+12); | |
1577 | env->gpr_d[8] = cpu_ldl_data(env, ea+16); | |
1578 | env->gpr_d[9] = cpu_ldl_data(env, ea+20); | |
1579 | env->gpr_d[10] = cpu_ldl_data(env, ea+24); | |
1580 | env->gpr_d[11] = cpu_ldl_data(env, ea+28); | |
1581 | env->gpr_a[12] = cpu_ldl_data(env, ea+32); | |
1582 | env->gpr_a[13] = cpu_ldl_data(env, ea+36); | |
1583 | env->gpr_a[14] = cpu_ldl_data(env, ea+40); | |
1584 | env->gpr_a[15] = cpu_ldl_data(env, ea+44); | |
1585 | env->gpr_d[12] = cpu_ldl_data(env, ea+48); | |
1586 | env->gpr_d[13] = cpu_ldl_data(env, ea+52); | |
1587 | env->gpr_d[14] = cpu_ldl_data(env, ea+56); | |
1588 | env->gpr_d[15] = cpu_ldl_data(env, ea+60); | |
9a31922b BK |
1589 | } |
1590 | ||
59543d4e BK |
1591 | static void restore_context_lower(CPUTriCoreState *env, int ea, |
1592 | target_ulong *ra, target_ulong *pcxi) | |
1593 | { | |
1594 | *pcxi = cpu_ldl_data(env, ea); | |
1595 | *ra = cpu_ldl_data(env, ea+4); | |
1596 | env->gpr_a[2] = cpu_ldl_data(env, ea+8); | |
1597 | env->gpr_a[3] = cpu_ldl_data(env, ea+12); | |
1598 | env->gpr_d[0] = cpu_ldl_data(env, ea+16); | |
1599 | env->gpr_d[1] = cpu_ldl_data(env, ea+20); | |
1600 | env->gpr_d[2] = cpu_ldl_data(env, ea+24); | |
1601 | env->gpr_d[3] = cpu_ldl_data(env, ea+28); | |
1602 | env->gpr_a[4] = cpu_ldl_data(env, ea+32); | |
1603 | env->gpr_a[5] = cpu_ldl_data(env, ea+36); | |
1604 | env->gpr_a[6] = cpu_ldl_data(env, ea+40); | |
1605 | env->gpr_a[7] = cpu_ldl_data(env, ea+44); | |
1606 | env->gpr_d[4] = cpu_ldl_data(env, ea+48); | |
1607 | env->gpr_d[5] = cpu_ldl_data(env, ea+52); | |
1608 | env->gpr_d[6] = cpu_ldl_data(env, ea+56); | |
1609 | env->gpr_d[7] = cpu_ldl_data(env, ea+60); | |
1610 | } | |
1611 | ||
9a31922b BK |
1612 | void helper_call(CPUTriCoreState *env, uint32_t next_pc) |
1613 | { | |
1614 | target_ulong tmp_FCX; | |
1615 | target_ulong ea; | |
1616 | target_ulong new_FCX; | |
1617 | target_ulong psw; | |
1618 | ||
1619 | psw = psw_read(env); | |
1620 | /* if (FCX == 0) trap(FCU); */ | |
1621 | if (env->FCX == 0) { | |
1622 | /* FCU trap */ | |
1623 | } | |
1624 | /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */ | |
1625 | if (psw & MASK_PSW_CDE) { | |
1626 | if (cdc_increment(&psw)) { | |
1627 | /* CDO trap */ | |
1628 | } | |
1629 | } | |
1630 | /* PSW.CDE = 1;*/ | |
1631 | psw |= MASK_PSW_CDE; | |
1632 | /* tmp_FCX = FCX; */ | |
1633 | tmp_FCX = env->FCX; | |
1634 | /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */ | |
1635 | ea = ((env->FCX & MASK_FCX_FCXS) << 12) + | |
1636 | ((env->FCX & MASK_FCX_FCXO) << 6); | |
030c58df BK |
1637 | /* new_FCX = M(EA, word); */ |
1638 | new_FCX = cpu_ldl_data(env, ea); | |
1639 | /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], | |
1640 | A[12], A[13], A[14], A[15], D[12], D[13], D[14], | |
1641 | D[15]}; */ | |
1642 | save_context_upper(env, ea); | |
9a31922b BK |
1643 | |
1644 | /* PCXI.PCPN = ICR.CCPN; */ | |
1645 | env->PCXI = (env->PCXI & 0xffffff) + | |
1646 | ((env->ICR & MASK_ICR_CCPN) << 24); | |
1647 | /* PCXI.PIE = ICR.IE; */ | |
1648 | env->PCXI = ((env->PCXI & ~MASK_PCXI_PIE) + | |
1649 | ((env->ICR & MASK_ICR_IE) << 15)); | |
1650 | /* PCXI.UL = 1; */ | |
1651 | env->PCXI |= MASK_PCXI_UL; | |
1652 | ||
1653 | /* PCXI[19: 0] = FCX[19: 0]; */ | |
1654 | env->PCXI = (env->PCXI & 0xfff00000) + (env->FCX & 0xfffff); | |
1655 | /* FCX[19: 0] = new_FCX[19: 0]; */ | |
1656 | env->FCX = (env->FCX & 0xfff00000) + (new_FCX & 0xfffff); | |
1657 | /* A[11] = next_pc[31: 0]; */ | |
1658 | env->gpr_a[11] = next_pc; | |
1659 | ||
1660 | /* if (tmp_FCX == LCX) trap(FCD);*/ | |
1661 | if (tmp_FCX == env->LCX) { | |
1662 | /* FCD trap */ | |
1663 | } | |
1664 | psw_write(env, psw); | |
1665 | } | |
1666 | ||
1667 | void helper_ret(CPUTriCoreState *env) | |
1668 | { | |
1669 | target_ulong ea; | |
1670 | target_ulong new_PCXI; | |
1671 | target_ulong new_PSW, psw; | |
1672 | ||
1673 | psw = psw_read(env); | |
1674 | /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/ | |
1675 | if (env->PSW & MASK_PSW_CDE) { | |
1676 | if (cdc_decrement(&(env->PSW))) { | |
1677 | /* CDU trap */ | |
1678 | } | |
1679 | } | |
1680 | /* if (PCXI[19: 0] == 0) then trap(CSU); */ | |
1681 | if ((env->PCXI & 0xfffff) == 0) { | |
1682 | /* CSU trap */ | |
1683 | } | |
1684 | /* if (PCXI.UL == 0) then trap(CTYP); */ | |
1685 | if ((env->PCXI & MASK_PCXI_UL) == 0) { | |
1686 | /* CTYP trap */ | |
1687 | } | |
1688 | /* PC = {A11 [31: 1], 1’b0}; */ | |
1689 | env->PC = env->gpr_a[11] & 0xfffffffe; | |
1690 | ||
1691 | /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */ | |
1692 | ea = ((env->PCXI & MASK_PCXI_PCXS) << 12) + | |
1693 | ((env->PCXI & MASK_PCXI_PCXO) << 6); | |
1694 | /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12], | |
030c58df | 1695 | A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */ |
9a31922b | 1696 | restore_context_upper(env, ea, &new_PCXI, &new_PSW); |
030c58df BK |
1697 | /* M(EA, word) = FCX; */ |
1698 | cpu_stl_data(env, ea, env->FCX); | |
9a31922b BK |
1699 | /* FCX[19: 0] = PCXI[19: 0]; */ |
1700 | env->FCX = (env->FCX & 0xfff00000) + (env->PCXI & 0x000fffff); | |
1701 | /* PCXI = new_PCXI; */ | |
1702 | env->PCXI = new_PCXI; | |
1703 | ||
1704 | if (tricore_feature(env, TRICORE_FEATURE_13)) { | |
1705 | /* PSW = new_PSW */ | |
1706 | psw_write(env, new_PSW); | |
1707 | } else { | |
1708 | /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */ | |
1709 | psw_write(env, (new_PSW & ~(0x3000000)) + (psw & (0x3000000))); | |
1710 | } | |
1711 | } | |
1712 | ||
5de93515 BK |
1713 | void helper_bisr(CPUTriCoreState *env, uint32_t const9) |
1714 | { | |
1715 | target_ulong tmp_FCX; | |
1716 | target_ulong ea; | |
1717 | target_ulong new_FCX; | |
1718 | ||
1719 | if (env->FCX == 0) { | |
1720 | /* FCU trap */ | |
1721 | } | |
1722 | ||
1723 | tmp_FCX = env->FCX; | |
1724 | ea = ((env->FCX & 0xf0000) << 12) + ((env->FCX & 0xffff) << 6); | |
1725 | ||
030c58df BK |
1726 | /* new_FCX = M(EA, word); */ |
1727 | new_FCX = cpu_ldl_data(env, ea); | |
1728 | /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4] | |
1729 | , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */ | |
1730 | save_context_lower(env, ea); | |
1731 | ||
5de93515 BK |
1732 | |
1733 | /* PCXI.PCPN = ICR.CCPN */ | |
1734 | env->PCXI = (env->PCXI & 0xffffff) + | |
1735 | ((env->ICR & MASK_ICR_CCPN) << 24); | |
1736 | /* PCXI.PIE = ICR.IE */ | |
1737 | env->PCXI = ((env->PCXI & ~MASK_PCXI_PIE) + | |
1738 | ((env->ICR & MASK_ICR_IE) << 15)); | |
1739 | /* PCXI.UL = 0 */ | |
1740 | env->PCXI &= ~(MASK_PCXI_UL); | |
1741 | /* PCXI[19: 0] = FCX[19: 0] */ | |
1742 | env->PCXI = (env->PCXI & 0xfff00000) + (env->FCX & 0xfffff); | |
1743 | /* FXC[19: 0] = new_FCX[19: 0] */ | |
1744 | env->FCX = (env->FCX & 0xfff00000) + (new_FCX & 0xfffff); | |
1745 | /* ICR.IE = 1 */ | |
1746 | env->ICR |= MASK_ICR_IE; | |
1747 | ||
1748 | env->ICR |= const9; /* ICR.CCPN = const9[7: 0];*/ | |
1749 | ||
1750 | if (tmp_FCX == env->LCX) { | |
1751 | /* FCD trap */ | |
1752 | } | |
1753 | } | |
1754 | ||
44ea3430 BK |
1755 | void helper_rfe(CPUTriCoreState *env) |
1756 | { | |
1757 | target_ulong ea; | |
1758 | target_ulong new_PCXI; | |
1759 | target_ulong new_PSW; | |
1760 | /* if (PCXI[19: 0] == 0) then trap(CSU); */ | |
1761 | if ((env->PCXI & 0xfffff) == 0) { | |
1762 | /* raise csu trap */ | |
1763 | } | |
1764 | /* if (PCXI.UL == 0) then trap(CTYP); */ | |
1765 | if ((env->PCXI & MASK_PCXI_UL) == 0) { | |
1766 | /* raise CTYP trap */ | |
1767 | } | |
1768 | /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */ | |
1769 | if (!cdc_zero(&(env->PSW)) && (env->PSW & MASK_PSW_CDE)) { | |
1770 | /* raise MNG trap */ | |
1771 | } | |
1772 | /* ICR.IE = PCXI.PIE; */ | |
1773 | env->ICR = (env->ICR & ~MASK_ICR_IE) + ((env->PCXI & MASK_PCXI_PIE) >> 15); | |
1774 | /* ICR.CCPN = PCXI.PCPN; */ | |
1775 | env->ICR = (env->ICR & ~MASK_ICR_CCPN) + | |
1776 | ((env->PCXI & MASK_PCXI_PCPN) >> 24); | |
1777 | /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/ | |
1778 | ea = ((env->PCXI & MASK_PCXI_PCXS) << 12) + | |
1779 | ((env->PCXI & MASK_PCXI_PCXO) << 6); | |
1780 | /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12], | |
030c58df | 1781 | A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */ |
44ea3430 | 1782 | restore_context_upper(env, ea, &new_PCXI, &new_PSW); |
030c58df BK |
1783 | /* M(EA, word) = FCX;*/ |
1784 | cpu_stl_data(env, ea, env->FCX); | |
44ea3430 BK |
1785 | /* FCX[19: 0] = PCXI[19: 0]; */ |
1786 | env->FCX = (env->FCX & 0xfff00000) + (env->PCXI & 0x000fffff); | |
1787 | /* PCXI = new_PCXI; */ | |
1788 | env->PCXI = new_PCXI; | |
1789 | /* write psw */ | |
1790 | psw_write(env, new_PSW); | |
1791 | } | |
1792 | ||
59543d4e BK |
1793 | void helper_ldlcx(CPUTriCoreState *env, uint32_t ea) |
1794 | { | |
1795 | uint32_t dummy; | |
1796 | /* insn doesn't load PCXI and RA */ | |
1797 | restore_context_lower(env, ea, &dummy, &dummy); | |
1798 | } | |
1799 | ||
1800 | void helper_lducx(CPUTriCoreState *env, uint32_t ea) | |
1801 | { | |
1802 | uint32_t dummy; | |
1803 | /* insn doesn't load PCXI and PSW */ | |
1804 | restore_context_upper(env, ea, &dummy, &dummy); | |
1805 | } | |
1806 | ||
1807 | void helper_stlcx(CPUTriCoreState *env, uint32_t ea) | |
1808 | { | |
1809 | save_context_lower(env, ea); | |
1810 | } | |
1811 | ||
1812 | void helper_stucx(CPUTriCoreState *env, uint32_t ea) | |
1813 | { | |
1814 | save_context_upper(env, ea); | |
1815 | } | |
1816 | ||
2b2f7d97 BK |
1817 | void helper_psw_write(CPUTriCoreState *env, uint32_t arg) |
1818 | { | |
1819 | psw_write(env, arg); | |
1820 | } | |
1821 | ||
1822 | uint32_t helper_psw_read(CPUTriCoreState *env) | |
1823 | { | |
1824 | return psw_read(env); | |
1825 | } | |
1826 | ||
1827 | ||
2d30267e BK |
1828 | static inline void QEMU_NORETURN do_raise_exception_err(CPUTriCoreState *env, |
1829 | uint32_t exception, | |
1830 | int error_code, | |
1831 | uintptr_t pc) | |
1832 | { | |
1833 | CPUState *cs = CPU(tricore_env_get_cpu(env)); | |
1834 | cs->exception_index = exception; | |
1835 | env->error_code = error_code; | |
1836 | ||
1837 | if (pc) { | |
1838 | /* now we have a real cpu fault */ | |
1839 | cpu_restore_state(cs, pc); | |
1840 | } | |
1841 | ||
1842 | cpu_loop_exit(cs); | |
1843 | } | |
1844 | ||
48e06fe0 BK |
1845 | void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, |
1846 | uintptr_t retaddr) | |
1847 | { | |
2d30267e BK |
1848 | int ret; |
1849 | ret = cpu_tricore_handle_mmu_fault(cs, addr, is_write, mmu_idx); | |
1850 | if (ret) { | |
1851 | TriCoreCPU *cpu = TRICORE_CPU(cs); | |
1852 | CPUTriCoreState *env = &cpu->env; | |
1853 | do_raise_exception_err(env, cs->exception_index, | |
1854 | env->error_code, retaddr); | |
1855 | } | |
48e06fe0 | 1856 | } |