单片机解密KEIL-BL51用户向导之覆盖数据内存
单片机解密覆盖数据内存
Data and bit segments marked as OVERLAYABLE may overlap the same physical memory space. By default, the Keil Cx51 Compiler and the Intel PL/M-51 Compiler store program arguments and local variables in fixed, overlayable memory rather than on the hardware stack. There are two reasons for this:
数据和标记为可覆盖的位段可能会与相同的物理内存空间重叠。默认情况下,Keil Cx51编译器和Intel PL/M-51编译器将程序参数和局部变量存储在固定的可覆盖内存中,而不是在硬件堆栈中。这有两个原因:
The 8051 hardware stack resides in on-chip DATA memory which is limited to a maximum of 256 bytes.
8051的硬件堆栈驻留在片上数据存储器中,其限制为最多256字节。
Stack-based addressing on the 8051 is slow and inefficient.
在8051上基于堆栈的寻址既慢又低效。
There are several benefits to overlaying data space rather than using the stack:
与使用堆栈相比,覆盖数据空间有几个好处:
- The linker can maximize the available space by overlaying memory.
§ 链接器可以通过覆盖内存来最大化可用空间。
- Direct access to memory is much faster on the 8051 than indirect access.
§ 在8051上直接访问内存比间接访问快得多。
To accomplish overlaying, the linker analyzes all references (calls) between the various functions in the program. Using this information the linker determinesprecisely which data and bit segments may be overlaid.
为了实现覆盖,链接器分析程序中各个函数之间的所有引用 (调用)。链接器使用这些信息精确地确定哪些数据和位段可以覆盖。
The following table describes all BL51 Linker/Locator directives that affect data overlaying.
下表描述了所有影响数据覆盖的BL51链接器/定位器指令。
Theory of Operation
操作理论
The system the linker uses to determine which function arguments (or parameters) and variables may be overlaid is quite sophisticated. It begins when the compiler generates the object code for a function.
单片机解密链接器用于确定哪些函数参数 (或参数) 和变量可以覆盖的系统的非常复杂。它从编译器为函数生成目标代码开始。
The compiler stores all function parameters and local variables in overlayable bit, data, pdata, or xdata segments. The segment names generated by the compiler for Parameters and Local Variables are well-defined. They are used by the compiler to access parameters and local variables.
编译器将所有函数参数和局部变量存储在可覆盖的位、数据、pdata或扩展数据段中。编译器为参数和局部变量生成的段名称是明确定义的。它们被编译器用来访问参数和局部变量。
As the linker resolves references between functions, it builds a call tree based on where those references appear. For instance, if function_a calls function_b, the compiler inserts a reference to function_b in the object code generated for function_a. When the linker resolves this reference, it inserts the address of function_b and adds a call from function_a to function_b in the call tree.
当链接器解析函数之间的引用时,它会根据这些引用出现的位置构建一个调用树。例如,如果function_a调用function_b,编译器会在为function_a生成的对象代码中插入对function_b的引用。当链接器解析此引用时,它会插入function_b的地址,并在调用树中添加从function_a到function_b的调用。
The local variables and parameters of function_a are overlaid with the variables and parameters of function_b only under the following conditions:
function_a的局部变量和参数仅在以下条件下与function_b的变量和参数覆盖:
No call references of any kind may exist between function_a and function_b. This includes direct calls between A and B as well as calls from other functions on the A branch to B and calls from functions on the B branch to A.
function_a和function_b之间不可存在任何类型的调用引用。这包括A和B之间的直接调用,以及从A分支上的其他函数到B的调用,以及从B分支上的函数到A的调用。
The functions A and B may be invoked by only one program event or root: either the main root or an interrupt but not both. It is impossible to overlay variables and parameters if a function is called by an interrupt and the main program or by two interrupts.

芯片解密