Fix hw/acpi.c build w/ DEBUG enabled
[qemu-kvm/fedora.git] / target-mips / op_mem.c
blob4b889a88dbe4b28ffb7e032293a656159e817f82
1 /*
2 * MIPS emulation memory micro-operations for qemu.
4 * Copyright (c) 2004-2005 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
21 /* "half" load and stores. We must do the memory access inline,
22 or fault handling won't work. */
24 #ifdef TARGET_WORDS_BIGENDIAN
25 #define GET_LMASK(v) ((v) & 3)
26 #define GET_OFFSET(addr, offset) (addr + (offset))
27 #else
28 #define GET_LMASK(v) (((v) & 3) ^ 3)
29 #define GET_OFFSET(addr, offset) (addr - (offset))
30 #endif
32 void glue(op_lwl, MEMSUFFIX) (void)
34 target_ulong tmp;
36 tmp = glue(ldub, MEMSUFFIX)(T0);
37 T1 = (T1 & 0x00FFFFFF) | (tmp << 24);
39 if (GET_LMASK(T0) <= 2) {
40 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 1));
41 T1 = (T1 & 0xFF00FFFF) | (tmp << 16);
44 if (GET_LMASK(T0) <= 1) {
45 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 2));
46 T1 = (T1 & 0xFFFF00FF) | (tmp << 8);
49 if (GET_LMASK(T0) == 0) {
50 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 3));
51 T1 = (T1 & 0xFFFFFF00) | tmp;
53 T1 = (int32_t)T1;
54 FORCE_RET();
57 void glue(op_lwr, MEMSUFFIX) (void)
59 target_ulong tmp;
61 tmp = glue(ldub, MEMSUFFIX)(T0);
62 T1 = (T1 & 0xFFFFFF00) | tmp;
64 if (GET_LMASK(T0) >= 1) {
65 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -1));
66 T1 = (T1 & 0xFFFF00FF) | (tmp << 8);
69 if (GET_LMASK(T0) >= 2) {
70 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -2));
71 T1 = (T1 & 0xFF00FFFF) | (tmp << 16);
74 if (GET_LMASK(T0) == 3) {
75 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -3));
76 T1 = (T1 & 0x00FFFFFF) | (tmp << 24);
78 T1 = (int32_t)T1;
79 FORCE_RET();
82 void glue(op_swl, MEMSUFFIX) (void)
84 glue(stb, MEMSUFFIX)(T0, (uint8_t)(T1 >> 24));
86 if (GET_LMASK(T0) <= 2)
87 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 1), (uint8_t)(T1 >> 16));
89 if (GET_LMASK(T0) <= 1)
90 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 2), (uint8_t)(T1 >> 8));
92 if (GET_LMASK(T0) == 0)
93 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 3), (uint8_t)T1);
95 FORCE_RET();
98 void glue(op_swr, MEMSUFFIX) (void)
100 glue(stb, MEMSUFFIX)(T0, (uint8_t)T1);
102 if (GET_LMASK(T0) >= 1)
103 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -1), (uint8_t)(T1 >> 8));
105 if (GET_LMASK(T0) >= 2)
106 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -2), (uint8_t)(T1 >> 16));
108 if (GET_LMASK(T0) == 3)
109 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -3), (uint8_t)(T1 >> 24));
111 FORCE_RET();
114 #if defined(TARGET_MIPS64)
115 /* "half" load and stores. We must do the memory access inline,
116 or fault handling won't work. */
118 #ifdef TARGET_WORDS_BIGENDIAN
119 #define GET_LMASK64(v) ((v) & 7)
120 #else
121 #define GET_LMASK64(v) (((v) & 7) ^ 7)
122 #endif
124 void glue(op_ldl, MEMSUFFIX) (void)
126 uint64_t tmp;
128 tmp = glue(ldub, MEMSUFFIX)(T0);
129 T1 = (T1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
131 if (GET_LMASK64(T0) <= 6) {
132 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 1));
133 T1 = (T1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
136 if (GET_LMASK64(T0) <= 5) {
137 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 2));
138 T1 = (T1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
141 if (GET_LMASK64(T0) <= 4) {
142 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 3));
143 T1 = (T1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
146 if (GET_LMASK64(T0) <= 3) {
147 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 4));
148 T1 = (T1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
151 if (GET_LMASK64(T0) <= 2) {
152 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 5));
153 T1 = (T1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
156 if (GET_LMASK64(T0) <= 1) {
157 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 6));
158 T1 = (T1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
161 if (GET_LMASK64(T0) == 0) {
162 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, 7));
163 T1 = (T1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
166 FORCE_RET();
169 void glue(op_ldr, MEMSUFFIX) (void)
171 uint64_t tmp;
173 tmp = glue(ldub, MEMSUFFIX)(T0);
174 T1 = (T1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
176 if (GET_LMASK64(T0) >= 1) {
177 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -1));
178 T1 = (T1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
181 if (GET_LMASK64(T0) >= 2) {
182 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -2));
183 T1 = (T1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
186 if (GET_LMASK64(T0) >= 3) {
187 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -3));
188 T1 = (T1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
191 if (GET_LMASK64(T0) >= 4) {
192 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -4));
193 T1 = (T1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
196 if (GET_LMASK64(T0) >= 5) {
197 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -5));
198 T1 = (T1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
201 if (GET_LMASK64(T0) >= 6) {
202 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -6));
203 T1 = (T1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
206 if (GET_LMASK64(T0) == 7) {
207 tmp = glue(ldub, MEMSUFFIX)(GET_OFFSET(T0, -7));
208 T1 = (T1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
211 FORCE_RET();
214 void glue(op_sdl, MEMSUFFIX) (void)
216 glue(stb, MEMSUFFIX)(T0, (uint8_t)(T1 >> 56));
218 if (GET_LMASK64(T0) <= 6)
219 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 1), (uint8_t)(T1 >> 48));
221 if (GET_LMASK64(T0) <= 5)
222 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 2), (uint8_t)(T1 >> 40));
224 if (GET_LMASK64(T0) <= 4)
225 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 3), (uint8_t)(T1 >> 32));
227 if (GET_LMASK64(T0) <= 3)
228 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 4), (uint8_t)(T1 >> 24));
230 if (GET_LMASK64(T0) <= 2)
231 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 5), (uint8_t)(T1 >> 16));
233 if (GET_LMASK64(T0) <= 1)
234 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 6), (uint8_t)(T1 >> 8));
236 if (GET_LMASK64(T0) <= 0)
237 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, 7), (uint8_t)T1);
239 FORCE_RET();
242 void glue(op_sdr, MEMSUFFIX) (void)
244 glue(stb, MEMSUFFIX)(T0, (uint8_t)T1);
246 if (GET_LMASK64(T0) >= 1)
247 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -1), (uint8_t)(T1 >> 8));
249 if (GET_LMASK64(T0) >= 2)
250 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -2), (uint8_t)(T1 >> 16));
252 if (GET_LMASK64(T0) >= 3)
253 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -3), (uint8_t)(T1 >> 24));
255 if (GET_LMASK64(T0) >= 4)
256 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -4), (uint8_t)(T1 >> 32));
258 if (GET_LMASK64(T0) >= 5)
259 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -5), (uint8_t)(T1 >> 40));
261 if (GET_LMASK64(T0) >= 6)
262 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -6), (uint8_t)(T1 >> 48));
264 if (GET_LMASK64(T0) == 7)
265 glue(stb, MEMSUFFIX)(GET_OFFSET(T0, -7), (uint8_t)(T1 >> 56));
267 FORCE_RET();
269 #endif /* TARGET_MIPS64 */
271 void glue(op_lwc1, MEMSUFFIX) (void)
273 WT0 = glue(ldl, MEMSUFFIX)(T0);
274 FORCE_RET();
276 void glue(op_swc1, MEMSUFFIX) (void)
278 glue(stl, MEMSUFFIX)(T0, WT0);
279 FORCE_RET();
281 void glue(op_ldc1, MEMSUFFIX) (void)
283 DT0 = glue(ldq, MEMSUFFIX)(T0);
284 FORCE_RET();
286 void glue(op_sdc1, MEMSUFFIX) (void)
288 glue(stq, MEMSUFFIX)(T0, DT0);
289 FORCE_RET();
291 void glue(op_luxc1, MEMSUFFIX) (void)
293 DT0 = glue(ldq, MEMSUFFIX)(T0 & ~0x7);
294 FORCE_RET();
296 void glue(op_suxc1, MEMSUFFIX) (void)
298 glue(stq, MEMSUFFIX)(T0 & ~0x7, DT0);
299 FORCE_RET();