Пример #1
0
static void read_data (FILE *fp)
/* ------------------------------------------------------------------------- *
 * Read in data files.  If NZ > 1, it is assumed that data are in the file
 * in plane-by-plane order.  For each plane, the ordering of data varies
 * depending on whether the file is in ASCII or binary format: for ASCII, the
 * fields are in column order, element-by-element (row-major), whereas for
 * binary formats the fields are written in the file sequentially.
 *
 * Automatic conversion between little- and big-endian binary formats.
 * ------------------------------------------------------------------------- */
{
  int  i, m, n, nplane;
  int  nr_chk, ns_chk, nz_chk, nel_chk;
  char buf[STR_MAX], *c;
  
  /* -- Read the header down to the field list, check size of input. */

  for (n = 0; n < 3; n++) {
    fgets (buf, STR_MAX, fp);
  }

  if (sscanf (buf, "%d%d%d%d", &nr_chk, &ns_chk, &nz_chk, &nel_chk) != 4) {
    fputs ("error reading size of field\n", stderr);
    exit  (EXIT_FAILURE);
  }

  if (nr != nr_chk || ns != ns_chk || nel != nel_chk) {
    fputs ("2D structure of mesh and field file do not agree\n", stderr);
    exit (EXIT_FAILURE);
  }

  for (n = 3; n < 9; n++) fgets(buf, STR_MAX, fp);

  /* -- Read the list of fields. */

  n       = 0;
  c       = buf;
  nfields = 0;
  while (isalpha(*c) && nfields < MAXFIELDS) type[nfields++] = (*c++);

  if (nfields > MAXFIELDS) {
    fprintf(stderr, "sem2tec: a maximum of %d fields may be converted.\n", 
	    MAXFIELDS);
    exit(EXIT_FAILURE);
  }

  /* -- Allocate memory. */

  nplane = nr * ns * nel;
  for (n = 0; n < nfields; n++)
    data[n] = (double*) malloc (nzp * nplane * sizeof (double));

  /* -- Check the format. */

  c = fgets(buf, STR_MAX, fp); 
  while (isspace(*c)) c++;

  switch (tolower(*c)) {                     /* ASCII or binary read? */

  case 'a':
    for (m = 0; m < nz; m++)
      for (i = 0; i < nplane; i++)
	for (n = 0; n < nfields; n++)
	  if (fscanf(fp, "%lf", data[n] + m * nplane + i) < 0) {
	    fputs("sem2tec: field file (ASCII) read error\n", stderr);
	    exit (EXIT_FAILURE);
	  }
    break;

  case 'b': {
    int swab, machine  = iformat();

    swab = (strstr (buf, "little") && machine == 0 ||
	    strstr (buf, "big"   ) && machine == 1  ) ? 1 : 0;

    for (n = 0; n < nfields; n++) {
      if (fread (data[n], sizeof(double), nz * nplane, fp) != nz * nplane) {
	fputs("sem2tec: field file (binary) read error\n", stderr);
	  exit (EXIT_FAILURE);
      }
      if (swab) dbrev (nz * nplane, data[n], 1, data[n], 1);
    }
    break;
  }

  default:
    fprintf (stderr, "sem2tec: unknown format flag: '%c'\n", *c);
    exit    (EXIT_FAILURE);
    break;
  }
}
Пример #2
0
/*
 * The purpose here is to provide useful clues about a kernel crash, so
 * less likely instructions, e.g. floating point, aren't fully decoded.
 */
static void
disassemble(unsigned int instr)
{
	int optype = instr >> 26;
	char buf[40], *s = buf;

	s += sprintf(buf, "%08x  %s ", instr, iname(instr));
	switch (iformat(optype)) {
		default:
		case NOT_INST:
		case MISC:
			break;

		case PAL:
			s += sprintf(s, "%d", instr);
			break;

		case BRANCH: {
			int reg = (instr >> 21) & 0x1f;
			int offset = instr & 0x1fffff;

			if (offset >= 0x100000)
				offset -= 0x200000;
			if (((optype & 3) == 0) || (optype >= 0x38)) {
				if ((optype != 0x30) || (reg != 0x1f))
					s += sprintf(s, "%s,", ireg_name[reg]);
			} else
				s += sprintf(s, "f%d,", reg);
			s += sprintf(s, ".%+d", (offset + 1) << 2);
			break;
		}

		case MEMORY: {
			int addr_reg = (instr >> 16) & 0x1f;
			int value_reg = (instr >> 21) & 0x1f;
			int offset = instr & 0xffff;

			if (offset >= 0x8000)
				offset -= 0x10000;
			if ((optype >= 0x20) && (optype < 0x28))
				s += sprintf(s, "f%d", value_reg);
			else
				s += sprintf(s, "%s", ireg_name[value_reg]);

			s += sprintf(s, ",%d(%s)", offset, ireg_name[addr_reg]);
			break;
		}

		case JUMP: {
			int target_reg = (instr >> 16) & 0x1f;
			int return_reg = (instr >> 21) & 0x1f;

			s += sprintf(s, "%s,", ireg_name[return_reg]);
			s += sprintf(s, "(%s)", ireg_name[target_reg]);
			break;
		}

		case OPERATE: {
			int areg = (instr >> 21) & 0x1f;
			int breg = (instr >> 16) & 0x1f;
			int creg = instr & 0x1f;
			int litflag = instr & (1<<12);
			int lit = (instr >> 13) & 0xff;

			s += sprintf(s, "%s,", ireg_name[areg]);
			if (litflag)
				s += sprintf(s, "%d", lit);
			else
				s += sprintf(s, "%s", ireg_name[breg]);
			s += sprintf(s, ",%s", ireg_name[creg]);
			break;
		}

		case FOPERATE: {
			int areg = (instr >> 21) & 0x1f;
			int breg = (instr >> 16) & 0x1f;
			int creg = instr & 0x1f;

			s += sprintf(s, "f%d,f%d,f%d", areg, breg, creg);
			break;
		}
	}
	buf[s-buf] = 0;
	printk("%s\n", buf);
}