Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AARCH64 demo #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add AARCH64 demo #17

wants to merge 3 commits into from

Conversation

bitterbit
Copy link

Arm64 demo like mentioned issue #15 😺

@AlexAltea
Copy link
Owner

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.

return e.reg_read_i64(uc.ARM64_REG_PC);
}
function pcWrite(value) {
return e.reg_write_i64(uc.ARM64_REG_PC, value);
Copy link
Owner

@AlexAltea AlexAltea Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails when value >= (1 << 52), we need to add another method:

this.reg_write_i64    = function (regid, value_lo, value_hi) { /* ... */ }

in: https://github.com/AlexAltea/unicorn.js/blob/dd2972c/src/unicorn-wrapper.js#L359

@@ -89,6 +89,7 @@ function Register(name, type, id) {
case 'i8': this.dataHex = utilIntToHex(value, 2); break;
case 'i16': this.dataHex = utilIntToHex(value, 4); break;
case 'i32': this.dataHex = utilIntToHex(value, 8); break;
case 'i64': this.dataHex = utilIntToHex(value, 16); break;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails when value >= (1 << 52). Additionally, note that utilIntToHex forces unsignedness via:

    if (n < 0) {
        n += Math.pow(2, 32);
    }

This works only in integers up to 32 bits in size, but not beyond that. The signature of utilIntToHex needs to be changed and add support for value_lo and value_hi.

@@ -104,6 +105,7 @@ function Register(name, type, id) {
case 'i8':
case 'i16':
case 'i32':
case 'i64':
Copy link
Owner

@AlexAltea AlexAltea Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this._update_int refreshes only (up to) 32-bit integers via:

        var value = e.reg_read_i32(this.id);

This will fail at updating the upper 32 bits of 64-bit registers.

@AlexAltea
Copy link
Owner

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
Copy link
Author

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

@bitterbit
Copy link
Author

bitterbit commented Sep 19, 2019

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
Copy link
Owner

@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
Copy link

itszn commented Apr 3, 2020

I have this same error on ubuntu 18.04

@asahilina
Copy link
Contributor

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
Copy link
Owner

AlexAltea commented Oct 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants