各位大佬好,打扰了。最近在 zynq7020 上测试发现,在启用 libc posix 后,尝试使用 printf, 发现打印 int 参数会导致 undefined instruction. 请问可能是什么原因, 谢谢.
测试代码:
#include <stdio.h>
int test_libc(int argc, char **argv)
{
int i = 12;
printf("hello libc %d\n", i);
return 0;
}
MSH_CMD_EXPORT(test_libc, test libc);
结果:
msh />
msh />test_libc
undefined instruction:
Execption:
r00:0x0013e520 r01:0x0014a02c r02:0x00137378 r03:0x0014b95c
r04:0x0014b95c r05:0xdeadbeef r06:0xdeadbeef r07:0xdeadbeef
r08:0xdeadbeef r09:0xdeadbeef r10:0xdeadbeef
fp :0x0014b97c ip :0x0014a77e
sp :0x0014b924 lr :0x00132609 pc :0x00133388
cpsr:0x20000033
thread pri status sp stack size max used left tick error
tshell 20 running 0x00000184 0x00001000 09% 0x00000009 000
ulog_async 30 suspend 0x000000ac 0x00000400 25% 0x00000013 000
tidle0 31 ready 0x00000060 0x00000200 22% 0x00000004 000
main 10 suspend 0x000000bc 0x00000800 28% 0x00000011 000
shutdown...
(0) assertion failed at function:rt_hw_cpu_shutdown, line number:85
根据 pc objdup 定位到的代码
00133380 <_vfprintf_r>:
133380: e92d 4ff0 stmdb sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
133384: 461c mov r4, r3
133386: ed2d 8b04 vpush {d8-d9}
13338a: 4688 mov r8, r1
13338c: 4693 mov fp, r2
13338e: 4605 mov r5, r0
133390: b0bd sub sp, #244 ; 0xf4
133392: 9005 str r0, [sp, #20]
编译参数
DEVICE = ' -Wall -mcpu=cortex-a9 -mfpu=vfpv3 -ffunction-sections -fdata-sections -ftree-vectorize -munaligned-access -ffast-math -mfloat-abi=hard'
CFLAGS = DEVICE
AFLAGS = ' -c -fmessage-length=0' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__ -I. '
LINK_SCRIPT = 'lscript.ld'
LFLAGS = DEVICE + ' -Wl,-Map=zynq7000.map,--gc-sections,-build-id=none -specs=Xilinx.spec -Wl,-T -Wl,%s' % LINK_SCRIPT
更多回帖