From 5525d5dde23ee28fd0241807c955f5e3cbf03371 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Mon, 9 Jul 2018 09:31:45 +0200 Subject: [PATCH] core: Android studio fixes - Clang edge cases for shifts - Avoid generating relocs by not using global symbols in ngen_arm.S (fixes #1109) --- core/arm_emitter/E_DataOp.h | 5 ++++- core/hw/arm7/arm7.cpp | 15 ++++++++++----- core/rec-ARM/ngen_arm.S | 4 ++-- core/rec-ARM/rec_arm.cpp | 2 +- .../app/src/main/jni/src/Android.cpp | 8 ++++++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/core/arm_emitter/E_DataOp.h b/core/arm_emitter/E_DataOp.h index 0bf896c32..c9d8dafcb 100755 --- a/core/arm_emitter/E_DataOp.h +++ b/core/arm_emitter/E_DataOp.h @@ -153,18 +153,21 @@ ADD.SP.REG 0x008D0000 for (int i=0;i<=30;i+=2) { u32 immv=(imm32<>(32-i)); + if (i == 0) + immv = imm32; if (immv<256) { return ((i/2)<<8) | immv; } } - + return -1; } static u32 ARMImmid8r4(u32 imm8r4) { u32 rv = ARMImmid8r4_enc(imm8r4); + verify(rv!=-1); return rv; } diff --git a/core/hw/arm7/arm7.cpp b/core/hw/arm7/arm7.cpp index b3bcec1bc..b878e8407 100644 --- a/core/hw/arm7/arm7.cpp +++ b/core/hw/arm7/arm7.cpp @@ -790,7 +790,7 @@ void armv_prof(OpType opt,u32 op,u32 flg); extern "C" void arm_dispatch(); extern "C" void arm_exit(); -extern "C" void DYNACALL arm_mainloop(u32 cycl); +extern "C" void DYNACALL arm_mainloop(u32 cycl, void* regs, void* entrypoints); extern "C" void DYNACALL arm_compilecode(); template @@ -1470,7 +1470,7 @@ naked void DYNACALL arm_compilecode() } } -naked void DYNACALL arm_mainloop(u32 cycl) +naked void DYNACALL arm_mainloop(u32 cycl, void* regs, void* entrypoints) { __asm { @@ -1590,8 +1590,13 @@ void armv_end(void* codestart, u32 cycl) SUB(r5,r5,cycl,true); else { - SUB(r5,r5,256); - SUB(r5,r5,cycl-256,true); + u32 togo = cycl; + while(ARMImmid8r4_enc(togo) == -1) + { + SUB(r5,r5,256); + togo -= 256; + } + SUB(r5,r5,togo,true); } JUMP((u32)&arm_exit,CC_MI); //statically predicted as not taken JUMP((u32)&arm_dispatch); @@ -1620,7 +1625,7 @@ void arm_Run(u32 CycleCount) for (int i=0;i<32;i++) { - arm_mainloop(CycleCount/32); + arm_mainloop(CycleCount/32, arm_Reg, EntryPoints); libAICA_TimeStep(); } diff --git a/core/rec-ARM/ngen_arm.S b/core/rec-ARM/ngen_arm.S index fddaded5f..b6c74dfbf 100644 --- a/core/rec-ARM/ngen_arm.S +++ b/core/rec-ARM/ngen_arm.S @@ -217,8 +217,8 @@ push {r4,r5,r8,r9,lr} ldr r8,Xarm_Reg @load cntx ldr r4,XEntryPoints @load lookup base #else - ldr r8,=arm_Reg @load cntx - ldr r4,=EntryPoints @load lookup base + mov r8,r1 @load cntx + mov r4,r2 @load lookup base #endif ldr r5,[r8,#192] @load cycle count diff --git a/core/rec-ARM/rec_arm.cpp b/core/rec-ARM/rec_arm.cpp index 12717931c..1f43e7745 100644 --- a/core/rec-ARM/rec_arm.cpp +++ b/core/rec-ARM/rec_arm.cpp @@ -1609,7 +1609,7 @@ void ngen_compile_opcode(RuntimeBlockInfo* block, shil_opcode* op, bool staging, if (op->rs2.is_imm()) { - if (!op->rs2.is_imm_u8()) + if (!is_i8r4(op->rs2._imm)) MOV32(rs2,(u32)op->rs2._imm); else is_imm=true; diff --git a/shell/android-studio/app/src/main/jni/src/Android.cpp b/shell/android-studio/app/src/main/jni/src/Android.cpp index 7d827a8fc..6f11de1da 100644 --- a/shell/android-studio/app/src/main/jni/src/Android.cpp +++ b/shell/android-studio/app/src/main/jni/src/Android.cpp @@ -339,8 +339,9 @@ int msgboxf(const wchar* Text,unsigned int Type,...) va_list Args; va_start(Args,Type); - vsprintf(S,Text,Args); + vsnprintf(S, 2048,Text,Args); va_end(Args); + puts(S); int byteCount = strlen(S); jbyteArray bytes = jenv->NewByteArray(byteCount); @@ -561,5 +562,8 @@ int push_vmu_screen(u8* buffer) void os_DebugBreak() { - //notify the parent thread about it ... + // TODO: notify the parent thread about it ... + + // Attach debugger here to figure out what went wrong + for(;;) ; }