release r2, update credits
[fceu.git] / drivers / gp2x / squidgehack.c
CommitLineData
937bf65b 1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7#include <unistd.h>
8
9extern char **g_argv;
10
11/* Call this MMU Hack kernel module after doing mmap, and before doing memset*/
12int mmuhack(void)
13{
14 char kocmd[1024];
b547bda7 15 int i, mmufd;
16
17 /* some programs like some versions of gpSP use some weird version of mmuhack.o
18 * which doesn't seem to work. What's even worse they leave their mmuhack loaded on exit.
19 * So we must remove whatever may be left and always reload _our_ mmuhack.o */
20 system("/sbin/rmmod mmuhack");
21
22 strcpy(kocmd, "/sbin/insmod ");
23 strncpy(kocmd+13, g_argv[0], 1023-13);
24 kocmd[1023] = 0;
0ab4d38f 25 for (i = strlen(kocmd); i > 13; i--)
26 if (kocmd[i] == '/') { i++; break; }
27 strcpy(kocmd+i, "mmuhack.o");
b547bda7 28
29 printf("Installing NK's kernel module for Squidge MMU Hack (%s)...\n", kocmd);
30 system(kocmd);
31 mmufd = open("/dev/mmuhack", O_RDWR);
937bf65b 32 if(mmufd < 0) return 0;
b547bda7 33
937bf65b 34 close(mmufd);
35 return 1;
b547bda7 36}
937bf65b 37
38
39/* Unload MMU Hack kernel module after closing all memory devices*/
40int mmuunhack(void)
41{
42 int ret;
43 printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout);
44 ret = system("/sbin/rmmod mmuhack");
45 printf("done (%i)\n", ret);
46
47 return ret;
48}