/* mgaprobe.c - become the RCM graphics process for mga0, report what the * kernel maps, read a few engine registers, let go. Reads only. * Claude Opus 5.5, 2026-10-13. * cc: xlc -o mgaprobe mgaprobe.c -bI:/usr/lib/rcm.exp * usage: mgaprobe [-h] (-h: only get the gsc handle, don't MAKE_GP) */ #include #include #include #include #include #include #include #include int main(int argc, char **argv) { gsc_handle h; make_gp mg; unmake_gp ug; gAddrRanges ar; unsigned int pd[8]; volatile unsigned char *base; int fd, rc, i; fd = open("/dev/rcm0", O_RDWR); if (fd < 0) { perror("open /dev/rcm0"); return 1; } memset(&h, 0, sizeof h); strcpy(h.devname, "mga0"); rc = ioctl(fd, GSC_HANDLE, &h); printf("GSC_HANDLE rc=%d errno=%d handle=0x%x\n", rc, rc ? errno : 0, h.handle); if (rc || (argc > 1 && strcmp(argv[1], "-h") == 0)) return rc != 0; memset(&mg, 0, sizeof mg); memset(pd, 0, sizeof pd); memset(&ar, 0, sizeof ar); mg.pData = (genericPtr) pd; mg.length = sizeof pd; mg.access = EXCLUSIVE_ACCESS | ADDR_ARRAY_VERSION | ALL_ADDR_RANGES; mg.NumAddrRanges = 1; mg.AddrRanges = &ar; rc = aixgsc(h.handle, MAKE_GP, &mg); printf("MAKE_GP rc=%d errno=%d error=%d segment=%p\n", rc, rc ? errno : 0, mg.error, (void *) mg.segment); if (rc) return 1; for (i = 0; i < 8; i++) printf("pData[%d] = 0x%08x\n", i, pd[i]); printf("range: base=%p len=0x%x id=%u\n", ar.BaseAddr, ar.RangeLength, ar.AddrRangeID); base = (volatile unsigned char *) ar.BaseAddr; printf("FIFOSTATUS 0x1e10 = 0x%08x\n", *(volatile unsigned int *)(base + 0x1e10)); printf("STATUS 0x1e14 = 0x%08x\n", *(volatile unsigned int *)(base + 0x1e14)); printf("OPMODE 0x1e54 = 0x%08x\n", *(volatile unsigned int *)(base + 0x1e54)); printf("MACCESS 0x1c04 = 0x%08x\n", *(volatile unsigned int *)(base + 0x1c04)); printf("PITCH 0x1c8c = 0x%08x\n", *(volatile unsigned int *)(base + 0x1c8c)); printf("YDSTORG 0x1c94 = 0x%08x\n", *(volatile unsigned int *)(base + 0x1c94)); memset(&ug, 0, sizeof ug); rc = aixgsc(h.handle, UNMAKE_GP, &ug); printf("UNMAKE_GP rc=%d error=%d\n", rc, ug.error); return 0; }