ARM __moddi3

When I was debugging an app on iPhone 4 (armv7), I found a function call:

Since ARM does not have Division/Modulo operators, compilers use other ways making your code work on devices like iPhone.

I followed the __moddi3 on iPhone 4, the moddi3() is provided by llvm’s compiler-rt (lib/builtins/moddi3.c).

Parameters a and b are 64-bit long and returned value is also 64-bit.

But in ARMv7, registers are 32-bit long. I’m trying to find out which registers are used.

I wrote a simple C file and compile to armv7 and x86_64

Compile to x86_64

Disassembe x86_64

x86_64 uses idivq, in this program:

Compile to armv7

Disassemble armv7

In armv7:

If both dividend and divisor are less than 0x100000000.

$r2 may be negative, like 0xfffffff3. ($r3 == 0).

means $r0 – $r2 == divisor

If signed integer $r2 is smaller than 0x80000000,
((long long) $r1 << 32 | $r0) - ((long long ) $r3 << 32 | $r2) == divisor.

ARM __moddi3 by @sskaje:

Virtualized ARM on Ubuntu

I was finding articles/wikis how to emulate an arm linux (armel) on centos/ubuntu, then I found this from MDN:

This article uses an old release by linaro which based on Ubuntu natty that can no longer be found on
As Ubuntu says, armel would not be supported, that’s why the latest code name of ubuntu supporting armel is begin with ‘Q’.

I found another server release and a new nano, tried that with similar commands, notes are below:

Continue reading “Virtualized ARM on Ubuntu” »

Virtualized ARM on Ubuntu by @sskaje:

Incoming search terms: