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: dev_disk.c,v 1.9 2005/11/13 00:14:08 debug Exp $ |
* $Id: dev_disk.c,v 1.12 2006/05/06 08:42:49 debug Exp $ |
29 |
* |
* |
30 |
* 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 |
31 |
* read and write data from disk devices. |
* read and write data from disk devices. |
32 |
*/ |
*/ |
33 |
|
|
44 |
#include "memory.h" |
#include "memory.h" |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
|
|
47 |
|
#include "testmachine/dev_disk.h" |
48 |
|
|
|
#define BUF_SIZE 8192 |
|
49 |
|
|
50 |
struct disk_data { |
struct disk_data { |
51 |
int64_t offset; |
int64_t offset; |
59 |
/* |
/* |
60 |
* dev_disk_buf_access(): |
* dev_disk_buf_access(): |
61 |
*/ |
*/ |
62 |
int dev_disk_buf_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(disk_buf) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
63 |
{ |
{ |
64 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = (struct disk_data *) extra; |
65 |
|
|
74 |
/* |
/* |
75 |
* dev_disk_access(): |
* dev_disk_access(): |
76 |
*/ |
*/ |
77 |
int dev_disk_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(disk) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
78 |
{ |
{ |
79 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = (struct disk_data *) extra; |
80 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
83 |
idata = memory_readmax64(cpu, data, len); |
idata = memory_readmax64(cpu, data, len); |
84 |
|
|
85 |
switch (relative_addr) { |
switch (relative_addr) { |
86 |
case 0x00: |
|
87 |
|
case DEV_DISK_OFFSET: |
88 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
89 |
odata = d->offset; |
odata = d->offset; |
90 |
} else { |
} else { |
91 |
d->offset = idata; |
d->offset = idata; |
92 |
} |
} |
93 |
break; |
break; |
94 |
case 0x10: |
|
95 |
|
case DEV_DISK_ID: |
96 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
97 |
odata = d->disk_id; |
odata = d->disk_id; |
98 |
} else { |
} else { |
99 |
d->disk_id = idata; |
d->disk_id = idata; |
100 |
} |
} |
101 |
break; |
break; |
102 |
case 0x20: |
|
103 |
|
case DEV_DISK_START_OPERATION: |
104 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
105 |
odata = d->command; |
odata = d->command; |
106 |
} else { |
} else { |
107 |
d->command = idata; |
d->command = idata; |
108 |
switch (d->command) { |
switch (d->command) { |
109 |
case 0: d->status = diskimage_access(cpu->machine, |
case 0: d->status = diskimage_access(cpu->machine, |
110 |
d->disk_id, DISKIMAGE_SCSI, 0, |
d->disk_id, DISKIMAGE_IDE, 0, |
111 |
d->offset, d->buf, 512); |
d->offset, d->buf, 512); |
112 |
break; |
break; |
113 |
case 1: d->status = diskimage_access(cpu->machine, |
case 1: d->status = diskimage_access(cpu->machine, |
114 |
d->disk_id, DISKIMAGE_SCSI, 1, |
d->disk_id, DISKIMAGE_IDE, 1, |
115 |
d->offset, d->buf, 512); |
d->offset, d->buf, 512); |
116 |
break; |
break; |
117 |
} |
} |
118 |
} |
} |
119 |
break; |
break; |
120 |
case 0x30: |
|
121 |
|
case DEV_DISK_STATUS: |
122 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
123 |
odata = d->status; |
odata = d->status; |
124 |
} else { |
} else { |
125 |
d->status = idata; |
d->status = idata; |
126 |
} |
} |
127 |
break; |
break; |
128 |
|
|
129 |
default:if (writeflag == MEM_WRITE) { |
default:if (writeflag == MEM_WRITE) { |
130 |
fatal("[ disk: unimplemented write to " |
fatal("[ disk: unimplemented write to " |
131 |
"offset 0x%x: data=0x%x ]\n", (int) |
"offset 0x%x: data=0x%x ]\n", (int) |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
/* |
DEVINIT(disk) |
|
* devinit_disk(): |
|
|
*/ |
|
|
int devinit_disk(struct devinit *devinit) |
|
147 |
{ |
{ |
148 |
struct disk_data *d = malloc(sizeof(struct disk_data)); |
struct disk_data *d = malloc(sizeof(struct disk_data)); |
149 |
size_t nlen; |
size_t nlen; |
170 |
snprintf(n2, nlen, "%s [data buffer]", devinit->name); |
snprintf(n2, nlen, "%s [data buffer]", devinit->name); |
171 |
|
|
172 |
memory_device_register(devinit->machine->memory, n1, |
memory_device_register(devinit->machine->memory, n1, |
173 |
devinit->addr, 0x4000, dev_disk_access, (void *)d, |
devinit->addr, DEV_DISK_BUFFER, dev_disk_access, (void *)d, |
174 |
DM_DEFAULT, NULL); |
DM_DEFAULT, NULL); |
175 |
|
|
176 |
memory_device_register(devinit->machine->memory, n2, |
memory_device_register(devinit->machine->memory, n2, |
177 |
devinit->addr + 0x4000, devinit->machine->arch_pagesize, |
devinit->addr + DEV_DISK_BUFFER, |
178 |
dev_disk_buf_access, (void *)d, DM_DYNTRANS_OK | |
devinit->machine->arch_pagesize, dev_disk_buf_access, |
179 |
DM_DYNTRANS_WRITE_OK | DM_READS_HAVE_NO_SIDE_EFFECTS, d->buf); |
(void *)d, DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK | |
180 |
|
DM_READS_HAVE_NO_SIDE_EFFECTS, d->buf); |
181 |
|
|
182 |
return 1; |
return 1; |
183 |
} |
} |