X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=ginge.git;a=blobdiff_plain;f=loader%2Fpatches.c;h=ccbaadf5fa9b7b9e4f4447a6d1103b87b8bb51fe;hp=9354d2fdcbc1ab35b981e58b9be87ef2fddbcead;hb=2ce69bdff40e40fb1c1954e0883d95de271cecc7;hpb=11913091045ebc44f003138d9e69cdc91fe4982e diff --git a/loader/patches.c b/loader/patches.c index 9354d2f..ccbaadf 100644 --- a/loader/patches.c +++ b/loader/patches.c @@ -5,10 +5,13 @@ #include #include #include +#include #include "header.h" #include "sys_cacheflush.h" +#define strace(...) + static const unsigned int sig_open[] = { 0xe59cc000, 0xe33c0000, 0x1a000003, 0xef900005 }; @@ -22,17 +25,24 @@ static const unsigned int sig_mmap_[] = { 0xe1b0ca05, 0x1a000006, 0xe1a05625, 0xef9000c0 }; -#define FAKE_DEVMEM_DEVICE 10001 +static const unsigned int sig_read[] = { + 0xe59fc080, 0xe59cc000, 0xe33c0000, 0x1a000003, 0xef900003 +}; + +#define FAKE_DEVMEM_DEVICE 10001 +#define FAKE_DEVGPIO_DEVICE 10002 static int w_open(const char *pathname, int flags, mode_t mode) { int ret; - if (strcmp(pathname, "/dev/mem") != 0) - ret = open(pathname, flags, mode); - else + if (strcmp(pathname, "/dev/mem") == 0) ret = FAKE_DEVMEM_DEVICE; + else if (strcmp(pathname, "/dev/GPIO") == 0) + ret = FAKE_DEVGPIO_DEVICE; + else + ret = open(pathname, flags, mode); - printf("open(%s) = %d\n", pathname, ret); + strace("open(%s) = %d\n", pathname, ret); return ret; } @@ -44,11 +54,22 @@ static void *w_mmap(void *addr, size_t length, int prot, int flags, int fd, off_ else ret = emu_mmap_dev(length, prot, flags, offset); - printf("mmap(%p, %x, %x, %x, %d, %lx) = %p\n", addr, length, prot, flags, fd, (long)offset, ret); + strace("mmap(%p, %x, %x, %x, %d, %lx) = %p\n", addr, length, prot, flags, fd, (long)offset, ret); return ret; } #define w_mmap_ w_mmap +ssize_t w_read(int fd, void *buf, size_t count) +{ + ssize_t ret; + if (fd != FAKE_DEVGPIO_DEVICE) + return read(fd, buf, count); + + ret = emu_read_gpiodev(buf, count); + //printf("read(%d, %p, %d) = %d\n", fd, buf, count, ret); + return ret; +} + #define PATCH(f) { sig_##f, ARRAY_SIZE(sig_##f), w_##f } static const struct { @@ -59,6 +80,7 @@ static const struct { PATCH(open), PATCH(mmap), PATCH(mmap_), // mmap using mmap2 syscall + PATCH(read), }; void do_patches(void *ptr, unsigned int size)