--- trunk/src/devices/dev_wdc.c 2007/10/08 16:18:06 5 +++ trunk/src/devices/dev_wdc.c 2007/10/08 16:18:11 6 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_wdc.c,v 1.33 2005/04/14 20:55:23 debug Exp $ + * $Id: dev_wdc.c,v 1.37 2005/05/27 07:29:25 debug Exp $ * * Standard IDE controller. */ @@ -52,6 +52,8 @@ /* INT_DELAY=2 to be safe, 1 is faster but maybe buggy. */ #define INT_DELAY 1 +extern int quiet_mode; + /* #define debug fatal */ /* #define DATA_DEBUG */ @@ -112,7 +114,7 @@ d->inbuf_head = (d->inbuf_head + 1) % WDC_INBUF_SIZE; if (d->inbuf_head == d->inbuf_tail) - fatal("WARNING! wdc inbuf overrun\n"); + fatal("[ wdc_addtoinbuf(): WARNING! wdc inbuf overrun ]\n"); } @@ -126,8 +128,8 @@ int c = d->inbuf[d->inbuf_tail]; if (d->inbuf_head == d->inbuf_tail) { - fatal("WARNING! someone is reading too much from the " - "wdc inbuf!\n"); + fatal("[ wdc: WARNING! someone is reading too much from the " + "wdc inbuf! ]\n"); return -1; } @@ -141,15 +143,16 @@ */ static void wdc_initialize_identify_struct(struct cpu *cpu, struct wdc_data *d) { - uint64_t total_size, cyls; + uint64_t total_size; + int cyls, heads, sectors_per_track; - total_size = diskimage_getsize(cpu->machine, d->drive + d->base_drive); + total_size = diskimage_getsize(cpu->machine, d->drive + d->base_drive, + DISKIMAGE_IDE); - memset(d->identify_struct, 0, sizeof(d->identify_struct)); + diskimage_getchs(cpu->machine, d->drive + d->base_drive, + DISKIMAGE_IDE, &cyls, &heads, §ors_per_track); - cyls = total_size / (63 * 16 * 512); - if (cyls * 63*16*512 < total_size) - cyls ++; + memset(d->identify_struct, 0, sizeof(d->identify_struct)); /* Offsets are in 16-bit WORDS! High byte, then low. */ @@ -162,12 +165,12 @@ d->identify_struct[2 * 1 + 1] = cyls & 255; /* 3: nr of heads */ - d->identify_struct[2 * 3 + 0] = 0; - d->identify_struct[2 * 3 + 1] = 16; + d->identify_struct[2 * 3 + 0] = heads >> 8; + d->identify_struct[2 * 3 + 1] = heads; /* 6: sectors per track */ - d->identify_struct[2 * 6 + 0] = 0; - d->identify_struct[2 * 6 + 1] = 63; + d->identify_struct[2 * 6 + 0] = sectors_per_track >> 8; + d->identify_struct[2 * 6 + 1] = sectors_per_track; /* 10-19: Serial number */ memcpy(&d->identify_struct[2 * 10], "S/N 1234-5678 ", 20); @@ -206,8 +209,8 @@ { int odata = 0; - if (diskimage_exist(cpu->machine, - d->drive + d->base_drive)) + if (diskimage_exist(cpu->machine, d->drive + d->base_drive, + DISKIMAGE_IDE)) odata |= WDCS_DRDY; if (d->inbuf_head != d->inbuf_tail) odata |= WDCS_DRQ; @@ -222,8 +225,8 @@ * * NetBSD/cobalt seems to want it, but Linux on MobilePro does not. */ - if (!diskimage_exist(cpu->machine, - d->drive + d->base_drive)) + if (!diskimage_exist(cpu->machine, d->drive + d->base_drive, + DISKIMAGE_IDE)) odata = 0xff; #endif @@ -269,7 +272,7 @@ { struct wdc_data *d = extra; uint64_t idata = 0, odata = 0; - int i; + int i, cyls, heads, sectors_per_track; idata = memory_readmax64(cpu, data, len); @@ -341,7 +344,7 @@ buf[i] = wdc_get_inbuf(d); diskimage_access(cpu->machine, - d->drive + d->base_drive, 1, + d->drive + d->base_drive, DISKIMAGE_IDE, 1, d->write_offset, buf, 512 * count); free(buf); @@ -430,7 +433,9 @@ if (writeflag==MEM_READ) { odata = status_byte(d, cpu); #if 1 - debug("[ wdc: read from STATUS: 0x%02x ]\n", odata); + if (!quiet_mode) + debug("[ wdc: read from STATUS: 0x%02x ]\n", + odata); #endif cpu_interrupt_ack(cpu, d->irq_nr); @@ -441,7 +446,7 @@ /* TODO: Is this correct behaviour? */ if (!diskimage_exist(cpu->machine, - d->drive + d->base_drive)) { + d->drive + d->base_drive, DISKIMAGE_IDE)) { d->error |= WDCE_ABRT; d->delayed_interrupt = INT_DELAY; break; @@ -456,12 +461,17 @@ d->sector, d->seccnt); /* TODO: HAHA! This should be removed quickly */ + diskimage_getchs(cpu->machine, d->drive + + d->base_drive, DISKIMAGE_IDE, &cyls, + &heads, §ors_per_track); + { unsigned char buf[512*256]; int cyl = d->cyl_hi * 256+ d->cyl_lo; int count = d->seccnt? d->seccnt : 256; uint64_t offset = 512 * (d->sector - 1 - + d->head * 63 + 16*63*cyl); + + d->head * sectors_per_track + + heads*sectors_per_track*cyl); #if 0 /* LBA: */ @@ -470,7 +480,8 @@ printf("WDC read from offset %lli\n", (long long)offset); #endif diskimage_access(cpu->machine, - d->drive + d->base_drive, 0, + d->drive + d->base_drive, + DISKIMAGE_IDE, 0, offset, buf, 512 * count); /* TODO: result code */ for (i=0; i<512 * count; i++) @@ -485,11 +496,15 @@ d->sector, d->seccnt); /* TODO: HAHA! This should be removed quickly */ + diskimage_getchs(cpu->machine, d->drive + + d->base_drive, DISKIMAGE_IDE, &cyls, + &heads, §ors_per_track); { int cyl = d->cyl_hi * 256+ d->cyl_lo; int count = d->seccnt? d->seccnt : 256; uint64_t offset = 512 * (d->sector - 1 - + d->head * 63 + 16*63*cyl); + + d->head * sectors_per_track + + heads*sectors_per_track*cyl); #if 0 /* LBA: */