1 // vim:shiftwidth=2:expandtab
10 #include <sys/types.h>
13 #include <asm/ucontext.h>
17 #include <sys/resource.h>
18 #include <sys/ioctl.h>
19 #include <linux/soundcard.h>
23 #include "../common/host_fb.h"
24 #include "../common/cmn.h"
25 #include "sys_cacheflush.h"
26 #include "realfuncs.h"
28 #if (DBG & 2) && !(DBG & 4)
43 #define iolog_unh log_io
45 #define iolog_unh(...)
49 #define segvlog printf
54 #if defined(LOG_IO) || defined(LOG_IO_UNK)
55 #include "mmsp2-regs.h"
58 typedef unsigned long long u64;
59 typedef unsigned int u32;
60 typedef unsigned short u16;
61 typedef unsigned char u8;
63 static pthread_mutex_t fb_mutex = PTHREAD_MUTEX_INITIALIZER;
64 static pthread_cond_t fb_cond = PTHREAD_COND_INITIALIZER;
85 #define SRCCTRL_INVIDEO (1 << 8)
86 #define SRCCTRL_SRCENB (1 << 7)
87 #define CTRL_TRANSPARENCYENB (1 << 11)
100 u16 mlc_stl_pallt_d[256*2];
101 u32 mlc_stl_pallt_d32[256];
108 u32 btn_state; // as seen through /dev/GPIO
112 static u16 *host_screen;
113 static int host_stride;
116 #if defined(LOG_IO) || defined(LOG_IO_UNK)
117 static void log_io(const char *pfx, u32 a, u32 d, int size)
119 const char *fmt, *reg = "";
121 case 8: fmt = "%s %08x %02x %s\n"; d &= 0xff; break;
122 case 32: fmt = "%s %08x %08x %s\n"; break;
123 default: fmt = "%s %08x %04x %s\n"; d &= 0xffff; break;
126 if ((a & ~0xffff) == 0x7f000000)
127 reg = regnames[a & 0xffff];
129 printf(fmt, pfx, a, d, reg);
133 static void memset16(void *dst, u32 pattern, int count)
138 d = (u16 *)((long)dst & ~1);
144 pattern |= pattern << 16;
151 *(u16 *)dl = pattern;
154 static void blt_tr(void *dst, void *src, u32 trc, int w)
156 u16 *d = (u16 *)((long)dst & ~1);
157 u16 *s = (u16 *)((long)src & ~1);
160 for (; w > 0; d++, s++, w--)
165 #define dump_blitter() \
167 u32 *r = &blitter.dstctrl; \
169 for (i = 0; i < 4*4; i++, r++) { \
170 printf("%08x ", *r); \
176 static void *uppermem_lookup(u32 addr, u8 **mem_end)
178 // XXX: maybe support mirroring?
179 if ((addr & 0xfe000000) != 0x02000000)
182 *mem_end = (u8 *)mmsp2.umem + 0x02000000;
183 return (u8 *)mmsp2.umem - 0x02000000 + addr;
186 static void blitter_do(void)
188 u8 *dst, *dste, *src = NULL, *srce = NULL;
189 int w, h, sstrd, dstrd;
193 w = blitter.size & 0x7ff;
194 h = (blitter.size >> 16) & 0x7ff;
195 sstrd = blitter.srcstride;
196 dstrd = blitter.dststride;
198 // XXX: need to confirm this..
199 addr = (blitter.dstaddr & ~3) | ((blitter.dstctrl & 0x1f) >> 3);
201 // use dst bpp.. How does it do blits with different src bpp?
202 bpp = (blitter.dstctrl & 0x20) ? 16 : 8;
205 if (((w == 320 && h == 240) || // blit whole screen
206 (w * h >= 320*240/2)) && // ..or at least half of the area
207 mmsp2.mlc_stl_adr <= addr && addr < mmsp2.mlc_stl_adr + 320*240*2)
210 dst = uppermem_lookup(addr, &dste);
212 // XXX: assume fill if no SRCENB, but it could be pattern blit..
213 if (blitter.srcctrl & SRCCTRL_SRCENB) {
214 if (!(blitter.srcctrl & SRCCTRL_INVIDEO))
217 addr = (blitter.srcaddr & ~3) | ((blitter.srcctrl & 0x1f) >> 3);
218 src = uppermem_lookup(addr, &srce);
222 if (src + sstrd * h > srce) {
223 err("blit %08x->%08x %dx%d did not fit src\n",
224 blitter.srcaddr, blitter.dstaddr, w, h);
225 h = (srce - src) / sstrd;
232 if (dst + dstrd * h > dste) {
233 err("blit %08x->%08x %dx%d did not fit dst\n",
234 blitter.srcaddr, blitter.dstaddr, w, h);
235 h = (dste - dst) / dstrd;
240 if (bpp == 16 && (blitter.ctrl & CTRL_TRANSPARENCYENB)) {
241 u32 trc = blitter.ctrl >> 16;
242 for (; h > 0; h--, dst += dstrd, src += sstrd)
243 blt_tr(dst, src, trc, w);
246 for (; h > 0; h--, dst += dstrd, src += sstrd)
247 memcpy(dst, src, w * bpp / 8);
251 // fill. Assume the pattern is cleared and bg color is used
252 u32 bgc = blitter.patbackcolor & 0xffff;
254 for (; h > 0; h--, dst += dstrd)
255 memset16(dst, bgc, w);
258 for (; h > 0; h--, dst += dstrd)
259 memset(dst, bgc, w); // bgc?
264 pthread_cond_signal(&fb_cond);
268 err("blit %08x->%08x %dx%d translated to %p->%p\n",
269 blitter.srcaddr, blitter.dstaddr, w, h, src, dst);
273 // TODO: hw scaler stuff
274 static void mlc_flip(u8 *src, int bpp)
276 u16 *dst = host_screen;
277 u16 *hpal = mmsp2.host_pal;
280 if (bpp <= 8 && mmsp2.dirty_pal) {
281 u32 *srcp = mmsp2.mlc_stl_pallt_d32;
284 for (i = 0; i < 256; i++, srcp++, dstp++) {
286 *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f);
293 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
294 for (u = 320 / 2; u > 0; u--, src++) {
295 *dst++ = hpal[*src >> 4];
296 *dst++ = hpal[*src & 0x0f];
302 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
303 for (u = 320 / 4; u > 0; u--) {
304 *dst++ = hpal[*src++];
305 *dst++ = hpal[*src++];
306 *dst++ = hpal[*src++];
307 *dst++ = hpal[*src++];
313 for (i = 0; i < 240; i++, dst += host_stride / 2, src += 320*2)
314 memcpy(dst, src, 320*2);
322 host_screen = host_video_flip();
325 #define ts_add_nsec(ts, ns) { \
327 if (ts.tv_nsec >= 1000000000) { \
329 ts.tv_nsec -= 1000000000; \
333 static void *fb_sync_thread(void *arg)
335 int invalid_fb_addr = 1;
336 int manual_refresh = 0;
340 //ret = pthread_setschedprio(pthread_self(), -1);
341 //log("pthread_setschedprio %d\n", ret);
342 //ret = setpriority(PRIO_PROCESS, 0, -1);
343 //log("setpriority %d\n", ret);
345 ret = clock_gettime(CLOCK_REALTIME, &ts);
347 perror(PFX "clock_gettime");
352 u8 *gp2x_fb, *gp2x_fb_end;
355 ret = pthread_mutex_lock(&fb_mutex);
356 wait_ret = pthread_cond_timedwait(&fb_cond, &fb_mutex, &ts);
357 ret |= pthread_mutex_unlock(&fb_mutex);
360 err("fb_thread: mutex error: %d\n", ret);
364 if (wait_ret != 0 && wait_ret != ETIMEDOUT) {
365 err("fb_thread: cond error: %d\n", wait_ret);
370 if (wait_ret != ETIMEDOUT) {
371 clock_gettime(CLOCK_REALTIME, &ts);
372 ts_add_nsec(ts, 50000000);
374 if (manual_refresh == 2)
375 log("fb_thread: switch to manual refresh\n");
377 ts_add_nsec(ts, 16666667);
378 if (manual_refresh > 1)
379 log("fb_thread: switch to auto refresh\n");
383 mode = (mmsp2.mlc_stl_cntl >> 9) & 3;
384 bpp = mode ? mode * 8 : 4;
386 gp2x_fb = uppermem_lookup(mmsp2.mlc_stl_adr, &gp2x_fb_end);
387 if (gp2x_fb == NULL || gp2x_fb + 320*240 * bpp / 8 > gp2x_fb_end) {
388 if (!invalid_fb_addr) {
389 err("fb_thread: %08x is out of range\n", mmsp2.mlc_stl_adr);
395 mlc_flip(gp2x_fb, bpp);
399 static u32 xread8(u32 a)
401 iolog("r8 ", a, 0, 8);
402 iolog_unh("r8 ", a, 0, 8);
406 static u32 xread16(u32 a)
408 static u32 fudge, old_a;
411 if ((a & 0xffff0000) == 0x7f000000) {
419 // 0000 P000 VuVd00 0000 YXBA RLSeSt 0R0D 0L0U
420 // | GPIOD |GPIOC[8:15]|GPIOM[0:7]|
423 case 0x1184: // GPIOC
424 d = ~mmsp2.btn_state & 0xff00;
427 case 0x1186: // GPIOD
428 t = ~mmsp2.btn_state;
429 d = (t >> 9) & 0x0080;
430 d |= (t >> 11) & 0x0040;
431 d |= (t >> 7) & 0x0800;
434 case 0x1198: // GPIOM
435 mmsp2.btn_state = host_read_btns();
436 d = ~mmsp2.btn_state & 0xff;
439 case 0x1836: // reserved
442 case 0x2816: // DPC_X_MAX
445 case 0x2818: // DPC_Y_MAX
449 d = mmsp2.mlc_stl_cntl;
453 d = mmsp2.mlc_stl_adrl;
457 d = mmsp2.mlc_stl_adrh;
460 d = mmsp2.mlc_stl_pallt_a;
474 iolog_unh("r16", a, d & 0xffff, 16);
478 iolog("r16", a, d, 16);
482 static u32 xread32(u32 a)
485 if ((a & 0xfff00000) == 0x7f000000) {
491 case 0x0a00: // TCOUNT, 1/7372800s
492 clock_gettime(CLOCK_REALTIME, &ts);
493 t64 = (u64)ts.tv_sec * 1000000000 + ts.tv_nsec;
494 // t * 7372800.0 / 1000000000 * 0x100000000 ~= t * 31665935
500 if ((a & 0xfff00000) == 0x7f100000) {
501 u32 *bl = &blitter.dstctrl;
510 iolog_unh("r32", a, d, 32);
513 iolog("r32", a, d, 32);
517 static void xwrite8(u32 a, u32 d)
519 iolog("w8 ", a, d, 8);
520 iolog_unh("w8 ", a, d, 8);
523 static void xwrite16(u32 a, u32 d)
525 iolog("w16", a, d, 16);
526 if ((a & 0xfff00000) == 0x7f000000) {
530 mmsp2.mlc_stl_cntl = d | 0xaa;
534 // odd addresses don't affect LCD. What about TV?
537 mmsp2.mlc_stl_adrl = d;
540 mmsp2.mlc_stl_adrh = d;
541 if (mmsp2.mlc_stl_adr != mmsp2.old_mlc_stl_adr)
543 pthread_cond_signal(&fb_cond);
544 mmsp2.old_mlc_stl_adr = mmsp2.mlc_stl_adr;
547 mmsp2.mlc_stl_pallt_a = d & 0x1ff;
550 mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++] = d;
551 mmsp2.mlc_stl_pallt_a &= 0x1ff;
556 iolog_unh("w16", a, d, 16);
559 static void xwrite32(u32 a, u32 d)
561 iolog("w32", a, d, 32);
563 if ((a & 0xfff00000) == 0x7f100000) {
564 u32 *bl = &blitter.dstctrl;
568 if (a_ == 0x34 && (d & 1))
573 iolog_unh("w32", a, d, 32);
576 #define LINKPAGE_SIZE 0x1000
577 #define LINKPAGE_COUNT 4
578 #define LINKPAGE_ALLOC (LINKPAGE_SIZE * LINKPAGE_COUNT)
587 void (*handler)(struct op_context *op_ctx);
591 struct op_stackframe {
596 static struct op_linkpage *g_linkpage;
597 static u32 *g_code_ptr;
598 static int g_linkpage_count;
600 #define BIT_SET(v, b) (v & (1 << (b)))
602 void emu_handle_op(struct op_context *op_ctx, struct op_stackframe *sframe)
604 u32 *regs = sframe->saved_regs;
606 u32 t, shift, ret, addr;
609 rd = (op & 0x0000f000) >> 12;
610 rn = (op & 0x000f0000) >> 16;
612 if ((op & 0x0f200090) == 0x01000090) { // AM3: LDRH, STRH
613 if (!BIT_SET(op, 5)) // !H
615 if (BIT_SET(op, 6) && !BIT_SET(op, 20)) // S && !L
618 if (BIT_SET(op, 22)) // imm offset
619 t = ((op & 0xf00) >> 4) | (op & 0x0f);
621 t = regs[op & 0x000f];
623 if (!BIT_SET(op, 23))
627 if (BIT_SET(op, 20)) { // Load
629 if (BIT_SET(op, 6)) { // S
631 ret = (signed int)ret >> 16;
636 xwrite16(addr, regs[rd]);
638 else if ((op & 0x0d200000) == 0x05000000) { // AM2: LDR[B], STR[B]
639 if (BIT_SET(op, 25)) { // reg offs
643 t = regs[op & 0x000f];
644 shift = (op & 0x0f80) >> 7;
645 switch ((op & 0x0060) >> 5) {
646 case 0: t = t << shift; break;
647 case 1: t = t >> (shift + 1); break;
648 case 2: t = (signed int)t >> (shift + 1); break;
649 case 3: goto unhandled; // I'm just lazy
655 if (!BIT_SET(op, 23))
659 if (BIT_SET(op, 20)) { // Load
660 if (BIT_SET(op, 22)) // Byte
667 if (BIT_SET(op, 22)) // Byte
668 xwrite8(addr, regs[rd]);
670 xwrite32(addr, regs[rd]);
677 if (addr != addr_check) {
678 fprintf(stderr, "bad calculated addr: %08x vs %08x\n", addr, addr_check);
685 err("unhandled IO op %08x @ %08x\n", op, op_ctx->pc);
688 static u32 make_offset12(u32 *pc, u32 *target)
692 lp_offs = (char *)target - (char *)pc - 2*4;
697 if (lp_offs >= LINKPAGE_SIZE) {
698 err("linkpage too far: %d\n", lp_offs);
702 return (u << 23) | lp_offs;
705 static u32 make_jmp(u32 *pc, u32 *target, int bl)
709 jmp_val = target - pc - 2;
710 if (jmp_val < (int)0xff000000 || jmp_val > 0x00ffffff) {
711 err("jump out of range (%p -> %p)\n", pc, target);
715 return 0xea000000 | (bl << 24) | (jmp_val & 0x00ffffff);
718 static void emit_op(u32 op)
723 static void emit_op_io(u32 op, u32 *target)
725 op |= make_offset12(g_code_ptr, target);
729 static void init_linkpage(void)
731 g_linkpage->handler = emu_call_handle_op;
732 g_code_ptr = g_linkpage->code;
735 static void segv_sigaction(int num, siginfo_t *info, void *ctx)
737 struct ucontext *context = ctx;
738 u32 *regs = (u32 *)&context->uc_mcontext.arm_r0;
739 u32 *pc = (u32 *)regs[15];
740 struct op_context *op_ctx;
743 if (((regs[15] ^ (u32)&segv_sigaction) & 0xff000000) == 0 || // PC is in our segment or
744 (((regs[15] ^ (u32)g_linkpage) & ~(LINKPAGE_ALLOC - 1)) == 0) || // .. in linkpage
745 ((long)info->si_addr & 0xffe00000) != 0x7f000000) // faulting not where expected
747 // real crash - time to die
748 err("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
749 for (i = 0; i < 8; i++)
750 err(" r%d=%08x r%2d=%08x\n", i, regs[i], i+8, regs[i+8]);
751 signal(num, SIG_DFL);
755 segvlog("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
758 op_ctx = (void *)g_code_ptr;
759 op_ctx->pc = (u32)pc;
761 g_code_ptr = &op_ctx->code[0];
763 // emit jump to code ptr
764 *pc = make_jmp(pc, g_code_ptr, 0);
767 emit_op (0xe50d0000 + 0xf00 - 4 * 0); // str r0, [sp, #(-0xf00 + r0_offs)]
768 emit_op (0xe50de000 + 0xf00 - 4 * 14); // str lr, [sp, #(-0xf00 + lr_offs)]
769 emit_op (0xe24f0000 + (g_code_ptr - (u32 *)op_ctx + 2) * 4); // sub r0, pc, #op_ctx
770 emit_op (0xe1a0e00f); // mov lr, pc
771 emit_op_io(0xe51ff000, (u32 *)&g_linkpage->handler); // ldr pc, =handle_op
772 emit_op (0xe51de000 + 0xf00 - 4 * 14); // ldr lr, [sp, #(-0xf00 + lr_offs)]
773 emit_op (make_jmp(g_code_ptr, pc + 1, 0)); // jmp <back>
776 sys_cacheflush(pc, pc + 1);
777 sys_cacheflush(g_linkpage, g_code_ptr);
779 lp_size = (char *)g_code_ptr - (char *)g_linkpage;
780 segvlog("code #%d %d/%d\n", g_linkpage_count, lp_size, LINKPAGE_SIZE);
782 if (lp_size + 13*4 > LINKPAGE_SIZE) {
784 if (g_linkpage_count >= LINKPAGE_COUNT) {
785 err("too many linkpages needed\n");
788 g_linkpage = (void *)((char *)g_linkpage + LINKPAGE_SIZE);
791 //handle_op(regs[15], op, regs, (u32)info->si_addr);
795 void emu_init(void *map_bottom)
797 sigaction_t segv_action = {
798 .sa_sigaction = segv_sigaction,
799 .sa_flags = SA_SIGINFO,
805 g_linkpage = (void *)(((u32)map_bottom - LINKPAGE_ALLOC) & ~0xfff);
806 pret = mmap(g_linkpage, LINKPAGE_ALLOC, PROT_READ|PROT_WRITE,
807 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
808 if (pret != g_linkpage) {
809 perror(PFX "mmap linkpage");
812 log("linkpages @ %p\n", g_linkpage);
815 mmsp2.umem = mmap(NULL, 0x2000000, PROT_READ|PROT_WRITE|PROT_EXEC,
816 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
817 if (mmsp2.umem == MAP_FAILED) {
818 perror(PFX "mmap upper mem");
823 ret = host_video_init(&host_stride, 0);
825 err("can't init video\n");
828 host_screen = host_video_flip();
830 ret = pthread_create(&tid, NULL, fb_sync_thread, NULL);
832 err("failed to create fb_sync_thread: %d\n", ret);
838 mmsp2.mlc_stl_adr = 0x03101000; // fb2 is at 0x03381000
839 mmsp2.mlc_stl_cntl = 0x4ab; // 16bpp, region 1 active
841 sigemptyset(&segv_action.sa_mask);
842 sigaction(SIGSEGV, &segv_action, NULL);
845 int emu_read_gpiodev(void *buf, int count)
850 err("gpiodev read %d?\n", count);
854 btns = host_read_btns();
855 memcpy(buf, &btns, 4);
859 struct dev_fd_t emu_interesting_fds[] = {
860 [IFD_SOUND] = { "/dev/dsp", -1 },
864 static void *emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset)
869 if ((offset & ~0xffff) == 0xc0000000) {
870 return mmap((void *)0x7f000000, length, PROT_NONE,
871 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
874 if ((offset & ~0xffff) == 0xe0020000) {
875 return mmap((void *)0x7f100000, length, PROT_NONE,
876 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
879 if ((offset & 0xfe000000) != 0x02000000) {
880 err("unexpected devmem mmap @ %08x\n", offset);
885 umem = uppermem_lookup(offset, &umem_end);
886 if (umem + length > umem_end)
887 err("warning: uppermem @ %08x overflows by %d bytes\n",
888 offset, umem + length - umem_end);
890 dbg("upper mem @ %08x %d\n", offset, length);
894 void *emu_do_mmap(unsigned int length, int prot, int flags, int fd, unsigned int offset)
896 if (fd == FAKEDEV_MEM)
897 return emu_mmap_dev(length, prot, flags, offset);
899 if (fd == FAKEDEV_FB0)
900 return emu_mmap_dev(length, prot, flags, offset + 0x03101000);
902 if (fd == FAKEDEV_FB1)
903 return emu_mmap_dev(length, prot, flags, offset + 0x03381000);
905 err("bad/ni mmap(?, %d, %x, %x, %d, %08x)\n", length, prot, flags, fd, offset);
910 static int emu_sound_ioctl(int fd, int request, void *argp)
915 dbg("snd ioctl(%d, %08x, %p)", fd, request, argp);
917 dbg_c(" [%d]", *arg);
921 /* People set strange frag settings on GP2X, which even manage
922 * to break audio on pandora (causes writes to fail).
923 * Catch this and set to something that works. */
924 if (request == SNDCTL_DSP_SPEED) {
925 int ret, bsize, frag;
927 // ~4ms. gpSP wants small buffers or else it stutters
928 // because of it's audio thread sync stuff
929 bsize = *arg / 250 * 4;
930 for (frag = 0; bsize; bsize >>= 1, frag++)
933 frag |= 16 << 16; // fragment count
934 ret = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag);
936 err("snd ioctl SETFRAGMENT %08x: ", frag);
940 else if (request == SNDCTL_DSP_SETFRAGMENT)
943 return ioctl(fd, request, argp);
946 int emu_do_ioctl(int fd, int request, void *argp)
948 if (fd == emu_interesting_fds[IFD_SOUND].fd)
949 return emu_sound_ioctl(fd, request, argp);
952 /* *********************** */
959 case FBIOGET_FSCREENINFO: {
960 struct fb_fix_screeninfo *fix = argp;
962 memset(fix, 0, sizeof(*fix));
963 strcpy(fix->id, "mmsp2_RGB0");
964 fix->type = FB_TYPE_PACKED_PIXELS;
965 fix->accel = FB_ACCEL_NONE;
966 fix->visual = FB_VISUAL_TRUECOLOR;
967 fix->line_length = 320*2;
968 fix->smem_start = (fd == FAKEDEV_FB0) ? 0x03101000 : 0x03381000;
969 fix->smem_len = 320*240*2;
972 case FBIOGET_VSCREENINFO: {
973 struct fb_var_screeninfo *var = argp;
974 static const struct fb_bitfield fbb_red = { offset: 11, length: 5, };
975 static const struct fb_bitfield fbb_green = { offset: 5, length: 6, };
976 static const struct fb_bitfield fbb_blue = { offset: 0, length: 5, };
978 memset(var, 0, sizeof(*var));
979 var->activate = FB_ACTIVATE_NOW;
981 var->xres_virtual = 320;
983 var->yres_virtual = 240;
986 var->vmode = FB_VMODE_NONINTERLACED;
987 var->bits_per_pixel = 16;
989 var->green = fbb_green;
990 var->blue = fbb_blue;
993 case FBIOPUT_VSCREENINFO: {
994 struct fb_var_screeninfo *var = argp;
995 dbg(" put vscreen: %dx%d@%d\n", var->xres, var->yres, var->bits_per_pixel);
996 if (var->xres != 320 || var->yres != 240 || var->bits_per_pixel != 16)
1002 /* *********************** */
1004 // fake tty0 to make GPH SDL happy
1005 if (request == 0x4b46) // KDGKBENT
1011 err("bad/ni ioctl(%d, %08x, %p)\n", fd, request, argp);
1016 static const struct {
1020 { "/mnt/tmp/", "/tmp/" },
1023 static const char *wrap_path(const char *path)
1029 // do only path mapping for now
1030 for (i = 0; i < ARRAY_SIZE(path_map); i++) {
1031 len = strlen(path_map[i].from);
1032 if (strncmp(path, path_map[i].from, len) == 0) {
1033 size = strlen(path) + strlen(path_map[i].to) + 1;
1034 buff = malloc(size);
1037 snprintf(buff, size, "%s%s", path_map[i].to, path + len);
1038 dbg("mapped path \"%s\" -> \"%s\"\n", path, buff);
1046 void *emu_do_fopen(const char *path, const char *mode)
1048 const char *w_path = wrap_path(path);
1050 ret = fopen(w_path, mode);
1052 free((void *)w_path);
1057 int emu_do_system(const char *command)
1059 static char tmp_path[512];
1063 if (command == NULL)
1066 // pass through stuff in PATH
1067 p = strchr(command, ' ');
1068 p2 = strchr(command, '/');
1069 if (p2 == NULL || (p != NULL && p2 > p))
1070 return system(command);
1072 make_local_path(tmp_path, sizeof(tmp_path), "ginge_prep");
1073 p = tmp_path + strlen(tmp_path);
1075 p2 = wrap_path(command);
1076 snprintf(p, sizeof(tmp_path) - (p - tmp_path), " %s", p2);
1080 dbg("system: \"%s\"\n", tmp_path);
1081 return system(tmp_path);