/[gxemul]/upstream/0.4.1/src/cpus/cpu_mips_instr_loadstore.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.1/src/cpus/cpu_mips_instr_loadstore.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations)
Mon Oct 8 16:20:32 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 7641 byte(s)
0.4.1
1 /*
2 * Copyright (C) 2006 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: cpu_mips_instr_loadstore.c,v 1.11 2006/05/20 08:03:30 debug Exp $
29 *
30 * MIPS load/store instructions; the following args are used:
31 *
32 * arg[0] = pointer to the register to load to or store from
33 * arg[1] = pointer to the base register
34 * arg[2] = offset (as an int32_t)
35 *
36 * The GENERIC function always checks for alignment, and supports both big
37 * and little endian byte order.
38 *
39 * The quick function is included twice (big/little endian) for each
40 * GENERIC function.
41 */
42
43
44 #ifdef LS_INCLUDE_GENERIC
45 void LS_GENERIC_N(struct cpu *cpu, struct mips_instr_call *ic)
46 {
47 MODE_int_t addr = reg(ic->arg[1]) + (int32_t)ic->arg[2];
48 uint8_t data[LS_SIZE];
49 #ifdef LS_LOAD
50 uint64_t x;
51 #endif
52
53 /* Synchronize the PC: */
54 int low_pc = ((size_t)ic - (size_t)cpu->cd.mips.cur_ic_page)
55 / sizeof(struct mips_instr_call);
56 cpu->pc &= ~((MIPS_IC_ENTRIES_PER_PAGE-1)<<MIPS_INSTR_ALIGNMENT_SHIFT);
57 cpu->pc += (low_pc << MIPS_INSTR_ALIGNMENT_SHIFT);
58
59 #ifndef LS_1
60 /* Check alignment: */
61 if (addr & (LS_SIZE - 1)) {
62 fatal("TODO: mips dyntrans alignment exception, size = %i,"
63 " addr = %016"PRIx64", pc = %016"PRIx64"\n", LS_SIZE,
64 (uint64_t) addr, cpu->pc);
65
66 /* TODO: Generalize this into a abort_call, or similar: */
67 cpu->running = 0;
68 cpu->dead = 1;
69 debugger_n_steps_left_before_interaction = 0;
70 cpu->running_translated = 0;
71 cpu->cd.mips.next_ic = &nothing_call;
72 return;
73 }
74 #endif
75
76 #ifdef LS_LOAD
77 if (!cpu->memory_rw(cpu, cpu->mem, addr, data, sizeof(data),
78 MEM_READ, CACHE_DATA)) {
79 /* Exception. */
80 return;
81 }
82 x = memory_readmax64(cpu, data, LS_SIZE);
83 #ifdef LS_SIGNED
84 #ifdef LS_1
85 x = (int8_t)x;
86 #endif
87 #ifdef LS_2
88 x = (int16_t)x;
89 #endif
90 #ifdef LS_4
91 x = (int32_t)x;
92 #endif
93 #endif
94 reg(ic->arg[0]) = x;
95 #else /* LS_STORE: */
96 memory_writemax64(cpu, data, LS_SIZE, reg(ic->arg[0]));
97 if (!cpu->memory_rw(cpu, cpu->mem, addr, data, sizeof(data),
98 MEM_WRITE, CACHE_DATA)) {
99 /* Exception. */
100 return;
101 }
102 #endif
103 }
104 #endif /* LS_INCLUDE_GENERIC */
105
106
107 void LS_N(struct cpu *cpu, struct mips_instr_call *ic)
108 {
109 MODE_uint_t addr = reg(ic->arg[1]) + (int32_t)ic->arg[2];
110 unsigned char *p;
111 #ifdef MODE32
112 #ifdef LS_LOAD
113 p = cpu->cd.mips.host_load[addr >> 12];
114 #else
115 p = cpu->cd.mips.host_store[addr >> 12];
116 #endif
117 #else /* !MODE32 */
118 const uint32_t mask1 = (1 << DYNTRANS_L1N) - 1;
119 const uint32_t mask2 = (1 << DYNTRANS_L2N) - 1;
120 const uint32_t mask3 = (1 << DYNTRANS_L3N) - 1;
121 uint32_t x1, x2, x3;
122 struct DYNTRANS_L2_64_TABLE *l2;
123 struct DYNTRANS_L3_64_TABLE *l3;
124
125 x1 = (addr >> (64-DYNTRANS_L1N)) & mask1;
126 x2 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N)) & mask2;
127 x3 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N-DYNTRANS_L3N)) & mask3;
128 /* fatal("X3: addr=%016"PRIx64" x1=%x x2=%x x3=%x\n",
129 (uint64_t) addr, (int) x1, (int) x2, (int) x3); */
130 l2 = cpu->cd.DYNTRANS_ARCH.l1_64[x1];
131 /* fatal(" l2 = %p\n", l2); */
132 l3 = l2->l3[x2];
133 /* fatal(" l3 = %p\n", l3); */
134 #ifdef LS_LOAD
135 p = l3->host_load[x3];
136 #else
137 p = l3->host_store[x3];
138 #endif
139 /* fatal(" p = %p\n", p); */
140 #endif
141
142 if (p == NULL
143 #ifndef LS_1
144 || addr & (LS_SIZE - 1)
145 #endif
146 ) {
147 LS_GENERIC_N(cpu, ic);
148 return;
149 }
150
151 addr &= 0xfff;
152
153 #ifdef LS_LOAD
154 /* Load: */
155
156 #ifdef LS_1
157 reg(ic->arg[0]) =
158 #ifdef LS_SIGNED
159 (int8_t)
160 #endif
161 p[addr];
162 #endif /* LS_1 */
163
164 #ifdef LS_2
165 reg(ic->arg[0]) =
166 #ifdef LS_SIGNED
167 (int16_t)
168 #endif
169 #ifdef LS_BE
170 #ifdef HOST_BIG_ENDIAN
171 ( *(uint16_t *)(p + addr) );
172 #else
173 ((p[addr]<<8) + p[addr+1]);
174 #endif
175 #else
176 #ifdef HOST_LITTLE_ENDIAN
177 ( *(uint16_t *)(p + addr) );
178 #else
179 (p[addr] + (p[addr+1]<<8));
180 #endif
181 #endif
182 #endif /* LS_2 */
183
184 #ifdef LS_4
185 reg(ic->arg[0]) =
186 #ifdef LS_SIGNED
187 (int32_t)
188 #else
189 (uint32_t)
190 #endif
191 #ifdef LS_BE
192 #ifdef HOST_BIG_ENDIAN
193 ( *(uint32_t *)(p + addr) );
194 #else
195 ((p[addr]<<24) + (p[addr+1]<<16) + (p[addr+2]<<8) + p[addr+3]);
196 #endif
197 #else
198 #ifdef HOST_LITTLE_ENDIAN
199 ( *(uint32_t *)(p + addr) );
200 #else
201 (p[addr] + (p[addr+1]<<8) + (p[addr+2]<<16) + (p[addr+3]<<24));
202 #endif
203 #endif
204 #endif /* LS_4 */
205
206 #ifdef LS_8
207 *((uint64_t *)ic->arg[0]) =
208 #ifdef LS_BE
209 #ifdef HOST_BIG_ENDIAN
210 ( *(uint64_t *)(p + addr) );
211 #else
212 ((uint64_t)p[addr] << 56) + ((uint64_t)p[addr+1] << 48) +
213 ((uint64_t)p[addr+2] << 40) + ((uint64_t)p[addr+3] << 32) +
214 ((uint64_t)p[addr+4] << 24) +
215 (p[addr+5] << 16) + (p[addr+6] << 8) + p[addr+7];
216 #endif
217 #else
218 #ifdef HOST_LITTLE_ENDIAN
219 ( *(uint64_t *)(p + addr) );
220 #else
221 p[addr+0] + (p[addr+1] << 8) + (p[addr+2] << 16) +
222 ((uint64_t)p[addr+3] << 24) + ((uint64_t)p[addr+4] << 32) +
223 ((uint64_t)p[addr+5] << 40) + ((uint64_t)p[addr+6] << 48) +
224 ((uint64_t)p[addr+7] << 56);
225 #endif
226 #endif
227 #endif /* LS_8 */
228
229 #else
230 /* Store: */
231
232 #ifdef LS_1
233 p[addr] = reg(ic->arg[0]);
234 #endif
235 #ifdef LS_2
236 { uint32_t x = reg(ic->arg[0]);
237 #ifdef LS_BE
238 #ifdef HOST_BIG_ENDIAN
239 *((uint16_t *)(p+addr)) = x; }
240 #else
241 p[addr] = x >> 8; p[addr+1] = x; }
242 #endif
243 #else
244 #ifdef HOST_LITTLE_ENDIAN
245 *((uint16_t *)(p+addr)) = x; }
246 #else
247 p[addr] = x; p[addr+1] = x >> 8; }
248 #endif
249 #endif
250 #endif /* LS_2 */
251 #ifdef LS_4
252 { uint32_t x = reg(ic->arg[0]);
253 #ifdef LS_BE
254 #ifdef HOST_BIG_ENDIAN
255 *((uint32_t *)(p+addr)) = x; }
256 #else
257 p[addr] = x >> 24; p[addr+1] = x >> 16;
258 p[addr+2] = x >> 8; p[addr+3] = x; }
259 #endif
260 #else
261 #ifdef HOST_LITTLE_ENDIAN
262 *((uint32_t *)(p+addr)) = x; }
263 #else
264 p[addr] = x; p[addr+1] = x >> 8;
265 p[addr+2] = x >> 16; p[addr+3] = x >> 24; }
266 #endif
267 #endif
268 #endif /* LS_4 */
269 #ifdef LS_8
270 { uint64_t x = *(uint64_t *)(ic->arg[0]);
271 #ifdef LS_BE
272 #ifdef HOST_BIG_ENDIAN
273 *((uint64_t *)(p+addr)) = x; }
274 #else
275 p[addr] = x >> 56; p[addr+1] = x >> 48; p[addr+2] = x >> 40;
276 p[addr+3] = x >> 32; p[addr+4] = x >> 24; p[addr+5] = x >> 16;
277 p[addr+6] = x >> 8; p[addr+7] = x; }
278 #endif
279 #else
280 #ifdef HOST_LITTLE_ENDIAN
281 *((uint64_t *)(p+addr)) = x; }
282 #else
283 p[addr] = x; p[addr+1] = x >> 8; p[addr+2] = x >> 16;
284 p[addr+3] = x >> 24; p[addr+4] = x >> 32; p[addr+5] = x >> 40;
285 p[addr+6] = x >> 48; p[addr+7] = x >> 56; }
286 #endif
287 #endif
288 #endif /* LS_8 */
289
290 #endif /* store */
291 }
292

  ViewVC Help
Powered by ViewVC 1.1.26