Created
January 1, 2021 06:01
-
-
Save rsaxvc/e9c133ade59ee6804968330327701aa8 to your computer and use it in GitHub Desktop.
MIPS K0/K1 Kernel Register Printer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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