FreeBSD/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
/*
 * Print a bitfield.  It's worth noting that the D compiler support for
 * bitfields is currently broken; printing "D`user_desc_t" (pulled in by the
 * various D provider files) will produce incorrect results compared to
 * "genunix`user_desc_t".
 */
Print a bitfield.  It's worth noting that the D compiler support for
bitfields is currently broken; printing "D`user_desc_t" (pulled in by the
various D provider files) will produce incorrect results compared to
"genunix`user_desc_t".
Print a bitfield . It ' s worth noting that the D compiler support for bitfields is currently broken ; printing " D ` user_desc_t " ( pulled in by the various D provider files ) will produce incorrect results compared to " genunix ` user_desc_t " .
static void
print_bitfield(dt_printarg_t *pap, ulong_t off, ctf_encoding_t *ep)
{
	FILE *fp = pap->pa_file;
	caddr_t addr = pap->pa_addr + off / NBBY;
	uint64_t mask = (1ULL << ep->cte_bits) - 1;
	uint64_t value = 0;
	size_t size = (ep->cte_bits + (NBBY - 1)) / NBBY;
	uint8_t *buf = (uint8_t *)&value;
	uint8_t shift;
#if BYTE_ORDER == _BIG_ENDIAN
	buf += sizeof (value) - size;
	off += ep->cte_bits;
#endif
	bcopy(addr, buf, size);
	shift = off % NBBY;
#if BYTE_ORDER == _BIG_ENDIAN
	shift = NBBY - shift;
#endif
	if (off % NBBY != 0)
		value >>= shift;
	value &= mask;
	(void) fprintf(fp, "%#llx", (u_longlong_t)value);
}
static void print_bitfield ( dt_printarg_t * pap , ulong_t off , ctf_encoding_t * ep ) { FILE * fp = pap -> pa_file ; caddr_t addr = pap -> pa_addr + off / NBBY ; uint64_t mask = ( 1ULL << ep -> cte_bits ) - 1 ; uint64_t value = 0 ; size_t size = ( ep -> cte_bits + ( NBBY - 1 ) ) / NBBY ; uint8_t * buf = ( uint8_t * ) & value ; uint8_t shift ; #if BYTE_ORDER == _BIG_ENDIAN buf += sizeof ( value ) - size ; off += ep -> cte_bits ; #endif bcopy ( addr , buf , size ) ; shift = off % NBBY ; #if BYTE_ORDER == _BIG_ENDIAN shift = NBBY - shift ; #endif if ( off % NBBY != 0 ) value >>= shift ; value &= mask ; ( void ) fprintf ( fp , " " , ( u_longlong_t ) value ) ; }
Print a bitfield.
Print a bitfield .
/*
	 * On big-endian machines, we need to adjust the buf pointer to refer
	 * to the lowest 'size' bytes in 'value', and we need to shift based on
	 * the offset from the end of the data, not the offset of the start.
	 */ /*
	 * Offsets are counted from opposite ends on little- and
	 * big-endian machines.
	 */ /*
	 * If the bits we want do not begin on a byte boundary, shift the data
	 * right so that the value is in the lowest 'cte_bits' of 'value'.
	 */