1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-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: dev_ram.c,v 1.19 2005/10/25 15:51:04 debug Exp $ |
* $Id: dev_ram.c,v 1.22 2006/09/19 10:50:08 debug Exp $ |
29 |
* |
* |
30 |
* A generic RAM (memory) device. Can also be used to mirror/alias another |
* A generic RAM (memory) device. Can also be used to mirror/alias another |
31 |
* part of RAM. |
* part of RAM. |
59 |
}; |
}; |
60 |
|
|
61 |
|
|
62 |
/* |
DEVICE_ACCESS(ram) |
|
* dev_ram_access(): |
|
|
*/ |
|
|
int dev_ram_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
63 |
{ |
{ |
64 |
struct ram_data *d = extra; |
struct ram_data *d = extra; |
65 |
|
|
108 |
int mode, uint64_t otheraddress) |
int mode, uint64_t otheraddress) |
109 |
{ |
{ |
110 |
struct ram_data *d; |
struct ram_data *d; |
111 |
int flags = MEM_DEFAULT, points_to_ram = 1; |
int flags = DM_DEFAULT, points_to_ram = 1; |
112 |
|
|
113 |
d = malloc(sizeof(struct ram_data)); |
d = malloc(sizeof(struct ram_data)); |
114 |
if (d == NULL) { |
if (d == NULL) { |
132 |
/* |
/* |
133 |
* Calculate the amount that the mirror memory is offset from |
* Calculate the amount that the mirror memory is offset from |
134 |
* the real (physical) memory. This is used in src/memory_rw.c |
* the real (physical) memory. This is used in src/memory_rw.c |
135 |
* with dyntrans accesses if MEM_EMULATED_RAM is set. |
* with dyntrans accesses if DM_EMULATED_RAM is set. |
136 |
*/ |
*/ |
137 |
d->offset = baseaddr - otheraddress; |
d->offset = baseaddr - otheraddress; |
138 |
|
|
141 |
(baseaddr & (machine->arch_pagesize-1)) == 0 && |
(baseaddr & (machine->arch_pagesize-1)) == 0 && |
142 |
(otheraddress & (machine->arch_pagesize - 1)) == 0 && |
(otheraddress & (machine->arch_pagesize - 1)) == 0 && |
143 |
(length & (machine->arch_pagesize - 1)) == 0) |
(length & (machine->arch_pagesize - 1)) == 0) |
144 |
flags |= MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK |
flags |= DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK |
145 |
| MEM_EMULATED_RAM; |
| DM_EMULATED_RAM; |
146 |
|
|
147 |
memory_device_register(machine->memory, "ram [mirror]", |
memory_device_register(machine->memory, "ram [mirror]", |
148 |
baseaddr, length, dev_ram_access, d, flags |
baseaddr, length, dev_ram_access, d, flags |
149 |
| MEM_READING_HAS_NO_SIDE_EFFECTS, (void *) &d->offset); |
| DM_READS_HAVE_NO_SIDE_EFFECTS, (void *) &d->offset); |
150 |
break; |
break; |
151 |
|
|
152 |
case DEV_RAM_RAM: |
case DEV_RAM_RAM: |
170 |
/* Aligned memory? Then it works with dyntrans. */ |
/* Aligned memory? Then it works with dyntrans. */ |
171 |
if ((baseaddr & (machine->arch_pagesize - 1)) == 0 && |
if ((baseaddr & (machine->arch_pagesize - 1)) == 0 && |
172 |
(length & (machine->arch_pagesize - 1)) == 0) |
(length & (machine->arch_pagesize - 1)) == 0) |
173 |
flags |= MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK; |
flags |= DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK; |
174 |
|
|
175 |
memory_device_register(machine->memory, "ram", baseaddr, |
memory_device_register(machine->memory, "ram", baseaddr, |
176 |
d->length, dev_ram_access, d, flags |
d->length, dev_ram_access, d, flags |
177 |
| MEM_READING_HAS_NO_SIDE_EFFECTS, d->data); |
| DM_READS_HAVE_NO_SIDE_EFFECTS, d->data); |
178 |
break; |
break; |
179 |
|
|
180 |
default: |
default: |