[go: up one dir, main page]

CN104866345B - The storage method of executable code under a kind of ARMv7m frameworks - Google Patents

The storage method of executable code under a kind of ARMv7m frameworks Download PDF

Info

Publication number
CN104866345B
CN104866345B CN201510262282.7A CN201510262282A CN104866345B CN 104866345 B CN104866345 B CN 104866345B CN 201510262282 A CN201510262282 A CN 201510262282A CN 104866345 B CN104866345 B CN 104866345B
Authority
CN
China
Prior art keywords
fpb
program
code
address
cpu
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201510262282.7A
Other languages
Chinese (zh)
Other versions
CN104866345A (en
Inventor
林志伟
黄健
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Centerm Information Co Ltd
Original Assignee
Fujian Centerm Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Centerm Information Co Ltd filed Critical Fujian Centerm Information Co Ltd
Priority to CN201510262282.7A priority Critical patent/CN104866345B/en
Publication of CN104866345A publication Critical patent/CN104866345A/en
Application granted granted Critical
Publication of CN104866345B publication Critical patent/CN104866345B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

本发明提供一种ARMv7m架构下可执行代码的存储方法,由编译和烧录程序、启动程序、FPB关联程序、执行程序以及总线异常处理程序五个逻辑单元参与,通过FPB关联程序将一片RAM空间关联到一处未和物理Flash关联的地址上,将其作为存储了可执行代码的存储空间,供CPU内核获取和执行机器指令使用。同时该RAM空间可以动态被更新为新值,且可以被FPB重新设置关联到新的Flash地址上。这样,本发明方法仅使用一小片片内的Flash存储FPB管理代码,就可以利用不大的RAM空间和廉价的片外Flash,将CPU的可执行代码的存储空间扩大到512MB。

The present invention provides a method for storing executable codes under the ARMv7m architecture, which is composed of five logical units including compiling and burning programs, startup programs, FPB related programs, execution programs, and bus exception handling programs, and a slice of RAM space is allocated through the FPB related programs Associated with an address that is not associated with the physical Flash, it is used as a storage space for storing executable code for the CPU core to obtain and execute machine instructions. At the same time, the RAM space can be dynamically updated to a new value, and can be reset and associated with a new Flash address by the FPB. In this way, the method of the present invention only uses a small piece of internal Flash to store the FPB management code, and can expand the storage space of the executable code of the CPU to 512MB by using a small RAM space and cheap off-chip Flash.

Description

一种ARMv7m架构下可执行代码的存储方法A storage method for executable code under ARMv7m architecture

技术领域technical field

本发明涉及一种ARMv7m架构下可执行代码的存储方法,特别涉及一种在ARMv7m架构下将可执行代码存储于片外无XIP的Flash上的方法。The invention relates to a method for storing executable codes under the ARMv7m architecture, in particular to a method for storing executable codes on an off-chip XIP-free Flash under the ARMv7m architecture.

背景技术Background technique

在计算机系统中,CPU需要先提取到机器指令、然后译码、最后才能执行机器指令。机器指令需要存储在CPU可直接寻址的存储器上,才能被CPU提取出来。CPU可直接寻址的存储器一般是片内RAM、片外并行总线的RAM、或者并行总线的支持XIP(片上执行)功能的Flash存储器。这样的存储器的单位存储空间价格都比较高,所以嵌入式MCU上一般不会配置大容量的可供存储执行代码的存储器。这使得嵌入式MCU上可提供的软件功能受到限制。如果通过外扩并行总线的存储器来扩展存储执行代码的空间,则会占用CPU的PIN脚资源,使可用IO资源变少。目前市面上有一种带有XIP功能的SPI总线的Flash,在特定的支持SPIXIPFlash的CPU上可以用来存储执行代码。但这使得产品方案的选型受限于特定的Flash和CPU器件。In a computer system, the CPU needs to fetch machine instructions first, then decode them, and finally execute the machine instructions. Machine instructions need to be stored in memory directly addressable by the CPU before they can be fetched by the CPU. The memory directly addressable by the CPU is generally an on-chip RAM, an off-chip parallel bus RAM, or a parallel bus supporting XIP (on-chip execution) function Flash memory. The unit storage space price of such a memory is relatively high, so the embedded MCU generally does not configure a large-capacity memory that can store the execution code. This limits the software functionality available on the embedded MCU. If the space for storing and executing code is expanded by expanding the memory of the parallel bus, the PIN resources of the CPU will be occupied, and the available IO resources will be reduced. At present, there is a Flash with SPI bus with XIP function on the market, which can be used to store and execute code on a specific CPU that supports SPIXIP Flash. But this makes the selection of product solutions limited to specific Flash and CPU devices.

ARM v7m是ARM公司发布第7版MCU内核架构。这种架构下,又因为CPU选配件的差异,衍生出Cortex-M3、Cortex-M4等子型号。基于这种架构的MCU其芯片效能相对与之前的ARM9/ARM11等处理器有明显提高,在工业控制、通讯设备、智能外设等领域有着广泛的应用。然而,ARM v7m架构的MCU,受上述提到的可直接存储可执行代码的空间大小的限制,难以被应用于复杂应用场景的设备中。这使得复杂应用场景的设备不得不使用芯片效能低的ARM9/ARM11处理器,或者ARM v7r、ARM v7a等高成本的处理器,进而影响到产品的性价。ARM v7m is the seventh version of the MCU core architecture released by ARM. Under this architecture, due to the difference in CPU options, sub-models such as Cortex-M3 and Cortex-M4 are derived. Compared with the previous ARM9/ARM11 and other processors, the chip performance of the MCU based on this architecture has been significantly improved, and it has a wide range of applications in industrial control, communication equipment, intelligent peripherals and other fields. However, the MCU of the ARM v7m architecture is difficult to be applied to devices in complex application scenarios due to the above-mentioned limitation of the space that can directly store executable codes. This makes devices with complex application scenarios have to use ARM9/ARM11 processors with low chip performance, or high-cost processors such as ARM v7r and ARM v7a, which in turn affects the price of products.

而ARM v7m架构中存在一个CPU选配组件,称为FPB(Flash补丁及断点模块),该组件一般用于在ARMv7m架构的处理器中实现在线调试功能。虽然FPB是选配组件,但目前大部分的ARMv7m的MCU实现都带有FPB组件。FPB的运行机制是临时性接管CPU内核对某些地址的Flash存储器的访问,将对应地址上的Flash内容替换成断点代码或者指定的RAM中存储的指令代码返回给CPU内核,让CPU内核因为执行到断点指令而停止运行,或执行被替换过的目标指令代码。ARMv7m架构中同时约定,0x00000000~0x1FFFFFFF地址的512MB空间为可存储执行代码的Flash空间。即使CPU上仅具备16KB的Flash空间,0x4000~0x1FFFFFFF的地址空间仍然被CPU内核作为Flash地址空间处理对待,且FPB同样可以在这片没有实际关联物理Flash的地址上生效,也就是说,可以通过FPB将一片RAM空间关联到一处未和物理Flash关联的地址上,将其作为存储了可执行代码的存储空间,供CPU内核获取和执行机器指令使用;同时,这片RAM空间可以动态被更新为新的值,且可以被FPB重新设置关联到新的Flash地址上。RAM上的执行代码不被使用时,还可以存放于片外的无XIP功能的SPINorFlash上或者NandFlash上,对存储设备无太大的要求。In the ARMv7m architecture, there is a CPU optional component called FPB (Flash Patch and Breakpoint Module), which is generally used to implement the online debugging function in the processor of the ARMv7m architecture. Although FPB is an optional component, most of the MCU implementations of ARMv7m currently have FPB components. The operating mechanism of FPB is to temporarily take over the access of the CPU core to the Flash memory of certain addresses, replace the Flash content on the corresponding address with the breakpoint code or the instruction code stored in the specified RAM and return it to the CPU core, so that the CPU core can Execute to the breakpoint instruction and stop running, or execute the replaced target instruction code. In the ARMv7m architecture, it is also agreed that the 512MB space at the address 0x00000000~0x1FFFFFFF is the Flash space that can store the execution code. Even if the CPU only has 16KB of Flash space, the address space from 0x4000 to 0x1FFFFFFF is still treated by the CPU core as the Flash address space, and FPB can also take effect on this address that is not actually associated with the physical Flash, that is, through FPB associates a piece of RAM space with an address that is not associated with physical Flash, and uses it as a storage space for storing executable code, which is used by the CPU core to obtain and execute machine instructions; at the same time, this piece of RAM space can be dynamically updated It is a new value and can be reset by FPB to be associated with a new Flash address. When the execution code on the RAM is not in use, it can also be stored on SPINorFlash or NandFlash without XIP function outside the chip, and there is no great requirement for the storage device.

因此,若能使用一小片片内的Flash存储FPB管理代码,就可以利用不大的RAM空间和廉价的片外Flash,将CPU的可执行代码的存储空间扩大到512MB。有鉴于此,本发明人特潜心研究该思想的实现方法而才有本发明问世。Therefore, if a small piece of on-chip Flash can be used to store the FPB management code, the storage space of the executable code of the CPU can be expanded to 512MB by using a small RAM space and cheap off-chip Flash. In view of this, the inventor has devoted himself to studying the realization method of this idea and has just come out of the present invention.

发明内容Contents of the invention

本发明要解决的技术问题,在于提供一种ARMv7m架构下可执行代码的存储方法,消耗内存小、不依赖于特定的Flash器件,可将程序代码的执行空间扩大到512MB。The technical problem to be solved by the present invention is to provide a method for storing executable codes under the ARMv7m architecture, which consumes less memory and does not depend on a specific Flash device, and can expand the execution space of program codes to 512MB.

本发明是这样实现的:一种ARMv7m架构下可执行代码的存储方法,在编译和烧录程序中,通过编译器的参数配置,将启动程序、FPB关联程序、执行程序、总线异常处理程序和系统及驱动程序定位于CPU片内物理存储器关联的Flash地址空间上,而将其他程序定位于CPU片内没有物理存储器关联的Flash地址空间上;编译生成目标可执行代码的二进制镜像文件;然后,软件开发人员将该启动程序、FPB关联程序、执行程序、总线异常处理程序和系统及驱动程序烧录到其编译时指定地址的CPU物理存储器上,并将所述其他程序烧录到片外Flash上;在设备上电启动后的第一阶段,所述启动程序先依次初始化系统和设备驱动、初始化FPB组件以及软件全局变量这些基本运行环境,然后启动程序提取出后续程序的第一条指令代码的Flash执行地址,送入所述FPB关联程序进行FPB关联处理,所述FPB关联程序能被所述启动程序和所述执行程序调用;所述FPB关联程序传入地址参数为本次需要关联执行的第一条指令代码的Flash执行地址,执行“加载被执行代码并对其进行FPB关联的过程”;在得到调用者传入的代码的Flash执行地址后,检查对应地址的代码是否已经被加载到RAM缓冲中,如果代码未被加载到RAM缓冲中,则通过Flash驱动程序从片外的Flash中将对应代码载入RAM缓冲中,加载完成后,计算出程序指令地址对应的代码在RAM中的存储地址,设FPB组件一共有n个单元可供使用,每个单元关联m个字节的Flash地址空间,该RAM缓冲的大小定义为k字节,则k字节应该至少等于n*m字节,通过设置FPB,将该存储地址开始n*m字节的RAM地址与代码的Flash执行地址实现关联;所述执行程序在所述FPB关联程序之后被调用,所述执行程序的传入地址参数和所述FPB关联程序传入的地址参数相同,所述执行程序将传入的地址参数送入CPU的PC寄存器,然后CPU将自动完成后续的代码执行过程;当所述执行程序执行过程引发总线异常时,所述总线异常处理程序被调用执行,通过查询CPU的异常状态寄存器,从而获知异常是由CPU取指令引发还是由CPU数据访问引发,若异常由CPU取指令引发,则将异常地址作为参数调用所述FPB关联程序进行重关联处理,若异常由CPU数据访问引发,则所述总线异常处理程序继续检查引发异常的指令是否为LDM多寄存器加载指令,若是,则由所述总线异常处理程序代替CPU完成LDM指令的功能,然后返回下一条指令代码地址让CPU继续执行,若不是,则将要访问的数据地址作为参数调用所述FPB关联程序进行重关联处理。The present invention is realized in the following way: a method for storing executable codes under the ARMv7m architecture, in compiling and burning programs, through the parameter configuration of the compiler, the startup program, FPB associated program, execution program, bus exception handling program and The system and the driver program are positioned on the Flash address space associated with the physical memory on the CPU chip, and other programs are positioned on the Flash address space that is not associated with the physical memory on the CPU chip; compile and generate a binary image file of the target executable code; then, The software developer burns the startup program, FPB associated program, execution program, bus exception handling program and system and driver program to the CPU physical memory at the specified address when compiling, and burns the other programs into the off-chip Flash In the first stage after the device is powered on, the startup program first initializes the basic operating environment of the system and device drivers, initializes FPB components, and software global variables in turn, and then the startup program extracts the first instruction code of the subsequent program The Flash execution address is sent to the FPB associated program to carry out FPB associated processing, and the FPB associated program can be called by the startup program and the execution program; the incoming address parameter of the FPB associated program is the required associated execution The Flash execution address of the first instruction code, execute "the process of loading the executed code and performing FPB association on it"; after obtaining the Flash execution address of the code passed in by the caller, check whether the code at the corresponding address has been loaded If the code is not loaded into the RAM buffer, the corresponding code is loaded into the RAM buffer from the off-chip Flash through the Flash driver. After the loading is completed, the code corresponding to the program instruction address is calculated in the RAM. Assuming that the FPB component has a total of n units available, each unit is associated with m bytes of Flash address space, and the size of the RAM buffer is defined as k bytes, then k bytes should be at least equal to n*m byte, by setting FPB, the RAM address of the storage address beginning n*m bytes is associated with the Flash execution address of the code; the execution program is called after the FPB associated program, and the incoming of the execution program Address parameter is identical with the address parameter that described FPB associated program imports, and described execution program sends the address parameter of import into the PC register of CPU, and then CPU will automatically complete follow-up code execution process; When described execution program execution process When a bus exception is caused, the bus exception handler is called and executed. By querying the exception status register of the CPU, it is known whether the exception is caused by CPU instruction fetching or CPU data access. If the exception is caused by CPU fetching instruction, the exception will be The address is used as a parameter to call the FPB associated program to carry out re-associated processing. If the exception is caused by CPU data access, then the bus exception handler continues to check whether the instruction that causes the exception is an LDM multi-register load instruction. exception handler generation Complete the function of the LDM instruction for the CPU, then return the next instruction code address to allow the CPU to continue to execute, if not, use the data address to be accessed as a parameter to call the FPB associated program to perform re-association processing.

进一步的,若CPU具备DMA功能,则所述FPB关联程序在执行所述“加载被执行代码并对其进行FPB关联的过程”之后还执行“加载预判为即将被执行的代码段的过程”,该“加载预判为即将被执行的代码段的过程”开辟一片与所述“加载被执行代码并对其进行FPB关联的过程”的RAM缓冲大小k字节相等的RAM空间作为辅助RAM缓冲,然后将片外的Flash上紧随所述“加载被执行代码并对其进行FPB关联的过程”所加载的代码之后的k字节代码加载到辅助RAM缓冲中,该加载过程通过DMA实现;且该“加载预判为即将被执行的代码段的过程”执行的结果用于加速下一次“加载被执行代码并对其进行FPB关联的过程”。Further, if the CPU has a DMA function, the FPB-associated program also executes the "process of loading code segments that are predicted to be executed soon" after executing the "process of loading the executed code and performing FPB association" , the "process of loading a code segment that is predicted to be executed soon" opens up a piece of RAM space equal to the RAM buffer size k bytes of the "process of loading the executed code and performing FPB association" as an auxiliary RAM buffer , then load the k-byte code following the loaded code on the off-chip Flash into the auxiliary RAM buffer, the loading process is realized by DMA; And the execution result of the "process of loading the code segment predicted to be executed" is used to accelerate the next "process of loading the executed code and performing FPB association on it".

本发明具有如下优点:The present invention has the following advantages:

本发明提供了一种在常见的ARMv7m处理器上可以实现的将执行代码存储与片外廉价存储器上的方法,该方法可将程序代码的执行空间扩大到512MB,消耗内存小、不依赖于特定的Flash器件,实现代价小、实现收益明显,且有利于将复杂的应用场景实现在基于ARMv7m的MCU上,扩大ARMv7m的MCU的应用场景,并降低对应产品的成本。The present invention provides a method for storing execution codes on common ARMv7m processors and low-cost off-chip memory. This method can expand the execution space of program codes to 512MB, consumes less memory, and does not depend on specific The Flash device has low implementation cost and obvious implementation benefits, and is conducive to implementing complex application scenarios on ARMv7m-based MCUs, expanding the application scenarios of ARMv7m MCUs, and reducing the cost of corresponding products.

附图说明Description of drawings

下面参照附图结合实施例对本发明作进一步的说明。The present invention will be further described below in conjunction with the embodiments with reference to the accompanying drawings.

图1为本发明方法执行流程图。Fig. 1 is a flow chart of the execution of the method of the present invention.

具体实施方式Detailed ways

如图1所示,本发明方法主要由五个逻辑单元参与,分别是:编译和烧录程序1、启动程序2、FPB关联程序3、执行程序4以及总线异常处理程序5。这五个逻辑单元在整体过程中的配合关系如图1所示。所述启动程序2、FPB关联程序3、执行程序4以及总线异常处理程序5这四个逻辑单元的软件实现均存储于CPU原生支持的代码存储器中,例如存储于片内的Flash或ROM中。As shown in Fig. 1, the method of the present invention is mainly participated by five logic units, namely: compiling and burning program 1, startup program 2, FPB associated program 3, execution program 4 and bus exception handling program 5. The coordination relationship of these five logic units in the overall process is shown in Figure 1. The software implementations of the four logic units of the startup program 2, the FPB associated program 3, the execution program 4, and the bus exception handling program 5 are all stored in the natively supported code memory of the CPU, such as in the on-chip Flash or ROM.

在所述编译和烧录程序1中,通过编译器的参数配置,将启动程序2、FPB关联程序3、执行程序4、总线异常处理程序5和系统及驱动程序定位于CPU片内物理存储器关联的Flash地址空间上,而将其他程序定位于CPU片内没有物理存储器关联的Flash地址空间上;编译生成目标可执行代码的二进制镜像文件;然后,软件开发人员将该启动程序2、FPB关联程序3、执行程序4、总线异常处理程序5和系统及驱动程序烧录到其编译时指定地址的CPU物理存储器上,并将所述其他程序烧录到片外Flash上。其中,所述系统及驱动程序指的是引导程序、任务调度、定时功能、系统异常处理、中断管理、硬件设备驱动等执行效果会明显受代码执行时间影响的程序和实现本专利功能的程序段;所述其它程序指的是执行效果受代码执行时间影响不明显的程序,一般包括纯软件逻辑的中间层代码、应用软件等。In the compiling and burning program 1, through the parameter configuration of the compiler, the startup program 2, the FPB associated program 3, the execution program 4, the bus exception handling program 5 and the system and the driver are positioned on the CPU on-chip physical memory associated on the Flash address space of the CPU, and locate other programs on the Flash address space associated with no physical memory in the CPU chip; compile and generate a binary image file of the target executable code; then, the software developer will start the program 2, FPB associated program 3. Burn the execution program 4, the bus exception handling program 5, the system and the driver program to the CPU physical memory at the specified address when compiling, and burn the other programs to the off-chip Flash. Among them, the system and driver refer to the boot program, task scheduling, timing function, system exception handling, interrupt management, hardware device driver and other programs whose execution effects will be obviously affected by the code execution time and the program segments that realize the functions of this patent ; The other programs refer to programs whose execution effects are not significantly affected by code execution time, generally including middle-level codes of pure software logic, application software, etc.

在设备上电启动后的第一阶段,所述启动程序2先依次初始化系统和设备驱动、初始化FPB组件以及软件全局变量这些基本运行环境,然后启动程序提取出后续程序的第一条指令代码的Flash执行地址,送入所述FPB关联程序3进行FPB关联处理。In the first stage after the device is powered on, the startup program 2 first initializes the basic operating environments such as the system and device drivers, initializes FPB components, and software global variables, and then the startup program extracts the first instruction code of the subsequent program. The Flash execution address is sent to the FPB associated program 3 for FPB associated processing.

所述FPB关联程序3能被所述启动程序2和所述执行程序4调用;所述FPB关联程序3传入地址参数为本次需要关联执行的第一条指令代码的Flash执行地址,所述FPB关联程序3将顺序执行“加载被执行代码并对其进行FPB关联的过程”和“加载预判为即将被执行的代码段的过程”两个过程。其中,“加载被执行代码并对其进行FPB关联的过程”为必选过程,“加载预判为即将被执行的代码段的过程”可根据CPU的配置选配,即若CPU具备DMA功能,则所述FPB关联程序在执行“加载被执行代码并对其进行FPB关联的过程”之后还执行“加载预判为即将被执行的代码段的过程”。The FPB associated program 3 can be called by the startup program 2 and the executive program 4; the FPB associated program 3 incoming address parameter is the Flash execution address of the first instruction code that needs to be associated and executed this time, and the The FPB association program 3 will sequentially execute two processes of "loading the executed code and performing FPB association" and "loading the code segment predicted to be executed". Among them, "the process of loading the executed code and performing FPB association on it" is a mandatory process, and "the process of loading the code segment that is predicted to be executed" can be selected according to the configuration of the CPU, that is, if the CPU has DMA function, Then, the FPB association program also executes "the process of loading the code segment that is predicted to be executed soon" after executing the "process of loading the executed code and performing FPB association on it".

所述“加载被执行代码并对其进行FPB关联的过程”在得到调用者传入的代码的Flash执行地址后,检查对应地址的代码是否已经被加载到RAM缓冲中,如果代码未被加载到RAM缓冲中,则通过Flash驱动程序从片外的Flash中将对应代码载入RAM缓冲中,加载完成后,该过程计算出程序指令地址对应的代码在RAM中的存储地址,设FPB组件一共有n个单元可供使用,每个单元关联m个字节的Flash地址空间,该RAM缓冲的大小定义为k字节,则k字节应该至少等于n*m字节,通过设置FPB,将该存储地址开始n*m字节的RAM地址与代码的Flash执行地址实现关联;The "process of loading the executed code and performing FPB association on it" checks whether the code at the corresponding address has been loaded into the RAM buffer after obtaining the Flash execution address of the code passed in by the caller, and if the code has not been loaded into the In the RAM buffer, the corresponding code is loaded into the RAM buffer from the off-chip Flash through the Flash driver. After the loading is completed, the process calculates the storage address of the code corresponding to the program instruction address in the RAM, and the FPB component has a total of n units are available, each unit is associated with m bytes of Flash address space, the size of the RAM buffer is defined as k bytes, then k bytes should be at least equal to n*m bytes, by setting FPB, the The RAM address of n*m bytes starting from the storage address is associated with the Flash execution address of the code;

该“加载预判为即将被执行的代码段的过程”开辟一片与所述“加载被执行代码并对其进行FPB关联的过程”的RAM缓冲大小k字节相等的RAM空间作为辅助RAM缓冲,然后将片外的Flash上紧随所述“加载被执行代码并对其进行FPB关联的过程”所加载的代码之后的k字节代码加载到辅助RAM缓冲中,该加载过程通过DMA实现;且该“加载预判为即将被执行的代码段的过程”执行的结果用于加速下一次“加载被执行代码并对其进行FPB关联的过程”。The "process of loading a code segment that is predicted to be executed" opens up a RAM space equal to the RAM buffer size k bytes of the "process of loading the executed code and performing FPB association" as an auxiliary RAM buffer, Then the k-byte code loaded on the off-chip Flash following the code loaded in the "loading the executed code and carrying out the process of FPB association" is loaded into the auxiliary RAM buffer, and the loading process is realized by DMA; and The execution result of the "process of loading the code segment predicted to be executed" is used to accelerate the next "process of loading the executed code and performing FPB association on it".

所述执行程序4在所述FPB关联程序3之后被调用,所述执行程序4的传入地址参数和所述FPB关联程序3传入的地址参数相同,所述执行程序4将传入的地址参数送入CPU的PC寄存器,然后CPU将自动完成后续的代码执行过程;The executive program 4 is called after the FPB associated program 3, the incoming address parameter of the executive program 4 is the same as the address parameter passed in by the FPB associated program 3, and the incoming address of the executive program 4 The parameters are sent to the PC register of the CPU, and then the CPU will automatically complete the subsequent code execution process;

所述总线异常处理程序5在所述执行程序4的过程中会被触发,在所述执行程序4执行时,如果代码执行到本次未被FPB指定关联的Flash地址且不属于物理Flash关联的地址时,会由于CPU内核无法提取到机器指令代码而引发一次总线异常,所述总线异常处理程序5在软件开发阶段就被关联到总线异常向量中,因此,异常发生时所述总线异常处理程序5被调用执行。在所述总线异常处理程序5被调用执行时,通过查询CPU的异常状态寄存器,从而获知异常是由CPU取指令引发还是由CPU数据访问引发,若异常由CPU取指令引发,则将异常地址作为参数调用所述FPB关联程序3进行重关联处理,若异常由CPU数据访问引发,则所述总线异常处理程序5继续检查引发异常的指令是否为LDM多寄存器加载指令,若是,则由所述总线异常处理程序5代替CPU完成LDM指令的功能,然后返回下一条指令代码地址让CPU继续执行,若不是,则将要访问的数据地址作为参数调用所述FPB关联程序3进行重关联处理。The bus exception handler 5 will be triggered during the execution of the program 4. When the execution of the program 4 is executed, if the code executes to the Flash address that is not specified by the FPB this time and is not associated with the physical Flash address, it will cause a bus exception because the CPU core cannot extract the machine instruction code, and the bus exception handler 5 is associated with the bus exception vector at the software development stage. Therefore, when an exception occurs, the bus exception handler 5 5 is called to execute. When the bus exception handling program 5 is called for execution, by querying the abnormal state register of the CPU, it is known whether the exception is caused by CPU fetching instructions or caused by CPU data access, if the exception is caused by CPU fetching instructions, the exception address is used as Parameter calls described FPB association program 3 to carry out re-association processing, if exception is caused by CPU data access, then described bus exception handler 5 continues to check whether the instruction that causes exception is LDM multi-register load instruction, if so, then by described bus Abnormal handling program 5 replaces CPU to complete the function of LDM instruction, then returns next instruction code address to allow CPU to continue to execute, if not, then the data address to be accessed is used as parameter to call described FPB association program 3 to carry out re-association processing.

虽然以上描述了本发明的具体实施方式,但是熟悉本技术领域的技术人员应当理解,我们所描述的具体的实施例只是说明性的,而不是用于对本发明的范围的限定,熟悉本领域的技术人员在依照本发明的精神所作的等效的修饰以及变化,都应当涵盖在本发明的权利要求所保护的范围内。Although the specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments we have described are only illustrative, rather than used to limit the scope of the present invention. Equivalent modifications and changes made by skilled personnel in accordance with the spirit of the present invention shall fall within the protection scope of the claims of the present invention.

Claims (2)

1.一种ARMv7m架构下可执行代码的存储方法,其特征在于:1. A method for storing executable codes under the ARMv7m framework, characterized in that: 在编译和烧录程序中,通过编译器的参数配置,将启动程序、FPB关联程序、执行程序、总线异常处理程序、系统及驱动程序定位于CPU片内物理存储器关联的Flash地址空间上,而将其他程序定位于CPU片内没有物理存储器关联的Flash地址空间上;编译生成目标可执行代码的二进制镜像文件;然后,软件开发人员将该启动程序、FPB关联程序、执行程序、总线异常处理程序、系统及驱动程序烧录到其编译时指定地址的CPU物理存储器上,并将所述其他程序烧录到片外Flash上;In compiling and burning the program, through the parameter configuration of the compiler, the startup program, FPB related program, execution program, bus exception handling program, system and driver are located in the Flash address space associated with the physical memory on the CPU chip, and Locate other programs on the Flash address space that is not associated with physical memory in the CPU chip; compile and generate a binary image file of the target executable code; , Burn the system and the driver program to the CPU physical memory of the specified address when compiling, and burn the other programs to the off-chip Flash; 在设备上电启动后的第一阶段,所述启动程序先依次初始化系统和设备驱动、初始化FPB组件以及软件全局变量这些基本运行环境,然后启动程序提取出后续程序的第一条指令代码的Flash执行地址,送入所述FPB关联程序进行FPB关联处理,所述FPB关联程序能被所述启动程序和所述执行程序调用;In the first stage after the device is powered on and started, the startup program first initializes the basic operating environments of the system and device drivers, initializes FPB components, and software global variables, and then the startup program extracts the Flash memory of the first instruction code of the subsequent program. Execution address is sent into the FPB associated program to carry out FPB associated processing, and the FPB associated program can be called by the startup program and the execution program; 所述FPB关联程序传入地址参数为本次需要关联执行的第一条指令代码的Flash执行地址,执行“加载被执行代码并对其进行FPB关联的过程”;在得到调用者传入的代码的Flash执行地址后,检查对应地址的代码是否已经被加载到RAM缓冲中,如果代码未被加载到RAM缓冲中,则通过Flash驱动程序从片外的Flash中将对应代码载入RAM缓冲中,加载完成后,计算出程序指令地址对应的代码在RAM中的存储地址,设FPB组件一共有n个单元可供使用,每个单元关联m个字节的Flash地址空间,该RAM缓冲的大小定义为k字节,则k字节应该至少等于n*m字节,通过设置FPB,将该存储地址开始n*m字节的RAM地址与代码的Flash执行地址实现关联;The incoming address parameter of the FPB associated program is the Flash execution address of the first instruction code that needs to be associated and executed this time, and executes "the process of loading the executed code and performing FPB association to it"; After executing the address of the Flash, check whether the code corresponding to the address has been loaded into the RAM buffer, if the code has not been loaded into the RAM buffer, load the corresponding code from the off-chip Flash into the RAM buffer through the Flash driver, After the loading is completed, calculate the storage address of the code corresponding to the program instruction address in RAM. Suppose that the FPB component has n units available for use, and each unit is associated with m bytes of Flash address space. The size of the RAM buffer is defined as is k bytes, then k bytes should be at least equal to n*m bytes. By setting FPB, the RAM address starting from the storage address of n*m bytes is associated with the Flash execution address of the code; 所述执行程序在所述FPB关联程序之后被调用,所述执行程序的传入地址参数和所述FPB关联程序传入的地址参数相同,所述执行程序将传入的地址参数送入CPU的PC寄存器,然后CPU将自动完成后续的代码执行过程;The execution program is called after the FPB associated program, the incoming address parameter of the execution program is the same as the address parameter passed in by the FPB associated program, and the incoming address parameter is sent into the CPU by the execution program PC register, and then the CPU will automatically complete the subsequent code execution process; 当所述执行程序执行过程引发总线异常时,所述总线异常处理程序被调用执行,通过查询CPU的异常状态寄存器,从而获知异常是由CPU取指令引发还是由CPU数据访问引发,若异常由CPU取指令引发,则将异常地址作为参数调用所述FPB关联程序进行重关联处理,若异常由CPU数据访问引发,则所述总线异常处理程序继续检查引发异常的指令是否为LDM多寄存器加载指令,若是,则由所述总线异常处理程序代替CPU完成LDM指令的功能,然后返回下一条指令代码地址让CPU继续执行,若不是,则将要访问的数据地址作为参数调用所述FPB关联程序进行重关联处理。When the execution process of the execution program causes a bus exception, the bus exception handler is called to execute, and by querying the exception status register of the CPU, it is known whether the exception is caused by CPU instruction fetching or CPU data access, if the exception is caused by the CPU Instruction fetching is caused, then the abnormal address is used as a parameter to call the FPB associated program to carry out re-association processing, if the exception is caused by CPU data access, then the bus exception handler continues to check whether the instruction causing the exception is an LDM multi-register load instruction, If so, the bus exception handler replaces the CPU to complete the function of the LDM instruction, then returns the next instruction code address to allow the CPU to continue executing, if not, the data address to be accessed is used as a parameter to call the FPB associated program to carry out re-association deal with. 2.根据权利要求1所述的一种ARMv7m架构下可执行代码的存储方法,其特征在于:若CPU具备DMA功能,则所述FPB关联程序在执行所述“加载被执行代码并对其进行FPB关联的过程”之后还执行“加载预判为即将被执行的代码段的过程”,该“加载预判为即将被执行的代码段的过程”开辟一片与所述“加载被执行代码并对其进行FPB关联的过程”的RAM缓冲大小k字节相等的RAM空间作为辅助RAM缓冲,然后将片外的Flash上紧随所述“加载被执行代码并对其进行FPB关联的过程”所加载的代码之后的k字节代码加载到辅助RAM缓冲中,该加载过程通过DMA实现;且该“加载预判为即将被执行的代码段的过程”执行的结果用于加速下一次“加载被执行代码并对其进行FPB关联的过程”。2. the storage method of executable code under a kind of ARMv7m framework according to claim 1, it is characterized in that: if CPU possesses DMA function, then described FPB associated program is executing described " loading and executing code and performing After the FPB-associated process", the "process of loading the code segment predicted to be executed" is also executed. The RAM buffer size equal to k bytes in the process of performing FPB association" is used as an auxiliary RAM buffer, and then the off-chip Flash is loaded following the "process of loading the executed code and performing FPB association" The k-byte code after the code is loaded into the auxiliary RAM buffer, and the loading process is realized by DMA; and the execution result of the "loading the code segment that is predicted to be executed" is used to accelerate the next "loading is executed code and FPB-associate it".
CN201510262282.7A 2015-05-21 2015-05-21 The storage method of executable code under a kind of ARMv7m frameworks Expired - Fee Related CN104866345B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510262282.7A CN104866345B (en) 2015-05-21 2015-05-21 The storage method of executable code under a kind of ARMv7m frameworks

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510262282.7A CN104866345B (en) 2015-05-21 2015-05-21 The storage method of executable code under a kind of ARMv7m frameworks

Publications (2)

Publication Number Publication Date
CN104866345A CN104866345A (en) 2015-08-26
CN104866345B true CN104866345B (en) 2018-03-23

Family

ID=53912194

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510262282.7A Expired - Fee Related CN104866345B (en) 2015-05-21 2015-05-21 The storage method of executable code under a kind of ARMv7m frameworks

Country Status (1)

Country Link
CN (1) CN104866345B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB2551574B (en) * 2016-06-24 2019-11-27 Advanced Risc Mach Ltd An apparatus and method for generating and processing a trace stream indicative of instruction execution by processing circuitry
CN106598879B (en) * 2016-11-22 2020-06-09 积成电子股份有限公司 Memory management method for RAM without power failure
CN111124550B (en) * 2020-03-26 2020-07-03 北京翼辉信息技术有限公司 Program dynamic loading method and device and storage medium
CN111459572B (en) * 2020-03-31 2023-01-31 深圳市汇顶科技股份有限公司 Program loading method, controller, chip and electronic equipment
CN114936108A (en) * 2022-05-26 2022-08-23 联想(北京)有限公司 Processing method and electronic equipment

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101334758A (en) * 2008-07-03 2008-12-31 深圳市中兴集成电路设计有限责任公司 Device and method for expanding storage space of embedded system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH09185551A (en) * 1996-01-08 1997-07-15 Mitsubishi Electric Corp Semiconductor memory device

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101334758A (en) * 2008-07-03 2008-12-31 深圳市中兴集成电路设计有限责任公司 Device and method for expanding storage space of embedded system

Also Published As

Publication number Publication date
CN104866345A (en) 2015-08-26

Similar Documents

Publication Publication Date Title
KR102262176B1 (en) Avoiding premature enabling of nonmaskable interrupts when returning from exceptions
CN104866345B (en) The storage method of executable code under a kind of ARMv7m frameworks
KR101773229B1 (en) Method for booting a heterogeneous system and presenting a symmetric core view
US12014199B1 (en) Virtualization extension modules
US8495344B2 (en) Simultaneous execution resumption of multiple processor cores after core state information dump to facilitate debugging via multi-core processor simulator using the state information
US10949207B2 (en) Processor core supporting a heterogeneous system instruction set architecture
CN101154259A (en) General automated unpacking engine and method
WO2021249054A1 (en) Data processing method and device, and storage medium
US11023342B2 (en) Cache diagnostic techniques
EP4254177B1 (en) Synchronous microthreading
CN101639791B (en) Method for improving interruption delay of embedded type real-time operation system
US6986028B2 (en) Repeat block with zero cycle overhead nesting
US20170060582A1 (en) Arbitrary instruction execution from context memory
CN111045730B (en) A hardware fast interrupt processing system and method for RISC-V architecture
CN106970825B (en) ARM7 simulation target machine implementation method based on GDB configurable framework
US11119149B2 (en) Debug command execution using existing datapath circuitry
CN113407240B (en) A Simulation Method of C64x+ DSP Software Pipeline Circular Buffer Mechanism
CN119149105A (en) Interface calling method, device, equipment and computer readable storage medium
US20230315444A1 (en) Synchronous microthreading
US20230315460A1 (en) Synchronous microthreading
Schmaltz Technical Report: MIPS-86–A Multi-Core MIPS ISA Specification (November 4, 2013)
Gomes et al. Non-intrusive hardware acceleration for dynamic binary translation in embedded systems
Garcia et al. A FPGA based C runtime hardware accelerator
CN110858254A (en) a security chip
Jo et al. Design for most compatible booting model of integrated memory-disk based on ARM linux

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
EXSB Decision made by sipo to initiate substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20180323

CF01 Termination of patent right due to non-payment of annual fee