Compare commits

...
126 Commits
Author SHA1 Message Date
ptitSeb 45c4117a40 Bumped version to v0.2.4 2023-08-19 17:22:35 +02:00
ptitSeb 4bd00b0f91 [TRACE] Fixed FF 25 opcode not decoding destination correctly in trace 2023-08-19 17:22:02 +02:00
ptitSeb 9e7225be36 [ELFLOADER] Adjusted fetching of symbol (help Steam Unity3d linux games, like Canabalt) 2023-08-19 16:35:57 +02:00
ptitSeb 154acbef72 Added profile for steam-runtime-launcher-service 2023-08-19 15:06:41 +02:00
ptitSeb 502611702e Added a few more wrapped symbol to libxcb-randr (for #287) 2023-08-18 21:49:57 +02:00
ptitSeb 009b9f7f3d Added many symbols to wrapped libgmp (for #900) 2023-08-18 21:34:27 +02:00
ptitSeb 77161c8e4d Merge pull request #936 from wannacu/main
Added some opcodes
2023-08-18 12:57:21 +02:00
wannacu b4cd6f27ba [RV64_DYNAREC] Added 10/11/12/13/14 opcodes 2023-08-18 18:22:53 +08:00
ptitSeb 2bb42ae9a9 Merge pull request #937 from kaixindeken/main
Fixed wild pointer error for my_context->elfs while calling my___libc_start_main
2023-08-18 08:55:03 +02:00
kaixindeken 54ce282b8c Avoid wild pointer error for my_context->elfs 2023-08-18 11:37:14 +08:00
ptitSeb 47057f076a Added some more wrapped symbols to libxcbrandr (for #287) 2023-08-17 22:15:16 +02:00
wannacu 7f775b7662 [ARM64_DYNAREC] Added F0 10/11 opcodes 2023-08-17 09:05:49 +08:00
ptitSeb 48317e0788 [ARM64_DYNAREC] Fixes 66 AD opcode and tweaked A0/A1 and 66 A1 opcodes 2023-08-15 16:14:57 +02:00
ptitSeb 6c77c8f1aa Added 1 more libasound wrapped symbol (for #904) 2023-08-15 15:14:15 +02:00
ptitSeb ca759d2c8f [ARM64_DYNAREC] Fixed F2/F3 AD and added AC (should help #924 a bit) 2023-08-15 14:52:23 +02:00
ptitSeb 53a59f593e Fixed AD opcode (for #924, probably other too) 2023-08-15 14:43:32 +02:00
ptitSeb d621670735 [ARM64_DYNAREC] Added 0F C0/C1 ocpodes (helps #927) 2023-08-15 13:19:43 +02:00
ptitSeb 6653cce464 Added 1 wrapped symbol to libglib2 2023-08-15 09:47:19 +02:00
ptitSeb acfbed72de Merge pull request #934 from wannacu/main
[RV64_DYNAREC] Added E0/E1/E2/E3 opcodes
2023-08-15 08:10:58 +02:00
wannacu c4e322a23a [RV64_DYNAREC] Added E0/E1/E2/E3 opcodes 2023-08-15 09:28:59 +08:00
wannacu 6b9d617fa6 [ARM64_DYNAREC] Fixed E0/E1 opcodes 2023-08-14 15:54:09 +08:00
ptitSeb 607ac40ab3 Added 0F A8/A9 opcodes 2023-08-13 14:20:30 +02:00
ptitSeb 69c7ca8bdc [32bits] Added 27/2F/37 opcodes 2023-08-13 14:18:59 +02:00
ptitSeb 692eb90dcd Added 0F A0/A1 opcodes 2023-08-13 14:15:30 +02:00
ptitSeb eee1c62325 [32bits] Fixed 67 prefixed opcodes 2023-08-13 14:09:46 +02:00
ptitSeb 442c3fdb9b Added another libxcbrandr wrapped symbol (for #287) 2023-08-13 13:58:05 +02:00
ptitSeb e2077c46ce Improved jmpbuff handling a bit 2023-08-13 12:24:12 +02:00
ptitSeb e8972efca1 [32bits] Added 62 opcode ([ARM64_DYNAREC] too) 2023-08-11 16:57:46 +02:00
ptitSeb f86c856e3b [32bits] Added 3F opcode ([ARM64_DYNAREC] too) 2023-08-11 16:51:18 +02:00
ptitSeb 6bb674420a Added some xcbrander wrapped symbols (for #287) 2023-08-11 16:43:05 +02:00
ptitSeb ee0fdc4332 Added a few gstreamer symbols (for #287) 2023-08-11 16:28:54 +02:00
ptitSeb 4006992f8d Merge pull request #929 from wannacu/main
Added some opcode
2023-08-11 07:03:46 +02:00
wannacu 8d04940c91 [ARM64_DYNAREC] Added 0F D1/D2 opcode 2023-08-11 11:43:45 +08:00
wannacu 4f1d3a75c2 [ARM64_DYNAREC] Added 0F FB opcode 2023-08-10 16:45:21 +08:00
wannacu 24c8af0363 [ARM64_DYNAREC] Fixed 66 98 opcode 2023-08-10 16:43:07 +08:00
ptitSeb 4474af2a9a Merge pull request #928 from wannacu/main
[ARM64_DYNAREC] Correct PF caculation
2023-08-09 11:51:24 +02:00
wannacu a3765ec0f8 [ARM64_DYNAREC] Correct PF caculation 2023-08-09 17:34:00 +08:00
wannacu b04712898c Submit the generation of wrapped library 2023-08-09 15:49:08 +08:00
ptitSeb adaafc2a6d Merge pull request #926 from wannacu/main
[RV64_DYNAREC] Added movbe opcode
2023-08-07 18:13:16 +02:00
wannacu 3308cc60e9 [RV64_DYNAREC] Added movbe opcode 2023-08-07 17:07:31 +08:00
ptitSeb e4b235378b Merge pull request #923 from strongtz/main
Add a new vulkan extension: VK_EXT_descriptor_buffer
2023-08-04 20:44:30 +02:00
Xilin Wu 4f5f6b25e8 Added a new vulkan extension
VK_EXT_descriptor_buffer is used by vkd3d-proton for implementing
the full Direct3D 12 API

Tested on Snapdragon 888 with Mesa Turnip
2023-08-04 23:01:25 +08:00
Xilin Wu 4b40179bc3 Added SD888 profile 2023-08-04 23:00:05 +08:00
ptitSeb 0f7b23148f Merge pull request #922 from wannacu/main
[ARM64_DYNAREC] Fixed BT/BTC/BTR/BTS opcodes
2023-08-04 12:09:49 +02:00
wannacu a46923e494 [ARM64_DYNAREC] Fixed BT/BTC/BTR/BTS opcodes 2023-08-04 16:50:27 +08:00
wannacu 1e7b4b8450 [ARM64] Added printer for FPRINTX 2023-08-04 16:28:39 +08:00
ptitSeb 0edf24ae97 Added sycalls 59 and 140 (for #918) 2023-08-03 11:03:00 +02:00
ptitSeb 82f60fee35 Merge pull request #920 from AndreRH/spellingfixes
Spelling fixes
2023-08-02 21:02:56 +02:00
ptitSeb 1333e37b71 Merge pull request #919 from AndreRH/curlybrackets
Add missing curly brackets
2023-08-02 21:00:38 +02:00
André Zwing 7f3e0b8fe0 Some spelling fixes 2023-08-02 20:44:54 +02:00
André Zwing 937863f4aa [DYNAREC] Some spelling fixes 2023-08-02 20:44:54 +02:00
André Zwing ff3a639c92 Add missing curly brackets 2023-08-02 20:44:26 +02:00
ptitSeb 3eae7156dc Added syscall 268 (for #918) 2023-08-02 17:07:57 +02:00
ptitSeb e12589ea8b Added syscal 160 (for #14) 2023-08-02 13:40:42 +02:00
ptitSeb 6b5ee5ecb5 Fixed non-dynarec behavior on setjmp 2023-07-30 23:40:14 +02:00
ptitSeb f3a9224547 Fixed, for good non-dynarec build 2023-07-30 23:21:29 +02:00
ptitSeb 8ef326fdc5 Fixed non-dynarec build 2023-07-30 23:13:44 +02:00
ptitSeb fb0e8ee9c6 Change again a bit how jmpbuffer and resuming of signal is handled 2023-07-30 22:12:30 +02:00
ptitSeb 6a8cc8ace3 Use my_conect directly on Interpreter 2023-07-30 21:53:32 +02:00
xctan f5fadea30e [RV64_DYNAREC] Added more opcodes for Yuzu (#911)
* [RV64_DYNAREC] Fixed PTEST opcode

* [RV64_DYNAREC] Added 64 66 89 MOV opcode

* [RV64_DYNAREC] Added 66 87 XCHG opcode
2023-07-28 19:31:46 +02:00
ptitSeb bedfb82066 Added a new vulkan extension 2023-07-27 16:22:15 +02:00
Ilya114 8a403d9126 Little fixes (#909)
* Update README_CN.md

* Update README_UK.md
2023-07-27 13:09:23 +02:00
Ilya114 aca4e6585c Ukrainian translate of README (#908)
* Ukrainian translate of README

* Update README_UK.md

* Update README_UK.md

* Update README_UK.md

* Update README.md

* Update README_UK.md

* Update README_UK.md

* Update README_UK.md
2023-07-27 12:18:36 +02:00
ptitSeb 0928f50bc6 Emit a SIGILL on Illegal FF opcode (and better trace for it). Also fixed some Warning 2023-07-26 18:58:11 +02:00
ptitSeb da098cc1f7 Merge pull request #902 from josch/cross
Use CMAKE_SYSTEM_PROCESSOR instead of CMAKE_HOST_SYSTEM_PROCESSOR
2023-07-23 14:20:25 +02:00
ptitSeb 8da631a14d Merge pull request #901 from josch/add-sysroot-paths
add /usr/x86_64-linux-gnu/lib to the shared library search path
2023-07-23 14:06:53 +02:00
Johannes Schauer Marin Rodrigues dafa5014a4 Use CMAKE_SYSTEM_PROCESSOR instead of CMAKE_HOST_SYSTEM_PROCESSOR
The former is exactly the same as the latter if compiling natively,
which is the output of `uname -m`. But this is the wrong architecture
when cross compiling where we do not want the architecture we are
compiling on (the build architecture in GNU terminology) but the
architecture we are compiling for (the host architecture in GNU
terminology). The CMAKE_SYSTEM_PROCESSOR variable is set to the correct
host architecture value when cross compiling.

With this change, it is possible to cross compile a arm64 executable of
box64 on an amd64 machine. Without this change, the "install" target
will be omitted, because CMakeLists.txt wrongly uses the build
architecture to decide whether the install target should be added or
not. Instead it should use the host architecture.
2023-07-23 13:59:07 +02:00
Johannes Schauer Marin Rodrigues 879c2f365e add /usr/x86_64-linux-gnu/lib to the shared library search path
On Debian there are the packages libstdc++6-amd64-cross and
libgcc-s1-amd64-cross which provide amd64 shared libraries which are
usually used for cross compiling without multiarch but using a sysroot
prefix instead. Since libgcc_s.so.1 and libstdc++.so.6 shipped by these
packages are fully functional, let box64 use them as a fallback if it
cannot find them in the other paths that it searched before.
2023-07-23 13:54:35 +02:00
ptitSeb 50032affcf [DYNAREC] Improvments to BOX64_DYNAREC_FORWARD handling 2023-07-23 13:04:14 +02:00
ptitSeb 784cc3ba9c [32BITS] Added C4 and C5 opcodes 2023-07-23 13:03:46 +02:00
ptitSeb 1d5a88a319 [32BITS] added D6 undocumented opcode 2023-07-23 12:38:05 +02:00
ptitSeb 392575ba04 [DYNAREC] Added more info when FillBlock generate a segfault 2023-07-23 12:37:41 +02:00
ptitSeb 83c808c42d [ARM64_DYNAREC] Fixed invalid DE opcodes handling 2023-07-23 12:36:33 +02:00
ptitSeb 9a61392cf9 [325BITS][ARM64_DYNAREC] Improved 66 50-5F opcodes 2023-07-23 12:36:01 +02:00
ptitSeb b2c2f7bbd2 [32BITS] Added 66 50-5F opcodes ([ARM64_DYNAREC] too, and fixed 66 61 opcode) 2023-07-23 11:15:31 +02:00
ptitSeb da6ad1a43d [32BITS] Added 66 FF /6 opcode ([ARM64_DYNAREC] too) 2023-07-23 11:02:22 +02:00
ptitSeb f9e4253cb7 Removed a debug leftover 2023-07-22 21:00:20 +02:00
ptitSeb 1675ce83b6 Updated README with more up-to-date Steam and Wine sections 2023-07-22 20:56:29 +02:00
ptitSeb 9b585ef706 Better handling of int 29/2C/2d with wine ([ARM64_DYNAREC] too) 2023-07-22 20:46:07 +02:00
ptitSeb 67c9378fb8 Hacked wrapped ptrace to avoid crash when wine handle exception (and debug registers in general) 2023-07-22 20:45:16 +02:00
ptitSeb 7ab299b246 [TRACE] Fixed crash when tracing a function that is not defined in main at beggining 2023-07-22 20:43:59 +02:00
ptitSeb 0733a87279 Merge pull request #896 from josch/exe
remove executable bits
2023-07-21 08:13:56 +02:00
Johannes Schauer Marin Rodrigues 28dc8e6751 remove executable bits
Closes: #895
2023-07-21 02:10:26 +02:00
ptitSeb 51cbb7e1fb Merge pull request #894 from ryanfortner/patch-2
Update package name in COMPILE.md
2023-07-20 15:29:25 +02:00
ptitSeb 3a82317dd5 Added 1 function to wrapped libatomic (for #46) 2023-07-20 15:27:16 +02:00
Ryan Fortner 1f2ef09d87 Update COMPILE.md 2023-07-20 08:33:13 -04:00
ptitSeb 5bf0f0215d Added 67 0F 11 opcode ([ARM64_DYNAREC] too) (for #892) 2023-07-19 17:02:09 +02:00
ptitSeb 8f968e4c9c Added 1 more symbol to wrapped libgtk3 (for #46) 2023-07-19 13:19:44 +02:00
ptitSeb a8ce60ed4a Added some more wrapped symbols to libx11 and friends 2023-07-19 13:14:54 +02:00
ptitSeb 27d8911dee Update CMakeLists.txt (for #890) 2023-07-17 22:25:20 +02:00
ptitSeb 4bf909393c Merge pull request #889 from rajdakin/main
Cleaner wrapper generator script
2023-07-17 21:50:13 +02:00
rajdakin 8fc0e1d384 [WRAPPERS] Generator version bump 2023-07-17 21:31:04 +02:00
rajdakin 60ae205bd4 [WRAPPERS] Better isRetX87Wrapper definition in the Python script 2023-07-17 21:30:17 +02:00
ptitSeb 65045c4897 Added 67 F3 0F 6F opcode ([ARM64_DYNAREC] too) (for #873 / steam on wow64) 2023-07-17 17:46:04 +02:00
ptitSeb e46133c850 Added 0F F4 opcode ([ARM64_DYNAREC] too) (for #888) 2023-07-17 17:29:39 +02:00
ptitSeb 37ef57f78f Added 0F D4 opcode ([ARM64_DYNAREC] too) 2023-07-17 15:59:17 +02:00
ptitSeb 3c50d99aba Added a large bunch of wrapped functions to libnss3 and libnspr4 2023-07-17 13:42:18 +02:00
ptitSeb 508efcf51c [DYNAREC] Small cosmetic change in updateNeed utility function 2023-07-17 10:56:18 +02:00
ptitSeb 36d11a4443 Actually added execle wrapped function (for #850) 2023-07-17 10:55:24 +02:00
ptitSeb 8590b0b4f3 Added a few wrapped function to libmpg123 (for #820) 2023-07-16 11:33:54 +02:00
ptitSeb 7817d629f1 [ARM64_DYNAREC] Fixed an issue with GB high extraction/re-insertion (for #867 and probably wany other) 2023-07-16 11:28:37 +02:00
ptitSeb 7607a87617 Added wrapped execle (for #850) 2023-07-16 10:54:32 +02:00
ptitSeb b2d37d4ddb [32BITS] Added 64 67 8B opcode (for #870) 2023-07-16 10:42:28 +02:00
ptitSeb 0003c72fc7 Fixed some warnings/build errors 2023-07-16 10:42:00 +02:00
ptitSeb 915f7cbd54 Fixed some of 16bits opcodes ([ARM64_DYNAREC] too) 2023-07-16 10:17:14 +02:00
ptitSeb 0b3097cd0b [ELFLOADER] Reworked R_X86_64_COPY and R_X86_64_GLOB_DAT handling, improving c++ program compatibility 2023-07-15 16:57:57 +02:00
ptitSeb c7e0ba82b4 [DYNAREC] Better handling if wrapped function that return float/double in x87 register 2023-07-14 14:16:52 +02:00
ptitSeb 6168fa4275 Remove native flag from generic ARM64 build profile, it doesn't work when cross-compiling 2023-07-14 12:11:08 +02:00
ptitSeb b61a788ce7 Fixed generic ARM64 build profile 2023-07-14 12:05:48 +02:00
ptitSeb 903ecd207d Added generic ARM64 build profile 2023-07-14 12:03:30 +02:00
ptitSeb d62e9652fc [ARM64_DYNAREC] Added 66 9C/9D opcodes (mostly for 32bits) 2023-07-14 11:18:30 +02:00
ptitSeb 41e3b2b1a1 Added 66 9C/9D opcodes (mostly for 32bits) 2023-07-14 11:17:53 +02:00
ptitSeb 3349757d0f [DYNAREC] Fixed an issue with forward jump state retreival 2023-07-14 11:03:11 +02:00
ptitSeb 066d7458ca Some fixes to wrapped libgio2 (for #840 and #46) 2023-07-14 10:23:15 +02:00
ptitSeb 88a59b4460 [DYNAREC] Fixed an issue with calling native function that return a long double (for #881) 2023-07-13 18:21:36 +02:00
ptitSeb aaab83356d Added some more gtkclass wrapping and fixed g_initable_new wrapping (for spotify) 2023-07-12 20:34:35 +02:00
ptitSeb 7c1637328a Added empty wrapped libcap.so.2 and libgomp.so.2 2023-07-12 18:51:30 +02:00
ptitSeb 0224346ed8 Added more path option when searching for x86_64 libraries 2023-07-12 18:50:59 +02:00
ptitSeb 35366b25a6 Improved handling of malloc_hack_2 2023-07-12 18:04:45 +02:00
ptitSeb b4c951b66b [DYNAREC] Used uwrapped malloc functions for dynarec 2023-07-12 15:56:47 +02:00
wannacu b1c09acb0c [WRAPPER HELPER] Improve Record Parsing (#880) 2023-07-12 09:43:08 +02:00
ptitSeb a6b231ce56 Added one more function to wrapped libdbus 2023-07-10 13:55:30 +02:00
ptitSeb 0862e4995c Improved wrapping of XextAddDisplay libxext function 2023-07-09 16:00:23 +02:00
ptitSeb 94832fd7d7 Fixed previous commit 2023-07-09 15:47:46 +02:00
ptitSeb 7cd82d16ce Removed useless box64context_t parameter to RunFunction and friend 2023-07-09 15:24:27 +02:00
ptitSeb dabbca767f [ELFLOADER] Added a check if lib version is compatible with what the elf loading it wants (helps Linux games on Steam) 2023-07-09 12:38:48 +02:00
1042 changed files with 6010 additions and 2734 deletions

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ on:
- RPI4ARM64
- SD845
- TEGRAX1
- ARM64
build_type:
description: 'Build type'
required: true
+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [X64, OTHER_ARM, RISCV, RPI4ARM64, RK3326, RK3399, RK3588, PHYTIUM, SD845]
platform: [X64, OTHER_ARM, RISCV, RPI4ARM64, RK3326, RK3399, RK3588, PHYTIUM, SD845, ARM64]
type: [Release, Trace]
os: [ubuntu-latest]
include:
Executable → Regular
View File
File mode changed.
Executable → Regular
+19 -7
View File
@@ -14,11 +14,13 @@ option(ODROIDN2 "Set to ON if targeting an Odroid-N2 device" ${ODROIDN2})
option(TEGRAX1 "Set to ON if targeting an Tegra X1 based device" ${TEGRAX1})
option(PHYTIUM "Set to ON if targeting an Phytium (D2000 or FT2000/4) based device" ${PHYTIUM})
option(SD845 "Set to ON if targeting a Snapragon 845 based device" ${SD845})
option(SD888 "Set to ON if targeting a Snapragon 888 based device" ${SD888})
option(M1 "Set to ON if targeting a AppleM1 running on Asahi computer" ${M1})
option(LARCH64 "Set to ON if targeting an Loongarch64 based device" ${LARCH64})
option(RV64 "Set to ON if targeting an RISC-V RV64GC based device" ${RV64})
option(PPC64LE "Set to ON if targeting an PowerPC 64 LE based device" ${PPC64LE})
option(LX2160A "Set to ON if targeting an LX2160A based device" ${LX2160A})
option(ARM64 "Set to ON if targeting a generic ARM64 based device" ${ARM64})
option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE})
option(HAVE_TRACE "Set to ON to have Trace ability (needs ZydisInfo library)" ${HAVE_TRACE})
option(NOLOADADDR "Set to ON to avoid fixing the load address of Box64" OFF)
@@ -46,13 +48,13 @@ if(PPC64LE)
set(RV64_DYNAREC OFF CACHE BOOL "")
set(PAGE16K OFF CACHE BOOL "")
endif()
if(RK3399 OR RK3588 OR ODROIDN2 OR RPI3ARM64 OR RPI4ARM64 OR RK3326 OR TEGRAX1 OR PHYTIUM OR SD845 OR LX2160A OR M1)
if(RK3399 OR RK3588 OR ODROIDN2 OR RPI3ARM64 OR RPI4ARM64 OR RK3326 OR TEGRAX1 OR PHYTIUM OR SD845 OR SD888 OR LX2160A OR M1 OR ARM64)
set(LD80BITS OFF CACHE BOOL "")
set(NOALIGN OFF CACHE BOOL "")
set(ARM_DYNAREC ON CACHE BOOL "")
set(RV64_DYNAREC OFF CACHE BOOL "")
endif()
if(RK3399 OR RK3588 OR ODROIDN2 OR RPI3ARM64 OR RPI4ARM64 OR RK3326 OR TEGRAX1 OR PHYTIUM OR SD845 OR LX2160A)
if(RK3399 OR RK3588 OR ODROIDN2 OR RPI3ARM64 OR RPI4ARM64 OR RK3326 OR TEGRAX1 OR PHYTIUM OR SD845 OR SD888 OR LX2160A)
set(PAGE16K OFF CACHE BOOL "")
endif()
if(RK3588)
@@ -137,13 +139,17 @@ elseif(TEGRAX1)
add_definitions(-pipe -march=armv8-a+crc+simd+crypto -mcpu=cortex-a57+crypto)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8-a+crc+simd+crypto -mcpu=cortex-a57+crypto")
elseif(PHYTIUM)
add_definitions(-DPHYSIUM)
add_definitions(-DPHYTIUM)
add_definitions(-pipe -march=armv8.1-a+crc+simd+crypto)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8.1-a+crc+simd+crypto+aes")
elseif(SD845)
add_definitions(-DSD845)
add_definitions(-pipe -march=armv8.2-a+simd+crypto -mtune=cortex-a75.cortex-a55)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8.2-a+simd+crypto -mtune=cortex-a75.cortex-a55")
elseif(SD888)
add_definitions(-DSD888)
add_definitions(-pipe -march=armv8.4-a+crypto)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8.4-a+crypto")
elseif(M1)
add_definitions(-DM1)
add_definitions(-pipe -march=armv8.5-a+simd+crypto)
@@ -164,6 +170,9 @@ elseif(LX2160A)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8-a+crypto+crc -mcpu=cortex-a72+crypto")
elseif(SW64)
add_definitions(-DSW64)
elseif(ARM64)
#add_definitions(-pipe -march=native)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8-a+simd")
elseif(ARM_DYNAREC)
set(CMAKE_ASM_FLAGS "-pipe -march=armv8-a+crc+simd+crypto")
endif()
@@ -309,6 +318,7 @@ set(INTERPRETER
"${BOX64_ROOT}/src/emu/x64run66f0.c"
"${BOX64_ROOT}/src/emu/x64run67.c"
"${BOX64_ROOT}/src/emu/x64run67_32.c"
"${BOX64_ROOT}/src/emu/x64run6764_32.c"
"${BOX64_ROOT}/src/emu/x64run670f.c"
"${BOX64_ROOT}/src/emu/x64run6766.c"
"${BOX64_ROOT}/src/emu/x64run67660f.c"
@@ -333,6 +343,7 @@ set(WRAPPEDS
"${BOX64_ROOT}/src/wrapped/wrappedatomic.c"
"${BOX64_ROOT}/src/wrapped/wrappedatspi.c"
"${BOX64_ROOT}/src/wrapped/wrappedbz2.c"
"${BOX64_ROOT}/src/wrapped/wrappedcap.c"
"${BOX64_ROOT}/src/wrapped/wrappedcairo.c"
"${BOX64_ROOT}/src/wrapped/wrappedcairogobject.c"
"${BOX64_ROOT}/src/wrapped/wrappedcrashhandler.c"
@@ -359,6 +370,7 @@ set(WRAPPEDS
"${BOX64_ROOT}/src/wrapped/wrappedgmp.c"
"${BOX64_ROOT}/src/wrapped/wrappedgnutls.c"
"${BOX64_ROOT}/src/wrapped/wrappedgobject2.c"
"${BOX64_ROOT}/src/wrapped/wrappedgomp.c"
"${BOX64_ROOT}/src/wrapped/wrappedgssapi.c"
"${BOX64_ROOT}/src/wrapped/wrappedgssapikrb5.c"
"${BOX64_ROOT}/src/wrapped/wrappedgstapp.c"
@@ -739,10 +751,10 @@ else()
endif()
endif()
string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "i686" _x86)
string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "x86_64" _x86_64)
string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "aarch64" _aarch64)
string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "riscv64" _riscv64)
string(COMPARE EQUAL "${CMAKE_SYSTEM_PROCESSOR}" "i686" _x86)
string(COMPARE EQUAL "${CMAKE_SYSTEM_PROCESSOR}" "x86_64" _x86_64)
string(COMPARE EQUAL "${CMAKE_SYSTEM_PROCESSOR}" "aarch64" _aarch64)
string(COMPARE EQUAL "${CMAKE_SYSTEM_PROCESSOR}" "riscv64" _riscv64)
if(_x86_64 OR _aarch64)
add_definitions(-DCONFIG_64BIT)
+5 -6
View File
@@ -2,7 +2,7 @@
Linux Userspace x86_64 Emulator with a twist
[View changelog](https://github.com/ptitSeb/box64/blob/main/docs/CHANGELOG.md) | [中文](https://github.com/ptitSeb/box64/blob/main/README_CN.md) | [Report an error](https://github.com/ptitSeb/box64/issues/new)
[View changelog](https://github.com/ptitSeb/box64/blob/main/docs/CHANGELOG.md) | [中文](https://github.com/ptitSeb/box64/blob/main/README_CN.md) | [Українська](https://github.com/ptitSeb/box64/blob/main/README_UK.md) | [Report an error](https://github.com/ptitSeb/box64/issues/new)
![build](https://app.travis-ci.com/ptitSeb/box64.svg?branch=main) ![stars](https://img.shields.io/github/stars/ptitSeb/box64) ![forks](https://img.shields.io/github/forks/ptitSeb/box64) ![contributors](https://img.shields.io/github/contributors/ptitSeb/box64) ![prs](https://img.shields.io/github/issues-pr/ptitSeb/box64) ![issues](https://img.shields.io/github/issues/ptitSeb/box64)
@@ -86,23 +86,22 @@ GTK libraries are now wrapped on box64, both gtk2 and gtk3.
Notes about Steam
----
Note that Steam is a hybrid 32-bit / 64-bit. You NEED box86 to run Steam, as the client app is a 32-bit binary. It also uses a 64-bit local server binaries, but like most stuff using libcef/chromium, it's not working correctly on box64 for now.
So, no Steam for now on box64.
Note that Steam is a hybrid 32-bit / 64-bit. You NEED box86 to run Steam, as the client app is a 32-bit binary. It also uses a 64-bit local server binaries, and that steamwebhelper process is now mendatory, even on the "small mode". And that process will eat lots of memory. So machine with less the 6Gb of RAM will need a swapfile tp use Steam.
----
Notes about Wine
----
Wine64 is supported on box64. Proton should also work. Be aware that 64-bit Wine also includes 32-bit components, to be able to run 32-bit Windows programs. The 32-bit apps will need box86 and will not run without it. On a system where both box64 and box86 are present and working, a wine 64-bit setup can run both 32-bit and 64-bit Windows programs (just use `wine` and `wine64` respectively).
Note that the new 32bits PE in 64bits process that the Wine time in currently implementing in Wine 7.+ is not yet supported. I tested Wine 7.5 64bits and it worked, but more recent version will probably just not work yet.
Wine64 is supported on box64. Proton too. Be aware that 64-bit Wine also includes 32-bit components, to be able to run 32-bit Windows programs. The 32-bit apps will need box86 and will not run without it. On a system where both box64 and box86 are present and working, a wine 64-bit setup can run both 32-bit and 64-bit Windows programs (just use `wine` and `wine64` respectively).
Note that the new 32bits PE in 64bits process that the Wine time in currently implementing in Wine 7.+ is now supported, but the support is quite young so there might be some residual issues.
----
Notes about Vulkan
----
Box64 wraps Vulkan libraries, but note that it as only been tested with a RX550 card, so some extensions may be missing depending on your graphics card.
Box64 wraps Vulkan libraries, but note that it as mostly been tested with a AMD RX550 card and on the Freedreno driver, so some extensions may be missing depending on your graphics card.
----
+1 -1
View File
@@ -6,7 +6,7 @@ Linux 上用户空间的 x86_64 应用模拟器(支持运行原生库)
----
![box64 build status](https://app.travis-ci.com/ptitSeb/box64.svg?branch=main)
[English](docs/README.md)
[English](docs/README.md) | [Українська](https://github.com/ptitSeb/box64/blob/main/README_UK.md)
Box64 可以在非 x86_64 Linux 系统(比如 ARM64)上运行 x86_64 Linux 程序(比如游戏),注意主机系统需要是 64 位小端。
+119
View File
@@ -0,0 +1,119 @@
![Official logo](docs/img/Box64Logo.png "Official Logo")
Емулятор простіра користувача x86_64 із родзинкою
[Дивитись журнал змін](https://github.com/ptitSeb/box64/blob/main/docs/CHANGELOG.md) | [中文](https://github.com/ptitSeb/box64/blob/main/README_CN.md) | [Українська](https://github.com/ptitSeb/box64/blob/main/README_UK.md) | [Повідомити про помилку](https://github.com/ptitSeb/box64/issues/new)
![build](https://app.travis-ci.com/ptitSeb/box64.svg?branch=main) ![stars](https://img.shields.io/github/stars/ptitSeb/box64) ![forks](https://img.shields.io/github/forks/ptitSeb/box64) ![contributors](https://img.shields.io/github/contributors/ptitSeb/box64) ![prs](https://img.shields.io/github/issues-pr/ptitSeb/box64) ![issues](https://img.shields.io/github/issues/ptitSeb/box64)
----
Box64 дозволяє запускати x86_64 Linux програми (наприклад, ігри) на системах Linux відмінних від x86_64, наприклад ARM (хост-система має мати 64-розрядний порядок редагування).
Ви можете знайти багато відео про Box64 в YouTube каналах [MicroLinux](https://www.youtube.com/channel/UCwFQAEj1lp3out4n7BeBatQ), [Pi Labs](https://www.youtube.com/channel/UCgfQjdc5RceRlTGfuthBs7g) або [The Byteman](https://www.youtube.com/channel/UCEr8lpIJ3B5Ctc5BvcOHSnA)
Оскільки Box64 використовує рідні версії деяких «системних» бібліотек, таких як libc, libm, SDL і OpenGL, його легко інтегрувати та використовувати з більшістю програм, а продуктивність у багатьох випадках може бути напрочуд високою. Подивіться на цей стендовий аналіз для прикладу [тут](https://box86.org/index.php/2021/06/game-performances/).
Box64 інтегрується з DynaRec (динамічний рекомпілятор) для платформ ARM64 і RV64 забезпечуючи підвищення швидкості в 5-10 разів, ніж використання лише інтерпретатора. Деякі високорівневі відомості про те, як працює DynaRec, можна знайти [тут](https://box86.org/2021/07/inner-workings-a-high%e2%80%91level-view-of-box86-and-a-low%e2%80%91level-view-of-the-dynarec/).
Деякі внутрішні коди операцій x64 використовують частини «Бібліотеки емулятора Realmode X86», дивіться [x64primop.c](src/emu/x64primop.c) для детальної інформації про авторські права.
<img src="docs/img/Box64Icon.png" width="96" height="96">
Логотип і піктограма зроблені @grayduck, дякую!
----
Використання
----
Є кілька змінних середовища для керування поведінкою Box64.
Дивіться [тут](docs/USAGE.md) для перегляду всіх змінних середовища та того, що вони роблять.
Примітка: Dynarec від Box64 використовує механізм із захистом пам’яті та обробником сигналу помилки сегментів для обробки JIT коду. Простіше кажучи, якщо ви хочете використовувати GDB для налагодження запущеної програми, яка використовує JIT-код (наприклад, mono/Unity3D), ви все одно матимете багато «звичайних» помилок сегментів. Пропонується використовувати щось на зразок `handle SIGSEGV nostop` в GDB, щоб не зупинятися на кожній помилці сегмента, і, можливо, поставити точку зупину всередині `my_memprotectionhandler` в `signals.c`, якщо ви хочете перехопити помилки сегментів.
----
Компіляція/Встановлення
----
> Інструкцію зі складання Box64 можна знайти [тут](docs/COMPILE.md).\
> Інструкцію з встановлення Wine для Box64 можна знайти [тут](docs/X64WINE.md).
----
Історія версій/Журнал змін
----
Історія версій доступна [тут](docs/CHANGELOG.md).
----
Примітки щодо 32 бітних платформ
----
Оскільки Box64 працює шляхом прямого перекладу викликів функцій з x86_64 на хост-систему, хост-система (та, на якій працює Box64) повинна мати 64-розрядні бібліотеки. Box64 не містить 64-біт <-> 32-біт перекладу.
Також розумійте що Box64 запускатиме лише 64-розрядні двійкові Linux файли. Для 32-розрядних двійкових файлів вам потрібен Box86 (з усіма хитрощами з мультиархітектурною системою або корінними правами). Зауважте, що багато інсталяторів (на основі mojo) повертаються до "x86" при виявленні ОС ARM64, і тому намагатимуться використовувати Box86 для налаштування, навіть якщо існує версія x86_64. Ви можете зламати свій шлях за допомогою фальшивого "uname", який повертає "x86_64", коли аргумент "-m"
----
Примітки щодо конфігурації Box64
----
Обидва файли мають однаковий синтаксис і в основному є файлами ini. Розділ у квадратних дужках визначає назву процесу, а решта — встановлють змінну середовища. Подивіться [використання](USAGE.md), щоб дізнатися, які параметри можна завдати. Box64 поставляється з файлом за замовчуванням, який слід встановити для кращої стабільності. Файл знаходиться в `system/box64.box64rc` і має бути встановлен в `/etc/box64.box64rc`. Якщо з певних причин ви не хочете встановлювати цей файл у `/etc`, принаймні скопіюйте його в `~/.box64rc` або гра може не працювати належним чином. Зауважте, що пріоритетом є: `~/.bashrc` > `/etc/box64.box64rc` > командний рядок
Таким чином, ваші налаштування в `~/.bashrc` можуть замінити налаштування з вашого командного рядка...
----
Примітки щодо емуляції ігор Unity
----
Запуск ігор Unity має працювати, але ви також повинні зауважити, що для багатьох ігор Unity3D потрібен OpenGL 3+, який може бути складно забезпечити на ARM SBC (одноплатних комп’ютерах). Крім того, багато нових ігор Unity3D (наприклад, KSP) використовують стиснуті текстури BC7, які не підтримуються багатьма інтегрованими GPU ARM.
Підказка: в Pi4 використовуйте `MESA_GL_VERSION_OVERRIDE=3.2`, а в Panfrost — `PAN_MESA_DEBUG=gl3`, щоб використовувати вищий профіль, якщо гра запускається, а потім завершується, перш ніж щось показує.
----
Примітки щодо програм GTK
----
Бібліотеки GTK2 і GTK3 тепер використовуються в Box64.
----
Примітки щодо Steam
----
Зауважте, що Steam є гібридом 32-біт / 64-біт. Вам ПОТРІБЕН box86, щоб запустити Steam, оскільки клієнта є 32-розрядною двійковою програмою. Він також використовує 64-розрядні двійкові файли локального сервера, і цей процес steamwebhelper тепер є обов’язковим навіть у «малому режимі». І цей процес з’їсть багато оперативної пам’яті, таким чином машині з 6 Гб оперативної пам’яті знадобиться файл підкачки для використання Steam.
----
Примітки щодо Wine
----
Wine64 підтримується Box64, Proton теж. Майте на увазі, що 64-розрядний Wine також містить 32-розрядні компоненти щоб мати можливість запускати 32-розрядні програми Windows. Для 32-розрядних програм потрібен Box86, і вони не працюватимуть без нього. У системі, де присутні і працюють Box64, і Box86, 64-розрядне встановлення Wine може запускати як 32-розрядні, так і 64-розрядні програми Windows (просто використовуйте `wine` і `wine64` відповідно).
Зауважте, що новий 32-бітний PE в 64-бітному процесі, який Wine зараз реалізує у Wine 7+ тепер підтримується, але підтримка є досить молодою тому можуть виникнути деякі проблеми.
----
Примітки щодо Vulkan
----
Box64 використовує бібліотеки Vulkan, але зауважте що він тестувався з картою AMD Radeon RX550 і драйвером Freedreno, тому деякі розширення можуть бути відсутні залежно від вашої відеокарти.
----
Останнє слово
----
Я хочу подякувати всім, хто зробив внесок у розвиток box64.
Є багато способів зробити внесок: внесок коду, фінансовий внесок, апаратне забезпечення та реклама!
Отже, без особливого порядку, я хочу подякувати:
* За основний внесок у код: rajdakin, mogery
* За великий фінансовий внесок: FlyingFathead, stormchaser3000, dennis1248, sll00, [libre-computer-project](https://libre.computer/)
* За апаратне забезпечення та міграцію LoongArch: [xiaoji](https://www.linuxgame.cn/), команда розробників Deepin Beijing
* За основний внесок у код RV64 Dynarec: ksco, xctan
* За внесок у апаратне забезпечення: [Radxa](https://rockpi.org/), [Pine64](https://www.pine64.org/), [StarFive](https://rvspace.org/)
* За безперервну рекламу Box64: salva ([microLinux](https://www.youtube.com/channel/UCwFQAEj1lp3out4n7BeBatQ)), [PILab](https://www.youtube.com/channel/UCgfQjdc5RceRlTGfuthBs7g)/Команда [TwisterOS](https://twisteros.com/), [The Byteman](https://www.youtube.com/channel/UCEr8lpIJ3B5Ctc5BvcOHSnA), [NicoD](https://www.youtube.com/channel/UCpv7NFr0-9AB5xoklh3Snhg), ekianjo ([Boilingsteam](https://boilingsteam.com/))
І я також дякую багатьом іншим людям, які хоч раз брали участь у цьому проекті.
(Якщо ви використовуєте Box64 у своєму проекті, будь ласка, не забудьте згадати про це!)
+25
View File
@@ -1,3 +1,28 @@
v0.2.4
======
* Added Dynarec for RISC-V
* Added partial 32 bits support (WoW64 works)
* Changed cpuid to display box64
* Fixed steam, again
* Improved hacked version for overridden malloc/free functions
* More wrapped libs
* More wrapped functions and syscalls
* Reduced memory footprint
* Added support for the BIND_NOW flags in ELF files
* Added RTLD_NOLOAD support
* Fixed some typos and general cleanup, again
* Added a cosimulation mode (to compare the behaviour of the dynarec with the interpreter)
* Added FASTNAN/FASTROUND handling for more opcodes
* Better float/double/long double handling
* Better dlopen/dlclose handling
* More games in the rc file
* Added BOX64_DYNAREC_MISSING to show only missing opcode, independantly of the log level
* Added BOX64_RESERVE_HIGH to reserve addresses above 47bits
* Improved multitreading support
* Ukrainian translation of the README
=> Dynarec now support RISC-V, large speedup on RISC-V 64, were games are now playable (like Stardew Valley on a Vision Five 2)
=> Improved compatibility with more fixes in elf handling, more wrapped libs and functiond, more fixed opcodes and refined profile
v0.2.2
======
* Added a hacked version for overridden malloc/free functions, enabling libcef (and derivative) to work.
Executable → Regular
+8 -1
View File
@@ -7,7 +7,7 @@ You can use [@ryanfortner](https://github.com/ryanfortner)'s apt repository to i
```
sudo wget https://ryanfortner.github.io/box64-debs/box64.list -O /etc/apt/sources.list.d/box64.list
wget -qO- https://ryanfortner.github.io/box64-debs/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg
sudo apt update && sudo apt install box64-generic-arm -y
sudo apt update && sudo apt install box64-arm64 -y
```
Alternatively, you can generate your own package using the [instructions below](https://github.com/ptitSeb/box64/blob/main/docs/COMPILE.md#debian-packaging).
@@ -111,6 +111,13 @@ Using a 64bit OS:
-D PHYTIUM=1 -D CMAKE_BUILD_TYPE=RelWithDebInfo
```
#### for a generic ARM64 machine
Using a 64bit OS:
```
-D ARM64=1 -D CMAKE_BUILD_TYPE=RelWithDebInfo
```
#### for M1
Only test on Asahi for now, using the default "16K page" kernel
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Executable → Regular
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

+26 -1
View File
@@ -824,6 +824,10 @@ def main(root: str, files: Iterable[Filename], ver: str):
allowed_regs : str = "cCwWiuIUlLp"
allowed_fpr : str = "fd"
# Detect functions which return in an x87 register
retx87_wraps: Dict[ClausesStr, List[FunctionType]] = {}
return_x87: str = "DK"
# Sanity checks
forbidden_simple: str = "EDKVOSNMHPAxX"
assert(len(allowed_simply) + len(allowed_regs) + len(allowed_fpr) + len(forbidden_simple) == len(allowed_conv.values))
@@ -831,6 +835,7 @@ def main(root: str, files: Iterable[Filename], ver: str):
assert(all(c not in allowed_simply + allowed_regs for c in allowed_fpr))
assert(all(c not in allowed_simply + allowed_regs + allowed_fpr for c in forbidden_simple))
assert(all(c in allowed_simply + allowed_regs + allowed_fpr + forbidden_simple for c in allowed_conv.values))
assert(all(c in allowed_conv.values for c in return_x87))
def check_simple(v: FunctionType) -> Optional[int]:
regs_count: int = 0
@@ -867,6 +872,15 @@ def main(root: str, files: Iterable[Filename], ver: str):
simple_wraps[k] = tmp
simple_idxs = sorted(simple_wraps.keys(), key=lambda x: Clauses(x).splitdef())
def check_return_x87(v: FunctionType) -> bool:
return v[0] in return_x87
for k in gbls:
tmp = [v for v in gbls[k] if check_return_x87(v)]
if tmp:
retx87_wraps[k] = tmp
retx87_idxs = sorted(retx87_wraps.keys(), key=lambda x: Clauses(x).splitdef())
# Now the files rebuilding part
# File headers and guards
files_header = {
@@ -1381,6 +1395,17 @@ def main(root: str, files: Iterable[Filename], ver: str):
file.write("#endif\n")
file.write("\treturn 0;\n}\n")
# Write the isRetX87Wrapper function
file.write("\nint isRetX87Wrapper(wrapper_t fun) {\n")
for k in retx87_idxs:
if k != str(Clauses()):
file.write("#if " + k + "\n")
for vf in retx87_wraps[k]:
file.write("\tif (fun == &" + vf + ") return 1;\n")
if k != str(Clauses()):
file.write("#endif\n")
file.write("\treturn 0;\n}\n")
file.write(files_guard["wrapper.c"].format(lbr="{", rbr="}", version=ver))
# Rewrite the wrapper.h file:
@@ -1454,6 +1479,6 @@ if __name__ == '__main__':
if v == "--":
limit.append(i)
Define.defines = list(map(DefineType, sys.argv[2:limit[0]]))
if main(sys.argv[1], sys.argv[limit[0]+1:], "2.2.0.17") != 0:
if main(sys.argv[1], sys.argv[limit[0]+1:], "2.2.0.18") != 0:
exit(2)
exit(0)
Executable → Regular
View File
File mode changed.
Executable → Regular
+4
View File
@@ -259,6 +259,8 @@ box64context_t *NewBox64Context(int argc)
context->segtls[4].present = 1;
context->segtls[4].is32bits = 1;
context->globdata = NewMapSymbols();
initAllHelpers(context);
return context;
@@ -353,6 +355,8 @@ void FreeBox64Context(box64context_t** context)
if(ctx->emu_sig)
FreeX64Emu(&ctx->emu_sig);
FreeMapSymbols(&ctx->globdata);
finiAllHelpers(ctx);
#ifdef DYNAREC
Executable → Regular
+1 -1
View File
@@ -3,6 +3,6 @@
#define BOX64_MAJOR 0
#define BOX64_MINOR 2
#define BOX64_REVISION 3
#define BOX64_REVISION 4
#endif //__BOX64_VERSION_H_
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
+2 -1
View File
@@ -1463,7 +1463,7 @@ void init_custommem_helper(box64context_t* ctx)
memprot[i].prot = memprot_default;
init_mutexes();
#ifdef DYNAREC
if(box64_dynarec)
if(box64_dynarec) {
for(int i=0; i<(1<<JMPTABL_SHIFT3); ++i)
box64_jmptbl3[i] = box64_jmptbldefault2;
for(int i=0; i<(1<<JMPTABL_SHIFT2); ++i)
@@ -1472,6 +1472,7 @@ void init_custommem_helper(box64context_t* ctx)
box64_jmptbldefault1[i] = box64_jmptbldefault0;
for(int i=0; i<(1<<JMPTABL_SHIFT0); ++i)
box64_jmptbldefault0[i] = (uintptr_t)native_next;
}
lockaddress = kh_init(lockaddress);
#endif
pthread_atfork(NULL, NULL, atfork_child_custommem);
+42 -11
View File
@@ -363,6 +363,9 @@
#define POP2_32(reg1, reg2) LDPw_S7_postindex(reg1, reg2, xRSP, 8)
#define PUSH2_32(reg1, reg2) STPw_S7_preindex(reg2, reg1, xRSP, -8)
#define POP1_16(reg) LDRH_S9_postindex(reg, xRSP, 2)
#define PUSH1_16(reg) STRH_S9_preindex(reg, xRSP, -2)
#define POP1z(reg) if(rex.is32bits) {POP1_32(reg);} else {POP1(reg);}
#define PUSH1z(reg) if(rex.is32bits) {PUSH1_32(reg);} else {PUSH1(reg);}
#define POP2z(reg1, reg2) if(rex.is32bits) {POP2_32(reg1, reg2);} else {POP2(reg1, reg2);}
@@ -487,9 +490,9 @@
#define CSNEGx(Rd, Rn, Rm, cond) EMIT(CSNEG_gen(1, Rm, cond, Rn, Rd))
#define CSNEGw(Rd, Rn, Rm, cond) EMIT(CSNEG_gen(0, Rm, cond, Rn, Rd))
#define CSNEGxw(Rd, Rn, Rm, cond) EMIT(CSNEG_gen(rex.w, Rm, cond, Rn, Rd))
#define CNEGx(Rd, Rn, cond) CSNEGx(Rn, Rn, Rn, invCond(cond))
#define CNEGw(Rd, Rn, cond) CSNEGw(Rn, Rn, Rn, invCond(cond))
#define CNEGxw(Rd, Rn, cond) CSNEGxw(Rn, Rn, Rn, invCond(cond))
#define CNEGx(Rd, Rn, cond) CSNEGx(Rn, Rn, Rd, invCond(cond))
#define CNEGw(Rd, Rn, cond) CSNEGw(Rn, Rn, Rd, invCond(cond))
#define CNEGxw(Rd, Rn, cond) CSNEGxw(Rn, Rn, Rd, invCond(cond))
// AND / ORR
#define LOGIC_gen(sf, opc, N, immr, imms, Rn, Rd) ((sf)<<31 | (opc)<<29 | 0b100100<<23 | (N)<<22 | (immr)<<16 | (imms)<<10 | (Rn)<<5 | Rd)
@@ -534,6 +537,15 @@
#define EORx_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(1, 0b10, 0b01, 0, Rm, lsr, Rn, Rd))
#define EORw_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(0, 0b10, 0b01, 0, Rm, lsr, Rn, Rd))
#define EORxw_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(rex.w, 0b10, 0b01, 0, Rm, lsr, Rn, Rd))
#define EONx_REG(Rd, Rn, Rm) EMIT(LOGIC_REG_gen(1, 0b10, 0b00, 1, Rm, 0, Rn, Rd))
#define EONw_REG(Rd, Rn, Rm) EMIT(LOGIC_REG_gen(0, 0b10, 0b00, 1, Rm, 0, Rn, Rd))
#define EONxw_REG(Rd, Rn, Rm) EMIT(LOGIC_REG_gen(rex.w, 0b10, 0b00, 1, Rm, 0, Rn, Rd))
#define EONx_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(1, 0b10, 0b00, 1, Rm, lsl, Rn, Rd))
#define EONw_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(0, 0b10, 0b00, 1, Rm, lsl, Rn, Rd))
#define EONxw_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(rex.w, 0b10, 0b00, 1, Rm, lsl, Rn, Rd))
#define EONx_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(1, 0b10, 0b01, 1, Rm, lsr, Rn, Rd))
#define EONw_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(0, 0b10, 0b01, 1, Rm, lsr, Rn, Rd))
#define EONxw_REG_LSR(Rd, Rn, Rm, lsr) EMIT(LOGIC_REG_gen(rex.w, 0b10, 0b01, 1, Rm, lsr, Rn, Rd))
#define MOVx_REG(Rd, Rm) ORRx_REG(Rd, xZR, Rm)
#define MOVw_REG(Rd, Rm) ORRw_REG(Rd, xZR, Rm)
#define MOVxw_REG(Rd, Rm) ORRxw_REG(Rd, xZR, Rm)
@@ -560,6 +572,12 @@
#define BICx_REG BICx
#define BICw_REG BICw
#define BICxw_REG BICxw
#define BICx_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(1, 0b00, 0b00, 1, Rm, lsl, Rn, Rd))
#define BICw_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(0, 0b00, 0b00, 1, Rm, lsl, Rn, Rd))
#define BICxw_REG_LSL(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(rex.w, 0b00, 0b00, 1, Rm, lsl, Rn, Rd))
#define BICx_REG_LSR(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(1, 0b00, 0b01, 1, Rm, lsl, Rn, Rd))
#define BICw_REG_LSR(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(0, 0b00, 0b01, 1, Rm, lsl, Rn, Rd))
#define BICxw_REG_LSR(Rd, Rn, Rm, lsl) EMIT(LOGIC_REG_gen(rex.w, 0b00, 0b01, 1, Rm, lsl, Rn, Rd))
#define TSTx_REG(Rn, Rm) ANDSx_REG(xZR, Rn, Rm)
#define TSTw_REG(Rn, Rm) ANDSw_REG(wZR, Rn, Rm)
#define TSTxw_REG(Rn, Rm) ANDSxw_REG(xZR, Rn, Rm)
@@ -950,6 +968,10 @@
#define VSUB_16(Vd, Vn, Vm) EMIT(ADDSUB_vector(0, 1, 0b01, Vm, Vn, Vd))
#define VSUB_32(Vd, Vn, Vm) EMIT(ADDSUB_vector(0, 1, 0b10, Vm, Vn, Vd))
#define ADDSUB_scalar(U, size, Rm, Rn, Rd) (01<<30 | (U)<<29 | 0b11110<<24 | (size)<<22 | 1<<21 | (Rm)<<16 | 0b10000<<11 | 1<<10 | (Rn)<<5 | (Rd))
#define ADD_64(Vd, Vn, Vm) EMIT(ADDSUB_scalar(0, 0b11, Vm, Vn, Vd))
#define SUB_64(Vd, Vn, Vm) EMIT(ADDSUB_scalar(1, 0b11, Vm, Vn, Vd))
#define NEGABS_vector(Q, U, size, Rn, Rd) ((Q)<<30 | (U)<<29 | 0b01110<<24 | (size)<<22 | 0b10000<<17 | 0b01011<<12 | 0b10<<10 | (Rn)<<5 | (Rd))
#define NEG_8(Vd, Vn) EMIT(NEGABS_vector(0, 1, 0b00, Vn, Vd))
#define NEG_16(Vd, Vn) EMIT(NEGABS_vector(0, 1, 0b01, Vn, Vd))
@@ -1424,14 +1446,23 @@
#define VUZP1Q_64(Rt, Rn, Rm) EMIT(UZP_gen(1, 0b11, Rm, 0, Rn, Rt))
#define VUZP2Q_64(Rt, Rn, Rm) EMIT(UZP_gen(1, 0b11, Rm, 1, Rn, Rt))
#define DUP_gen(Q, imm5, Rn, Rd) ((Q)<<30 | 0b01110000<<21 | (imm5)<<16 | 1<<10 | (Rn)<<5 | (Rd))
#define VDUP_8(Vd, Vn, idx) EMIT(DUP_gen(0, ((idx)<<1|1), Vn, Vd))
#define VDUPQ_8(Vd, Vn, idx) EMIT(DUP_gen(1, ((idx)<<1|1), Vn, Vd))
#define VDUP_16(Vd, Vn, idx) EMIT(DUP_gen(0, ((idx)<<2|0b10), Vn, Vd))
#define VDUPQ_16(Vd, Vn, idx) EMIT(DUP_gen(1, ((idx)<<2|0b10), Vn, Vd))
#define VDUP_32(Vd, Vn, idx) EMIT(DUP_gen(0, ((idx)<<3|0b100), Vn, Vd))
#define VDUPQ_32(Vd, Vn, idx) EMIT(DUP_gen(1, ((idx)<<3|0b100), Vn, Vd))
#define VDUPQ_64(Vd, Vn, idx) EMIT(DUP_gen(1, ((idx)<<4|0b1000), Vn, Vd))
#define DUP_element(Q, imm5, Rn, Rd) ((Q)<<30 | 0b01110000<<21 | (imm5)<<16 | 1<<10 | (Rn)<<5 | (Rd))
#define VDUP_8(Vd, Vn, idx) EMIT(DUP_element(0, ((idx)<<1|1), Vn, Vd))
#define VDUPQ_8(Vd, Vn, idx) EMIT(DUP_element(1, ((idx)<<1|1), Vn, Vd))
#define VDUP_16(Vd, Vn, idx) EMIT(DUP_element(0, ((idx)<<2|0b10), Vn, Vd))
#define VDUPQ_16(Vd, Vn, idx) EMIT(DUP_element(1, ((idx)<<2|0b10), Vn, Vd))
#define VDUP_32(Vd, Vn, idx) EMIT(DUP_element(0, ((idx)<<3|0b100), Vn, Vd))
#define VDUPQ_32(Vd, Vn, idx) EMIT(DUP_element(1, ((idx)<<3|0b100), Vn, Vd))
#define VDUPQ_64(Vd, Vn, idx) EMIT(DUP_element(1, ((idx)<<4|0b1000), Vn, Vd))
#define DUP_general(Q, imm5, Rn, Rd) ((Q)<<30 | 0b01110000<<21 | (imm5)<<16 | 0b11<<10 | (Rn)<<5 | (Rd))
#define VDUPB(Vd, Wn) EMIT(DUP_general(0, 0b1, Wn, Vd))
#define VDUPQB(Vd, Wn) EMIT(DUP_general(1, 0b1, Wn, Vd))
#define VDUPH(Vd, Wn) EMIT(DUP_general(0, 0b10, Wn, Vd))
#define VDUPQH(Vd, Wn) EMIT(DUP_general(1, 0b10, Wn, Vd))
#define VDUPS(Vd, Wn) EMIT(DUP_general(0, 0b100, Wn, Vd))
#define VDUPQS(Vd, Wn) EMIT(DUP_general(1, 0b100, Wn, Vd))
#define VDUPQD(Vd, Xn) EMIT(DUP_general(1, 0b1000, Xn, Vd))
// TBL
#define TBL_gen(Q, Rm, len, op, Rn, Rd) ((Q)<<30 | 0b001110<<24 | (Rm)<<16 | (len)<<13 | (op)<<12 | (Rn)<<5 | (Rd))
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
Executable → Regular
+13 -13
View File
@@ -27,46 +27,46 @@ extern void arm64_lock_read_dq(uint64_t * a, uint64_t* b, void* addr);
// STLXRD of ADDR, return 0 if ok, 1 if not
extern int arm64_lock_write_dq(uint64_t a, uint64_t b, void* addr);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uintptr_t arm64_lock_xchg_dd(void* p, uintptr_t val);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uint32_t arm64_lock_xchg_d(void* p, uint32_t val);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uint32_t arm64_lock_xchg_h(void* p, uint32_t val);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uint32_t arm64_lock_xchg_b(void* p, uint32_t val);
// Atomicaly store value to [p] only if [p] is NULL. Return old [p] value
// Atomically store value to [p] only if [p] is NULL. Return old [p] value
extern uint32_t arm64_lock_storeifnull_d(void*p, uint32_t val);
// Atomicaly store value to [p] only if [p] is NULL. Return old [p] value
// Atomically store value to [p] only if [p] is NULL. Return old [p] value
extern void* arm64_lock_storeifnull(void*p, void* val);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern void* arm64_lock_storeifref(void*p, void* val, void* ref);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern uint32_t arm64_lock_storeifref_d(void*p, uint32_t val, uint32_t ref);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern uint32_t arm64_lock_storeifref2_d(void*p, uint32_t val, uint32_t ref);
// decrement atomicaly the byte at [p] (but only if p not 0)
// decrement atomically the byte at [p] (but only if p not 0)
extern void arm64_lock_decifnot0b(void*p);
// atomic store (with memory barrier)
extern void arm64_lock_storeb(void*p, uint8_t b);
// increment atomicaly the int at [p] only if it was 0. Return the old value of [p]
// increment atomically the int at [p] only if it was 0. Return the old value of [p]
extern int arm64_lock_incif0(void*p);
// decrement atomicaly the int at [p] (but only if p not 0)
// decrement atomically the int at [p] (but only if p not 0)
extern int arm64_lock_decifnot0(void*p);
// atomic store (with memory barrier)
extern void arm64_lock_store(void*p, uint32_t v);
#endif //__ARM64_LOCK__H__
#endif //__ARM64_LOCK__H__
Executable → Regular
View File
File mode changed.
+26 -3
View File
@@ -1107,7 +1107,19 @@ const char* arm64_print(uint32_t opcode, uintptr_t addr)
snprintf(buff, sizeof(buff), "FSQRT %c%d, %c%d", s, Rd, s, Rn);
return buff;
}
// FPRINTX
if(isMask(opcode, "0Q1011100f100001100110nnnnnddddd", &a)) {
char s = a.Q?'V':'D';
char d = sf?'D':'S';
int n = (a.Q && !sf)?4:2;
snprintf(buff, sizeof(buff), "VFRINTX %c%d.%d%c, %c%d.%d%c", s, Rd, n, d, s, Rn, n, d);
return buff;
}
if (isMask(opcode, "00011110ff100111010000nnnnnddddd", &a)) {
char s = (sf==0)?'S':((sf==1)?'D':'?');
snprintf(buff, sizeof(buff), "FRINTX %c%d, %c%d", s, Rd, s, Rn);
return buff;
}
// FRINTI
if(isMask(opcode, "0Q1011101f100001100110nnnnnddddd", &a)) {
char s = a.Q?'V':'D';
@@ -1487,7 +1499,7 @@ const char* arm64_print(uint32_t opcode, uintptr_t addr)
// DUP
if(isMask(opcode, "0Q001110000iiiii000001nnnnnddddd", &a)) {
const char* Y[] = {"8B", "16B", "4H", "8H", "2S", "4S", "2D", "??"};
const char* Y[] = {"8B", "16B", "4H", "8H", "2S", "4S", "??", "2D"};
const char* Z[] = {"B", "H", "S", "D"};
int sz = 3;
if((imm&0b0001)==0b0001) sz=0;
@@ -1499,7 +1511,18 @@ const char* arm64_print(uint32_t opcode, uintptr_t addr)
snprintf(buff, sizeof(buff), "DUP V%d.%s, V%d.%s[%d]", Rd, Vd, Rn, Vn, sh);
return buff;
}
if(isMask(opcode, "0Q001110000iiiii000011nnnnnddddd", &a)) {
const char* Y[] = {"8B", "16B", "4H", "8H", "2S", "4S", "??", "2D"};
int sz = 3;
if((imm&0b0001)==0b0001) sz=0;
else if((imm&0b0011)==0b0010) sz=1;
else if((imm&0b0111)==0b0100) sz=2;
const char* Vd = Y[(sz<<1)|a.Q];
snprintf(buff, sizeof(buff), "DUP V%d.%s, X%d", Rd, Vd, Rn);
return buff;
}
// AES
if(isMask(opcode, "0100111000101000010f10nnnnnddddd", &a)) {
snprintf(buff, sizeof(buff), "AES%c V%d.16B, V%d.16B", sf?'D':'E', Rd, Rn);
Executable → Regular
View File
File mode changed.
+74 -30
View File
@@ -25,6 +25,7 @@
#include "dynarec_arm64_helper.h"
int isSimpleWrapper(wrapper_t fun);
int isRetX87Wrapper(wrapper_t fun);
uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, rex_t rex, int rep, int* ok, int* need_epilog)
{
@@ -525,6 +526,19 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
emit_cmp32_0(dyn, ninst, rex, xRAX, x3, x4);
break;
case 0x3F:
if(rex.is32bits) {
INST_NAME("AAS");
MESSAGE(LOG_DUMP, "Need Optimization AAS\n");
READFLAGS(X_AF);
SETFLAGS(X_AF|X_CF|X_PF|X_SF|X_ZF, SF_SET);
UXTHw(x1, xRAX);
CALL_(aas16, x1, 0);
BFIx(xRAX, x1, 0, 16);
} else {
DEFAULT;
}
break;
case 0x40:
case 0x41:
case 0x42:
@@ -665,7 +679,16 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
DEFAULT;
}
break;
case 0x62:
if(rex.is32bits) {
// BOUND here
DEFAULT;
} else {
INST_NAME("BOUND Gd, Ed");
nextop = F8;
FAKEED(0);
}
break;
case 0x63:
if(rex.is32bits) {
// ARPL here
@@ -1007,7 +1030,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
nextop=F8;
GETGD;
GETED(0);
emit_test32(dyn, ninst, rex, ed, gd, x3, x5);
emit_test32(dyn, ninst, rex, ed, gd, x3, x5, x6);
break;
case 0x86:
INST_NAME("(LOCK)XCHG Eb, Gb");
@@ -1301,6 +1324,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
else
u64 = F64;
MOV64z(x1, u64);
SMREAD();
LDRB_U12(x2, x1, 0);
BFIx(xRAX, x2, 0, 8);
break;
@@ -1311,6 +1335,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
else
u64 = F64;
MOV64z(x1, u64);
SMREAD();
LDRxw_U12(xRAX, x1, 0);
break;
case 0xA2:
@@ -1476,7 +1501,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
SETFLAGS(X_ALL, SF_SET_PENDING);
i64 = F32S;
MOV64xw(x2, i64);
emit_test32(dyn, ninst, rex, xRAX, x2, x3, x4);
emit_test32(dyn, ninst, rex, xRAX, x2, x3, x4, x5);
break;
case 0xAA:
if(rep) {
@@ -1522,26 +1547,42 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
ADDx_REG(xRDI, xRDI, x3);
}
break;
case 0xAC:
if(rep) {
INST_NAME("REP LODSB");
} else {
INST_NAME("LODSB");
}
GETDIR(x1, 1);
if(rep) {
CBZx_NEXT(xRCX);
MARK;
}
LDRB_U12(x2, xRSI, 0);
ADDx_REG(xRSI, xRSI, x1);
if(rep) {
SUBx_U12(xRCX, xRCX, 1);
CBNZx_MARK(xRCX);
}
BFIx(xRAX, x2, 0, 8);
break;
case 0xAD:
if(rep) {
INST_NAME("REP LODSD");
} else {
INST_NAME("LODSD");
}
LDRxw_U12(xRAX, xRSI, 0);
BFIw(x2, xFlags, F_DF, 1);
if(rex.w) {
MOV32w(x1, 8);
} else {
MOV32w(x1, 4);
}
EORxw_REG_LSL(x1, x1, x2, rex.w?63:31);
GETDIR(x1, rex.w?8:4);
if(rep) {
MULxw(x1, x1, xRCX);
EORw_REG(xRCX, xRCX, xRCX);
CBZx_NEXT(xRCX);
MARK;
}
LDRxw_U12(xRAX, xRSI, 0);
ADDx_REG(xRSI, xRSI, x1);
if(rep) {
SUBx_U12(xRCX, xRCX, 1);
CBNZx_MARK(xRCX);
}
break;
case 0xAE:
switch(rep) {
@@ -1901,6 +1942,9 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
x87_forget(dyn, ninst, x3, x4, 0);
sse_purge07cache(dyn, ninst, x3);
tmp = isSimpleWrapper(*(wrapper_t*)(addr));
if(isRetX87Wrapper(*(wrapper_t*)(addr)))
// return value will be on the stack, so the stack depth needs to be updated
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
if((box64_log<2 && !cycle_log) && tmp) {
//GETIP(ip+3+8+8); // read the 0xCC
call_n(dyn, ninst, *(void**)(addr+8), tmp);
@@ -1941,10 +1985,15 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
break;
case 0xCD:
u8 = F8;
if(box64_wine && u8==0x2D) {
INST_NAME("INT 2D");
if(box64_wine && (u8==0x2D || u8==0x2C || u8==0x29)) {
INST_NAME("INT 29/2c/2d");
// lets do nothing
MESSAGE(LOG_INFO, "INT 2D Windows anti-debug hack\n");
MESSAGE(LOG_INFO, "INT 29/2c/2d Windows interruption\n");
GETIP(ip);
STORE_XEMU_CALL(xRIP);
MOV32w(x1, u8);
CALL(native_int, -1);
LOAD_XEMU_CALL(xRIP);
} else if (u8==0x80) {
INST_NAME("32bits SYSCALL");
NOTEST(x1);
@@ -1961,14 +2010,6 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
MARK;
LOAD_XEMU_REM();
jump_to_epilog(dyn, 0, xRIP, ninst);
} else if(box64_wine && u8==0x29) {
INST_NAME("INT 0x29");
// __fastfail ignored!
MOV32w(x1, 1);
STRw_U12(x1, xEmu, offsetof(x64emu_t, quit));
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
*ok = 0;
} else {
INST_NAME("INT n");
SETFLAGS(X_ALL, SF_SET); // Hack to set flags in "don't care" state
@@ -2338,7 +2379,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
READFLAGS(X_ZF);
i8 = F8S;
SUBz_U12(xRCX, xRCX, 1);
TBNZ_NEXT(xFlags, 1<<F_ZF);
TBNZ_NEXT(xFlags, F_ZF);
GO(0);
break;
case 0xE1:
@@ -2346,7 +2387,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
READFLAGS(X_ZF);
i8 = F8S;
SUBz_U12(xRCX, xRCX, 1);
TBZ_NEXT(xFlags, 1<<F_ZF);
TBZ_NEXT(xFlags, F_ZF);
GO(0);
break;
case 0xE2:
@@ -2392,10 +2433,13 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
SKIPTEST(x1); // disable test as this hack dos 2 instructions for 1
// calling a native function
sse_purge07cache(dyn, ninst, x3);
if((box64_log<2 && !cycle_log) && dyn->insts[ninst].natcall)
if((box64_log<2 && !cycle_log) && dyn->insts[ninst].natcall) {
tmp=isSimpleWrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2));
else
} else
tmp=0;
if(dyn->insts[ninst].natcall && isRetX87Wrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2)))
// return value will be on the stack, so the stack depth needs to be updated
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
if((box64_log<2 && !cycle_log) && dyn->insts[ninst].natcall && tmp) {
//GETIP(ip+3+8+8); // read the 0xCC
call_n(dyn, ninst, *(void**)(dyn->insts[ninst].natcall+2+8), tmp);
@@ -2604,7 +2648,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
GETEDH(x1, 4);
i64 = F32S;
MOV64xw(x2, i64);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4, x5);
break;
case 2:
INST_NAME("NOT Ed");
+108 -16
View File
@@ -30,8 +30,8 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
uint8_t opcode = F8;
uint8_t nextop, u8;
uint8_t gd, ed;
uint8_t wback, wb2;
uint8_t eb1, eb2;
uint8_t wback, wb1, wb2;
uint8_t eb1, eb2, gb1, gb2;
int32_t i32, i32_;
int cacheupd = 0;
int v0, v1;
@@ -42,9 +42,12 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
int64_t j64;
int64_t fixedaddress;
int unscaled;
MAYUSE(wb1);
MAYUSE(wb2);
MAYUSE(eb1);
MAYUSE(eb2);
MAYUSE(gb1);
MAYUSE(gb2);
MAYUSE(q0);
MAYUSE(q1);
MAYUSE(d0);
@@ -1104,7 +1107,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<(2+rex.w), (1<<(2+rex.w))-1, rex, NULL, 0, 0);
ASRxw(x1, gd, 5+rex.w); // r1 = (gd>>5)
ASRx(x1, gd, 5+rex.w); // r1 = (gd>>5)
ADDx_REG_LSL(x3, wback, x1, 2+rex.w); //(&ed)+=r1*4;
LDxw(x1, x3, fixedaddress);
ed = x1;
@@ -1152,7 +1155,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<(2+rex.w), (1<<(2+rex.w))-1, rex, NULL, 0, 0);
ASRxw(x1, gd, 5+rex.w); // r1 = (gd>>5)
ASRx(x1, gd, 5+rex.w); // r1 = (gd>>5)
ADDx_REG_LSL(x3, wback, x1, 2+rex.w); //(&ed)+=r1*4;
LDxw(x1, x3, fixedaddress);
ed = x1;
@@ -1318,7 +1321,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<(2+rex.w), (1<<(2+rex.w))-1, rex, NULL, 0, 0);
ASRxw(x1, gd, 5+rex.w); // r1 = (gd>>5)
ASRx(x1, gd, 5+rex.w); // r1 = (gd>>5)
ADDx_REG_LSL(x3, wback, x1, 2+rex.w); //(&ed)+=r1*4;
LDxw(x1, x3, fixedaddress);
ed = x1;
@@ -1331,15 +1334,14 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
}
LSRxw_REG(x4, ed, x2);
if(rex.w) {
ANDSx_mask(x4, x4, 1, 0, 0); //mask=1
ANDx_mask(x4, x4, 1, 0, 0); //mask=1
} else {
ANDSw_mask(x4, x4, 0, 0); //mask=1
ANDw_mask(x4, x4, 0, 0); //mask=1
}
BFIw(xFlags, x4, F_CF, 1);
MOV32w(x4, 1);
LSLxw_REG(x4, x4, x2);
EORxw_REG(x4, ed, x4);
CSELxw(ed, ed, x4, cEQ);
BICxw_REG(ed, ed, x4);
if(wback) {
STRxw_U12(ed, wback, fixedaddress);
SMWRITE();
@@ -1418,7 +1420,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
BFXILxw(xFlags, ed, u8, 1); // inject 1 bit from u8 to F_CF (i.e. pos 0)
TBNZ_MARK3(xFlags, 0); // bit already set, jump to next instruction
MOV32w(x4, 1);
EORxw_REG_LSL(ed, ed, x4, u8);
ORRxw_REG_LSL(ed, ed, x4, u8);
if(wback) {
STxw(ed, wback, fixedaddress);
SMWRITE();
@@ -1443,7 +1445,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
BFXILxw(xFlags, ed, u8, 1); // inject 1 bit from u8 to F_CF (i.e. pos 0)
TBZ_MARK3(xFlags, 0); // bit already clear, jump to next instruction
MOV32w(x4, 1);
EORxw_REG_LSL(ed, ed, x4, u8);
BICxw_REG_LSL(ed, ed, x4, u8);
if(wback) {
STxw(ed, wback, fixedaddress);
SMWRITE();
@@ -1490,7 +1492,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<(2+rex.w), (1<<(2+rex.w))-1, rex, NULL, 0, 0);
ASRxw(x1, gd, 5+rex.w); // r1 = (gd>>5)
ASRx(x1, gd, 5+rex.w); // r1 = (gd>>5)
ADDx_REG_LSL(x3, wback, x1, 2+rex.w); //(&ed)+=r1*4;
LDxw(x1, x3, fixedaddress);
ed = x1;
@@ -1580,7 +1582,29 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
LDSHxw(gd, ed, fixedaddress);
}
break;
case 0xC0:
INST_NAME("XADD Gb, Eb");
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGB(x1);
GETEB(x2, 0);
gd = x2; ed = x1; // swap gd/ed
emit_add8(dyn, ninst, x1, x2, x4, x5);
GBBACK; // gb gets x2 (old ed)
EBBACK; // eb gets x1 (sum)
break;
case 0xC1:
INST_NAME("XADD Gd, Ed");
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGD;
GETED(0);
MOVxw_REG(x3, ed);
MOVxw_REG(ed, gd);
MOVxw_REG(gd, x3);
emit_add32(dyn, ninst, rex, ed, gd, x4, x5);
WBACK;
break;
case 0xC2:
INST_NAME("CMPPS Gx, Ex, Ib");
nextop = F8;
@@ -1701,7 +1725,56 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
gd = xRAX+(opcode&7)+(rex.b<<3);
REVxw(gd, gd);
break;
case 0xD1:
INST_NAME("PSRLW Gm, Em");
nextop = F8;
GETGM(d0);
GETEM(d1, 0);
if(MODREG) {
q0 = fpu_get_scratch(dyn);
}
else {
q0 = d1;
}
q1 = fpu_get_scratch(dyn);
VMOVBto(x1, d1, 0);
MOVZw(x2, 16);
SUBSw_REG(x2, x2, x1);
B_MARK(cGT);
VMOVQDfrom(d0, 0, xZR);
B_NEXT_nocond;
MARK;
VDUPQS(q1, x2);
UXTL_16(q0, d0);
USHLQ_32(q0, q0, q1);
VUZP2Q_16(q0, q0, q0);
VMOVeD(d0, 0, q0, 0);
break;
case 0xD2:
INST_NAME("PSRLD Gm, Em");
nextop = F8;
GETGM(d0);
GETEM(d1, 0);
if(MODREG) {
q0 = fpu_get_scratch(dyn);
}
else {
q0 = d1;
}
q1 = fpu_get_scratch(dyn);
VMOVBto(x1, d1, 0);
MOVZw(x2, 32);
SUBSw_REG(x2, x2, x1);
B_MARK(cGT);
VMOVQDfrom(d0, 0, xZR);
B_NEXT_nocond;
MARK;
VDUPQD(q1, x2);
UXTL_32(q0, d0);
USHLQ_64(q0, q0, q1);
VUZP2Q_32(q0, q0, q0);
VMOVeD(d0, 0, q0, 0);
break;
case 0xD3:
INST_NAME("PSRLQ Gm,Em");
nextop = F8;
@@ -1714,7 +1787,13 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
NEG_64(q0, d1);
USHL_R_64(d0, d0, q0);
break;
case 0xD4:
INST_NAME("PADDQ Gm,Em");
nextop = F8;
GETGM(v0);
GETEM(q0, 0);
ADD_64(v0, v0, q0);
break;
case 0xD5:
INST_NAME("PMULLW Gm, Em");
nextop = F8;
@@ -1908,7 +1987,13 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
SQXTN_32(v0, v0); // 2*q1 in 32bits now
SSHL_32(d0, d0, v0);
break;
case 0xF4:
INST_NAME("PMULUDQ Gx,Ex");
nextop = F8;
GETGX(v0, 1);
GETEX(v1, 0, 0);
VUMULL_32(v0, v0, v1);
break;
case 0xF5:
INST_NAME("PMADDWD Gm, Em");
nextop = F8;
@@ -1961,6 +2046,13 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
GETEM(v1, 0);
VADD_8(v0, v0, v1);
break;
case 0xFB:
INST_NAME("PSUBQ Gm, Em");
nextop = F8;
GETGM(v0);
GETEM(v1, 0);
SUB_64(v0, v0, v1);
break;
case 0xFD:
INST_NAME("PADDW Gm, Em");
nextop = F8;
+1 -1
View File
@@ -884,7 +884,7 @@ uintptr_t dynarec64_64(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
GETEDO(x6, 4);
i64 = F32S;
MOV64xw(x2, i64);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4, x5);
break;
case 2:
INST_NAME("NOT Ed");
+106 -26
View File
@@ -319,35 +319,78 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
emit_dec16(dyn, ninst, x1, x2, x3);
BFIw(gd, x1, 0, 16);
break;
case 0x50:
case 0x51:
case 0x52:
case 0x53:
case 0x54:
case 0x55:
case 0x56:
case 0x57:
if(rex.is32bits) {
INST_NAME("PUSH reg");
gd = xRAX+(opcode&0x07);
if (gd == xRSP) {
MOVw_REG(x1, xRSP);
PUSH1_16(x1);
} else {
PUSH1_16(gd);
}
} else {
DEFAULT;
}
break;
case 0x58:
case 0x59:
case 0x5A:
case 0x5B:
case 0x5C:
case 0x5D:
case 0x5E:
case 0x5F:
if(rex.is32bits) {
INST_NAME("POP reg");
gd = xRAX+(opcode&0x07);
POP1_16(x1);
BFIw(gd, x1, 0, 16);
} else {
DEFAULT;
}
break;
case 0x60:
if(rex.is32bits) {
INST_NAME("PUSHA 16 (32bits)");
INST_NAME("PUSHA 16bits (32bits)");
MOVw_REG(x1, xRSP);
STRH_S9_preindex(xRAX, xRSP, -2);
STRH_S9_preindex(xRCX, xRSP, -2);
STRH_S9_preindex(xRDX, xRSP, -2);
STRH_S9_preindex(xRBX, xRSP, -2);
STRH_S9_preindex(x1, xRSP, -2);
STRH_S9_preindex(xRBP, xRSP, -2);
STRH_S9_preindex(xRSI, xRSP, -2);
STRH_S9_preindex(xRDI, xRSP, -2);
PUSH1_16(xRAX);
PUSH1_16(xRCX);
PUSH1_16(xRDX);
PUSH1_16(xRBX);
PUSH1_16(x1);
PUSH1_16(xRBP);
PUSH1_16(xRSI);
PUSH1_16(xRDI);
} else {
DEFAULT;
}
break;
case 0x61:
if(rex.is32bits) {
INST_NAME("POPA 16 (32bits)");
MOVw_REG(x1, xRSP);
LDRH_S9_postindex(xRDI, xRSP, 2);
LDRH_S9_postindex(xRSI, xRSP, 2);
LDRH_S9_postindex(xRBP, xRSP, 2);
LDRH_S9_postindex(x1, xRSP, 2);
LDRH_S9_postindex(xRBX, xRSP, 2);
LDRH_S9_postindex(xRDX, xRSP, 2);
LDRH_S9_postindex(xRCX, xRSP, 2);
LDRH_S9_postindex(xRAX, xRSP, 2);
INST_NAME("POPA 16bits (32bits)");
POP1_16(x1);
BFIw(xRDI, x1, 0, 16);
POP1_16(x1);
BFIw(xRSI, x1, 0, 16);
POP1_16(x1);
BFIw(xRBP, x1, 0, 16);
POP1_16(x1); // RSP ignored
POP1_16(x1);
BFIw(xRBX, x1, 0, 16);
POP1_16(x1);
BFIw(xRDX, x1, 0, 16);
POP1_16(x1);
BFIw(xRCX, x1, 0, 16);
POP1_16(x1);
BFIw(xRAX, x1, 0, 16);
} else {
DEFAULT;
}
@@ -589,7 +632,30 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
case 0x98:
INST_NAME("CBW");
SXTBw(x1, xRAX);
BFIw(xRAX, x1, 0, 16);
BFIx(xRAX, x1, 0, 16);
break;
case 0x9C:
INST_NAME("PUSHF");
READFLAGS(X_ALL);
PUSH1_16(xFlags);
break;
case 0x9D:
INST_NAME("POPF");
SETFLAGS(X_ALL, SF_SET);
POP1_16(x1); // probably not usefull...
BFIw(xFlags, x1, 0, 16);
MOV32w(x1, 0x3F7FD7);
ANDw_REG(xFlags, xFlags, x1);
ORRw_mask(xFlags, xFlags, 0b011111, 0); //mask=0x00000002
SET_DFNONE(x1);
if(box64_wine) { // should this be done all the time?
TBZ_NEXT(xFlags, F_TF);
MOV64x(x1, addr);
STORE_XEMU_CALL(x1);
CALL(native_singlestep, -1);
BFCw(xFlags, F_TF, 1);
}
break;
case 0xA1:
@@ -599,6 +665,7 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
else
u64 = F64;
MOV64z(x1, u64);
SMREAD();
LDRH_U12(x2, x1, 0);
BFIx(xRAX, x2, 0, 16);
break;
@@ -719,20 +786,23 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
CBZx_NEXT(xRCX);
TBNZ_MARK2(xFlags, F_DF);
MARK; // Part with DF==0
LDRH_S9_postindex(xRAX, xRSI, 2);
LDRH_S9_postindex(x2, xRSI, 2);
SUBx_U12(xRCX, xRCX, 1);
CBNZx_MARK(xRCX);
B_NEXT_nocond;
B_MARK3_nocond;
MARK2; // Part with DF==1
LDRH_S9_postindex(xRAX, xRSI, -2);
LDRH_S9_postindex(x2, xRSI, -2);
SUBx_U12(xRCX, xRCX, 1);
CBNZx_MARK2(xRCX);
MARK3;
BFIx(xRAX, x2, 0, 16);
// done
} else {
INST_NAME("STOSW");
INST_NAME("LODSW");
GETDIR(x3, 2);
LDRH_U12(xRAX, xRSI, 0);
LDRH_U12(x2, xRSI, 0);
ADDx_REG(xRSI, xRSI, x3);
BFIx(xRAX, x2, 0, 16);
}
break;
@@ -1094,6 +1164,16 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
emit_dec16(dyn, ninst, x1, x2, x4);
EWBACK;
break;
case 6: // Push Ew
if(rex.is32bits) {
INST_NAME("PUSH Ew");
GETEW(x1, 0);
PUSH1_16(ed);
} else {
DEFAULT;
}
break;
default:
DEFAULT;
}
+40 -9
View File
@@ -747,7 +747,37 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
VEORQ(q0, q0, q1);
}
break;
case 0xF0:
INST_NAME("MOVBE Gw, Ew");
nextop=F8;
gd = xRAX+((nextop&0x38)>>3)+(rex.r<<3);
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
REV16x(x1, ed);
BFIx(gd, x1, 0, 16);
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
LDH(x1, ed, fixedaddress);
REV16x(x1, x1);
BFIx(gd, x1, 0, 16);
}
break;
case 0xF1:
INST_NAME("MOVBE Ew, Gw");
nextop=F8;
gd = xRAX+((nextop&0x38)>>3)+(rex.r<<3);
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
REV16x(x1, gd);
BFIx(ed, x1, 0, 16);
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
REV16x(x1, gd);
STH(x1, ed, fixedaddress);
}
break;
default:
DEFAULT;
}
@@ -1756,7 +1786,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
SBFXw(x1, gd, 4, 12); // r1 = (gw>>4)
SBFXx(x1, gd, 4, 12); // r1 = (gw>>4)
ADDx_REG_LSL(x3, wback, x1, 1); //(&ed)+=r1*2;
LDH(x1, x3, fixedaddress);
ed = x1;
@@ -1797,9 +1827,10 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
wback = 0;
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
SBFXw(x4, gd, 4, 12); // r1 = (gw>>4)
SBFXx(x4, gd, 4, 12); // r1 = (gw>>4)
ADDx_REG_LSL(x3, wback, x4, 1); //(&ed)+=r1*2;
LDH(x4, x3, fixedaddress);
wback = x3;
ed = x4;
}
ANDw_mask(x2, gd, 0, 0b000011); // mask=0x0f
@@ -1809,7 +1840,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
B_NEXT(cNE);
MOV32w(x1, 1);
LSLxw_REG(x1, x1, x2);
EORx_REG(ed, ed, x1);
ORRx_REG(ed, ed, x1);
if(wback) {
STRH_U12(ed, wback, fixedaddress);
}
@@ -1859,7 +1890,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
SBFXw(x4, gd, 4, 12); // r1 = (gw>>4)
SBFXx(x4, gd, 4, 12); // r1 = (gw>>4)
ADDx_REG_LSL(x3, wback, x4, 1); //(&ed)+=r1*2;
LDH(x4, x3, fixedaddress);
wback = x3;
@@ -1872,7 +1903,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
B_NEXT(cEQ);
MOV32w(x1, 1);
LSLxw_REG(x1, x1, x2);
EORx_REG(ed, ed, x1);
BICx_REG(ed, ed, x1);
if(wback) {
STH(ed, wback, fixedaddress);
SMWRITE();
@@ -1939,7 +1970,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
BFXILxw(xFlags, ed, u8, 1); // inject 1 bit from u8 to F_CF (i.e. pos 0)
TBNZ_MARK3(xFlags, 0); // bit already set, jump to next instruction
MOV32w(x4, 1);
EORxw_REG_LSL(ed, ed, x4, u8);
ORRxw_REG_LSL(ed, ed, x4, u8);
EWBACK(x1);
MARK3;
break;
@@ -1953,7 +1984,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
BFXILxw(xFlags, ed, u8, 1); // inject 1 bit from u8 to F_CF (i.e. pos 0)
TBZ_MARK3(xFlags, 0); // bit already clear, jump to next instruction
MOV32w(x4, 1);
EORxw_REG_LSL(ed, ed, x4, u8);
BICxw_REG_LSL(ed, ed, x4, u8);
EWBACK(x1);
MARK3;
break;
@@ -1985,7 +2016,7 @@ uintptr_t dynarec64_660F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
} else {
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, &unscaled, 0xfff<<2, (1<<2)-1, rex, NULL, 0, 0);
SBFXw(x4, gd, 4, 12); // r1 = (gw>>4)
SBFXx(x4, gd, 4, 12); // r1 = (gw>>4)
ADDx_REG_LSL(x3, wback, x4, 1); //(&ed)+=r1*2;
LDH(x4, x3, fixedaddress);
wback = x3;
+22 -1
View File
@@ -152,7 +152,28 @@ uintptr_t dynarec64_66F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
DEFAULT;
}
break;
case 0x11:
INST_NAME("LOCK ADC Ew, Gw");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGW(x5);
SMDMB();
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
UXTHw(x6, ed);
emit_adc16(dyn, ninst, x6, x5, x3, x4);
BFIx(ed, x6, 0, 16);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x2, &fixedaddress, NULL, 0, 0, rex, LOCK_LOCK, 0, 0);
MARKLOCK;
LDAXRH(x1, wback);
emit_adc16(dyn, ninst, x1, x5, x3, x4);
STLXRH(x3, x1, wback);
CBNZx_MARKLOCK(x3);
}
SMDMB();
break;
case 0x81:
case 0x83:
nextop = F8;
+37 -1
View File
@@ -166,6 +166,28 @@ uintptr_t dynarec64_67(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
opcode=F8;
switch(opcode) {
case 0x11:
switch(rep) {
case 0:
INST_NAME("MOVUPS Ex,Gx");
nextop = F8;
GETG;
v0 = sse_get_reg(dyn, ninst, x1, gd, 0);
if(MODREG) {
ed = (nextop&7)+(rex.b<<3);
v1 = sse_get_reg_empty(dyn, ninst, x1, ed);
VMOVQ(v1, v0);
} else {
addr = geted32(dyn, addr, ninst, nextop, &ed, x1, &fixedaddress, &unscaled, 0xfff<<4, 15, rex, NULL, 0, 0);
VST128(v0, ed, fixedaddress);
SMWRITE2();
}
break;
default:
DEFAULT;
}
break;
case 0x2E:
// no special check...
case 0x2F:
@@ -208,6 +230,20 @@ uintptr_t dynarec64_67(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
VLD64(v0, ed, fixedaddress);
}
break;
case 2:
INST_NAME("MOVDQU Gx,Ex");
nextop = F8;
if(MODREG) {
v1 = sse_get_reg(dyn, ninst, x1, (nextop&7)+(rex.b<<3), 0);
GETGX_empty(v0);
VMOVQ(v0, v1);
} else {
GETGX_empty(v0);
SMREAD();
addr = geted32(dyn, addr, ninst, nextop, &ed, x1, &fixedaddress, &unscaled, 0xfff<<4, 15, rex, NULL, 0, 0);
VLD128(v0, ed, fixedaddress);
}
break;
default:
DEFAULT;
}
@@ -954,7 +990,7 @@ uintptr_t dynarec64_67(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
GETED32H(x1, 4);
i64 = F32S;
MOV64xw(x2, i64);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4);
emit_test32(dyn, ninst, rex, ed, x2, x3, x4, x5);
break;
case 2:
INST_NAME("NOT Ed");
+2 -1
View File
@@ -184,7 +184,8 @@ uintptr_t dynarec64_DE(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
case 0xDD:
case 0xDE:
case 0xDF:
return 0;
DEFAULT;
break;
default:
switch((nextop>>3)&7) {
case 0:
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+5 -12
View File
@@ -265,8 +265,8 @@ void emit_cmp8_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4)
}
}
// emit TEST32 instruction, from test s1, s2, using s3 and s4 as scratch
void emit_test32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4)
// emit TEST32 instruction, from test s1, s2, using s3, s4 and s5 as scratch
void emit_test32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4, int s5)
{
MAYUSE(s1); MAYUSE(s2); MAYUSE(s3); MAYUSE(s4);
IFX_PENDOR0 {
@@ -292,18 +292,11 @@ void emit_test32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s
}
// PF: (((emu->x64emu_parity_tab[(res) / 32] >> ((res) % 32)) & 1) == 0)
IFX(X_PF) {
ANDw_mask(s3, s3, 0b011011, 0b000010); // 0xE0
LSRw(s3, s3, 5);
MOV64x(s4, (uintptr_t)GetParityTab());
LDRw_REG_LSL2(s4, s4, s3);
ANDw_mask(s3, s1, 0, 0b000100); // 0x1f
LSRw_REG(s4, s4, s3);
MVNx_REG(s4, s4);
BFIw(xFlags, s4, F_PF, 1);
emit_pf(dyn, ninst, s3, s4, s5);
}
}
// emit TEST16 instruction, from test s1, s2, using s3 and s4 as scratch
// emit TEST16 instruction, from test s1, s2, using s3, s4 and s5 as scratch
void emit_test16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5)
{
MAYUSE(s1); MAYUSE(s2);
@@ -334,7 +327,7 @@ void emit_test16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4,
}
}
// emit TEST8 instruction, from test s1, s2, using s3 and s4 as scratch
// emit TEST8 instruction, from test s1, s2, using s3, s4 and s5 as scratch
void emit_test8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5)
{
MAYUSE(s1); MAYUSE(s2);
+58 -14
View File
@@ -173,8 +173,7 @@ uintptr_t dynarec64_F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
BFIw(xFlags, x4, F_CF, 1);
MOV32w(x4, 1);
LSLxw_REG(x4, x4, x2);
EORxw_REG(x4, ed, x4);
CSELxw(ed, ed, x4, cNE);
ORRxw_REG(ed, ed, x4);
} else {
// Will fetch only 1 byte, to avoid alignment issue
if(rex.w) {
@@ -191,12 +190,11 @@ uintptr_t dynarec64_F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
ed = x1;
wback = x3;
LSRw_REG(x4, ed, x2);
ANDSw_mask(x4, x4, 0, 0); //mask=1
ANDw_mask(x4, x4, 0, 0); //mask=1
BFIw(xFlags, x4, F_CF, 1);
MOV32w(x4, 1);
LSLw_REG(x4, x4, x2);
EORw_REG(x4, ed, x4);
CSELw(ed, ed, x4, cNE);
ORRw_REG(ed, ed, x4);
STLXRB(x4, ed, wback);
CBNZw_MARKLOCK(x4);
SMDMB();
@@ -322,15 +320,14 @@ uintptr_t dynarec64_F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
}
LSRxw_REG(x4, ed, x2);
if(rex.w) {
ANDSx_mask(x4, x4, 1, 0, 0); //mask=1
ANDx_mask(x4, x4, 1, 0, 0); //mask=1
} else {
ANDSw_mask(x4, x4, 0, 0); //mask=1
ANDw_mask(x4, x4, 0, 0); //mask=1
}
BFIw(xFlags, x4, F_CF, 1);
MOV32w(x4, 1);
LSLxw_REG(x4, x4, x2);
EORxw_REG(x4, ed, x4);
CSELxw(ed, ed, x4, cEQ);
BICxw_REG(ed, ed, x4);
} else {
// Will fetch only 1 byte, to avoid alignment issue
if(rex.w) {
@@ -340,19 +337,18 @@ uintptr_t dynarec64_F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
}
SMDMB();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, NULL, 0, 0, rex, LOCK_LOCK, 0, 0);
ASRxw(x1, gd, 3); // r1 = (gd>>3)
ASRx(x1, gd, 3); // r1 = (gd>>3)
ADDx_REG_LSL(x3, wback, x1, 0); //(&ed)+=r1;
MARKLOCK;
LDAXRB(x1, wback);
ed = x1;
wback = x3;
LSRw_REG(x4, ed, x2);
ANDSw_mask(x4, x4, 0, 0); //mask=1
ANDw_mask(x4, x4, 0, 0); //mask=1
BFIw(xFlags, x4, F_CF, 1);
MOV32w(x4, 1);
LSLw_REG(x4, x4, x2);
EORw_REG(x4, ed, x4);
CSELw(ed, ed, x4, cEQ);
ORRw_REG(ed, ed, x4);
STLXRB(x4, ed, wback);
CBNZw_MARKLOCK(x4);
SMDMB();
@@ -440,7 +436,55 @@ uintptr_t dynarec64_F0(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
DEFAULT;
}
break;
case 0x10:
INST_NAME("LOCK ADC Eb, Gb");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
SMDMB();
GETGB(x2);
if((nextop&0xC0)==0xC0) {
if(rex.rex) {
wback = xRAX + (nextop&7) + (rex.b<<3);
wb2 = 0;
} else {
wback = (nextop&7);
wb2 = (wback>>2);
wback = xRAX+(wback&3);
}
UBFXw(x1, wback, wb2*8, 8);
emit_adc8(dyn, ninst, x1, x2, x4, x5);
BFIx(wback, x1, wb2*8, 8);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x3, &fixedaddress, NULL, 0, 0, rex, LOCK_LOCK, 0, 0);
MARKLOCK;
LDAXRB(x1, wback);
emit_adc8(dyn, ninst, x1, x2, x4, x5);
STLXRB(x4, x1, wback);
CBNZx_MARKLOCK(x4);
}
SMDMB();
break;
case 0x11:
INST_NAME("LOCK ADC Ed, Gd");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGD;
SMDMB();
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
emit_adc32(dyn, ninst, rex, ed, gd, x3, x4);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x2, &fixedaddress, NULL, 0, 0, rex, LOCK_LOCK, 0, 0);
MARKLOCK;
LDAXRxw(x1, wback);
emit_adc32(dyn, ninst, rex, x1, gd, x4, x5);
STLXRxw(x4, x1, wback);
CBNZx_MARKLOCK(x4);
}
SMDMB();
break;
case 0x21:
INST_NAME("LOCK AND Ed, Gd");
SETFLAGS(X_ALL, SF_SET_PENDING);
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+1 -1
View File
@@ -36,7 +36,7 @@ void neoncache_promote_double(dynarec_arm_t* dyn, int ninst, int a);
// Combine and propagate if needed (pass 1 only)
int neoncache_combine_st(dynarec_arm_t* dyn, int ninst, int a, int b); // with stack current dyn->n_stack*
// FPU Cache transformation (for loops) // Specific, need to be written par backend
// FPU Cache transformation (for loops) // Specific, need to be written by backend
int fpuCacheNeedsTransform(dynarec_arm_t* dyn, int ninst);
// Undo the changes of a neoncache to get the status before the instruction
+2 -2
View File
@@ -477,8 +477,8 @@ uintptr_t geted16(dynarec_arm_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
int64_t offset = 0;
int absmin = 0;
if(s) absmin = -absmax;
if(!n && m==6) {
offset = F16;
if(!n && (m&7)==6) {
offset = F16S;
MOVZw(ret, offset);
} else {
switch(n) {
+9 -9
View File
@@ -34,12 +34,12 @@
// Strong mem emulation helpers
// Sequence of Read will trigger a DMB on "first" read if strongmem is 2
// Squence of Write will trigger a DMB on "last" write if strongmem is 1
// Sequence of Write will trigger a DMB on "last" write if strongmem is 1
// Opcode will read
#define SMREAD() if(!dyn->smread && box64_dynarec_strongmem>1) {SMDMB();}
// Opcode will read with option forced lock
#define SMREADLOCK(lock) if(lock || (!dyn->smread && box64_dynarec_strongmem>1)) {SMDMB();}
// Opcode migh read (depend on nextop)
// Opcode might read (depend on nextop)
#define SMMIGHTREAD() if(!MODREG) {SMREAD();}
// Opcode has wrote
#define SMWRITE() dyn->smwrite=1
@@ -47,7 +47,7 @@
#define SMWRITE2() if(box64_dynarec_strongmem>1) dyn->smwrite=1
// Opcode has wrote with option forced lock
#define SMWRITELOCK(lock) if(lock) {SMDMB();} else dyn->smwrite=1
// Opcode migh have wrote (depend on nextop)
// Opcode might have wrote (depend on nextop)
#define SMMIGHTWRITE() if(!MODREG) {SMWRITE();}
// Start of sequence
#define SMSTART() SMEND()
@@ -360,18 +360,18 @@
gb2 = 0; \
} else { \
gd = (nextop&0x38)>>3; \
gb2 = ((gd&4)>>2); \
gb2 = ((gd&4)<<1); \
gb1 = xRAX+(gd&3); \
} \
gd = i; \
UBFXx(gd, gb1, gb2*8, 8);
//GETSGB signe extend GB, will use i for gd
UBFXx(gd, gb1, gb2, 8);
//GETSGB sign extend GB, will use i for gd
#define GETSGB(i) if(rex.rex) { \
gb1 = xRAX+((nextop&0x38)>>3)+(rex.r<<3); \
gb2 = 0; \
} else { \
gd = (nextop&0x38)>>3; \
gb2 = ((gd&4)>>2); \
gb2 = ((gd&4)<<1); \
gb1 = xRAX+(gd&3); \
} \
gd = i; \
@@ -1035,7 +1035,7 @@ void emit_cmp16_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4);
void emit_cmp32_0(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s3, int s4);
void emit_test8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5);
void emit_test16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5);
void emit_test32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4);
void emit_test32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4, int s5);
void emit_add32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4);
void emit_add32c(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int64_t c, int s3, int s4, int s5);
void emit_add8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4);
@@ -1100,7 +1100,7 @@ void emit_shld32c(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, uint
void emit_pf(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4);
// x87 helper
// cache of the local stack counter, to avoid upadte at every call
// cache of the local stack counter, to avoid update at every call
void x87_stackcount(dynarec_arm_t* dyn, int ninst, int scratch);
// fpu push. Return the Dd value to be used
int x87_do_push(dynarec_arm_t* dyn, int ninst, int s1, int t);
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+6 -6
View File
@@ -77,8 +77,8 @@ typedef struct instruction_arm64_s {
uintptr_t natcall;
int retn;
int barrier_maybe;
flagcache_t f_exit; // flags status at end of intruction
neoncache_t n; // neoncache at end of intruction (but before poping)
flagcache_t f_exit; // flags status at end of instruction
neoncache_t n; // neoncache at end of instruction (but before poping)
flagcache_t f_entry; // flags status before the instruction begin
} instruction_arm64_t;
@@ -87,12 +87,12 @@ typedef struct dynarec_arm_s {
int32_t size;
int32_t cap;
uintptr_t start; // start of the block
uint32_t isize; // size in byte of x64 instructions included
uint32_t isize; // size in bytes of x64 instructions included
void* block; // memory pointer where next instruction is emitted
uintptr_t native_start; // start of the arm code
size_t native_size; // size of emitted arm code
uintptr_t last_ip; // last set IP in RIP (or NULL if unclean state) TODO: move to a cache something
uint64_t* table64; // table of 64bits value
uint64_t* table64; // table of 64bits values
int table64size;// size of table (will be appended at end of executable code)
int table64cap;
uintptr_t tablestart;
@@ -106,7 +106,7 @@ typedef struct dynarec_arm_s {
dynablock_t* dynablock;
instsize_t* instsize;
size_t insts_size; // size of the instruction size array (calculated)
uint8_t smread; // for strongmem model emulation
uint8_t smread; // for strongmem model emulation
uint8_t smwrite; // for strongmem model emulation
uintptr_t forward; // address of the last end of code while testing forward
uintptr_t forward_to; // address of the next jump to (to check if everything is ok)
@@ -122,7 +122,7 @@ uintptr_t get_closest_next(dynarec_arm_t *dyn, uintptr_t addr);
int is_nops(dynarec_arm_t *dyn, uintptr_t addr, int n);
int is_instructions(dynarec_arm_t *dyn, uintptr_t addr, int n);
int Table64(dynarec_arm_t *dyn, uint64_t val, int pass); // add a value to etable64 (if needed) and gives back the imm19 to use in LDR_literal
int Table64(dynarec_arm_t *dyn, uint64_t val, int pass); // add a value to table64 (if needed) and gives back the imm19 to use in LDR_literal
void CreateJmpNext(void* addr, void* next);
Executable → Regular
+1 -1
View File
@@ -209,7 +209,7 @@ static dynablock_t* internalDBGetBlock(x64emu_t* emu, uintptr_t addr, uintptr_t
// fill the block
block->x64_addr = (void*)addr;
if(sigsetjmp(&dynarec_jmpbuf, 1)) {
printf_log(LOG_INFO, "FillBlock at %p triggered a segfault, cancelling\n", (void*)addr);
printf_log(LOG_INFO, "FillBlock at %p triggered a segfault, canceling\n", (void*)addr);
FreeDynablock(block, 0);
if(need_lock)
mutex_unlock(&my_context->mutex_dyndump);
Executable → Regular
View File
File mode changed.
Executable → Regular
+46 -97
View File
@@ -73,114 +73,65 @@ void* LinkNext(x64emu_t* emu, uintptr_t addr, void* x2, uintptr_t* x3)
}
#endif
#ifdef __GNUC__
// Disable "clobbered" warnings
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclobbered"
#endif
void DynaCall(x64emu_t* emu, uintptr_t addr)
{
// prepare setjump for signal handling
struct __jmp_buf_tag jmpbuf[1] = {0};
int skip = 0;
struct __jmp_buf_tag *old_jmpbuf = emu->jmpbuf;
emu->jmpbuf = jmpbuf;
if((skip = sigsetjmp(emu->jmpbuf, 1))) {
printf_log(LOG_DEBUG, "Setjmp DynaCall, fs=0x%x\n", emu->segs[_FS]);
addr = R_RIP; // not sure if it should still be inside DynaCall!
#ifdef DYNAREC
if(box64_dynarec_test) {
if(emu->test.clean)
x64test_check(emu, R_RIP);
emu->test.clean = 0;
}
#endif
uint64_t old_rsp = R_RSP;
uint64_t old_rbx = R_RBX;
uint64_t old_rdi = R_RDI;
uint64_t old_rsi = R_RSI;
uint64_t old_rbp = R_RBP;
uint64_t old_rip = R_RIP;
PushExit(emu);
R_RIP = addr;
emu->df = d_none;
DynaRun(emu);
emu->quit = 0; // reset Quit flags...
emu->df = d_none;
if(emu->flags.quitonlongjmp && emu->flags.longjmp) {
if(emu->flags.quitonlongjmp==1)
emu->flags.longjmp = 0; // don't change anything because of the longjmp
} else {
R_RBX = old_rbx;
R_RDI = old_rdi;
R_RSI = old_rsi;
R_RBP = old_rbp;
R_RSP = old_rsp;
R_RIP = old_rip; // and set back instruction pointer
}
#ifdef DYNAREC
if(!box64_dynarec)
#endif
EmuCall(emu, addr);
#ifdef DYNAREC
else {
uint64_t old_rsp = R_RSP;
uint64_t old_rbx = R_RBX;
uint64_t old_rdi = R_RDI;
uint64_t old_rsi = R_RSI;
uint64_t old_rbp = R_RBP;
uint64_t old_rip = R_RIP;
PushExit(emu);
R_RIP = addr;
emu->df = d_none;
while(!emu->quit) {
int is32bits = (emu->segs[_CS]==0x23);
dynablock_t* block = (skip)?NULL:DBGetBlock(emu, R_RIP, 1, is32bits);
if(!block || !block->block || !block->done) {
skip = 0;
// no block, of block doesn't have DynaRec content (yet, temp is not null)
// Use interpreter (should use single instruction step...)
dynarec_log(LOG_DEBUG, "%04d|Calling Interpreter @%p, emu=%p\n", GetTID(), (void*)R_RIP, emu);
if(box64_dynarec_test)
emu->test.clean = 0;
Run(emu, 1);
} else {
dynarec_log(LOG_DEBUG, "%04d|Calling DynaRec Block @%p (%p) of %d x64 instructions (hash=0x%x) emu=%p\n", GetTID(), (void*)R_RIP, block->block, block->isize ,block->hash, emu);
CHECK_FLAGS(emu);
// block is here, let's run it!
native_prolog(emu, block->block);
}
if(emu->fork) {
int forktype = emu->fork;
emu->quit = 0;
emu->fork = 0;
emu = x64emu_fork(emu, forktype);
}
}
emu->quit = 0; // reset Quit flags...
emu->df = d_none;
if(emu->quitonlongjmp && emu->longjmp) {
if(emu->quitonlongjmp==1)
emu->longjmp = 0; // don't change anything because of the longjmp
} else {
R_RBX = old_rbx;
R_RDI = old_rdi;
R_RSI = old_rsi;
R_RBP = old_rbp;
R_RSP = old_rsp;
R_RIP = old_rip; // and set back instruction pointer
}
}
#endif
// clear the setjmp
emu->jmpbuf = old_jmpbuf;
}
int DynaRun(x64emu_t* emu)
void DynaRun(x64emu_t* emu)
{
// prepare setjump for signal handling
struct __jmp_buf_tag jmpbuf[1] = {0};
int skip = 0;
struct __jmp_buf_tag *old_jmpbuf = emu->jmpbuf;
emu->jmpbuf = jmpbuf;
emu->flags.jmpbuf_ready = 0;
if((skip=sigsetjmp(emu->jmpbuf, 1))) {
printf_log(LOG_DEBUG, "Setjmp DynaRun, fs=0x%x\n", emu->segs[_FS]);
#ifdef DYNAREC
if(box64_dynarec_test) {
if(emu->test.clean)
x64test_check(emu, R_RIP);
emu->test.clean = 0;
while(!(emu->quit)) {
if(!emu->jmpbuf || (emu->flags.need_jmpbuf && emu->jmpbuf!=jmpbuf)) {
emu->jmpbuf = jmpbuf;
emu->flags.jmpbuf_ready = 1;
if((skip=sigsetjmp(emu->jmpbuf, 1))) {
printf_log(LOG_DEBUG, "Setjmp DynaRun, fs=0x%x\n", emu->segs[_FS]);
#ifdef DYNAREC
if(box64_dynarec_test) {
if(emu->test.clean)
x64test_check(emu, R_RIP);
emu->test.clean = 0;
}
#endif
}
}
#endif
}
if(emu->flags.need_jmpbuf)
emu->flags.need_jmpbuf = 0;
#ifdef DYNAREC
if(!box64_dynarec)
if(!box64_dynarec)
#endif
return Run(emu, 0);
Run(emu, 0);
#ifdef DYNAREC
else {
while(!emu->quit) {
else {
int is32bits = (emu->segs[_CS]==0x23);
dynablock_t* block = (skip)?NULL:DBGetBlock(emu, R_RIP, 1, is32bits);
if(!block || !block->block || !block->done) {
@@ -203,12 +154,10 @@ int DynaRun(x64emu_t* emu)
emu = x64emu_fork(emu, forktype);
}
}
#endif
if(emu->flags.need_jmpbuf)
emu->quit = 0;
}
// clear the setjmp
emu->jmpbuf = old_jmpbuf;
return 0;
#endif
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
Executable → Regular
+22 -15
View File
@@ -78,7 +78,7 @@ void add_next(dynarec_native_t *dyn, uintptr_t addr) {
dyn->next[dyn->next_sz++] = addr;
}
uintptr_t get_closest_next(dynarec_native_t *dyn, uintptr_t addr) {
// get closest, but no addresses befores
// get closest, but no addresses before
uintptr_t best = 0;
int i = 0;
while((i<dyn->next_sz) && (best!=addr)) {
@@ -124,8 +124,8 @@ int is_nops(dynarec_native_t *dyn, uintptr_t addr, int n)
return 0;
}
// return size of next instuciton, -1 is unknown
// not all instrction are setup
// return size of next instruction, -1 is unknown
// not all instructions are setup
int next_instruction(dynarec_native_t *dyn, uintptr_t addr)
{
uint8_t opcode = PK(0);
@@ -293,7 +293,7 @@ int Table64(dynarec_native_t *dyn, uint64_t val, int pass)
static void fillPredecessors(dynarec_native_t* dyn)
{
int pred_sz = 1; // to be safe
// compute total size of predecessor to alocate the array
// compute total size of predecessor to allocate the array
// first compute the jumps
for(int i=0; i<dyn->size; ++i) {
if(dyn->insts[i].x64.jmp && (dyn->insts[i].x64.jmp_insts!=-1)) {
@@ -301,6 +301,13 @@ static void fillPredecessors(dynarec_native_t* dyn)
dyn->insts[dyn->insts[i].x64.jmp_insts].pred_sz++;
}
}
// remove "has_next" from orphan branch
for(int i=0; i<dyn->size-1; ++i) {
if(!dyn->insts[i].x64.has_next) {
if(dyn->insts[i+1].x64.has_next && !dyn->insts[i+1].pred_sz)
dyn->insts[i+1].x64.has_next = 0;
}
}
// second the "has_next"
for(int i=0; i<dyn->size-1; ++i) {
if(dyn->insts[i].x64.has_next) {
@@ -328,7 +335,7 @@ static void fillPredecessors(dynarec_native_t* dyn)
}
}
// updateNeed goes backward, from last intruction to top
// updateNeed goes backward, from last instruction to top
static int updateNeed(dynarec_native_t* dyn, int ninst, uint8_t need) {
while (ninst>=0) {
// need pending but instruction is only a subset: remove pend and use an X_ALL instead
@@ -368,9 +375,9 @@ static int updateNeed(dynarec_native_t* dyn, int ninst, uint8_t need) {
else
updateNeed(dyn, dyn->insts[ninst].pred[i], need);
}
if(!ok)
return ninst - 1;
--ninst;
if(!ok)
return ninst;
}
return ninst;
}
@@ -410,7 +417,7 @@ void* CreateEmptyBlock(dynablock_t* block, uintptr_t addr) {
void* actual_p = (void*)AllocDynarecMap(sz);
void* p = actual_p + sizeof(void*);
if(actual_p==NULL) {
dynarec_log(LOG_INFO, "AllocDynarecMap(%p, %zu) failed, cancelling block\n", block, sz);
dynarec_log(LOG_INFO, "AllocDynarecMap(%p, %zu) failed, canceling block\n", block, sz);
CancelBlock64(0);
return NULL;
}
@@ -437,11 +444,11 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
B+8 .. B+15 : 2 Native code for jmpnext (or jmp epilog in case of empty block)
B+16 .. B+23 : jmpnext (or jmp_epilog) address
B+24 .. B+31 : empty (in case an architecture needs more than 2 opcodes)
B+32 .. B+32+sz : instsize (compressed array with each instruction lenght on x64 and native side)
B+32 .. B+32+sz : instsize (compressed array with each instruction length on x64 and native side)
*/
if(IsInHotPage(addr)) {
dynarec_log(LOG_DEBUG, "Cancelling dynarec FillBlock on hotpage for %p\n", (void*)addr);
dynarec_log(LOG_DEBUG, "Canceling dynarec FillBlock on hotpage for %p\n", (void*)addr);
return NULL;
}
if(addr>=box64_nodynarec_start && addr<box64_nodynarec_end) {
@@ -449,7 +456,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
return CreateEmptyBlock(block, addr);
}
if(current_helper) {
dynarec_log(LOG_DEBUG, "Cancelling dynarec FillBlock at %p as anothor one is going on\n", (void*)addr);
dynarec_log(LOG_DEBUG, "Canceling dynarec FillBlock at %p as another one is going on\n", (void*)addr);
return NULL;
}
// protect the 1st page
@@ -513,7 +520,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
while (pos>=0)
pos = updateNeed(&helper, pos, 0);
// pass 1, float optimisations, first pass for flags
// pass 1, float optimizations, first pass for flags
native_pass1(&helper, addr, alternate, is32bits);
// pass 2, instruction size
@@ -531,7 +538,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
void* next = tablestart + helper.table64size*sizeof(uint64_t);
void* instsize = next + 4*sizeof(void*);
if(actual_p==NULL) {
dynarec_log(LOG_INFO, "AllocDynarecMap(%p, %zu) failed, cancelling block\n", block, sz);
dynarec_log(LOG_INFO, "AllocDynarecMap(%p, %zu) failed, canceling block\n", block, sz);
CancelBlock64(0);
return NULL;
}
@@ -581,7 +588,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
// all done...
__clear_cache(actual_p, actual_p+sz); // need to clear the cache before execution...
block->hash = X31_hash_code(block->x64_addr, block->x64_size);
// Check if something changed, to abbort if it as
// Check if something changed, to abort if it is
if((block->hash != hash)) {
dynarec_log(LOG_DEBUG, "Warning, a block changed while being processed hash(%p:%ld)=%x/%x\n", block->x64_addr, block->x64_size, block->hash, hash);
AddHotPage(addr);
@@ -604,7 +611,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit
return NULL;
}
if(insts_rsize/sizeof(instsize_t)<helper.insts_size) {
printf_log(LOG_NONE, "BOX64: Warning, ists_size difference in block between pass2 (%zu) and pass3 (%zu), allocated: %zu\n", oldinstsize, helper.insts_size, insts_rsize/sizeof(instsize_t));
printf_log(LOG_NONE, "BOX64: Warning, insts_size difference in block between pass2 (%zu) and pass3 (%zu), allocated: %zu\n", oldinstsize, helper.insts_size, insts_rsize/sizeof(instsize_t));
}
if(!isprotectedDB(addr, end-addr)) {
dynarec_log(LOG_DEBUG, "Warning, block unprotected while being processed %p:%ld, marking as need_test\n", block->x64_addr, block->x64_size);
+7 -1
View File
@@ -138,7 +138,7 @@ void native_fistp64(x64emu_t* emu, int64_t* ed)
void native_fistt64(x64emu_t* emu, int64_t* ed)
{
// used of memcpy to avoid aligments issues
// used of memcpy to avoid alignments issues
int64_t tmp = ST0.d;
memcpy(ed, &tmp, sizeof(tmp));
}
@@ -163,6 +163,12 @@ void native_priv(x64emu_t* emu)
emit_signal(emu, SIGSEGV, (void*)R_RIP, 0);
}
void native_int(x64emu_t* emu, int num)
{
emu->test.test = 0;
emit_interruption(emu, num, (void*)R_RIP);
}
void native_singlestep(x64emu_t* emu)
{
emit_signal(emu, SIGTRAP, (void*)R_RIP, 1);
+1
View File
@@ -46,6 +46,7 @@ void native_clflush(x64emu_t* emu, void* p);
void native_ud(x64emu_t* emu);
void native_priv(x64emu_t* emu);
void native_singlestep(x64emu_t* emu);
void native_int(x64emu_t* emu, int num);
// Caches transformation (for loops) // Specific, need to be written par backend
int CacheNeedsTransform(dynarec_native_t* dyn, int i1);
+28 -11
View File
@@ -47,7 +47,7 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
ARCH_INIT();
int reset_n = -1;
dyn->last_ip = (alternate || (dyn->insts && dyn->insts[0].pred_sz))?0:ip; // RIP is always set at start of block unless there is a predecessor!
int stopblock = 2+(FindElfAddress(my_context, addr)?0:1); // if block is in elf_memory, it can be extended with bligblocks==2, else it needs 3
int stopblock = 2+(FindElfAddress(my_context, addr)?0:1); // if block is in elf_memory, it can be extended with box64_dynarec_bigblock==2, else it needs 3
// ok, go now
INIT;
while(ok) {
@@ -74,7 +74,7 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
}
reset_n = -1;
} else if(ninst && (dyn->insts[ninst].pred_sz>1 || (dyn->insts[ninst].pred_sz==1 && dyn->insts[ninst].pred[0]!=ninst-1)))
dyn->last_ip = 0; // reset IP if some jump are comming here
dyn->last_ip = 0; // reset IP if some jump are coming here
fpu_propagate_stack(dyn, ninst);
NEW_INST;
if(!ninst) {
@@ -166,7 +166,7 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
if((dyn->insts[ii].x64.barrier&BARRIER_FULL)==BARRIER_FULL)
reset_n = -2; // hack to say Barrier!
else {
reset_n = getNominalPred(dyn, ii); // may get -1 if no predecessor are availble
reset_n = getNominalPred(dyn, ii); // may get -1 if no predecessor are available
if(reset_n==-1) {
reset_n = -2;
MESSAGE(LOG_DEBUG, "Warning, Reset Caches mark not found\n");
@@ -183,7 +183,7 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
dyn->forward_size = 0;
dyn->forward_ninst = 0;
ok = 1; // in case it was 0
} else if ((dyn->forward_to < addr) || !ok) {
} else if ((dyn->forward_to < addr) || ok<=0) {
// something when wrong! rollback
if(box64_dynarec_dump) dynarec_log(LOG_NONE, "Could not forward extend block for %d bytes %p -> %p\n", dyn->forward_to-dyn->forward, (void*)dyn->forward, (void*)dyn->forward_to);
ok = 0;
@@ -214,12 +214,19 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
if(box64_dynarec_dump) dynarec_log(LOG_NONE, "Extend block %p, %p -> %p (ninst=%d, jump from %d)\n", dyn, (void*)addr, (void*)next, ninst, reset_n);
} else if(next && (next-addr)<box64_dynarec_forward && (getProtection(next)&PROT_READ)/*box64_dynarec_bigblock>=stopblock*/) {
if(!((box64_dynarec_bigblock<stopblock) && !isJumpTableDefault64((void*)next))) {
dyn->forward = addr;
dyn->forward_to = next;
dyn->forward_size = dyn->size;
dyn->forward_ninst = ninst;
reset_n = -2;
ok = 1;
if(dyn->forward) {
if(next<dyn->forward_to)
dyn->forward_to = next;
reset_n = -2;
ok = 1;
} else {
dyn->forward = addr;
dyn->forward_to = next;
dyn->forward_size = dyn->size;
dyn->forward_ninst = ninst;
reset_n = -2;
ok = 1;
}
}
}
}
@@ -235,6 +242,16 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
dyn->insts[ninst].x64.need_after |= X_PEND;
++ninst;
}
if(dyn->forward) {
// stopping too soon
dyn->size = dyn->forward_size;
ninst = dyn->forward_ninst+1;
addr = dyn->forward;
dyn->forward = 0;
dyn->forward_to = 0;
dyn->forward_size = 0;
dyn->forward_ninst = 0;
}
#endif
}
++ninst;
@@ -279,7 +296,7 @@ uintptr_t native_pass(dynarec_native_t* dyn, uintptr_t addr, int alternate, int
if(need_epilog) {
NOTEST(x3);
fpu_purgecache(dyn, ninst, 0, x1, x2, x3);
jump_to_epilog(dyn, ip, 0, ninst); // no linker here, it's an unknow instruction
jump_to_epilog(dyn, ip, 0, ninst); // no linker here, it's an unknown instruction
}
FINI;
MESSAGE(LOG_DUMP, "---- END OF BLOCK ---- (%d)\n", dyn->size);
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
-2
View File
@@ -25,8 +25,6 @@
#include "dynarec_rv64_functions.h"
#include "dynarec_rv64_helper.h"
int isSimpleWrapper(wrapper_t fun);
uintptr_t dynarec64_00(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, rex_t rex, int rep, int* ok, int* need_epilog)
{
uint8_t opcode;
+47 -4
View File
@@ -25,8 +25,6 @@
#include "dynarec_rv64_functions.h"
#include "dynarec_rv64_helper.h"
int isSimpleWrapper(wrapper_t fun);
uintptr_t dynarec64_00_0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, rex_t rex, int rep, int* ok, int* need_epilog)
{
uint8_t nextop, opcode;
@@ -169,7 +167,16 @@ uintptr_t dynarec64_00_0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
DEFAULT;
}
break;
case 0x10:
INST_NAME("ADC Eb, Gb");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETEB(x1, 0);
GETGB(x2);
emit_adc8(dyn, ninst, x1, x2, x4, x5, x3);
EBBACK(x5, 0);
break;
case 0x11:
INST_NAME("ADC Ed, Gd");
READFLAGS(X_CF);
@@ -180,7 +187,43 @@ uintptr_t dynarec64_00_0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
emit_adc32(dyn, ninst, rex, ed, gd, x3, x4, x5, x6);
WBACK;
break;
case 0x12:
INST_NAME("ADC Gb, Eb");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETEB(x2, 0);
GETGB(x1);
emit_adc8(dyn, ninst, x1, x2, x4, x3, x5);
GBBACK(x5);
break;
case 0x13:
INST_NAME("ADC Gd, Ed");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGD;
GETED(0);
emit_adc32(dyn, ninst, rex, gd, ed, x3, x4, x5, x6);
break;
case 0x14:
INST_NAME("ADC AL, Ib");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
u8 = F8;
ANDI(x1, xRAX, 0xff);
emit_adc8c(dyn, ninst, x1, u8, x3, x4, x5, x6);
ANDI(xRAX, xRAX, -256);
OR(xRAX, xRAX, x1);
break;
case 0x15:
INST_NAME("ADC EAX, Id");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
i64 = F32S;
MOV64xw(x1, i64);
emit_adc32(dyn, ninst, rex, xRAX, x1, x3, x4, x5, x6);
break;
case 0x18:
INST_NAME("SBB Eb, Gb");
READFLAGS(X_CF);
-2
View File
@@ -25,8 +25,6 @@
#include "dynarec_rv64_functions.h"
#include "dynarec_rv64_helper.h"
int isSimpleWrapper(wrapper_t fun);
uintptr_t dynarec64_00_2(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, rex_t rex, int rep, int* ok, int* need_epilog)
{
uint8_t nextop, opcode;
+59
View File
@@ -26,6 +26,7 @@
#include "dynarec_rv64_helper.h"
int isSimpleWrapper(wrapper_t fun);
int isRetX87Wrapper(wrapper_t fun);
uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, rex_t rex, int rep, int* ok, int* need_epilog)
{
@@ -307,6 +308,9 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
// disabling isSimpleWrapper because all signed value less than 64bits needs to be sign extended
// and return value needs to be cleanned up
tmp = 0;//isSimpleWrapper(*(wrapper_t*)(addr));
if(isRetX87Wrapper(*(wrapper_t*)(addr)))
// return value will be on the stack, so the stack depth needs to be updated
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
if(tmp<0 || tmp>1)
tmp=0; //TODO: removed when FP is in place
if((box64_log<2 && !cycle_log) && tmp) {
@@ -617,6 +621,58 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
case 0xDF:
addr = dynarec64_DF(dyn, addr, ip, ninst, rex, rep, ok, need_epilog);
break;
#define GO(Z) \
BARRIER(BARRIER_MAYBE); \
JUMP(addr+i8, 1); \
if(dyn->insts[ninst].x64.jmp_insts==-1 || \
CHECK_CACHE()) { \
/* out of the block */ \
i32 = dyn->insts[ninst].epilog-(dyn->native_size); \
if(Z) {BNE(xRCX, xZR, i32);} else {BEQ(xRCX, xZR, i32);}; \
if(dyn->insts[ninst].x64.jmp_insts==-1) { \
if(!(dyn->insts[ninst].x64.barrier&BARRIER_FLOAT)) \
fpu_purgecache(dyn, ninst, 1, x1, x2, x3); \
jump_to_next(dyn, addr+i8, 0, ninst); \
} else { \
CacheTransform(dyn, ninst, cacheupd, x1, x2, x3); \
i32 = dyn->insts[dyn->insts[ninst].x64.jmp_insts].address-(dyn->native_size); \
B(i32); \
} \
} else { \
/* inside the block */ \
i32 = dyn->insts[dyn->insts[ninst].x64.jmp_insts].address-(dyn->native_size); \
if(Z) {BEQ(xRCX, xZR, i32);} else {BNE(xRCX, xZR, i32);}; \
}
case 0xE0:
INST_NAME("LOOPNZ");
READFLAGS(X_ZF);
i8 = F8S;
SUBI(xRCX, xRCX, 1);
ANDI(x1, xFlags, 1 << F_ZF);
CBNZ_NEXT(x1);
GO(0);
break;
case 0xE1:
INST_NAME("LOOPZ");
READFLAGS(X_ZF);
i8 = F8S;
SUBI(xRCX, xRCX, 1);
ANDI(x1, xFlags, 1 << F_ZF);
CBZ_NEXT(x1);
GO(0);
break;
case 0xE2:
INST_NAME("LOOP");
i8 = F8S;
SUBI(xRCX, xRCX, 1);
GO(0);
break;
case 0xE3:
INST_NAME("JECXZ");
i8 = F8S;
GO(1);
break;
#undef GO
case 0xE8:
INST_NAME("CALL Id");
@@ -657,6 +713,9 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
tmp=0; // float paramters not ready!
} else
tmp=0;
if(dyn->insts[ninst].natcall && isRetX87Wrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2)))
// return value will be on the stack, so the stack depth needs to be updated
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
if((box64_log<2 && !cycle_log) && dyn->insts[ninst].natcall && tmp) {
//GETIP(ip+3+8+8); // read the 0xCC
call_n(dyn, ninst, *(void**)(dyn->insts[ninst].natcall+2+8), tmp);
+127
View File
@@ -316,7 +316,134 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
SRLI(xRDX, x3, 32);
AND(xRAX, x3, 32); // wipe upper part
break;
case 0x38:
//SSE3
nextop=F8;
switch(nextop) {
case 0xF0:
INST_NAME("MOVBE Gd, Ed");
nextop=F8;
GETGD;
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x1, &fixedaddress, rex, NULL, 1, 0);
LDxw(gd, ed, fixedaddress);
if (rv64_zbb) {
REV8(gd, gd);
if (!rex.w) {
SRLI(gd, gd, 32);
}
} else {
if (rex.w) {
MOV_U12(x2, 0xff);
SLLI(x1, gd, 56);
SRLI(x3, gd, 56);
SRLI(x4, gd, 40);
SLLI(x2, x2, 8);
AND(x4, x4, x2);
OR(x1, x1, x3);
OR(x1, x1, x4);
SLLI(x3, gd, 40);
SLLI(x4, x2, 40);
AND(x3, x3, x4);
OR(x1, x1, x3);
SRLI(x3, gd, 24);
SLLI(x4, x2, 8);
AND(x3, x3, x4);
OR(x1, x1, x3);
SLLI(x3, gd, 24);
SLLI(x4, x2, 32);
AND(x3, x3, x4);
OR(x1, x1, x3);
SRLI(x3, gd, 8);
SLLI(x4, x2, 16);
AND(x3, x3, x4);
OR(x1, x1, x3);
SLLI(x3, gd, 8);
SLLI(x4, x2, 24);
AND(x3, x3, x4);
OR(gd, x1, x3);
} else {
MOV_U12(x2, 0xff);
SLLIW(x2, x2, 8);
SLLIW(x1, gd, 24);
SRLIW(x3, gd, 24);
SRLIW(x4, gd, 8);
AND(x4, x4, x2);
OR(x1, x1, x3);
OR(x1, x1, x4);
SLLIW(gd, gd, 8);
LUI(x2, 0xff0);
AND(gd, gd, x2);
OR(gd, gd, x1);
}
}
break;
case 0xF1:
INST_NAME("MOVBE Ed, Gd");
nextop=F8;
GETGD;
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x2, x1, &fixedaddress, rex, NULL, 1, 0);
if (rv64_zbb) {
REV8(x1, gd);
if (!rex.w) {
SRLI(x1, x1, 32);
}
} else {
if (rex.w) {
MOV_U12(x2, 0xff);
SLLI(x1, gd, 56);
SRLI(x3, gd, 56);
SRLI(x4, gd, 40);
SLLI(x2, x2, 8);
AND(x4, x4, x2);
OR(x1, x1, x3);
OR(x1, x1, x4);
SLLI(x3, gd, 40);
SLLI(x4, x2, 40);
AND(x3, x3, x4);
OR(x1, x1, x3);
SRLI(x3, gd, 24);
SLLI(x4, x2, 8);
AND(x3, x3, x4);
OR(x1, x1, x3);
SLLI(x3, gd, 24);
SLLI(x4, x2, 32);
AND(x3, x3, x4);
OR(x1, x1, x3);
SRLI(x3, gd, 8);
SLLI(x4, x2, 16);
AND(x3, x3, x4);
OR(x1, x1, x3);
SLLI(x3, gd, 8);
SLLI(x4, x2, 24);
AND(x3, x3, x4);
OR(x1, x1, x3);
} else {
MOV_U12(x2, 0xff);
SLLIW(x2, x2, 8);
SLLIW(x1, gd, 24);
SRLIW(x3, gd, 24);
SRLIW(x4, gd, 8);
AND(x4, x4, x2);
OR(x1, x1, x3);
OR(x1, x1, x4);
SLLIW(x3, gd, 8);
LUI(x2, 0xff0);
AND(x3, x3, x2);
OR(x1, x1, x3);
}
}
SDxw(x1, wback, fixedaddress);
break;
default:
DEFAULT;
}
break;
#define GO(GETFLAGS, NO, YES, F) \
READFLAGS(F); \
+98
View File
@@ -117,6 +117,43 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
case 0x0F:
addr = dynarec64_660F(dyn, addr, ip, ninst, rex, ok, need_epilog);
break;
case 0x11:
INST_NAME("ADC Ew, Gw");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGW(x2);
GETEW(x1, 0);
emit_adc16(dyn, ninst, x1, x2, x4, x3, x5);
EWBACK;
break;
case 0x13:
INST_NAME("ADC Gw, Ew");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGW(x1);
GETEW(x2, 0);
emit_adc16(dyn, ninst, x1, x2, x4, x3, x5);
GWBACK;
break;
case 0x15:
INST_NAME("ADC AX, Iw");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
i16 = F16;
SRLI(x6, xMASK, 16);
AND(x1, xRAX, x6);
MOV32w(x2, i16);
emit_adc16(dyn, ninst, x1, x2, x3, x4, x5);
if (rv64_zbb) {
ANDN(xRAX, xRAX, x6);
} else {
NOT(x6, x6);
AND(xRAX, xRAX, x6);
}
OR(xRAX, xRAX, x1);
break;
case 0x19:
INST_NAME("SBB Ew, Gw");
READFLAGS(X_CF);
@@ -427,6 +464,67 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
GETGW(x2);
emit_test16(dyn, ninst, x1, x2, x3, x4, x5);
break;
case 0x87:
INST_NAME("(LOCK)XCHG Ew, Gw");
nextop = F8;
if(MODREG) {
GETGD;
GETED(0);
ADDI(x1, gd, 0);
LUI(x3, 0xffff0);
AND(gd, gd, x3);
ZEXTH(x4, ed);
OR(gd, gd, x4);
AND(ed, ed, x3);
ZEXTH(x4, x1);
OR(ed, ed, x4);
} else {
GETGD;
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x1, &fixedaddress, rex, LOCK_LOCK, 0, 0);
SMDMB();
ANDI(x3, ed, 1);
BNEZ_MARK(x3);
ANDI(x3, ed, 0b10);
LUI(x5, 0xffff0);
ZEXTH(x6, gd);
BNEZ_MARK3(x3);
MARKLOCK;
LR_W(x1, ed, 1, 0);
AND(x3, x1, x5);
OR(x3, x3, x6);
SC_W(x3, x3, ed, 0, 1);
BNEZ_MARKLOCK(x3);
ZEXTH(x1, x1);
B_MARK2_nocond;
MARK3;
NOT(x5, x5);
SLLI(x5, x5, 16);
SLLI(x6, x6, 16);
NOT(x5, x5);
LR_W(x1, ed, 1, 0);
AND(x3, x1, x5);
OR(x3, x3, x6);
SC_W(x3, x3, ed, 0, 1);
BNEZ(x3, -4 * 4);
SRLI(x1, x1, 16);
ZEXTH(x1, x1);
B_MARK2_nocond;
MARK;
LHU(x1, ed, 0);
SH(gd, ed, 0);
MARK2;
SMDMB();
LUI(x5, 0xffff0);
AND(gd, gd, x5);
OR(gd, gd, x1);
}
break;
case 0x89:
INST_NAME("MOV Ew, Gw");
nextop = F8;
+39 -1
View File
@@ -411,7 +411,7 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
AND(x4, x4, x6);
OR(x3, x3, x4);
BNEZ(x3, 8);
ORI(xFlags, xFlags, 1<<F_ZF);
ORI(xFlags, xFlags, 1<<F_CF);
}
}
break;
@@ -715,6 +715,44 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEX(x2, 0);
SSE_LOOP_Q(x3, x4, XOR(x3, x3, x4));
break;
case 0xF0:
INST_NAME("MOVBE Gw, Ew");
nextop=F8;
GETGD;
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &ed, x3, x2, &fixedaddress, rex, NULL, 0, 1);
LHU(x1, ed, fixedaddress);
if (rv64_zbb) {
REV8(x1, x1);
SRLI(x1, x1, 48);
} else {
ANDI(x2, x1, 0xff);
SLLI(x2, x2, 8);
SRLI(x1, x1, 8);
OR(x1, x1, x2);
}
LUI(x2, 0xffff0);
AND(gd, gd, x2);
OR(gd, gd, x1);
break;
case 0xF1:
INST_NAME("MOVBE Ew, Gw");
nextop=F8;
GETGD;
SMREAD();
addr = geted(dyn, addr, ninst, nextop, &wback, x3, x2, &fixedaddress, rex, NULL, 0, 1);
if (rv64_zbb) {
REV8(x1, gd);
SRLI(x1, x1, 48);
} else {
ANDI(x1, gd, 0xff);
SLLI(x1, x1, 8);
SRLI(x2, gd, 8);
ANDI(x2, x2, 0xff);
OR(x1, x1, x2);
}
SH(x1, wback, fixedaddress);
break;
default:
DEFAULT;
}
+29 -1
View File
@@ -37,6 +37,35 @@ uintptr_t dynarec64_6664(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETREX();
switch(opcode) {
case 0x89:
INST_NAME("MOV FS:Ew, Gw");
nextop = F8;
GETGD; // don't need GETGW here
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
if(rex.w) {
ADDI(ed, gd, 0);
} else {
if(ed!=gd) {
LUI(x1, 0xffff0);
AND(gd, gd, x1);
ZEXTH(x1, ed);
OR(gd, gd, x1);
}
}
} else {
grab_segdata(dyn, addr, ninst, x4, seg);
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x1, &fixedaddress, rex, NULL, 1, 0);
ADD(x4, ed, x4);
if(rex.w) {
SD(gd, x4, fixedaddress);
} else {
SH(gd, x4, fixedaddress);
}
SMWRITE();
}
break;
case 0x8B:
INST_NAME("MOV Gd, FS:Ed");
nextop=F8;
@@ -69,7 +98,6 @@ uintptr_t dynarec64_6664(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
}
break;
default:
DEFAULT;
}
+66
View File
@@ -8,6 +8,7 @@
#include "dynarec.h"
#include "emu/x64emu_private.h"
#include "emu/x64run_private.h"
#include "rv64_emitter.h"
#include "x64run.h"
#include "x64emu.h"
#include "box64stack.h"
@@ -48,6 +49,71 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETREX();
switch(opcode) {
case 0x11:
INST_NAME("LOCK ADC Ew, Gw");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGW(x1);
SMDMB();
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
MOV32w(x6, 0xFFFF);
AND(x2, ed, x6);
emit_adc16(dyn, ninst, x1, x2, x3, x4, x5);
if (rv64_zbb) {
ANDN(ed, ed, x6);
} else {
NOT(x6, x6);
AND(ed, ed, x6);
}
OR(ed, ed, x2);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x2, x3, &fixedaddress, rex, LOCK_LOCK, 0, 0);
ANDI(x3, wback, 0b10);
MOV32w(x4, 0xffff); // x4 = mask
BNEZ_MARK(x3);
// lower 16bits
MARKLOCK;
LR_W(x5, wback, 1, 1);
AND(x6, x5, x4); // x6 = Ed.h[0]
SRLIW(x5, x5, 16);
SLLIW(x5, x5, 16); // x5 = clear Ed.h[0]
ADDW(x2, x1, x6); // x2 = Gw + Ew
ANDI(x9, xFlags, 1 << F_CF);
ADDW(x2, x2, x9); // x2 = adc
AND(x2, x2, x4);
OR(x5, x5, x2);
SC_W(x2, x5, wback, 1, 1);
BNEZ_MARKLOCK(x2);
B_MARK3_nocond;
MARK;
// upper 16bits
SLLIW(x3, x4, 16); // x3 = mask
SUBI(wback, wback, 2); // aligning address
SLLI(x1, x1, 16); // x1 = extended Gw
MARK2;
LR_W(x6, wback, 1, 1); // x6 = Ed
AND(x5, x6, x3); // x5 = Ed.h[1] << 16
ADDW(x5,x5, x1);
ANDI(x9, xFlags, 1 << F_CF);
SLLIW(x9, x9, 16);
ADDW(x5, x5, x9); // x5 = adc << 16
AND(x9, x6, x4); // x9 = Ed.h[0]
OR(x5, x5, x9);
SC_W(x9, x5, wback, 1, 1);
BNEZ_MARK2(x9);
IFX(X_ALL|X_PEND) {
SRLIW(x6, x6, 16);
SRLIW(x1, x1, 16);
}
MARK3;
IFX(X_ALL|X_PEND) {
emit_adc16(dyn, ninst, x1, x6, x3, x4, x5);
}
}
SMDMB();
break;
case 0x81:
case 0x83:
nextop = F8;
+57
View File
@@ -567,6 +567,63 @@ uintptr_t dynarec64_67(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
}
}
break;
#define GO(Z) \
BARRIER(BARRIER_MAYBE); \
JUMP(addr+i8, 1); \
if(dyn->insts[ninst].x64.jmp_insts==-1 || \
CHECK_CACHE()) { \
/* out of the block */ \
i32 = dyn->insts[ninst].epilog-(dyn->native_size); \
if(Z) {BNE(x1, xZR, i32);} else {BEQ(x1, xZR, i32);}; \
if(dyn->insts[ninst].x64.jmp_insts==-1) { \
if(!(dyn->insts[ninst].x64.barrier&BARRIER_FLOAT)) \
fpu_purgecache(dyn, ninst, 1, x1, x2, x3); \
jump_to_next(dyn, addr+i8, 0, ninst); \
} else { \
CacheTransform(dyn, ninst, cacheupd, x1, x2, x3); \
i32 = dyn->insts[dyn->insts[ninst].x64.jmp_insts].address-(dyn->native_size); \
B(i32); \
} \
} else { \
/* inside the block */ \
i32 = dyn->insts[dyn->insts[ninst].x64.jmp_insts].address-(dyn->native_size); \
if(Z) {BEQ(x1, xZR, i32);} else {BNE(x1, xZR, i32);}; \
}
case 0xE0:
INST_NAME("LOOPNZ (32bits)");
READFLAGS(X_ZF);
i8 = F8S;
SUBI(xRCX, xRCX, 1);
ANDI(x1, xFlags, 1 << F_ZF);
CBNZ_NEXT(x1);
AND(x1, xRCX, xMASK);
GO(0);
break;
case 0xE1:
INST_NAME("LOOPZ (32bits)");
READFLAGS(X_ZF);
i8 = F8S;
SUBI(xRCX, xRCX, 1);
ANDI(x1, xFlags, 1 << F_ZF);
CBZ_NEXT(x1);
AND(x1, xRCX, xMASK);
GO(0);
break;
case 0xE2:
INST_NAME("LOOP (32bits)");
i8 = F8S;
SUBI(xRCX, xRCX, 1);
AND(x1, xRCX, xMASK);
GO(0);
break;
case 0xE3:
INST_NAME("JECXZ (32bits)");
i8 = F8S;
AND(x1, xRCX, xMASK);
GO(1);
break;
#undef GO
default:
DEFAULT;
}
+98
View File
@@ -339,6 +339,101 @@ uintptr_t dynarec64_F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
DEFAULT;
}
break;
case 0x10:
INST_NAME("LOCK ADC Eb, Gb");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGB(x2);
SMDMB();
if((nextop&0xC0)==0xC0) {
if(rex.rex) {
wback = xRAX + (nextop&7) + (rex.b<<3);
wb2 = 0;
} else {
wback = (nextop&7);
wb2 = (wback>>2);
wback = xRAX+(wback&3);
}
SRLIW(x1, wback, wb2*8);
ANDI(x1, x1, 0xFF);
emit_adc8(dyn, ninst, x1, x2, x3, x4, x5);
SLLI(x1, x1, wb2*8);
MOV_U12(x3, 0xFF);
SLLI(x3, x3, wb2*8);
NOT(x3, x3);
AND(wback, wback, x3);
OR(wback, wback, x1);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x1, x3, &fixedaddress, rex, LOCK_LOCK, 0, 0);
ANDI(x3, wback, 0b11);
BNEZ_MARK(x3);
MARKLOCK;
LR_W(x5, wback, 1, 1);
ANDI(x4, x5, 0xff); // x4 = Ed.b[0]
ANDI(x5, x5, -256); // x5 = clear Ed.b[0]
ADDW(x6, x4, x2);
ANDI(x9, xFlags, 1 << F_CF);
ADDW(x6, x6, x9); // x6 = adc
ANDI(x6, x6, 0xff);
OR(x5, x5, x6);
SC_W(x9, x5, wback, 1, 1);
BNEZ_MARKLOCK(x9);
B_MARK3_nocond;
MARK;
SLLI(x3, x3, 3);
MOV_U12(x4, 0xff);
ANDI(wback, wback, ~3); // aligning address
SLLI(x4, x4, x3); // x4 = byte mask
NOT(x5, x4); // x5 = ~mask
SLL(x2, x2, x3); // x2 = extented Gb
MARK2;
LR_W(x6, wback, 1, 1); // x6 = Ed
AND(x9, x6, x4); // x9 = extended Ed.b[dest]
AND(x6, x6, x5); // x6 = clear Ed.b[dest]
ADDW(x5, x9, x2);
ANDI(x4, xFlags, 1 << F_CF);
SLL(x4, x4, x3); // extented
ADDW(x5, x5, x4); // x5 = adc
OR(x5, x5, x6);
SC_W(x4, x5, wback, 1, 1);
BNEZ_MARK2(x4);
IFX(X_ALL|X_PEND) {
SRLI(x2, x2, x3); // Gb
SRLI(x4, x9, x3); // Eb
}
MARK3;
IFX(X_ALL|X_PEND) {
emit_adc8(dyn, ninst, x4, x2, x3, x5, x6);
}
}
SMDMB();
break;
case 0x11:
INST_NAME("LOCK ADC Ed, Gd");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
nextop = F8;
GETGD;
SMDMB();
if(MODREG) {
ed = xRAX+(nextop&7)+(rex.b<<3);
emit_adc32(dyn, ninst, rex, ed, gd, x3, x4, x5, x6);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x2, x1, &fixedaddress, rex, LOCK_LOCK, 0, 0);
MARKLOCK;
LRxw(x1, wback, 1, 1);
ADDxw(x3, x1, gd);
ANDI(x4, xFlags, 1 << F_CF);
ADDxw(x3, x3, x4);
SCxw(x4, x3, wback, 1, 1);
BNEZ_MARKLOCK(x4);
IFX(X_ALL|X_PEND) {
emit_adc32(dyn, ninst, rex, x1, gd, x3, x4, x5, x6);
}
}
SMDMB();
break;
case 0x21:
INST_NAME("LOCK AND Ed, Gd");
SETFLAGS(X_ALL, SF_SET_PENDING);
@@ -381,6 +476,9 @@ uintptr_t dynarec64_F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
}
SMDMB();
break;
case 0x66:
return dynarec64_66F0(dyn, addr, ip, ninst, rex, rep, ok, need_epilog);
case 0x80:
nextop = F8;
SMDMB();
+1 -1
View File
@@ -135,7 +135,7 @@ uintptr_t get_closest_next(dynarec_rv64_t *dyn, uintptr_t addr);
int is_nops(dynarec_rv64_t *dyn, uintptr_t addr, int n);
int is_instructions(dynarec_rv64_t *dyn, uintptr_t addr, int n);
int Table64(dynarec_rv64_t *dyn, uint64_t val, int pass); // add a value to etable64 (if needed) and gives back the imm19 to use in LDR_literal
int Table64(dynarec_rv64_t *dyn, uint64_t val, int pass); // add a value to table64 (if needed) and gives back the imm19 to use in LDR_literal
void CreateJmpNext(void* addr, void* next);
+1
View File
@@ -128,6 +128,7 @@ f28–31 ft8–11 FP temporaries Caller
// RV32I
// put imm20 in the [31:12] bits of rd, zero [11:0] and sign extend bits31
#define LUI(rd, imm20) EMIT(U_type((imm20)<<12, rd, 0b0110111))
// put PC+imm20 in rd
#define AUIPC(rd, imm20) EMIT(U_type((imm20)<<12, rd, 0b0010111))
+13 -13
View File
@@ -2,49 +2,49 @@
#define __RV64_LOCK__H__
#include <stdint.h>
// Atomicaly store val at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
// Atomically store val at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
extern int rv64_lock_cas_d(void* p, int32_t ref, int32_t val);
// Atomicaly store val at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
// Atomically store val at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
extern int rv64_lock_cas_dd(void* p, int64_t ref, int64_t val);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uintptr_t rv64_lock_xchg_dd(void* p, uintptr_t val);
// Atomicaly exchange value at [p] with val, return old p
// Atomically exchange value at [p] with val, return old p
extern uint32_t rv64_lock_xchg_d(void* p, uint32_t val);
// Atomicaly store value to [p] only if [p] is NULL. Return old [p] value
// Atomically store value to [p] only if [p] is NULL. Return old [p] value
extern uint32_t rv64_lock_storeifnull_d(void*p, uint32_t val);
// Atomicaly store value to [p] only if [p] is NULL. Return old [p] value
// Atomically store value to [p] only if [p] is NULL. Return old [p] value
extern void* rv64_lock_storeifnull(void*p, void* val);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern void* rv64_lock_storeifref(void*p, void* val, void* ref);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern uint32_t rv64_lock_storeifref_d(void*p, uint32_t val, uint32_t ref);
// Atomicaly store value to [p] only if [p] is ref. Return new [p] value (so val or old)
// Atomically store value to [p] only if [p] is ref. Return new [p] value (so val or old)
extern uint32_t rv64_lock_storeifref2_d(void*p, uint32_t val, uint32_t ref);
// decrement atomicaly the byte at [p] (but only if p not 0)
// decrement atomically the byte at [p] (but only if p not 0)
extern void rv64_lock_decifnot0b(void*p);
// atomic store (with memory barrier)
extern void rv64_lock_storeb(void*p, uint8_t b);
// increment atomicaly the int at [p] only if it was 0. Return the old value of [p]
// increment atomically the int at [p] only if it was 0. Return the old value of [p]
extern int rv64_lock_incif0(void*p);
// decrement atomicaly the int at [p] (but only if p not 0)
// decrement atomically the int at [p] (but only if p not 0)
extern int rv64_lock_decifnot0(void*p);
// atomic store (with memory barrier)
extern void rv64_lock_store(void*p, uint32_t v);
// (mostly) Atomicaly store val1 and val2 at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
// (mostly) Atomically store val1 and val2 at [p] if old [p] is ref. Return 0 if OK, 1 is not. p needs to be aligned
extern int rv64_lock_cas_dq(void* p, uint64_t ref, uint64_t val1, uint64_t val2);
// Not defined in assembler but in dynarec_rv64_functions
Executable → Regular
View File
File mode changed.
Executable → Regular
+69 -21
View File
@@ -311,8 +311,10 @@ void FreeElfMemory(elfheader_t* head)
for(int i=0; i<head->multiblock_n; ++i) {
#ifdef DYNAREC
dynarec_log(LOG_INFO, "Free DynaBlocks for %s\n", head->path);
cleanDBFromAddressRange((uintptr_t)head->multiblock[i], head->multiblock_size[i], 1);
freeProtection((uintptr_t)head->multiblock[i], head->multiblock_size[i]);
if(box64_dynarec) {
cleanDBFromAddressRange((uintptr_t)head->multiblock[i], head->multiblock_size[i], 1);
freeProtection((uintptr_t)head->multiblock[i], head->multiblock_size[i]);
}
#endif
munmap(head->multiblock[i], head->multiblock_size[i]);
}
@@ -374,6 +376,23 @@ int LoadElfMemory(FILE* f, box64context_t* context, elfheader_t* head)
return 0;
}
int isElfHasNeededVer(elfheader_t* head, const char* libname, elfheader_t* verneeded)
{
if(!verneeded || !head)
return 1;
if(!head->VerDef || !verneeded->VerNeed)
return 1;
int cnt = GetNeededVersionCnt(verneeded, libname);
for (int i=0; i<cnt; ++i) {
const char* vername = GetNeededVersionString(verneeded, libname, i);
if(vername && !GetVersionIndice(head, vername)) {
printf_log(/*LOG_DEBUG*/LOG_INFO, "Discarding %s for missing version %s\n", head->path, vername);
return 0; // missing version
}
}
return 1;
}
int ReloadElfMemory(FILE* f, box64context_t* context, elfheader_t* head)
{
(void)context;
@@ -471,11 +490,20 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t*
end = offs + sym->st_size;
}*/
// so weak symbol are the one left
if(!offs && !end) {
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(bind==STB_WEAK) {
if(!offs && !end) {
if(!offs && !end && local_maplib)
GetGlobalWeakSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalWeakSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
}
} else {
if(!offs && !end) {
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
}
}
}
uintptr_t globoffs, globend;
@@ -503,7 +531,8 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t*
if(sym->st_size && offs) {
printf_dump(LOG_NEVER, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) size=%ld on sym=%s \n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)(offs + head->delta), (void*)globoffs, sym->st_size, symname);
memmove((void*)globoffs, (void*)offs, sym->st_size); // preapply to copy part from lib to main elf
AddUniqueSymbol(GetGlobalData(maplib), symname, offs + head->delta, sym->st_size, version, vername);
AddUniqueSymbol(GetGlobalData(maplib), symname, globoffs, sym->st_size, version, vername);
AddUniqueSymbol(my_context->globdata, symname, offs + head->delta, sym->st_size, version, vername);
} else {
printf_dump(LOG_NEVER, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) null sized on sym=%s \n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, symname);
}
@@ -528,7 +557,7 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t*
uintptr_t old_offs = offs;
uintptr_t old_end = end;
offs = 0;
GetSizedSymbolStartEnd(GetGlobalData(maplib), symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first
GetSizedSymbolStartEnd(my_context->globdata, symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first
if(offs==0) {
GetNoSelfSymbolStartEnd(maplib, symname, &offs, &end, head, size, version, vername, globdefver, weakdefver); // get original copy if any
if(!offs && local_maplib)
@@ -672,13 +701,24 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
end = offs + sym->st_size;
}*/
// so weak symbol are the one left
if(old_version==version && old_bind==bind && old_symname==symname) {
offs = old_offs;
end = old_end;
if(bind==STB_WEAK) {
if(old_version==version && old_bind==bind && old_symname==symname) {
offs = old_offs;
end = old_end;
} else {
GetGlobalWeakSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalWeakSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
}
} else {
GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(old_version==version && old_bind==bind && old_symname==symname) {
offs = old_offs;
end = old_end;
} else {
GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
if(!offs && !end && local_maplib)
GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver);
}
}
}
old_bind = bind;
@@ -712,7 +752,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
globoffs = offs;
globend = end;
offs = end = 0;
GetSizedSymbolStartEnd(GetGlobalData(maplib), symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first
GetSizedSymbolStartEnd(my_context->globdata, symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first
if(!offs && local_maplib)
GetNoSelfSymbolStartEnd(local_maplib, symname, &offs, &end, head, size, version, vername, globdefver, weakdefver);
if(!offs)
@@ -737,7 +777,8 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
(bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0),
(void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, sym->st_size, symname, version, vername?vername:"(none)");
//memmove((void*)globoffs, (void*)offs, sym->st_size); // preapply to copy part from lib to main elf
AddUniqueSymbol(GetGlobalData(maplib), symname, offs, sym->st_size, version, vername);
AddUniqueSymbol(GetGlobalData(maplib), symname, globoffs, sym->st_size, version, vername);
AddUniqueSymbol(my_context->globdata, symname, offs, sym->st_size, version, vername);
} else {
printf_dump(LOG_NEVER, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) null sized on sym=%s (ver=%d/%s)\n",
(bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0),
@@ -1201,7 +1242,7 @@ int LoadNeededLibs(elfheader_t* h, lib_t *maplib, int local, int bindnow, box64c
h->needed->names[j++] = h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val;
// TODO: Add LD_LIBRARY_PATH and RPATH handling
if(AddNeededLib(maplib, local, bindnow, h->needed, box64, emu)) {
if(AddNeededLib(maplib, local, bindnow, h->needed, h, box64, emu)) {
printf_log(LOG_INFO, "Error loading one of needed lib\n");
if(!allow_missing_libs)
return 1; //error...
@@ -1246,6 +1287,7 @@ void MarkElfInitDone(elfheader_t* h)
if(h)
h->init_done = 1;
}
void startMallocHook();
void RunElfInitPltResolver(elfheader_t* h, x64emu_t *emu)
{
if(!h || h->init_done)
@@ -1260,17 +1302,20 @@ void RunElfInitPltResolver(elfheader_t* h, x64emu_t *emu)
}
printf_dump(LOG_DEBUG, "Calling Init for %s @%p\n", ElfName(h), (void*)p);
if(h->initentry)
RunSafeFunction(my_context, p, 3, my_context->argc, my_context->argv, my_context->envv);
RunSafeFunction(p, 3, my_context->argc, my_context->argv, my_context->envv);
printf_dump(LOG_DEBUG, "Done Init for %s\n", ElfName(h));
// and check init array now
Elf64_Addr *addr = (Elf64_Addr*)(h->initarray + h->delta);
for (size_t i=0; i<h->initarray_sz; ++i) {
if(addr[i]) {
printf_dump(LOG_DEBUG, "Calling Init[%zu] for %s @%p\n", i, ElfName(h), (void*)addr[i]);
RunSafeFunction(my_context, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv);
RunSafeFunction((uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv);
}
}
if(h->malloc_hook_2)
startMallocHook();
h->fini_done = 0; // can be fini'd now (in case it was re-inited)
printf_dump(LOG_DEBUG, "All Init Done for %s\n", ElfName(h));
return;
@@ -1315,6 +1360,9 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
}
}
if(h->malloc_hook_2)
startMallocHook();
h->fini_done = 0; // can be fini'd now (in case it was re-inited)
printf_dump(LOG_DEBUG, "All Init Done for %s\n", ElfName(h));
return;
@@ -1587,7 +1635,7 @@ static int my_dl_iterate_phdr_##A(struct dl_phdr_info* a, size_t b, void* c)
return 0; \
if(!a->dlpi_name[0]) /*don't send informations about box64 itself*/ \
return 0; \
return (int)RunFunction(my_context, my_dl_iterate_phdr_fct_##A, 3, a, b, c); \
return (int)RunFunction(my_dl_iterate_phdr_fct_##A, 3, a, b, c); \
}
SUPER()
#undef GO
Executable → Regular
+1
View File
@@ -87,6 +87,7 @@ struct elfheader_s {
int init_done;
int fini_done;
int refcnt; // ref count for the elf
int malloc_hook_2; // this elf hook malloc, hacking it
char* memory; // char* and not void* to allow math on memory pointer
void** multiblock;
Executable → Regular
+40 -12
View File
@@ -416,18 +416,6 @@ int GetVersionIndice(elfheader_t* h, const char* vername)
{
if(!vername)
return 0;
if(h->VerNeed) {
Elf64_Verneed *ver = (Elf64_Verneed*)((uintptr_t)h->VerNeed + h->delta);
while(ver) {
Elf64_Vernaux *aux = (Elf64_Vernaux*)((uintptr_t)ver + ver->vn_aux);
for(int j=0; j<ver->vn_cnt; ++j) {
if(!strcmp(h->DynStr+aux->vna_name, vername))
return aux->vna_other;
aux = (Elf64_Vernaux*)((uintptr_t)aux + aux->vna_next);
}
ver = ver->vn_next?((Elf64_Verneed*)((uintptr_t)ver + ver->vn_next)):NULL;
}
}
if(h->VerDef) {
Elf64_Verdef *def = (Elf64_Verdef*)((uintptr_t)h->VerDef + h->delta);
while(def) {
@@ -438,4 +426,44 @@ int GetVersionIndice(elfheader_t* h, const char* vername)
}
}
return 0;
}
int GetNeededVersionCnt(elfheader_t* h, const char* libname)
{
if(!libname)
return 0;
if(h->VerNeed) {
Elf64_Verneed *ver = (Elf64_Verneed*)((uintptr_t)h->VerNeed + h->delta);
while(ver) {
char *filename = h->DynStr + ver->vn_file;
Elf64_Vernaux *aux = (Elf64_Vernaux*)((uintptr_t)ver + ver->vn_aux);
if(!strcmp(filename, libname))
return ver->vn_cnt;
ver = ver->vn_next?((Elf64_Verneed*)((uintptr_t)ver + ver->vn_next)):NULL;
}
}
return 0;
}
const char* GetNeededVersionString(elfheader_t* h, const char* libname, int idx)
{
if(!libname)
return 0;
if(h->VerNeed) {
Elf64_Verneed *ver = (Elf64_Verneed*)((uintptr_t)h->VerNeed + h->delta);
while(ver) {
char *filename = h->DynStr + ver->vn_file;
Elf64_Vernaux *aux = (Elf64_Vernaux*)((uintptr_t)ver + ver->vn_aux);
if(!strcmp(filename, libname)) {
for(int j=0; j<ver->vn_cnt; ++j) {
if(j==idx)
return h->DynStr+aux->vna_name;
aux = (Elf64_Vernaux*)((uintptr_t)aux + aux->vna_next);
}
return NULL; // idx out of bound, return NULL...
}
ver = ver->vn_next?((Elf64_Verneed*)((uintptr_t)ver + ver->vn_next)):NULL;
}
}
return NULL;
}
+2
View File
@@ -34,6 +34,7 @@
#define GETEW(D) oped=TestEw(test, &addr, rex, nextop, D)
#define GETEW32(D) oped=TestEw32O(test, &addr, rex, nextop, D, 0)
#define GETEW_OFFS(D, O) oped=TestEdO(test, &addr, rex, nextop, D, O)
#define GETEW_OFFS_16(O) oped=TestEw16off(test, &addr, rex, nextop, O)
#define GETGW opgd=GetGw(test->emu, &addr, rex, nextop)
#define GETEX(D) opex=TestEx(test, &addr, rex, nextop, D)
#define GETEX32(D) opex=TestEx32O(test, &addr, rex, nextop, D, 0)
@@ -58,6 +59,7 @@
#define GETEW(D) oped=GetEw(emu, &addr, rex, nextop, D)
#define GETEW32(D) oped=GetEw32O(emu, &addr, rex, nextop, D, 0)
#define GETEW_OFFS(D, O) oped=GetEdO(emu, &addr, rex, nextop, D, O)
#define GETEW_OFFS_16(O) oped=GetEw16off(emu, &addr, rex, nextop, O)
#define GETGW opgd=GetGw(emu, &addr, rex, nextop)
#define GETEX(D) opex=GetEx(emu, &addr, rex, nextop, D)
#define GETEX32(D) opex=GetEx32O(emu, &addr, rex, nextop, D, 0)
Executable → Regular
+3 -3
View File
@@ -567,9 +567,9 @@ void EmuCall(x64emu_t* emu, uintptr_t addr)
Run(emu, 0);
emu->quit = 0; // reset Quit flags...
emu->df = d_none;
if(emu->quitonlongjmp && emu->longjmp) {
if(emu->quitonlongjmp==1)
emu->longjmp = 0; // don't change anything because of the longjmp
if(emu->flags.quitonlongjmp && emu->flags.longjmp) {
if(emu->flags.quitonlongjmp==1)
emu->flags.longjmp = 0; // don't change anything because of the longjmp
} else {
R_RBX = old_rbx;
R_RDI = old_rdi;
Executable → Regular
+12 -6
View File
@@ -36,6 +36,14 @@ typedef struct x64test_s {
uint8_t mem[16];
} x64test_t;
typedef struct emu_flags_s {
uint32_t need_jmpbuf:1; // need a new jmpbuff for signal handling
uint32_t quitonlongjmp:2; // quit if longjmp is called
uint32_t quitonexit:2; // quit if exit/_exit is called
uint32_t longjmp:1; // if quit because of longjmp
uint32_t jmpbuf_ready:1; // the jmpbuf in the emu is ok and don't need refresh
} emu_flags_t;
typedef struct x64emu_s {
// cpu
reg64_t regs[16];
@@ -48,7 +56,7 @@ typedef struct x64emu_s {
mmx87_regs_t mmx[8];
x87control_t cw;
x87flags_t sw;
uint32_t top; // top is part of sw, but it's faster to have it separatly
uint32_t top; // top is part of sw, but it's faster to have it separately
int fpu_stack;
mmxcontrol_t mxcsr;
fpu_ld_t fpu_ld[8]; // for long double emulation / 80bits fld fst
@@ -83,16 +91,14 @@ typedef struct x64emu_s {
int quit;
int error;
int fork; // quit because need to fork
forkpty_t* forkpty_info;
int exit;
int quitonlongjmp; // quit if longjmp is called
int quitonexit; // quit if exit/_exit is called
int longjmp; // if quit because of longjmp
forkpty_t* forkpty_info;
emu_flags_t flags;
x64test_t test; // used for dynarec testing
#ifdef HAVE_TRACE
sse_regs_t old_xmm[16];
#endif
// scratch stack, used for alignement of double and 64bits ints on arm. 200 elements should be enough
// scratch stack, used for alignment of double and 64bits ints on arm. 200 elements should be enough
uint64_t scratch[200];
// local stack, do be deleted when emu is freed
void* stack2free; // this is the stack to free (can be NULL)
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
Executable → Regular
View File
File mode changed.
Executable → Regular
+91 -19
View File
@@ -227,11 +227,34 @@ x64emurun:
emu->segs_serial[_DS] = 0;
break;
case 0x27: /* DAA */
if(rex.is32bits) {
R_AL = daa8(emu, R_AL);
} else {
unimp = 1;
goto fini;
}
break;
case 0x2F: /* DAS */
if(rex.is32bits) {
R_AL = das8(emu, R_AL);
} else {
unimp = 1;
goto fini;
}
break;
case 0x2E: /* segments are ignored */
case 0x26:
case 0x36: /* SS: (ignored) */
break;
case 0x37: /* AAA */
if(rex.is32bits) {
R_AX = aaa16(emu, R_AX);
} else {
unimp = 1;
goto fini;
}
break;
case 0x38:
nextop = F8;
GETEB(0);
@@ -271,6 +294,15 @@ x64emurun:
else
cmp32(emu, R_EAX, F32);
break;
case 0x3F: /* AAS */
if(rex.is32bits) {
R_AX = aas16(emu, R_AX);
} else {
unimp = 1;
goto fini;
}
break;
case 0x40:
case 0x41:
case 0x42:
@@ -361,7 +393,14 @@ x64emurun:
goto fini;
}
break;
case 0x62: /* BOUND Gd, Ed */
if(rex.is32bits) {
FAKEED(0);
} else {
unimp = 1;
goto fini;
}
break;
case 0x63: /* MOVSXD Gd,Ed */
nextop = F8;
GETED(0);
@@ -659,12 +698,12 @@ x64emurun:
GETEB(0);
GETGB;
if(!MODREG)
pthread_mutex_lock(&emu->context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
pthread_mutex_lock(&my_context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
tmp8u = GB;
GB = EB->byte[0];
EB->byte[0] = tmp8u;
if(!MODREG)
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0x87: /* XCHG Ed,Gd */
@@ -693,7 +732,7 @@ x64emurun:
GETED(0);
GETGD;
if(!MODREG)
pthread_mutex_lock(&emu->context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
pthread_mutex_lock(&my_context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
if(rex.w) {
tmp64u = GD->q[0];
GD->q[0] = ED->q[0];
@@ -707,7 +746,7 @@ x64emurun:
ED->dword[0] = tmp32u;
}
if(!MODREG)
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0x88: /* MOV Eb,Gb */
@@ -1315,7 +1354,32 @@ x64emurun:
addr = rex.is32bits?Pop32(emu):Pop64(emu);
STEP2
break;
case 0xC4: /* LES Gd,Ed */
if(rex.is32bits) {
nextop = F8;
GETED(0);
GETGD;
emu->segs[_ES] = *(__uint16_t*)(((char*)ED)+4);
emu->segs_serial[_ES] = 0;
GD->dword[0] = *(uint32_t*)ED;
} else {
// AVX not supported yet
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
}
break;
case 0xC5: /* LDS Gd,Ed */
if(rex.is32bits) {
nextop = F8;
GETED(0);
GETGD;
emu->segs[_DS] = *(__uint16_t*)(((char*)ED)+4);
emu->segs_serial[_DS] = 0;
GD->dword[0] = *(uint32_t*)ED;
} else {
// AVX not supported yet
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
}
break;
case 0xC6: /* MOV Eb,Ib */
nextop = F8;
GETEB(1);
@@ -1378,12 +1442,14 @@ x64emurun:
if(box64_wine && tmp8u==0x2D) {
// lets ignore the INT 2D
printf_log(LOG_DEBUG, "INT 2D called\n");
emit_interruption(emu, 0x2d, (void*)R_RIP);
} else if(box64_wine && tmp8u==0x2c) {
printf_log(LOG_DEBUG, "INT 2c called\n");
emit_interruption(emu, 0x2c, (void*)R_RIP);
} else if(box64_wine && tmp8u==0x29) {
// INT 29 is __fastfail
printf_log(LOG_DEBUG, "INT 29 called => __fastfail(0x%x)\n", R_ECX);
emu->quit = 1;
R_RIP = addr;
goto fini;
emit_interruption(emu, 0x29, (void*)R_RIP);
} else if (tmp8u==0x80) {
// 32bits syscall
#ifndef TEST_INTERPRETER
@@ -1470,6 +1536,15 @@ x64emurun:
}
break;
case 0xD6: /* SALC */
if(rex.is32bits) {
CHECK_FLAGS(emu);
R_AL = ACCESS_FLAG(F_CF)?0xff:0x00;
} else {
unimp = 1;
goto fini;
};
break;
case 0xD7: /* XLAT */
R_AL = *(uint8_t*)(R_RBX + R_AL);
break;
@@ -1871,9 +1946,8 @@ x64emurun:
case 3: /* CALL FAR Ed */
GETET(0);
if(MODREG) {
printf_log(LOG_NONE, "Illegal Opcode %p: %02X %02X %02X %02X\n", (void*)R_RIP, opcode, nextop, PK(2), PK(3));
emu->quit=1;
emu->error |= ERR_ILLEGAL;
printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1));
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
goto fini;
} else {
if(rex.is32bits || !rex.w) {
@@ -1902,9 +1976,8 @@ x64emurun:
case 5: /* JMP FAR Ed */
GETET(0);
if(MODREG) {
printf_log(LOG_NONE, "Illegal Opcode %p: 0x%02X 0x%02X %02X %02X\n", (void*)R_RIP, opcode, nextop, PK(2), PK(3));
emu->quit=1;
emu->error |= ERR_ILLEGAL;
printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1));
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
goto fini;
} else {
if(rex.is32bits || !rex.w) {
@@ -1929,9 +2002,8 @@ x64emurun:
}
break;
default:
printf_log(LOG_NONE, "Illegal Opcode %p: %02X %02X %02X %02X %02X %02X\n",(void*)R_RIP, opcode, nextop, PK(2), PK(3), PK(4), PK(5));
emu->quit=1;
emu->error |= ERR_ILLEGAL;
printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1), PK(2), PK(3));
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
goto fini;
}
break;
+45 -4
View File
@@ -813,7 +813,19 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
, EB->byte[0]=0;
,
) /* 0x90 -> 0x9F SETxx Eb */
case 0xA0: /* PUSH FS */
if(rex.is32bits)
Push32(emu, emu->segs[_FS]);
else
Push64(emu, emu->segs[_FS]);
break;
case 0xA1: /* POP FS */
if(rex.is32bits)
emu->segs[_FS] = Pop32(emu);
else
emu->segs[_FS] = Pop64(emu);
emu->segs_serial[_FS] = 0;
break;
case 0xA2: /* CPUID */
tmp32u = R_EAX;
my_cpuid(emu, tmp32u);
@@ -869,6 +881,20 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
}
break;
case 0xA8: /* PUSH GS */
if(rex.is32bits)
Push32(emu, emu->segs[_GS]);
else
Push64(emu, emu->segs[_GS]);
break;
case 0xA9: /* POP GS */
if(rex.is32bits)
emu->segs[_GS] = Pop32(emu);
else
emu->segs[_GS] = Pop64(emu);
emu->segs_serial[_FS] = 0;
break;
case 0xAB: /* BTS Ed,Gd */
CHECK_FLAGS(emu);
nextop = F8;
@@ -1438,7 +1464,12 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
GETGM;
GM->q = (EM->q > 63) ? 0L : (GM->q >> EM->q);
break;
case 0xD4: /* PADDQ Gm,Em */
nextop = F8;
GETEM(0);
GETGM;
GM->sq += EM->sq;
break;
case 0xD5: /* PMULLW Gm,Em */
nextop = F8;
GETEM(0);
@@ -1677,7 +1708,12 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
GETGM;
GM->q = (EM->q > 63) ? 0L : (GM->q << EM->ub[0]);
break;
case 0xF4: /* PMULUDQ Gm,Em */
nextop = F8;
GETEM(0);
GETGM;
GM->q = (uint64_t)GM->ud[0] * (uint64_t)EM->ud[0];
break;
case 0xF5: /* PMADDWD Gm, Em */
nextop = F8;
GETEM(0);
@@ -1720,7 +1756,12 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
for(int i=0; i<2; ++i)
GM->ud[i] -= EM->ud[i];
break;
case 0xFB: /* PSUBQ Gm, Em */
nextop = F8;
GETEM(0);
GETGM;
GM->sq -= EM->sq;
break;
case 0xFC: /* PADDB Gm, Em */
nextop = F8;
GETEM(0);
+5
View File
@@ -326,6 +326,11 @@ uintptr_t Run64(x64emu_t *emu, rex_t rex, int seg, uintptr_t addr)
case 0x66:
return Run6664(emu, rex, seg, addr);
case 0x67:
if(rex.is32bits)
return Run6764_32(emu, rex, seg, seg, addr);
else
return 0;
case 0x80: /* GRP Eb,Ib */
nextop = F8;
+62 -25
View File
@@ -166,7 +166,33 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
tmp8u = opcode&7;
emu->regs[tmp8u].word[0] = dec16(emu, emu->regs[tmp8u].word[0]);
break;
case 0x50:
case 0x51:
case 0x52:
case 0x53:
case 0x55:
case 0x56:
case 0x57: /* PUSH Reg */
if(rex.is32bits) {
tmp8u = opcode&7;
Push16(emu, emu->regs[tmp8u].word[0]);
} else
return 0;
break;
case 0x58:
case 0x59:
case 0x5A:
case 0x5B:
case 0x5C: /* POP ESP */
case 0x5D:
case 0x5E:
case 0x5F: /* POP Reg */
if(rex.is32bits) {
tmp8u = opcode&7;
emu->regs[tmp8u].word[0] = Pop16(emu);
} else
return 0;
break;
case 0x60: /* PUSHA */
if(rex.is32bits) {
tmp16u = R_SP;
@@ -338,27 +364,26 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
GD->word[0] = (uint16_t)tmp64u;
break;
case 0x90: /* NOP or XCHG R8d, AX*/
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97: /* XCHG reg,AX */
tmp8u = _AX+(opcode&7)+(rex.b<<3);
if(tmp8u!=_AX) {
if(rex.w) {
tmp64u = R_RAX;
R_RAX = emu->regs[tmp8u].q[0];
emu->regs[tmp8u].q[0] = tmp64u;
} else {
tmp16u = R_AX;
R_AX = emu->regs[tmp8u].word[0];
emu->regs[tmp8u].word[0] = tmp16u;
}
case 0x90: /* NOP or XCHG R8d, AX*/
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97: /* XCHG reg,AX */
tmp8u = _AX+(opcode&7)+(rex.b<<3);
if(tmp8u!=_AX) {
if(rex.w) {
tmp64u = R_RAX;
R_RAX = emu->regs[tmp8u].q[0];
emu->regs[tmp8u].q[0] = tmp64u;
} else {
tmp16u = R_AX;
R_AX = emu->regs[tmp8u].word[0];
emu->regs[tmp8u].word[0] = tmp16u;
}
break;
}
break;
case 0x98: /* CBW */
@@ -368,6 +393,16 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
R_DX=((R_AX & 0x8000)?0xFFFF:0x0000);
break;
case 0x9C: /* PUSHFW */
CHECK_FLAGS(emu);
Push16(emu, (uint16_t)emu->eflags.x64);
break;
case 0x9D: /* POPFW */
CHECK_FLAGS(emu);
emu->eflags.x64 &=0xffff0000;
emu->eflags.x64 |= (Pop16(emu) & 0x3F7FD7) | 0x2;
break;
case 0xA1: /* MOV EAX,Od */
if(rex.is32bits) {
R_AX = *(uint16_t*)(uintptr_t)F32;
@@ -789,7 +824,6 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
case 0xFF: /* GRP 5 Ew */
nextop = F8;
GETEW(0);
GETGW;
switch((nextop>>3)&7) {
case 0: /* INC Ed */
EW->word[0] = inc16(emu, EW->word[0]);
@@ -807,9 +841,12 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
}
addr = tmp64u;
break;
/*case 6:
Push16(emu, EW->word[0]);
break;*/
case 6: /* Push Ew */
if(rex.is32bits) {
Push16(emu, EW->word[0]);
} else
return 0;
break;
default:
printf_log(LOG_NONE, "Illegal Opcode %p: 66 %02X %02X %02X %02X %02X %02X\n",(void*)R_RIP, opcode, nextop, PK(2), PK(3), PK(4), PK(5));
emu->quit=1;
+12 -1
View File
@@ -788,7 +788,18 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr)
GX->q[0] ^= EX->q[0];
GX->q[1] ^= EX->q[1];
break;
case 0xF0: /* MOVBE Gw, Ew */
nextop = F8;
GETEX(0);
GETGX;
GX->uw[0] = __builtin_bswap16(EX->uw[0]);
break;
case 0xF1: /* MOVBE Ew, Gw */
nextop = F8;
GETEX(0);
GETGX;
EX->uw[0] = __builtin_bswap16(GX->uw[0]);
break;
default:
return 0;
}
+16 -16
View File
@@ -79,14 +79,14 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
}
} while(tmp32s);
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
cmp16(emu, R_AX, EW->word[0]);
if(ACCESS_FLAG(F_ZF)) {
EW->word[0] = GW->word[0];
} else {
R_AX = EW->word[0];
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -110,11 +110,11 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
}
GD->word[0] = tmp16u;
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
tmp16u = add16(emu, ED->word[0], GD->word[0]);
GD->word[0] = ED->word[0];
ED->word[0] = tmp16u;
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -148,22 +148,22 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
nextop = F8; \
GETEW(0); \
GETGW; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
EW->word[0] = OP##16(emu, EW->word[0], GW->word[0]); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+3: \
nextop = F8; \
GETEW(0); \
GETGW; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
GW->word[0] = OP##16(emu, GW->word[0], EW->word[0]); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+5: \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
R_AX = OP##16(emu, R_AX, F16); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break;
#endif
GO(0x00, add) /* ADD 0x00 -> 0x05 */
@@ -205,7 +205,7 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
case 7: cmp16(emu, ED->word[0], tmp16u); break;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
switch((nextop>>3)&7) {
case 0: ED->word[0] = add16(emu, ED->word[0], tmp16u); break;
case 1: ED->word[0] = or16(emu, ED->word[0], tmp16u); break;
@@ -216,7 +216,7 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
case 6: ED->word[0] = xor16(emu, ED->word[0], tmp16u); break;
case 7: cmp16(emu, ED->word[0], tmp16u); break;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -241,9 +241,9 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(native_lock_write_h(ED, inc16(emu, tmp16u)));
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
ED->word[0] = inc16(emu, ED->word[0]);
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 1: /* DEC Ed */
@@ -252,9 +252,9 @@ uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr)
tmp16u = native_lock_read_h(ED);
} while(native_lock_write_h(ED, dec16(emu, tmp16u)));
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
ED->word[0] = dec16(emu, ED->word[0]);
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
default:
+6 -2
View File
@@ -39,10 +39,14 @@ uintptr_t Run67(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
#ifdef TEST_INTERPRETER
x64emu_t* emu = test->emu;
#endif
opcode = F8;
if(rex.is32bits)
#ifdef TEST_INTERPRETER
return Test67_32(test, rex, rep, addr);
#else
return Run67_32(emu, rex, rep, addr);
#endif
opcode = F8;
while(opcode==0x67)
opcode = F8;
+19
View File
@@ -51,6 +51,19 @@ uintptr_t Run670F(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
switch(opcode) {
case 0x11:
switch(rep) {
case 0: /* MOVUPS Ex,Gx */
nextop = F8;
GETEX32(0);
GETGX;
EX->u128 = GX->u128;
break;
default:
return 0;
}
break;
case 0x2E:
// same for now
case 0x2F:
@@ -84,6 +97,12 @@ uintptr_t Run670F(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
GETGM;
GM->q = EM->q;
break;
case 2: /* MOVDQU Gx, Ex */
nextop = F8;
GETEX32(0);
GETGX;
memcpy(GX, EX, 16); // unaligned...
break;
default:
return 0;
}
+67
View File
@@ -0,0 +1,67 @@
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include "debug.h"
#include "box64stack.h"
#include "x64emu.h"
#include "x64run.h"
#include "x64emu_private.h"
#include "x64run_private.h"
#include "x64primop.h"
#include "x64trace.h"
#include "x87emu_private.h"
#include "box64context.h"
#include "bridge.h"
#include "modrm.h"
#ifdef TEST_INTERPRETER
uintptr_t Test6764_32(x64test_t *test, rex_t rex, int rep, int seg, uintptr_t addr)
#else
uintptr_t Run6764_32(x64emu_t *emu, rex_t rex, int rep, int seg, uintptr_t addr)
#endif
{
uint8_t opcode;
uint8_t nextop;
int8_t tmp8s;
uint8_t tmp8u;
uint32_t tmp32u;
int32_t tmp32s;
uint64_t tmp64u;
reg64_t *oped, *opgd;
#ifdef TEST_INTERPRETER
x64emu_t* emu = test->emu;
#endif
uintptr_t tlsdata = GetSegmentBaseEmu(emu, seg);
opcode = F8;
while(opcode==0x67)
opcode = F8;
rex.rex = 0;
while((opcode==0xF2) || (opcode==0xF3)) {
rep = opcode-0xF1;
opcode = F8;
}
switch(opcode) {
case 0x8B: /* MOV Gw, FS:Ew */
nextop = F8;
GETEW_OFFS_16(tlsdata);
GETGW;
GW->word[0] = EW->word[0];
break;
default:
return 0;
}
return addr;
}
+15
View File
@@ -52,6 +52,21 @@ uintptr_t Run67_32(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
switch(opcode) {
case 0x64: /* FS: prefix */
#ifdef TEST_INTERPRETER
return Test6764_32(test, rex, rep, _FS, addr);
#else
return Run6764_32(emu, rex, rep, _FS, addr);
#endif
break;
case 0x65: /* GS: prefix */
#ifdef TEST_INTERPRETER
return Test6764_32(test, rex, rep, _GS, addr);
#else
return Run6764_32(emu, rex, rep, _GS, addr);
#endif
break;
case 0xE0: /* LOOPNZ */
CHECK_FLAGS(emu);
tmp8s = F8S;
Executable → Regular
+24 -9
View File
@@ -53,9 +53,13 @@ int32_t EXPORT my___libc_start_main(x64emu_t* emu, int *(main) (int, char * *, c
SetRBP(emu, old_rbp);
emu->quit = 0;
} else {
RunElfInit(my_context->elfs[0], emu);
if(my_context->elfs[0]) {
RunElfInit(my_context->elfs[0], emu);
}
}
if(my_context->elfs[0]) {
MarkElfInitDone(my_context->elfs[0]);
}
MarkElfInitDone(my_context->elfs[0]);
printf_log(LOG_DEBUG, "Transfert to main(%d, %p, %p)=>%p from __libc_start_main\n", my_context->argc, my_context->argv, my_context->envv, main);
// call main and finish
Push64(emu, GetRBP(emu)); // set frame pointer
@@ -1094,14 +1098,25 @@ void PrintTrace(x64emu_t* emu, uintptr_t ip, int dynarec)
printf_log(LOG_NONE, " STACK_TOP: %p ", (void*)(uintptr_t)*(uint32_t*)(R_RSP));
} else if(peek==0xF3 && PK(1)==0x0F && PK(2)==0x1E && PK(3)==0xFA && !is32bits) {
printFunctionAddr(*(uintptr_t*)(R_RSP), " STACK_TOP: ");
} else if(peek==0xE8) { // Call
} else if(peek==0xE8 || peek==0xE9) { // Call & Jmp
uintptr_t nextaddr = ip + 5 + PK32(1);
printFunctionAddr(nextaddr, "=> ");
} else if(peek==0xFF) {
if(PK(1)==0x25) {
uintptr_t nextaddr = ip + 6 + PK32(2);
uintptr_t nextaddr = *(uintptr_t*)(ip + 6 + PK32(2));
if(!printFunctionAddr(nextaddr, "=> "))
printf_log(LOG_NONE, " => %p", (void*)nextaddr);
} else if((PK(1)==0x14) && (PK(2)==0x25)) {
uintptr_t nextaddr = *(uintptr_t*)(uintptr_t)PK32(3);
printf_log(LOG_NONE, " => %p", (void*)nextaddr);
printFunctionAddr(nextaddr, "=> ");
} else if((PK(1)==0x14) && (PK(2)==0xC2) && rex.rex==0x41) {
uintptr_t nextaddr = *(uintptr_t*)(R_R10 + R_RAX*8);
printf_log(LOG_NONE, " => %p", (void*)nextaddr);
printFunctionAddr(nextaddr, "=> ");
}
}
printf_log(LOG_NONE, "\n");
}
@@ -1185,7 +1200,7 @@ reg64_t* GetEw16_32(x64emu_t *emu, uintptr_t* addr, uint8_t m, uint32_t base)
case 7: base+= R_BX; break;
}
switch((m>>6)&3) {
case 0: if(m==6) base+= F16(addr); break;
case 0: if((m&7)==6) base= F16S(addr); break;
case 1: base += F8S(addr); break;
case 2: base += F16S(addr); break;
// case 3 is C0..C7, already dealt with
@@ -1538,7 +1553,7 @@ reg64_t* GetEw16(x64emu_t *emu, uintptr_t* addr, rex_t rex, uint8_t v)
case 7: base = R_BX; break;
}
switch((m>>6)&3) {
case 0: if(m==6) base = F16(addr); break;
case 0: if((m&7)==6) base = F16S(addr); break;
case 1: base += F8S(addr); break;
case 2: base += F16S(addr); break;
// case 3 is C0..C7, already dealt with
@@ -1568,7 +1583,7 @@ reg64_t* TestEw16(x64test_t *test, uintptr_t* addr, rex_t rex, uint8_t v)
case 7: base = R_BX; break;
}
switch((m>>6)&3) {
case 0: if(m==6) base = F16(addr); break;
case 0: if((m&7)==6) base = F16S(addr); break;
case 1: base += F8S(addr); break;
case 2: base += F16S(addr); break;
// case 3 is C0..C7, already dealt with
@@ -1600,7 +1615,7 @@ reg64_t* GetEw16off(x64emu_t *emu, uintptr_t* addr, rex_t rex, uint8_t v, uintpt
case 7: base = R_BX; break;
}
switch((m>>6)&3) {
case 0: if(m==6) base = F16(addr); break;
case 0: if((m&7)==6) base = F16S(addr); break;
case 1: base += F8S(addr); break;
case 2: base += F16S(addr); break;
// case 3 is C0..C7, already dealt with
@@ -1630,7 +1645,7 @@ reg64_t* TestEw16off(x64test_t *test, uintptr_t* addr, rex_t rex, uint8_t v, uin
case 7: base = R_BX; break;
}
switch((m>>6)&3) {
case 0: if(m==6) base = F16(addr); break;
case 0: if((m&7)==6) base = F16S(addr); break;
case 1: base += F8S(addr); break;
case 2: base += F16S(addr); break;
// case 3 is C0..C7, already dealt with
Executable → Regular
+2
View File
@@ -135,6 +135,7 @@ uintptr_t Run66DD(x64emu_t *emu, rex_t rex, uintptr_t addr);
uintptr_t Run66F0(x64emu_t *emu, rex_t rex, uintptr_t addr);
uintptr_t Run67(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr);
uintptr_t Run67_32(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr);
uintptr_t Run6764_32(x64emu_t *emu, rex_t rex, int rep, int seg, uintptr_t addr);
uintptr_t Run670F(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr);
uintptr_t Run6766(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr);
uintptr_t Run67660F(x64emu_t *emu, rex_t rex, uintptr_t addr);
@@ -160,6 +161,7 @@ uintptr_t Test66DD(x64test_t *test, rex_t rex, uintptr_t addr);
uintptr_t Test66F0(x64test_t *test, rex_t rex, uintptr_t addr);
uintptr_t Test67(x64test_t *test, rex_t rex, int rep, uintptr_t addr);
uintptr_t Test67_32(x64test_t *test, rex_t rex, int rep, uintptr_t addr);
uintptr_t Test6764_32(x64test_t *test, rex_t rex, int rep, int seg, uintptr_t addr);
uintptr_t Test670F(x64test_t *test, rex_t rex, int rep, uintptr_t addr);
uintptr_t Test6766(x64test_t *test, rex_t rex, int rep, uintptr_t addr);
uintptr_t Test67660F(x64test_t *test, rex_t rex, uintptr_t addr);
+50 -50
View File
@@ -116,15 +116,15 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
nextop = F8; \
GETEB(0); \
GETGB; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
EB->byte[0] = OP##8(emu, EB->byte[0], GB); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+1: \
nextop = F8; \
GETED(0); \
GETGD; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
if(rex.w) \
ED->q[0] = OP##64(emu, ED->q[0], GD->q[0]); \
else \
@@ -132,39 +132,39 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
ED->q[0] = OP##32(emu, ED->dword[0], GD->dword[0]); \
else \
ED->dword[0] = OP##32(emu, ED->dword[0], GD->dword[0]); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+2: \
nextop = F8; \
GETEB(0); \
GETGB; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
GB = OP##8(emu, GB, EB->byte[0]); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+3: \
nextop = F8; \
GETED(0); \
GETGD; \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
if(rex.w) \
GD->q[0] = OP##64(emu, GD->q[0], ED->q[0]); \
else \
GD->q[0] = OP##32(emu, GD->dword[0], ED->dword[0]); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+4: \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
R_AL = OP##8(emu, R_AL, F8); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break; \
case B+5: \
pthread_mutex_lock(&emu->context->mutex_lock); \
pthread_mutex_lock(&my_context->mutex_lock); \
if(rex.w) \
R_RAX = OP##64(emu, R_RAX, F32S64); \
else \
R_RAX = OP##32(emu, R_EAX, F32); \
pthread_mutex_unlock(&emu->context->mutex_lock); \
pthread_mutex_unlock(&my_context->mutex_lock); \
break;
#endif
GO(0x00, add) /* ADD 0x00 -> 0x05 */
@@ -245,7 +245,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(tmp32s);
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp8u&=63;
if(ED->q[0] & (1LL<<tmp8u))
@@ -265,7 +265,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
if(MODREG)
ED->dword[1] = 0;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -286,14 +286,14 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
}
} while(tmp32s);
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
cmp8(emu, R_AL, EB->byte[0]);
if(ACCESS_FLAG(F_ZF)) {
EB->byte[0] = GB;
} else {
R_AL = EB->byte[0];
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0xB1: /* CMPXCHG Ed,Gd */
@@ -343,7 +343,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
ED->dword[1] = 0;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
cmp64(emu, R_RAX, ED->q[0]);
if(ACCESS_FLAG(F_ZF)) {
@@ -362,7 +362,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
if(MODREG)
ED->dword[1] = 0;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -416,7 +416,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
ED->dword[1] = 0;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
if(ED->q[0] & (1<<tmp8u)) {
SET_FLAG(F_CF);
@@ -432,7 +432,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
if(MODREG)
ED->dword[1] = 0;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -490,7 +490,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(tmp32s);
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp8u&=63;
if(ED->q[0] & (1LL<<tmp8u)) {
@@ -508,7 +508,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
CLEAR_FLAG(F_CF);
}
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 6: /* BTR Ed, Ib */
@@ -544,7 +544,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(tmp32s);
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp8u&=63;
if(ED->q[0] & (1LL<<tmp8u)) {
@@ -560,7 +560,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} else
CLEAR_FLAG(F_CF);
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 7: /* BTC Ed, Ib */
@@ -592,7 +592,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(tmp32s);
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp8u&=63;
if(ED->q[0] & (1LL<<tmp8u))
@@ -608,7 +608,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
CLEAR_FLAG(F_CF);
ED->dword[0] ^= (1<<tmp8u);
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -628,11 +628,11 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
} while(native_lock_write_b(EB, tmp8u2));
GB = tmp8u;
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
tmp8u = add8(emu, EB->byte[0], GB);
GB = EB->byte[0];
EB->byte[0] = tmp8u;
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0xC1: /* XADD Gd,Ed */
@@ -665,7 +665,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
ED->dword[1] = 0;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp64u = add64(emu, ED->q[0], GD->q[0]);
GD->q[0] = ED->q[0];
@@ -678,7 +678,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
else
ED->dword[0] = tmp32u;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -717,7 +717,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
}
} while(tmp32s);
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
#ifdef TEST_INTERPRETER
test->memsize = 16;
@@ -749,7 +749,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
R_RDX = tmp32u2;
}
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
default:
@@ -785,7 +785,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
case 7: cmp8(emu, EB->byte[0], tmp8u); break;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
switch((nextop>>3)&7) {
case 0: EB->byte[0] = add8(emu, EB->byte[0], tmp8u); break;
case 1: EB->byte[0] = or8(emu, EB->byte[0], tmp8u); break;
@@ -796,7 +796,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
case 6: EB->byte[0] = xor8(emu, EB->byte[0], tmp8u); break;
case 7: cmp8(emu, EB->byte[0], tmp8u); break;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0x81: /* GRP Ed,Id */
@@ -845,7 +845,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
}
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
switch((nextop>>3)&7) {
case 0: ED->q[0] = add64(emu, ED->q[0], tmp64u); break;
@@ -881,7 +881,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
case 7: cmp32(emu, ED->dword[0], tmp64u); break;
}
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -904,12 +904,12 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
GETEB(0);
GETGB;
if(!MODREG)
pthread_mutex_lock(&emu->context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
pthread_mutex_lock(&my_context->mutex_lock); // XCHG always LOCK (but when accessing memory only)
tmp8u = GB;
GB = EB->byte[0];
EB->byte[0] = tmp8u;
if(!MODREG)
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 0x87: /* XCHG Ed,Gd */
@@ -937,7 +937,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
#else
GETED(0);
GETGD;
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
tmp64u = GD->q[0];
GD->q[0] = ED->q[0];
@@ -950,7 +950,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
else
ED->dword[0] = tmp32u;
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
@@ -966,9 +966,9 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
tmp8u2 = not8(emu, tmp8u2);
} while(native_lock_write_b(EB, tmp8u2));
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
EB->byte[0] = not8(emu, EB->byte[0]);
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
default:
@@ -986,9 +986,9 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
tmp8u = native_lock_read_b(ED);
} while(native_lock_write_b(ED, inc8(emu, tmp8u)));
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
ED->byte[0] = inc8(emu, ED->byte[0]);
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 1: /* DEC Ed */
@@ -997,9 +997,9 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
tmp8u = native_lock_read_b(ED);
} while(native_lock_write_b(ED, dec8(emu, tmp8u)));
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
ED->byte[0] = dec8(emu, ED->byte[0]);
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
default:
@@ -1047,7 +1047,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
if(MODREG) ED->dword[1] = 0;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
ED->q[0] = inc64(emu, ED->q[0]);
} else {
@@ -1056,7 +1056,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
else
ED->dword[0] = inc32(emu, ED->dword[0]);
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
case 1: /* DEC Ed */
@@ -1082,7 +1082,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
if(MODREG) ED->dword[1] = 0;
}
#else
pthread_mutex_lock(&emu->context->mutex_lock);
pthread_mutex_lock(&my_context->mutex_lock);
if(rex.w) {
ED->q[0] = dec64(emu, ED->q[0]);
} else {
@@ -1091,7 +1091,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
else
ED->dword[0] = dec32(emu, ED->dword[0]);
}
pthread_mutex_unlock(&emu->context->mutex_lock);
pthread_mutex_unlock(&my_context->mutex_lock);
#endif
break;
default:
Executable → Regular
+15
View File
@@ -62,6 +62,7 @@ int32_t my_epoll_pwait(x64emu_t* emu, int32_t epfd, void* events, int32_t maxeve
pid_t my_vfork(x64emu_t* emu);
#endif
int32_t my_fcntl(x64emu_t* emu, int32_t a, int32_t b, void* c);
int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]);
// cannot include <fcntl.h>, it conflict with some asm includes...
#ifndef O_NONBLOCK
@@ -136,6 +137,7 @@ static scwrap_t syscallwrap[] = {
{ 57, __NR_fork, 0 }, // should wrap this one, because of the struct pt_regs (the only arg)?
#endif
//{58, __NR_vfork, 0},
//{59, __NR_execve, 3},
{ 60, __NR_exit, 1}, // Nees wrapping?
{ 61, __NR_wait4, 4},
{ 62, __NR_kill, 2 },
@@ -181,9 +183,11 @@ static scwrap_t syscallwrap[] = {
{ 127, __NR_rt_sigpending, 2},
{ 128, __NR_rt_sigtimedwait, 4},
//{ 131, __NR_sigaltstack, 2}, // wrapped to use my_sigaltstack*
{ 140, __NR_getpriority, 2},
{ 155, __NR_pivot_root, 2},
{ 157, __NR_prctl, 5 }, // needs wrapping?
//{ 158, __NR_arch_prctl, 2}, //need wrapping
{ 160, __NR_setrlimit, 2},
{ 161, __NR_chroot, 1},
{ 186, __NR_gettid, 0 }, //0xBA
{ 200, __NR_tkill, 2 },
@@ -234,6 +238,7 @@ static scwrap_t syscallwrap[] = {
{ 264, __NR_renameat, 4},
#endif
{ 267, __NR_readlinkat, 4},
{ 268, __NR_fchmodat, 3},
{ 270, __NR_pselect6, 6},
{ 272, __NR_unshare, 1},
{ 273, __NR_set_robust_list, 2},
@@ -599,6 +604,14 @@ void EXPORT x64Syscall(x64emu_t *emu)
R_RAX = (uint64_t)-errno;
}
break;
case 59: // execve
{
int64_t r = my_execve(emu, (const char*)R_RDI, (char* const*)R_RSI, (char* const*)R_RDX);
R_RAX = r;
if(R_EAX==0xffffffff)
R_RAX = (uint64_t)-errno;
}
break;
case 63: //uname
{
old_utsname_t *old = (old_utsname_t*)R_RDI;
@@ -895,6 +908,8 @@ uintptr_t EXPORT my_syscall(x64emu_t *emu)
#endif
case 58: // vfork
return my_vfork(emu);
case 59: // execve
return my_execve(emu, (const char*)R_RSI, (char* const*)R_RDX, (char* const*)R_RCX);
case 63: //uname
{
old_utsname_t *old = (old_utsname_t*)R_RSI;
Executable → Regular
+15 -3
View File
@@ -130,9 +130,21 @@ uint32_t my_modify_ldt(x64emu_t* emu, int op, thread_area_t* td, int size)
}
static void* GetSeg43Base();
static const char* arch_prctl_param(int code)
{
static char ret[10] = {0};
switch (code) {
case 0x1001: return "ARCH_SET_GS";
case 0x1002: return "ARCH_SET_FS";
case 0x1003: return "ARCH_GET_FS";
case 0x1004: return "ARCH_GET_GS";
}
sprintf(ret, "0x%x", code);
return ret;
}
int my_arch_prctl(x64emu_t *emu, int code, void* addr)
{
printf_log(LOG_DEBUG, "%04d| arch_prctl(0x%x, %p) (RSP=%p, FS=0x%x, GS=0x%x)\n", GetTID(), code, addr,(void*)R_RSP, emu->segs[_FS], emu->segs[_GS]);
printf_log(LOG_DEBUG, "%04d| arch_prctl(%s, %p) (RSP=%p, FS=0x%x, GS=0x%x)\n", GetTID(), arch_prctl_param(code), addr,(void*)R_RSP, emu->segs[_FS], emu->segs[_GS]);
#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
@@ -152,12 +164,12 @@ int my_arch_prctl(x64emu_t *emu, int code, void* addr)
seg=(code==ARCH_SET_FS)?_FS:_GS;
int idx = -1;
// search if it's a TLS base
if(GetSeg43Base()==addr)
idx = 0x43>>3;
// Is this search only occurs when seg==0?
for (int i=9; i<15 && idx==-1; ++i)
if(my_context->segtls[i].present && my_context->segtls[i].base==(uintptr_t)addr)
idx=i;
if(idx==-1 && GetSeg43Base()==addr)
idx = 0x43>>3;
// found...
if(idx!=-1) {
printf_log(LOG_DEBUG, "Changing segment selector from 0x%x to 0x%x\n", emu->segs[seg], (idx<<3) +3);
Loaded 100 of 1042 files, more files were not shown because too many files have changed in this diff. Show more