25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_disk.c,v 1.14 2007/02/03 20:14:23 debug Exp $ |
* $Id: dev_disk.c,v 1.15 2007/06/15 18:44:19 debug Exp $ |
29 |
|
* |
30 |
|
* COMMENT: A simple disk controller device, for the test machines |
31 |
* |
* |
32 |
* Basic "disk" device. This is a simple test device which can be used to |
* Basic "disk" device. This is a simple test device which can be used to |
33 |
* read and write data from disk devices. |
* read and write data from disk devices. |
57 |
}; |
}; |
58 |
|
|
59 |
|
|
|
/* |
|
|
* dev_disk_buf_access(): |
|
|
*/ |
|
60 |
DEVICE_ACCESS(disk_buf) |
DEVICE_ACCESS(disk_buf) |
61 |
{ |
{ |
62 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = extra; |
63 |
|
|
64 |
if (writeflag == MEM_WRITE) |
if (writeflag == MEM_WRITE) |
65 |
memcpy(d->buf + relative_addr, data, len); |
memcpy(d->buf + relative_addr, data, len); |
66 |
else |
else |
67 |
memcpy(data, d->buf + relative_addr, len); |
memcpy(data, d->buf + relative_addr, len); |
68 |
|
|
69 |
return 1; |
return 1; |
70 |
} |
} |
71 |
|
|
72 |
|
|
|
/* |
|
|
* dev_disk_access(): |
|
|
*/ |
|
73 |
DEVICE_ACCESS(disk) |
DEVICE_ACCESS(disk) |
74 |
{ |
{ |
75 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = extra; |
76 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
77 |
|
|
78 |
if (writeflag == MEM_WRITE) |
if (writeflag == MEM_WRITE) |
141 |
|
|
142 |
DEVINIT(disk) |
DEVINIT(disk) |
143 |
{ |
{ |
144 |
struct disk_data *d = malloc(sizeof(struct disk_data)); |
struct disk_data *d; |
145 |
size_t nlen; |
size_t nlen; |
146 |
char *n1, *n2; |
char *n1, *n2; |
147 |
|
|
148 |
nlen = strlen(devinit->name) + 30; |
CHECK_ALLOCATION(d = malloc(sizeof(struct disk_data))); |
|
n1 = malloc(nlen); |
|
|
n2 = malloc(nlen); |
|
|
|
|
|
if (d == NULL || n1 == NULL || n2 == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
149 |
memset(d, 0, sizeof(struct disk_data)); |
memset(d, 0, sizeof(struct disk_data)); |
150 |
|
|
151 |
d->buf = malloc(devinit->machine->arch_pagesize); |
nlen = strlen(devinit->name) + 30; |
152 |
if (d->buf == NULL) { |
CHECK_ALLOCATION(n1 = malloc(nlen)); |
153 |
fprintf(stderr, "out of memory\n"); |
CHECK_ALLOCATION(n2 = malloc(nlen)); |
154 |
exit(1); |
|
155 |
} |
CHECK_ALLOCATION(d->buf = malloc(devinit->machine->arch_pagesize)); |
156 |
memset(d->buf, 0, devinit->machine->arch_pagesize); |
memset(d->buf, 0, devinit->machine->arch_pagesize); |
157 |
|
|
158 |
snprintf(n1, nlen, "%s [control]", devinit->name); |
snprintf(n1, nlen, "%s [control]", devinit->name); |