代码拉取完成,页面将自动刷新
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <inttypes.h>
#include <sys/types.h>
#include <unistd.h>
#include "version.h"
#include "sysreg.h"
extern const char *program;
void aarch64_read_register(int fd, uint64_t *data, int size, uint32_t reg);
void aarch64_printf(int mode, uint64_t data, unsigned int highbit,
unsigned int lowbit);
/* support aarch64 */
void aarch64_read_register(int fd, uint64_t *data, int size, uint32_t reg)
{
uint64_t data_read;
if (pread(fd, &data_read, sizeof data_read, reg) != sizeof(data_read)) {
perror("rdasr:pread");
fprintf(stderr,
"This register is UNDEFINED or unreadable currently!\n");
exit(127);
}
*data = data_read;
}
void aarch64_printf(int mode, uint64_t data,unsigned int highbit,
unsigned int lowbit)
{
unsigned int bits;
int width;
char *pat;
bits = highbit-lowbit+1;
if (bits < 64) {
/* Show only part of register */
data >>= lowbit;
data &= (1ULL << bits)-1;
}
pat = NULL;
width = 1; /* Default */
switch(mode) {
case OF_HEX:
pat = "0x%*llx\n";
break;
case OF_CHX:
pat = "%*llX\n";
break;
case OF_DEC:
pat = "%*llu\n";
break;
case OF_OCT:
pat = "%*llo\n";
break;
case OF_HEX | OF_C:
pat = "0x%*llx\n";
break;
case OF_CHX | OF_C:
pat = "0x%*llX\n";
break;
case OF_OCT | OF_C:
pat = "0%*llo\n";
break;
case OF_DEC | OF_C:
case OF_DEC | OF_FILL:
case OF_DEC | OF_FILL | OF_C:
pat = "%*lluU\n";
break;
case OF_HEX | OF_FILL:
pat = "0x%0*llx\n";
width = (bits+3) / 4;
break;
case OF_CHX | OF_FILL:
pat = "%0*llX\n";
width = (bits+3) / 4;
break;
case OF_OCT | OF_FILL:
pat = "%0*llo\n";
width = (bits+2) / 3;
break;
case OF_HEX | OF_FILL | OF_C:
pat = "0x%0*llx\n";
width = (bits+3) / 4;
break;
case OF_CHX | OF_FILL | OF_C:
pat = "0x%0*llX\n";
width = (bits+3) / 4;
break;
case OF_OCT | OF_FILL | OF_C:
pat = "0%0*llo\n";
width = (bits+2) / 3;
break;
case OF_RAW:
case OF_RAW | OF_FILL:
fwrite(&data, sizeof(data), 1, stdout);
break;
case OF_RAW | OF_C:
case OF_RAW | OF_FILL | OF_C:
{
unsigned char *p = (unsigned char *)&data;
int i;
for ( i = 0 ; i < sizeof data ; i++ ) {
printf("%s0x%02x", i?",":"{", (unsigned int)(*p++));
}
printf("}\n");
}
break;
default:
fprintf(stderr,
"%s: Impossible case, line %d\n", program, __LINE__);
exit(127);
}
if (width < 1) {
width = 1;
}
if (pat) {
printf(pat, width, data);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。