2024-04-02 04:29:15 +00:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
|
|
2024-03-28 23:32:13 +00:00
|
|
|
/* INCLUDES ==================================================================*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*/
|
|
|
|
|
//#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
/* printf()
|
|
|
|
|
*/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
/* bswap_32(x)
|
|
|
|
|
*/
|
|
|
|
|
#include <byteswap.h>
|
|
|
|
|
|
|
|
|
|
#include "bit.h"
|
|
|
|
|
|
|
|
|
|
/* MACROS ====================================================================*/
|
|
|
|
|
|
|
|
|
|
/* ENUMERATIONS ==============================================================*/
|
|
|
|
|
|
|
|
|
|
/* STRUCTS ===================================================================*/
|
|
|
|
|
|
|
|
|
|
/* GLOBAL VARIABLES ==========================================================*/
|
|
|
|
|
|
|
|
|
|
/* PROTOTYPES ================================================================*/
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS =================================================================*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print a unsigned char buffer
|
|
|
|
|
*/
|
|
|
|
|
void bit_print_buffer_u8(void *buf, unsigned long len, unsigned long width, int print_header)
|
|
|
|
|
{
|
|
|
|
|
unsigned long i, j, k, rows;
|
|
|
|
|
__u8 *ptr;
|
|
|
|
|
|
|
|
|
|
/* STEP 1: Verify Inputs */
|
|
|
|
|
if ( buf == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ( len == 0 )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ( width == 0 )
|
|
|
|
|
width = BIT_DEFAULT_WIDTH;
|
|
|
|
|
|
|
|
|
|
if ( width < BIT_MIN_WIDTH )
|
|
|
|
|
width = BIT_MIN_WIDTH;
|
|
|
|
|
|
|
|
|
|
ptr = (__u8*) buf;
|
|
|
|
|
|
|
|
|
|
/* Compute the number of rows to print */
|
|
|
|
|
rows = len / width;
|
|
|
|
|
if ( (len % width) > 0)
|
|
|
|
|
rows++;
|
|
|
|
|
|
|
|
|
|
/* Print index '0x0000: ' */
|
|
|
|
|
if (print_header) {
|
|
|
|
|
printf(" ");
|
|
|
|
|
for ( i = 0 ; i < width ; i++ )
|
|
|
|
|
printf("%02lu ", i);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
for ( i = 0 ; i < rows ; i++ ) {
|
|
|
|
|
printf("0x%08lx: ", i * width);
|
|
|
|
|
for ( j = 0 ; j < width ; j++ ) {
|
|
|
|
|
if (k >= len)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
printf("%02x ", ptr[i*width + j]);
|
|
|
|
|
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print a unsigned long buffer
|
|
|
|
|
*/
|
|
|
|
|
void bit_print_buffer_u32(void *buf, unsigned long len, int print_header, int byteswap)
|
|
|
|
|
{
|
|
|
|
|
unsigned long i, rows;
|
|
|
|
|
__u32 *ptr;
|
|
|
|
|
|
|
|
|
|
/* STEP 1: Verify Inputs */
|
|
|
|
|
if ( buf == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ( len == 0 )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ptr = (__u32*) buf;
|
|
|
|
|
|
|
|
|
|
/* Compute the number of rows to print */
|
|
|
|
|
rows = len;
|
|
|
|
|
|
|
|
|
|
/* Print index '0x0000: ' */
|
|
|
|
|
if (print_header) {
|
|
|
|
|
printf(" ");
|
|
|
|
|
for ( i = 0 ; i < sizeof(__u32) ; i++ )
|
|
|
|
|
printf("%02lu", i);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print data */
|
|
|
|
|
for ( i = 0 ; i < rows ; i++ ) {
|
|
|
|
|
if (byteswap)
|
|
|
|
|
printf("0x%08lx: %08x\n", i, bswap_32(ptr[i]));
|
|
|
|
|
else
|
|
|
|
|
printf("0x%08lx: %08x\n", i, ptr[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|