AlexAltea / unicorn.js

Unicorn CPU emulator framework port for JavaScript
https://alexaltea.github.io/unicorn.js/
GNU General Public License v2.0
566 stars 36 forks source link

Add AARCH64 demo #17

Open bitterbit opened 4 years ago

bitterbit commented 4 years ago

Arm64 demo like mentioned issue #15 😺

AlexAltea commented 4 years ago

Thanks for your contribution!

JavaScript doesn't support 64-bit integers natively. Upper limit is 52-bit, and consequently heavy changes to src/unicorn-wrapper.js are needed. Many functions that receive (up to) 64-bit integers as arguments need to provide an explicit _i64 version where such arguments are split in two 32-bit "high" and "low" integers.

Below, I'll point several places where this could cause trouble in your patch.

AlexAltea commented 4 years ago

That said, I don't mind if we merge this patch, as long as the code mentions these limitations in the form of comments and we place a disclaimer/alert message when entering the demo.

bitterbit commented 4 years ago

Cool, I had the feeling I was missing something. I'll look into it

bitterbit commented 4 years ago

Im having a hard time trying to compile unicorn into the dist packages. I managed to compile a sample c application using emscripten (with a makefile) but when trying to compile unicorn it fails on cd qemu && ./configure...

@AlexAltea do you have any idea what am I missing?

running grunt build results in the error

ty test_tb_x86 test_x86 test_x86_rip_bug test_x86_shl_enter_leave test_x86_soft_paging
>> make: ['make']
cd qemu && \
        ./configure --cc="/Users/galtashma/dev/emsdk/fastcomp/emscripten/emcc" --extra-cflags="-DUNICORN_HAS_X86 -DUNICORN_HAS_ARM -DUNICORN_HAS_ARMEB -DUNICORN_HAS_M68K -DUNICORN_HAS_ARM64 -DUNICORN_HAS_MIPS -DUNICORN_HAS_MIPSEL -DUNICORN_HAS_MIPS64 -DUNICORN_HAS_MIPS64EL -DUNICORN_HAS_SPARC -fPIC -fvisibility=hidden -m32 -arch i386 -m64 -arch x86_64" --target-list="x86_64-softmmu, arm-softmmu, armeb-softmmu, m68k-softmmu, aarch64-softmmu, mips-softmmu, mipsel-softmmu, mips64-softmmu, mips64el-softmmu, sparc-softmmu,sparc64-softmmu," --disable-debug-info

ERROR: "/Users/galtashma/dev/emsdk/fastcomp/emscripten/emcc" either does not exist or does not work

>> make: * [qemu/config-host.h-timestamp] Error 1
>> shared:ERROR: unicorn/libunicorn.a: No such file or directory ("unicorn/libunicorn.a" was expected to be an input file, based on the commandline arguments provided)

For some reason this configure does not work , here is a detailed error:

qemu❯ VERBOSE=1 EMCC_DEBUG=1 emconfigure ./configure --extra-cflags="-DUNICORN_HAS_ARM64 -fPIC -fvisibility=hidden" --target-list="aarch64-softmmu," --disable-debug-info
shared:DEBUG: python versions older than 2.7.12 are known to run into outdated SSL certificate related issues, https://github.com/emscripten-core/emscripten/issues/6275
shared:DEBUG: EM_CONFIG is located in /Users/galtashma/.emscripten
cache:DEBUG: PID 60293 acquiring multiprocess file lock to Emscripten cache at /Users/galtashma/.emscripten_cache
cache:DEBUG: done
cache:DEBUG: PID 60293 released multiprocess file lock to Emscripten cache at /Users/galtashma/.emscripten_cache
shared:DEBUG: check tells us to use asm.js backend

ERROR: "/Users/galtashma/dev/emsdk/fastcomp/emscripten/emcc" either does not exist or does not work

Note that /Users/galtashma/dev/emsdk/fastcomp/emscripten/emcc exists and is functional. P.s. I am running on macos.

AlexAltea commented 4 years ago

@bitterbit It's quite possible that some regression happened in Emscripten (quite commonplace, unfortunately). I'm a bit busy this week, but I'll check what's wrong in my macOS machine next Monday/Tuesday and let you know.

itszn commented 4 years ago

I have this same error on ubuntu 18.04

asahilina commented 9 months ago

Just thought I'd drop by and mention I got unicorn.js to work with real ARM64 code using very large 64-bit PC addresses and register values. PR #46 has some needed changes, and here is the code where I used it. Maybe that demo is useful as an example of how to get everything 64-bit clean and working?

AlexAltea commented 9 months ago

Just thought I'd drop by and mention I got unicorn.js to work with real ARM64 code using very large 64-bit PC addresses and register values. PR #46 has some needed changes, and here is the code where I used it. Maybe that demo is useful as an example of how to get everything 64-bit clean and working?

This is incredible, thank you very much for sharing it and for your PR. I hope it can be useful to others.

@bitterbit If you have time and are interested, try rebasing your PR on top of @asahilina's latest changes (merged now). If it works, I would be glad to merge it.