Exemple #1
0
char *sym_find(int addr)
{
    static char buf[256];
    Sym  *s;
    int   offset;

    addr&=ADDRMASK;

    // find
    s=sym+findsym(addr);
    offset=addr-s->addr;

    if(offset<0 || offset>99999)
    {
        int a;
        a=mem_read32(addr);
        if(OP_OP(a)==19)
        {
            sprintf(buf,"?<patch:%i>",OP_IMM(a));
            return(buf);
        }
        else return("?");
    }

    if(offset==0) strcpy(buf,s->text);
    else sprintf(buf,"?%i+%s",offset,s->text);
    return(buf);
}
Exemple #2
0
char *copreg(dword x,int reg)
{
    int cop=OP_OP(x)&3;
    static char buf[32];
    if(reg>=32)
    {
        sprintf(buf,"Ctrl%02i",reg-32);
        return(buf);
    }
    if(rsp)
    {
        if(cop==0)
        {
            sprintf(buf,"DMA%02i",reg);
            return(buf);
        }
        else if(cop==2)
        {
            sprintf(buf,"vec%02i",reg);
            return(buf);
        }
        else
        {
            sprintf(buf,"GR%02i",reg);
            return(buf);
        }
    }
    else
    {
        if(cop==0)
        {
            return(mmuregnames[reg]);
        }
        else if(cop==1)
        {
            sprintf(buf,"FP%02i",reg);
            return(buf);
        }
        else
        {
            sprintf(buf,"GR%02i",reg);
            return(buf);
        }
    }
}
Exemple #3
0
void routinecrc2(dword addr,int barrier,dword *xcrc1,dword *xcrc2)
{
    dword crc,crc1=0,crc2=0;
    dword x1,x2;
    int i,in,errorsaid=0;
    int dump=0;

//    if(addr>=0x002004b0 && addr<=0x002004ff) dump=1;

    if(!barrier) crc1=*xcrc1;

    in=16;

    x1=mem_read32(addr);
    if(!(x1&0xffffff))
    {
        *xcrc1=-1;
        *xcrc2=-1;
        return;
    }

    for(i=0; i<in; i++)
    {
        x1=mem_read32(addr+i*4);
        if(x1==0x03e00008)
        {   // JR ret
            in=i+2;
            if(in>16) in=16;
        }
    }

    for(i=0; i<in; i++)
    {
        x1=mem_read32(addr+i*4);
        crc=i;
        if(OP_OP(x1)==3 || OP_OP(x1)==2)
        {   // JAL or J
            crc+=OP_OP(x1);
        }
        else if(OP_OP(x1)==15)
        {   // LUI
            if(OP_IMM(x1)>=0xa400 && OP_IMM(x1)<=0xafff) crc2+=x1; // must be right
            else crc+=OP_OP(x1);
        }
        else if(OP_OP(x1)==16)
        {   // COP0
            crc2^=x1; // these must be totally correct
            crc=0;
        }
        else if(OP_OP(x1)==17)
        {   // COP1
            crc2^=x1; // these must be totally correct
            crc=0;
        }
        else
        {   // default instr, just check upper 16 bits
            if(barrier)
            {   // generating
                x2=mem_read32(addr+i*4+barrier);
                if(OP_OP(x1)>=4 && OP_OP(x1)<=15)
                {   // immediates
                    crc1|=(1<<i);
                    crc^=x1>>16;
                }
                else if(x1!=x2)
                {
                    if((x1^x2)>>16)
                    {
                        if(!errorsaid)
                        {
                            //print("32-bit routine difference at %08X\n",addr+i*4);
                            errorsaid=1;
                            crc1|=-1;
                        }
                    }
                    crc1|=(1<<i);
                    crc^=x1>>16;
                }
                else
                {
                    crc^=x1;
                }
            }
Exemple #4
0
int tuple_process(tuple_t tuple, unsigned char *pc,
		  int isNew, Register *reg)
{
  for (; ; pc = advance(pc)) {
  eval_loop: /* for jump instructions */
    switch (0xf0 & *(const unsigned char*)pc) {

    case 0x00: // some '8-bit' instruction
      switch (0x0f & *(const unsigned char*)pc) {

      case 0x00: // RETURN
#ifdef DEBUG_INSTRS
	printf("RETURN\n");
#endif
	return RET_RET;
	break;

      case 0x01: // NEXT
#ifdef DEBUG_INSTRS
	printf("NEXT\n");
#endif
	return RET_NEXT;
	break;

      case 0x02: // ELSE
	fprintf(stderr, "ELSE NOT IMPLEMENTED YET!\n");
	assert(0);
	break;

      case 0x08: // SEND
      case 0x09: // SEND
      case 0x0a: // SEND
      case 0x0b: // SEND
	{
	const unsigned char *old_pc = pc+3;
	Register send_reg = reg[SEND_MSG(pc)];
	Register send_rt = reg[SEND_RT(pc)];

#ifdef DEBUG_INSTRS
	printf("SEND\n");
#endif

	tuple_send((tuple_t)MELD_CONVERT_REG_TO_PTR(send_reg),
		   MELD_CONVERT_REG_TO_PTR(send_rt),
		   MELD_INT(eval(SEND_DELAY(pc), &tuple, &old_pc, reg)), isNew);
	break;
	}

      default:
	fprintf(stderr, "INVALID INSTRUCTION %u", *pc);
	assert(0);
	break;
      }
      break;

    case 0x20: // CALL
      {
      Register *dst = &reg[CALL_DST(pc)];
      Register args[CALL_ARGS(pc)];

      assert(CALL_ARGS(pc) <= 5);

#ifdef DEBUG_INSTRS
      printf("CALL %d (%d)\n", CALL_ID(pc), CALL_ARGS(pc));
#endif
        
      int i;
      const unsigned char *old_pc = pc+2;
      for (i = 0; i < CALL_ARGS(pc); i++) {
	unsigned char value = CALL_VAL(old_pc);
	old_pc++;
	args[i] = MELD_CONVERT_PTR_TO_REG(eval(value, &tuple, &old_pc, reg));
      }

      switch (CALL_ARGS(pc)) {
      default:
	break;
      case 0:
	*dst = CALL_FUNC(pc)();
	break;
      case 1:
	*dst = CALL_FUNC(pc)(args[0]);
	break;
      case 2:
	*dst = CALL_FUNC(pc)(args[0], args[1]);
	break;
      case 3:
	*dst = CALL_FUNC(pc)(args[0], args[1], args[2]);
	break;
      case 4:
	*dst = CALL_FUNC(pc)(args[0], args[1], args[2], args[3]);
	break;
      case 5:
	*dst = CALL_FUNC(pc)(args[0], args[1], args[2], args[3], args[4]);
	break;
      }
      break;
      }

    case 0x30: // MOVE
      {
      const unsigned char *old_pc = pc+2;

#ifdef DEBUG_INSTRS
      {
	char src = MOVE_SRC(pc);
	char dst = MOVE_DST(pc);

        printf("MOVE ");
        if(VAL_IS_TUPLE(src))
          printf("tuple");
        else if(VAL_IS_REG(src))
          printf("reg %d", VAL_REG(src));
        else if(VAL_IS_HOST(src))
          printf("host");
        else if(VAL_IS_FIELD(src))
          printf("FIELD");
        else if(VAL_IS_INT(src))
          printf("INT");
        else if(VAL_IS_FLOAT(src))
          printf("float");
	else if(VAL_IS_REVERSE(src))
	  printf("reverse");
        else printf("??");

        printf(" ");

        if(VAL_IS_TUPLE(dst))
          printf("tuple");
        else if(VAL_IS_REG(dst))
          printf("reg %d", VAL_REG(dst));
        else if(VAL_IS_HOST(dst))
          printf("host");
        else if(VAL_IS_FIELD(dst))
          printf("FIELD");
        else if(VAL_IS_INT(dst))
          printf("INT");
        else if(VAL_IS_FLOAT(dst))
          printf("float");
	else if(VAL_IS_REVERSE(dst))
	  printf("reverse");
        else printf("??");

	printf("\n");
      }
#endif
      size_t size = 0;

      Register *src = eval(MOVE_SRC(pc), &tuple, &old_pc, reg);
      Register *dst = eval_dst(MOVE_DST(pc), &old_pc, reg, &size);

      memcpy(dst, src, size);
      break;
      }

    case 0x40: // ALLOC
    case 0x50: // ALLOC
      {
      const unsigned char *old_pc = pc+2;
      tuple_t *dst;
      
#if defined(DEBUG_INSTRS) || defined(DEBUG_ALLOCS)
      {
        tuple_type type = ALLOC_TYPE(pc);
        printf("ALLOC %s\n", tuple_names[type]);
      }
#endif

      dst = eval(ALLOC_DST(pc), &tuple, &old_pc, reg);
			
      *dst = ALLOC_TUPLE(TYPE_SIZE(ALLOC_TYPE(pc)));
      memset(*dst, 0, TYPE_SIZE(ALLOC_TYPE(pc)));
      TUPLE_TYPE(*dst) = ALLOC_TYPE(pc);
      break;
      }

    case 0x60: // IF
    case 0x70: // IF
#ifdef DEBUG_INSTRS
      printf("IF reg %d ", IF_REG(pc));
#endif
      if (!reg[IF_REG(pc)]) {
#ifdef DEBUG_INSTRS
	printf("no\n");
#endif
	pc += IF_JUMP(pc);
	goto eval_loop;
      }

#ifdef DEBUG_INSTRS
      printf("yes\n");
#endif
      break;

    case 0x80: // REMOVE
    case 0x90: // REMOVE
      if (isNew > 0) {
        int reg_remove = REMOVE_REG(pc);
	int size = TYPE_SIZE(TUPLE_TYPE(MELD_CONVERT_REG_TO_PTR(reg[reg_remove])));

	tuple_handle(memcpy(malloc(size),MELD_CONVERT_REG_TO_PTR(reg[reg_remove]), size), -1, reg);
	reg[REMOVE_REG(pc)] = 0;
      }	
      break;

    case 0xa0: // ITER
      {
      const tuple_type type = ITER_TYPE(pc);
      int i, length;
      void **list;
      unsigned char *jump = pc + ITER_JUMP(pc);
      int size = TYPE_SIZE(type);
			
      /* produce a random ordering for all tuples of the appropriate type */
			
      if(TYPE_IS_PERSISTENT(type) && !TYPE_IS_AGG(type)) {
	/* persistent aggregate types not supported */
        persistent_set *persistents = &PERSISTENT[type];
        
        length = persistents->current;
        list = malloc(sizeof(tuple_t) * length);

        for(i = 0; i < length; i++) {
          int j = random() % (i + 1);
          
          list[i] = list[j];
          list[j] = persistents->array + i * size;
        }
      } else {
	/* non-persistent type */
	tuple_entry *entry = TUPLES[type].head;
		    
	length = queue_length(&TUPLES[ITER_TYPE(pc)]);
	list = malloc(sizeof(tuple_t) * length);
		    
	for (i = 0; i < length; i++) {
	  int j = random() % (i+1);

	  list[i] = list[j];
	  list[j] = entry->tuple;

	  entry = entry->next;
	}
      }
			
#ifdef DEBUG_INSTRS
      printf("ITER %s len=%d\n", tuple_names[type], length);
#endif

      if(length == 0) {
        /* no need to execute any further code, just jump! */
        pc = jump;
	goto eval_loop;
      }

      /* iterate over all tuples of the appropriate type */
      void *next_tuple;
      
      for (i = 0; i < length; i++) {
	next_tuple = list[i];

	unsigned char matched = 1;
	const unsigned char *tmppc;

        tmppc = pc + ITER_BASE;

        if(!ITER_MATCH_NONE(tmppc)) {
	  /* check to see if it matches */
          while (1) {
            const unsigned char *old_pc = tmppc + 2;
	    const unsigned char fieldnum = ITER_MATCH_FIELD(tmppc);
	    const unsigned char type_size = TYPE_ARG_SIZE(type, fieldnum);

            Register *field = GET_TUPLE_FIELD(next_tuple, fieldnum);
            Register *val = eval(ITER_MATCH_VAL(tmppc), &tuple, &old_pc, reg);
            
            matched = matched && (memcmp(field, val, type_size) == 0);

            if(ITER_MATCH_END(tmppc))
              break;

            tmppc = old_pc;
          }
	}

#ifdef DEBUG_INSTRS
	printf("MATCHED: %d %d\n", matched, length);
#endif
          
	if (matched) {
	  if (RET_RET == tuple_process(next_tuple, advance(pc), isNew, reg)) {
	    free(list);
	    return RET_RET;
	  }
	}
      }

      free(list);

      /* advance the pc to the end of the loop */
      pc = jump;
      goto eval_loop;
      break;
      }

    case 0xc0: // OP
    case 0xd0: // OP
    case 0xe0: // OP
    case 0xf0: // OP
      {
      const unsigned char *old_pc = pc+3;
			
#ifdef DEBUG_INSTRS
      printf("OP to %d\n", OP_DST(pc));
#endif

      Register *arg1, *arg2;
      
      arg1 = eval(OP_ARG1(pc), &tuple, &old_pc, reg);
      arg2 = eval(OP_ARG2(pc), &tuple, &old_pc, reg);
      
#ifdef DEBUG_INSTRS
      printf ("%ld", MELD_INT(arg1));
      printf ("OP");
      printf ("%ld", MELD_INT(arg2));
      printf ("\n");
#endif

      Register *dest = reg + OP_DST(pc);
      
      switch(OP_OP(pc)) {
      case OP_NEQI: *dest = (MELD_INT(arg1) != MELD_INT(arg2)); break;
      case OP_EQI: *dest = (MELD_INT(arg1) == MELD_INT(arg2)); break;
      case OP_LESSI: *dest = (MELD_INT(arg1) < MELD_INT(arg2)); break;
      case OP_LESSEQI: *dest = (MELD_INT(arg1) <= MELD_INT(arg2)); break;
      case OP_GREATERI: *dest = (MELD_INT(arg1) > MELD_INT(arg2)); break;
      case OP_GREATEREQI: *dest = (MELD_INT(arg1) >= MELD_INT(arg2)); break;
      case OP_MODI: MELD_INT(dest) = (MELD_INT(arg1) % MELD_INT(arg2)); break;
      case OP_PLUSI: MELD_INT(dest) = (MELD_INT(arg1) + MELD_INT(arg2)); break;
      case OP_MINUSI: MELD_INT(dest) = (MELD_INT(arg1) - MELD_INT(arg2)); break;
      case OP_TIMESI: MELD_INT(dest) = (MELD_INT(arg1) * MELD_INT(arg2)); break;
      case OP_DIVI: MELD_INT(dest) = (MELD_INT(arg1) / MELD_INT(arg2)); break;
      case OP_NEQF: *dest = (MELD_FLOAT(arg1) != MELD_FLOAT(arg2)); break;
      case OP_EQF: *dest = (MELD_FLOAT(arg1) == MELD_FLOAT(arg2)); break;
      case OP_LESSF: *dest = (MELD_FLOAT(arg1) < MELD_FLOAT(arg2)); break;
      case OP_LESSEQF: *dest = (MELD_FLOAT(arg1) <= MELD_FLOAT(arg2)); break;
      case OP_GREATERF: *dest = (MELD_FLOAT(arg1) > MELD_FLOAT(arg2)); break;
      case OP_GREATEREQF: *dest = (MELD_FLOAT(arg1) >= MELD_FLOAT(arg2)); break;
      case OP_MODF: MELD_FLOAT(dest) = fmod(MELD_FLOAT(arg1), MELD_FLOAT(arg2)); break;
      case OP_PLUSF: MELD_FLOAT(dest) = (MELD_FLOAT(arg1) + MELD_FLOAT(arg2)); break;
      case OP_MINUSF: MELD_FLOAT(dest) = (MELD_FLOAT(arg1) - MELD_FLOAT(arg2)); break;
      case OP_TIMESF: MELD_FLOAT(dest) = (MELD_FLOAT(arg1) * MELD_FLOAT(arg2)); break;
      case OP_DIVF: MELD_FLOAT(dest) = (MELD_FLOAT(arg1) / MELD_FLOAT(arg2)); break;
      case OP_NEQA: *dest = (MELD_PTR(arg1) != MELD_PTR(arg2)); break;
      case OP_EQA: *dest = (MELD_PTR(arg1) == MELD_PTR(arg2)); break;
      }
      break;
      }

    default:
      fprintf(stderr, "INVALID INSTRUCTION %u", *pc);
      assert(0);
      break;
    }
  }

  return RET_RET;
}