Skip to content

Instantly share code, notes, and snippets.

@rsaxvc
Created January 1, 2021 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsaxvc/e9c133ade59ee6804968330327701aa8 to your computer and use it in GitHub Desktop.
Save rsaxvc/e9c133ade59ee6804968330327701aa8 to your computer and use it in GitHub Desktop.
MIPS K0/K1 Kernel Register Printer
#include <unordered_set>
#include <cstdio>
//Represents bits from a register
#define reg_t unsigned
//Keep track of register contents seen already
std::unordered_set<reg_t> ks;
//Read either K0 or K1
static reg_t read_k( unsigned reg )
{
reg_t x;
#if __mips__
if( reg == 0 )
asm volatile ("move %0, $k0" : "=r" (x));
else
asm volatile ("move %0, $k1" : "=r" (x));
#else
#error "Incorrect CPU architecture"
#endif
return x;
}
//
int main( void )
{
unsigned reg = 1;
while(1)
{
reg ^= 1;
reg_t k = read_k( reg );
if(!ks.count(k))
{
std::printf("Found new k%u:0x%08x\n",reg,k);
ks.insert(k);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment