Signed Register Functions
afrocheese opened this issue · comments
Charles commented
git clone --depth=50 https://github.com/lunixbochs/usercorn.git usercorn
cd usercorn
git fetch origin +refs/pull/311/merge
git checkout -f FETCH_HEAD
make deps
make
$ ./usercorn run -repl bins/x86_64.darwin.macho
0x100002426> rax = -1
0x100002426> rax
0xffffffffffffffff
0x100002426> rax = 0xffffffffffffffff
could not restore rax: bad type: NaN
This occurs on all architectures that I have tested and also occurs using u.reg_write
.
Ryan Hileman commented
I added int64 types to luaish but the parser probably needs to be modified to autopromote large constants.
Ryan Hileman commented
Ryan Hileman commented
Oh! parseNumber just needs to try parsing unsigned as well to handle the > int64 <= uint64 range
Ryan Hileman commented
Fixed in lunixbochs/luaish@50b0cd6:
~/projects/luaish] ./glua
GopherLua 0.1 Copyright (C) 2015 Yusuke Inuzuka
> rax = 0.1
> print(rax)
0.1
> rax = 0xfffffffffffffff
> print(rax)
1152921504606846975
> rax = 0xffffffffffffffff
> print(rax)
-1
> rax = 0xfffffffffffffffff
> print(rax)
NaN
Run make get
to update the luaish dependency.
Charles commented
Thanks for the quick turn around! The only slightly surprising behavior that I've noticed is writing a NaN number with u.reg_write
, but I think it might be unrelated.
0x0> x0
0
0x0> u.reg_write(arm64.x0, 0xfffffffffffffffff)
0x0> x0
0x8000000000000000
Ryan Hileman commented
Huh, what happens if you set a register to like 1.5? Maybe floats shouldn’t be allowed there.
Charles commented
0x0> x0 = 1.5
could not restore x0: bad type: 1.5
0x0> u.reg_write(arm64.x0, 1.999999)
0x0> x0
1
0x0> u.reg_write(arm64.x0, -0.999999)
0x0> x0
0
0x0> u.reg_write(arm64.x0, -1.999999)
0x0> x0
0xffffffffffffffff
0x0> u.reg_write(arm64.x0, -5.999999)
0x0> x0
0xfffffffffffffffb
seems to more or less make sense how it handles floats