2 * UniCore32 helper routines
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or (at your option) any
9 * later version. See the COPYING file in the top-level directory.
14 #define SIGNBIT (uint32_t)0x80000000
15 #define SIGNBIT64 ((uint64_t)1 << 63)
17 void HELPER(exception
)(CPUUniCore32State
*env
, uint32_t excp
)
19 env
->exception_index
= excp
;
23 static target_ulong
asr_read(CPUUniCore32State
*env
)
27 return env
->uncached_asr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
28 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3);
31 target_ulong
cpu_asr_read(CPUUniCore32State
*env
)
36 target_ulong
HELPER(asr_read
)(CPUUniCore32State
*env
)
41 static void asr_write(CPUUniCore32State
*env
, target_ulong val
,
44 if (mask
& ASR_NZCV
) {
45 env
->ZF
= (~val
) & ASR_Z
;
47 env
->CF
= (val
>> 29) & 1;
48 env
->VF
= (val
<< 3) & 0x80000000;
51 if ((env
->uncached_asr
^ val
) & mask
& ASR_M
) {
52 switch_mode(env
, val
& ASR_M
);
55 env
->uncached_asr
= (env
->uncached_asr
& ~mask
) | (val
& mask
);
58 void cpu_asr_write(CPUUniCore32State
*env
, target_ulong val
, target_ulong mask
)
60 asr_write(env
, val
, mask
);
63 void HELPER(asr_write
)(CPUUniCore32State
*env
, target_ulong val
,
66 asr_write(env
, val
, mask
);
69 /* Access to user mode registers from privileged modes. */
70 uint32_t HELPER(get_user_reg
)(CPUUniCore32State
*env
, uint32_t regno
)
75 val
= env
->banked_r29
[0];
76 } else if (regno
== 30) {
77 val
= env
->banked_r30
[0];
79 val
= env
->regs
[regno
];
84 void HELPER(set_user_reg
)(CPUUniCore32State
*env
, uint32_t regno
, uint32_t val
)
87 env
->banked_r29
[0] = val
;
88 } else if (regno
== 30) {
89 env
->banked_r30
[0] = val
;
91 env
->regs
[regno
] = val
;
95 /* ??? Flag setting arithmetic is awkward because we need to do comparisons.
96 The only way to do that in TCG is a conditional branch, which clobbers
97 all our temporaries. For now implement these as helper functions. */
99 uint32_t HELPER(add_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
103 env
->NF
= env
->ZF
= result
;
104 env
->CF
= result
< a
;
105 env
->VF
= (a
^ b
^ -1) & (a
^ result
);
109 uint32_t HELPER(adc_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
114 env
->CF
= result
< a
;
117 env
->CF
= result
<= a
;
119 env
->VF
= (a
^ b
^ -1) & (a
^ result
);
120 env
->NF
= env
->ZF
= result
;
124 uint32_t HELPER(sub_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
128 env
->NF
= env
->ZF
= result
;
130 env
->VF
= (a
^ b
) & (a
^ result
);
134 uint32_t HELPER(sbc_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
144 env
->VF
= (a
^ b
) & (a
^ result
);
145 env
->NF
= env
->ZF
= result
;
149 /* Similarly for variable shift instructions. */
151 uint32_t HELPER(shl
)(uint32_t x
, uint32_t i
)
153 int shift
= i
& 0xff;
160 uint32_t HELPER(shr
)(uint32_t x
, uint32_t i
)
162 int shift
= i
& 0xff;
166 return (uint32_t)x
>> shift
;
169 uint32_t HELPER(sar
)(uint32_t x
, uint32_t i
)
171 int shift
= i
& 0xff;
175 return (int32_t)x
>> shift
;
178 uint32_t HELPER(shl_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
180 int shift
= i
& 0xff;
188 } else if (shift
!= 0) {
189 env
->CF
= (x
>> (32 - shift
)) & 1;
195 uint32_t HELPER(shr_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
197 int shift
= i
& 0xff;
200 env
->CF
= (x
>> 31) & 1;
205 } else if (shift
!= 0) {
206 env
->CF
= (x
>> (shift
- 1)) & 1;
212 uint32_t HELPER(sar_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
214 int shift
= i
& 0xff;
216 env
->CF
= (x
>> 31) & 1;
217 return (int32_t)x
>> 31;
218 } else if (shift
!= 0) {
219 env
->CF
= (x
>> (shift
- 1)) & 1;
220 return (int32_t)x
>> shift
;
225 uint32_t HELPER(ror_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
229 shift
= shift1
& 0x1f;
232 env
->CF
= (x
>> 31) & 1;
236 env
->CF
= (x
>> (shift
- 1)) & 1;
237 return ((uint32_t)x
>> shift
) | (x
<< (32 - shift
));
241 #ifndef CONFIG_USER_ONLY
242 #define MMUSUFFIX _mmu
245 #include "exec/softmmu_template.h"
248 #include "exec/softmmu_template.h"
251 #include "exec/softmmu_template.h"
254 #include "exec/softmmu_template.h"
256 void tlb_fill(CPUUniCore32State
*env
, target_ulong addr
, int is_write
,
257 int mmu_idx
, uintptr_t retaddr
)
261 ret
= uc32_cpu_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
264 /* now we have a real cpu fault */
265 cpu_restore_state(env
, retaddr
);