实例详解——编译器命令#pragma section作用于函数时作用域是否覆盖到其子函数
在之前的博客【链接脚本(Linker Script)应用实例(一)使用copy table将函数载入到RAM中运行】中,我们第一步使用#pragma section命令将PFlashProgram函数存储至程序段.flash_driver,具体程序如下:
#pragma section ".flash_driver" ax void PFlashProgram( uint32 flash, uint32 addr, uint32 word_l, uint32 word_u ) { uint32 load_cnt; uint16 endinitSfty_pw = IfxScuWdt_getSafetyWatchdogPasswordInline(); IfxFlash_enterPageMode(addr); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); /* write 32 bytes (8 doublewords) into assembly buffer */ ; load_cnt < ; load_cnt++) { IfxFlash_loadPage2X32(addr, word_l, word_u); } /* write page */ IfxScuWdt_clearSafetyEndinitInline(endinitSfty_pw); IfxFlash_writePage(addr); IfxScuWdt_setSafetyEndinitInline(endinitSfty_pw); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); } #pragma section
编译之后的map文件如下,可以看到PFlashProgram函数生成的程序段大小为280字节。下面对函数的内容进行调整后重新编译,以验证将PFlashProgram函数存储到.flash_driver程序段时是否同时也将IfxFlash_enterPageMode、IfxFlash_waitUnbusy及IfxFlash_loadPage2X32等子函数同时存储到该段。这个问题之所以值得关注,是因为若不将其子函数也存储到该段,子函数将默认存储在ROM(Flash)中,那么PFlashProgram函数执行到其子函数时将从Flash而不是RAM中取指令。由于TC297不支持Flash操作函数对其所在的Flash进行擦写(Flash大多都具有这种特性)(Flash操作函数必须在RAM中或另一个Flash Bank中运行从而执行擦写操作),PFlashProgram函数无法成功执行对PFlash的写入操作。另外,了解#pragma section命令的这个特性也有助于程序员对代码存储与执行情况的掌握。
Linker version: GNU ld version (GNU Binutils) 2.20 (TriCore) using BFD version (GNU Binutils) 2.20 (v2.3), Tool Version v2.7 Name of linker executable: c:/hightec/toolchains/tricore/v4.9.1.0-infineon-2.0/bin/../lib/gcc/tricore/4.9.4/../../../../tricore/bin/ld.exe Date of link run: Thu Sep 05 10:42:28 2019 Name of linker map file: Flash_test.map >>> Symbols (global (S = g) and static (S = l); sorted by address) ============================================================================================================================================================ Start End Size S Name Memory O-Sec I-Sec Input object ============================================================================================================================================================ g __TRICORE_DERIVATE_MEMORY_MAP__ *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK0_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK1_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK2_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_HEAP_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_USTACK0_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_USTACK1_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_USTACK2_SIZE *ABS* *ABS* *ABS* *ABS* ...................... g __TRAPTAB_CPU2 pfls0 .traptab_tc2 .traptab_tc2 Flash_test.elf g IfxCpu_Trap_vectorTable1 pfls0 .traptab_tc1 .traptab_cpu1 0_Src\4_McHal\Tricore\Cpu\Trap\IfxCpu_Trap.o g LCF_TRAPVEC1_START *ABS* *ABS* *ABS* *ABS* g __TRAPTAB_CPU1 pfls0 .traptab_tc1 .traptab_tc1 Flash_test.elf g _SMALL_DATA4_ *ABS* *ABS* *ABS* *ABS* g __A9_MEM *ABS* *ABS* *ABS* *ABS* g PFlashProgram psram_local .code2ram .flash_driver 0_Src\0_AppSw\Tricore\Demo_Illd\FlashDemo.o
(1)首先注释掉与Flash操作相关的5个子函数,然后重新编译,查看map文件。可见PFlashProgram函数产生的程序段大小变为136字节,这是否说明这5个Flash操作函数对应的程序段大小为144(280-136)字节呢?我们继续进行测试
#pragma section ".flash_driver" ax void PFlashProgram( uint32 flash, uint32 addr, uint32 word_l, uint32 word_u ) { uint32 load_cnt; uint16 endinitSfty_pw = IfxScuWdt_getSafetyWatchdogPasswordInline(); // IfxFlash_enterPageMode(addr); /* wait until unbusy */ // IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); /* write 32 bytes (8 doublewords) into assembly buffer */ ; load_cnt < ; load_cnt++) { // IfxFlash_loadPage2X32(addr, word_l, word_u); } /* write page */ IfxScuWdt_clearSafetyEndinitInline(endinitSfty_pw); // IfxFlash_writePage(addr); IfxScuWdt_setSafetyEndinitInline(endinitSfty_pw); /* wait until unbusy */ // IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); } #pragma section
Linker version: GNU ld version (GNU Binutils) 2.20 (TriCore) using BFD version (GNU Binutils) 2.20 (v2.3), Tool Version v2.7 Name of linker executable: c:/hightec/toolchains/tricore/v4.9.1.0-infineon-2.0/bin/../lib/gcc/tricore/4.9.4/../../../../tricore/bin/ld.exe Date of link run: Thu Sep 05 18:34:08 2019 Name of linker map file: Flash_test.map >>> Symbols (global (S = g) and static (S = l); sorted by address) ============================================================================================================================================================ Start End Size S Name Memory O-Sec I-Sec Input object ============================================================================================================================================================ g __TRICORE_DERIVATE_MEMORY_MAP__ *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK0_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK1_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK2_SIZE *ABS* *ABS* *ABS* *ABS* .......... g __TRAPTAB_CPU1 pfls0 .traptab_tc1 .traptab_tc1 Flash_test.elf g _SMALL_DATA4_ *ABS* *ABS* *ABS* *ABS* g __A9_MEM *ABS* *ABS* *ABS* *ABS* g PFlashProgram psram_local .code2ram .flash_driver 0_Src\0_AppSw\Tricore\Demo_Illd\FlashDemo.o
现在,我们注释掉5个Flash操作函数以外的代码,map文件如下。可以看到PFlashProgram的大小变为146字节而不是之前推测的144字节。为什么多出2字节呢?我们接下来将整个函数体内部的语句全部注释掉试试,看看函数的“框架”占用多大空间。
#pragma section ".flash_driver" ax void PFlashProgram( uint32 flash, uint32 addr, uint32 word_l, uint32 word_u ) { // uint32 load_cnt; // uint16 endinitSfty_pw = IfxScuWdt_getSafetyWatchdogPasswordInline(); IfxFlash_enterPageMode(addr); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); /* write 32 bytes (8 doublewords) into assembly buffer */ // for (load_cnt = 0; load_cnt < 4; load_cnt++) // { IfxFlash_loadPage2X32(addr, word_l, word_u); // } /* write page */ // IfxScuWdt_clearSafetyEndinitInline(endinitSfty_pw); IfxFlash_writePage(addr); // IfxScuWdt_setSafetyEndinitInline(endinitSfty_pw); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); } #pragma section
Linker version: GNU ld version (GNU Binutils) 2.20 (TriCore) using BFD version (GNU Binutils) 2.20 (v2.3), Tool Version v2.7 Name of linker executable: c:/hightec/toolchains/tricore/v4.9.1.0-infineon-2.0/bin/../lib/gcc/tricore/4.9.4/../../../../tricore/bin/ld.exe Date of link run: Thu Sep 05 18:45:58 2019 Name of linker map file: Flash_test.map >>> Symbols (global (S = g) and static (S = l); sorted by address) ============================================================================================================================================================ Start End Size S Name Memory O-Sec I-Sec Input object ============================================================================================================================================================ g __TRICORE_DERIVATE_MEMORY_MAP__ *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK0_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK1_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK2_SIZE *ABS* *ABS* *ABS* *ABS* .......... g __TRAPTAB_CPU1 pfls0 .traptab_tc1 .traptab_tc1 Flash_test.elf g _SMALL_DATA4_ *ABS* *ABS* *ABS* *ABS* g __A9_MEM *ABS* *ABS* *ABS* *ABS* g PFlashProgram psram_local .code2ram .flash_driver 0_Src\0_AppSw\Tricore\Demo_Illd\FlashDemo.o
由map文件可以看到,这个空的函数大小为2字节。到这里我们知道函数总大小为280字节,其中函数“框架”占2字节,5个Flash操作函数占144字节,其他语句和函数占134字节。
到此,我们可以得出本篇博文最重要的结论:#pragma section命令将一个函数存储到程序段时,会将其调用的子函数也一起存储到该段中。
#pragma section ".flash_driver" ax void PFlashProgram( uint32 flash, uint32 addr, uint32 word_l, uint32 word_u ) { // uint32 load_cnt; // uint16 endinitSfty_pw = IfxScuWdt_getSafetyWatchdogPasswordInline(); // IfxFlash_enterPageMode(addr); /* wait until unbusy */ // IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); /* write 32 bytes (8 doublewords) into assembly buffer */ // for (load_cnt = 0; load_cnt < 4; load_cnt++) // { // IfxFlash_loadPage2X32(addr, word_l, word_u); // } /* write page */ // IfxScuWdt_clearSafetyEndinitInline(endinitSfty_pw); // IfxFlash_writePage(addr); // IfxScuWdt_setSafetyEndinitInline(endinitSfty_pw); /* wait until unbusy */ // IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); } #pragma section
Linker version: GNU ld version (GNU Binutils) 2.20 (TriCore) using BFD version (GNU Binutils) 2.20 (v2.3), Tool Version v2.7 Name of linker executable: c:/hightec/toolchains/tricore/v4.9.1.0-infineon-2.0/bin/../lib/gcc/tricore/4.9.4/../../../../tricore/bin/ld.exe Date of link run: Thu Sep 05 18:52:56 2019 Name of linker map file: Flash_test.map >>> Symbols (global (S = g) and static (S = l); sorted by address) ============================================================================================================================================================ Start End Size S Name Memory O-Sec I-Sec Input object ============================================================================================================================================================ g __TRICORE_DERIVATE_MEMORY_MAP__ *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK0_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK1_SIZE *ABS* *ABS* *ABS* *ABS* g LCF_ISTACK2_SIZE *ABS* *ABS* *ABS* *ABS* .......... g __TRAPTAB_CPU1 pfls0 .traptab_tc1 .traptab_tc1 Flash_test.elf g _SMALL_DATA4_ *ABS* *ABS* *ABS* *ABS* g __A9_MEM *ABS* *ABS* *ABS* *ABS* g PFlashProgram psram_local .code2ram .flash_driver 0_Src\0_AppSw\Tricore\Demo_Illd\FlashDemo.o
最新文章
- codeforces754D Fedor and coupons
- [MVC_Json序列化]MVC之Json序列化循环引用
- xml文档解析
- coursera机器学习-logistic回归,正则化
- 【深入Java虚拟机】之二:Java垃圾回收机制
- PHP-权限控制类
- 利用FFmpeg生成视频缩略图 2.1.6
- 表单重置reset
- EntityFramework之创建数据库及基本操作(一)
- WinCE启动次数的记录
- Oracle 隔离级别
- 用Firefly创建第一个工程
- 使用下拉列表框<;select>;标签,节省空间
- KNN算法理解
- 如何在新浪sae服务器上面连接redis
- I/O输入输出流
- MicroPython开发之物联网快速开发板
- HTML学习笔记【思维导图版】
- final和static关键字
- [洛谷P1484] 种树
热门文章
- docker compose网络设置
- 大数据之路day01_1--Java下载、安装等配置
- python手册学习笔记1
- python——多线程
- yum.rpm一点点
- 创建基于OData的Web API - Knowledge Builder API, Part IV: Write Controller
- nyoj 163 Phone List(动态字典树<;trie>;) poj Phone List (静态字典树<;trie>;)
- byteCTF 2019
- nexus https proxy
- LoadRunner中的90%响应时间