Add libdarm.so, migrate Darm class to BizInvoker

`Tools` > `Debugger` no longer crashes immediately on Linux with mGBA core
This commit is contained in:
YoshiRulz 2020-09-20 04:30:27 +10:00
parent 0bdd1b6d64
commit fb5a5ed78c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 19 additions and 10 deletions

BIN
Assets/dll/libdarm.so Executable file

Binary file not shown.

View File

@ -2,11 +2,12 @@
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using BizHawk.BizInvoke;
namespace BizHawk.Emulation.Cores.Components.ARM namespace BizHawk.Emulation.Cores.Components.ARM
{ {
public static class Darm public abstract class Darm
{ {
public const string dllname = "libdarm.dll";
public const CallingConvention cc = CallingConvention.Cdecl; public const CallingConvention cc = CallingConvention.Cdecl;
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@ -76,20 +77,20 @@ namespace BizHawk.Emulation.Cores.Components.ARM
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] mnemonic = new byte[12]; public byte[] mnemonic = new byte[12];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6 * 32)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6 * 32)]
public byte[,] arg = new byte[6, 32]; public byte[] arg = new byte[6 * 32];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] shift = new byte[12]; public byte[] shift = new byte[12];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] total = new byte[64]; public byte[] total = new byte[64];
} }
[DllImport(dllname, CallingConvention = cc, EntryPoint = "darm_disasm")] [BizImport(cc, Compatibility = true, EntryPoint = "darm_disasm")]
public static extern bool Disassemble([Out] Darm_T d, ushort w, ushort w2, uint addr); public abstract bool Disassemble([Out] Darm_T d, ushort w, ushort w2, uint addr);
[DllImport(dllname, CallingConvention = cc, EntryPoint = "darm_str2")] [BizImport(cc, Compatibility = true, EntryPoint = "darm_str2")]
public static extern bool Str([In] [Out]Darm_T d, [Out]Darm_Str_T s, bool lowercase); public abstract bool Str([In] [Out]Darm_T d, [Out]Darm_Str_T s, bool lowercase);
public static string DisassembleStuff(uint addr, uint opcode) public string DisassembleStuff(uint addr, uint opcode)
{ {
var d = new Darm_T(); var d = new Darm_T();
var s = new Darm_Str_T(); var s = new Darm_Str_T();

View File

@ -1,4 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.BizInvoke;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.ARM; using BizHawk.Emulation.Cores.Components.ARM;
@ -6,6 +9,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
{ {
public class ArmV4Disassembler : VerifiedDisassembler public class ArmV4Disassembler : VerifiedDisassembler
{ {
private readonly Darm _libdarm = BizInvoker.GetInvoker<Darm>(
new DynamicLibraryImportResolver(OSTailoredCode.IsUnixHost ? "libdarm.so" : "libdarm.dll", hasLimitedLifetime: false),
CallingConventionAdapters.Native
);
public override IEnumerable<string> AvailableCpus => new[] public override IEnumerable<string> AvailableCpus => new[]
{ {
"ARM v4", "ARM v4",
@ -20,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
{ {
addr &= unchecked((uint)~1); addr &= unchecked((uint)~1);
int op = m.PeekByte((int)addr) | m.PeekByte((int)addr + 1) << 8; int op = m.PeekByte((int)addr) | m.PeekByte((int)addr + 1) << 8;
string ret = Darm.DisassembleStuff(addr | 1, (uint)op); string ret = _libdarm.DisassembleStuff(addr | 1, (uint)op);
length = 2; length = 2;
return ret; return ret;
} }
@ -31,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
| m.PeekByte((int)addr + 1) << 8 | m.PeekByte((int)addr + 1) << 8
| m.PeekByte((int)addr + 2) << 16 | m.PeekByte((int)addr + 2) << 16
| m.PeekByte((int)addr + 3) << 24; | m.PeekByte((int)addr + 3) << 24;
string ret = Darm.DisassembleStuff(addr, (uint)op); string ret = _libdarm.DisassembleStuff(addr, (uint)op);
length = 4; length = 4;
return ret; return ret;
} }