mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
fix: keep NZCV across patched LSE min/max stubs and catch st* aliases
This commit is contained in:
1 parent
a0c86abcd3
commit
a5e79b7f2f
4 files changed
+33
-6
No files matched your search
@@ -1,7 +1,9 @@
|
||||
# LSE-Emu
|
||||
|
||||
`lse_emu.c` is an unmodified copy of [SildurFX/LSE-Emu](https://github.com/SildurFX/LSE-Emu)
|
||||
at commit `8bc9548ac6fd24a8d506b266b17ba8d0e71a9b01` (GPL-3.0-or-later).
|
||||
`lse_emu.c` is a copy of [SildurFX/LSE-Emu](https://github.com/SildurFX/LSE-Emu) at commit
|
||||
`8bc9548ac6fd24a8d506b266b17ba8d0e71a9b01` (GPL-3.0-or-later) with one fix: the patched stub
|
||||
for `LDSMAX`/`LDSMIN`/`LDUMAX`/`LDUMIN` saves and restores NZCV around its `cmp`/`csel`, since
|
||||
the real instructions leave the flags alone. Carry that fix forward until upstream has it.
|
||||
|
||||
It is an `LD_PRELOAD` library that emulates the ARMv8.1 LSE atomic instructions (and `LDAPR`)
|
||||
on ARMv8.0 CPUs. A SIGILL handler performs each trapped instruction with an LL/SC loop. With
|
||||
|
||||
@@ -9,6 +9,6 @@ mkdir -p "$(dirname "$out")"
|
||||
"$CC" -shared -fPIC -O2 -march=armv8-a -mno-outline-atomics -Wall -Wextra -Wno-unused-parameter \
|
||||
-Wl,-z,now,-z,max-page-size=65536 -o "$out" "$here/lse_emu.c" -ldl
|
||||
"$STRIP" --strip-unneeded "$out"
|
||||
if "${OBJDUMP:-aarch64-linux-gnu-objdump}" -d "$out" | grep -qE $'\t(ld(add|clr|eor|set|smax|smin|umax|umin)|swp|cas)[a-z]*\t'; then
|
||||
if "${OBJDUMP:-aarch64-linux-gnu-objdump}" -d "$out" | grep -qE $'\t((ld|st)(add|clr|eor|set|smax|smin|umax|umin)|swp|cas)[a-z]*\t'; then
|
||||
echo "::error::liblse_emu.so itself contains LSE instructions"; exit 1
|
||||
fi
|
||||
@@ -246,6 +246,10 @@ static int gen(uint32_t *w, uintptr_t stub, uintptr_t ret, uint32_t i) {
|
||||
|
||||
W(STP2(t0, t1));
|
||||
W(STR16(t2));
|
||||
if (kind == 4) { // cmp/csel below clobber NZCV, the real instruction does not
|
||||
W(0xD53B4200u | t2); // mrs t2, nzcv
|
||||
W(0xF9000C00u | (31u << 5) | t2); // str t2,[sp,#24]
|
||||
}
|
||||
int loop = n;
|
||||
W(ldx(size, acq, t0, rn)); // t0 = old
|
||||
if (kind == 1) {
|
||||
@@ -283,6 +287,10 @@ static int gen(uint32_t *w, uintptr_t stub, uintptr_t ret, uint32_t i) {
|
||||
}
|
||||
if (kind == 2) { if (rs != 31) W(MOVX(rs, t0)); }
|
||||
else if (rt != 31) W(MOVX(rt, t0));
|
||||
if (kind == 4) {
|
||||
W(0xF9400C00u | (31u << 5) | t2); // ldr t2,[sp,#24]
|
||||
W(0xD51B4200u | t2); // msr nzcv, t2
|
||||
}
|
||||
W(LDR16(t2));
|
||||
W(LDP2(t0, t1));
|
||||
{ int64_t off = (int64_t)ret - (int64_t)(stub + 4 * (uintptr_t)n);
|
||||
|
||||
Reference in new issue
Block a user