3

我正在开发一个加密和解密应用程序。我使用 bignum 算法。那就是 polarSSL。在Xcode模拟器中,它运行良好并且可以成功解密文件。但是当我在真实设备(iPad 4)上运行相同的项目时,它崩溃了。

所以我调试它,我找到了原因。在模拟器中,它执行以下代码:

 #if defined(__i386__)
#define MULADDC_INIT                            \
    asm( "movl   %0, %%esi      " :: "m" (s));  \
    asm( "movl   %0, %%edi      " :: "m" (d));  \
    asm( "movl   %0, %%ecx      " :: "m" (c));  \
    asm( "movl   %0, %%ebx      " :: "m" (b));

#define MULADDC_CORE                            \
    asm( "lodsl                 " );            \
    asm( "mull   %ebx           " );            \
    asm( "addl   %ecx,   %eax   " );            \
    asm( "adcl   $0,     %edx   " );            \
    asm( "addl   (%edi), %eax   " );            \
    asm( "adcl   $0,     %edx   " );            \
    asm( "movl   %edx,   %ecx   " );            \
    asm( "stosl                 " );

#define MULADDC_STOP                            \
    asm( "movl   %%ecx, %0      " :: "m" (c));  \
    asm( "movl   %%edi, %0      " :: "m" (d));  \
    asm( "movl   %%esi, %0      " :: "m" (s) :  \
    "eax", "ecx", "edx", "ebx", "esi", "edi" );

while in iPad4, it execute the following code:
#if defined(__arm__)

#define MULADDC_INIT                            \
    asm( "ldr    r0, %0         " :: "m" (s));  \
    asm( "ldr    r1, %0         " :: "m" (d));  \
    asm( "ldr    r2, %0         " :: "m" (c));  \
    asm( "ldr    r3, %0         " :: "m" (b));

#define MULADDC_CORE                            \
    asm( "ldr    r4, [r0], #4   " );            \
    asm( "mov    r5, #0         " );            \
    asm( "ldr    r6, [r1]       " );            \
    asm( "umlal  r2, r5, r3, r4 " );            \
    asm( "adds   r7, r6, r2     " );            \
    asm( "adc    r2, r5, #0     " );            \
    asm( "str    r7, [r1], #4   " );

#define MULADDC_STOP                            \
    asm( "str    r2, %0         " :: "m" (c));  \
    asm( "str    r1, %0         " :: "m" (d));  \
    asm( "str    r0, %0         " :: "m" (s) :  \
    "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" );

原因很清楚,设备的cpu是ARM架构,模拟器是i386。但是i386代码可以成功执行,而arm失败让我很困惑。这些asm代码来自polarSSL,是用标准arm指令编写的。所以我认为Apple Inc是否改变CPU架构,众所周知,iPad 4的cpu是Apple设计的A6X。所以我不知道如何解决这个问题。希望有人能帮助我。非常感谢

4

1 回答 1

0

根据您提供的代码,您使用的是旧版本的库!

如果您检查“当前” bn_mul.h,您将看到语句已更改为“单个” asm 语句(编译器优化所必需的)..

请尝试新的并报告:)

于 2014-01-07T09:58:57.667 回答