- 论坛徽章:
- 0
|
想把一段代码放到特定的内存区,不想遇到 “字面常量”无法指定位置的问题。先看段代码吧:
__attribute__ ((section (".tcm.text")))
void My_printf(int id, const char* fmt, ...)
{
...
}
__attribute__ ((section (".tcm.text")))
void My_test(void)
{
My_printf("%s\n", "Hello");
}
ffff0040 <My_printf>:
ffff0040: e92d000e push {r1, r2, r3}
ffff0044: e92d4003 push {r0, r1, lr}
ffff0048: e59d000c ldr r0, [sp, #12]
ffff004c: e28d1010 add r1, sp, #16
ffff0050: e58d1004 str r1, [sp, #4]
ffff0054: eb000009 bl ffff0080 <__vprintf_veneer>
ffff0058: e8bd400c pop {r2, r3, lr}
ffff005c: e28dd00c add sp, sp, #12
ffff0060: e12fff1e bx lr
ffff0064 <My_test>:
ffff0064: e59f1008 ldr r1, [pc, #8] ; ffff0074 <My_test+0x10>
ffff0068: e59f2008 ldr r2, [pc, #8] ; ffff0078 <My_test+0x14>
ffff006c: e3a00c01 mov r0, #256 ; 0x100
ffff0070: eafffff2 b ffff0040 <My_printf>
ffff0074: 0404e886 .word 0x0404e886
ffff0078: 0404ec78 .word 0x0404ec78
ffff007c: 00000000 .word 0x00000000
My_printf()和My_test()这两个函数通过attribute section机制,代码被放到TCM区。
我的期望是,执行这两函数期间,取指、取数据都发生在TCM区。但是上面代码中的“字面常量”("%s\n", 和"Hello")却被放在了普通内存区,这就导致代码执行时取数据会去访问普通内存,与我的期望不符。
查了许多资料,没找到有没什么办法,能将字面常量指定位置,所以来这里求助大家了,望不吝赐教! |
|