From 45ea1fa9905d20d7c3a839e28f571aff0b3e76f5 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 31 Oct 2020 17:40:05 +0100 Subject: Fix compilation issues on pedantic cpp compilers. (#783) * Fix compilation issues on pedantic cpp compilers. * Avoid using fullblown static function. --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/ARMJIT_x64') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index c6419c9..9785ffc 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -101,6 +101,11 @@ void Compiler::A_Comp_MRS() MOV(32, rd, R(RCPSR)); } +void UpdateModeTrampoline(ARM* arm, u32 oldmode, u32 newmode) +{ + arm->UpdateMode(oldmode, newmode); +} + void Compiler::A_Comp_MSR() { Comp_AddCycles_C(); @@ -185,7 +190,7 @@ void Compiler::A_Comp_MSR() MOV(32, R(ABI_PARAM3), R(RCPSR)); MOV(32, R(ABI_PARAM2), R(RSCRATCH3)); MOV(64, R(ABI_PARAM1), R(RCPU)); - CALL((void*)&ARM::UpdateMode); + CALL((void*)&UpdateModeTrampoline); PopRegs(true); } @@ -896,5 +901,4 @@ void Compiler::Comp_AddCycles_CD() else ConstantCycles += cycles; } - -} \ No newline at end of file +} -- cgit v1.2.3 From fbca47381b9e37ee19a2bdfdcd4e393d0ea69a7d Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 31 Oct 2020 17:53:01 +0100 Subject: Fix a couple of wrong cpp function pointers. (#785) --- src/ARMJIT_x64/ARMJIT_Branch.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/ARMJIT_x64') diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 819fe3c..70ec781 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -130,6 +130,16 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); } +void ARMv4JumpToTrampoline(ARMv4* arm, u32 addr, bool restorecpsr) +{ + arm->JumpTo(addr, restorecpsr); +} + +void ARMv5JumpToTrampoline(ARMv5* arm, u32 addr, bool restorecpsr) +{ + arm->JumpTo(addr, restorecpsr); +} + void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) { IrregularCycles = true; @@ -146,9 +156,9 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) else MOV(32, R(ABI_PARAM3), Imm32(true)); // what a waste if (Num == 0) - CALL((void*)&ARMv5::JumpTo); + CALL((void*)&ARMv5JumpToTrampoline); else - CALL((void*)&ARMv4::JumpTo); + CALL((void*)&ARMv4JumpToTrampoline); PopRegs(restoreCPSR); @@ -269,4 +279,4 @@ void Compiler::T_Comp_BL_Merged() Comp_JumpTo(target); } -} \ No newline at end of file +} -- cgit v1.2.3 From 78839f862e6bd1a8d0a3d99737bd377c5dccf11f Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 9 Nov 2020 20:43:31 +0100 Subject: JIT fixes - fix fastmem problems on linux - small fix memory leak - SlowWrite functions always take in a 32-bit variable so that the C compiler knows that the values aren't necessary zero extended - a few other stylistic things - handle SIGBUS as well (for macos) --- src/ARMJIT.cpp | 14 ++-- src/ARMJIT_A64/ARMJIT_Compiler.h | 4 +- src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 17 ++-- src/ARMJIT_Internal.h | 4 +- src/ARMJIT_Memory.cpp | 153 ++++++++++++++++++++++++------------ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 12 +-- src/ARMJIT_x64/ARMJIT_Compiler.h | 4 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 23 +++--- 8 files changed, 140 insertions(+), 91 deletions(-) (limited to 'src/ARMJIT_x64') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 82f1d79..1921f13 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -176,7 +176,7 @@ T SlowRead9(u32 addr, ARMv5* cpu) } template -void SlowWrite9(u32 addr, ARMv5* cpu, T val) +void SlowWrite9(u32 addr, ARMv5* cpu, u32 val) { addr &= ~(sizeof(T) - 1); @@ -224,7 +224,7 @@ T SlowRead7(u32 addr) } template -void SlowWrite7(u32 addr, T val) +void SlowWrite7(u32 addr, u32 val) { addr &= ~(sizeof(T) - 1); @@ -266,16 +266,16 @@ void SlowBlockTransfer7(u32 addr, u64* data, u32 num) #define INSTANTIATE_SLOWMEM(consoleType) \ template void SlowWrite9(u32, ARMv5*, u32); \ - template void SlowWrite9(u32, ARMv5*, u16); \ - template void SlowWrite9(u32, ARMv5*, u8); \ + template void SlowWrite9(u32, ARMv5*, u32); \ + template void SlowWrite9(u32, ARMv5*, u32); \ \ template u32 SlowRead9(u32, ARMv5*); \ template u16 SlowRead9(u32, ARMv5*); \ template u8 SlowRead9(u32, ARMv5*); \ \ template void SlowWrite7(u32, u32); \ - template void SlowWrite7(u32, u16); \ - template void SlowWrite7(u32, u8); \ + template void SlowWrite7(u32, u32); \ + template void SlowWrite7(u32, u32); \ \ template u32 SlowRead7(u32); \ template u16 SlowRead7(u32); \ @@ -298,6 +298,7 @@ void Init() void DeInit() { + ResetBlockCache(); ARMJIT_Memory::DeInit(); delete JITCompiler; @@ -1117,6 +1118,7 @@ void ResetBlockCache() range->Blocks.Clear(); range->Code = 0; } + delete block; } JitBlocks9.clear(); JitBlocks7.clear(); diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.h b/src/ARMJIT_A64/ARMJIT_Compiler.h index ef40ea4..a79e9da 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.h +++ b/src/ARMJIT_A64/ARMJIT_Compiler.h @@ -214,8 +214,8 @@ public: return (u8*)entry - GetRXBase(); } - bool IsJITFault(u64 pc); - s64 RewriteMemAccess(u64 pc); + bool IsJITFault(u8* pc); + u8* RewriteMemAccess(u8* pc); void SwapCodeRegion() { diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp index 86e257a..2c14dc6 100644 --- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -9,37 +9,34 @@ using namespace Arm64Gen; namespace ARMJIT { -bool Compiler::IsJITFault(u64 pc) +bool Compiler::IsJITFault(u8* pc) { - return pc >= (u64)GetRXBase() && pc - (u64)GetRXBase() < (JitMemMainSize + JitMemSecondarySize); + return (u64)pc >= (u64)GetRXBase() && (u64)pc - (u64)GetRXBase() < (JitMemMainSize + JitMemSecondarySize); } -s64 Compiler::RewriteMemAccess(u64 pc) +u8* Compiler::RewriteMemAccess(u8* pc) { - ptrdiff_t pcOffset = pc - (u64)GetRXBase(); + ptrdiff_t pcOffset = pc - GetRXBase(); auto it = LoadStorePatches.find(pcOffset); if (it != LoadStorePatches.end()) { LoadStorePatch patch = it->second; + LoadStorePatches.erase(it); ptrdiff_t curCodeOffset = GetCodeOffset(); SetCodePtrUnsafe(pcOffset + patch.PatchOffset); BL(patch.PatchFunc); - for (int i = 0; i < patch.PatchSize / 4 - 1; i++) HINT(HINT_NOP); - FlushIcacheSection((u8*)pc + patch.PatchOffset, (u8*)GetRXPtr()); SetCodePtrUnsafe(curCodeOffset); - LoadStorePatches.erase(it); - - return patch.PatchOffset; + return pc + (ptrdiff_t)patch.PatchOffset; } printf("this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc)); abort(); @@ -192,7 +189,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags) else { LDRGeneric(size, flags & memop_SignExtend, rdMapped, size > 8 ? X1 : X0, X7); - if (size == 32) + if (size == 32 && !addrIsStatic) { UBFIZ(W0, W0, 3, 2); RORV(rdMapped, rdMapped, W0); diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index 4244470..b1e35f5 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -216,9 +216,9 @@ template void LinkBlock(ARM* cpu, u32 codeOffset); template T SlowRead9(u32 addr, ARMv5* cpu); -template void SlowWrite9(u32 addr, ARMv5* cpu, T val); +template void SlowWrite9(u32 addr, ARMv5* cpu, u32 val); template T SlowRead7(u32 addr); -template void SlowWrite7(u32 addr, T val); +template void SlowWrite7(u32 addr, u32 val); template void SlowBlockTransfer9(u32 addr, u64* data, u32 num, ARMv5* cpu); template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp index d321d2f..355031e 100644 --- a/src/ARMJIT_Memory.cpp +++ b/src/ARMJIT_Memory.cpp @@ -40,7 +40,8 @@ We handle this by only mapping those regions which are actually used and by praying the games don't go wild. - Beware, this file is full of platform specific code. + Beware, this file is full of platform specific code and copied + from Dolphin, so enjoy the copied comments! */ @@ -49,10 +50,10 @@ namespace ARMJIT_Memory struct FaultDescription { u32 EmulatedFaultAddr; - u64 FaultPC; + u8* FaultPC; }; -bool FaultHandler(FaultDescription* faultDesc, s32& offset); +bool FaultHandler(FaultDescription& faultDesc); } #if defined(__SWITCH__) @@ -75,7 +76,7 @@ void __libnx_exception_handler(ThreadExceptionDump* ctx) ARMJIT_Memory::FaultDescription desc; u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start); desc.EmulatedFaultAddr = (u8*)ctx->far.x - curArea; - desc.FaultPC = ctx->pc.x; + desc.FaultPC = (u8*)ctx->pc.x; u64 integerRegisters[33]; memcpy(integerRegisters, &ctx->cpu_gprs[0].x, 8*29); @@ -84,10 +85,9 @@ void __libnx_exception_handler(ThreadExceptionDump* ctx) integerRegisters[31] = ctx->sp.x; integerRegisters[32] = ctx->pc.x; - s32 offset; - if (ARMJIT_Memory::FaultHandler(&desc, offset)) + if (ARMJIT_Memory::FaultHandler(desc, offset)) { - integerRegisters[32] += offset; + integerRegisters[32] = (u64)desc.FaultPC; ARM_RestoreContext(integerRegisters); } @@ -117,12 +117,11 @@ static LONG ExceptionHandler(EXCEPTION_POINTERS* exceptionInfo) ARMJIT_Memory::FaultDescription desc; u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start); desc.EmulatedFaultAddr = (u8*)exceptionInfo->ExceptionRecord->ExceptionInformation[1] - curArea; - desc.FaultPC = exceptionInfo->ContextRecord->Rip; + desc.FaultPC = (u8*)exceptionInfo->ContextRecord->Rip; - s32 offset = 0; - if (ARMJIT_Memory::FaultHandler(&desc, offset)) + if (ARMJIT_Memory::FaultHandler(desc)) { - exceptionInfo->ContextRecord->Rip += offset; + exceptionInfo->ContextRecord->Rip = (u8*)desc.FaultPC; return EXCEPTION_CONTINUE_EXECUTION; } @@ -131,50 +130,66 @@ static LONG ExceptionHandler(EXCEPTION_POINTERS* exceptionInfo) #else -struct sigaction NewSa; -struct sigaction OldSa; +static struct sigaction OldSaSegv; +static struct sigaction OldSaBus; static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext) { + if (sig != SIGSEGV && sig != SIGBUS) + { + // We are not interested in other signals - handle it as usual. + return; + } + if (info->si_code != SEGV_MAPERR && info->si_code != SEGV_ACCERR) + { + // Huh? Return. + return; + } + ucontext_t* context = (ucontext_t*)rawContext; - + ARMJIT_Memory::FaultDescription desc; u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start); #ifdef __x86_64__ desc.EmulatedFaultAddr = (u8*)info->si_addr - curArea; - desc.FaultPC = context->uc_mcontext.gregs[REG_RIP]; + desc.FaultPC = (u8*)context->uc_mcontext.gregs[REG_RIP]; #else desc.EmulatedFaultAddr = (u8*)context->uc_mcontext.fault_address - curArea; - desc.FaultPC = context->uc_mcontext.pc; + desc.FaultPC = (u8*)context->uc_mcontext.pc; #endif - s32 offset = 0; - if (ARMJIT_Memory::FaultHandler(&desc, offset)) + if (ARMJIT_Memory::FaultHandler(desc)) { #ifdef __x86_64__ - context->uc_mcontext.gregs[REG_RIP] += offset; + context->uc_mcontext.gregs[REG_RIP] = (u64)desc.FaultPC; #else - context->uc_mcontext.pc += offset; + context->uc_mcontext.pc = (u64)desc.FaultPC; #endif return; } - if (OldSa.sa_flags & SA_SIGINFO) + struct sigaction* oldSa; + if (sig == SIGSEGV) + oldSa = &OldSaSegv; + else + oldSa = &OldSaBus; + + if (oldSa->sa_flags & SA_SIGINFO) { - OldSa.sa_sigaction(sig, info, rawContext); + oldSa->sa_sigaction(sig, info, rawContext); return; } - if (OldSa.sa_handler == SIG_DFL) + if (oldSa->sa_handler == SIG_DFL) { signal(sig, SIG_DFL); return; } - if (OldSa.sa_handler == SIG_IGN) + if (oldSa->sa_handler == SIG_IGN) { // Ignore signal return; } - OldSa.sa_handler(sig); + oldSa->sa_handler(sig); } #endif @@ -231,7 +246,7 @@ enum { memstate_Unmapped, memstate_MappedRW, - // on switch this is unmapped as well + // on Switch this is unmapped as well memstate_MappedProtected, }; @@ -505,6 +520,21 @@ bool MapAtAddress(u32 addr) bool isExecutable = ARMJIT::CodeMemRegions[region]; #ifndef __SWITCH__ + if (num == 0) + { + // if a DTCM mapping is mapped before the mapping below it + // we unmap it, so it won't just be overriden + for (int i = 0; i < Mappings[memregion_DTCM].Length; i++) + { + Mapping& mapping = Mappings[memregion_DTCM][i]; + if (mirrorStart < mapping.Addr + mapping.Size && mirrorStart + mirrorSize >= mapping.Addr) + { + mapping.Unmap(memregion_DTCM); + } + } + Mappings[memregion_DTCM].Clear(); + } + bool succeded = MapIntoRange(mirrorStart, num, OffsetsPerRegion[region] + memoryOffset, mirrorSize); assert(succeded); #endif @@ -562,21 +592,20 @@ bool MapAtAddress(u32 addr) return true; } -bool FaultHandler(FaultDescription* faultDesc, s32& offset) +bool FaultHandler(FaultDescription& faultDesc) { - if (ARMJIT::JITCompiler->IsJITFault(faultDesc->FaultPC)) + if (ARMJIT::JITCompiler->IsJITFault(faultDesc.FaultPC)) { bool rewriteToSlowPath = true; - u32 addr = faultDesc->EmulatedFaultAddr; + u8* memStatus = NDS::CurCPU == 0 ? MappingStatus9 : MappingStatus7; - if ((NDS::CurCPU == 0 ? MappingStatus9 : MappingStatus7)[addr >> 12] == memstate_Unmapped) - rewriteToSlowPath = !MapAtAddress(faultDesc->EmulatedFaultAddr); + if (memStatus[faultDesc.EmulatedFaultAddr >> 12] == memstate_Unmapped) + rewriteToSlowPath = !MapAtAddress(faultDesc.EmulatedFaultAddr); if (rewriteToSlowPath) - { - offset = ARMJIT::JITCompiler->RewriteMemAccess(faultDesc->FaultPC); - } + faultDesc.FaultPC = ARMJIT::JITCompiler->RewriteMemAccess(faultDesc.FaultPC); + return true; } return false; @@ -624,22 +653,28 @@ void Init() u8* basePtr = MemoryBase; #else - FastMem9Start = mmap(NULL, AddrSpaceSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); - FastMem7Start = mmap(NULL, AddrSpaceSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); - - MemoryBase = (u8*)mmap(NULL, MemoryTotalSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); + // this used to be allocated with three different mmaps + // The idea was to give the OS more freedom where to position the buffers, + // but something was bad about this so instead we take this vmem eating monster + // which seems to work better. + MemoryBase = (u8*)mmap(NULL, AddrSpaceSize*4, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); + munmap(MemoryBase, AddrSpaceSize*4); + FastMem9Start = MemoryBase; + FastMem7Start = MemoryBase + AddrSpaceSize; + MemoryBase = MemoryBase + AddrSpaceSize*2; MemoryFile = memfd_create("melondsfastmem", 0); ftruncate(MemoryFile, MemoryTotalSize); - NewSa.sa_flags = SA_SIGINFO; - sigemptyset(&NewSa.sa_mask); - NewSa.sa_sigaction = SigsegvHandler; - sigaction(SIGSEGV, &NewSa, &OldSa); - - munmap(MemoryBase, MemoryTotalSize); - munmap(FastMem9Start, AddrSpaceSize); - munmap(FastMem7Start, AddrSpaceSize); + struct sigaction sa; + sa.sa_handler = nullptr; + sa.sa_sigaction = &SigsegvHandler; + sa.sa_flags = SA_SIGINFO; + sigemptyset(&sa.sa_mask); + sigaction(SIGSEGV, &sa, &OldSaSegv); +#ifdef __APPLE__ + sigaction(SIGBUS, &sa, &OldSaBus); +#endif mmap(MemoryBase, MemoryTotalSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, MemoryFile, 0); @@ -657,8 +692,8 @@ void Init() void DeInit() { #if defined(__SWITCH__) - virtmemFree(FastMem9Start, 0x100000000); - virtmemFree(FastMem7Start, 0x100000000); + virtmemFree(FastMem9Start, AddrSpaceSize); + virtmemFree(FastMem7Start, AddrSpaceSize); svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64)MemoryBaseCodeMem, (u64)MemoryBase, MemoryTotalSize); virtmemFree(MemoryBaseCodeMem, MemoryTotalSize); @@ -668,6 +703,14 @@ void DeInit() CloseHandle(MemoryFile); RemoveVectoredExceptionHandler(ExceptionHandlerHandle); +#else + sigaction(SIGSEGV, &OldSaSegv, nullptr); +#ifdef __APPLE__ + sigaction(SIGBUS, &OldSaBus, nullptr); +#endif + + munmap(MemoryBase, MemoryTotalSize); + close(MemoryFile); #endif } @@ -702,7 +745,15 @@ bool IsFastmemCompatible(int region) || region == memregion_NewSharedWRAM_C) return false; #endif - return OffsetsPerRegion[region] != UINT32_MAX; + if (region == memregion_DTCM + || region == memregion_MainRAM + || region == memregion_NewSharedWRAM_A + || region == memregion_NewSharedWRAM_B + || region == memregion_NewSharedWRAM_C + || region == memregion_SharedWRAM) + return false; + //return OffsetsPerRegion[region] != UINT32_MAX; + return false; } bool GetMirrorLocation(int region, u32 num, u32 addr, u32& memoryOffset, u32& mirrorStart, u32& mirrorSize) @@ -997,9 +1048,11 @@ int ClassifyAddress7(u32 addr) case 0x06000000: case 0x06800000: return memregion_VWRAM; + + default: + return memregion_Other; } } - return memregion_Other; } void WifiWrite32(u32 addr, u32 val) diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 9785ffc..076f48c 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -345,7 +345,7 @@ Compiler::Compiler() ABI_PushRegistersAndAdjustStack(CallerSavedPushRegs, 8); if (consoleType == 0) { - switch ((8 << size) | num) + switch ((8 << size) | num) { case 32: ABI_CallFunction(SlowWrite9); break; case 33: ABI_CallFunction(SlowWrite7); break; @@ -357,7 +357,7 @@ Compiler::Compiler() } else { - switch ((8 << size) | num) + switch ((8 << size) | num) { case 32: ABI_CallFunction(SlowWrite9); break; case 33: ABI_CallFunction(SlowWrite7); break; @@ -380,7 +380,7 @@ Compiler::Compiler() ABI_PushRegistersAndAdjustStack(CallerSavedPushRegs, 8); if (consoleType == 0) { - switch ((8 << size) | num) + switch ((8 << size) | num) { case 32: ABI_CallFunction(SlowRead9); break; case 33: ABI_CallFunction(SlowRead7); break; @@ -392,7 +392,7 @@ Compiler::Compiler() } else { - switch ((8 << size) | num) + switch ((8 << size) | num) { case 32: ABI_CallFunction(SlowRead9); break; case 33: ABI_CallFunction(SlowRead7); break; @@ -617,9 +617,9 @@ void Compiler::Reset() LoadStorePatches.clear(); } -bool Compiler::IsJITFault(u64 addr) +bool Compiler::IsJITFault(u8* addr) { - return addr >= (u64)CodeMemory && addr < (u64)CodeMemory + sizeof(CodeMemory); + return (u64)addr >= (u64)ResetStart && (u64)addr < (u64)ResetStart + CodeMemSize; } void Compiler::Comp_SpecialBranchBehaviour(bool taken) diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 3e900c3..57aab7b 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -208,9 +208,9 @@ public: SetCodePtr(FarCode); } - bool IsJITFault(u64 addr); + bool IsJITFault(u8* addr); - s32 RewriteMemAccess(u64 pc); + u8* RewriteMemAccess(u8* pc); u8* FarCode; u8* NearCode; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 8b4e8fe..d80b25b 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -15,28 +15,24 @@ int squeezePointer(T* ptr) return truncated; } -s32 Compiler::RewriteMemAccess(u64 pc) +u8* Compiler::RewriteMemAccess(u8* pc) { - auto it = LoadStorePatches.find((u8*)pc); + auto it = LoadStorePatches.find(pc); if (it != LoadStorePatches.end()) { LoadStorePatch patch = it->second; LoadStorePatches.erase(it); - u8* curCodePtr = GetWritableCodePtr(); - u8* rewritePtr = (u8*)pc + (ptrdiff_t)patch.Offset; - SetCodePtr(rewritePtr); + //printf("rewriting memory access %p %d %d\n", (u8*)pc-ResetStart, patch.Offset, patch.Size); - CALL(patch.PatchFunc); - u32 remainingSize = patch.Size - (GetWritableCodePtr() - rewritePtr); + XEmitter emitter(pc + (ptrdiff_t)patch.Offset); + emitter.CALL(patch.PatchFunc); + ptrdiff_t remainingSize = (ptrdiff_t)patch.Size - 5; + assert(remainingSize >= 0); if (remainingSize > 0) - NOP(remainingSize); + emitter.NOP(remainingSize); - //printf("rewriting memory access %p %d %d\n", patch.PatchFunc, patch.Offset, patch.Size); - - SetCodePtr(curCodePtr); - - return patch.Offset; + return pc + (ptrdiff_t)patch.Offset; } printf("this is a JIT bug %llx\n", pc); @@ -192,6 +188,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, const Op2& op2, int size, int flag u8* memopStart = GetWritableCodePtr(); LoadStorePatch patch; + assert(rdMapped.GetSimpleReg() >= 0 && rdMapped.GetSimpleReg() < 16); patch.PatchFunc = flags & memop_Store ? PatchedStoreFuncs[NDS::ConsoleType][Num][__builtin_ctz(size) - 3][rdMapped.GetSimpleReg()] : PatchedLoadFuncs[NDS::ConsoleType][Num][__builtin_ctz(size) - 3][!!(flags & memop_SignExtend)][rdMapped.GetSimpleReg()]; -- cgit v1.2.3 From 7da4550eea43a5ec83d1afc88022aaa62827febc Mon Sep 17 00:00:00 2001 From: WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com> Date: Sun, 29 Nov 2020 08:11:33 -0800 Subject: Add support for macOS (#771) * use shm_open() instead of memfd_create() on macOS malloc.h isn't a header on macOS * Change OpenGL headers + create ifdef for DO_PROCLIST macOS seems to already have the OpenGL functions defined, without the ifdef, it gives "ambiguous references" errors. * macOS doesn't have ->gregs in uc_mcontext and it doesn't have REG_RIP either https://github.com/gperftools/gperftools/blob/master/m4/pc_from_ucontext.m4 * use getpid() to make memory file name unique * #ifndef __APPLE__ for AF_PACKET and linux/if_packet.h * Add include and link directories for macOS and link the OpenGL framework * Add macOS CI * Use newly added libslirp package from Homebrew https://github.com/Homebrew/homebrew-core/pull/63412 * Use Apple's Clang instead of GNU GCC on macOS * Add macOS build instructions to README * Try to fix macOS undefined symbol * snprintf doesn't take null terminator into account * Map new memory on macOS for JIT * Only use gcc-ar if using GNU Compiler * re-add fastmem code - whoops! * Fix style issue - use camelCase not snake_case * Set Minimum macOS version * Switch Minimum OS X version to 10.9 * Add macOS libpcap library name * fix memory leak * Fix binding keys in macOS * Allow getting MAC address on macOS melonDS on Linux uses AF_PACKET, which doesn't exist on macOS. Instead, this commit uses AF_LINK on macOS to get the MAC address. * Remove unneeded macOS CI dependencies * Build melonDS app bundle on macOS Now it is no longer required to install the libraries on macOS, they come with the app bundle. * fix macOS CI not being able to find macdeployqt * copy melonDS.app with recursive because it's a folder * Disable fastmem checkbox on macOS * Disable fastmem by default in config * forgot a semicolon * Don't bundle libraries, causes issues on macOS <10.15 * Update README + allow finding version in Finder on macOS * Make sure fastmem checkbox stays uncheckable --- .github/workflows/build-macos.yml | 39 ++++++++++++++++++++++++++++++ CMakeLists.txt | 4 ++- README.md | 15 ++++++++++++ melonDS.icns | Bin 0 -> 401172 bytes melonDS.plist | 24 ++++++++++++++++++ src/ARMJIT_Memory.cpp | 31 +++++++++++++++++++++--- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 2 ++ src/ARMJIT_x64/ARMJIT_Linkage.s | 10 ++++++++ src/CMakeLists.txt | 9 ++++++- src/Config.cpp | 6 ++++- src/OpenGLSupport.h | 15 ++++++++++-- src/frontend/qt_sdl/CMakeLists.txt | 15 +++++++++++- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 7 +++++- src/frontend/qt_sdl/InputConfigDialog.cpp | 1 + src/frontend/qt_sdl/LAN_PCap.cpp | 21 ++++++++++++++-- 15 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build-macos.yml create mode 100644 melonDS.icns create mode 100644 melonDS.plist (limited to 'src/ARMJIT_x64') diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml new file mode 100644 index 0000000..e2b942a --- /dev/null +++ b/.github/workflows/build-macos.yml @@ -0,0 +1,39 @@ +name: CMake Build (macOS x86-64) + +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + BUILD_TYPE: Release + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v1 + - name: Install dependencies + working-directory: ${{runner.workspace}} + run: | + brew install cmake sdl2 qt5 libslirp + - name: Create build environment + run: mkdir ${{runner.workspace}}/build + - name: Configure + working-directory: ${{runner.workspace}}/build + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 + - name: Make + working-directory: ${{runner.workspace}}/build + run: | + make -j$(sysctl -n hw.ncpu) + mkdir dist + cp -r melonDS.app dist + - uses: actions/upload-artifact@v1 + with: + name: melonDS.app + path: ${{runner.workspace}}/build/dist diff --git a/CMakeLists.txt b/CMakeLists.txt index 04ad2a5..fcd4741 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ if (POLICY CMP0076) cmake_policy(SET CMP0076 NEW) endif() +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") + project(melonDS CXX) set(CMAKE_C_STANDARD 11) @@ -100,4 +102,4 @@ add_subdirectory(src) if (BUILD_QT_SDL) add_subdirectory(src/frontend/qt_sdl) -endif() +endif() \ No newline at end of file diff --git a/README.md b/README.md index 2fb2315..64489db 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ If everything went well, melonDS and the libraries it needs should now be in the ``` If everything went well, melonDS should now be in the `dist` folder. +### macOS: +1. Install the [Homebrew Package Manager](https://brew.sh) +2. Install dependencies: `brew install git pkg-config cmake sdl2 qt5 libslirp` +3. Compile: + ```zsh + git clone https://github.com/Arisotura/melonDS.git + cd melonDS + mkdir build && cd build + cmake .. -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 + make -j$(sysctl -n hw.ncpu) + mkdir dist && cp -r melonDS.app dist + ``` +If everything went well, melonDS.app should now be in the `dist` folder. + + ## TODO LIST * DSi emulation diff --git a/melonDS.icns b/melonDS.icns new file mode 100644 index 0000000..b4f3733 Binary files /dev/null and b/melonDS.icns differ diff --git a/melonDS.plist b/melonDS.plist new file mode 100644 index 0000000..1328777 --- /dev/null +++ b/melonDS.plist @@ -0,0 +1,24 @@ + + + + + CFBundleExecutable + melonDS + CFBundleIconFile + melonDS.icns + CFBundleIdentifier + net.kuribo64.melonDS + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleVersion + 0.9 + CFBundleShortVersionString + 0.9 + NSHumanReadableCopyright + Licensed under GPLv3 + NSHighResolutionCapable + + + \ No newline at end of file diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp index 70d18e6..cc0f149 100644 --- a/src/ARMJIT_Memory.cpp +++ b/src/ARMJIT_Memory.cpp @@ -22,7 +22,9 @@ #include "NDSCart.h" #include "SPU.h" +#ifndef __APPLE__ #include +#endif /* We're handling fastmem here. @@ -152,7 +154,12 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext) u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start); #ifdef __x86_64__ desc.EmulatedFaultAddr = (u8*)info->si_addr - curArea; - desc.FaultPC = (u8*)context->uc_mcontext.gregs[REG_RIP]; + #ifdef __APPLE__ + desc.FaultPC = (u8*)context->uc_mcontext->__ss.__rip; + #else + desc.FaultPC = (u8*)context->uc_mcontext.gregs[REG_RIP]; + #endif + #else desc.EmulatedFaultAddr = (u8*)context->uc_mcontext.fault_address - curArea; desc.FaultPC = (u8*)context->uc_mcontext.pc; @@ -161,7 +168,11 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext) if (ARMJIT_Memory::FaultHandler(desc)) { #ifdef __x86_64__ - context->uc_mcontext.gregs[REG_RIP] = (u64)desc.FaultPC; + #ifdef __APPLE__ + context->uc_mcontext->__ss.__rip = (u64)desc.FaultPC; + #else + context->uc_mcontext.gregs[REG_RIP] = (u64)desc.FaultPC; + #endif #else context->uc_mcontext.pc = (u64)desc.FaultPC; #endif @@ -701,7 +712,14 @@ void Init() FastMem7Start = MemoryBase + AddrSpaceSize; MemoryBase = MemoryBase + AddrSpaceSize*2; - MemoryFile = memfd_create("melondsfastmem", 0); + #ifdef __APPLE__ + char* fastmemPidName = new char[snprintf(NULL, 0, "melondsfastmem%d", getpid()) + 1]; + sprintf(fastmemPidName, "melondsfastmem%d", getpid()); + MemoryFile = shm_open(fastmemPidName, O_RDWR|O_CREAT, 0600); + delete[] fastmemPidName; + #else + MemoryFile = memfd_create("melondsfastmem", 0); + #endif ftruncate(MemoryFile, MemoryTotalSize); struct sigaction sa; @@ -736,6 +754,11 @@ void DeInit() svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64)MemoryBaseCodeMem, (u64)MemoryBase, MemoryTotalSize); virtmemFree(MemoryBaseCodeMem, MemoryTotalSize); free(MemoryBase); +#elif defined(__APPLE__) + char* fastmemPidName = new char[snprintf(NULL, 0, "melondsfastmem%d", getpid()) + 1]; + sprintf(fastmemPidName, "melondsfastmem%d", getpid()); + shm_unlink(fastmemPidName); + delete[] fastmemPidName; #elif defined(_WIN32) assert(UnmapViewOfFile(MemoryBase)); CloseHandle(MemoryFile); @@ -1259,4 +1282,4 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) return NULL; } -} \ No newline at end of file +} diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 076f48c..cc4ad80 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -221,6 +221,8 @@ Compiler::Compiler() #ifdef _WIN32 DWORD dummy; VirtualProtect(pageAligned, alignedSize, PAGE_EXECUTE_READWRITE, &dummy); + #elif defined(__APPLE__) + pageAligned = (u8*)mmap(NULL, 1024*1024*32, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS ,-1, 0); #else mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); #endif diff --git a/src/ARMJIT_x64/ARMJIT_Linkage.s b/src/ARMJIT_x64/ARMJIT_Linkage.s index 0a84df0..8cc0b5f 100644 --- a/src/ARMJIT_x64/ARMJIT_Linkage.s +++ b/src/ARMJIT_x64/ARMJIT_Linkage.s @@ -29,8 +29,13 @@ .p2align 4,,15 +#ifdef __APPLE__ +.global _ARM_Dispatch +_ARM_Dispatch: +#else .global ARM_Dispatch ARM_Dispatch: +#endif #ifdef WIN64 push rdi push rsi @@ -54,8 +59,13 @@ ARM_Dispatch: .p2align 4,,15 +#ifdef __APPLE__ +.global _ARM_Ret +_ARM_Ret: +#else .global ARM_Ret ARM_Ret: +#endif mov [RCPU + ARM_CPSR_offset], RCPSR #ifdef WIN64 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6c3897..446480d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,10 +100,17 @@ if (ENABLE_JIT) endif() endif() +if (APPLE) + target_include_directories(core PUBLIC /usr/local/include) + target_link_directories(core PUBLIC /usr/local/lib) +endif() + if (ENABLE_OGLRENDERER) if (WIN32) target_link_libraries(core ole32 comctl32 ws2_32 opengl32) - else() + elseif (APPLE) + target_link_libraries(core "-framework OpenGL") + else() target_link_libraries(core GL EGL) endif() else() diff --git a/src/Config.cpp b/src/Config.cpp index 341b14c..f7db252 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -73,7 +73,11 @@ ConfigEntry ConfigFile[] = {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, {"JIT_BranchOptimisations", 0, &JIT_BranchOptimisations, 1, NULL, 0}, {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, - {"JIT_FastMemory", 0, &JIT_FastMemory, 1, NULL, 0}, + #ifdef __APPLE__ + {"JIT_FastMemory", 0, &JIT_FastMemory, 0, NULL, 0}, + #else + {"JIT_FastMemory", 0, &JIT_FastMemory, 1, NULL, 0}, + #endif #endif {"", -1, NULL, 0, NULL, 0} diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index 925c0ad..44c511f 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -23,8 +23,13 @@ #include // TODO: different includes for each platform -#include -#include +#ifdef __APPLE__ + #include + #include +#else + #include + #include +#endif #include "Platform.h" @@ -61,6 +66,11 @@ #endif +#ifdef __APPLE__ + +#define DO_PROCLIST(func) + +#else #define DO_PROCLIST(func) \ DO_PROCLIST_1_3(func) \ @@ -128,6 +138,7 @@ \ func(GLGETSTRINGI, glGetStringi); \ +#endif namespace OpenGL { diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 9a0a025..0d695d6 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -95,6 +95,19 @@ if (PORTABLE) add_definitions(-DPORTABLE) endif() +if (APPLE) + set_target_properties(melonDS PROPERTIES + MACOSX_BUNDLE true + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/melonDS.plist + OUTPUT_NAME melonDS + ) + + # Copy icon into the bundle + target_sources(melonDS PRIVATE "${CMAKE_SOURCE_DIR}/melonDS.icns") + set_source_files_properties("${CMAKE_SOURCE_DIR}/melonDS.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + +endif() + install(FILES ../../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) install(FILES ../../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) @@ -102,4 +115,4 @@ install(FILES ../../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/ install(FILES ../../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) -install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +install(TARGETS melonDS BUNDLE DESTINATION ${CMAKE_BINARY_DIR} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 79ce5ed..3183182 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -65,6 +65,9 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->chkJITBranchOptimisations->setChecked(Config::JIT_BranchOptimisations != 0); ui->chkJITLiteralOptimisations->setChecked(Config::JIT_LiteralOptimisations != 0); ui->chkJITFastMemory->setChecked(Config::JIT_FastMemory != 0); + #ifdef __APPLE__ + ui->chkJITFastMemory->setDisabled(true); + #endif ui->spnJITMaximumBlockSize->setValue(Config::JIT_MaxBlockSize); #else ui->chkEnableJIT->setDisabled(true); @@ -329,6 +332,8 @@ void EmuSettingsDialog::on_chkEnableJIT_toggled() bool disabled = !ui->chkEnableJIT->isChecked(); ui->chkJITBranchOptimisations->setDisabled(disabled); ui->chkJITLiteralOptimisations->setDisabled(disabled); - ui->chkJITFastMemory->setDisabled(disabled); + #ifndef __APPLE__ + ui->chkJITFastMemory->setDisabled(disabled); + #endif ui->spnJITMaximumBlockSize->setDisabled(disabled); } diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 9f08731..eaf1e9b 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -216,6 +216,7 @@ KeyMapButton::KeyMapButton(int* mapping, bool hotkey) : QPushButton() setCheckable(true); setText(mappingText()); + setFocusPolicy(Qt::StrongFocus); //Fixes binding keys in macOS connect(this, &KeyMapButton::clicked, this, &KeyMapButton::onClick); } diff --git a/src/frontend/qt_sdl/LAN_PCap.cpp b/src/frontend/qt_sdl/LAN_PCap.cpp index ce278bc..8138699 100644 --- a/src/frontend/qt_sdl/LAN_PCap.cpp +++ b/src/frontend/qt_sdl/LAN_PCap.cpp @@ -33,7 +33,11 @@ #include #include #include - #include + #ifdef __APPLE__ + #include + #else + #include + #endif #endif @@ -66,6 +70,9 @@ const char* PCapLibNames[] = #ifdef __WIN32__ // TODO: name for npcap in non-WinPCap mode "wpcap.dll", +#elif defined(__APPLE__) + "libpcap.A.dylib", + "libpcap.dylib", #else // Linux lib names "libpcap.so.1", @@ -276,6 +283,16 @@ bool Init(bool open_adapter) struct sockaddr_in* sa = (sockaddr_in*)curaddr->ifa_addr; memcpy(adata->IP_v4, &sa->sin_addr, 4); } + #ifdef __APPLE__ + else if (af == AF_LINK) + { + struct sockaddr_dl* sa = (sockaddr_dl*)curaddr->ifa_addr; + if (sa->sdl_alen != 6) + printf("weird MAC length %d for %s\n", sa->sdl_alen, curaddr->ifa_name); + else + memcpy(adata->MAC, LLADDR(sa), 6); + } + #else else if (af == AF_PACKET) { struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr; @@ -284,7 +301,7 @@ bool Init(bool open_adapter) else memcpy(adata->MAC, sa->sll_addr, 6); } - + #endif curaddr = curaddr->ifa_next; } } -- cgit v1.2.3 From 298b958e2a105ba29f07ee110cd9f856da1f66d7 Mon Sep 17 00:00:00 2001 From: webgeek1234 Date: Tue, 1 Dec 2020 12:48:46 -0600 Subject: Rename jit linkage asm files (#836) An extension of lower case s indicates to not run the preprocessor while upper case S does. These files have defines. --- src/ARMJIT_A64/ARMJIT_Linkage.S | 68 +++++++++++++++++++++++++++++++ src/ARMJIT_A64/ARMJIT_Linkage.s | 68 ------------------------------- src/ARMJIT_x64/ARMJIT_Linkage.S | 88 +++++++++++++++++++++++++++++++++++++++++ src/ARMJIT_x64/ARMJIT_Linkage.s | 88 ----------------------------------------- src/CMakeLists.txt | 6 +-- 5 files changed, 158 insertions(+), 160 deletions(-) create mode 100644 src/ARMJIT_A64/ARMJIT_Linkage.S delete mode 100644 src/ARMJIT_A64/ARMJIT_Linkage.s create mode 100644 src/ARMJIT_x64/ARMJIT_Linkage.S delete mode 100644 src/ARMJIT_x64/ARMJIT_Linkage.s (limited to 'src/ARMJIT_x64') diff --git a/src/ARMJIT_A64/ARMJIT_Linkage.S b/src/ARMJIT_A64/ARMJIT_Linkage.S new file mode 100644 index 0000000..7886315 --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_Linkage.S @@ -0,0 +1,68 @@ +#include "../ARMJIT_x64/ARMJIT_Offsets.h" + +.text + +#define RCPSR w27 +#define RCycles w28 +#define RCPU x29 + +.p2align 4,,15 + +.global ARM_Dispatch +ARM_Dispatch: + stp x19, x20, [sp, #-96]! + stp x21, x22, [sp, #16] + stp x23, x24, [sp, #32] + stp x25, x26, [sp, #48] + stp x27, x28, [sp, #64] + stp x29, x30, [sp, #80] + + mov RCPU, x0 + ldr RCycles, [RCPU, ARM_Cycles_offset] + ldr RCPSR, [RCPU, ARM_CPSR_offset] + + br x1 + +.p2align 4,,15 + +.global ARM_Ret +ARM_Ret: + str RCycles, [RCPU, ARM_Cycles_offset] + str RCPSR, [RCPU, ARM_CPSR_offset] + + ldp x29, x30, [sp, #80] + ldp x27, x28, [sp, #64] + ldp x25, x26, [sp, #48] + ldp x23, x24, [sp, #32] + ldp x21, x22, [sp, #16] + ldp x19, x20, [sp], #96 + + ret + +.p2align 4,,15 + +.global ARM_RestoreContext +ARM_RestoreContext: + mov sp, x0 + + ldp x0, x1, [sp] + ldp x2, x3, [sp, #16] + ldp x4, x5, [sp, #32] + ldp x6, x7, [sp, #48] + ldp x8, x9, [sp, #64] + ldp x10, x11, [sp, #80] + ldp x12, x13, [sp, #96] + ldp x14, x15, [sp, #112] + ldp x16, x17, [sp, #128] + ldp x18, x19, [sp, #144] + ldp x20, x21, [sp, #160] + ldp x22, x23, [sp, #176] + ldp x24, x25, [sp, #192] + ldp x26, x27, [sp, #208] + ldp x28, x29, [sp, #224] + ldr x30, [sp, #240] + + ldp x17, x18, [sp, #248] + mov sp, x17 + + br x18 \ No newline at end of file diff --git a/src/ARMJIT_A64/ARMJIT_Linkage.s b/src/ARMJIT_A64/ARMJIT_Linkage.s deleted file mode 100644 index 7886315..0000000 --- a/src/ARMJIT_A64/ARMJIT_Linkage.s +++ /dev/null @@ -1,68 +0,0 @@ -#include "../ARMJIT_x64/ARMJIT_Offsets.h" - -.text - -#define RCPSR w27 -#define RCycles w28 -#define RCPU x29 - -.p2align 4,,15 - -.global ARM_Dispatch -ARM_Dispatch: - stp x19, x20, [sp, #-96]! - stp x21, x22, [sp, #16] - stp x23, x24, [sp, #32] - stp x25, x26, [sp, #48] - stp x27, x28, [sp, #64] - stp x29, x30, [sp, #80] - - mov RCPU, x0 - ldr RCycles, [RCPU, ARM_Cycles_offset] - ldr RCPSR, [RCPU, ARM_CPSR_offset] - - br x1 - -.p2align 4,,15 - -.global ARM_Ret -ARM_Ret: - str RCycles, [RCPU, ARM_Cycles_offset] - str RCPSR, [RCPU, ARM_CPSR_offset] - - ldp x29, x30, [sp, #80] - ldp x27, x28, [sp, #64] - ldp x25, x26, [sp, #48] - ldp x23, x24, [sp, #32] - ldp x21, x22, [sp, #16] - ldp x19, x20, [sp], #96 - - ret - -.p2align 4,,15 - -.global ARM_RestoreContext -ARM_RestoreContext: - mov sp, x0 - - ldp x0, x1, [sp] - ldp x2, x3, [sp, #16] - ldp x4, x5, [sp, #32] - ldp x6, x7, [sp, #48] - ldp x8, x9, [sp, #64] - ldp x10, x11, [sp, #80] - ldp x12, x13, [sp, #96] - ldp x14, x15, [sp, #112] - ldp x16, x17, [sp, #128] - ldp x18, x19, [sp, #144] - ldp x20, x21, [sp, #160] - ldp x22, x23, [sp, #176] - ldp x24, x25, [sp, #192] - ldp x26, x27, [sp, #208] - ldp x28, x29, [sp, #224] - ldr x30, [sp, #240] - - ldp x17, x18, [sp, #248] - mov sp, x17 - - br x18 \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Linkage.S b/src/ARMJIT_x64/ARMJIT_Linkage.S new file mode 100644 index 0000000..8cc0b5f --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Linkage.S @@ -0,0 +1,88 @@ +.intel_syntax noprefix + +#include "ARMJIT_Offsets.h" + +.text + +#define RCPU rbp +#define RCPSR r15d + +#ifdef WIN64 +#define ARG1_REG ecx +#define ARG2_REG edx +#define ARG3_REG r8d +#define ARG4_REG r9d +#define ARG1_REG64 rcx +#define ARG2_REG64 rdx +#define ARG3_REG64 r8 +#define ARG4_REG64 r9 +#else +#define ARG1_REG edi +#define ARG2_REG esi +#define ARG3_REG edx +#define ARG4_REG ecx +#define ARG1_REG64 rdi +#define ARG2_REG64 rsi +#define ARG3_REG64 rdx +#define ARG4_REG64 rcx +#endif + +.p2align 4,,15 + +#ifdef __APPLE__ +.global _ARM_Dispatch +_ARM_Dispatch: +#else +.global ARM_Dispatch +ARM_Dispatch: +#endif +#ifdef WIN64 + push rdi + push rsi +#endif + push rbx + push r12 + push r13 + push r14 + push r15 + push rbp + +#ifdef WIN64 + sub rsp, 0x28 +#else + sub rsp, 0x8 +#endif + mov RCPU, ARG1_REG64 + mov RCPSR, [RCPU + ARM_CPSR_offset] + + jmp ARG2_REG64 + +.p2align 4,,15 + +#ifdef __APPLE__ +.global _ARM_Ret +_ARM_Ret: +#else +.global ARM_Ret +ARM_Ret: +#endif + mov [RCPU + ARM_CPSR_offset], RCPSR + +#ifdef WIN64 + add rsp, 0x28 +#else + add rsp, 0x8 +#endif + + pop rbp + pop r15 + pop r14 + pop r13 + pop r12 + pop rbx +#ifdef WIN64 + pop rsi + pop rdi +#endif + + ret diff --git a/src/ARMJIT_x64/ARMJIT_Linkage.s b/src/ARMJIT_x64/ARMJIT_Linkage.s deleted file mode 100644 index 8cc0b5f..0000000 --- a/src/ARMJIT_x64/ARMJIT_Linkage.s +++ /dev/null @@ -1,88 +0,0 @@ -.intel_syntax noprefix - -#include "ARMJIT_Offsets.h" - -.text - -#define RCPU rbp -#define RCPSR r15d - -#ifdef WIN64 -#define ARG1_REG ecx -#define ARG2_REG edx -#define ARG3_REG r8d -#define ARG4_REG r9d -#define ARG1_REG64 rcx -#define ARG2_REG64 rdx -#define ARG3_REG64 r8 -#define ARG4_REG64 r9 -#else -#define ARG1_REG edi -#define ARG2_REG esi -#define ARG3_REG edx -#define ARG4_REG ecx -#define ARG1_REG64 rdi -#define ARG2_REG64 rsi -#define ARG3_REG64 rdx -#define ARG4_REG64 rcx -#endif - -.p2align 4,,15 - -#ifdef __APPLE__ -.global _ARM_Dispatch -_ARM_Dispatch: -#else -.global ARM_Dispatch -ARM_Dispatch: -#endif -#ifdef WIN64 - push rdi - push rsi -#endif - push rbx - push r12 - push r13 - push r14 - push r15 - push rbp - -#ifdef WIN64 - sub rsp, 0x28 -#else - sub rsp, 0x8 -#endif - mov RCPU, ARG1_REG64 - mov RCPSR, [RCPU + ARM_CPSR_offset] - - jmp ARG2_REG64 - -.p2align 4,,15 - -#ifdef __APPLE__ -.global _ARM_Ret -_ARM_Ret: -#else -.global ARM_Ret -ARM_Ret: -#endif - mov [RCPU + ARM_CPSR_offset], RCPSR - -#ifdef WIN64 - add rsp, 0x28 -#else - add rsp, 0x8 -#endif - - pop rbp - pop r15 - pop r14 - pop r13 - pop r12 - pop rbx -#ifdef WIN64 - pop rsi - pop rdi -#endif - - ret diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 446480d..c16da9f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,9 +80,8 @@ if (ENABLE_JIT) ARMJIT_x64/ARMJIT_LoadStore.cpp ARMJIT_x64/ARMJIT_Branch.cpp - ARMJIT_x64/ARMJIT_Linkage.s + ARMJIT_x64/ARMJIT_Linkage.S ) - set_source_files_properties(ARMJIT_x64/ARMJIT_Linkage.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") endif() if (ARCHITECTURE STREQUAL ARM64) target_sources(core PRIVATE @@ -94,9 +93,8 @@ if (ENABLE_JIT) ARMJIT_A64/ARMJIT_LoadStore.cpp ARMJIT_A64/ARMJIT_Branch.cpp - ARMJIT_A64/ARMJIT_Linkage.s + ARMJIT_A64/ARMJIT_Linkage.S ) - set_source_files_properties(ARMJIT_A64/ARMJIT_Linkage.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") endif() endif() -- cgit v1.2.3