void memdebug(void) { ulong maxpa, maxpa1, maxpa2; maxpa = (nvramread(0x18)<<8)|nvramread(0x17); maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30); maxpa2 = (nvramread(0x16)<<8)|nvramread(0x15); print("maxpa = %luX -> %luX, maxpa1 = %luX maxpa2 = %luX\n", maxpa, MB+maxpa*KB, maxpa1, maxpa2); mapprint(&rmapram); mapprint(&rmapumb); mapprint(&rmapumbrw); mapprint(&rmapupa); }
void memdebug(void) { uintptr maxpa, maxpa1, maxpa2; if(!MEMDEBUG) return; maxpa = (nvramread(0x18)<<8)|nvramread(0x17); maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30); maxpa2 = (nvramread(0x16)<<8)|nvramread(0x15); print("maxpa = %#p -> %#p, maxpa1 = %#p maxpa2 = %#p\n", maxpa, MiB+maxpa*KiB, maxpa1, maxpa2); mapprint(&rmapram); mapprint(&rmapumb); mapprint(&rmapumbrw); mapprint(&rmapupa); }
/* * Give out otherwise-unused physical address space * for use in configuring devices. Note that unlike upamalloc * before it, upaalloc does not map the physical address * into virtual memory. Call vmap to do that. */ ulong upaalloc(int size, int align) { ulong a; a = mapalloc(&rmapupa, 0, size, align); if(a == 0){ print("out of physical address space allocating %d\n", size); mapprint(&rmapupa); } return a; }
/* * rlines -- display the last offset lines of the file. */ static void rlines(FILE *fp, const char *fn, off_t off, struct stat *sbp) { struct mapinfo map; off_t curoff, size; int i; if (!(size = sbp->st_size)) return; map.start = NULL; map.fd = fileno(fp); map.mapoff = map.maxoff = size; /* * Last char is special, ignore whether newline or not. Note that * size == 0 is dealt with above, and size == 1 sets curoff to -1. */ curoff = size - 2; while (curoff >= 0) { if (curoff < map.mapoff && maparound(&map, curoff) != 0) { ierr(fn); return; } for (i = curoff - map.mapoff; i >= 0; i--) if (map.start[i] == '\n' && --off == 0) break; /* `i' is either the map offset of a '\n', or -1. */ curoff = map.mapoff + i; if (i >= 0) break; } curoff++; if (mapprint(&map, curoff, size - curoff) != 0) { ierr(fn); exit(1); } /* Set the file pointer to reflect the length displayed. */ if (fseeko(fp, sbp->st_size, SEEK_SET) == -1) { ierr(fn); return; } if (map.start != NULL && munmap(map.start, map.maplen)) { ierr(fn); return; } }
/* * r_reg -- display a regular file in reverse order by line. */ static void r_reg(FILE *fp, enum STYLE style, off_t off, struct stat *sbp) { struct mapinfo map; off_t curoff, size, lineend; int i; if (!(size = sbp->st_size)) return; map.start = NULL; map.mapoff = map.maxoff = size; map.fd = fileno(fp); /* * Last char is special, ignore whether newline or not. Note that * size == 0 is dealt with above, and size == 1 sets curoff to -1. */ curoff = size - 2; lineend = size; while (curoff >= 0) { if (curoff < map.mapoff || curoff >= map.mapoff + (off_t)map.maplen) { if (maparound(&map, curoff) != 0) { ierr(); return; } } for (i = curoff - map.mapoff; i >= 0; i--) { if (style == RBYTES && --off == 0) break; if (map.start[i] == '\n') break; } /* `i' is either the map offset of a '\n', or -1. */ curoff = map.mapoff + i; if (i < 0) continue; /* Print the line and update offsets. */ if (mapprint(&map, curoff + 1, lineend - curoff - 1) != 0) { ierr(); return; } lineend = curoff + 1; curoff--; if (style == RLINES) off--; if (off == 0 && style != REVERSE) { /* Avoid printing anything below. */ curoff = 0; break; } } if (curoff < 0 && mapprint(&map, 0, lineend) != 0) { ierr(); return; } if (map.start != NULL && munmap(map.start, map.maplen)) ierr(); }