Ignore:
Timestamp:
08/01/95 15:33:39 (28 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
4f90134
Parents:
4a6e64d
Message:

updated mvme162 code from Misha (mms@…)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/m68k/mvme162/tools/sload.c

    r4a6e64d rc6fb8e90  
    5454
    5555unsigned int ahdtoi(unsigned char digit)
    56 /*       converts a hexadecimal char to an integer
    57  *
    58  *       entry        : digit = character to convert
    59  *                    : 0..15 = result
    60  *                    : -1    = char is not a digit
     56/*   converts a hexadecimal char to an integer
     57 * 
     58 *   entry        : digit = character to convert
     59 *                        : 0..15 = result
     60 *                        : -1    = char is not a digit
    6161 */
    6262{
    6363/* check digit */
    64         if (!isxdigit(digit))
    65                 return(-1);
    66 
    67         switch (toupper(digit)) {
    68                 case 'A' : return(0xA);
    69                 case 'B' : return(0xB);
    70                 case 'C' : return(0xC);
    71                 case 'D' : return(0xD);
    72                 case 'E' : return(0xE);
    73                 case 'F' : return(0xF);
    74                 default  : return(digit - 0x30);
    75         }
     64  if (!isxdigit(digit))
     65    return(-1);
     66
     67  switch (toupper(digit)) {
     68    case 'A' : return(0xA);
     69    case 'B' : return(0xB);
     70    case 'C' : return(0xC);
     71    case 'D' : return(0xD);
     72    case 'E' : return(0xE);
     73    case 'F' : return(0xF);
     74    default  : return(digit - 0x30);
     75  }
    7676}
    7777
    7878int issrec(char *str)
    79 /*      attempts to identify the type of Srecord string passed
    80  *
    81  *       entry   : str =  pointer to null terminated string
    82  *       returns : 0,1,2,3,5,7,8,9 for S0..S9 except S6 & S4
    83  *               : -1 = invalid header or header not found
    84  *                       : -2 = invalid header number
     79/*  attempts to identify the type of Srecord string passed
     80 * 
     81 *   entry   : str =  pointer to null terminated string
     82 *   returns : 0,1,2,3,5,7,8,9 for S0..S9 except S6 & S4
     83 *           : -1 = invalid header or header not found
     84 *                   : -2 = invalid header number
    8585 */
    8686{
    8787/* Check first character for S */
    88         if ((isupper(str[0]) && (str[0] == 'S')) ||
    89             (islower(str[0]) && (str[0] == 's')))
    90         {
    91         /* check for valid header number */
    92                 switch (str[1]) {
    93                         case '0' : return 0;    /* header record */
    94                         case '1' : return 1;    /* data record, 2byte addr */
    95                         case '2' : return 2;    /*  "     "   , 3byte addr */
    96                         case '3' : return 3;    /*  "     "   , 4byte addr */
    97                         case '5' : return 5;    /* number of S1,S2,S3 blocks */
    98                         case '7' : return 7;    /* S3 terminator */
    99                         case '8' : return 8;    /* S2 terminator */
    100                         case '9' : return 9;    /* S1 terminator */
    101                         default  : return -2;   /* all others are invalid */
    102                 }
    103         }
    104         return(-1);
     88  if ((isupper(str[0]) && (str[0] == 'S')) || (islower(str[0]) && (str[0] == 's')))
     89  {
     90  /* check for valid header number */
     91    switch (str[1]) {
     92      case '0' : return 0;    /* header record */
     93      case '1' : return 1;    /* data record, 2byte addr */
     94      case '2' : return 2;    /*  "     "   , 3byte addr */
     95      case '3' : return 3;    /*  "     "   , 4byte addr */
     96      case '5' : return 5;    /* number of S1,S2,S3 blocks */
     97      case '7' : return 7;    /* S3 terminator */
     98      case '8' : return 8;    /* S2 terminator */
     99      case '9' : return 9;    /* S1 terminator */
     100      default  : return -2;   /* all others are invalid */
     101    }
     102  }
     103  return(-1);
    105104}
    106105
    107106int validrec(char *str)
    108 /*      Tests for a valid srecord. tests checksum & for nondigit characters
    109  *      doesn't rely on any other srecord routines.
    110  *
    111  *        entry   : str   =  pointer to null terminated string
    112  *        returns : -1        =  srecord contains invalid characters
    113  *                            : -2    =  srecord checksum is invalid
    114  *                        : -3    =  srecord record length is invalid
    115  *                : 0     =  srecord is valid
    116  */
    117 {
    118         int                                     cn = 1, rlen=0;
    119         int                                     mchksum=0, rchksum=0;
     107/*  Tests for a valid srecord. tests checksum & for nondigit characters
     108 *  doesn't rely on any other srecord routines.
     109 * 
     110 *    entry   : str   =  pointer to null terminated string
     111 *    returns : -1        =  srecord contains invalid characters
     112 *                        : -2    =  srecord checksum is invalid
     113 *                    : -3    =  srecord record length is invalid
     114 *            : 0     =  srecord is valid
     115 */
     116{
     117  int         cn = 1, rlen=0;
     118  int         mchksum=0, rchksum=0;
    120119
    121120/* first check if there are any non-digit characters except S */
    122         while (str[cn]!=0)
    123                 if (!isxdigit(str[cn++]))
    124                         return(-1);
     121  while (str[cn]!=0)
     122    if (!isxdigit(str[cn++]))
     123      return(-1);
    125124
    126125/* test number of data bytes */
    127         rlen = ahdtoi(str[2])* 0x10 + ahdtoi(str[3]);
    128         if (((strlen(str)-4)/2U) != rlen) return(-3);
     126  rlen = ahdtoi(str[2])* 0x10 + ahdtoi(str[3]);
     127  if (((strlen(str)-4)/2U) != rlen) return(-3);
    129128
    130129/* get checksum from string */
    131         rchksum = ahdtoi(str[rlen*2+2])*0x10 + ahdtoi(str[rlen*2+3]);
    132              /* string chksum */
     130  rchksum = ahdtoi(str[rlen*2+2])*0x10 + ahdtoi(str[rlen*2+3]); /* string chksum */
    133131
    134132/* now calculate my own checksum */
    135         for (cn=2; cn <= rlen*2; )
    136                 mchksum += ahdtoi(str[cn++])*0x10 + ahdtoi(str[cn++]);
    137         mchksum = ~mchksum & 0xFF;
    138         if (mchksum != rchksum) return(-2); /* return -2 in not equal */
     133  for (cn=2; cn <= rlen*2; )
     134    mchksum += ahdtoi(str[cn++])*0x10 + ahdtoi(str[cn++]);
     135  mchksum = ~mchksum & 0xFF;
     136  if (mchksum != rchksum) return(-2); /* return -2 in not equal */
    139137
    140138/* return OK if we didn't fail any of these tests */
    141         return(0);
     139  return(0);
    142140}
    143141
    144142void hdr2str(char *sstr, char *pstr)
    145 /*      converts header record (S0) string into a plain string
    146  *
    147  *      entry        : sstr = pointer to S0 string record
    148  *      exit         : pstr = pointer to string long enough to hold string
    149  *                              (caller must allocate enough space for string)
    150  */
    151 {
    152         int                     rlen, cn, pn=0;
    153 
    154         rlen = ahdtoi(sstr[2])*0x10 + ahdtoi(sstr[3]);
    155         for (cn=8; cn <= rlen*2; )
    156                 pstr[pn++] = ahdtoi(sstr[cn++])*0x10 + ahdtoi(sstr[cn++]);
    157         pstr[pn]=0;
     143/*  converts header record (S0) string into a plain string
     144 * 
     145 *  entry        : sstr = pointer to S0 string record
     146 *  exit         : pstr = pointer to string long enough to hold string
     147 *                                (caller must allocate enough space for string)
     148 */
     149{
     150  int     rlen, cn, pn=0;
     151
     152  rlen = ahdtoi(sstr[2])*0x10 + ahdtoi(sstr[3]);
     153  for (cn=8; cn <= rlen*2; )
     154    pstr[pn++] = ahdtoi(sstr[cn++])*0x10 + ahdtoi(sstr[cn++]);
     155  pstr[pn]=0;
    158156}
    159157
    160158unsigned long getaddr(char *str)
    161 /*      returns the address of the srecord in str. assumes record is valid.
    162  *
    163  *      entry        : str = pointer to srecord string
    164  *      exit         : address of data, word or long.
    165  */
    166 {
    167         unsigned long addr=0;
    168 
    169         switch (issrec(str)) {
    170                 case 0 :
    171                 case 1 :
    172                 case 5 :
    173                 case 9 :
    174                   addr = ahdtoi(str[4])*0x1000 + ahdtoi(str[5])*0x100
    175                          + ahdtoi(str[6])*0x10 + ahdtoi(str[7]);
    176                   return(addr);
    177                 case 2 :
    178                 case 8 :
    179                   addr = ahdtoi(str[4])*0x100000 + ahdtoi(str[5])*0x10000
    180                          + ahdtoi(str[6])*0x1000 + ahdtoi(str[7])*0x100
    181                          + ahdtoi(str[8])*0x10 + ahdtoi(str[9]);
    182                   return(addr);
    183                 case 3 :
    184                 case 7 :
    185                   addr = ahdtoi(str[4])*0x10000000 + ahdtoi(str[5])*0x1000000
    186                          + ahdtoi(str[6])*0x100000 + ahdtoi(str[7])*0x10000
    187                          + ahdtoi(str[8])*0x1000 + ahdtoi(str[9])*0x100
    188                          + ahdtoi(str[10])*0x10 + ahdtoi(str[11]);
    189                   return(addr);
    190                 default : return(-1);
    191         }
     159/*  returns the address of the srecord in str. assumes record is valid.
     160 * 
     161 *  entry        : str = pointer to srecord string
     162 *  exit         : address of data, word or long.
     163 */
     164{
     165  unsigned long addr=0;
     166
     167  switch (issrec(str)) {
     168    case 0 :
     169    case 1 :
     170    case 5 :
     171    case 9 :  addr = ahdtoi(str[4])*0x1000 + ahdtoi(str[5])*0x100
     172              + ahdtoi(str[6])*0x10 + ahdtoi(str[7]);
     173              return(addr);
     174    case 2 :
     175    case 8 :  addr = ahdtoi(str[4])*0x100000 + ahdtoi(str[5])*0x10000
     176              + ahdtoi(str[6])*0x1000 + ahdtoi(str[7])*0x100
     177              + ahdtoi(str[8])*0x10 + ahdtoi(str[9]);
     178              return(addr);
     179    case 3 :
     180    case 7 :  addr = ahdtoi(str[4])*0x10000000 + ahdtoi(str[5])*0x1000000
     181              + ahdtoi(str[6])*0x100000 + ahdtoi(str[7])*0x10000
     182              + ahdtoi(str[8])*0x1000 + ahdtoi(str[9])*0x100
     183              + ahdtoi(str[10])*0x10 + ahdtoi(str[11]);
     184              return(addr);
     185    default : return(-1);
     186  }
    192187}
    193188
    194189unsigned int datasize(char *str)
    195190/*
    196  *    returns the number of data bytes in the srecord. assumes record is valid.
    197  *
    198  *      entry        : str = pointer to srecord string
    199  *      exit         : number of bytes of data in the data field.
    200  */
    201 {
    202         unsigned int size=0;
    203 
    204         switch (issrec(str)) {
    205                 case 0  :
    206                 case 1  :
    207                 case 5  :
    208                 case 7  :
    209                 case 8  :
    210                 case 9  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
    211                                                         return(size-3);
    212                 case 2  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
    213                                                         return(size-4);
    214                 case 3  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
    215                                                         return(size-5);
    216                 default : return(-1);
    217         }
     191 *  returns the number of data bytes in the srecord. assumes record is valid.
     192 * 
     193 *  entry        : str = pointer to srecord string
     194 *  exit         : number of bytes of data in the data field.
     195 */
     196{
     197  unsigned int size=0;
     198
     199  switch (issrec(str)) {
     200    case 0  :
     201    case 1  :
     202    case 5  :
     203    case 7  :
     204    case 8  :
     205    case 9  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
     206              return(size-3);
     207    case 2  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
     208              return(size-4);
     209    case 3  : size = ahdtoi(str[2])*0x10 + ahdtoi(str[3]);
     210              return(size-5);
     211    default : return(-1);
     212  }
    218213}
    219214
    220215void usage (void)
    221216/*
    222  *      prints correct usage on stdout
    223  */
    224 {
    225          printf("\nUSAGE :  sload [-v][-g][-r] [file]\n");
    226          printf("  file is an s-record file\n");
    227          printf("  -v for verbose summary of s-records loaded\n");
    228          printf("  -g to start execution\n");
    229          printf("  -r to reset MVME162\n\n");
     217 *  prints correct usage on stdout
     218 */
     219{
     220   printf("\nUSAGE :  sload [-v][-g][-r] [file]\n");
     221   printf("  file is an s-record file\n");
     222   printf("  -v for verbose summary of s-records loaded\n");
     223   printf("  -g to start execution\n");
     224   printf("  -r to reset MVME162\n\n");
    230225}
    231226
    232227int MVMEControl(u_long entry, int reset, int go)
    233 /*      Controls MVME-162 from other VME master:
     228/*  Controls MVME-162 from other VME master:
    234229 *  if entry != 0, loads it as start address
    235  *      if go != 0, starts program execution from entry
    236  *      if reset != 0, resets mvme162's local bus
     230 *  if go != 0, starts program execution from entry
     231 *  if reset != 0, resets mvme162's local bus 
    237232 *  Depends upon #define'ed GROUP_BASE_ADDRESS and BOARD_BASE_ADDRESS
    238  *      which in turn are set by the 162-BUG's ENV command.
    239  */
    240 {
    241         int          vme;
    242         char         vmedev[32] = "/dev/vme16d32"; /* d32 is important !!!  */
    243         u_long       pagesize;
    244         struct gcsr *gcsr_map;
    245 
    246         pagesize = sysconf(_SC_PAGESIZE);  /* mmap likes to be page-aligned */
    247 
    248         if ((vme = open(vmedev, O_RDWR)) == -1) {
    249           perror("open");
    250           fprintf(stderr, "Cannot open vme as %s to access GCSR\n", vmedev);
    251           return 1;
    252         }
     233 *  which in turn are set by the 162-BUG's ENV command.
     234 */
     235{
     236  int         vme;
     237  char        vmedev[32] = "/dev/vme16d32";  /* d32 is important !!!  */
     238  u_long      pagesize;
     239  struct gcsr *gcsr_map;
     240
     241  pagesize = sysconf(_SC_PAGESIZE);   /* mmap likes to be page-aligned */
     242 
     243  if ((vme = open(vmedev, O_RDWR)) == -1) {
     244    perror("open");
     245    fprintf(stderr, "Cannot open vme as %s to access GCSR\n", vmedev);
     246    return 1;
     247  }
    253248
    254249/* "MAP_SHARED" is important here */
    255         gcsr_map = (struct gcsr *)
    256           mmap(0, 0x1000, PROT_WRITE|PROT_READ, MAP_SHARED,
    257                vme, (u_long)gcsr_vme / pagesize * pagesize);
    258         if (gcsr_map == (struct gcsr *) - 1) {
    259           perror("mmap");
    260           fprintf(stderr, "Cannot mmap() to remote bus address 0x%08X\n",
    261                            (u_long)gcsr_vme / pagesize * pagesize);
    262                 return 1;
    263         }
     250  gcsr_map = (struct gcsr *) mmap(0, 0x1000, PROT_WRITE|PROT_READ, MAP_SHARED,
     251                          vme, (u_long)gcsr_vme / pagesize * pagesize);
     252  if (gcsr_map == (struct gcsr *) - 1) {
     253    perror("mmap");
     254    fprintf(stderr, "Cannot mmap() to remote bus address 0x%08X\n",
     255                 (u_long)gcsr_vme / pagesize * pagesize);
     256    return 1;
     257  }
    264258
    265259/*
    266260 * use GCSR to start execution in MVME162
    267  * adjust pointer to compensate for page alignement
    268  */
    269         gcsr_map = (struct gcsr *)((u_long)gcsr_map +
    270                        (u_long)gcsr_vme % pagesize);
    271 
    272         if (reset) {                           /* reset the local bus... */
    273                 gcsr_map->board_scr |= 0x80;
    274         }
    275         if (entry) {                           /* ...load start address... */
    276                 gcsr_map->gpr[0] = entry >> 16U;
    277                 gcsr_map->gpr[1] = entry & 0x0000FFFF;
    278         }
    279         if (go) {                              /* ... and kick it in the ass! */
    280                 gcsr_map->lmsig = 0x1;
    281         }
     261 * adjust pointer to compensate for page alignement
     262 */
     263  gcsr_map = (struct gcsr *)((u_long)gcsr_map + (u_long)gcsr_vme % pagesize);
     264
     265  if (reset) {                /* reset the local bus... */
     266    gcsr_map->board_scr |= 0x80;
     267  }
     268  if (entry) {                /* ...load start address... */
     269    gcsr_map->gpr[0] = entry >> 16U;
     270    gcsr_map->gpr[1] = entry & 0x0000FFFF;
     271  }
     272  if (go) {                   /* ... and kick it in the ass! */
     273    gcsr_map->lmsig = 0x1;
     274  }
    282275}
    283276
     
    285278main(int argc, char *argv[])
    286279{
    287         char       inpstr[256];
    288         u_char     image[256];
    289         char       hdrstr[64];
    290         int        i, j, k, result, size, line=0, lastrec=0;
    291         long       addr, tsize=0, naddr=0, blksize=0, blknum=1;
    292         FILE       *in;
    293         char       infile[256] = "";
    294         char       vmedev[32] = "/dev/vme32d32";  /* Assume "/dev/vme32d32"  */
    295         int        vme, verbose = 0, go = 0, reset = 0, havefile = 0;
    296 
    297 /*      Parse the command line */
     280  char        inpstr[256];
     281  u_char      image[256];
     282  char        hdrstr[64];
     283  int         i, j, k, result, size, line=0, lastrec=0;
     284  long        addr, tsize=0, naddr=0, blksize=0, blknum=1;
     285  FILE        *in;
     286  char        infile[256] = "";
     287  char        vmedev[32] = "/dev/vme32d32";   /* Assume "/dev/vme32d32"  */
     288  int         vme, verbose = 0, go = 0, reset = 0, havefile = 0;
     289 
     290/*  Parse the command line */
    298291
    299292  --argc;
    300293
    301294  while (argv++, argc--) {
    302         if (**argv != '-') {
    303                 strcpy(infile, *argv);
    304                 havefile = 1;
     295    if (**argv != '-') {
     296      strcpy(infile, *argv);
     297      havefile = 1;
    305298    } else if (!strcmp(*argv, "-v")) {
    306299      verbose = 1;
     
    326319  if (!havefile) {
    327320    if (!reset && !go) {
    328       usage();
     321        usage();
    329322    }
    330323    else {
     
    333326    exit(0);
    334327  }
    335 
     328 
    336329  if ((in = fopen(infile, "r")) == NULL) {
    337330    perror("open");
    338331    fprintf(stderr, "Cannot open input file %s\n", infile);
    339     exit(1);
     332    exit(1); 
    340333  }
    341334
     
    348341    if (validrec(inpstr) == 0) {
    349342      switch (issrec(inpstr)) {
    350         case 0 :
    351           hdr2str(inpstr, hdrstr);
    352           if (verbose) printf("HEADER string = `%s'\n", hdrstr);
    353           lastrec=HEADER;
    354           break;
    355         case 1 :
    356           addr = getaddr(inpstr);
    357           size = datasize(inpstr);
    358           if (blksize == 0) {
    359             blksize+=size;
    360             naddr=addr+size;
    361             if (verbose) printf("DATA\tS19\t$%04lX", addr);
    362             lastrec=DATA19;
     343      case 0 :
     344        hdr2str(inpstr, hdrstr);
     345        if (verbose) printf("HEADER string = `%s'\n", hdrstr);
     346        lastrec=HEADER;
     347        break;
     348      case 1 :
     349        addr = getaddr(inpstr);
     350        size = datasize(inpstr);
     351        if (blksize == 0) {
     352          blksize+=size;
     353          naddr=addr+size;
     354          if (verbose) printf("DATA\tS19\t$%04lX", addr);
     355          lastrec=DATA19;
     356        }
     357        else if ((blksize!=0) && (addr==naddr)) {
     358          blksize+=size;
     359          naddr=addr+size;
     360        }
     361        else {
     362          if (verbose) printf("\t$%04lX\t%lu", naddr-1, blksize);
     363          if (verbose) printf("\t%d\n", blknum);
     364          blknum+=1;
     365          naddr=addr+size;
     366          blksize=size;
     367          if (verbose) printf("DATA\tS19\t$%04lX", addr);
     368          lastrec=DATA19;
     369        }
     370        tsize += size;
     371        if (vme == -1) break;
     372        for (i = 0, j = 8, k = size; k-- > 0; i += 1, j += 2) {
     373          image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
     374        }
     375        if (lseek(vme, addr, SEEK_SET) == -1) {
     376          fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
     377        }
     378        else {
     379          if (write(vme, (u_char *)image, size) != size) {
     380            fprintf(stderr, "Write to vme address %08X failed\n", addr);
    363381          }
    364           else if ((blksize!=0) && (addr==naddr)) {
    365             blksize+=size;
    366             naddr=addr+size;
     382        }
     383        break;
     384      case 2 :
     385        addr = getaddr(inpstr);
     386        size = datasize(inpstr);
     387        if (blksize == 0) {
     388          blksize+=size;
     389          naddr=addr+size;
     390          if (verbose) printf("DATA\tS28\t$%06lX",addr);
     391          lastrec=DATA28;
     392        }
     393        else if ((blksize!=0) && (addr==naddr)) {
     394          blksize+=size;
     395          naddr=addr+size;
     396        }
     397        else {
     398          if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
     399          if (verbose) printf("\t%d\n",blknum);
     400          blknum+=1;
     401          naddr=addr+size;
     402          blksize=size;
     403          if (verbose) printf("DATA\tS28\t$%06lX",addr);
     404          lastrec=DATA28;
     405        }
     406        tsize += size;
     407        if (vme == -1) break;
     408        for (i = 0, j = 10, k = size; k-- > 0; i += 1, j += 2) {
     409          image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
     410        }
     411        if (lseek(vme, addr, SEEK_SET) == -1) {
     412          fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
     413        }
     414        else {
     415          if (write(vme, (u_char *)image, size) != size) {
     416            fprintf(stderr, "Write to vme address %08X failed\n", addr);
    367417          }
    368           else {
    369             if (verbose) printf("\t$%04lX\t%lu", naddr-1, blksize);
    370             if (verbose) printf("\t%d\n", blknum);
    371             blknum+=1;
    372             naddr=addr+size;
    373             blksize=size;
    374             if (verbose) printf("DATA\tS19\t$%04lX", addr);
    375             lastrec=DATA19;
     418        }
     419        break;
     420      case 3 :
     421        addr = getaddr(inpstr);
     422        size = datasize(inpstr);
     423        if (blksize == 0) {
     424          blksize+=size;
     425          naddr=addr+size;
     426          if (verbose) printf("DATA\tS37\t$%08lX",addr);
     427          lastrec=DATA37;
     428        }
     429        else if ((blksize!=0) && (addr==naddr)) {
     430          blksize+=size;
     431          naddr=addr+size;
     432        }
     433        else {
     434          if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
     435          if (verbose) printf("\t%d\n",blknum);
     436          blknum+=1;
     437          naddr=addr+size;
     438          blksize=size;
     439          if (verbose) printf("DATA\tS37\t$%08lX",addr);
     440          lastrec=DATA37;
     441        }
     442        tsize += size;
     443        if (vme == -1) break;
     444        for (i = 0, j = 12, k = size; k-- > 0; i += 1, j += 2) {
     445          image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
     446        }
     447        if (lseek(vme, addr, SEEK_SET) == -1) {
     448          fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
     449        }
     450        else {
     451          if (write(vme, (u_char *)image, size) != size) {
     452            fprintf(stderr, "Write to vme address %08X failed\n", addr);
    376453          }
    377           tsize += size;
    378           if (vme == -1) break;
    379           for (i = 0, j = 8, k = size; k-- > 0; i += 1, j += 2) {
    380             image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
    381           }
    382           if (lseek(vme, addr, SEEK_SET) == -1) {
    383             fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
    384           }
    385           else {
    386             if (write(vme, (u_char *)image, size) != size) {
    387               fprintf(stderr, "Write to vme address %08X failed\n", addr);
    388             }
    389           }
    390           break;
    391         case 2 :
    392           addr = getaddr(inpstr);
    393           size = datasize(inpstr);
    394           if (blksize == 0) {
    395             blksize+=size;
    396             naddr=addr+size;
    397             if (verbose) printf("DATA\tS28\t$%06lX",addr);
    398             lastrec=DATA28;
    399           }
    400           else if ((blksize!=0) && (addr==naddr)) {
    401             blksize+=size;
    402             naddr=addr+size;
    403           }
    404           else {
    405             if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
    406             if (verbose) printf("\t%d\n",blknum);
    407             blknum+=1;
    408             naddr=addr+size;
    409             blksize=size;
    410             if (verbose) printf("DATA\tS28\t$%06lX",addr);
    411             lastrec=DATA28;
    412           }
    413           tsize += size;
    414           if (vme == -1) break;
    415           for (i = 0, j = 10, k = size; k-- > 0; i += 1, j += 2) {
    416             image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
    417           }
    418           if (lseek(vme, addr, SEEK_SET) == -1) {
    419             fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
    420           }
    421           else {
    422             if (write(vme, (u_char *)image, size) != size) {
    423               fprintf(stderr, "Write to vme address %08X failed\n", addr);
    424             }
    425           }
    426           break;
    427         case 3 :
    428           addr = getaddr(inpstr);
    429           size = datasize(inpstr);
    430           if (blksize == 0) {
    431             blksize+=size;
    432             naddr=addr+size;
    433             if (verbose) printf("DATA\tS37\t$%08lX",addr);
    434             lastrec=DATA37;
    435           }
    436           else if ((blksize!=0) && (addr==naddr)) {
    437             blksize+=size;
    438             naddr=addr+size;
    439           }
    440           else {
    441             if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
    442             if (verbose) printf("\t%d\n",blknum);
    443             blknum+=1;
    444             naddr=addr+size;
    445             blksize=size;
    446             if (verbose) printf("DATA\tS37\t$%08lX",addr);
    447             lastrec=DATA37;
    448           }
    449           tsize += size;
    450           if (vme == -1) break;
    451           for (i = 0, j = 12, k = size; k-- > 0; i += 1, j += 2) {
    452             image[i] = ahdtoi(inpstr[j])*0x10 + ahdtoi(inpstr[j+1]);
    453           }
    454           if (lseek(vme, addr, SEEK_SET) == -1) {
    455             fprintf(stderr, "lseek() to vme address %08X failed\n", addr);
    456           }
    457           else {
    458             if (write(vme, (u_char *)image, size) != size) {
    459               fprintf(stderr, "Write to vme address %08X failed\n", addr);
    460             }
    461           }
    462           break;
    463         case 7 :
    464           if (lastrec==DATA19){
    465             if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);
    466           }
    467           if (lastrec==DATA28){
    468             if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
    469           }
    470           if (lastrec==DATA37){
    471             if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
    472           }
    473           if (verbose) printf("\t%d\n",blknum);
    474           addr = getaddr(inpstr);
    475           if (verbose) printf("TERM\tS37");
    476           printf("\nExecution address = $%08lX\n", addr);
    477           lastrec=TERMINATOR;
    478           break;
    479         case 8 :
    480           if (lastrec==DATA19){
    481             if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);
    482           }
    483           if (lastrec==DATA28){
    484             if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
    485           }
    486           if (lastrec==DATA37){
    487             if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
    488           }
    489           if (verbose) printf("\t%d\n",blknum);
    490           addr = getaddr(inpstr);
    491           if (verbose) printf("TERM\tS28");
    492           printf("\nExecution address = $%06lX\n", addr);
    493           lastrec=TERMINATOR;
    494           break;
    495         case 9 :
    496           if (lastrec==DATA19){
    497             if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);
    498           }
    499           if (lastrec==DATA28){
    500             if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
    501           }
    502           if (lastrec==DATA37){
    503             if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
    504           }
    505           if (verbose) printf("\t%d\n",blknum);
    506           addr = getaddr(inpstr);
    507           if (verbose) printf("TERM\tS19");
    508           printf("\nExecution address = $%04lX\n", addr);
    509           lastrec=TERMINATOR;
    510           break;
    511         }
     454        }
     455        break;
     456      case 7 :
     457        if (lastrec==DATA19){if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);}
     458        if (lastrec==DATA28){if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);}
     459        if (lastrec==DATA37){if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);}
     460        if (verbose) printf("\t%d\n",blknum);
     461        addr = getaddr(inpstr);
     462        if (verbose) printf("TERM\tS37");
     463        printf("\nExecution address = $%08lX\n", addr);
     464        lastrec=TERMINATOR;
     465        break;
     466      case 8 :
     467        if (lastrec==DATA19){if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);}
     468        if (lastrec==DATA28){if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);}
     469        if (lastrec==DATA37){if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);}
     470        if (verbose) printf("\t%d\n",blknum);
     471        addr = getaddr(inpstr);
     472        if (verbose) printf("TERM\tS28");
     473        printf("\nExecution address = $%06lX\n", addr);
     474        lastrec=TERMINATOR;
     475        break;
     476      case 9 :
     477        if (lastrec==DATA19){if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);}
     478        if (lastrec==DATA28){if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);}
     479        if (lastrec==DATA37){if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);}
     480        if (verbose) printf("\t%d\n",blknum);
     481        addr = getaddr(inpstr);
     482        if (verbose) printf("TERM\tS19");
     483        printf("\nExecution address = $%04lX\n", addr);
     484        lastrec=TERMINATOR;
     485        break;
    512486      }
    513       else {
    514         printf("\nError on line %d. ",line);
    515         switch (validrec(inpstr)) {
    516           case -1 : {printf("SRecord contains invalid characters.\n"); break; }
    517           case -2 : {printf("SRecord checksum is invalid.\n"); break;}
    518           case -3 : {printf("SRecord length is invalid.\n"); break;}
    519         }
    520        exit(1);
    521      }
    522    }
    523 
    524    if ((lastrec==DATA19) || (lastrec==DATA28) || (lastrec==DATA37)) {
    525      if (lastrec==DATA19){
    526        if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);
    527      }
    528      if (lastrec==DATA28){
    529        if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);
    530      }
    531      if (lastrec==DATA37){
    532        if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);
    533      }
    534      if (verbose) printf("\t%d\n",blknum);
    535      printf("ERROR: terminator record not found.\n");
    536    }
    537    else {
    538      for (i = 0x000FFFF; i-- > 0;) ; /* mystique delay... */
    539        MVMEControl(addr, reset, go);
    540      }
    541    if (verbose) printf("total data size = %lu bytes\n", tsize);
    542 }
     487    }
     488    else {
     489      printf("\nError on line %d. ",line);
     490      switch (validrec(inpstr)) {
     491      case -1 : {printf("SRecord contains invalid characters.\n"); break; }
     492      case -2 : {printf("SRecord checksum is invalid.\n"); break;}
     493      case -3 : {printf("SRecord length is invalid.\n"); break;}
     494      }
     495      exit(1);
     496    }
     497  }
     498
     499  if ((lastrec==DATA19) || (lastrec==DATA28) || (lastrec==DATA37)) {
     500    if (lastrec==DATA19){if (verbose) printf("\t$%04lX\t%lu",naddr-1,blksize);}
     501    if (lastrec==DATA28){if (verbose) printf("\t$%06lX\t%lu",naddr-1,blksize);}
     502    if (lastrec==DATA37){if (verbose) printf("\t$%08lX\t%lu",naddr-1,blksize);}
     503    if (verbose) printf("\t%d\n",blknum);
     504    printf("ERROR: terminator record not found.\n");
     505  }
     506  else {
     507    for (i = 0x000FFFF; i-- > 0;) ;           /* mystique delay... */
     508    MVMEControl(addr, reset, go);
     509  }
     510  if (verbose) printf("total data size = %lu bytes\n", tsize);
     511}
Note: See TracChangeset for help on using the changeset viewer.