* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+/*
+ * The controller is used in Sun4m systems in a slightly different
+ * way. There are changes in DOR register and DMA is not available.
+ */
#include "vl.h"
/********************************************************/
}
/********************************************************/
-/* Intel 82078 floppy disk controler emulation */
+/* Intel 82078 floppy disk controller emulation */
static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq);
static void fdctrl_reset_fifo (fdctrl_t *fdctrl);
-static int fdctrl_transfer_handler (void *opaque, target_ulong addr, int size);
+static int fdctrl_transfer_handler (void *opaque, int nchan,
+ int dma_pos, int dma_len);
static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status);
static void fdctrl_result_timer(void *opaque);
struct fdctrl_t {
fdctrl_t *fdctrl;
- /* Controler's identification */
+ /* Controller's identification */
uint8_t version;
/* HW */
int irq_lvl;
int dma_chann;
uint32_t io_base;
- /* Controler state */
+ /* Controller state */
QEMUTimer *result_timer;
uint8_t state;
uint8_t dma_en;
uint32_t retval;
switch (reg & 0x07) {
+#ifdef TARGET_SPARC
+ case 0x00:
+ // Identify to Linux as S82078B
+ retval = fdctrl_read_statusB(fdctrl);
+ break;
+#endif
case 0x01:
retval = fdctrl_read_statusB(fdctrl);
break;
}
}
+static uint32_t fdctrl_read_mem (void *opaque, target_phys_addr_t reg)
+{
+ return fdctrl_read(opaque, reg);
+}
+
+static void fdctrl_write_mem (void *opaque,
+ target_phys_addr_t reg, uint32_t value)
+{
+ fdctrl_write(opaque, reg, value);
+}
+
+static CPUReadMemoryFunc *fdctrl_mem_read[3] = {
+ fdctrl_read_mem,
+ fdctrl_read_mem,
+ fdctrl_read_mem,
+};
+
+static CPUWriteMemoryFunc *fdctrl_mem_write[3] = {
+ fdctrl_write_mem,
+ fdctrl_write_mem,
+ fdctrl_write_mem,
+};
+
static void fd_change_cb (void *opaque)
{
fdrive_t *drv = opaque;
BlockDriverState **fds)
{
fdctrl_t *fdctrl;
-// int io_mem;
+ int io_mem;
int i;
- FLOPPY_DPRINTF("init controler\n");
+ FLOPPY_DPRINTF("init controller\n");
fdctrl = qemu_mallocz(sizeof(fdctrl_t));
if (!fdctrl)
return NULL;
fdctrl->result_timer = qemu_new_timer(vm_clock,
fdctrl_result_timer, fdctrl);
- fdctrl->version = 0x90; /* Intel 82078 controler */
+ fdctrl->version = 0x90; /* Intel 82078 controller */
fdctrl->irq_lvl = irq_lvl;
fdctrl->dma_chann = dma_chann;
fdctrl->io_base = io_base;
fdctrl_reset(fdctrl, 0);
fdctrl->state = FD_CTRL_ACTIVE;
if (mem_mapped) {
- FLOPPY_ERROR("memory mapped floppy not supported by now !\n");
-#if 0
- io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write);
- cpu_register_physical_memory(base, 0x08, io_mem);
-#endif
+ io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write, fdctrl);
+ cpu_register_physical_memory(io_base, 0x08, io_mem);
} else {
register_ioport_read(io_base + 0x01, 5, 1, &fdctrl_read, fdctrl);
register_ioport_read(io_base + 0x07, 1, 1, &fdctrl_read, fdctrl);
static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status)
{
+#ifdef TARGET_SPARC
+ // Sparc mutation
+ if (!fdctrl->dma_en) {
+ fdctrl->state &= ~FD_CTRL_BUSY;
+ fdctrl->int_status = status;
+ return;
+ }
+#endif
if (~(fdctrl->state & FD_CTRL_INTR)) {
pic_set_irq(fdctrl->irq_lvl, 1);
fdctrl->state |= FD_CTRL_INTR;
fdctrl->int_status = status;
}
-/* Reset controler */
+/* Reset controller */
static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq)
{
int i;
- FLOPPY_DPRINTF("reset controler\n");
+ FLOPPY_DPRINTF("reset controller\n");
fdctrl_reset_irq(fdctrl);
- /* Initialise controler */
+ /* Initialise controller */
fdctrl->cur_drv = 0;
/* FIFO state */
fdctrl->data_pos = 0;
/* Reset mode */
if (fdctrl->state & FD_CTRL_RESET) {
if (!(value & 0x04)) {
- FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
+ FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
return;
}
}
/* Reset */
if (!(value & 0x04)) {
if (!(fdctrl->state & FD_CTRL_RESET)) {
- FLOPPY_DPRINTF("controler enter RESET state\n");
+ FLOPPY_DPRINTF("controller enter RESET state\n");
fdctrl->state |= FD_CTRL_RESET;
}
} else {
if (fdctrl->state & FD_CTRL_RESET) {
- FLOPPY_DPRINTF("controler out of RESET state\n");
+ FLOPPY_DPRINTF("controller out of RESET state\n");
fdctrl_reset(fdctrl, 1);
fdctrl->state &= ~(FD_CTRL_RESET | FD_CTRL_SLEEP);
}
{
/* Reset mode */
if (fdctrl->state & FD_CTRL_RESET) {
- FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
+ FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
return;
}
FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
{
/* Reset mode */
if (fdctrl->state & FD_CTRL_RESET) {
- FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
+ FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
return;
}
FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
kt = fdctrl->fifo[2];
kh = fdctrl->fifo[3];
ks = fdctrl->fifo[4];
- FLOPPY_DPRINTF("Start tranfer at %d %d %02x %02x (%d)\n",
+ FLOPPY_DPRINTF("Start transfer at %d %d %02x %02x (%d)\n",
fdctrl->cur_drv, kh, kt, ks,
_fd_sector(kh, kt, ks, cur_drv->last_sect));
did_seek = 0;
(direction == FD_DIR_READ && dma_mode == 1)) {
/* No access is allowed until DMA transfer has completed */
fdctrl->state |= FD_CTRL_BUSY;
- /* Now, we just have to wait for the DMA controler to
+ /* Now, we just have to wait for the DMA controller to
* recall us...
*/
DMA_hold_DREQ(fdctrl->dma_chann);
}
/* handlers for DMA transfers */
-static int fdctrl_transfer_handler (void *opaque, target_ulong addr, int size)
+static int fdctrl_transfer_handler (void *opaque, int nchan,
+ int dma_pos, int dma_len)
{
fdctrl_t *fdctrl;
fdrive_t *cur_drv;
if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
fdctrl->data_dir == FD_DIR_SCANH)
status2 = 0x04;
- if (size > fdctrl->data_len)
- size = fdctrl->data_len;
+ if (dma_len > fdctrl->data_len)
+ dma_len = fdctrl->data_len;
if (cur_drv->bs == NULL) {
if (fdctrl->data_dir == FD_DIR_WRITE)
fdctrl_stop_transfer(fdctrl, 0x60, 0x00, 0x00);
goto transfer_error;
}
rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
- for (start_pos = fdctrl->data_pos; fdctrl->data_pos < size;) {
- len = size - fdctrl->data_pos;
+ for (start_pos = fdctrl->data_pos; fdctrl->data_pos < dma_len;) {
+ len = dma_len - fdctrl->data_pos;
if (len + rel_pos > FD_SECTOR_LEN)
len = FD_SECTOR_LEN - rel_pos;
- FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x %02x "
- "(%d-0x%08x 0x%08x)\n", len, size, fdctrl->data_pos,
+ FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x "
+ "(%d-0x%08x 0x%08x)\n", len, dma_len, fdctrl->data_pos,
fdctrl->data_len, fdctrl->cur_drv, cur_drv->head,
cur_drv->track, cur_drv->sect, fd_sector(cur_drv),
- fd_sector(cur_drv) * 512, addr);
+ fd_sector(cur_drv) * 512);
if (fdctrl->data_dir != FD_DIR_WRITE ||
len < FD_SECTOR_LEN || rel_pos != 0) {
/* READ & SCAN commands and realign to a sector for WRITE */
switch (fdctrl->data_dir) {
case FD_DIR_READ:
/* READ commands */
- cpu_physical_memory_write(addr + fdctrl->data_pos,
- fdctrl->fifo + rel_pos, len);
+ DMA_write_memory (nchan, fdctrl->fifo + rel_pos,
+ fdctrl->data_pos, len);
+/* cpu_physical_memory_write(addr + fdctrl->data_pos, */
+/* fdctrl->fifo + rel_pos, len); */
break;
case FD_DIR_WRITE:
/* WRITE commands */
- cpu_physical_memory_read(addr + fdctrl->data_pos,
- fdctrl->fifo + rel_pos, len);
+ DMA_read_memory (nchan, fdctrl->fifo + rel_pos,
+ fdctrl->data_pos, len);
+/* cpu_physical_memory_read(addr + fdctrl->data_pos, */
+/* fdctrl->fifo + rel_pos, len); */
if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
fdctrl->fifo, 1) < 0) {
FLOPPY_ERROR("writting sector %d\n", fd_sector(cur_drv));
{
uint8_t tmpbuf[FD_SECTOR_LEN];
int ret;
- cpu_physical_memory_read(addr + fdctrl->data_pos,
- tmpbuf, len);
+ DMA_read_memory (nchan, tmpbuf, fdctrl->data_pos, len);
+/* cpu_physical_memory_read(addr + fdctrl->data_pos, */
+/* tmpbuf, len); */
ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
if (ret == 0) {
status2 = 0x08;
FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d) (%d)\n",
cur_drv->head, cur_drv->track, cur_drv->sect,
fd_sector(cur_drv),
- fdctrl->data_pos - size);
+ fdctrl->data_pos - len);
/* XXX: cur_drv->sect >= cur_drv->last_sect should be an
error in fact */
if (cur_drv->sect >= cur_drv->last_sect ||
cur_drv = get_cur_drv(fdctrl);
/* Reset mode */
if (fdctrl->state & FD_CTRL_RESET) {
- FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
+ FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
return;
}
fdctrl->state &= ~FD_CTRL_SLEEP;
FLOPPY_DPRINTF("SENSE_INTERRUPT_STATUS command (%02x)\n",
fdctrl->int_status);
/* No parameters cmd: returns status if no interrupt */
+#if 0
fdctrl->fifo[0] =
fdctrl->int_status | (cur_drv->head << 2) | fdctrl->cur_drv;
+#else
+ /* XXX: int_status handling is broken for read/write
+ commands, so we do this hack. It should be suppressed
+ ASAP */
+ fdctrl->fifo[0] =
+ 0x20 | (cur_drv->head << 2) | fdctrl->cur_drv;
+#endif
fdctrl->fifo[1] = cur_drv->track;
fdctrl_set_fifo(fdctrl, 2, 0);
fdctrl_reset_irq(fdctrl);
/* VERSION */
FLOPPY_DPRINTF("VERSION command\n");
/* No parameters cmd */
- /* Controler's version */
+ /* Controller's version */
fdctrl->fifo[0] = fdctrl->version;
fdctrl_set_fifo(fdctrl, 1, 1);
return;