/[gxemul]/trunk/src/diskimage.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/diskimage.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: diskimage.c,v 1.95 2005/08/10 22:25:50 debug Exp $   *  $Id: diskimage.c,v 1.102 2005/11/21 09:17:25 debug Exp $
29   *   *
30   *  Disk image support.   *  Disk image support.
31   *   *
# Line 53  Line 53 
53  #include "misc.h"  #include "misc.h"
54    
55    
56  extern int quiet_mode;  /*  #define debug fatal  */
57    
58  extern int single_step;  extern int single_step;
59    
60  static char *diskimage_types[] = DISKIMAGE_TYPES;  static char *diskimage_types[] = DISKIMAGE_TYPES;
# Line 478  static int diskimage__internal_access(st Line 479  static int diskimage__internal_access(st
479  int diskimage_scsicommand(struct cpu *cpu, int id, int type,  int diskimage_scsicommand(struct cpu *cpu, int id, int type,
480          struct scsi_transfer *xferp)          struct scsi_transfer *xferp)
481  {  {
482          int retlen, i;          char namebuf[16];
483            int retlen, i, q;
484          uint64_t size;          uint64_t size;
485          int64_t ofs;          int64_t ofs;
486          int pagecode;          int pagecode;
# Line 588  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 590  xferp->data_in[4] = 0x2c - 4;  /*  Additi
590                  xferp->data_in[6] = 0x04;  /*  ACKREQQ  */                  xferp->data_in[6] = 0x04;  /*  ACKREQQ  */
591                  xferp->data_in[7] = 0x60;  /*  WBus32, WBus16  */                  xferp->data_in[7] = 0x60;  /*  WBus32, WBus16  */
592    
593                  /*  These must be padded with spaces:  */                  /*  These are padded with spaces:  */
594                  memcpy(xferp->data_in+8,  "FAKE    ", 8);  
595                  memcpy(xferp->data_in+16, "DISK            ", 16);                  memcpy(xferp->data_in+8,  "GXemul  ", 8);
596                  memcpy(xferp->data_in+32, "V0.0", 4);                  if (diskimage_getname(cpu->machine, id,
597                        type, namebuf, sizeof(namebuf))) {
598                            int i;
599                            for (i=0; i<sizeof(namebuf); i++)
600                                    if (namebuf[i] == 0) {
601                                            for (; i<sizeof(namebuf); i++)
602                                                    namebuf[i] = ' ';
603                                            break;
604                                    }
605                            memcpy(xferp->data_in+16, namebuf, 16);
606                    } else
607                            memcpy(xferp->data_in+16, "DISK            ", 16);
608                    memcpy(xferp->data_in+32, "0   ", 4);
609    
610                  /*                  /*
611                   *  Some Ultrix kernels want specific responses from                   *  Some Ultrix kernels want specific responses from
# Line 610  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 624  xferp->data_in[4] = 0x2c - 4;  /*  Additi
624                  if (d->is_a_cdrom) {                  if (d->is_a_cdrom) {
625                          xferp->data_in[0] = 0x05;  /*  0x05 = CD-ROM  */                          xferp->data_in[0] = 0x05;  /*  0x05 = CD-ROM  */
626                          xferp->data_in[1] = 0x80;  /*  0x80 = removable  */                          xferp->data_in[1] = 0x80;  /*  0x80 = removable  */
627                          memcpy(xferp->data_in+16, "CD-ROM          ", 16);                          /*  memcpy(xferp->data_in+16, "CD-ROM          ", 16);*/
628    
629                          if (machine->machine_type == MACHINE_DEC) {                          if (machine->machine_type == MACHINE_DEC) {
630                                  /*  SONY, CD-ROM:  */                                  /*  SONY, CD-ROM:  */
# Line 623  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 637  xferp->data_in[4] = 0x2c - 4;  /*  Additi
637                                  memcpy(xferp->data_in+16,                                  memcpy(xferp->data_in+16,
638                                      "RRD42   (C) DEC ", 16);                                      "RRD42   (C) DEC ", 16);
639                                  memcpy(xferp->data_in+32, "4.5d", 4);                                  memcpy(xferp->data_in+32, "4.5d", 4);
640                          } else {                          } else if (machine->machine_type == MACHINE_ARC) {
641                                  /*  NEC, CD-ROM:  */                                  /*  NEC, CD-ROM:  */
642                                  memcpy(xferp->data_in+8, "NEC     ", 8);                                  memcpy(xferp->data_in+8, "NEC     ", 8);
643                                  memcpy(xferp->data_in+16,                                  memcpy(xferp->data_in+16,
# Line 693  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 707  xferp->data_in[4] = 0x2c - 4;  /*  Additi
707                  break;                  break;
708    
709          case SCSICMD_MODE_SENSE:          case SCSICMD_MODE_SENSE:
710            case SCSICMD_MODE_SENSE10:      
711                  debug("MODE_SENSE");                  debug("MODE_SENSE");
712                    q = 4; retlen = xferp->cmd[4];
713                  if (xferp->cmd_len != 6)                  switch (xferp->cmd_len) {
714                          fatal(" (unimplemented mode_sense len=%i)",                  case 6: break;
715                    case 10:q = 8;
716                            retlen = xferp->cmd[7] * 256 + xferp->cmd[8];
717                            break;
718                    default:fatal(" (unimplemented mode_sense len=%i)",
719                              xferp->cmd_len);                              xferp->cmd_len);
720                    }
                 retlen = xferp->cmd[4];  
721    
722                  /*                  /*
723                   *  NOTE/TODO: This code doesn't handle too short retlens                   *  NOTE/TODO: This code doesn't handle too short retlens
# Line 734  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 752  xferp->data_in[4] = 0x2c - 4;  /*  Additi
752                  xferp->data_in[3] = 8 * 1;      /*  block descriptor                  xferp->data_in[3] = 8 * 1;      /*  block descriptor
753                                                      length: 1 page (?)  */                                                      length: 1 page (?)  */
754    
755                  /*  TODO: update this when implementing 10-byte commands:  */                  xferp->data_in[q+0] = 0x00;     /*  density code  */
756                  xferp->data_in[4] = 0x00;       /*  density code  */                  xferp->data_in[q+1] = 0;        /*  nr of blocks, high  */
757                  xferp->data_in[5] = 0;          /*  nr of blocks, high  */                  xferp->data_in[q+2] = 0;        /*  nr of blocks, mid  */
758                  xferp->data_in[6] = 0;          /*  nr of blocks, mid  */                  xferp->data_in[q+3] = 0;        /*  nr of blocks, low */
759                  xferp->data_in[7] = 0;          /*  nr of blocks, low */                  xferp->data_in[q+4] = 0x00;     /*  reserved  */
760                  xferp->data_in[8] = 0x00;       /*  reserved  */                  xferp->data_in[q+5] = (d->logical_block_size >> 16) & 255;
761                  xferp->data_in[9] = (d->logical_block_size >> 16) & 255;                  xferp->data_in[q+6] = (d->logical_block_size >> 8) & 255;
762                  xferp->data_in[10] = (d->logical_block_size >> 8) & 255;                  xferp->data_in[q+7] = d->logical_block_size & 255;
763                  xferp->data_in[11] = d->logical_block_size & 255;                  q += 8;
764    
765                  diskimage__return_default_status_and_message(xferp);                  diskimage__return_default_status_and_message(xferp);
766    
# Line 754  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 772  xferp->data_in[4] = 0x2c - 4;  /*  Additi
772                          /*  TODO: Nothing here?  */                          /*  TODO: Nothing here?  */
773                          break;                          break;
774                  case 1:         /*  read-write error recovery page  */                  case 1:         /*  read-write error recovery page  */
775                          xferp->data_in[12 + 0] = pagecode;                          xferp->data_in[q + 0] = pagecode;
776                          xferp->data_in[12 + 1] = 10;                          xferp->data_in[q + 1] = 10;
777                          break;                          break;
778                  case 3:         /*  format device page  */                  case 3:         /*  format device page  */
779                          xferp->data_in[12 + 0] = pagecode;                          xferp->data_in[q + 0] = pagecode;
780                          xferp->data_in[12 + 1] = 22;                          xferp->data_in[q + 1] = 22;
781    
782                          /*  10,11 = sectors per track  */                          /*  10,11 = sectors per track  */
783                          xferp->data_in[12 + 10] = 0;                          xferp->data_in[q + 10] = 0;
784                          xferp->data_in[12 + 11] = d->sectors_per_track;                          xferp->data_in[q + 11] = d->sectors_per_track;
785    
786                          /*  12,13 = physical sector size  */                          /*  12,13 = physical sector size  */
787                          xferp->data_in[12 + 12] =                          xferp->data_in[q + 12] =
788                              (d->logical_block_size >> 8) & 255;                              (d->logical_block_size >> 8) & 255;
789                          xferp->data_in[12 + 13] = d->logical_block_size & 255;                          xferp->data_in[q + 13] = d->logical_block_size & 255;
790                          break;                          break;
791                  case 4:         /*  rigid disk geometry page  */                  case 4:         /*  rigid disk geometry page  */
792                          xferp->data_in[12 + 0] = pagecode;                          xferp->data_in[q + 0] = pagecode;
793                          xferp->data_in[12 + 1] = 22;                          xferp->data_in[q + 1] = 22;
794                          xferp->data_in[12 + 2] = (d->ncyls >> 16) & 255;                          xferp->data_in[q + 2] = (d->ncyls >> 16) & 255;
795                          xferp->data_in[12 + 3] = (d->ncyls >> 8) & 255;                          xferp->data_in[q + 3] = (d->ncyls >> 8) & 255;
796                          xferp->data_in[12 + 4] = d->ncyls & 255;                          xferp->data_in[q + 4] = d->ncyls & 255;
797                          xferp->data_in[12 + 5] = d->heads;                          xferp->data_in[q + 5] = d->heads;
798    
799                          xferp->data_in[12 + 20] = (d->rpms >> 8) & 255;                          xferp->data_in[q + 20] = (d->rpms >> 8) & 255;
800                          xferp->data_in[12 + 21] = d->rpms & 255;                          xferp->data_in[q + 21] = d->rpms & 255;
801                          break;                          break;
802                  case 5:         /*  flexible disk page  */                  case 5:         /*  flexible disk page  */
803                          xferp->data_in[12 + 0] = pagecode;                          xferp->data_in[q + 0] = pagecode;
804                          xferp->data_in[12 + 1] = 0x1e;                          xferp->data_in[q + 1] = 0x1e;
805    
806                          /*  2,3 = transfer rate  */                          /*  2,3 = transfer rate  */
807                          xferp->data_in[12 + 2] = ((5000) >> 8) & 255;                          xferp->data_in[q + 2] = ((5000) >> 8) & 255;
808                          xferp->data_in[12 + 3] = (5000) & 255;                          xferp->data_in[q + 3] = (5000) & 255;
809    
810                          xferp->data_in[12 + 4] = d->heads;                          xferp->data_in[q + 4] = d->heads;
811                          xferp->data_in[12 + 5] = d->sectors_per_track;                          xferp->data_in[q + 5] = d->sectors_per_track;
812    
813                          /*  6,7 = data bytes per sector  */                          /*  6,7 = data bytes per sector  */
814                          xferp->data_in[12 + 6] = (d->logical_block_size >> 8)                          xferp->data_in[q + 6] = (d->logical_block_size >> 8)
815                              & 255;                              & 255;
816                          xferp->data_in[12 + 7] = d->logical_block_size & 255;                          xferp->data_in[q + 7] = d->logical_block_size & 255;
817    
818                          xferp->data_in[12 + 8] = (d->ncyls >> 8) & 255;                          xferp->data_in[q + 8] = (d->ncyls >> 8) & 255;
819                          xferp->data_in[12 + 9] = d->ncyls & 255;                          xferp->data_in[q + 9] = d->ncyls & 255;
820    
821                          xferp->data_in[12 + 28] = (d->rpms >> 8) & 255;                          xferp->data_in[q + 28] = (d->rpms >> 8) & 255;
822                          xferp->data_in[12 + 29] = d->rpms & 255;                          xferp->data_in[q + 29] = d->rpms & 255;
823                          break;                          break;
824                  default:                  default:
825                          fatal("[ MODE_SENSE for page %i is not yet "                          fatal("[ MODE_SENSE for page %i is not yet "
# Line 1215  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 1233  xferp->data_in[4] = 0x2c - 4;  /*  Additi
1233                  scsi_transfer_allocbuf(&xferp->data_in_len,                  scsi_transfer_allocbuf(&xferp->data_in_len,
1234                      &xferp->data_in, retlen, 1);                      &xferp->data_in, retlen, 1);
1235    
1236                  /*  TODO  */                  xferp->data_in[0] = 0;
1237                    xferp->data_in[1] = 10;
1238                    xferp->data_in[2] = 0;          /*  First track.  */
1239                    xferp->data_in[3] = 0;          /*  Last track.  */
1240    
1241                    /*  Track 0 data:  */
1242                    xferp->data_in[4] = 0x00;       /*  Reserved.  */
1243                    xferp->data_in[5] = 0x04;       /*  ADR + CTRL:
1244                                                        Data, not audio  */
1245                    xferp->data_in[6] = 0x00;       /*  Track nr  */
1246                    xferp->data_in[7] = 0x00;       /*  Reserved  */
1247                    /*  8..11 = absolute CDROM address  */
1248    
1249                  diskimage__return_default_status_and_message(xferp);                  diskimage__return_default_status_and_message(xferp);
1250                  break;                  break;
# Line 1268  xferp->data_in[4] = 0x2c - 4;  /*  Additi Line 1297  xferp->data_in[4] = 0x2c - 4;  /*  Additi
1297                  diskimage__return_default_status_and_message(xferp);                  diskimage__return_default_status_and_message(xferp);
1298                  break;                  break;
1299    
1300          case 0x1e:          case SCSICMD_PREVENT_ALLOW_REMOVE:
1301                  debug("[ SCSI 0x%02x: TODO ]\n", xferp->cmd[0]);                  debug("[ SCSI 0x%02x Prevent/allow medium removal: "
1302                        "TODO ]\n", xferp->cmd[0]);
                 /*  TODO  */  
1303    
1304                  diskimage__return_default_status_and_message(xferp);                  diskimage__return_default_status_and_message(xferp);
1305                  break;                  break;
# Line 1477  int diskimage_add(struct machine *machin Line 1505  int diskimage_add(struct machine *machin
1505              machine->machine_type == MACHINE_COBALT ||              machine->machine_type == MACHINE_COBALT ||
1506              machine->machine_type == MACHINE_EVBMIPS ||              machine->machine_type == MACHINE_EVBMIPS ||
1507              machine->machine_type == MACHINE_HPCMIPS ||              machine->machine_type == MACHINE_HPCMIPS ||
1508                machine->machine_type == MACHINE_BEBOX ||
1509                machine->machine_type == MACHINE_PREP ||
1510                machine->machine_type == MACHINE_CATS ||
1511                machine->machine_type == MACHINE_NETWINDER ||
1512              machine->machine_type == MACHINE_PS2)              machine->machine_type == MACHINE_PS2)
1513                  d->type = DISKIMAGE_IDE;                  d->type = DISKIMAGE_IDE;
1514    
# Line 1505  int diskimage_add(struct machine *machin Line 1537  int diskimage_add(struct machine *machin
1537           *  Is this a tape, CD-ROM or a normal disk?           *  Is this a tape, CD-ROM or a normal disk?
1538           *           *
1539           *  An intelligent guess, if no prefixes are used, would be that           *  An intelligent guess, if no prefixes are used, would be that
1540           *  filenames ending with .iso are CD-ROM images.           *  filenames ending with .iso or .cdr are CD-ROM images.
1541           */           */
1542          if (prefix_t) {          if (prefix_t) {
1543                  d->is_a_tape = 1;                  d->is_a_tape = 1;
1544          } else {          } else {
1545                  if (prefix_c ||                  if (prefix_c ||
1546                      ((strlen(d->fname) > 4 &&                      ((strlen(d->fname) > 4 &&
1547                      strcasecmp(d->fname + strlen(d->fname) - 4, ".iso") == 0)                      (strcasecmp(d->fname + strlen(d->fname) - 4, ".cdr") == 0 ||
1548                        strcasecmp(d->fname + strlen(d->fname) - 4, ".iso") == 0))
1549                      && !prefix_d)                      && !prefix_d)
1550                     ) {                     ) {
1551                          d->is_a_cdrom = 1;                          d->is_a_cdrom = 1;
# Line 1669  int diskimage_bootdev(struct machine *ma Line 1702  int diskimage_bootdev(struct machine *ma
1702  }  }
1703    
1704    
1705    /*
1706     *  diskimage_getname():
1707     *
1708     *  Returns 1 if a valid disk image name was returned, 0 otherwise.
1709     */
1710    int diskimage_getname(struct machine *machine, int id, int type,
1711            char *buf, size_t bufsize)
1712    {
1713            struct diskimage *d = machine->first_diskimage;
1714    
1715            if (buf == NULL)
1716                    return 0;
1717    
1718            while (d != NULL) {
1719                    if (d->type == type && d->id == id) {
1720                            char *p = strrchr(d->fname, '/');
1721                            if (p == NULL)
1722                                    p = d->fname;
1723                            else
1724                                    p ++;
1725                            snprintf(buf, bufsize, "%s", p);
1726                            return 1;
1727                    }
1728                    d = d->next;
1729            }
1730            return 0;
1731    }
1732    
1733    
1734  /*  /*
1735   *  diskimage_is_a_cdrom():   *  diskimage_is_a_cdrom():
1736   *   *

Legend:
Removed from v.12  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26