#include #include #include #include #include #include #if defined(__i386__) # define get_mtrr i386_get_mtrr # define MTRR_AFMT "%10llx" #elif defined(__x86_64__) # define get_mtrr x86_64_get_mtrr # define MTRR_AFMT "%16llx" #else # error no mtrr on this platform #endif #define NUM_MTRR 128 static const char * gettype(uint8_t type) { switch (type) { case MTRR_TYPE_UC: return "uc"; case MTRR_TYPE_WC: return "wc"; case MTRR_TYPE_UNDEF1: return "undef1"; case MTRR_TYPE_UNDEF2: return "undef2"; case MTRR_TYPE_WT: return "wt"; case MTRR_TYPE_WP: return "wp"; case MTRR_TYPE_WB: return "wb"; default: return "??"; } } int main(void) { struct mtrr *mtrrp; int i, n = NUM_MTRR, error; mtrrp = calloc(NUM_MTRR, sizeof(*mtrrp)); error = get_mtrr(mtrrp, &n); if (error) err(1, "get_mtrr"); printf("MTRR (%d)\n----\n\n", n); for (i = 0; i < n; i++) { printf("%02d: " MTRR_AFMT " - " MTRR_AFMT " type %s flags ", i, mtrrp[i].base, mtrrp[i].base + mtrrp[i].len - 1, gettype(mtrrp[i].type)); if (mtrrp[i].flags & MTRR_VALID) { printf("valid"); if (mtrrp[i].flags & MTRR_FIXED) printf(", fixed"); if (mtrrp[i].flags & MTRR_PRIVATE) printf(", private (pid=%d)", mtrrp[i].owner); } else printf("invalid"); printf("\n"); } }