1 |
/* |
/* |
2 |
* Copyright (C) 2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2007 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.8 2005/10/26 14:37:03 debug Exp $ |
* $Id: dev_disk.c,v 1.14 2007/02/03 20:14:23 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 |
|
|
37 |
|
|
38 |
#include "cpu.h" |
#include "cpu.h" |
39 |
#include "device.h" |
#include "device.h" |
|
#include "devices.h" |
|
40 |
#include "diskimage.h" |
#include "diskimage.h" |
41 |
#include "emul.h" |
#include "emul.h" |
42 |
#include "machine.h" |
#include "machine.h" |
43 |
#include "memory.h" |
#include "memory.h" |
44 |
#include "misc.h" |
#include "misc.h" |
45 |
|
|
46 |
|
#include "testmachine/dev_disk.h" |
47 |
|
|
|
#define BUF_SIZE 8192 |
|
48 |
|
|
49 |
struct disk_data { |
struct disk_data { |
50 |
int64_t offset; |
int64_t offset; |
58 |
/* |
/* |
59 |
* dev_disk_buf_access(): |
* dev_disk_buf_access(): |
60 |
*/ |
*/ |
61 |
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) |
|
62 |
{ |
{ |
63 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = (struct disk_data *) extra; |
64 |
|
|
73 |
/* |
/* |
74 |
* dev_disk_access(): |
* dev_disk_access(): |
75 |
*/ |
*/ |
76 |
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) |
|
77 |
{ |
{ |
78 |
struct disk_data *d = (struct disk_data *) extra; |
struct disk_data *d = (struct disk_data *) extra; |
79 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
82 |
idata = memory_readmax64(cpu, data, len); |
idata = memory_readmax64(cpu, data, len); |
83 |
|
|
84 |
switch (relative_addr) { |
switch (relative_addr) { |
85 |
case 0x00: |
|
86 |
|
case DEV_DISK_OFFSET: |
87 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
88 |
odata = d->offset; |
odata = d->offset; |
89 |
} else { |
} else { |
90 |
d->offset = idata; |
d->offset = idata; |
91 |
} |
} |
92 |
break; |
break; |
93 |
case 0x10: |
|
94 |
|
case DEV_DISK_ID: |
95 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
96 |
odata = d->disk_id; |
odata = d->disk_id; |
97 |
} else { |
} else { |
98 |
d->disk_id = idata; |
d->disk_id = idata; |
99 |
} |
} |
100 |
break; |
break; |
101 |
case 0x20: |
|
102 |
|
case DEV_DISK_START_OPERATION: |
103 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
104 |
odata = d->command; |
odata = d->command; |
105 |
} else { |
} else { |
106 |
d->command = idata; |
d->command = idata; |
107 |
switch (d->command) { |
switch (d->command) { |
108 |
case 0: d->status = diskimage_access(cpu->machine, |
case 0: d->status = diskimage_access(cpu->machine, |
109 |
d->disk_id, DISKIMAGE_SCSI, 0, |
d->disk_id, DISKIMAGE_IDE, 0, |
110 |
d->offset, d->buf, 512); |
d->offset, d->buf, 512); |
111 |
break; |
break; |
112 |
case 1: d->status = diskimage_access(cpu->machine, |
case 1: d->status = diskimage_access(cpu->machine, |
113 |
d->disk_id, DISKIMAGE_SCSI, 1, |
d->disk_id, DISKIMAGE_IDE, 1, |
114 |
d->offset, d->buf, 512); |
d->offset, d->buf, 512); |
115 |
break; |
break; |
116 |
} |
} |
117 |
} |
} |
118 |
break; |
break; |
119 |
case 0x30: |
|
120 |
|
case DEV_DISK_STATUS: |
121 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
122 |
odata = d->status; |
odata = d->status; |
123 |
} else { |
} else { |
124 |
d->status = idata; |
d->status = idata; |
125 |
} |
} |
126 |
break; |
break; |
127 |
|
|
128 |
default:if (writeflag == MEM_WRITE) { |
default:if (writeflag == MEM_WRITE) { |
129 |
fatal("[ disk: unimplemented write to " |
fatal("[ disk: unimplemented write to " |
130 |
"offset 0x%x: data=0x%x ]\n", (int) |
"offset 0x%x: data=0x%x ]\n", (int) |
142 |
} |
} |
143 |
|
|
144 |
|
|
145 |
/* |
DEVINIT(disk) |
|
* devinit_disk(): |
|
|
*/ |
|
|
int devinit_disk(struct devinit *devinit) |
|
146 |
{ |
{ |
147 |
struct disk_data *d = malloc(sizeof(struct disk_data)); |
struct disk_data *d = malloc(sizeof(struct disk_data)); |
148 |
size_t nlen; |
size_t nlen; |
169 |
snprintf(n2, nlen, "%s [data buffer]", devinit->name); |
snprintf(n2, nlen, "%s [data buffer]", devinit->name); |
170 |
|
|
171 |
memory_device_register(devinit->machine->memory, n1, |
memory_device_register(devinit->machine->memory, n1, |
172 |
devinit->addr, 0x4000, dev_disk_access, (void *)d, |
devinit->addr, DEV_DISK_BUFFER, dev_disk_access, (void *)d, |
173 |
MEM_DEFAULT, NULL); |
DM_DEFAULT, NULL); |
174 |
|
|
175 |
memory_device_register(devinit->machine->memory, n2, |
memory_device_register(devinit->machine->memory, n2, |
176 |
devinit->addr + 0x4000, devinit->machine->arch_pagesize, |
devinit->addr + DEV_DISK_BUFFER, |
177 |
dev_disk_buf_access, (void *)d, MEM_DYNTRANS_OK | |
devinit->machine->arch_pagesize, dev_disk_buf_access, |
178 |
MEM_DYNTRANS_WRITE_OK | MEM_READING_HAS_NO_SIDE_EFFECTS, d->buf); |
(void *)d, DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK | |
179 |
|
DM_READS_HAVE_NO_SIDE_EFFECTS, d->buf); |
180 |
|
|
181 |
return 1; |
return 1; |
182 |
} |
} |