Example #1
0
void Value::doConvert(Type newType) {
    switch (type) {
    case TYPE_I32:
        type = newType;
        switch (newType) {
        case TYPE_I8:  constant.i8  =  S08(constant.i32); return;
        case TYPE_I16: constant.i16 = S16(constant.i32); return;
        case TYPE_I32: constant.i32 = S32(constant.i32); return;
        case TYPE_I64: constant.i64 = S64(constant.i32); return;
        case TYPE_F32: constant.f32 = F32(constant.i32); return;
        case TYPE_F64: constant.f64 = F64(constant.i32); return;
        default:
            assert_always("Unimplemented case");
            return;
        }
    case TYPE_I64:
        type = newType;
        switch (newType) {
        case TYPE_I8:  constant.i8  =  S08(constant.i64); return;
        case TYPE_I16: constant.i16 = S16(constant.i64); return;
        case TYPE_I32: constant.i32 = S32(constant.i64); return;
        case TYPE_I64: constant.i64 = S64(constant.i64); return;
        case TYPE_F32: constant.f32 = F32(constant.i64); return;
        case TYPE_F64: constant.f64 = F64(constant.i64); return;
        default:
            assert_always("Unimplemented case");
            return;
        }
    case TYPE_F32:
        type = newType;
        switch (newType) {
        case TYPE_I8:  constant.i8  =  S08(constant.f32); return;
        case TYPE_I16: constant.i16 = S16(constant.f32); return;
        case TYPE_I32: constant.i32 = S32(constant.f32); return;
        case TYPE_I64: constant.i64 = S64(constant.f32); return;
        case TYPE_F32: constant.f32 = F32(constant.f32); return;
        case TYPE_F64: constant.f64 = F64(constant.f32); return;
        default:
            assert_always("Unimplemented case");
            return;
        }
    case TYPE_F64:
        type = newType;
        switch (newType) {
        case TYPE_I8:  constant.i8  =  S08(constant.f64); return;
        case TYPE_I16: constant.i16 = S16(constant.f64); return;
        case TYPE_I32: constant.i32 = S32(constant.f64); return;
        case TYPE_I64: constant.i64 = S64(constant.f64); return;
        case TYPE_F32: constant.f32 = F32(constant.f64); return;
        case TYPE_F64: constant.f64 = F64(constant.f64); return;
        default:
            assert_always("Unimplemented case");
            return;
        }
    default:
        assert_always("Unimplemented case");
        return;
    }
}
Example #2
0
static struct elf_header * read_elf_header(const struct elf_header *p)
{
	static struct elf_header hdr;

	hdr = *p;

	if (need_byteswap)
	{
		hdr.type      = S16(hdr.type);
		hdr.machine   = S16(hdr.machine);
		hdr.version   = S32(hdr.version);
		hdr.entry     = S32(hdr.entry);
		hdr.phoff     = S32(hdr.phoff);
		hdr.shoff     = S32(hdr.shoff);
		hdr.flags     = S32(hdr.flags);
		hdr.ehsize    = S16(hdr.ehsize);
		hdr.phentsize = S16(hdr.phentsize);
		hdr.phnum     = S16(hdr.phnum);
		hdr.shentsize = S16(hdr.shentsize);
		hdr.shnum     = S16(hdr.shnum);
		hdr.shtrndx   = S16(hdr.shtrndx);
	}

	return &hdr;
}
Example #3
0
static void tx_kickstart(struct net_device *dev)
{
	struct fs_enet_private *fep = netdev_priv(dev);
	fcc_t __iomem *fccp = fep->fcc.fccp;

	S16(fccp, fcc_ftodr, 0x8000);
}
Example #4
0
static void napi_enable_rx(struct net_device *dev)
{
	struct fs_enet_private *fep = netdev_priv(dev);
	fcc_t __iomem *fccp = fep->fcc.fccp;

	S16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
}
static void set_promiscuous_mode(struct net_device *dev)
{
	struct fs_enet_private *fep = netdev_priv(dev);
	scc_t __iomem *sccp = fep->scc.sccp;

	S16(sccp, scc_psmr, SCC_PSMR_PRO);
}
Example #6
0
void AtlasOldMesher::writeVertex(Stream *s, Vert *vert, const S8 level)
{
   S16 x, y, z;

   const Point2I &vertPos = vert->pos;
   Point3F center;
   mBounds.getCenter(&center);

   if (vert->special)
      z = vert->z;
   else
      z = mHeight->sampleRead(vertPos);

   S32 xTmp, yTmp;
   xTmp = (S32)mFloor(((vertPos.x * mHeight->mSampleSpacing - center.x) * mCompressionFactor.x) + 0.5);
   yTmp = (S32)mFloor(((vertPos.y * mHeight->mSampleSpacing - center.y) * mCompressionFactor.y) + 0.5);

   AssertFatal(S16(xTmp) == xTmp,
      "AtlasOldMesher::writeVertex - Overflow writing x-coordinate!");
   AssertFatal(S16(yTmp) == yTmp,
      "AtlasOldMesher::writeVertex - Overflow writing y-coordinate!");

   x = xTmp;
   y = yTmp;

   s->write(x);
   s->write(y);
   s->write(z);

   // Morph info.  Calculate the difference between the
   // vert height, and the height of the same spot in the
   // next lower-LOD mesh.
   S16 morphHeight;
   if (vert->special)
      morphHeight = z;	// special verts don't morph.
   else
   {
      morphHeight = mHeight->getHeightAtLOD(vertPos, level + 1);
   }

   S32 morphDelta = (S32(morphHeight) - S32(z));
   s->write(S16(morphDelta));

   if(morphDelta != S16(morphDelta))
      Con::warnf("AtlasOldMesher::writeVertex - overflow in lerpedHeight!");
}
	/// @brief Assigns to a member
	/// @note upvalue 1: Member descriptor, non-permissions, and lookup data
	static void NewIndexMember (lua_State * L)
	{
		// Point to the requested member.
		Uint8 * pData = GetFields(L);	// data, key, value, D, D[key], offset, type

		// Assign the appropriate type.
		switch (U(L, 7))
		{
		case Member_Reg::ePointer:
			*(void**)pData = UD(L, 3);
			break;
		case Member_Reg::eU8:
		case Member_Reg::eUChar:
			*(Uint8*)pData = U8(L, 3);
			break;
		case Member_Reg::eS8:
		case Member_Reg::eSChar:
		//	*(Sint8*)pData = S8(L, 3);
			break;
		case Member_Reg::eU16:
		case Member_Reg::eUShort:
			*(Uint16*)pData = U16(L, 3);
			break;
		case Member_Reg::eS16:
		case Member_Reg::eSShort:
			*(Sint16*)pData = S16(L, 3);
			break;
		case Member_Reg::eU32:
			*(Uint32*)pData = U(L, 3);
			break;
		case Member_Reg::eS32:
			*(Sint32*)pData = S32(L, 3);
			break;
		case Member_Reg::eULong:
			break;
		case Member_Reg::eSLong:
			*(long*)pData = LI(L, 3);
			break;
		case Member_Reg::eUInt:
			break;
		case Member_Reg::eSInt:
			*(Sint32*)pData = S32(L, 3);
			break;
		case Member_Reg::eFSingle:
			*(float*)pData = F(L, 3);
			break;
		case Member_Reg::eFDouble:
			break;
		case Member_Reg::eString:
			break;
		case Member_Reg::eBoolean:
			*(bool*)pData = B(L, 3);
			break;
		}
	}
Example #8
0
/// change touch input to stick input (Last_Actions)
bool SBOnTouchEvent( unsigned short x, unsigned short y, unsigned short state )
{
#ifdef SB_BUILD_VIRTUAL_PAD
//	dbg_msg("SBOnTouchEvent(): %d  %d, %d \n", state, x,y);

	if (state == 2) //UP
	switch ( Scene_State )
	{
	case SCENE_TITLE:
//		if ( key == ' ' || key == 62 )
		{
			Sub_State++;
			return true;
		}
		break;

	case SCENE_PLAY:
		if ( game_paused )
		{
//			SBOnTogglePause();
		}
		break;

	case SCENE_END:
//		if ( sIsDebugStartScene(key) )
		{
//			if( Sub_State==SUB_STATE0 )
//			dbg_msg("SBOnTouchEvent() SCENE END: counter:%d \n", s_CountDownBeforeGoingToTitle);
			return true;
		}
#if 0
//ifdef DEBUG
		if ( sIsDebugNextScene(key) )
		{
			Is_GameOver = FALSE;
			Is_GameCleared = TRUE;
		}
#endif
		break;
	}

	if ( s_touchPadMode == 0 )
	{
		float TOUCH_OFFSET = 3.0f;
		unsigned short TOUCH_THRESHOLD = 0;

		if ( state == 1 )	// MOVE
		{
			if ( ABS(x-LastTouchX) >= TOUCH_THRESHOLD )
			{
				float angleX = (x-LastTouchX) * TOUCH_OFFSET;
				Last_Actions[RIGHT] = angleX>0;
				Last_Actions[LEFT] = angleX<0;
			}
			if ( ABS(y-LastTouchY) >= TOUCH_THRESHOLD )
			{
				float angleY = (y-LastTouchY) * TOUCH_OFFSET;
				Last_Actions[DOWN] = angleY<0;
				Last_Actions[UP] = angleY>0;
			}
			s_isTouchDown = true;
		}
		else if ( state == 2 ) //UP
		{
			for ( int i=UP; i <= RIGHT; i++ )
			{
			//	Last_Actions[i] = false;
			}

  			s_isTouchDown = false;
			return true;
		}

		// DOWN
		LastTouchX = x;
		LastTouchY = y;
	}
	else if (s_touchPadMode == 1 )
	{
		if ( state == 2 ) //UP
		{
			for ( int i=UP; i <= RIGHT; i++ )
			{
				Last_Actions[i] = false;
			}

  			s_isTouchDown = false;
			return true;
		}
		else
		{
			s_isTouchDown = true;
		}

		//convert x,y to DPAD game keys
		const S16 diffx = S16(x) - DPAD_X;
		const S16 diffy = Screen_H - S16(y) - DPAD_Y;

		//dbg_msg("SBOnTouchEvent(): %d  %d, %d \n", state, diffx, diffy);

		if ( ABS(diffx) > DPAD_SIZE_OUT 
			||  ( ABS(diffy) > DPAD_SIZE_OUT ) )
		{
			Last_Actions[LEFT] = Last_Actions[RIGHT] = false;
			Last_Actions[UP] = Last_Actions[DOWN] = false;
		}
		else
		{
			if (DPAD_SIZE_IN <= ABS(diffx))
			{
				const char i = diffx > 0 ? RIGHT:LEFT;
				const char j = i==LEFT? RIGHT:LEFT;
				Last_Actions[i] = true;
				Last_Actions[j] = false;
				//dbg_msg("SBOnTouchEvent() DIFF: %d  %d, %d \n", state, diffx, x);
			}

			if ( DPAD_SIZE_IN <= ABS(diffy) )
			{
				const char i = diffy > 0 ? DOWN:UP;
				const char j = i==UP? DOWN:UP;
				Last_Actions[i] = true;
				Last_Actions[j] = false;
			}
		}
	}
	else if ( s_touchPadMode==2 )
	{
		for ( int i=UP; i <= RIGHT; i++ )
		{
			Last_Actions[i] = false;
		}

		if ( state == 1 )	// MOVE
		{
			float p[2];
			// map screen coor to our coor
			p[0] = CHAN_X * x / Screen_W + (-CHAN_X*0.5);
			p[1] = - CHAN_Y * y / Screen_H + (CHAN_Y*0.5);
			//dbg_msg("SBOnTouchEvent(): res:  %.2f  %.2f  \n", p[0], p[1] );

			//calculate vectors and then map it to Last_Actions[]
			for ( char i=0; i<2; ++i )
			{
				const float diff = p[i] - Dream_State.pos[i];
				if ( fabs(diff) > 0.2 )
				{
					const char dir = i==0 ? LEFT : UP;
					Last_Actions[dir] = diff < 0;
					Last_Actions[dir+1] = !Last_Actions[dir];
				}
			}

			s_isTouchDown = true;
		}
		else //if ( state == 2 ) //UP
		{
			s_isTouchDown = false;
		}
	}
#endif
	return true;
}
Example #9
0
    //
    // New and improved sweep
    //
    void Sweep(UnitObj *u)
    {
      ASSERT(sysInit);
      ASSERT(u);
      //ASSERT(u->GetTeam());
      ASSERT(u->OnMap());

      START(sweepTime);

      r = u->GetSeeingRange();
      unit = u;
      cellX = u->cellX;
      cellZ = u->cellZ;

      ASSERT(r < MAXR)

      // Get sight map and mask
      maskLo = u->sightMap->GetBitMask(Map::LV_LO);
      mapLo = u->sightMap->GetByteMap(Map::LV_LO);

      // Reset max radius seen
      u->sightMap->lastR = S16_MIN;

      // Set teams that this sweep will provide LOS for
      Team *myTeam = u->GetTeam();
      teamBits = 0;

      if (myTeam)
      {
        for (U32 team = 0; team < Game::MAX_TEAMS; ++team)
        {
          Team *other = Team::Id2Team(team);

          if (other)
          {
            if
            (
              // Other team is an ally
              Team::TestUnitRelation(u, other, Relation::ALLY)

              ||

              // Other team is giving us line of sight
              myTeam->GivingSightTo(other->GetId())
            )
            {
              ASSERT(teamRemap[team] < teamCount)
              Game::TeamSet(teamBits, teamRemap[team]);
            }
          }
        }
      }

      // Dirty cells that line of sight has changed in
      DirtyCells(cellX - r, cellZ - r, cellX + r, cellZ + r, teamBits);

      // Set up viewing radius
      if (r > 0)
      {
        r2 = r * r;
        r2Inv = 1.0f / F32(r2);

        // Get eye position
        eyePos = EyePosition(u);

        // In the code below the row and column of cells with the
        // same y and x value of the unit are processed twice but
        // their viewing information is only updated once. Stuff
        // the slight inneficiency (2*r extra comparisons). This
        // way we require 1/4 the memory and the code is more
        // elegant.

        // scan ++ quadrant
        quadrantX = POS;
        quadrantZ = POS;

        FillGradMap();
        FillMaxGradMapPosZ();
        CompareGradPosPos();

        // Scan -+ quadrant
        quadrantX = NEG;

        FillGradMapRotated();
        FillMaxGradMapPosZ();
        CompareGradNegPos();

        // Scan -- quadrant
        quadrantZ = NEG;

        FillGradMap();
        FillMaxGradMapNegZ();
        CompareGradNegNeg();

        // Scan +- quadrant
        quadrantX = POS;

        FillGradMapRotated();
        FillMaxGradMapNegZ();
        CompareGradPosNeg();
      }

      // Can always see cell that unit is occupying
      CanSee(cellX, cellZ, 0, 0, mapLo, maskLo, teamBits, Map::LV_LO);

      // Update scan info in unit's sight map
      u->sightMap->lastTeam = teamBits;
      u->sightMap->lastR = S16(r);
      u->sightMap->lastX = cellX;
      u->sightMap->lastZ = cellZ;
      u->sightMap->lastAlt = eyePos;

      STOP(sweepTime);
    }
Example #10
0
void test(int M, int N, int O, int P, int Q, int R)
{
  /* Scattering iterators. */
  int p1, p3, p5;
  /* Original iterators. */
  int i, j, k;
  if (M == 1) {
    S1() ;
    S2() ;
    S3() ;
    S4() ;
    S5() ;
    S6() ;
    S7() ;
    S8() ;
    S9() ;
    S10() ;
    S11() ;
    S12() ;
    S13() ;
    S14() ;
    S15() ;
    S16() ;
    S17() ;
    S18() ;
    S19() ;
    S20() ;
    S21() ;
    S22() ;
    S23() ;
    S24() ;
    S25() ;
    S26() ;
    S27() ;
  }
  if (M == 1) {
    for (p1=1;p1<=N;p1++) {
      for (p3=1;p3<=N;p3++) {
        S28(p1,p3) ;
        S29(p1,p3) ;
        S30(p1,p3) ;
      }
      S31(p1) ;
    }
  }
  if (M == 1) {
    S32() ;
    S33() ;
    S34() ;
  }
  if ((M == 1) && (O <= 1)) {
    S35() ;
  }
  if (M == 1) {
    S36() ;
    S37() ;
  }
  if ((M == 1) && (N >= 1) && (Q >= 1) && (R >= 1)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S40(p1,p3,p5) ;
          S41(p1,p3,p5) ;
          S42(p1,p3,p5) ;
          S43(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S44(p1,p3) ;
        S45(p1,p3) ;
        S46(p1,p3) ;
        S47(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S48(p1,p3) ;
        S49(p1,p3) ;
        S50(p1,p3) ;
        S51(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S59(p1,p3,p5) ;
          S60(p1,p3,p5) ;
          S61(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S62(p1,p3) ;
        S63(p1,p3) ;
        S64(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S65(p1,p3) ;
        S66(p1,p3) ;
        S67(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      for (p3=1;p3<=N;p3++) {
        for (p5=1;p5<=N;p5++) {
          S95(p1,p3,p5) ;
          S96(p1,p3,p5) ;
          S97(p1,p3,p5) ;
        }
        S98(p1,p3) ;
      }
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S102(p1,p3,p5) ;
          S103(p1,p3,p5) ;
          S104(p1,p3,p5) ;
          S105(p1,p3,p5) ;
          S106(p1,p3,p5) ;
          S107(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S108(p1,p3) ;
        S109(p1,p3) ;
        S110(p1,p3) ;
        S111(p1,p3) ;
        S112(p1,p3) ;
        S113(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S114(p1,p3) ;
        S115(p1,p3) ;
        S116(p1,p3) ;
        S117(p1,p3) ;
        S118(p1,p3) ;
        S119(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N <= 0) && (Q >= 1) && (R >= 1)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S40(p1,p3,p5) ;
          S41(p1,p3,p5) ;
          S42(p1,p3,p5) ;
          S43(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S44(p1,p3) ;
        S45(p1,p3) ;
        S46(p1,p3) ;
        S47(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S48(p1,p3) ;
        S49(p1,p3) ;
        S50(p1,p3) ;
        S51(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S59(p1,p3,p5) ;
          S60(p1,p3,p5) ;
          S61(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S62(p1,p3) ;
        S63(p1,p3) ;
        S64(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S65(p1,p3) ;
        S66(p1,p3) ;
        S67(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=Q;p3++) {
        for (p5=1;p5<=R;p5++) {
          S102(p1,p3,p5) ;
          S103(p1,p3,p5) ;
          S104(p1,p3,p5) ;
          S105(p1,p3,p5) ;
          S106(p1,p3,p5) ;
          S107(p1,p3,p5) ;
        }
      }
      for (p3=1;p3<=Q;p3++) {
        S108(p1,p3) ;
        S109(p1,p3) ;
        S110(p1,p3) ;
        S111(p1,p3) ;
        S112(p1,p3) ;
        S113(p1,p3) ;
      }
      for (p3=1;p3<=R;p3++) {
        S114(p1,p3) ;
        S115(p1,p3) ;
        S116(p1,p3) ;
        S117(p1,p3) ;
        S118(p1,p3) ;
        S119(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N >= 1) && (Q <= 0) && (R >= 1)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=R;p3++) {
        S48(p1,p3) ;
        S49(p1,p3) ;
        S50(p1,p3) ;
        S51(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=R;p3++) {
        S65(p1,p3) ;
        S66(p1,p3) ;
        S67(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      for (p3=1;p3<=N;p3++) {
        for (p5=1;p5<=N;p5++) {
          S95(p1,p3,p5) ;
          S96(p1,p3,p5) ;
          S97(p1,p3,p5) ;
        }
        S98(p1,p3) ;
      }
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=R;p3++) {
        S114(p1,p3) ;
        S115(p1,p3) ;
        S116(p1,p3) ;
        S117(p1,p3) ;
        S118(p1,p3) ;
        S119(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N <= 0) && (Q <= 0) && (R >= 1)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=R;p3++) {
        S48(p1,p3) ;
        S49(p1,p3) ;
        S50(p1,p3) ;
        S51(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=R;p3++) {
        S65(p1,p3) ;
        S66(p1,p3) ;
        S67(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=R;p3++) {
        S114(p1,p3) ;
        S115(p1,p3) ;
        S116(p1,p3) ;
        S117(p1,p3) ;
        S118(p1,p3) ;
        S119(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N >= 1) && (Q <= 0) && (R <= 0)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      for (p3=1;p3<=N;p3++) {
        for (p5=1;p5<=N;p5++) {
          S95(p1,p3,p5) ;
          S96(p1,p3,p5) ;
          S97(p1,p3,p5) ;
        }
        S98(p1,p3) ;
      }
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N <= 0) && (Q <= 0) && (R <= 0)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N >= 1) && (Q >= 1) && (R <= 0)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S44(p1,p3) ;
        S45(p1,p3) ;
        S46(p1,p3) ;
        S47(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S62(p1,p3) ;
        S63(p1,p3) ;
        S64(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      for (p3=1;p3<=N;p3++) {
        for (p5=1;p5<=N;p5++) {
          S95(p1,p3,p5) ;
          S96(p1,p3,p5) ;
          S97(p1,p3,p5) ;
        }
        S98(p1,p3) ;
      }
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S108(p1,p3) ;
        S109(p1,p3) ;
        S110(p1,p3) ;
        S111(p1,p3) ;
        S112(p1,p3) ;
        S113(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
  if ((M == 1) && (N <= 0) && (Q >= 1) && (R <= 0)) {
    for (p1=2;p1<=P;p1++) {
      S38(p1) ;
      S39(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S44(p1,p3) ;
        S45(p1,p3) ;
        S46(p1,p3) ;
        S47(p1,p3) ;
      }
      S52(p1) ;
      S53(p1) ;
      S54(p1) ;
      S55(p1) ;
      S56(p1) ;
      S57(p1) ;
      S58(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S62(p1,p3) ;
        S63(p1,p3) ;
        S64(p1,p3) ;
      }
      S68(p1) ;
      S69(p1) ;
      S70(p1) ;
      S71(p1) ;
      S72(p1) ;
      S73(p1) ;
      S74(p1) ;
      S75(p1) ;
      S76(p1) ;
      S77(p1) ;
      S78(p1) ;
      S79(p1) ;
      S80(p1) ;
      S81(p1) ;
      S82(p1) ;
      S83(p1) ;
      S84(p1) ;
      S85(p1) ;
      S86(p1) ;
      S87(p1) ;
      S88(p1) ;
      S89(p1) ;
      S90(p1) ;
      S91(p1) ;
      S92(p1) ;
      S93(p1) ;
      S94(p1) ;
      S99(p1) ;
      S100(p1) ;
      S101(p1) ;
      for (p3=1;p3<=Q;p3++) {
        S108(p1,p3) ;
        S109(p1,p3) ;
        S110(p1,p3) ;
        S111(p1,p3) ;
        S112(p1,p3) ;
        S113(p1,p3) ;
      }
      S120(p1) ;
      S121(p1) ;
      S122(p1) ;
      S123(p1) ;
      S124(p1) ;
      S125(p1) ;
    }
  }
}
Example #11
0
int main()
{
	u8 *buf = NULL, *newContentBuf = NULL;
	FILE *f = fopen("title.cia","rb");
	if(!f)
	{
		puts("Unable to open title.cia!");
		goto end;
	}
	fseek(f,0,SEEK_END);
	size_t fsize = ftell(f);
	fseek(f,0,SEEK_SET);
	buf = malloc(fsize);
	if(!buf)
	{
		printf("Unable to allocate %i bytes!\n",fsize);
		goto end;
	}
	fread(buf,1,fsize,f);
	fclose(f);
	f = NULL;
	u32 certsize = A64(*(u32*)(buf+0x8)), tiksize=A64(*(u32*)(buf+0xC)), tmdsize=A64(*(u32*)(buf+0x10)),
		metasize=A64(*(u32*)(buf+0x14)), contentsize=A64(*(u32*)(buf+0x18));
	printf("Cert Size:%x, Tik Size: %x, TMD Size: %x\nMeta Size: %x, Total Content Size:%x\n",
		certsize,tiksize,tmdsize,metasize,contentsize);
	u32 tmdstart = 0x2040+certsize+tiksize;
	printf("TMD Start: %x\n",tmdstart);
	u32 sigtype = S32(*(u32*)(buf+tmdstart));
	u32 tmdsigsize = 0x100;

	if(sigtype != RSA_2048_SHA256)
	{
		printf("Signature Type not supported:0x%08x\n",sigtype);
		goto end;
	}

	u32 tmdhdr = A64(tmdstart+4+tmdsigsize);
	u32 tmdverpos = tmdhdr+0x40;
	int tmdver = *(buf+tmdverpos);
	if(tmdver != 1)
	{
		printf("Unknown tmd ver:%i\n",tmdver);
		goto end;
	}
	printf("Title ID: %016I64x\n",S64(*(u64*)(buf+tmdhdr+0x4C)));
	u32 numcontentpos = tmdhdr+0x9E;
	u16 numcontents = S16(*(u16*)(buf+numcontentpos));
	printf("Num Contents: %i\n",numcontents);
	u32 infoshapos = numcontentpos+6; //has sha1 of 0x900 inforecords
	u32 inforecords = infoshapos+0x20; //has sha1 of each chunkrecord
	f = fopen("content.bin","rb");
	fseek(f,0,SEEK_END);
	size_t newContentSize = ftell(f);
	fseek(f,0,SEEK_SET);
	newContentBuf = malloc(newContentSize);
	fread(newContentBuf,newContentSize,1,f);
	fclose(f);
	memcpy(buf+0x18,&newContentSize,4);
	printf("New Content Size: %x\n",A64(*(u32*)(buf+0x18)));
	u32 chunkrecords = inforecords+(0x40*0x24); //has sha1 of each content
	u32 chunkrecordsSize = chunkrecords+(numcontents*0x30);
	u32 content = A64(chunkrecordsSize);
	printf("Content starts at 0x%x\n",content);
	int i;
	for(i = 0; i < numcontents; i++)
	{
		*(u64*)(buf+(chunkrecords+(i*0x30))+0x8) = S64(newContentSize);
		u64 thisContentSize = S64(*(u64*)(buf+(chunkrecords+(i*0x30))+0x8));
		printf("Content %i Size: %I64x\n", 
			S16(*(u16*)(buf+(chunkrecords+(i*0x30))+0x4)),
			thisContentSize);
		sha2(newContentBuf,(u32)thisContentSize,buf+(chunkrecords+(i*0x30))+0x10,0);
	}
	sha2(buf+chunkrecords,0x30,buf+inforecords+4,0);
	sha2(buf+inforecords,(0x40*0x24),buf+infoshapos,0);
	printf("Signing TMD, RsaSignVerify=%i\n",
		RsaSignVerify(buf+tmdstart+0x140,0xC4,buf+tmdstart+4,mod,priv_exp,RSA_2048_SHA256,CTR_RSA_SIGN));
	f = fopen("titleNew.cia","wb");
	fwrite(buf,content,1,f);
	fwrite(newContentBuf,newContentSize,1,f);
	if(metasize > 0)
	{
		u32 metastart = 0x2040+certsize+tiksize+tmdsize+contentsize;
		fwrite(buf+metastart,metasize,1,f);
	}
	fclose(f);
	puts("Wrote titleNew.cia");
end:
	if(buf) free(buf);
	if(f) fclose(f);
	return 0;
}
Example #12
0
enum parseType S()
{
	char *save = next;
	if (!S01()) {
		next = save;
		if (!S02()) {
			next = save;
			if (!S03()) {
				next = save;
				if (!S04()) {
					next = save;
					if (!S05()) {
						next = save;
						goto S06_above;
					} else return tS05;
				} else return tS04;
			} else return tS03;
		} else return tS02;
	} else return tS01;
S06_above:
	if (!S06()) {
		next = save;
		if (!S07()) {
			next = save;
			if (!S08()) {
				next = save;
				if (!S09()) {
					next = save;
					if (!S10()) {
						next = save;
						goto S11_above;
					} else return tS10;
				} else return tS09;
			} else return tS08;
		} else return tS07;
	} else return tS06;
S11_above:
	if (!S11()) {
		next = save;
		if (!S12()) {
			next = save;
			if (!S13()) {
				next = save;
				if (!S14()) {
					next = save;
					if (!S15()) {
						next = save;
						goto S16_above;
					} else return tS15;
				} else return tS14;
			} else return tS13;
		} else return tS12;
	} else return tS11;
S16_above:
	if (!S16()) {
		next = save;
		if (!S17()) {
			next = save;
			if (!S18()) {
				next = save;
				if (!S19()) {
					next = save;
					if (!S20()) {
						goto S21_above;
					} else return tS20;
				} else return tS19;
			} else return tS18;
		} else return tS17;
	} else return tS16;
S21_above:
	if (!S21()) {
		return tERR;
	} else return tS21;
	return tERR;
}
/*
 * This function is called to start or restart the FEC during a link
 * change.  This only happens when switching between half and full
 * duplex.
 */
static void restart(struct net_device *dev)
{
	struct fs_enet_private *fep = netdev_priv(dev);
	scc_t __iomem *sccp = fep->scc.sccp;
	scc_enet_t __iomem *ep = fep->scc.ep;
	const struct fs_platform_info *fpi = fep->fpi;
	u16 paddrh, paddrm, paddrl;
	const unsigned char *mac;
	int i;

	C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);

	/* clear everything (slow & steady does it) */
	for (i = 0; i < sizeof(*ep); i++)
		__fs_out8((u8 __iomem *)ep + i, 0);

	/* point to bds */
	W16(ep, sen_genscc.scc_rbase, fep->ring_mem_addr);
	W16(ep, sen_genscc.scc_tbase,
	    fep->ring_mem_addr + sizeof(cbd_t) * fpi->rx_ring);

	/* Initialize function code registers for big-endian.
	 */
#ifndef CONFIG_NOT_COHERENT_CACHE
	W8(ep, sen_genscc.scc_rfcr, SCC_EB | SCC_GBL);
	W8(ep, sen_genscc.scc_tfcr, SCC_EB | SCC_GBL);
#else
	W8(ep, sen_genscc.scc_rfcr, SCC_EB);
	W8(ep, sen_genscc.scc_tfcr, SCC_EB);
#endif

	/* Set maximum bytes per receive buffer.
	 * This appears to be an Ethernet frame size, not the buffer
	 * fragment size.  It must be a multiple of four.
	 */
	W16(ep, sen_genscc.scc_mrblr, 0x5f0);

	/* Set CRC preset and mask.
	 */
	W32(ep, sen_cpres, 0xffffffff);
	W32(ep, sen_cmask, 0xdebb20e3);

	W32(ep, sen_crcec, 0);	/* CRC Error counter */
	W32(ep, sen_alec, 0);	/* alignment error counter */
	W32(ep, sen_disfc, 0);	/* discard frame counter */

	W16(ep, sen_pads, 0x8888);	/* Tx short frame pad character */
	W16(ep, sen_retlim, 15);	/* Retry limit threshold */

	W16(ep, sen_maxflr, 0x5ee);	/* maximum frame length register */

	W16(ep, sen_minflr, PKT_MINBUF_SIZE);	/* minimum frame length register */

	W16(ep, sen_maxd1, 0x000005f0);	/* maximum DMA1 length */
	W16(ep, sen_maxd2, 0x000005f0);	/* maximum DMA2 length */

	/* Clear hash tables.
	 */
	W16(ep, sen_gaddr1, 0);
	W16(ep, sen_gaddr2, 0);
	W16(ep, sen_gaddr3, 0);
	W16(ep, sen_gaddr4, 0);
	W16(ep, sen_iaddr1, 0);
	W16(ep, sen_iaddr2, 0);
	W16(ep, sen_iaddr3, 0);
	W16(ep, sen_iaddr4, 0);

	/* set address
	 */
	mac = dev->dev_addr;
	paddrh = ((u16) mac[5] << 8) | mac[4];
	paddrm = ((u16) mac[3] << 8) | mac[2];
	paddrl = ((u16) mac[1] << 8) | mac[0];

	W16(ep, sen_paddrh, paddrh);
	W16(ep, sen_paddrm, paddrm);
	W16(ep, sen_paddrl, paddrl);

	W16(ep, sen_pper, 0);
	W16(ep, sen_taddrl, 0);
	W16(ep, sen_taddrm, 0);
	W16(ep, sen_taddrh, 0);

	fs_init_bds(dev);

	scc_cr_cmd(fep, CPM_CR_INIT_TRX);

	W16(sccp, scc_scce, 0xffff);

	/* Enable interrupts we wish to service.
	 */
	W16(sccp, scc_sccm, SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);

	/* Set GSMR_H to enable all normal operating modes.
	 * Set GSMR_L to enable Ethernet to MC68160.
	 */
	W32(sccp, scc_gsmrh, 0);
	W32(sccp, scc_gsmrl,
	    SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 | SCC_GSMRL_TPP_10 |
	    SCC_GSMRL_MODE_ENET);

	/* Set sync/delimiters.
	 */
	W16(sccp, scc_dsr, 0xd555);

	/* Set processing mode.  Use Ethernet CRC, catch broadcast, and
	 * start frame search 22 bit times after RENA.
	 */
	W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);

	/* Set full duplex mode if needed */
	if (fep->phydev->duplex)
		S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);

	S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
}