Exemplo n.º 1
0
int
do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
    const char *file, void *lml)
#endif
{
#ifdef DO_RELOC_LIBLD
#define	sym (* rel_desc_sname_func)(rdesc)
	uchar_t	rtype = rdesc->rel_rtype;
#endif
	Xword	uvalue = 0;
	Xword	basevalue, sigbit_mask, sigfit_mask;
	Xword	corevalue = *value;
	uchar_t	bshift;
	int	field_size, re_flags;
	const	Rel_entry	*rep;

	rep = &reloc_table[rtype];
	bshift = rep->re_bshift;
	field_size = rep->re_fsize;
	re_flags = rep->re_flags;
	sigbit_mask = S_MASK(rep->re_sigbits);

	if ((re_flags & FLG_RE_SIGN) && sigbit_mask) {
		/*
		 * sigfit_mask takes into account that a value
		 * might be signed and discards the signbit for
		 * comparison.
		 */
		sigfit_mask = S_MASK(rep->re_sigbits - 1);
	} else
		sigfit_mask = sigbit_mask;

	if (field_size == 0) {
		REL_ERR_UNIMPL(lml, file, sym, rtype);
		return (0);
	}

	/*
	 * We have two ways to retrieve the base value, a general one
	 * that will work with data of any alignment, and another that is
	 * fast, but which requires the data to be aligned according to
	 * sparc alignment rules.
	 *
	 * For non-native linking, we always use the general path. For
	 * native linking, the FLG_RE_UNALIGN determines it.
	 */
#if defined(DORELOC_NATIVE)
	if (re_flags & FLG_RE_UNALIGN)
#endif
	{
		int	i;
		uchar_t	*dest = (uchar_t *)&basevalue;

		basevalue = 0;
#if !defined(DORELOC_NATIVE)
		if (bswap) {
			int j = field_size - 1;

			for (i = 0; i < field_size; i++, j--)
				dest[i] = off[j];

		} else
#endif
		{
			/*
			 * Adjust the offset
			 */
			/* LINTED */
			i = (int)(sizeof (Xword) - field_size);
			if (i > 0)
				dest += i;
			for (i = field_size - 1; i >= 0; i--)
				dest[i] = off[i];
		}
	}

	/*
	 * Non-native linker: We have already fetched the value above,
	 *	but if the relocation does not have the FLG_RE_UNALIGN
	 *	flag set, we still need to do the same error checking we
	 *	would do on a native linker.
	 * Native-linker: If this is an aligned relocation, we need to
	 *	fetch the value and also do the error checking.
	 *
	 * The FETCH macro is used to conditionalize the fetching so that
	 * it only happens in the native case.
	 */
#if defined(DORELOC_NATIVE)
#define	FETCH(_type) basevalue = (Xword)*((_type *)off);
#else
#define	FETCH(_type)
#endif
	if ((re_flags & FLG_RE_UNALIGN) == 0) {
		if (((field_size == 2) && ((uintptr_t)off & 0x1)) ||
		    ((field_size == 4) && ((uintptr_t)off & 0x3)) ||
		    ((field_size == 8) && ((uintptr_t)off & 0x7))) {
			REL_ERR_NONALIGN(lml, file, sym, rtype, (uintptr_t)off);
			return (0);
		}
		switch (field_size) {
		case 1:
			/* LINTED */
			FETCH(uchar_t);
			break;
		case 2:
			/* LINTED */
			FETCH(Half);
			break;
		case 4:
			/* LINTED */
			FETCH(Word);
			break;
		case 8:
			/* LINTED */
			FETCH(Xword);
			break;
		default:
			REL_ERR_UNNOBITS(lml, file, sym, rtype,
			    (rep->re_fsize * 8));
			return (0);
		}
	}
#undef FETCH

	if (sigbit_mask) {
		/*
		 * The WDISP16 relocation is an unusual one in that it's bits
		 * are not all contiguous.  We have to selectivly pull them out.
		 */
		if (re_flags & FLG_RE_WDISP16) {
			uvalue = ((basevalue & 0x300000) >> 6) |
			    (basevalue & 0x3fff);
			basevalue &= ~0x303fff;
		} else {
Exemplo n.º 2
0
UINT16 nec_common_device::fetchword()
{
	UINT16 r = FETCH();
	r |= (FETCH()<<8);
	return r;
}
Exemplo n.º 3
0
static struct cookie *
parse_set_cookies (const char *sc)
{
  struct cookie *cookie = cookie_new ();

  enum { S_NAME_PRE, S_NAME, S_NAME_POST,
	 S_VALUE_PRE, S_VALUE, S_VALUE_TRAILSPACE_MAYBE,
	 S_QUOTED_VALUE, S_QUOTED_VALUE_POST,
	 S_ATTR_ACTION,
	 S_DONE, S_ERROR } state = S_NAME_PRE;

  const char *p = sc;
  char c;

  const char *name_b  = NULL, *name_e  = NULL;
  const char *value_b = NULL, *value_e = NULL;

  FETCH (c, p);

  while (state != S_DONE && state != S_ERROR)
    {
      switch (state)
	{
	case S_NAME_PRE:
	  if (ISSPACE (c))
	    FETCH (c, p);
	  else if (ATTR_NAME_CHAR (c))
	    {
	      name_b = p - 1;
	      FETCH1 (c, p);
	      state = S_NAME;
	    }
	  else
	    /* empty attr name not allowed */
	    state = S_ERROR;
	  break;
	case S_NAME:
	  if (ATTR_NAME_CHAR (c))
	    FETCH1 (c, p);
	  else if (!c || c == ';' || c == '=' || ISSPACE (c))
	    {
	      name_e = p - 1;
	      state = S_NAME_POST;
	    }
	  else
	    state = S_ERROR;
	  break;
	case S_NAME_POST:
	  if (ISSPACE (c))
	    FETCH1 (c, p);
	  else if (!c || c == ';')
	    {
	      value_b = value_e = NULL;
	      state = S_ATTR_ACTION;
	    }
	  else if (c == '=')
	    {
	      FETCH1 (c, p);
	      state = S_VALUE_PRE;
	    }
	  else
	    state = S_ERROR;
	  break;
	case S_VALUE_PRE:
	  if (ISSPACE (c))
	    FETCH1 (c, p);
	  else if (c == '"')
	    {
	      value_b = p;
	      FETCH (c, p);
	      state = S_QUOTED_VALUE;
	    }
	  else if (c == ';' || c == '\0')
	    {
	      value_b = value_e = p - 1;
	      state = S_ATTR_ACTION;
	    }
	  else
	    {
	      value_b = p - 1;
	      value_e = NULL;
	      state = S_VALUE;
	    }
	  break;
	case S_VALUE:
	  if (c == ';' || c == '\0')
	    {
	      if (!value_e)
		value_e = p - 1;
	      state = S_ATTR_ACTION;
	    }
	  else if (ISSPACE (c))
	    {
	      value_e = p - 1;
	      FETCH1 (c, p);
	      state = S_VALUE_TRAILSPACE_MAYBE;
	    }
	  else
	    {
	      value_e = NULL;	/* no trailing space */
	      FETCH1 (c, p);
	    }
	  break;
	case S_VALUE_TRAILSPACE_MAYBE:
	  if (ISSPACE (c))
	    FETCH1 (c, p);
	  else
	    state = S_VALUE;
	  break;
	case S_QUOTED_VALUE:
	  if (c == '"')
	    {
	      value_e = p - 1;
	      FETCH1 (c, p);
	      state = S_QUOTED_VALUE_POST;
	    }
	  else
	    FETCH (c, p);
	  break;
	case S_QUOTED_VALUE_POST:
	  if (c == ';' || !c)
	    state = S_ATTR_ACTION;
	  else if (ISSPACE (c))
	    FETCH1 (c, p);
	  else
	    state = S_ERROR;
	  break;
	case S_ATTR_ACTION:
	  {
	    int legal = update_cookie_field (cookie, name_b, name_e,
					     value_b, value_e);
	    if (!legal)
	      {
		char *name;
		BOUNDED_TO_ALLOCA (name_b, name_e, name);
		logprintf (LOG_NOTQUIET,
			   _("Error in Set-Cookie, field `%s'"), name);
		state = S_ERROR;
		break;
	      }

	    if (c)
	      FETCH1 (c, p);
	    if (!c)
	      state = S_DONE;
	    else
	      state = S_NAME_PRE;
	  }
	  break;
	case S_DONE:
	case S_ERROR:
	  /* handled by loop condition */
	  break;
	}
    }
  if (state == S_DONE)
    return cookie;

  delete_cookie (cookie);
  if (state == S_ERROR)
    logprintf (LOG_NOTQUIET, _("Syntax error in Set-Cookie at character `%c'.\n"), c);
  else
    abort ();
  return NULL;

 eof:
  delete_cookie (cookie);
  logprintf (LOG_NOTQUIET,
	     _("Syntax error in Set-Cookie: premature end of string.\n"));
  return NULL;
}
Exemplo n.º 4
0
HANDLE_OPCODE($opcode /*vAAAA, vBBBB*/)
    vdst = FETCH(1);
    vsrc1 = FETCH(2);
    ILOGV("|move%s/16 v%d,v%d %s(v%d=0x%08x)",
        (INST_INST(inst) == OP_MOVE_16) ? "" : "-object", vdst, vsrc1,
        kSpacing, vdst, GET_REGISTER(vsrc1));
    SET_REGISTER(vdst, GET_REGISTER(vsrc1));
#if defined(LOCCS_DIAOS)
#if INST_INST(inst) != OP_MOVE_16
    //ALOG(LOG_VERBOSE,"YWB","need to verify object");
    diaos_monitor_object(curMethod, (Object*)GET_REGISTER(vdst));
#endif
#endif
    FINISH(3);
OP_END
Exemplo n.º 5
0
static void I386OP(fpu_group_d8)(void)		/* Opcode 0xd8 */
{
	UINT8 modrm = FETCH();
	osd_die("I386: FPU Op D8 %02X at %08X\n", modrm, I.pc-2);
}
Exemplo n.º 6
0
GOTO_TARGET(filledNewArray, bool methodCallRange, bool)
    {
        ClassObject* arrayClass;
        ArrayObject* newArray;
        u4* contents;
        char typeCh;
        int i;
        u4 arg5;

        EXPORT_PC();

        ref = FETCH(1);             /* class ref */
        vdst = FETCH(2);            /* first 4 regs -or- range base */

        if (methodCallRange) {
            vsrc1 = INST_AA(inst);  /* #of elements */
            arg5 = -1;              /* silence compiler warning */
            ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
                vsrc1, ref, vdst, vdst+vsrc1-1);
        } else {
            arg5 = INST_A(inst);
            vsrc1 = INST_B(inst);   /* #of elements */
            ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
               vsrc1, ref, vdst, arg5);
        }

        /*
         * Resolve the array class.
         */
        arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
        if (arrayClass == NULL) {
            arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
            if (arrayClass == NULL)
                GOTO_exceptionThrown();
        }
        /*
        if (!dvmIsArrayClass(arrayClass)) {
            dvmThrowRuntimeException(
                "filled-new-array needs array class");
            GOTO_exceptionThrown();
        }
        */
        /* verifier guarantees this is an array class */
        assert(dvmIsArrayClass(arrayClass));
        assert(dvmIsClassInitialized(arrayClass));

        /*
         * Create an array of the specified type.
         */
        LOGVV("+++ filled-new-array type is '%s'", arrayClass->descriptor);
        typeCh = arrayClass->descriptor[1];
        if (typeCh == 'D' || typeCh == 'J') {
            /* category 2 primitives not allowed */
            dvmThrowRuntimeException("bad filled array req");
            GOTO_exceptionThrown();
        } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
            /* TODO: requires multiple "fill in" loops with different widths */
            ALOGE("non-int primitives not implemented");
            dvmThrowInternalError(
                "filled-new-array not implemented for anything but 'int'");
            GOTO_exceptionThrown();
        }

        newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
        if (newArray == NULL)
            GOTO_exceptionThrown();

        /*
         * Fill in the elements.  It's legal for vsrc1 to be zero.
         */
        contents = (u4*)(void*)newArray->contents;
        if (methodCallRange) {
            for (i = 0; i < vsrc1; i++)
                contents[i] = GET_REGISTER(vdst+i);
        } else {
            assert(vsrc1 <= 5);
            if (vsrc1 == 5) {
                contents[4] = GET_REGISTER(arg5);
                vsrc1--;
            }
            for (i = 0; i < vsrc1; i++) {
                contents[i] = GET_REGISTER(vdst & 0x0f);
                vdst >>= 4;
            }
        }
        if (typeCh == 'L' || typeCh == '[') {
            dvmWriteBarrierArray(newArray, 0, newArray->length);
        }

        retval.l = (Object*)newArray;
    }
Exemplo n.º 7
0
static void I486OP(group0F01_32)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT32 address, ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address, 1 );
				} else {
					ea = GetEA(cpustate,modrm,1);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address, 1 );
				}
				else
				{
					ea = GetEA(cpustate,modrm,1);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if(PROTECTED_MODE && cpustate->CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address, 0 );
				} else {
					ea = GetEA(cpustate,modrm,0);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if(PROTECTED_MODE && cpustate->CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address, 0 );
				} else {
					ea = GetEA(cpustate,modrm,0);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 4:			/* SMSW */
			{
				if( modrm >= 0xc0 ) {
					STORE_RM32(modrm, cpustate->cr[0] & 0xffff);
					CYCLES(cpustate,CYCLES_SMSW_REG);
				} else {
					/* always 16-bit memory operand */
					ea = GetEA(cpustate,modrm,1);
					WRITE16(cpustate,ea, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_MEM);
				}
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
Exemplo n.º 8
0
static void I486OP(group0F01_16)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT16 address;
	UINT32 ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				}
				else
				{
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 4:			/* SMSW */
			{
				if( modrm >= 0xc0 ) {
					STORE_RM16(modrm, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm);
					WRITE16(cpustate,ea, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_MEM);
				}
				break;
			}
		case 6:			/* LMSW */
			{
				// TODO: Check for protection fault
				UINT8 b;
				if( modrm >= 0xc0 ) {
					b = LOAD_RM8(modrm);
					CYCLES(cpustate,CYCLES_LMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm);
					CYCLES(cpustate,CYCLES_LMSW_MEM);
				b = READ8(cpustate,ea);
				}
				cpustate->cr[0] &= ~0x03;
				cpustate->cr[0] |= b & 0x03;
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
Exemplo n.º 9
0
GOTO_TARGET_END

GOTO_TARGET(invokeSuper, bool methodCallRange)
{
    Method* baseMethod;
    u2 thisReg;

    EXPORT_PC();

    vsrc1 = INST_AA(inst);      /* AA (count) or BA (count + arg 5) */
    ref = FETCH(1);             /* method ref */
    vdst = FETCH(2);            /* 4 regs -or- first reg */

    if (methodCallRange) {
        ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
              vsrc1, ref, vdst, vdst+vsrc1-1);
        thisReg = vdst;
    } else {
        ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
              vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
        thisReg = vdst & 0x0f;
    }

    /* impossible in well-formed code, but we must check nevertheless */
    if (!checkForNull((Object*) GET_REGISTER(thisReg)))
        GOTO_exceptionThrown();

    /*
     * Resolve the method.  This is the correct method for the static
     * type of the object.  We also verify access permissions here.
     * The first arg to dvmResolveMethod() is just the referring class
     * (used for class loaders and such), so we don't want to pass
     * the superclass into the resolution call.
     */
    baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
    if (baseMethod == NULL) {
        baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
        if (baseMethod == NULL) {
            ILOGV("+ unknown method or access denied");
            GOTO_exceptionThrown();
        }
    }

    /*
     * Combine the object we found with the vtable offset in the
     * method's class.
     *
     * We're using the current method's class' superclass, not the
     * superclass of "this".  This is because we might be executing
     * in a method inherited from a superclass, and we want to run
     * in that class' superclass.
     */
    if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
        /*
         * Method does not exist in the superclass.  Could happen if
         * superclass gets updated.
         */
        dvmThrowNoSuchMethodError(baseMethod->name);
        GOTO_exceptionThrown();
    }
    methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];

#if 0
    if (dvmIsAbstractMethod(methodToCall)) {
        dvmThrowAbstractMethodError("abstract method not implemented");
        GOTO_exceptionThrown();
    }
#else
    assert(!dvmIsAbstractMethod(methodToCall) ||
           methodToCall->nativeFunc != NULL);
#endif
    LOGVV("+++ base=%s.%s super-virtual=%s.%s",
          baseMethod->clazz->descriptor, baseMethod->name,
          methodToCall->clazz->descriptor, methodToCall->name);
    assert(methodToCall != NULL);

    GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
}
Exemplo n.º 10
0
void i386_device::i486_group0F01_16()      // Opcode 0x0f 01
{
	UINT8 modrm = FETCH();
	UINT16 address;
	UINT32 ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:         /* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( CS, address, 1 );
				} else {
					ea = GetEA(modrm,1);
				}
				WRITE16(ea, m_gdtr.limit);
				WRITE32(ea + 2, m_gdtr.base & 0xffffff);
				CYCLES(CYCLES_SGDT);
				break;
			}
		case 1:         /* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM16(modrm);
					ea = i386_translate( CS, address, 1 );
				}
				else
				{
					ea = GetEA(modrm,1);
				}
				WRITE16(ea, m_idtr.limit);
				WRITE32(ea + 2, m_idtr.base & 0xffffff);
				CYCLES(CYCLES_SIDT);
				break;
			}
		case 2:         /* LGDT */
			{
				if(PROTECTED_MODE && m_CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( CS, address, 0 );
				} else {
					ea = GetEA(modrm,0);
				}
				m_gdtr.limit = READ16(ea);
				m_gdtr.base = READ32(ea + 2) & 0xffffff;
				CYCLES(CYCLES_LGDT);
				break;
			}
		case 3:         /* LIDT */
			{
				if(PROTECTED_MODE && m_CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( CS, address, 0 );
				} else {
					ea = GetEA(modrm,0);
				}
				m_idtr.limit = READ16(ea);
				m_idtr.base = READ32(ea + 2) & 0xffffff;
				CYCLES(CYCLES_LIDT);
				break;
			}
		case 4:         /* SMSW */
			{
				if( modrm >= 0xc0 ) {
					STORE_RM16(modrm, m_cr[0]);
					CYCLES(CYCLES_SMSW_REG);
				} else {
					ea = GetEA(modrm,1);
					WRITE16(ea, m_cr[0]);
					CYCLES(CYCLES_SMSW_MEM);
				}
				break;
			}
		case 6:         /* LMSW */
			{
				UINT16 b;
				if(PROTECTED_MODE && m_CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					b = LOAD_RM16(modrm);
					CYCLES(CYCLES_LMSW_REG);
				} else {
					ea = GetEA(modrm,0);
					CYCLES(CYCLES_LMSW_MEM);
					b = READ16(ea);
				}
				if(PROTECTED_MODE)
					b |= 0x0001;  // cannot return to real mode using this instruction.
				m_cr[0] &= ~0x0000000f;
				m_cr[0] |= b & 0x0000000f;
				break;
			}
		case 7:         /* INVLPG */
			{
				if(PROTECTED_MODE && m_CPL)
					FAULT(FAULT_GP,0)
				if(modrm >= 0xc0)
				{
					logerror("i486: invlpg with modrm %02X\n", modrm);
					FAULT(FAULT_UD,0)
				}
				ea = GetEA(modrm,-1);
				CYCLES(25); // TODO: add to cycles.h
				vtlb_flush_address(m_vtlb, ea);
				break;
			}
		default:
			report_invalid_modrm("group0F01_16", modrm);
			break;
	}
Exemplo n.º 11
0
static void I486OP(group0F01_16)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT16 address;
	UINT32 ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address, 1 );
				} else {
					ea = GetEA(cpustate,modrm,1);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address, 1 );
				}
				else
				{
					ea = GetEA(cpustate,modrm,1);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if(PROTECTED_MODE && cpustate->CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address, 0 );
				} else {
					ea = GetEA(cpustate,modrm,0);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if(PROTECTED_MODE && cpustate->CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address, 0 );
				} else {
					ea = GetEA(cpustate,modrm,0);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 4:			/* SMSW */
			{
				if( modrm >= 0xc0 ) {
					STORE_RM16(modrm, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm,1);
					WRITE16(cpustate,ea, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_MEM);
				}
				break;
			}
		case 6:			/* LMSW */
			{
				UINT16 b;
				if(PROTECTED_MODE && cpustate->CPL)
					FAULT(FAULT_GP,0)
				if( modrm >= 0xc0 ) {
					b = LOAD_RM16(modrm);
					CYCLES(cpustate,CYCLES_LMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm,0);
					CYCLES(cpustate,CYCLES_LMSW_MEM);
					b = READ16(cpustate,ea);
				}
				if(PROTECTED_MODE)
					b |= 0x0001;  // cannot return to real mode using this instruction.
				cpustate->cr[0] &= ~0x0000000f;
				cpustate->cr[0] |= b & 0x0000000f;
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
Exemplo n.º 12
0
/**
 * Main interpreter loop
 *
 *------- Computed Goto Definitions (Labels as Values) -------
 * Popular interpreters such as Python and Ruby utilize this
 * GCC extension for up to 20% performance improvement.
 * The advantage of using of an explicit jump table and explicit
 * indirect jump instruction after each opcode's execution is
 * described in the Python 3.3 source (ceval.c).
 * Eli Bendersky also has a good explanation and demo available
 * at http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables
 * NOTE (directly from Python 3.3):
 * "care must be taken that the compiler doesn't try to 'optimize' the
 * indirect jumps by sharing them between all opcodes. Such optimizations
 * can be disabled on gcc by using the -fno-gcse flag (or possibly
 * -fno-crossjumping)."
 *
 * @param frame top-level function to being interpreting
 */
void eval(LuciObject *frame)
{

/* If GNU extensions are available... defined by GCC/Clang */
#ifdef __GNUC__

#include "dispatch.h"  /* include static jump table */

/** initial dispatch */
#define INTERP_INIT()   DISPATCH
/** no op */
#define SWITCH
/** no op */
#define DEFAULT
/** label (as value) */
#define HANDLE(op)      do_##op: { GC_COLLECT(); a = GETARG; }
/** computed goto */
#define DISPATCH        goto *dispatch_table[GETOPCODE]

#else /* __GNUC__ */

/** no op */
#define INTERP_INIT()
/** switch statement */
#define SWITCH          switch(GETOPCODE)
/** default case */
#define DEFAULT         default: goto done_eval;
/** case statement for opcode */
#define HANDLE(op)      case (op): { GC_COLLECT(); a = GETARG; }
/** break statement */
#define DISPATCH        break

#endif /* __GNUC__ */
/**************************************************************/

/** increment instruction pointer */
#define FETCH(c)        (ip += (c))
/** dereference instruction pointer */
#define READ            (*ip)
/** get opcode from instruction */
#define GETOPCODE       OPCODE(READ)
/** get argument from instruction */
#define GETARG          OPARG(READ)

    LuciObject *stack = LuciList_new();

    gc_track_root(&stack);
    gc_track_root(&frame);

    LuciObject* lfargs[MAX_LIBFUNC_ARGS];
    register LuciObject *x = LuciNilObj;
    register LuciObject *y = LuciNilObj;
    register LuciObject *z = LuciNilObj;
    int a;
    int i = 0;
    Instruction *ip = AS_FUNCTION(frame)->instructions;

    for (i = 0; i < MAX_LIBFUNC_ARGS; i++) {
        lfargs[i] = LuciNilObj;
    }
    i = 0;

    INTERP_INIT();

    /* Begin interpreting instructions */
#define EVER ;; /* saw this on stackoverflow. so dumb */
    for(EVER) {
        SWITCH {

        HANDLE(NOP) {
            LUCI_DEBUG("%s\n", "NOP");
        }
        FETCH(1);
        DISPATCH;

        HANDLE(ADD) {
            LUCI_DEBUG("%s\n", "ADD");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->add(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(SUB) {
            LUCI_DEBUG("%s\n", "SUB");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->sub(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(MUL) {
            LUCI_DEBUG("%s\n", "MUL");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->mul(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(DIV) {
            LUCI_DEBUG("%s\n", "DIV");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->div(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(MOD) {
            LUCI_DEBUG("%s\n", "MOD");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->mod(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(POW) {
            LUCI_DEBUG("%s\n", "POW");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->pow(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(EQ) {
            LUCI_DEBUG("%s\n", "EQ");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->eq(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(NEQ) {
            LUCI_DEBUG("%s\n", "NEQ");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->neq(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(LT) {
            LUCI_DEBUG("%s\n", "LT");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->lt(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(GT) {
            LUCI_DEBUG("%s\n", "GT");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->gt(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(LTE) {
            LUCI_DEBUG("%s\n", "LTE");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->lte(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(GTE) {
            LUCI_DEBUG("%s\n", "GTE");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->gte(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(LGOR) {
            LUCI_DEBUG("%s\n", "LGOR");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->lgor(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(LGAND) {
            LUCI_DEBUG("%s\n", "LGAND");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->lgand(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(BWXOR) {
            LUCI_DEBUG("%s\n", "BWXOR");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->bwxor(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(BWOR) {
            LUCI_DEBUG("%s\n", "BWOR");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->bwor(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(BWAND) {
            LUCI_DEBUG("%s\n", "BWAND");
            y = LuciList_pop(stack);
            x = LuciList_pop(stack);
            z = x->type->bwand(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(NEG) {
            LUCI_DEBUG("%s\n", "NEG");
            x = LuciList_pop(stack);
            y = x->type->neg(x);
            LuciList_push(stack, y);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(LGNOT) {
            LUCI_DEBUG("%s\n", "LGNOT");
            x = LuciList_pop(stack);
            y = x->type->lgnot(x);
            LuciList_push(stack, y);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(BWNOT) {
            LUCI_DEBUG("%s\n", "BWNOT");
            x = LuciList_pop(stack);
            y = x->type->bwnot(x);
            LuciList_push(stack, y);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(POP)
        {
            LUCI_DEBUG("%s\n", "POP");
            x = LuciList_pop(stack);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(PUSHNIL)
            LUCI_DEBUG("%s\n", "PUSHNIL");
            LuciList_push(stack, LuciNilObj);
        FETCH(1);
        DISPATCH;

        HANDLE(LOADK)
            LUCI_DEBUG("LOADK %d\n", a);
            x = AS_FUNCTION(frame)->constants[a];
            LuciList_push(stack, x);

        FETCH(1);
        DISPATCH;

        HANDLE(LOADS)
            LUCI_DEBUG("LOADS %d\n", a);
            x = AS_FUNCTION(frame)->locals[a];
            LuciList_push(stack, x);
        FETCH(1);
        DISPATCH;

        HANDLE(LOADG)
            LUCI_DEBUG("LOADG %d\n", a);
            x = AS_FUNCTION(frame)->globals[a];
            LuciList_push(stack, x);
        FETCH(1);
        DISPATCH;

        HANDLE(LOADB)
            LUCI_DEBUG("LOADB %d\n", a);
            x = builtins[a];
            LuciList_push(stack, x);
        FETCH(1);
        DISPATCH;

        HANDLE(DUP)
            LUCI_DEBUG("%s\n", "DUP");
            /* duplicate object on top of stack
             * and push it back on */
            x = LuciList_peek(stack);
            y = x->type->copy(x);
            LuciList_push(stack, y);
        FETCH(1);
        DISPATCH;

        HANDLE(STORE)
            LUCI_DEBUG("STORE %d\n", a);
            /* pop object off of stack */
            x = LuciList_pop(stack);
            /* store the new object */
            y = x->type->copy(x);
            AS_FUNCTION(frame)->locals[a] = y;
        FETCH(1);
        DISPATCH;

        HANDLE(CALL)
        {
            LUCI_DEBUG("CALL %d\n", a);
            x = LuciList_pop(stack);    /* function object */

            /* setup user-defined function */
            if (ISTYPE(x, obj_func_t)) {
                /* save instruction pointer */
                AS_FUNCTION(frame)->ip = ip;

                /* save pointer to current frame */
                LuciObject *parent_frame = frame;

                /* activate a copy of the function frame */
                frame = x->type->copy(x);

                /* check that the # of arguments equals the # of parameters */
                if (a < AS_FUNCTION(frame)->nparams) {
                    LUCI_DIE("%s", "Missing arguments to function.\n");
                } else if (a > AS_FUNCTION(frame)->nparams) {
                    LUCI_DIE("%s", "Too many arguments to function.\n");
                }

                /* pop arguments and push COPIES into locals */
                for (i = 0; i < a; i++) {
                    y = LuciList_pop(stack);
                    AS_FUNCTION(frame)->locals[i] = y->type->copy(y);
                }

                /* the stack is clean, now push the previous frame */
                LuciList_push(stack, parent_frame);

                /* reset instruction pointer and carry on our merry way */
                /* NOTE: while ugly, we decrement ip by one instruction
                 * so that the following FETCH call starts at the 1st
                 * instruction!!! */
                ip = AS_FUNCTION(frame)->instructions - 1;
            }

            /* call library function */
            else if (ISTYPE(x, obj_libfunc_t)) {
                if (a >= MAX_LIBFUNC_ARGS) {
                    LUCI_DIE("%s\n", "Too many arguments to function");
                } else if (a < AS_LIBFUNC(x)->min_args) {
                    LUCI_DIE("%s\n", "Missing arguments to function");
                }

                /* pop args and push into args array */
                /* must happen in reverse */
                for (i = a - 1; i >= 0; i--) {
                    y = LuciList_pop(stack);
                    lfargs[i] = y->type->copy(y);
                }

                /* call func, passing args array and arg count */
                z = ((LuciLibFuncObj *)x)->func(lfargs, a);
                LuciList_push(stack, z);    /* always push return val */
            }
            else {
                LUCI_DIE("%s", "Can't call something that isn't a function\n");
            }
        }
        FETCH(1);
        DISPATCH;

        HANDLE(RETURN)
            LUCI_DEBUG("%s\n", "RETURN");

            /* pop the return value */
            LuciObject *return_value = LuciList_pop(stack);

            /* pop function stack frame and replace active frame */
            frame = LuciList_pop(stack);
            //assert(frame->type == &obj_func_t);

            /* push the return value back onto the stack */
            LuciList_push(stack, return_value);

            /* restore saved instruction pointer */
            ip = AS_FUNCTION(frame)->ip;
        FETCH(1);
        DISPATCH;

        HANDLE(MKMAP)
            LUCI_DEBUG("MKMAP %d\n", a);
            x = LuciMap_new();
            for (i = 0; i < a; i ++) {
                /* first item is the value */
                y = LuciList_pop(stack);
                /* then the key */
                z = LuciList_pop(stack);
                /* add the key & value to the map */
                x->type->cput(x, z, y);
            }
            LuciList_push(stack, x);
        FETCH(1);
        DISPATCH;

        HANDLE(MKLIST)
            LUCI_DEBUG("MKLIST %d\n", a);
            x = LuciList_new();
            for (i = 0; i < a; i ++) {
                y = LuciList_pop(stack);
                LuciList_append(x, y);
            }
            LuciList_push(stack, x);
        FETCH(1);
        DISPATCH;

        HANDLE(CGET)
        {
            LUCI_DEBUG("%s\n", "CGET");
            /* pop container */
            x = LuciList_pop(stack);
            /* pop 'index' */
            y = LuciList_pop(stack);
            /* cget from the container */
            z = x->type->cget(x, y);
            LuciList_push(stack, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(CPUT)
        {
            LUCI_DEBUG("%s\n", "CPUT");
            /* pop container */
            x = LuciList_pop(stack);
            /* pop index/key/... */
            y = LuciList_pop(stack);
            /* pop right hand value */
            z = LuciList_pop(stack);
            /* put the right hand value into the container */
            y = x->type->cput(x, y, z);
        }
        FETCH(1);
        DISPATCH;

        HANDLE(MKITER)
            LUCI_DEBUG("%s\n", "MKITER");
            /* x should be a container */
            x = LuciList_pop(stack);
            y = LuciIterator_new(x, 1); /* step = 1 */
            LuciList_push(stack, y);
        FETCH(1);
        DISPATCH;

        HANDLE(JUMP)
            LUCI_DEBUG("JUMP %d\n", a);
        FETCH(a);
        DISPATCH;

        HANDLE(POPJUMP)
            LUCI_DEBUG("POPJUMP %d\n", a);
            x = LuciList_pop(stack);
        FETCH(a);
        DISPATCH;

        HANDLE(JUMPZ)
            LUCI_DEBUG("JUMPZ %d\n", a);
            x = LuciList_pop(stack);
            if (((LuciIntObj *)x)->i == 0) {
                FETCH(a);
            } else {
                FETCH(1);
            }
        DISPATCH;

        HANDLE(ITERJUMP)
            LUCI_DEBUG("ITERJUMP %d\n", a);
            x = LuciList_peek(stack);
            /* get a COPY of the next object in the iterator's list */
            y = iterator_next_object(x);
            /* if the iterator returned NULL, jump to the
             * end of the for loop. Otherwise, push iterator->next */
            if (y == NULL) {
                /* pop the iterator object */
                x = LuciList_pop(stack);
                FETCH(a);
            } else {
                LuciList_push(stack, y);
                FETCH(1);
            }
        DISPATCH;

        HANDLE(HALT)
            LUCI_DEBUG("%s\n", "HALT");
            gc_untrack_roots();
            goto done_eval;
        DISPATCH;

        DEFAULT
            LUCI_DIE("Invalid opcode: %d\n", GETOPCODE);
        }
    }

done_eval:;

    return;
}
Exemplo n.º 13
0
static void __init __maybe_unused cfe_read_configuration(void)
{
	int fetched = 0;

	printk(KERN_INFO "Fetching vars from bootloader... ");
	if (cfe_seal != CFE_EPTSEAL) {
		printk(KERN_CONT "none present, using defaults.\n");
		return;
	}

#define DPRINTK(...) do { } while (0)
/* #define DPRINTK(...) printk(__VA_ARGS__) */

#define FETCH(name, fn, arg) do { \
	if (cfe_getenv(name, cfe_buf, COMMAND_LINE_SIZE) == CFE_OK) { \
		DPRINTK("Fetch var '%s' = '%s'\n", name, cfe_buf); \
		fn(cfe_buf, arg); \
		fetched++; \
	} else { \
		DPRINTK("Could not fetch var '%s'\n", name); \
	} \
	} while (0)

	FETCH("ETH0_HWADDR", parse_eth0_hwaddr, brcm_eth0_macaddr);
	memcpy(brcm_moca0_macaddr, brcm_eth0_macaddr, ETH_ALEN);
	macaddr_increment(brcm_moca0_macaddr, ETH_ALEN, 1);
	FETCH("MOCA0_HWADDR", parse_eth0_hwaddr, brcm_moca0_macaddr);
	FETCH("DRAM0_SIZE", parse_ulong, &brcm_dram0_size_mb);
	FETCH("DRAM1_SIZE", parse_ulong, &brcm_dram1_size_mb);
	FETCH("CFE_BOARDNAME", parse_boardname, NULL);
	FETCH("BOOT_FLAGS", parse_cmdline, arcs_cmdline);

	FETCH("LINUX_FFS_STARTAD", parse_hex, &brcm_mtd_rootfs_start);
	FETCH("LINUX_FFS_SIZE", parse_hex, &brcm_mtd_rootfs_len);
	FETCH("LINUX_PART_STARTAD", parse_hex, &brcm_mtd_kernel_start);
	FETCH("LINUX_PART_SIZE", parse_hex, &brcm_mtd_kernel_len);
	FETCH("OCAP_PART_STARTAD", parse_hex, &brcm_mtd_ocap_start);
	FETCH("OCAP_PART_SIZE", parse_hex, &brcm_mtd_ocap_len);
	FETCH("FLASH_SIZE", parse_ulong, &brcm_mtd_flash_size_mb);
	FETCH("FLASH_TYPE", parse_string, brcm_mtd_flash_type);

	printk(KERN_CONT "found %d vars.\n", fetched);
}
Exemplo n.º 14
0
INLINE UINT16 fetchword(nec_state_t *nec_state)
{
	UINT16 r = FETCH();
	r |= (FETCH()<<8);
	return r;
}
Exemplo n.º 15
0
void imhand(register int j)
{				/* Pointer to optab[] entry   *//* * * * * * * * * *  START OF imhand()  * * * * * * * * * */

    static char a[128], b[32];
    unsigned long pc;
    register int k;
    int offset, oflag, immed, iflag, mod, opi, w, rm;
    int m, n;

    objini(j);

    FETCH(k);

    pc = PC + 1;

    offset = 0;
    mod = (k & 0xc0) >> 6;
    opi = (k & 0x38) >> 3;
    w = j & 1;
    rm = k & 7;

    if ((j & 2)
	&& ((opi == 1)
	    || (opi == 4)
	    || (opi == 6))) {
	badseq(j, k);
	return;
    }

    strcpy(a, OPFAM[opi]);

    if (!w)
	strcat(a, "b");

    if ((oflag = mod) > 2)
	oflag = 0;

    if ((mod == 0) && (rm == 6)) {
	FETCH(m);
	FETCH(n);
	offset = (n << 8) | m;
    } else if (oflag)
	if (oflag == 2) {
	    FETCH(m);
	    FETCH(n);
	    offset = (n << 8) | m;
	} else {
	    FETCH(m);
	    if (m & 0x80)
		n = -0xFF;
	    else
		n = 0;
	    offset = n | m;
	}

    switch (j & 3) {
    case 0:
    case 2:
	FETCH(immed);
	iflag = 0;
	break;
    case 1:
	FETCH(m);
	FETCH(n);
	immed = (n << 8) | m;
	iflag = 1;
	break;
    case 3:
	FETCH(immed);
	if (immed & 0x80)
	    immed &= 0xff00;
	iflag = 0;
	break;
    }

    strcat(a, "\t");

    switch (mod) {
    case 0:
	if (rm == 6)
	    strcat(a, lookup((long) (offset), N_DATA, LOOK_ABS, pc));
	else {
	    sprintf(b, "(%s)", REGS0[rm]);
	    strcat(a, b);
	}
	break;
    case 1:
    case 2:
	if (mod == 1) {
	    strcat(a, "*");
	    sprintf(b, "%d(", (short) offset);
	} else {
	    strcat(a, "#");
	    if (offset < 100 || offset > 65436)
		sprintf(b, "%d(", (short) offset);
	    else
		sprintf(b, "$%04x(", offset);
	}
	strcat(a, b);
	strcat(a, REGS1[rm]);
	strcat(a, ")");
	break;
    case 3:
	strcat(a, REGS[(w << 3) | rm]);
	break;
    }

    strcat(a, ",");
    if (iflag) {
	strcat(a, "#");
	if (immed < 100 || immed > 65436)
	    sprintf(b, "%d", (short) immed);
	else
	    sprintf(b, "$%04x", immed);
    } else {
	strcat(a, "*");
	sprintf(b, "%d", immed);
    }
    strcat(a, b);

    printf("%s\n", a);

    objout();

}				/* * * * * * * * * * * END OF imhand() * * * * * * * * * * */
Exemplo n.º 16
0
/* sp points to IAC byte */
static int
telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
{
	int i, x;
	u_int c;
	const u_char *osp, *p;
#define FETCH(c, sp, length) \
	do { \
		if (length < 1) \
			goto pktend; \
		ND_TCHECK(*sp); \
		c = *sp++; \
		length--; \
	} while (0)

	osp = sp;

	FETCH(c, sp, length);
	if (c != IAC)
		goto pktend;
	FETCH(c, sp, length);
	if (c == IAC) {		/* <IAC><IAC>! */
		if (print)
			ND_PRINT((ndo, "IAC IAC"));
		goto done;
	}

	i = c - TELCMD_FIRST;
	if (i < 0 || i > IAC - TELCMD_FIRST)
		goto pktend;

	switch (c) {
	case DONT:
	case DO:
	case WONT:
	case WILL:
	case SB:
		/* DONT/DO/WONT/WILL x */
		FETCH(x, sp, length);
		if (x >= 0 && x < NTELOPTS) {
			if (print)
				ND_PRINT((ndo, "%s %s", telcmds[i], telopts[x]));
		} else {
			if (print)
				ND_PRINT((ndo, "%s %#x", telcmds[i], x));
		}
		if (c != SB)
			break;
		/* IAC SB .... IAC SE */
		p = sp;
		while (length > (u_int)(p + 1 - sp)) {
			ND_TCHECK2(*p, 2);
			if (p[0] == IAC && p[1] == SE)
				break;
			p++;
		}
		if (*p != IAC)
			goto pktend;

		switch (x) {
		case TELOPT_AUTHENTICATION:
			if (p <= sp)
				break;
			FETCH(c, sp, length);
			if (print)
				ND_PRINT((ndo, " %s", STR_OR_ID(c, authcmd)));
			if (p <= sp)
				break;
			FETCH(c, sp, length);
			if (print)
				ND_PRINT((ndo, " %s", STR_OR_ID(c, authtype)));
			break;
		case TELOPT_ENCRYPT:
			if (p <= sp)
				break;
			FETCH(c, sp, length);
			if (print)
				ND_PRINT((ndo, " %s", STR_OR_ID(c, enccmd)));
			if (p <= sp)
				break;
			FETCH(c, sp, length);
			if (print)
				ND_PRINT((ndo, " %s", STR_OR_ID(c, enctype)));
			break;
		default:
			if (p <= sp)
				break;
			FETCH(c, sp, length);
			if (print)
				ND_PRINT((ndo, " %s", STR_OR_ID(c, cmds)));
			break;
		}
		while (p > sp) {
			FETCH(x, sp, length);
			if (print)
				ND_PRINT((ndo, " %#x", x));
		}
		/* terminating IAC SE */
		if (print)
			ND_PRINT((ndo, " SE"));
		sp += 2;
		break;
	default:
		if (print)
			ND_PRINT((ndo, "%s", telcmds[i]));
		goto done;
	}

done:
	return sp - osp;

trunc:
	ND_PRINT((ndo, "%s", tstr));
pktend:
	return -1;
#undef FETCH
}
Exemplo n.º 17
0
void mahand(register int j)
{				/* Pointer to optab[] entry   *//* * * * * * * * * *  START OF mahand()  * * * * * * * * * */

    char *a;
    register int k;
    char b[80];

    objini(j);

    FETCH(k);

    a = mtrans((j & 0xfd), (k & 0xc7), TR_STD);

    mtrunc(a);

    switch (((k = objbuf[1]) & 0x38) >> 3) {
    case 0:
	printf("\ttest");
	break;
    case 1:
	badseq(j, k);
	return;
    case 2:
	printf("\tnot");
	break;
    case 3:
	printf("\tneg");
	break;
    case 4:
	printf("\tmul");
	break;
    case 5:
	printf("\timul");
	break;
    case 6:
	printf("\tdiv");
	break;
    case 7:
	printf("\tidiv");
	break;
    }

    if (!(j & 1))
	putchar('b');

    printf("\t%s", a);

    if (k & 0x38)
	putchar('\n');
    else if (j & 1) {
	FETCH(j);
	FETCH(k);
	k = (k << 8) | j;
	if (lookext((long) (k), (PC - 1), b))
	    printf(",#%s\n", b);
	else
	    printf(",#$%04x\n", k);
    } else {
	FETCH(k);
	printf(",*%d\n", k);
    }

    objout();

}				/* * * * * * * * * * * END OF mahand() * * * * * * * * * * */
Exemplo n.º 18
0
static void I486OP(group0F01_32)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT32 address, ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				}
				else
				{
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
Exemplo n.º 19
0
void mjhand(register int j)
{				/* Pointer to optab[] entry   *//* * * * * * * * * *  START OF mjhand()  * * * * * * * * * */

    char *a;
    register int k;

    objini(j);

    FETCH(k);

    a = mtrans((j & 0xfd), (k & 0xc7), TR_STD);

    mtrunc(a);

    switch (((k = objbuf[1]) & 0x38) >> 3) {
    case 0:
	printf("\tinc");
	if (!(j & 1))
	    putchar('b');
	putchar('\t');
	break;
    case 1:
	printf("\tdec");
	if (!(j & 1))
	    putchar('b');
	putchar('\t');
	break;
    case 2:
	if (j & 1)
	    printf("\tcall\t@");
	else
	    goto BAD;
	break;
    case 3:
	if (j & 1)
	    printf("\tcalli\t@");
	else
	    goto BAD;
	break;
    case 4:
	if (j & 1)
	    printf("\tjmp\t@");
	else
	    goto BAD;
	break;
    case 5:
	if (j & 1)
	    printf("\tjmpi\t@");
	else
	    goto BAD;
	break;
    case 6:
	if (j & 1)
	    printf("\tpush\t");
	else
	    goto BAD;
	break;
    case 7:
      BAD:
	badseq(j, k);
	return;
    }

    printf("%s\n", a);

    objout();

}				/* * * * * * * * * * * END OF mjhand() * * * * * * * * * * */
Exemplo n.º 20
0
            methodToCall = dvmResolveMethod(curMethod->clazz, ref,
                            METHOD_DIRECT);
            if (methodToCall == NULL) {
                ILOGV("+ unknown direct method");     // should be impossible
                GOTO_exceptionThrown();
            }
        }
        GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
    }
GOTO_TARGET_END

GOTO_TARGET(invokeStatic, bool methodCallRange)
    EXPORT_PC();

    vsrc1 = INST_AA(inst);      /* AA (count) or BA (count + arg 5) */
    ref = FETCH(1);             /* method ref */
    vdst = FETCH(2);            /* 4 regs -or- first reg */

    if (methodCallRange)
        ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
            vsrc1, ref, vdst, vdst+vsrc1-1);
    else
        ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
            vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);

    methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
    if (methodToCall == NULL) {
        methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
        if (methodToCall == NULL) {
            ILOGV("+ unknown method");
            GOTO_exceptionThrown();
Exemplo n.º 21
0
HANDLE_OPCODE($opcode /*vAA, vBBBB*/)
    vdst = INST_AA(inst);
    vsrc1 = FETCH(1);
    ILOGV("|move%s/from16 v%d,v%d %s(v%d=0x%08x)",
        (INST_INST(inst) == OP_MOVE_FROM16) ? "" : "-object", vdst, vsrc1,
        kSpacing, vdst, GET_REGISTER(vsrc1));
    SET_REGISTER(vdst, GET_REGISTER(vsrc1));
#if defined(LOCCS_DIAOS)
#if INST_INST(inst) != OP_MOVE_FROM16
    //ALOG(LOG_VERBOSE,"YWB","need to verify object");
    diaos_monitor_object(curMethod, (Object*)GET_REGISTER(vdst));
#endif
#endif
    FINISH(2);
OP_END
Exemplo n.º 22
0
GOTO_TARGET_END


GOTO_TARGET(invokeVirtual, bool methodCallRange, bool)
    {
        Method* baseMethod;
        Object* thisPtr;

        EXPORT_PC();

        vsrc1 = INST_AA(inst);      /* AA (count) or BA (count + arg 5) */
        ref = FETCH(1);             /* method ref */
        vdst = FETCH(2);            /* 4 regs -or- first reg */

        /*
         * The object against which we are executing a method is always
         * in the first argument.
         */
        if (methodCallRange) {
            assert(vsrc1 > 0);
            ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
                vsrc1, ref, vdst, vdst+vsrc1-1);
            thisPtr = (Object*) GET_REGISTER(vdst);
        } else {
            assert((vsrc1>>4) > 0);
            ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
                vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
            thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
        }

        if (!checkForNull(thisPtr))
            GOTO_exceptionThrown();

        /*
         * Resolve the method.  This is the correct method for the static
         * type of the object.  We also verify access permissions here.
         */
        baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
        if (baseMethod == NULL) {
            baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
            if (baseMethod == NULL) {
                ILOGV("+ unknown method or access denied");
                GOTO_exceptionThrown();
            }
        }

        /*
         * Combine the object we found with the vtable offset in the
         * method.
         */
        assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
        methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];

#if defined(WITH_JIT) && defined(MTERP_STUB)
        self->methodToCall = methodToCall;
        self->callsiteClass = thisPtr->clazz;
#endif

#if 0
        if (dvmIsAbstractMethod(methodToCall)) {
            /*
             * This can happen if you create two classes, Base and Sub, where
             * Sub is a sub-class of Base.  Declare a protected abstract
             * method foo() in Base, and invoke foo() from a method in Base.
             * Base is an "abstract base class" and is never instantiated
             * directly.  Now, Override foo() in Sub, and use Sub.  This
             * Works fine unless Sub stops providing an implementation of
             * the method.
             */
            dvmThrowAbstractMethodError("abstract method not implemented");
            GOTO_exceptionThrown();
        }
#else
        assert(!dvmIsAbstractMethod(methodToCall) ||
            methodToCall->nativeFunc != NULL);
#endif

        LOGVV("+++ base=%s.%s virtual[%d]=%s.%s",
            baseMethod->clazz->descriptor, baseMethod->name,
            (u4) baseMethod->methodIndex,
            methodToCall->clazz->descriptor, methodToCall->name);
        assert(methodToCall != NULL);

#if 0
        if (vsrc1 != methodToCall->insSize) {
            ALOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s",
                baseMethod->clazz->descriptor, baseMethod->name,
                (u4) baseMethod->methodIndex,
                methodToCall->clazz->descriptor, methodToCall->name);
            //dvmDumpClass(baseMethod->clazz);
            //dvmDumpClass(methodToCall->clazz);
            dvmDumpAllClasses(0);
        }
#endif

        GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
    }
Exemplo n.º 23
0
int getBaxData(BaxData *b, char *fname)
{ hid_t   field_space;
  hid_t   field_set;
  hsize_t field_len[2];
  hid_t   file_id;
  herr_t  stat;
  int     ecode;
  hid_t   type;
  hid_t   attr;
  char   *name;

  H5Eset_auto(H5E_DEFAULT,0,0); // silence hdf5 error stack

  file_id = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
  if (file_id < 0)
    return (CANNOT_OPEN_BAX_FILE);

#ifdef DEBUG
  printf("PROCESSING %s, file_id: %d\n", baxFileName, file_id);
#endif

#define GET_SIZE(path,error)									\
  { ecode = error;										\
    if ((field_set = H5Dopen2(file_id, path, H5P_DEFAULT)) < 0) goto exit0;			\
    if ((field_space = H5Dget_space(field_set)) < 0) goto exit1;				\
    H5Sget_simple_extent_dims(field_space, field_len, NULL);					\
  }

#define FETCH(field,type)									\
  { stat = H5Dread(field_set, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, b->field);			\
    H5Sclose(field_space);									\
    H5Dclose(field_set);									\
    if (stat < 0) goto exit0;									\
  }

#define CHECK_FETCH(path,error,field,type,cntr)							\
  { GET_SIZE(path,error)									\
    if (b->cntr != field_len[0]) goto exit2;							\
    FETCH(field,type)										\
  }

  ecode = BAX_MOVIENAME_ERR;
  if ((field_set = H5Gopen2(file_id,"/ScanData/RunInfo",H5P_DEFAULT)) < 0) goto exit0;
  if ((attr = H5Aopen(field_set,"MovieName",H5P_DEFAULT)) < 0) goto exit3;
  if ((field_space = H5Aget_space(attr)) < 0) goto exit4;
  if ((type = H5Aget_type(attr)) < 0) goto exit5;

  H5Aread(attr,type,&name);
  ensureMovie(b,strlen(name));
  strcpy(b->movieName,name);

  H5Tclose(type);
  H5Sclose(field_space);
  H5Aclose(attr);
  H5Gclose(field_set);

  GET_SIZE("/PulseData/BaseCalls/Basecall",BAX_BASECALL_ERR)
  ensureBases(b,field_len[0]);
  FETCH(baseCall,H5T_NATIVE_UCHAR)
  if (b->arrow)
    CHECK_FETCH("/PulseData/BaseCalls/WidthInFrames",BAX_PULSE_ERR,pulseW,H5T_NATIVE_USHORT,numBP)
  if (b->fastq)
    CHECK_FETCH("/PulseData/BaseCalls/QualityValue",BAX_QV_ERR,fastQV,H5T_NATIVE_UCHAR,numBP)
  if (b->quivqv)
    { CHECK_FETCH("/PulseData/BaseCalls/DeletionQV",    BAX_DEL_ERR,delQV,  H5T_NATIVE_UCHAR,numBP)
      CHECK_FETCH("/PulseData/BaseCalls/DeletionTag",   BAX_TAG_ERR,delTag, H5T_NATIVE_UCHAR,numBP)
      CHECK_FETCH("/PulseData/BaseCalls/InsertionQV",   BAX_INS_ERR,insQV,  H5T_NATIVE_UCHAR,numBP)
      CHECK_FETCH("/PulseData/BaseCalls/MergeQV",       BAX_MRG_ERR,mergeQV,H5T_NATIVE_UCHAR,numBP)
      CHECK_FETCH("/PulseData/BaseCalls/SubstitutionQV",BAX_SUB_ERR,subQV,  H5T_NATIVE_UCHAR,numBP)
    }

  GET_SIZE("/PulseData/BaseCalls/ZMW/HoleStatus",BAX_HOLESTATUS_ERR)
  ensureZMW(b,field_len[0]);
  FETCH(holeType,H5T_NATIVE_UCHAR)
  CHECK_FETCH("/PulseData/BaseCalls/ZMW/NumEvent",BAX_NR_EVENTS_ERR,readLen,H5T_NATIVE_INT,numZMW)
  if (b->arrow)
    { CHECK_FETCH("/PulseData/BaseCalls/ZMWMetrics/HQRegionSNR",BAX_SNR_ERR,snrVec,
                  H5T_NATIVE_FLOAT,numZMW)

      ecode = BAX_CHIPSET_ERR;
      if ((field_set = H5Gopen2(file_id,"/ScanData/DyeSet",H5P_DEFAULT)) < 0) goto exit0;
      if ((attr = H5Aopen(field_set,"BaseMap",H5P_DEFAULT)) < 0) goto exit3;
      if ((field_space = H5Aget_space(attr)) < 0) goto exit4;
      if ((type = H5Aget_type(attr)) < 0) goto exit5;

      H5Aread(attr,type,&name);

      { int i;

        for (i = 0; i < 4; i++)
          b->chan[i] = DNA_2_NUMBER[(int) name[i]];
      }

      H5Tclose(type);
      H5Sclose(field_space);
      H5Aclose(attr);
      H5Gclose(field_set);

    }

  GET_SIZE("/PulseData/Regions",BAX_REGION_ERR)
  ensureHQR(b,field_len[0]);
  FETCH(regions,H5T_NATIVE_INT)

  //  Find the Del QV associated with N's in the Del Tag

  if (b->quivqv)
    { hsize_t  i;
  
      for (i = 0; i < b->numBP; i++)
        if (b->delTag[i] == 'N')
          { b->delLimit = b->delQV[i];
            break;
          }
    }

  H5Fclose(file_id);
  return (0);

exit5:
  H5Sclose(field_space);
exit4:
  H5Aclose(attr);
exit3:
  H5Gclose(field_set);
  H5Fclose(file_id);
  return (ecode);

exit2:
  H5Sclose(field_space);
exit1:
  H5Dclose(field_set);
exit0:
  H5Fclose(file_id);
  return (ecode);
}