Commit Graph
372 Commits
Author SHA1 Message Date
Stefanos Kornilios Mitsis Poiitidis a4c677bcbf Interpreter: Fix Mask calculation for OP_NOT 2020-08-28 18:24:04 +03:00
Ryan Houdek ab2020fe62 Merge pull request #309 from phire/ir_cleanup
Misc Optimisation and IR cleanup
2020-08-27 23:07:35 -07:00
Ryan Houdek 092f5249c6 Removes NO_REPLY packet from gdbserver 2020-08-27 13:36:57 -07:00
Ryan Houdek 95a8aba433 Extends gdbstub functionality
There are a significant number of changes here that I don't really
expect much review on.
Adds a bunch of new features and allows us to support GDB, IDA, and
Binja through their remote GDB debugging facilities.
Ghidra may also work but I haven't tried.

This work isn't quite yet complete to do correct thread stepping yet. We
need to add support for stopping threads using signals since threads may
be stuck inside of a syscall.

I have a hack locally that tries pausing all threads and times out after
a few seconds which works well enough for local testing.
2020-08-27 13:34:42 -07:00
Ryan Houdek 2ecd103aed Fixes thread stepping
This doesn't yet work around the problem of threads stalled in a syscall
2020-08-27 13:34:42 -07:00
Ryan Houdek 8ea871729c Moves RunningMode to the config struct 2020-08-27 13:34:42 -07:00
Stefanos Kornilios Mitsis Poiitidis 240806ba67 Merge pull request #307 from Sonicadvance1/implement_sigpending
Implements rt_sigpending
2020-08-25 16:14:57 +03:00
Scott Mansell fd06b594d9 Remove BFE's ablitly to handle FPRs
All instances have already been moved to other IR_OPs
It's just useless code

Also, an optimisation for X86's BFEs might have crept in
2020-08-26 00:59:28 +12:00
Scott Mansell 6dadf81001 x64jit: FPR 8/16bit Load Context/Mem should zext
Fixes OpenGL corruption issue in FTL with previous commits

Also includes an ir test
2020-08-26 00:47:40 +12:00
Scott Mansell c90945b072 JitArm64: Remove Zext, add Sbfe 2020-08-26 00:47:40 +12:00
Scott Mansell 43615f41ee Remove some unnessicary BFEs
Store result insures 32bit args are always sign extended
Inserting a BFE if needed.
2020-08-26 00:47:40 +12:00
Scott Mansell 5119a0bdb3 Elimiante ALU IR nodes that don't zero extend
Add and substract were the main culprits here.

We are trying to more towards a state where:
  * Every IR op can expect it isn't given extra bits
     on it's input
  * Every IR op never sets more bits than it's size
  * All unnessicary BFEs are never emitted
  * ARM doesn't have to implement special 8 and 16bit versions of IR ops
      All masking required to implement 8/16bit math on
      arm should be explictly generated from Opcode decoder
2020-08-26 00:47:40 +12:00
Scott Mansell 8023800213 Implemement Sbfe for x86
And fix interpeter
2020-08-26 00:47:40 +12:00
Scott Mansell 3989772a4f Remove OP_Zext
Zext has confusing sematics and does excatly the same thing as BFE

 * Repace with other ops (mostly BFE)
 * Allow specifying BFE size
2020-08-26 00:47:01 +12:00
Scott Mansell 3031d54823 InstallToX87Table: Fix segfault in debug assert 2020-08-25 20:17:49 +12:00
Ryan Houdek 758de4deaa Implements rt_sigpending
Any time a guest signal is blocked, add it to the guest signal mask.
This doesn't use a signal queue so repeat signals can end up being lost.
This is expected behaviour

This doesn't help with implementing the problem of unblocking signals
causing the masked signal to be resent
2020-08-20 13:47:03 -07:00
Stefanos Kornilios Mitsis Poiitidis 043c7c62be Merge pull request #301 from Sonicadvance1/cleanup_tables
Small bit of OpDispatcher table cleanup
2020-08-20 11:08:32 +03:00
Stefanos Kornilios Mitsis Poiitidis 9457119c2f Jit/armv8.0: Fix AtomicSwap 2020-08-20 10:21:40 +03:00
Stefanos Kornilios Mitsis Poiitidis 70b17848d6 Jit/x86: Fix OP_ATOMICSWAP 2020-08-20 09:55:02 +03:00
Stefanos Kornilios Mitsis Poiitidis 8390f30155 xchg: lock prefix is implied 2020-08-20 09:55:02 +03:00
Ryan Houdek 7fc8e3b685 Small bit of OpDispatcher table cleanup
Bunch of templated instructions that didn't need to be templated.
Removes a bunch of duplicate entries.
Saves a couple hundred kilobytes on the final file
2020-08-19 23:15:40 -07:00
Ryan Houdek a2cd49ed66 Adds some more flags to the x87 tables 2020-08-19 23:09:55 -07:00
Ryan Houdek 5efab55ea9 Removes LLVM from FEX
LLVM has too many problems with it to use it as a tiered level of JIT.
We won't be able to use it
2020-08-19 18:02:28 -07:00
Stefanos Kornilios Mitsis Poiitidis b8b227f098 Merge pull request #297 from Sonicadvance1/fix_atomicswap
Fixes a potential crash in ARM64's AtomicSwap
2020-08-20 00:05:12 +03:00
Ryan Houdek bad7cd1262 Fixes a potential crash in ARM64's AtomicSwap
When RA made the source address register be the same register as the
destination register then we could have overwritten the address with the
move.
Use a temporary until we get RA constraints in place.
2020-08-19 13:51:40 -07:00
Ryan Houdek c9b2c36ef7 Removes usage of vixl's MacroAssembler
This gives us two more volatile registers to play with
2020-08-19 12:52:37 -07:00
Ryan Houdek 7ab55d058a Bug fix for crash when code overran code size
This was checking the wrong code size. Needs to check the buffer code
size instead of the max code size
2020-08-18 21:00:33 +01:00
Ryan Houdek f11f0ab989 Switches to atomic loadstores for TSO implementation
Doesn't support fallback to the true TSO implementation yet
2020-08-18 21:00:33 +01:00
Ryan Houdek 7700a4d24b Adds support for guest sigprocmask
This was causing our SIGBUS handling to fail in FTL
2020-08-18 21:00:33 +01:00
Ryan Houdek 1db1a42576 Switches the OpcodeDispatcher over to using TSO IR ops
For loadstores to memory, this will use TSO ops to emulate x86
behaviour.
In the case that the source register is the stack pointer then it falls
back down to using regular loadstores. Since it is expected that stack
pointer usage will be thread specific.

With the AArch64 implementation this makes us be quite a bit closer to
being x86 TSO compliant
2020-08-13 20:49:19 +01:00
Ryan Houdek acfb38497f AArch64 TSO signal handler hookup
This patches unaligned LORegion loadstores with DMB wrapped loadstores.
This will ensure full cacheline consistency on loadstores, at the
expense of speed.

The performance can potentially be improved with "Half-barriers"
Described a bit here: https://github.com/dotnet/runtime/issues/8072

We can worry about that path after the initial implementation
2020-08-13 20:49:19 +01:00
Ryan Houdek ea3c4be9ed Implements TSO loadstore ops for the AArch64 JIT
This is the base implementation that uses LORegion loadstore
instructions to support the load/store release semantics, which these
instructions use.

Sadly these don't match the alignment requirements of x86 loadstores, so
if it was just used everywhere then it will cause alignment faults.
This means we need to catch the sigbus and backpatch the instruction to
do safe (aka expensive) TSO.

Currently this backpatch just falls back to regular loadstores
surrounded by DMB instructions.
Basically unaligned loadstores will fall back to nearly what we are
doing now, so significantly improved but not perfect.

A follow up PR will change this over to using a helper routine to be
100% safe
2020-08-12 15:24:01 -07:00
Ryan Houdek 9d19a60a70 Implements TSO memory ops on x86 JIT 2020-08-12 15:24:01 -07:00
Ryan Houdek b2182613b2 Implements TSO ops in LLVM backend
Same limitation as the interpreter side
2020-08-12 15:24:01 -07:00
Ryan Houdek 57c704c743 Implements TSO memory ops in interpreter
This won't be true TSO on ARM but it is impossible to work around sanely
here
2020-08-12 15:24:00 -07:00
Ryan Houdek 448516882c Implements signal handling in the AArch64 JIT
Also removes the simulator for running on x86-64, which we can no longer
support.
2020-08-11 00:33:50 +01:00
Ryan Houdek f705baf2f0 Extends SignalDelegator duty
It needs to track guest SigAltAction and have its own definitions for
sigaction and sa_mask. sa_mask specifically is defined differently
between the kernel and glibc.

Also fixes some issues with the SignalDelegator that posix tests found
2020-08-11 00:33:49 +01:00
Stefanos Kornilios Mitsis Poiitidis 211aebcfa4 Merge pull request #286 from Sonicadvance1/interpreter_initialization_order
Creates the interpreter core just before the IR jit
2020-08-08 16:56:48 +03:00
Ryan Houdek 26a05a467e Creates the interpreter core just before the IR jit
Arm64 IR JIT needs the interpreter to be around first to get a pointer
to it
2020-08-08 06:45:09 -07:00
Ryan Houdek f3099647a2 Declares new sigret x86 instruction and IR op
We are rebranding an x86-64 illegal instruction near VIA's old ALTINST
instruction as an instruction to handle returning from guest signals
cleanly.

If this ever collides with a new x86-64 (unlikely) then we will need to
change the instruction.
This ends up looking similar to what we will do for thunk callbacks
2020-08-08 06:42:06 -07:00
Stefanos Kornilios Mitsis Poiitidis daa0e284b1 Merge pull request #290 from Sonicadvance1/guest_x86_code_section
Adds an x86 generated code helper class
2020-08-04 18:50:12 +03:00
Stefanos Kornilios Mitsis Poiitidis ab68990932 Merge pull request #291 from Sonicadvance1/asm_dispatcher_exit_fix
Allows ASM dispatcher to leave cleanly
2020-08-04 18:29:08 +03:00
Ryan Houdek 555589cbcb Allows ASM dispatcher to leave cleanly
This needs to live outside of the dispatcher to do correct threading
cleanup
2020-08-02 18:20:15 -07:00
Ryan Houdek 246e36c061 Adds an x86 generated code helper class
Just generates some context level x86 code space for our guest to jump
in to.
This is only currently used for sigret but will become more important as
we come to support vdso.
2020-08-02 18:14:47 -07:00
Ryan Houdek f524162ed1 Allows block cache to export virtual memory size 2020-08-02 17:53:20 -07:00
Stefanos Kornilios Mitsis Poiitidis 8c8e6294b6 Thunks: ALTINST, OP_THUNK, basic infrastructure 2020-07-20 13:52:28 +03:00
Ryan Houdek 9b78876862 Fixes LLVM not clearing code cache on ARM platforms
Surprised this hasn't caused issues before but was picked up on the
SolidRun Honeycomb LX2K
2020-07-19 12:08:27 +11:00
Ryan Houdek 2536bfe42c Correctly fixes prefix ordering in the frontend
This was sort of partially worked around.
The issue comes down to REX.W and Operand size prefix ordering on an
instruction.
When an instruction has both prefixes, then the one that has occured
later will overwrite the previous one.
Additionally in the case of 66h being reused as an escape prefix, we
needed to ignore it in this case.

The previous workaround was that if an instruction happened to have both
widening and narrowing, then widening would win(for MODRM args),
but then later on in the instruction decoding the literal constant
decoding would properly check which order the flags came in.
This resulted in literal constants working, but not modrm bytes

Instead replace the "last" flag handling with a two deep stack that we
can push and pop the flags correctly on to it, this ensures that the
flags stay around in the 66h ignoring mode (so widening doesn't get
obliterated).

This effects every instruction that supports REX.W and 66h Operand size
prefix, so it could be fixing some unknown bugs elsewhere.
Very specifically this one was found in OpenSSL, because it looks like
GCC is padding a mov instruction with 66h.

Instruction Examples:
Only difference is the prefix order being swapped
0x00000000   4                 66488b1f  mov rbx, qword [rdi]
0x00000004   4                 48668b1f  mov bx, word [rdi]
2020-07-15 00:10:20 -07:00
Ryan Houdek ac68dc40e5 Fixes INC and DEC flag setting
These two instructions explicitly don't set the CF flag.
Otherwise they behave the same as ADD/SUB flag setting
Fixes part of curl
2020-07-15 00:09:16 -07:00
Ryan Houdek 2dd7a8d16d Disables CLMUL in CPUID
This would be a pain to support in NEON since it requires a 128bit
resulting multiply
2020-07-13 10:27:48 -07:00