25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: memory_rw.c,v 1.101 2007/02/10 14:04:51 debug Exp $ |
* $Id: memory_rw.c,v 1.102 2007/04/16 15:13:44 debug Exp $ |
29 |
* |
* |
30 |
* Generic memory_rw(), with special hacks for specific CPU families. |
* Generic memory_rw(), with special hacks for specific CPU families. |
31 |
* |
* |
373 |
paddr & ~offset_mask); |
paddr & ~offset_mask); |
374 |
|
|
375 |
/* |
/* |
376 |
* If writing, then invalidate code translations for the (physical) |
* If writing, or if mapping a page where writing is ok later on, |
377 |
* page address: |
* then invalidate code translations for the (physical) page address: |
378 |
*/ |
*/ |
379 |
if (writeflag == MEM_WRITE && cpu->invalidate_code_translation != NULL) |
if ((writeflag == MEM_WRITE |
380 |
|
#if !defined(MEM_USERLAND) |
381 |
|
|| ok == 2 |
382 |
|
#endif |
383 |
|
) && cpu->invalidate_code_translation != NULL) |
384 |
cpu->invalidate_code_translation(cpu, paddr, INVALIDATE_PADDR); |
cpu->invalidate_code_translation(cpu, paddr, INVALIDATE_PADDR); |
385 |
|
|
386 |
if ((paddr&((1<<BITS_PER_MEMBLOCK)-1)) + len > (1<<BITS_PER_MEMBLOCK)) { |
if ((paddr&((1<<BITS_PER_MEMBLOCK)-1)) + len > (1<<BITS_PER_MEMBLOCK)) { |
388 |
exit(1); |
exit(1); |
389 |
} |
} |
390 |
|
|
391 |
if (writeflag == MEM_WRITE) { |
/* And finally, read or write the data: */ |
392 |
/* Ugly optimization, but it works: */ |
if (writeflag == MEM_WRITE) |
393 |
if (len == sizeof(uint32_t) && (offset & 3)==0 |
memcpy(memblock + offset, data, len); |
394 |
&& ((size_t)data&3)==0) |
else |
395 |
*(uint32_t *)(memblock + offset) = *(uint32_t *)data; |
memcpy(data, memblock + offset, len); |
|
else if (len == sizeof(uint8_t)) |
|
|
*(uint8_t *)(memblock + offset) = *(uint8_t *)data; |
|
|
else |
|
|
memcpy(memblock + offset, data, len); |
|
|
} else { |
|
|
/* Ugly optimization, but it works: */ |
|
|
if (len == sizeof(uint32_t) && (offset & 3)==0 |
|
|
&& ((size_t)data&3)==0) |
|
|
*(uint32_t *)data = *(uint32_t *)(memblock + offset); |
|
|
else if (len == sizeof(uint8_t)) |
|
|
*(uint8_t *)data = *(uint8_t *)(memblock + offset); |
|
|
else |
|
|
memcpy(data, memblock + offset, len); |
|
|
} |
|
|
|
|
396 |
|
|
397 |
do_return_ok: |
do_return_ok: |
398 |
return MEMORY_ACCESS_OK; |
return MEMORY_ACCESS_OK; |