int macdbg_dmphex( const char* buff, int len );
int macdbg_dmphex( const char* buff, int len )
{
int retval = 0;
int x, y, tot, lineoff;
const char* curr;
lineoff = 0;
curr = buff;
tot = 0;
char pre_16bytes[16]={0x00};
int dump_line = 0x00;
memset(pre_16bytes, 0xff, sizeof(pre_16bytes));
at_uart_log_string( "\nbuff = 0x%08x.\n", buff );
for( x = 0; len > x+16; ){
if( memcmp(pre_16bytes, curr, 16)==0x00 && curr!=buff ){
if( dump_line==0x00 ){
at_uart_log_string("0x%08x: ", lineoff);
at_uart_log_string("* \n");
dump_line = 0x01;
}
tot = tot + 16;
goto skip_next;
}
dump_line = 0x00;
at_uart_log_string("0x%08x: ", lineoff);
for( y = 0; y < 16; y++ ){
at_uart_log_string("%02x ", (unsigned char)*(curr + y));
}
at_uart_log_string(" |");
for( y = 0; y < 16; y++ ){
char c;
c = *(curr + y);
if( c > 31 && c < 127 ){
at_uart_log_string("%c", c);
}else{
at_uart_log_string("%c", '.');
}
tot++;
}
at_uart_log_string("|\n");
skip_next:
memcpy(pre_16bytes, curr, 16);
curr += 16;
x += 16;
lineoff+=16;
}
//do last line
//Ser_Printf("tot %d.\r\n", tot );
//Ser_Printf("len %d.\r\n", len );
if( tot < len ){
curr = (buff + tot);
at_uart_log_string("0x%08x: ", lineoff);
for( y = 0; y < (len - tot); y++ ){
at_uart_log_string("%02x ", (unsigned char)*(curr + y));
}
//padding with spaces
//Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
if( (len - tot) < 16 ){
for( y = 0; y < (32 - ((len - tot)*2)); y++ ){
at_uart_log_string(" ");
}
}
for( y = 0; y < 16-(len - tot); y++ ){
at_uart_log_string(" ");
}
at_uart_log_string(" |");
//Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
for( y = 0; y < (len - tot); y++ ){
char c;
c = *(curr + y);
if( c >31 && c < 127 ){
at_uart_log_string("%c", c);
}else{
at_uart_log_string("%c", '.');
}
}
}
at_uart_log_string("|\n");
return retval;
}
//寄存器名 汇编名 功能描述 调用返回后其值是否保持不变
//x0 zero 零寄存器 未定义
//x1 ra 返回地址 否
//x2 sp 栈指针 是
//x3 gp 全局指针 未定义
//x4 tp 线程指针 未定义
//x5 t0 临时寄存器,或者用作替代链接寄存器 否
//x6 t1 临时寄存器 否
//x7 t2 临时寄存器 否
//x8 s0/fp 该寄存器需要被调函数予以保存 是
// 或也可用作调用栈的帧指针
//x9 s1 该寄存器需要被调函数予以保存 是
//x10-x11 a0-a1 函数参数或返回值 否
//x12-x17 a2-a7 函数参数 否
//x18-x27 s2-s11 该寄存器需要被调函数予以保存 是
//x28-x31 t3-t6 临时寄存器 否
unsigned char g_debug_buff[512] = {0x00};
static inline int a_ll(volatile int *p)
{
int v;
__asm__ __volatile__ ("lw %0, (%1)" : "=&r"(v) : "r"(p));
//lw s4,8(s2)
return v;
}
//at_handle_HELLO_cmd_set
unsigned int get_sp( void );
unsigned int get_sp( void )
{
unsigned int sp_reg;
__asm__ __volatile__( "mv %0, sp" : "=r"(sp_reg) );
__asm__ __volatile__("nop");
__asm__ __volatile__("nop");
__asm__ __volatile__("nop");
//__asm__ __volatile__("l.li a0,0x1070634");
//__asm__ __volatile__("li a0,0x1070635");
//__asm__ __volatile__("lui a0,0x1234");
//memset( g_debug_buff, 0x00, sizeof(g_debug_buff) );
//at_uart_log_string( "g_debug_buff = %p\n", g_debug_buff );
//__asm__ __volatile__("mv t3, sp");
//__asm__ __volatile__("la sp, g_debug_buff");
__asm__ __volatile__("la t0, g_debug_buff");
__asm__ __volatile__("l.li t4,0x11223344");
//__asm__ __volatile__("sw t4, 0x00(t0)");
//at_uart_log_string( "g_debug_buffx = %#x\n", a_ll((volatile int *)g_debug_buff) );
return sp_reg;
}