--- kernel/machdep/ppc/miniMonMachdep.c 2018/04/24 18:26:09 1.1 +++ kernel/machdep/ppc/miniMonMachdep.c 2018/04/24 18:33:06 1.1.1.2 @@ -35,6 +35,12 @@ */ #include + +#include + +#include +#include + #include @@ -58,23 +64,89 @@ static int xx(char c) return 0; } -static unsigned int -xtoi(char *str) +static void +xtoi(char *str, unsigned *nump) +{ + for (*nump = 0; *str && ishex(*str); str++) + *nump = 16*(*nump) + xx(*str); +} + +static unsigned found_valu = 0; +static unsigned prev_valu = 0; + +static boolean_t +miniMonFind(char *line) { - unsigned int num = 0; + static unsigned *start = (unsigned *)0; + static unsigned howmany = 0; + static unsigned prev_howmany = 0; + struct phys_entry *pp; + struct mapping *mp; + static unsigned found = 0; + extern unsigned *find_phys(); + extern vm_size_t mem_size; + extern vm_offset_t virtual_avail; + + /* Skip command name */ + while (*line && (*line != ' ' && *line != '\t')) + line++; + /* Skip whitespace */ + while (*line && (*line == ' ' || *line == '\t')) + line++; + + xtoi(line, &found_valu); - while (*str && ishex(*str)) { - num = (16 * num) + xx(*str); - str++; + /* Skip found_valu */ + while (*line && (*line != ' ' && *line != '\t')) + line++; + /* Skip whitespace */ + while (*line && (*line == ' ' || *line == '\t')) + line++; + + xtoi(line, &howmany); + + if (found_valu == 0 && howmany == 0) { + found_valu = prev_valu; + howmany = prev_howmany; + } else { + start = (unsigned *)0; + prev_valu = found_valu; + prev_howmany = howmany; + found = 0; + } + + if (howmany == 0) + howmany = (unsigned)(-1); + + for (; howmany--; start++) { + start = find_phys(found_valu, start, mem_size); + if (start == (unsigned *)0) + break; + if (start == &found_valu || start == &prev_valu) + continue; + safe_prf("P: %08x V:", start); + found++; + if (start < (unsigned *)virtual_avail) + safe_prf(" 0/%08x", start); + else if ((pp = pmap_find_physentry((vm_offset_t)start))) { + queue_iterate(&pp->phys_link, mp, struct mapping *, phys_link) + { + safe_prf(" %x/%08x ", mp->pmap->space, + (mp->vm_info.bits.page << PPC_PGSHIFT) | + ((unsigned)start & (PPC_PGBYTES - 1))); + } + } + safe_prf("\n"); } - return num; + safe_prf("%d found.\n", found); + return TRUE; } static boolean_t miniMonDump(char *line) { int addr, count; - static unsigned int *ptr = 0x10000; + static unsigned int *ptr = (unsigned int *)0x10000; static unsigned int old_count = 8; int text; @@ -86,20 +158,24 @@ miniMonDump(char *line) /* Skip whitespace */ while (*line && (*line == ' ' || *line == '\t')) line++; - addr = xtoi(line); + + xtoi(line, &addr); if (addr != 0) ptr = (unsigned int *)addr; + /* Skip address */ while (*line && (*line != ' ' && *line != '\t')) line++; /* Skip whitespace */ while (*line && (*line == ' ' || *line == '\t')) line++; + if (*line == 's') { - safe_prf(ptr); + safe_prf("%08x (as string) : %s\n", ptr, (char *) ptr); return TRUE; } - count = xtoi(line); + + xtoi(line, &count); if (count == 0) count = old_count; else @@ -122,6 +198,7 @@ miniMonCommand_t miniMonMDCommands[] = { {"dump", miniMonDump, "Dump memory"}, {"text", miniMonDump, "Dump text"}, + {"find", miniMonFind, "Find value in physical memory"}, {0,0,0} };