Exemplo n.º 1
0
static void CopyLineQwordsSwap(void * dst, const void * src, u32 qwords)
{
#ifdef FAST_TMEM_COPY
	u32* src32 = (u32*)src;
	u32* dst32 = (u32*)dst;

	DAEDALUS_ASSERT( ((uintptr_t)src32&0x3 )==0, "src is not aligned!");

	while(qwords--)
	{
		dst32[1]  = BSWAP32(src32[0]);
		dst32[0]  = BSWAP32(src32[1]);
		dst32 += 2;
		src32 += 2;
	}
#else
	u8* src8 = (u8*)src;
	u8* dst8 = (u8*)dst;
	u32 bytes = qwords * 8;
	while(bytes--)
	{
		*(u8*)((uintptr_t)dst8++ ^ 0x4)  = *(u8*)((uintptr_t)src8++ ^ U8_TWIDDLE);
	}
#endif
}
Exemplo n.º 2
0
int i4btrace_open(wtap *wth, int *err, gchar **err_info)
{
	int bytes_read;
	i4b_trace_hdr_t hdr;
	gboolean byte_swapped = FALSE;
	i4btrace_t *i4btrace;

	/* I4B trace files have no magic in the header... Sigh */
	errno = WTAP_ERR_CANT_READ;
	bytes_read = file_read(&hdr, sizeof(hdr), wth->fh);
	if (bytes_read != sizeof(hdr)) {
		*err = file_error(wth->fh, err_info);
		if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
			return -1;
		return 0;
	}

	/* Silly heuristic... */
	if (!I4B_HDR_IS_OK(hdr)) {
		/*
		 * OK, try byte-swapping the header fields.
		 */
		hdr.length = BSWAP32(hdr.length);
		hdr.unit = BSWAP32(hdr.unit);
		hdr.type = BSWAP32(hdr.type);
		hdr.dir = BSWAP32(hdr.dir);
		hdr.trunc = BSWAP32(hdr.trunc);
		if (!I4B_HDR_IS_OK(hdr)) {
			/*
			 * It doesn't look valid in either byte order.
			 */
			return 0;
		}

		/*
		 * It looks valid byte-swapped, so assume it's a
		 * trace written in the opposite byte order.
		 */
		byte_swapped = TRUE;
	}

	if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
		return -1;

	/* Get capture start time */

	wth->file_type = WTAP_FILE_I4BTRACE;
	i4btrace = (i4btrace_t *)g_malloc(sizeof(i4btrace_t));
	wth->priv = (void *)i4btrace;
	wth->subtype_read = i4btrace_read;
	wth->subtype_seek_read = i4btrace_seek_read;
	wth->snapshot_length = 0;	/* not known */

	i4btrace->byte_swapped = byte_swapped;

	wth->file_encap = WTAP_ENCAP_ISDN;
	wth->tsprecision = WTAP_FILE_TSPREC_USEC;

	return 1;
}
Exemplo n.º 3
0
/** Check if all GRFs in the GRF config from a savegame can be loaded.
 * @param grfconfig GrfConfig to check
 * @return will return any of the following 3 values:<br>
 * <ul>
 * <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded
 * <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
 *     compatible GRF with the same grfid was found and used instead
 * <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
 * </ul> */
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
{
	GRFListCompatibility res = GLC_ALL_GOOD;

	for (GRFConfig *c = grfconfig; c != NULL; c = c->next) {
		const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
		if (f == NULL) {
			char buf[256];

			/* If we have not found the exactly matching GRF try to find one with the
			 * same grfid, as it most likely is compatible */
			f = FindGRFConfig(c->ident.grfid);
			if (f != NULL) {
				md5sumToString(buf, lastof(buf), c->ident.md5sum);
				DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
				if (!HasBit(c->flags, GCF_COMPATIBLE)) {
					/* Preserve original_md5sum after it has been assigned */
					SetBit(c->flags, GCF_COMPATIBLE);
					memcpy(c->original_md5sum, c->ident.md5sum, sizeof(c->original_md5sum));
				}

				/* Non-found has precedence over compatibility load */
				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
				goto compatible_grf;
			}

			/* No compatible grf was found, mark it as disabled */
			md5sumToString(buf, lastof(buf), c->ident.md5sum);
			DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->filename, buf);

			c->status = GCS_NOT_FOUND;
			res = GLC_NOT_FOUND;
		} else {
compatible_grf:
			DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
			/* The filename could be the filename as in the savegame. As we need
			 * to load the GRF here, we need the correct filename, so overwrite that
			 * in any case and set the name and info when it is not set already.
			 * When the GCF_COPY flag is set, it is certain that the filename is
			 * already a local one, so there is no need to replace it. */
			if (!HasBit(c->flags, GCF_COPY)) {
				free(c->filename);
				c->filename = strdup(f->filename);
				memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
				if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
				if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
				c->error = NULL;
			}
		}
	}

	return res;
}
Exemplo n.º 4
0
static inline void CopyLine(void * dst, const void * src, u32 bytes)
{
#ifdef FAST_TMEM_COPY
	u32* src32 = (u32*)src;
	u32* dst32 = (u32*)dst;

	DAEDALUS_ASSERT((bytes&0x3)==0, "CopyLine: Remaning bytes! (%d)",bytes);

	u32 size32 = bytes >> 2;
	u32 src_alignment = (uintptr_t)src32&0x3;

	if(src_alignment == 0)
	{
		while (size32--)
		{
			*dst32++ = BSWAP32(src32[0]);
			src32++;
		}
	}
	else
	{
		// Zelda and DK64 have unaligned copies. so let's optimize 'em
		src32 = (u32*)((uintptr_t)src & ~0x3);
		u32 src_tmp = *src32++;
		u32 dst_tmp = 0;

		// calculate offset 3..1..2
		u32 offset = 4-src_alignment;
		u32 lshift = src_alignment<<3;
		u32 rshift = offset<<3;

		while(size32--)
		{
			dst_tmp = src_tmp << lshift;
			src_tmp = *src32++;
			dst_tmp|= src_tmp >> rshift;
			*dst32++ = BSWAP32(dst_tmp);
		}
		src32 -= offset;
	}
#else
	u8* src8 = (u8*)src;
	u8* dst8 = (u8*)dst;
	while(bytes--)
	{
		*dst8++ = *(u8*)((uintptr_t)src8++ ^ U8_TWIDDLE);
	}
#endif
}
Exemplo n.º 5
0
void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& icon) {


	Ref<ImageTexture> it = memnew( ImageTexture );
	int size=512;

	Vector<uint8_t> data;

	data.resize(8);
	data[0]='i';
	data[1]='c';
	data[2]='n';
	data[3]='s';

	const char *name[]={"ic09","ic08","ic07","icp6","icp5","icp4"};
	int index=0;

	while(size>=16) {

		Image copy = p_icon;
		copy.convert(Image::FORMAT_RGBA);
		copy.resize(size,size);
		it->create_from_image(copy);
		String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/icon.png";
		ResourceSaver::save(path,it);

		FileAccess *f = FileAccess::open(path,FileAccess::READ);
		ERR_FAIL_COND(!f);

		int ofs = data.size();
		uint32_t len = f->get_len();
		data.resize(data.size()+len+8);
		f->get_buffer(&data[ofs+8],len);
		memdelete(f);
		len+=8;
		len=BSWAP32(len);
		copymem(&data[ofs],name[index],4);
		encode_uint32(len,&data[ofs+4]);
		index++;
		size/=2;
	}

	uint32_t total_len = data.size();
	total_len = BSWAP32(total_len);
	encode_uint32(total_len,&data[4]);

	icon=data;
}
Exemplo n.º 6
0
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHECK_NEWGRFS)
{
	if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET;

	uint grf_count = p->Recv_uint8();
	NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;

	/* Check all GRFs */
	for (; grf_count > 0; grf_count--) {
		GRFIdentifier c;
		this->ReceiveGRFIdentifier(p, &c);

		/* Check whether we know this GRF */
		const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
		if (f == NULL) {
			/* We do not know this GRF, bail out of initialization */
			char buf[sizeof(c.md5sum) * 2 + 1];
			md5sumToString(buf, lastof(buf), c.md5sum);
			DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf);
			ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
		}
	}

	if (ret == NETWORK_RECV_STATUS_OKAY) {
		/* Start receiving the map */
		return SendNewGRFsOk();
	}

	/* NewGRF mismatch, bail out */
	_switch_mode_errorstr = STR_NETWORK_ERROR_NEWGRF_MISMATCH;
	return ret;
}
Exemplo n.º 7
0
static void
global_user_list_cb (USER * user, struct guldata *data)
{
    ASSERT (validate_user (user));
    ASSERT (data != 0);
    if (data->flags)
    {
	/* selectively display users based on user level/muzzle/cloak */
	if (!
	    (((data->flags & ON_GFLAG_ADMIN) && user->level == LEVEL_ADMIN)
	     || ((data->flags & ON_GFLAG_ELITE) && user->level == LEVEL_ELITE)
	     || ((data->flags & ON_GFLAG_MODERATOR)
		 && user->level == LEVEL_MODERATOR)
	     || ((data->flags & ON_GFLAG_USERS) && user->level == LEVEL_USER)
	     || ((data->flags & ON_GFLAG_LEECH) && user->level == LEVEL_LEECH)
	     || ((data->flags & ON_GFLAG_MUZZLED) && user->muzzled)
	     || ((data->flags & ON_GFLAG_CLOAKED) && user->cloaked)
	     || ((data->flags & ON_GFLAG_USERIP) && (user->ip & data->mask) == (data->ip & data->mask))))
	    return;
    }
    if (data->server && *data->server != '*' &&
	strcasecmp (data->server, user->server) != 0)
	return;			/* no match */
    send_cmd (data->con, MSG_SERVER_GLOBAL_USER_LIST, "%s %s", user->nick,
	      my_ntoa (BSWAP32 (user->ip)));
}
Exemplo n.º 8
0
int DumpScan::process(DumpDataList::iterator startDump, unsigned long startByte)
{
	unsigned long min = m_address - m_maxOffset;
	unsigned long max = m_address;
	if (m_maxOffset > m_address)
		min = 0;
	m_counter = 0;
	for (DumpDataList::iterator it = startDump; it!= m_dumps.end(); ++it)
	{
		char *data = (*it)->data;
		CHECK_CANCEL;
		for (unsigned long i=startByte; i<((*it)->header.end - (*it)->header.begin)-3; ++i)
		{
			unsigned long currentAddress = BSWAP32(*(unsigned long*)(&data[i]));
			CHECK_CANCEL;
			if ( currentAddress >= min && currentAddress <= max) //we want this
			{
				PointerOffsets po = m_offsets;
				po.push_front(m_address - currentAddress);
				m_results.push_back(ScanResult(i+(*it)->header.begin, po));
				if (++m_counter >= m_maxResults)
				{
					m_counter = 0;
					m_currentDump = it;
					m_currentByte = i+1;
					return DUMP_SCAN_STATUS_CONTINUE;
				}
			}
		}
	}
	return DUMP_SCAN_STATUS_DONE;
}
Exemplo n.º 9
0
void cmd_page_erase()
{
	int adrs=BSWAP32(PacketFromPC.adrs);
	if( check_flash_adrs(adrs)) {
		FLASH_ErasePage(adrs);
	}
}
Exemplo n.º 10
0
/********************************************************************
 *	FLASHのページ単位書き込み.	(引数は書き込みadrsとsize)
 ********************************************************************
  STM32では、word単位で書き込みが可能. (flush動作不要)

  他のマイコン(LPCなど)では、
  	実際にはRAM上のページバッファにword単位でためておいて、
  	最後にsize=0を指定してページバッファを一発書き込みする実装になることもある.
 

 */
void cmd_page_write()
{
	int  *p = PacketFromPC.data;
	int   i;
	int   size = BSWAP16(PacketFromPC.size);
	int	   adr = BSWAP32(PacketFromPC.adrs);

	// ここでbyte数をword数に変換している.
	size = (size+3) >> 2;		// size は4byte単位に限る.

//#if	defined(LPC1343)||defined(LPC2388)
	if(size==0) {				// size が 0 のときは書き込みflush動作をする.
		FLASH_ProgramPage(adr);	// これはSTM32に限り不要(ダミー関数)
		return ;
	}
//#endif

	for(i=0; i<size; i++) {
		if( check_flash_adrs(adr) ) {
			FLASH_ProgramWord(adr, *p);	// STM32では直接FLUSHに書く.
		}								// 他のマイコンでは、ページバッファに記録.
		p++;
		adr+=4;
	}
}
Exemplo n.º 11
0
/********************************************************************
 *	接続テストの返答
 ********************************************************************
 */
void cmd_echo(void)
{
	int *fl_stat = (int*) &PacketToPC.rawint[2];
	PacketToPC.raw[1]=DEVID;				// PIC25/14K
	PacketToPC.raw[2]=VER_L;				// version.L
	PacketToPC.raw[3]=VER_H;				// version.H
	PacketToPC.raw[4]=DEV_LOADER;			// bootloader
	PacketToPC.raw[5]=PacketFromPC.raw[1];	// ECHOBACK

	fl_stat[0] = BSWAP32(FLASH_END_ADR);
	fl_stat[1] = BSWAP32(search_flash_end(FLASH_END_ADR));
	fl_stat[2] = BSWAP32(total_errs);

	total_errs=0;
	ToPcRdy = 1;
}
Exemplo n.º 12
0
void cmd_page_write()
{
	int   i;
	int   size = BSWAP16(PacketFromPC.size);
	int	   adr = BSWAP32(PacketFromPC.adrs);
	int     *p = 		 PacketFromPC.data;
	size = (size+3) >> 2;

#if	defined(LPC1343)||defined(LPC2388)
	if(size==0) {
		FLASH_ProgramPage(adr);
		return ;
	}
#endif
	if(	size <= (48) ) {
		total_errs += flash_write(adr,size,p);
		return;
	}

	while(size>0) {
		int buf[64/4];

		int len = size;
		if( len >= BLK_SIZE ) {len = BLK_SIZE;}

		USBgetpacket((uchar*)buf,len);

		total_errs += flash_write(adr, len ,buf);
		size -= len;
		adr  += len;
	}
}
Exemplo n.º 13
0
void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {

	Ref<ImageTexture> it = memnew(ImageTexture);
	int size = 512;

	Vector<uint8_t> data;

	data.resize(8);
	data[0] = 'i';
	data[1] = 'c';
	data[2] = 'n';
	data[3] = 's';

	const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
	int index = 0;

	while (size >= 16) {

		Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
		copy->convert(Image::FORMAT_RGBA8);
		copy->resize(size, size);
		it->create_from_image(copy);
		String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
		ResourceSaver::save(path, it);

		FileAccess *f = FileAccess::open(path, FileAccess::READ);
		ERR_FAIL_COND(!f);

		int ofs = data.size();
		uint32_t len = f->get_len();
		data.resize(data.size() + len + 8);
		f->get_buffer(&data[ofs + 8], len);
		memdelete(f);
		len += 8;
		len = BSWAP32(len);
		copymem(&data[ofs], name[index], 4);
		encode_uint32(len, &data[ofs + 4]);
		index++;
		size /= 2;
	}

	uint32_t total_len = data.size();
	total_len = BSWAP32(total_len);
	encode_uint32(total_len, &data[4]);

	p_data = data;
}
static void
byteswap_msg (ossmix_commad_packet_t * msg)
{
  BSWAP32 (msg->cmd);
  BSWAP32 (msg->p1);
  BSWAP32 (msg->p2);
  BSWAP32 (msg->p3);
  BSWAP32 (msg->p4);
  BSWAP32 (msg->p5);
  BSWAP32 (msg->ack_rq);
  BSWAP32 (msg->unsolicited);
  BSWAP32 (msg->payload_size);
}
Exemplo n.º 15
0
static void
try_connect (server_auth_t * auth)
{
    int     f;
    CONNECTION *cli;
    unsigned int ip;

    /* attempt a connection.  we do this nonblocking so that the server
       doesn't halt if it takes a long time to connect */
    f = make_tcp_connection (auth->name, auth->port, &ip);
    if (f == -1)
	return;

    cli = new_connection ();
    if (!cli)
	goto error;
    cli->fd = f;
    cli->host = STRDUP (auth->alias ? auth->alias : auth->name);
    if (!cli->host)
    {
	OUTOFMEMORY ("try_connect");
	goto error;
    }
    cli->server_login = 1;
    if ((cli->opt.auth = CALLOC (1, sizeof (AUTH))) == 0)
    {
	OUTOFMEMORY ("try_connect");
	goto error;
    }
    cli->opt.auth->nonce = generate_nonce ();
    if (!cli->opt.auth->nonce)
    {
	log_message ("try_connect: could not generate nonce, closing connection");
	goto error;
    }
    cli->ip = BSWAP32 (ip);
    cli->port = auth->port;

    if (add_client (cli, 1/* server connection */))
	goto error;

    return;
  error:
    log_message ("try_connect: closing connection");
    if (cli)
    {
	CLOSE (cli->fd);
	if (cli->host)
	    FREE (cli->host);
	if (cli->opt.auth)
	{
	    if (cli->opt.auth->nonce)
		FREE (cli->opt.auth->nonce);
	    FREE (cli->opt.auth);
	}
	FREE (cli);
    }
}
Exemplo n.º 16
0
void StreamPeer::put_32(int32_t p_val) {

	if (big_endian) {
		p_val = BSWAP32(p_val);
	}
	uint8_t buf[4];
	encode_uint32(p_val, buf);
	put_data(buf, 4);
}
Exemplo n.º 17
0
int32_t StreamPeer::get_32() {

	uint8_t buf[4];
	get_data(buf, 4);
	uint32_t r = decode_uint32(buf);
	if (big_endian) {
		r = BSWAP32(r);
	}
	return r;
}
Exemplo n.º 18
0
static inline void CopyLineSwap(void * dst, const void * src, u32 bytes)
{
	u32* src32 = (u32*)src;
	u32* dst32 = (u32*)dst;

#ifdef FAST_TMEM_COPY
	DAEDALUS_ASSERT((bytes&0x7)==0, "CopyLineSwap: Remaning bytes! (%d)",bytes);

	if( ((uintptr_t)src32&0x3 )==0)
	{
		u32 size64 = bytes >> 3;

		while (size64--)
		{
			dst32[0] = BSWAP32(src32[1]);
			dst32[1] = BSWAP32(src32[0]);
			dst32 += 2;
			src32 += 2;
		}
	}
Exemplo n.º 19
0
float StreamPeer::get_float() {

	uint8_t buf[4];
	get_data(buf, 4);

	if (big_endian) {
		uint32_t *p32 = (uint32_t *)buf;
		*p32 = BSWAP32(*p32);
	}

	return decode_float(buf);
}
Exemplo n.º 20
0
/********************************************************************
 *	データ引取りモードの設定
 ********************************************************************
 */
void cmd_set_mode(void)
{
	poll_mode = BSWAP16( PacketFromPC.size );
	poll_addr = (uchar  *) BSWAP32( PacketFromPC.adrs );

	if(	poll_mode == POLL_ANALOG) {
//		mInitPOT();
//		ADCON0bits.GO = 1;              // Start AD conversion
	}

	make_report();
}
Exemplo n.º 21
0
void StreamPeer::put_float(float p_val) {

	uint8_t buf[4];

	encode_float(p_val, buf);
	if (big_endian) {
		uint32_t *p32 = (uint32_t *)buf;
		*p32 = BSWAP32(*p32);
	}

	put_data(buf, 4);
}
Exemplo n.º 22
0
/********************************************************************
 *	モニタコマンド受信と実行.
 ********************************************************************
 */
void ProcessIO(void)
{
	// 返答パケットが空であること、かつ、
	// 処理対象の受信データがある.
	{	//if((ToPcRdy == 0)) {
		//受信データがあれば、受信データを受け取る.
		PacketToPC.raw[0]=Cmd0;		// CMD ECHOBACK

#if	APPLICATION_MODE
#if	PICAVR_WRITER
		//コマンドに対応する処理を呼び出す.
			 if(Cmd0 >= HIDASP_PAGE_TX)  {cmd_avrspx();}	// AVRライターコマンド.
		else 
#endif
			 if(Cmd0 >= PICSPX_SETADRS24){cmd_picspx();}	// PICライターコマンド.
		else 
#endif

		switch(Cmd0) {
		 case HIDASP_PEEK: 		{cmd_peek();break;}	// メモリー読み出し.
		 case HIDASP_POKE: 		{cmd_poke();break;}	// メモリー書き込み.
		 case HIDASP_JMP: 		{cmd_exec(
		 						BSWAP32(PacketFromPC.adrs),BSWAP16(PacketFromPC.size)
		 			);
		 			break;}	// 実行.
		 case HIDASP_PAGE_ERASE:{cmd_page_erase();break;}	//Flash消去.
		 case HIDASP_PAGE_WRITE:{cmd_page_write();break;}	//Flash書込.
		 case HIDASP_FLASH_LOCK:{cmd_flash_lock();break;}	//FlashLock.
		 case HIDASP_SET_MODE:  {cmd_set_mode();break;}
		 case HIDASP_SAMPLING: 	{cmd_sampling();break;}
		 case HIDASP_TEST: 		{cmd_echo();break;}			// 接続テスト.

#if	APPLICATION_MODE
		 case HIDASP_GET_STRING:{cmd_get_string();break;}
		 case HIDASP_USER_CMD:  {cmd_user_cmd();break;}
#endif
		 default: break;
		}
	}

	// 必要なら、返答パケットをインタラプト転送(EP1)でホストPCに返却する.
	if( ToPcRdy ) {
		USBputpacket(PacketToPC.raw,PACKET_SIZE);
		ToPcRdy = 0;

		if(poll_mode!=0) {
			if(mHIDRxIsBusy()) {	//コマンドが来ない限り送り続ける.
				make_report();
			}
		}
	}
}
static void
bswap_enuminfo (void *data, int len)
{
  oss_mixer_enuminfo *ei = (oss_mixer_enuminfo *) data;

  int i;

  if (len != sizeof (*ei))
    {
      fprintf (stderr, "bswap_enuminfo: Bad size (%d/%lu)\n", len,
	       (unsigned long)sizeof (*ei));
      exit (EXIT_FAILURE);
    }

  BSWAP32 (ei->dev);
  BSWAP32 (ei->ctrl);
  BSWAP32 (ei->nvalues);
  BSWAP32 (ei->version);

  for (i = 0; i < OSS_ENUM_MAXVALUE; i++)
    BSWAP32 (ei->strindex[i]);
}
Exemplo n.º 24
0
static void
adjust_header(wtap *wth, struct pcaprec_hdr *hdr)
{
	guint32 temp;
	libpcap_t *libpcap;

	libpcap = (libpcap_t *)wth->priv;
	if (libpcap->byte_swapped) {
		/* Byte-swap the record header fields. */
		hdr->ts_sec = BSWAP32(hdr->ts_sec);
		hdr->ts_usec = BSWAP32(hdr->ts_usec);
		hdr->incl_len = BSWAP32(hdr->incl_len);
		hdr->orig_len = BSWAP32(hdr->orig_len);
	}

	/* Swap the "incl_len" and "orig_len" fields, if necessary. */
	switch (libpcap->lengths_swapped) {

	case NOT_SWAPPED:
		break;

	case MAYBE_SWAPPED:
		if (hdr->incl_len <= hdr->orig_len) {
			/*
			 * The captured length is <= the actual length,
			 * so presumably they weren't swapped.
			 */
			break;
		}
		/* FALLTHROUGH */

	case SWAPPED:
		temp = hdr->orig_len;
		hdr->orig_len = hdr->incl_len;
		hdr->incl_len = temp;
		break;
	}
}
Exemplo n.º 25
0
static int ieee1394_GetFetchAgentState(struct SBP2Device *dev){
	unsigned long int FetchAgentState;
	int result;

	if((result=iLinkTrRead(dev->trContext, dev->CommandBlockAgent_high, dev->CommandBlockAgent_low, &FetchAgentState, 4))<0){
		XPRINTF("Error reading the Fetch Agent's AGENT_STATE register @ 0x%08lx %08lx. Code: %d.\n", dev->CommandBlockAgent_high, dev->CommandBlockAgent_low, result);
		return -1;
	}
	else{
		FetchAgentState=BSWAP32(FetchAgentState);
		XPRINTF("Fetch Agent state: %lu.\n", FetchAgentState);
		return FetchAgentState;
	}
}
Exemplo n.º 26
0
/********************************************************************
 *	メモリー読み出し
 ********************************************************************
 */
void cmd_peek(void)
{
	Packet *t = &PacketFromPC;
	int  size = BSWAP16(t->size);
	int  adrs = BSWAP32(t->adrs);
	int    i,subcmd;
	uchar  *pb;
	ushort *ph;
	uint   *pw;

	uchar  *tb;
	ushort *th;
	uint   *tw;

	subcmd = t->subcmd;

	if(size > PACKET_SIZE) {
		cmd_peek_large_block(adrs,size);
		return;
	}

	switch(subcmd) {
	default:
	case MEM_BYTE:
		pb = (uchar *)adrs;
		tb = (uchar *)PacketToPC.raw;
		for(i=0; i<size; i++) {
			*tb++ = *pb++;
		}
		break;
	case MEM_HALF:
		ph = (ushort *)adrs;
		th = (ushort *)PacketToPC.rawint;
		for(i=0; i<size; i+=2) {
			*th++ = *ph++;
		}
		break;
	case MEM_WORD:
		pw = (uint *)adrs;
		tw = (uint *)PacketToPC.rawint;
		for(i=0; i<size; i+=4) {
			*tw++ = *pw++;
		}
		break;
	}

	USBputpacket(PacketToPC.raw,PACKET_SIZE);

//	ToPcRdy = 1;
}
static void
bswap_int_array (void *data, int len)
{
  int *arr = (int *) data;
  int i;

  if (len % sizeof (int) != 0)
    {
      fprintf (stderr, "bswap_int_array: Bad size %d\n", len);
      exit (EXIT_FAILURE);
    }

  for (i = 0; i < len / sizeof (int); i++)
    BSWAP32 (arr[i]);
}
Exemplo n.º 28
0
static void
i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr)
{
	i4btrace_t *i4btrace = (i4btrace_t *)wth->priv;

	if (i4btrace->byte_swapped) {
		/*
		 * Byte-swap the header.
		 */
		hdr->length = BSWAP32(hdr->length);
		hdr->unit = BSWAP32(hdr->unit);
		hdr->type = BSWAP32(hdr->type);
		hdr->dir = BSWAP32(hdr->dir);
		hdr->trunc = BSWAP32(hdr->trunc);
		hdr->count = BSWAP32(hdr->count);
		hdr->ts_sec = BSWAP32(hdr->ts_sec);
		hdr->ts_usec = BSWAP32(hdr->ts_usec);
	}
}
Exemplo n.º 29
0
void EMU_FASTCALL GX_Fifo_Write32(u32 addr, u32 data) {
    static u8 cmd = FIFO_GET8(0);
    
    *(u32*)(gp::g_fifo_buffer + gp::g_fifo_write_ptr) = BSWAP32(data);
    gp::g_fifo_write_ptr += 4;
    
    /*if ((data == 0x45000002) && ((cmd & 0xf8) == 0x60)) {

        while (!gp::g_frame_finished) {
        }
        gp::g_frame_finished = 0;
        
        GX_PE_FINISH = 1;
        PE_Update();
    }*/
    if (!common::g_config->enable_multicore()) {
        gp::Fifo_DecodeCommand();
    }
}
Exemplo n.º 30
0
/********************************************************************
 *	メモリー書き込み
 ********************************************************************
 */
void cmd_poke(void)
{
	Packet *t = &PacketFromPC;
	int  size = BSWAP16(t->size);
	int  adrs = BSWAP32(t->adrs);
	int  i,subcmd;

	uchar  *pb;
	ushort *ph;
	uint   *pw;

	uchar  *sb;
	ushort *sh;
	uint   *sw;

	subcmd = t->subcmd;

	switch(subcmd) {
	default:
	case MEM_BYTE:
		pb = (uchar *)adrs;
		sb = (uchar *)t->data;
		for(i=0; i<size; i++) {
			*pb++ = *sb++;
		}
		break;
	case MEM_HALF:
		ph = (ushort *)adrs;
		sh = (ushort *)t->data;
		for(i=0; i<size; i+=2) {
			*ph++ = *sh++;
		}
		break;
	case MEM_WORD:
		pw = (uint *)adrs;
		sw = (uint *)t->data;
		for(i=0; i<size; i+=4) {
			*pw++ = *sw++;
		}
		break;
	}
}