我正在使用没有 FPU 的 MIPS 24k 内核。我已经成功交叉编译了 QT,它工作正常。但有时当它触及 qatomic_mips.h 中定义的 QBasicAtomicInt::testAndSetAcquire() 时,我得到一个 SIGSEGV。
代码主体具有内联汇编语言。这是我第一次使用它。因此,当我一开始试图找到故障行时,它指向最后一行,其中提到了被破坏的寄存器列表。
后来当我采取另一种方法时,它似乎在下面突出显示的行中失败了。知道 _q_value 是什么意思吗?
inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
{
register int result;
register int tempValue;
asm volatile(".set push\n"
SET_MIPS2
"0:\n"
"ll %[result], %[_q_value]\n" //this line causes the SIGSEGV
"xor %[result], %[result], %[expectedValue]\n"
"bnez %[result], 0f\n"
"nop\n"
"move %[tempValue], %[newValue]\n"
"sc %[tempValue], %[_q_value]\n"
"beqz %[tempValue], 0b\n"
"nop\n"
"sync\n"
"0:\n"
".set pop\n"
: [result] "=&r" (result),
[tempValue] "=&r" (tempValue),
[_q_value] "+m" (_q_value)
: [expectedValue] "r" (expectedValue),
[newValue] "r" (newValue)
: "cc", "memory");
return result == 0;
}
拆卸:
00207478 <_ZN20QEventDispatcherUNIX6wakeUpEv>:
207478: 3c1c001a lui gp,0x1a
20747c: 279c99f8 addiu gp,gp,-26120
207480: 0399e021 addu gp,gp,t9
207484: 27bdffc8 addiu sp,sp,-56
207488: afbf0030 sw ra,48(sp)
20748c: afb3002c sw s3,44(sp)
207490: afb20028 sw s2,40(sp)
207494: afb10024 sw s1,36(sp)
207498: afb00020 sw s0,32(sp)
20749c: afbc0010 sw gp,16(sp)
2074a0: 8c860004 lw a2,4(a0)
2074a4: 00001821 move v1,zero
2074a8: 24020001 li v0,1
2074ac: c0c40768 ll a0,1896(a2) //this is the exact line
2074b0: 00832026 xor a0,a0,v1
2074b4: 14800008 bnez a0,2074d8 <_ZN20QEventDispatcherUNIX6wakeUpEv+0x60>
2074b8: 00000000 nop
2074bc: 00000000 nop
2074c0: 00402821 move a1,v0
2074c4: e0c50768 sc a1,1896(a2)
2074c8: 10a0fff8 beqz a1,2074ac <_ZN20QEventDispatcherUNIX6wakeUpEv+0x34>
2074cc: 00000000 nop
2074d0: 00000000 nop
2074d4: 0000000f sync
2074d8: 14800012 bnez a0,207524 <_ZN20QEventDispatcherUNIX6wakeUpEv+0xac>
2074dc: 27b30018 addiu s3,sp,24
2074e0: a3a00018 sb zero,24(sp)
2074e4: 8cd00058 lw s0,88(a2)
2074e8: 2412ffff li s2,-1
2074ec: 24110004 li s1,4
2074f0: 8f99cef0 lw t9,-12560(gp)
2074f4: 02002021 move a0,s0
2074f8: 02602821 move a1,s3
2074fc: 0320f809 jalr t9
207500: 24060001 li a2,1
207504: 8fbc0010 lw gp,16(sp)
207508: 14520006 bne v0,s2,207524 <_ZN20QEventDispatcherUNIX6wakeUpEv+0xac>
20750c: 8f99c864 lw t9,-14236(gp)
207510: 0320f809 jalr t9
207514: 00000000 nop
207518: 8c430000 lw v1,0(v0)
20751c: 1071fff4 beq v1,s1,2074f0 <_ZN20QEventDispatcherUNIX6wakeUpEv+0x78>
207520: 8fbc0010 lw gp,16(sp)
207524: 8fbf0030 lw ra,48(sp)
207528: 8fb3002c lw s3,44(sp)
20752c: 8fb20028 lw s2,40(sp)
207530: 8fb10024 lw s1,36(sp)
207534: 8fb00020 lw s0,32(sp)
207538: 03e00008 jr ra
20753c: 27bd0038 addiu sp,sp,56