昨天提到,libtask中的asm.S使用的是ARM 32位的语法,因此在ARM 64下无法编译通过。
于是查了一下资料,改写了一下汇编代码,使得可以在64位下编译通过。源码如下
#if defined(__linux__) && defined(__arm__)
.globl getmcontext
getmcontext:
str r1, [r0,#4]
str r2, [r0,#8]
str r3, [r0,#12]
str r4, [r0,#16]
str r5, [r0,#20]
str r6, [r0,#24]
str r7, [r0,#28]
str r8, [r0,#32]
str r9, [r0,#36]
str r10, [r0,#40]
str r11, [r0,#44]
str r12, [r0,#48]
str r13, [r0,#52]
str r14, [r0,#56]
/* store 1 as r0-to-restore */
mov r1, #1
str r1, [r0]
/* return 0 */
mov r0, #0
mov pc, lr
.globl setmcontext
setmcontext:
ldr r1, [r0,#4]
ldr r2, [r0,#8]
ldr r3, [r0,#12]
ldr r4, [r0,#16]
ldr r5, [r0,#20]
ldr r6, [r0,#24]
ldr r7, [r0,#28]
ldr r8, [r0,#32]
ldr r9, [r0,#36]
ldr r10, [r0,#40]
ldr r11, [r0,#44]
ldr r12, [r0,#48]
ldr r13, [r0,#52]
ldr r14, [r0,#56]
ldr r0, [r0]
mov pc, lr
#elif defined(__linux__) && (defined(__arm64__) || defined(__aarch64__))
.globl getmcontext
getmcontext:
str x1, [x0,#4]
str x2, [x0,#8]
str x3, [x0,#12]
str x4, [x0,#16]
str x5, [x0,#20]
str x6, [x0,#24]
str x7, [x0,#28]
str x8, [x0,#32]
str x9, [x0,#36]
str x10, [x0,#40]
str x11, [x0,#44]
str x12, [x0,#48]
str x13, [x0,#52]
str x14, [x0,#56]
/* store 1 as r0-to-restore */
mov x1, #1
str x1, [x0]
/* return 0 */
mov x0, #0
/*mov pc, lr */
/*PC寄存器, Program Counter, 记录当前执行的代码的地址. 它是一个隐含的寄存器, 无法被直接访问, 只能被特定的指令隐含访问.*/
.globl setmcontext
setmcontext:
ldr x1, [x0,#4]
ldr x2, [x0,#8]
ldr x3, [x0,#12]
ldr x4, [x0,#16]
ldr x5, [x0,#20]
ldr x6, [x0,#24]
ldr x7, [x0,#28]
ldr x8, [x0,#32]
ldr x9, [x0,#36]
ldr x10, [x0,#40]
ldr x11, [x0,#44]
ldr x12, [x0,#48]
ldr x13, [x0,#52]
ldr x14, [x0,#56]
ldr x0, [x0]
/*mov pc, lr*/
#else
#error unknown platform
#endif
结论是:
【记录一个问题】用毫无用处的方法解决了libtask的asm.S在ndk下编译的问题
原文:https://www.cnblogs.com/ahfuzhang/p/11290509.html