src/wd2010.c

branch
experimental_memory_mapper_v2
changeset 128
3246b74d96bc
parent 126
d79a028161fd
child 132
8a7dc9b5b1db
     1.1 diff -r 4c03f6433d0d -r 3246b74d96bc src/wd2010.c
     1.2 --- a/src/wd2010.c	Wed Jan 16 00:41:51 2013 +0000
     1.3 +++ b/src/wd2010.c	Fri Jan 18 17:03:48 2013 +0000
     1.4 @@ -263,6 +263,7 @@
     1.5  	size_t lba;
     1.6  	int new_track;
     1.7  	int sector_count;
     1.8 +	unsigned int ssz;
     1.9  
    1.10  	m68k_end_timeslice();
    1.11  
    1.12 @@ -296,7 +297,7 @@
    1.13  			break;
    1.14  		case WD2010_REG_SDH:
    1.15  			/*XXX: remove this once the DMA page fault test passes (unless this is actually the correct behavior here)*/
    1.16 -			ctx->data_pos = ctx->data_len = 0;
    1.17 +			//ctx->data_pos = ctx->data_len = 0;
    1.18  			ctx->sdh = val;
    1.19  			break;
    1.20  		case WD2010_REG_COMMAND:	// Command register
    1.21 @@ -343,13 +344,23 @@
    1.22  							break;
    1.23  						case CMD_READ_SECTOR:
    1.24  							/*XXX: does a separate function to set the head have to be added?*/
    1.25 -							LOG("WD2010: READ SECTOR cmd=%02X chs=%d:%d:%d nsectors=%d", cmd, ctx->track, ctx->head, ctx->sector, ctx->sector_count);
    1.26 +							LOG("WD2010: READ SECTOR cmd=%02X sdh=0x%02X drive=%d ddrive1=%d chs=%d:%d:%d nsectors=%d", cmd, ctx->sdh, (ctx->sdh >> 3) & 3, ctx->mcr2_ddrive1, ctx->track, ctx->head, ctx->sector, val&CMD_MULTI_SECTOR ? ctx->sector_count : 1);
    1.27 +
    1.28 +							switch ((ctx->sdh >> 5) & 0x03) {
    1.29 +								case 0: ssz = 256; break;
    1.30 +								case 1: ssz = 512; break;
    1.31 +								case 2: ssz = 1024; break;
    1.32 +								case 3: ssz = 128; break;
    1.33 +							}
    1.34 +							if (ssz != ctx->geom_secsz)
    1.35 +								LOG("WARNING: Geometry mismatch. WD2010 Write Sector with secsz %d != phys_secsz %d.", ssz, ctx->geom_secsz);
    1.36  
    1.37  							// Read Sector
    1.38  
    1.39  							// Check to see if the cyl, hd and sec are valid
    1.40 -							if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || ((ctx->sector + ctx->sector_count - 1) > ctx->geom_spt-1)) {
    1.41 -								LOG("*** WD2010 ALERT: CHS parameter limit exceeded! CHS=%d:%d:%d, nSecs=%d, endSec=%d maxCHS=%d:%d:%d",
    1.42 +							if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || ((ctx->sector + ctx->sector_count - 1) > ctx->geom_spt-1) || (ssz != ctx->geom_secsz)) {
    1.43 +								LOG("*** WD2010 ALERT: CHS parameter limit exceeded! dDrive1=%d CHS=%d:%d:%d, nSecs=%d, endSec=%d maxCHS=%d:%d:%d",
    1.44 +										ctx->mcr2_ddrive1,
    1.45  										ctx->track, ctx->head, ctx->sector,
    1.46  										ctx->sector_count,
    1.47  										ctx->sector + ctx->sector_count - 1,
    1.48 @@ -395,12 +406,22 @@
    1.49  						case CMD_WRITE_FORMAT:
    1.50  							ctx->sector = 0;
    1.51  						case CMD_WRITE_SECTOR:
    1.52 -							LOG("WD2010: WRITE SECTOR cmd=%02X chs=%d:%d:%d nsectors=%d", cmd, ctx->track, ctx->head, ctx->sector, ctx->sector_count);
    1.53 +							LOG("WD2010: WRITE SECTOR cmd=%02X sdh=0x%02X drive=%d ddrive1=%d chs=%d:%d:%d nsectors=%d", cmd, ctx->sdh, (ctx->sdh >> 3) & 3, ctx->mcr2_ddrive1, ctx->track, ctx->head, ctx->sector, val&CMD_MULTI_SECTOR ? ctx->sector_count : 1);
    1.54  							// Write Sector
    1.55  
    1.56 +							switch ((ctx->sdh >> 5) & 0x03) {
    1.57 +								case 0: ssz = 256; break;
    1.58 +								case 1: ssz = 512; break;
    1.59 +								case 2: ssz = 1024; break;
    1.60 +								case 3: ssz = 128; break;
    1.61 +							}
    1.62 +							if (ssz != ctx->geom_secsz)
    1.63 +								LOG("WARNING: Geometry mismatch. WD2010 Write Sector with secsz %d != phys_secsz %d.", ssz, ctx->geom_secsz);
    1.64 +
    1.65  							// Check to see if the cyl, hd and sec are valid
    1.66 -							if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || ((ctx->sector + ctx->sector_count - 1) > ctx->geom_spt-1)) {
    1.67 -								LOG("*** WD2010 ALERT: CHS parameter limit exceeded! CHS=%d:%d:%d, nSecs=%d, endSec=%d maxCHS=%d:%d:%d",
    1.68 +							if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || ((ctx->sector + ctx->sector_count - 1) > ctx->geom_spt-1) || (ssz != ctx->geom_secsz)) {
    1.69 +								LOG("*** WD2010 ALERT: CHS parameter limit exceeded! dDrive1=%d CHS=%d:%d:%d, nSecs=%d, endSec=%d maxCHS=%d:%d:%d",
    1.70 +										ctx->mcr2_ddrive1,
    1.71  										ctx->track, ctx->head, ctx->sector,
    1.72  										ctx->sector_count,
    1.73  										ctx->sector + ctx->sector_count - 1,