diff options
Diffstat (limited to 'hdata/test/hdata_to_dt.c')
-rw-r--r-- | hdata/test/hdata_to_dt.c | 115 |
1 files changed, 82 insertions, 33 deletions
diff --git a/hdata/test/hdata_to_dt.c b/hdata/test/hdata_to_dt.c index 38bf825..86fdf5c 100644 --- a/hdata/test/hdata_to_dt.c +++ b/hdata/test/hdata_to_dt.c @@ -46,16 +46,19 @@ static void *ntuple_addr(const struct spira_ntuple *n); #define __this_cpu ((struct cpu_thread *)NULL) #define zalloc(expr) calloc(1, (expr)) +unsigned long tb_hz = 512000000; + /* Don't include processor-specific stuff. */ #define __PROCESSOR_H #define PVR_TYPE(_pvr) _pvr -/* PVR definitions */ +/* PVR definitions - copied from skiboot include/processor.h */ #define PVR_TYPE_P7 0x003f #define PVR_TYPE_P7P 0x004a #define PVR_TYPE_P8E 0x004b #define PVR_TYPE_P8 0x004d #define PVR_TYPE_P8NVL 0x004c +#define PVR_TYPE_P9 0x004e #define SPR_PVR 0x11f /* RO: Processor version register */ @@ -82,7 +85,9 @@ struct dt_node *add_ics_node(void) #include <bitutils.h> /* Your pointers won't be correct, that's OK. */ -#define spira_check_ptr(ptr, file, line) ((ptr) != NULL) +#define spira_check_ptr spira_check_ptr + +static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line); #include "../cpu-common.c" #include "../fsp.c" @@ -107,13 +112,30 @@ char __rodata_start[1], __rodata_end[1]; enum proc_gen proc_gen = proc_gen_p7; +static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line) +{ + if (!ptr) + return false; + /* we fake the SPIRA pointer as it's relative to where it was loaded + * on real hardware */ + (void)file; + (void)line; + return true; +} + static void *ntuple_addr(const struct spira_ntuple *n) { uint64_t addr = be64_to_cpu(n->addr); if (n->addr == 0) return NULL; - assert(addr >= base_addr); - assert(addr < base_addr + spira_heap_size); + if (addr < base_addr) { + fprintf(stderr, "assert failed: addr >= base_addr (%"PRIu64" >= %"PRIu64")\n", addr, base_addr); + exit(EXIT_FAILURE); + } + if (addr >= base_addr + spira_heap_size) { + fprintf(stderr, "assert failed: addr not in spira_heap\n"); + exit(EXIT_FAILURE); + } return spira_heap + ((unsigned long)addr - base_addr); } @@ -125,43 +147,64 @@ static void undefined_bytes(void *p, size_t len) int main(int argc, char *argv[]) { - int fd, r; - bool verbose = false, quiet = false, tree_only = false; + int fd, r, i = 0, opt_count = 0; + bool verbose = false, quiet = false, tree_only = false, new_spira = false; - while (argv[1]) { - if (strcmp(argv[1], "-v") == 0) { + while (argv[++i]) { + if (strcmp(argv[i], "-v") == 0) { verbose = true; - argv++; - argc--; - } else if (strcmp(argv[1], "-q") == 0) { + opt_count++; + } else if (strcmp(argv[i], "-q") == 0) { quiet = true; - argv++; - argc--; - } else if (strcmp(argv[1], "-t") == 0) { + opt_count++; + } else if (strcmp(argv[i], "-t") == 0) { tree_only = true; - argv++; - argc--; - } else - break; + opt_count++; + } else if (strcmp(argv[i], "-s") == 0) { + new_spira = true; + opt_count++; + } } - if (argc != 3) - errx(1, "Usage: hdata [-v|-q|-t] <spira-dump> <heap-dump>"); + argc -= opt_count; + argv += opt_count; + if (argc != 3) { + errx(1, "Usage:\n" + " hdata [-v|-q|-t] <spira-dump> <heap-dump>\n" + " hdata -s [-v|-q|-t] <spirah-dump> <spiras-dump>\n"); + } /* Copy in spira dump (assumes little has changed!). */ - fd = open(argv[1], O_RDONLY); - if (fd < 0) - err(1, "opening %s", argv[1]); - r = read(fd, &spira, sizeof(spira)); - if (r < sizeof(spira.hdr)) - err(1, "reading %s gave %i", argv[1], r); - if (verbose) - printf("verbose: read spira %u bytes\n", r); - close(fd); - - undefined_bytes((void *)&spira + r, sizeof(spira) - r); + if (new_spira) { + fd = open(argv[1], O_RDONLY); + if (fd < 0) + err(1, "opening %s", argv[1]); + r = read(fd, &spirah, sizeof(spirah)); + if (r < sizeof(spirah.hdr)) + err(1, "reading %s gave %i", argv[1], r); + if (verbose) + printf("verbose: read spirah %u bytes\n", r); + close(fd); + + undefined_bytes((void *)&spirah + r, sizeof(spirah) - r); + + base_addr = be64_to_cpu(spirah.ntuples.hs_data_area.addr); + } else { + fd = open(argv[1], O_RDONLY); + if (fd < 0) + err(1, "opening %s", argv[1]); + r = read(fd, &spira, sizeof(spira)); + if (r < sizeof(spira.hdr)) + err(1, "reading %s gave %i", argv[1], r); + if (verbose) + printf("verbose: read spira %u bytes\n", r); + close(fd); + + undefined_bytes((void *)&spira + r, sizeof(spira) - r); + + base_addr = be64_to_cpu(spira.ntuples.heap.addr); + } - base_addr = be64_to_cpu(spira.ntuples.heap.addr); if (!base_addr) errx(1, "Invalid base addr"); if (verbose) @@ -181,12 +224,18 @@ int main(int argc, char *argv[]) spira_heap_size, spira_heap); close(fd); + if (new_spira) + spiras = (struct spiras *)spira_heap; + if (quiet) { fclose(stdout); fclose(stderr); } - parse_hdat(false, 0); + if(parse_hdat(false, 0) < 0) { + fprintf(stderr, "FATAL ERROR parsing HDAT\n"); + exit(EXIT_FAILURE); + } if (!quiet) dump_dt(dt_root, 0, !tree_only); |