| 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <sys/mman.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | #include "soc.h" |
| 10 | #include "../common/emu.h" |
| 11 | |
| 12 | gp2x_soc_t soc_detect(void) |
| 13 | { |
| 14 | volatile unsigned short *memregs; |
| 15 | volatile unsigned int *memregl; |
| 16 | static gp2x_soc_t ret = -1; |
| 17 | int pollux_chipname[0x30/4 + 1]; |
| 18 | char *pollux_chipname_c = (char *)pollux_chipname; |
| 19 | int memdev; |
| 20 | int i; |
| 21 | |
| 22 | if (ret != -1) |
| 23 | /* already detected */ |
| 24 | return ret; |
| 25 | |
| 26 | memdev = open("/dev/mem", O_RDONLY); |
| 27 | if (memdev == -1) |
| 28 | { |
| 29 | perror("open(/dev/mem)"); |
| 30 | return -1; |
| 31 | } |
| 32 | |
| 33 | memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, memdev, 0xc0000000); |
| 34 | if (memregs == MAP_FAILED) |
| 35 | { |
| 36 | perror("mmap(memregs)"); |
| 37 | close(memdev); |
| 38 | return -1; |
| 39 | } |
| 40 | memregl = (volatile void *)memregs; |
| 41 | |
| 42 | if (memregs[0x1836>>1] == 0x2330) |
| 43 | { |
| 44 | printf("looks like this is MMSP2\n"); |
| 45 | ret = SOCID_MMSP2; |
| 46 | goto out; |
| 47 | } |
| 48 | |
| 49 | /* perform word reads. Byte reads might also work, |
| 50 | * but we don't want to play with that. */ |
| 51 | for (i = 0; i < 0x30; i += 4) |
| 52 | { |
| 53 | pollux_chipname[i >> 2] = memregl[(0x1f810 + i) >> 2]; |
| 54 | } |
| 55 | pollux_chipname_c[0x30] = 0; |
| 56 | |
| 57 | for (i = 0; i < 0x30; i++) |
| 58 | { |
| 59 | unsigned char c = pollux_chipname_c[i]; |
| 60 | if (c < 0x20 || c > 0x7f) |
| 61 | goto not_pollux_like; |
| 62 | } |
| 63 | |
| 64 | printf("found pollux-like id: \"%s\"\n", pollux_chipname_c); |
| 65 | |
| 66 | if (strncmp(pollux_chipname_c, "MAGICEYES-LEAPFROG-LF1000", 25) || |
| 67 | strncmp(pollux_chipname_c, "MAGICEYES-POLLUX", 16)) |
| 68 | { |
| 69 | ret = SOCID_POLLUX; |
| 70 | goto out; |
| 71 | } |
| 72 | |
| 73 | not_pollux_like: |
| 74 | out: |
| 75 | munmap((void *)memregs, 0x20000); |
| 76 | close(memdev); |
| 77 | return ret; |
| 78 | } |
| 79 | |