Skip to content

Instantly share code, notes, and snippets.

@cyyself
Last active July 15, 2024 17:11
Show Gist options
  • Save cyyself/295113206e0fc6a26860a4b6847cbe16 to your computer and use it in GitHub Desktop.
Save cyyself/295113206e0fc6a26860a4b6847cbe16 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdint>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
void dump_regs(volatile void *regs) {
for (int i=0;i<122;i++) {
uint32_t ctl_reg = *(uint32_t *)(regs + 0x1000 * i);
uint32_t io_reg = *(uint32_t *)(regs + 0x1000 * i + 0x4);
bool oe = ctl_reg >> 9 & 1;
printf("%02d: CTL: 0x%08x, IO: 0x%08x, oe=%d\n", i, ctl_reg, io_reg, oe);
}
}
int main() {
int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
volatile void *regs = mmap(0, 0x300000, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, 0x1000000);
dump_regs(regs);
return 0;
}
@cyyself
Copy link
Author

cyyself commented Jul 15, 2024

#include <cstdio>
#include <cstdint>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

uint32_t test[122][2] = {
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000209u, 0x00000001u},
    {0x00000209u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000203u, 0x00000000u},
    {0x00000203u, 0x00000003u},
    {0x00000203u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x000000c3u, 0x00000001u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x000002c0u, 0x00000000u},
    {0x00000203u, 0x00000000u},
    {0x00000201u, 0x00000000u},
    {0x00000203u, 0x00000003u},
    {0x00000203u, 0x00000003u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000000u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000085u, 0x00000000u},
    {0x00000085u, 0x00000000u},
    {0x00000085u, 0x00000000u},
    {0x00000085u, 0x00000000u},
    {0x00000085u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000002u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000200u, 0x00000000u},
    {0x00000200u, 0x00000000u},
    {0x00000200u, 0x00000000u},
    {0x00000001u, 0x00000001u},
    {0x00000204u, 0x00000001u},
    {0x00000204u, 0x00000000u},
    {0x00000204u, 0x00000001u},
    {0x00000007u, 0x00000001u},
    {0x00000204u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000001u},
    {0x00000205u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x000002c0u, 0x00000003u},
    {0x00000204u, 0x00000000u},
    {0x00000204u, 0x00000000u},
    {0x00000204u, 0x00000000u},
    {0x00000204u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000205u, 0x00000000u},
    {0x00000003u, 0x00000001u},
    {0x00000001u, 0x00000000u},
    {0x00000003u, 0x00000001u},
    {0x000000c3u, 0x00000001u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000203u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000000u},
    {0x00000001u, 0x00000001u},
    {0x00000001u, 0x00000001u},
};

void set_regs(volatile void *regs) {
    for (int i=0;i<122;i++) {
        *(volatile uint32_t *)(regs + 0x1000 * i) = test[i][0];
        *(volatile uint32_t *)(regs + 0x1000 * i + 0x4) = test[i][1];
    }
}

int main() {
    int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
    volatile void *regs = mmap(0, 0x300000, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, 0x1000000);
    set_regs(regs);
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment