src/wd2010.c

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