1 |
/* |
/* |
2 |
* Copyright (C) 2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_alpha_instr_loadstore.c,v 1.2 2005/11/22 17:52:58 debug Exp $ |
* $Id: cpu_alpha_instr_loadstore.c,v 1.5 2006/06/30 20:22:53 debug Exp $ |
29 |
* |
* |
30 |
* Alpha load/store instructions. (Included from cpu_alpha_instr_inc.c.) |
* Alpha load/store instructions. (Included from cpu_alpha_instr_inc.c.) |
31 |
* |
* |
43 |
|
|
44 |
|
|
45 |
#ifndef LS_IGNORE_OFFSET |
#ifndef LS_IGNORE_OFFSET |
|
#ifndef LS_ALIGN_CHECK |
|
46 |
static void LS_GENERIC_N(struct cpu *cpu, struct alpha_instr_call *ic) |
static void LS_GENERIC_N(struct cpu *cpu, struct alpha_instr_call *ic) |
47 |
{ |
{ |
48 |
#ifdef LS_B |
#ifdef LS_B |
124 |
#endif |
#endif |
125 |
} |
} |
126 |
#endif |
#endif |
|
#endif |
|
127 |
|
|
128 |
|
|
129 |
static void LS_N(struct cpu *cpu, struct alpha_instr_call *ic) |
static void LS_N(struct cpu *cpu, struct alpha_instr_call *ic) |
130 |
{ |
{ |
131 |
int first, a, b, c; |
unsigned char *page; |
132 |
uint64_t addr; |
uint64_t addr = (*((uint64_t *)ic->arg[1])) |
|
|
|
|
addr = (*((uint64_t *)ic->arg[1])) |
|
133 |
#ifndef LS_IGNORE_OFFSET |
#ifndef LS_IGNORE_OFFSET |
134 |
+ (int32_t)ic->arg[2] |
+ (int32_t)ic->arg[2] |
135 |
#endif |
#endif |
136 |
; |
; |
137 |
|
|
138 |
|
const uint32_t mask1 = (1 << DYNTRANS_L1N) - 1; |
139 |
|
const uint32_t mask2 = (1 << DYNTRANS_L2N) - 1; |
140 |
|
const uint32_t mask3 = (1 << DYNTRANS_L3N) - 1; |
141 |
|
uint32_t x1, x2, x3, c; |
142 |
|
struct DYNTRANS_L2_64_TABLE *l2; |
143 |
|
struct DYNTRANS_L3_64_TABLE *l3; |
144 |
|
x1 = (addr >> (64-DYNTRANS_L1N)) & mask1; |
145 |
|
x2 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N)) & mask2; |
146 |
|
x3 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N-DYNTRANS_L3N)) & mask3; |
147 |
|
/* fatal("X3: addr=%016"PRIx64" x1=%x x2=%x x3=%x\n", |
148 |
|
(uint64_t) addr, (int) x1, (int) x2, (int) x3); */ |
149 |
|
l2 = cpu->cd.DYNTRANS_ARCH.l1_64[x1]; |
150 |
|
/* fatal(" l2 = %p\n", l2); */ |
151 |
|
l3 = l2->l3[x2]; |
152 |
|
/* fatal(" l3 = %p\n", l3); */ |
153 |
|
#ifdef LS_LOAD |
154 |
|
page = l3->host_load[x3]; |
155 |
|
#else |
156 |
|
page = l3->host_store[x3]; |
157 |
|
#endif |
158 |
|
|
159 |
#ifdef LS_UNALIGNED |
#ifdef LS_UNALIGNED |
160 |
addr &= ~7; |
addr &= ~7; |
161 |
#endif |
#endif |
178 |
#endif |
#endif |
179 |
#endif |
#endif |
180 |
|
|
|
first = addr >> ALPHA_TOPSHIFT; |
|
|
a = (addr >> ALPHA_LEVEL0_SHIFT) & (ALPHA_LEVEL0 - 1); |
|
|
b = (addr >> ALPHA_LEVEL1_SHIFT) & (ALPHA_LEVEL1 - 1); |
|
181 |
c = addr & 8191; |
c = addr & 8191; |
182 |
|
|
|
#ifdef LS_ALIGN_CHECK |
|
183 |
#ifndef LS_B |
#ifndef LS_B |
184 |
if (c & |
if (c & |
185 |
#ifdef LS_W |
#ifdef LS_W |
197 |
} |
} |
198 |
else |
else |
199 |
#endif |
#endif |
|
#endif |
|
200 |
|
|
201 |
if (first == 0) { |
if (page != NULL) { |
|
struct alpha_vph_page *vph_p; |
|
|
unsigned char *page; |
|
|
vph_p = cpu->cd.alpha.vph_table0[a]; |
|
|
#ifdef LS_LOAD |
|
|
page = vph_p->host_load[b]; |
|
|
#else |
|
|
page = vph_p->host_store[b]; |
|
|
#endif |
|
|
if (page != NULL) { |
|
|
#ifdef LS_LOAD |
|
|
#ifdef HOST_BIG_ENDIAN |
|
|
uint64_t data_x; |
|
|
data_x = page[c]; |
|
|
#ifndef LS_B |
|
|
data_x += (page[c+1] << 8); |
|
|
#ifndef LS_W |
|
|
data_x += (page[c+2] << 16); |
|
|
data_x += ((uint64_t)page[c+3] << 24); |
|
|
#ifndef LS_L |
|
|
data_x += ((uint64_t)page[c+4] << 32); |
|
|
data_x += ((uint64_t)page[c+5] << 40); |
|
|
data_x += ((uint64_t)page[c+6] << 48); |
|
|
data_x += ((uint64_t)page[c+7] << 56); |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#ifdef LS_L |
|
|
*((uint64_t *)ic->arg[0]) = (int64_t)(int32_t)data_x; |
|
|
#else |
|
|
*((uint64_t *)ic->arg[0]) = data_x; |
|
|
#endif |
|
|
#else |
|
|
#ifdef LS_B |
|
|
*((uint64_t *)ic->arg[0]) = page[c]; |
|
|
#endif |
|
|
#ifdef LS_W |
|
|
uint16_t d = *((uint16_t *) (page + c)); |
|
|
*((uint64_t *)ic->arg[0]) = d; |
|
|
#endif |
|
|
#ifdef LS_L |
|
|
int32_t d = *((int32_t *) (page + c)); |
|
|
*((uint64_t *)ic->arg[0]) = (int64_t)d; |
|
|
#endif |
|
|
#ifdef LS_Q |
|
|
uint64_t d = *((uint64_t *) (page + c)); |
|
|
*((uint64_t *)ic->arg[0]) = d; |
|
|
#endif |
|
|
#endif |
|
|
#else |
|
|
/* Store: */ |
|
|
#ifdef HOST_BIG_ENDIAN |
|
|
uint64_t data_x = *((uint64_t *)ic->arg[0]); |
|
|
page[c] = data_x; |
|
|
#ifndef LS_B |
|
|
page[c+1] = data_x >> 8; |
|
|
#ifndef LS_W |
|
|
page[c+2] = data_x >> 16; |
|
|
page[c+3] = data_x >> 24; |
|
|
#ifndef LS_L |
|
|
page[c+4] = data_x >> 32; |
|
|
page[c+5] = data_x >> 40; |
|
|
page[c+6] = data_x >> 48; |
|
|
page[c+7] = data_x >> 56; |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#else |
|
|
/* Native byte order: */ |
|
|
#ifdef LS_B |
|
|
page[c] = *((uint64_t *)ic->arg[0]); |
|
|
#endif |
|
|
#ifdef LS_W |
|
|
uint32_t d = *((uint64_t *)ic->arg[0]); |
|
|
*((uint16_t *) (page + c)) = d; |
|
|
#endif |
|
|
#ifdef LS_L |
|
|
uint32_t d = *((uint64_t *)ic->arg[0]); |
|
|
*((uint32_t *) (page + c)) = d; |
|
|
#endif |
|
|
#ifdef LS_Q |
|
|
uint64_t d = *((uint64_t *)ic->arg[0]); |
|
|
*((uint64_t *) (page + c)) = d; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
#ifdef LS_LLSC |
|
|
#ifndef LS_LOAD |
|
|
*((uint64_t *)ic->arg[0]) = 1; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
#endif /* !LS_LOAD */ |
|
|
} else |
|
|
LS_GENERIC_N(cpu, ic); |
|
|
} else if (first == ALPHA_TOP_KERNEL) { |
|
|
struct alpha_vph_page *vph_p; |
|
|
unsigned char *page; |
|
|
vph_p = cpu->cd.alpha.vph_table0_kernel[a]; |
|
|
#ifdef LS_LOAD |
|
|
page = vph_p->host_load[b]; |
|
|
#else |
|
|
page = vph_p->host_store[b]; |
|
|
#endif |
|
|
if (page != NULL) { |
|
202 |
#ifdef LS_LOAD |
#ifdef LS_LOAD |
203 |
#ifdef HOST_BIG_ENDIAN |
#ifdef HOST_BIG_ENDIAN |
204 |
uint64_t data_x; |
uint64_t data_x; |
205 |
data_x = page[c]; |
data_x = page[c]; |
206 |
#ifndef LS_B |
#ifndef LS_B |
207 |
data_x += (page[c+1] << 8); |
data_x += (page[c+1] << 8); |
208 |
#ifndef LS_W |
#ifndef LS_W |
209 |
data_x += (page[c+2] << 16); |
data_x += (page[c+2] << 16); |
210 |
data_x += ((uint64_t)page[c+3] << 24); |
data_x += ((uint64_t)page[c+3] << 24); |
211 |
#ifndef LS_L |
#ifndef LS_L |
212 |
data_x += ((uint64_t)page[c+4] << 32); |
data_x += ((uint64_t)page[c+4] << 32); |
213 |
data_x += ((uint64_t)page[c+5] << 40); |
data_x += ((uint64_t)page[c+5] << 40); |
214 |
data_x += ((uint64_t)page[c+6] << 48); |
data_x += ((uint64_t)page[c+6] << 48); |
215 |
data_x += ((uint64_t)page[c+7] << 56); |
data_x += ((uint64_t)page[c+7] << 56); |
216 |
#endif |
#endif |
217 |
#endif |
#endif |
218 |
#endif |
#endif |
219 |
#ifdef LS_L |
#ifdef LS_L |
220 |
*((uint64_t *)ic->arg[0]) = (int64_t)(int32_t)data_x; |
*((uint64_t *)ic->arg[0]) = (int64_t)(int32_t)data_x; |
221 |
#else |
#else |
222 |
*((uint64_t *)ic->arg[0]) = data_x; |
*((uint64_t *)ic->arg[0]) = data_x; |
223 |
#endif |
#endif |
224 |
#else |
#else |
225 |
#ifdef LS_B |
#ifdef LS_B |
226 |
*((uint64_t *)ic->arg[0]) = page[c]; |
*((uint64_t *)ic->arg[0]) = page[c]; |
227 |
#endif |
#endif |
228 |
#ifdef LS_W |
#ifdef LS_W |
229 |
uint16_t d = *((uint16_t *) (page + c)); |
uint16_t d = *((uint16_t *) (page + c)); |
230 |
*((uint64_t *)ic->arg[0]) = d; |
*((uint64_t *)ic->arg[0]) = d; |
231 |
#endif |
#endif |
232 |
#ifdef LS_L |
#ifdef LS_L |
233 |
int32_t d = *((int32_t *) (page + c)); |
int32_t d = *((int32_t *) (page + c)); |
234 |
*((uint64_t *)ic->arg[0]) = (int64_t)d; |
*((uint64_t *)ic->arg[0]) = (int64_t)d; |
235 |
#endif |
#endif |
236 |
#ifdef LS_Q |
#ifdef LS_Q |
237 |
uint64_t d = *((uint64_t *) (page + c)); |
uint64_t d = *((uint64_t *) (page + c)); |
238 |
*((uint64_t *)ic->arg[0]) = d; |
*((uint64_t *)ic->arg[0]) = d; |
239 |
#endif |
#endif |
240 |
#endif |
#endif |
241 |
#else |
#else |
242 |
/* Store: */ |
/* Store: */ |
243 |
#ifdef HOST_BIG_ENDIAN |
#ifdef HOST_BIG_ENDIAN |
244 |
uint64_t data_x = *((uint64_t *)ic->arg[0]); |
uint64_t data_x = *((uint64_t *)ic->arg[0]); |
245 |
page[c] = data_x; |
page[c] = data_x; |
246 |
#ifndef LS_B |
#ifndef LS_B |
247 |
page[c+1] = data_x >> 8; |
page[c+1] = data_x >> 8; |
248 |
#ifndef LS_W |
#ifndef LS_W |
249 |
page[c+2] = data_x >> 16; |
page[c+2] = data_x >> 16; |
250 |
page[c+3] = data_x >> 24; |
page[c+3] = data_x >> 24; |
251 |
#ifndef LS_L |
#ifndef LS_L |
252 |
page[c+4] = data_x >> 32; |
page[c+4] = data_x >> 32; |
253 |
page[c+5] = data_x >> 40; |
page[c+5] = data_x >> 40; |
254 |
page[c+6] = data_x >> 48; |
page[c+6] = data_x >> 48; |
255 |
page[c+7] = data_x >> 56; |
page[c+7] = data_x >> 56; |
256 |
#endif |
#endif |
257 |
#endif |
#endif |
258 |
#endif |
#endif |
259 |
#else |
#else |
260 |
/* Native byte order: */ |
/* Native byte order: */ |
261 |
#ifdef LS_B |
#ifdef LS_B |
262 |
page[c] = *((uint64_t *)ic->arg[0]); |
page[c] = *((uint64_t *)ic->arg[0]); |
263 |
#endif |
#endif |
264 |
#ifdef LS_W |
#ifdef LS_W |
265 |
uint32_t d = *((uint64_t *)ic->arg[0]); |
uint32_t d = *((uint64_t *)ic->arg[0]); |
266 |
*((uint16_t *) (page + c)) = d; |
*((uint16_t *) (page + c)) = d; |
267 |
#endif |
#endif |
268 |
#ifdef LS_L |
#ifdef LS_L |
269 |
uint32_t d = *((uint64_t *)ic->arg[0]); |
uint32_t d = *((uint64_t *)ic->arg[0]); |
270 |
*((uint32_t *) (page + c)) = d; |
*((uint32_t *) (page + c)) = d; |
271 |
#endif |
#endif |
272 |
#ifdef LS_Q |
#ifdef LS_Q |
273 |
uint64_t d = *((uint64_t *)ic->arg[0]); |
uint64_t d = *((uint64_t *)ic->arg[0]); |
274 |
*((uint64_t *) (page + c)) = d; |
*((uint64_t *) (page + c)) = d; |
275 |
#endif |
#endif |
276 |
#endif |
#endif |
277 |
|
|
278 |
#ifdef LS_LLSC |
#ifdef LS_LLSC |
279 |
#ifndef LS_LOAD |
#ifndef LS_LOAD |
280 |
*((uint64_t *)ic->arg[0]) = 1; |
*((uint64_t *)ic->arg[0]) = 1; |
281 |
#endif |
#endif |
282 |
#endif |
#endif |
283 |
|
|
284 |
#endif /* !LS_LOAD */ |
#endif /* !LS_LOAD */ |
|
} else |
|
|
LS_GENERIC_N(cpu, ic); |
|
285 |
} else |
} else |
286 |
LS_GENERIC_N(cpu, ic); |
LS_GENERIC_N(cpu, ic); |
287 |
} |
} |