X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=ginge.git;a=blobdiff_plain;f=loader%2Femu.c;h=313bd062b90c65e40517ed5deec2db221773cf86;hp=64c2c993b7f8982282bd631c8e1c943bfc4ba528;hb=f01759de2aca10619ab74e6f2cda92a7799e6234;hpb=d0b9b0df7ed0dc36aabe30e2d584c27c8c32a3d9 diff --git a/loader/emu.c b/loader/emu.c index 64c2c99..313bd06 100644 --- a/loader/emu.c +++ b/loader/emu.c @@ -370,7 +370,7 @@ static void *fb_sync_thread(void *arg) && wait_ret != -ETIMEDOUT) { err("fb_thread: futex error: %d\n", wait_ret); - g_sleep(1); + sleep(1); goto check_keys; } if (fb_sync_thread_paused) { @@ -643,10 +643,10 @@ static void xwrite16(u32 a, u32 d) } mmsp2.old_mlc_stl_adr = mmsp2.mlc_stl_adr; return; - case 0x2958: + case 0x2958: // MLC_STL_PALLT_A mmsp2.mlc_stl_pallt_a = d & 0x1ff; return; - case 0x295a: + case 0x295a: // MLC_STL_PALLT_D mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++] = d; mmsp2.mlc_stl_pallt_a &= 0x1ff; mmsp2.v.dirty_pal = DIRTY_PAL_MMSP2; @@ -663,6 +663,14 @@ static void xwrite32(u32 a, u32 d) if ((a & 0xfff00000) == 0x7f000000) { u32 a_ = a & 0xffff; switch (a_) { + // GP2X + case 0x295a: // MLC_STL_PALLT_D + // special unaligned 32bit write, allegro seems to rely on it + mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++ & 0x1ff] = d; + mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++ & 0x1ff] = d >> 16; + mmsp2.mlc_stl_pallt_a &= 0x1ff; + mmsp2.v.dirty_pal = DIRTY_PAL_MMSP2; + return; // Wiz case 0x4024: // MLCCONTROL0 case 0x4058: // MLCCONTROL1 @@ -977,8 +985,8 @@ void emu_init(void *map_bottom) #ifdef PND if (geteuid() == 0) { - fprintf(stderr, "don't try to run as root, device registers or memory " - "might get trashed crashing the OS or even damaging the device.\n"); + err("don't try to run as root, device registers or memory " + "might get trashed crashing the OS or even damaging the device.\n"); exit(1); } #endif @@ -1051,11 +1059,11 @@ void emu_init(void *map_bottom) sigaction(SIGSEGV, &segv_action, NULL); } -int emu_read_gpiodev(void *buf, int count) +long emu_read_gpiodev(void *buf, int count) { if (count <= 0) { err("gpiodev read %d?\n", count); - return -1; + return -EINVAL; } if (count > 4) count = 4; @@ -1065,25 +1073,24 @@ int emu_read_gpiodev(void *buf, int count) return count; } -static void *emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset) +static long emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset) { u8 *umem, *umem_end; // SoC regs if ((offset & ~0x1ffff) == 0xc0000000) { - return mmap((void *)0x7f000000, length, PROT_NONE, + return g_mmap2_raw((void *)0x7f000000, length, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0); } // MMSP2 blitter if ((offset & ~0xffff) == 0xe0020000) { - return mmap((void *)0x7f100000, length, PROT_NONE, + return g_mmap2_raw((void *)0x7f100000, length, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0); } // upper mem if ((offset & 0xfe000000) != 0x02000000) { err("unexpected devmem mmap @ %08x\n", offset); - errno = EINVAL; - return MAP_FAILED; + return -EINVAL; } umem = uppermem_lookup(offset, &umem_end); @@ -1092,10 +1099,11 @@ static void *emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset, umem + length - umem_end); dbg("upper mem @ %08x %x = %p\n", offset, length, umem); - return umem; + return (long)umem; } -void *emu_do_mmap(unsigned int length, int prot, int flags, int fd, unsigned int offset) +long emu_do_mmap(unsigned int length, int prot, int flags, int fd, + unsigned int offset) { if (fd == FAKEDEV_MEM) return emu_mmap_dev(length, prot, flags, offset); @@ -1107,11 +1115,10 @@ void *emu_do_mmap(unsigned int length, int prot, int flags, int fd, unsigned int return emu_mmap_dev(length, prot, flags, offset + 0x03381000); err("bad/ni mmap(?, %d, %x, %x, %d, %08x)\n", length, prot, flags, fd, offset); - errno = EINVAL; - return MAP_FAILED; + return -EINVAL; } -int emu_do_munmap(void *addr, unsigned int length) +long emu_do_munmap(void *addr, unsigned int length) { u8 *p = addr; @@ -1131,15 +1138,13 @@ static void emu_sound_open(int fd) // set default buffer size to 16 * 1K frag = (16<<16) | 10; // 16K - ret = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag); - if (ret != 0) { - err("snd ioctl SETFRAGMENT %08x: ", frag); - perror(NULL); - } + ret = g_ioctl_raw(fd, SNDCTL_DSP_SETFRAGMENT, &frag); + if (ret != 0) + err("snd ioctl SETFRAGMENT %08x: %d\n", frag, ret); #endif } -static int emu_sound_ioctl(int fd, int request, void *argp) +static long emu_sound_ioctl(int fd, int request, void *argp) { int *arg = argp; @@ -1155,7 +1160,9 @@ static int emu_sound_ioctl(int fd, int request, void *argp) * Catch this and set to something that works. */ switch(request) { case SNDCTL_DSP_SETFRAGMENT: { - int ret, bsize, frag, frag_cnt; + int bsize, frag, frag_cnt; + long ret; + if (arg == NULL) break; @@ -1180,11 +1187,9 @@ static int emu_sound_ioctl(int fd, int request, void *argp) } frag |= frag_cnt << 16; - ret = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag); - if (ret != 0) { - err("snd ioctl SETFRAGMENT %08x: ", frag); - perror(NULL); - } + ret = g_ioctl_raw(fd, SNDCTL_DSP_SETFRAGMENT, &frag); + if (ret != 0) + err("snd ioctl SETFRAGMENT %08x: %ld\n", frag, ret); // indicate success even if we fail (because of ALSA mostly), // things like MikMod will bail out otherwise. return 0; @@ -1196,10 +1201,10 @@ static int emu_sound_ioctl(int fd, int request, void *argp) break; } - return ioctl(fd, request, argp); + return g_ioctl_raw(fd, request, argp); } -int emu_do_ioctl(int fd, int request, void *argp) +long emu_do_ioctl(int fd, int request, void *argp) { if (fd == emu_interesting_fds[IFD_SOUND].fd) return emu_sound_ioctl(fd, request, argp); @@ -1265,8 +1270,7 @@ int emu_do_ioctl(int fd, int request, void *argp) fail: err("bad/ni ioctl(%d, %08x, %p)\n", fd, request, argp); - errno = EINVAL; - return -1; + return -EINVAL; } struct dev_fd_t emu_interesting_fds[] = {