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 CPUState
*cs
= CPU(uc32_env_get_cpu(env
));
21 cs
->exception_index
= excp
;
25 static target_ulong
asr_read(CPUUniCore32State
*env
)
29 return env
->uncached_asr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
30 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3);
33 target_ulong
cpu_asr_read(CPUUniCore32State
*env
)
38 target_ulong
HELPER(asr_read
)(CPUUniCore32State
*env
)
43 static void asr_write(CPUUniCore32State
*env
, target_ulong val
,
46 if (mask
& ASR_NZCV
) {
47 env
->ZF
= (~val
) & ASR_Z
;
49 env
->CF
= (val
>> 29) & 1;
50 env
->VF
= (val
<< 3) & 0x80000000;
53 if ((env
->uncached_asr
^ val
) & mask
& ASR_M
) {
54 switch_mode(env
, val
& ASR_M
);
57 env
->uncached_asr
= (env
->uncached_asr
& ~mask
) | (val
& mask
);
60 void cpu_asr_write(CPUUniCore32State
*env
, target_ulong val
, target_ulong mask
)
62 asr_write(env
, val
, mask
);
65 void HELPER(asr_write
)(CPUUniCore32State
*env
, target_ulong val
,
68 asr_write(env
, val
, mask
);
71 /* Access to user mode registers from privileged modes. */
72 uint32_t HELPER(get_user_reg
)(CPUUniCore32State
*env
, uint32_t regno
)
77 val
= env
->banked_r29
[0];
78 } else if (regno
== 30) {
79 val
= env
->banked_r30
[0];
81 val
= env
->regs
[regno
];
86 void HELPER(set_user_reg
)(CPUUniCore32State
*env
, uint32_t regno
, uint32_t val
)
89 env
->banked_r29
[0] = val
;
90 } else if (regno
== 30) {
91 env
->banked_r30
[0] = val
;
93 env
->regs
[regno
] = val
;
97 /* ??? Flag setting arithmetic is awkward because we need to do comparisons.
98 The only way to do that in TCG is a conditional branch, which clobbers
99 all our temporaries. For now implement these as helper functions. */
101 uint32_t HELPER(add_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
105 env
->NF
= env
->ZF
= result
;
106 env
->CF
= result
< a
;
107 env
->VF
= (a
^ b
^ -1) & (a
^ result
);
111 uint32_t HELPER(adc_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
116 env
->CF
= result
< a
;
119 env
->CF
= result
<= a
;
121 env
->VF
= (a
^ b
^ -1) & (a
^ result
);
122 env
->NF
= env
->ZF
= result
;
126 uint32_t HELPER(sub_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
130 env
->NF
= env
->ZF
= result
;
132 env
->VF
= (a
^ b
) & (a
^ result
);
136 uint32_t HELPER(sbc_cc
)(CPUUniCore32State
*env
, uint32_t a
, uint32_t b
)
146 env
->VF
= (a
^ b
) & (a
^ result
);
147 env
->NF
= env
->ZF
= result
;
151 /* Similarly for variable shift instructions. */
153 uint32_t HELPER(shl
)(uint32_t x
, uint32_t i
)
155 int shift
= i
& 0xff;
162 uint32_t HELPER(shr
)(uint32_t x
, uint32_t i
)
164 int shift
= i
& 0xff;
168 return (uint32_t)x
>> shift
;
171 uint32_t HELPER(sar
)(uint32_t x
, uint32_t i
)
173 int shift
= i
& 0xff;
177 return (int32_t)x
>> shift
;
180 uint32_t HELPER(shl_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
182 int shift
= i
& 0xff;
190 } else if (shift
!= 0) {
191 env
->CF
= (x
>> (32 - shift
)) & 1;
197 uint32_t HELPER(shr_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
199 int shift
= i
& 0xff;
202 env
->CF
= (x
>> 31) & 1;
207 } else if (shift
!= 0) {
208 env
->CF
= (x
>> (shift
- 1)) & 1;
214 uint32_t HELPER(sar_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
216 int shift
= i
& 0xff;
218 env
->CF
= (x
>> 31) & 1;
219 return (int32_t)x
>> 31;
220 } else if (shift
!= 0) {
221 env
->CF
= (x
>> (shift
- 1)) & 1;
222 return (int32_t)x
>> shift
;
227 uint32_t HELPER(ror_cc
)(CPUUniCore32State
*env
, uint32_t x
, uint32_t i
)
231 shift
= shift1
& 0x1f;
234 env
->CF
= (x
>> 31) & 1;
238 env
->CF
= (x
>> (shift
- 1)) & 1;
239 return ((uint32_t)x
>> shift
) | (x
<< (32 - shift
));
243 #ifndef CONFIG_USER_ONLY
244 #include "exec/softmmu_exec.h"
246 #define MMUSUFFIX _mmu
249 #include "exec/softmmu_template.h"
252 #include "exec/softmmu_template.h"
255 #include "exec/softmmu_template.h"
258 #include "exec/softmmu_template.h"
260 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
,
261 int mmu_idx
, uintptr_t retaddr
)
265 ret
= uc32_cpu_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
268 /* now we have a real cpu fault */
269 cpu_restore_state(cs
, retaddr
);