2 * PPC emulation helpers for qemu.
4 * Copyright (c) 2003 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 void cpu_loop_exit(void)
26 longjmp(env->jmp_env, 1);
29 /* shortcuts to generate exceptions */
30 void raise_exception_err (int exception_index, int error_code)
32 env->exception_index = exception_index;
33 env->error_code = error_code;
38 void raise_exception (int exception_index)
40 env->exception_index = exception_index;
46 /* Helpers for "fat" micro operations */
47 uint32_t do_load_cr (void)
49 return (env->crf[0] << 28) |
59 void do_store_cr (uint32_t crn, uint32_t value)
63 for (i = 0, sh = 7; i < 8; i++, sh --) {
65 env->crf[i] = (value >> (sh * 4)) & 0xF;
69 uint32_t do_load_xer (void)
71 return (xer_so << XER_SO) |
77 void do_store_xer (uint32_t value)
79 xer_so = (value >> XER_SO) & 0x01;
80 xer_ov = (value >> XER_OV) & 0x01;
81 xer_ca = (value >> XER_CA) & 0x01;
82 xer_bc = (value >> XER_BC) & 0x1f;
85 uint32_t do_load_msr (void)
87 return (msr_pow << MSR_POW) |
88 (msr_ile << MSR_ILE) |
93 (msr_fe0 << MSR_FE0) |
96 (msr_fe1 << MSR_FE1) |
104 void do_store_msr (uint32_t msr_value)
106 msr_pow = (msr_value >> MSR_POW) & 0x03;
107 msr_ile = (msr_value >> MSR_ILE) & 0x01;
108 msr_ee = (msr_value >> MSR_EE) & 0x01;
109 msr_pr = (msr_value >> MSR_PR) & 0x01;
110 msr_fp = (msr_value >> MSR_FP) & 0x01;
111 msr_me = (msr_value >> MSR_ME) & 0x01;
112 msr_fe0 = (msr_value >> MSR_FE0) & 0x01;
113 msr_se = (msr_value >> MSR_SE) & 0x01;
114 msr_be = (msr_value >> MSR_BE) & 0x01;
115 msr_fe1 = (msr_value >> MSR_FE1) & 0x01;
116 msr_ip = (msr_value >> MSR_IP) & 0x01;
117 msr_ir = (msr_value >> MSR_IR) & 0x01;
118 msr_dr = (msr_value >> MSR_DR) & 0x01;
119 msr_ri = (msr_value >> MSR_RI) & 0x01;
120 msr_le = (msr_value >> MSR_LE) & 0x01;
123 /* The 32 MSB of the target fpr are undefined. They'll be zero... */
124 /* Floating point operations helpers */
125 void do_load_fpscr (void)
127 /* The 32 MSB of the target fpr are undefined.
140 for (i = 0; i < 8; i++)
141 u.s.u[1] |= env->fpscr[i] << (4 * i);
145 void do_store_fpscr (uint32_t mask)
148 * We use only the 32 LSB of the incoming fpr
160 env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.s.u[1] >> 28) & ~0x9);
161 for (i = 1; i < 7; i++) {
162 if (mask & (1 << (7 - i)))
163 env->fpscr[i] = (u.s.u[1] >> (4 * (7 - i))) & 0xF;
165 /* TODO: update FEX & VX */
166 /* Set rounding mode */
167 switch (env->fpscr[0] & 0x3) {
169 /* Best approximation (round to nearest) */
170 fesetround(FE_TONEAREST);
173 /* Smaller magnitude (round toward zero) */
174 fesetround(FE_TOWARDZERO);
177 /* Round toward +infinite */
178 fesetround(FE_UPWARD);
181 /* Round toward -infinite */
182 fesetround(FE_DOWNWARD);
187 int32_t do_sraw(int32_t value, uint32_t shift)
193 ret = (-1) * ((uint32_t)value >> 31);
197 ret = value >> (shift & 0x1f);
198 if (ret < 0 && (value & ((1 << shift) - 1)) != 0)
205 void do_lmw (int reg, uint32_t src)
207 for (; reg <= 31; reg++, src += 4)
208 ugpr(reg) = ld32(src);
211 void do_stmw (int reg, uint32_t dest)
213 for (; reg <= 31; reg++, dest += 4)
214 st32(dest, ugpr(reg));
217 void do_lsw (uint32_t reg, int count, uint32_t src)
222 for (; count > 3; count -= 4, src += 4) {
223 ugpr(reg++) = ld32(src);
229 for (sh = 24; count > 0; count--, src++, sh -= 8) {
230 tmp |= ld8(src) << sh;
236 void do_stsw (uint32_t reg, int count, uint32_t dest)
240 for (; count > 3; count -= 4, dest += 4) {
241 st32(dest, ugpr(reg++));
246 for (sh = 24; count > 0; count--, dest++, sh -= 8) {
247 st8(dest, (ugpr(reg) >> sh) & 0xFF);
256 /* Assume cache line size is 32 */
257 for (i = 0; i < 8; i++) {
263 /* Instruction cache invalidation helper */
266 tb_invalidate_page(T0);