2 * UniCore32 helper routines
4 * Copyright (C) 2010-2011 GUAN Xue-tao
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.
13 #define SIGNBIT (uint32_t)0x80000000
14 #define SIGNBIT64 ((uint64_t)1 << 63)
16 void HELPER(exception)(uint32_t excp)
18 env->exception_index = excp;
22 static target_ulong asr_read(void)
26 return env->uncached_asr | (env->NF & 0x80000000) | (ZF << 30) |
27 (env->CF << 29) | ((env->VF & 0x80000000) >> 3);
30 target_ulong cpu_asr_read(CPUState *env1)
42 target_ulong HELPER(asr_read)(void)
47 static void asr_write(target_ulong val, target_ulong mask)
49 if (mask & ASR_NZCV) {
50 env->ZF = (~val) & ASR_Z;
52 env->CF = (val >> 29) & 1;
53 env->VF = (val << 3) & 0x80000000;
56 if ((env->uncached_asr ^ val) & mask & ASR_M) {
57 switch_mode(env, val & ASR_M);
60 env->uncached_asr = (env->uncached_asr & ~mask) | (val & mask);
63 void cpu_asr_write(CPUState *env1, target_ulong val, target_ulong mask)
73 void HELPER(asr_write)(target_ulong val, target_ulong mask)
78 /* Access to user mode registers from privileged modes. */
79 uint32_t HELPER(get_user_reg)(uint32_t regno)
84 val = env->banked_r29[0];
85 } else if (regno == 30) {
86 val = env->banked_r30[0];
88 val = env->regs[regno];
93 void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
96 env->banked_r29[0] = val;
97 } else if (regno == 30) {
98 env->banked_r30[0] = val;
100 env->regs[regno] = val;
104 /* ??? Flag setting arithmetic is awkward because we need to do comparisons.
105 The only way to do that in TCG is a conditional branch, which clobbers
106 all our temporaries. For now implement these as helper functions. */
108 uint32_t HELPER(add_cc)(uint32_t a, uint32_t b)
112 env->NF = env->ZF = result;
113 env->CF = result < a;
114 env->VF = (a ^ b ^ -1) & (a ^ result);
118 uint32_t HELPER(adc_cc)(uint32_t a, uint32_t b)
123 env->CF = result < a;
126 env->CF = result <= a;
128 env->VF = (a ^ b ^ -1) & (a ^ result);
129 env->NF = env->ZF = result;
133 uint32_t HELPER(sub_cc)(uint32_t a, uint32_t b)
137 env->NF = env->ZF = result;
139 env->VF = (a ^ b) & (a ^ result);
143 uint32_t HELPER(sbc_cc)(uint32_t a, uint32_t b)
153 env->VF = (a ^ b) & (a ^ result);
154 env->NF = env->ZF = result;
158 /* Similarly for variable shift instructions. */
160 uint32_t HELPER(shl)(uint32_t x, uint32_t i)
162 int shift = i & 0xff;
169 uint32_t HELPER(shr)(uint32_t x, uint32_t i)
171 int shift = i & 0xff;
175 return (uint32_t)x >> shift;
178 uint32_t HELPER(sar)(uint32_t x, uint32_t i)
180 int shift = i & 0xff;
184 return (int32_t)x >> shift;
187 uint32_t HELPER(shl_cc)(uint32_t x, uint32_t i)
189 int shift = i & 0xff;
197 } else if (shift != 0) {
198 env->CF = (x >> (32 - shift)) & 1;
204 uint32_t HELPER(shr_cc)(uint32_t x, uint32_t i)
206 int shift = i & 0xff;
209 env->CF = (x >> 31) & 1;
214 } else if (shift != 0) {
215 env->CF = (x >> (shift - 1)) & 1;
221 uint32_t HELPER(sar_cc)(uint32_t x, uint32_t i)
223 int shift = i & 0xff;
225 env->CF = (x >> 31) & 1;
226 return (int32_t)x >> 31;
227 } else if (shift != 0) {
228 env->CF = (x >> (shift - 1)) & 1;
229 return (int32_t)x >> shift;
234 uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
238 shift = shift1 & 0x1f;
241 env->CF = (x >> 31) & 1;
245 env->CF = (x >> (shift - 1)) & 1;
246 return ((uint32_t)x >> shift) | (x << (32 - shift));