RT-Thread the code during startup and $ Sub $ $ main, $ Super $ $ main

Reprinted from the article: https: //blog.csdn.net/yang1111111112/article/details/80913001

We find a place a system reset, you can track down a single step.
① executed from the system initialization, the function will assign the address of the R0 register, execution jumps to the address R0 and back here (BLX, is with Link, i.e., with the return jump).
② The main function address to the R0, the function address assigned R0, R0 jumps to address the implementation does not return (BX jump is not returned).
 
③ Jump to the $ Sub $$ main.
[Note: In __CC_ARM compiler environment, use the $ Sub $$ and $ Super $ $ "patch" feature.
See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0377g/pge1362065967698.html
 
This is a special mode: the case has a function and can not be changed in an existing. These two modes can help patch the original function. If there is a function foo ();
$ Sub $ $ foo: New performance function defined in foo () function before / after use $ Sub $ $ foo can add a new program code.
$ Super $ $ foo: is the original unpatched function foo, using the $ Super $ $ foo foo function will jump directly to the () function.
$ Sub $$ main mainly in some of the system boot code (system initialization).
 
④ In rtthread_startup, the main achievement of the board-level initialization (initialization and peripheral drive); print logo and version information of the RT-Thread; initializes the system timer; initialization scheduler; application creates a thread (here, the main function of the user as a thread , which is the main user empty); initialize the software timers; create idle threads; launch system scheduling (When enabled scheduling, dispatching main function will start running involved).
[So $ Sub $ $ main before the main dry live is carried rt-thread system initialization, in order to make it easier to use, allowing users to not worry too much]
 
The following are the main function of threads created in rt_application_init () function:
 

 

 

$ Super $ $ mian can jump directly to the main () function; users can write application code in the main:
 
 
It can be used as follows:
func uint8_t ( void ) 
{ 
    uint8_t var1 = 0 ; 
    var1 ++ ;
     return var1; 
} 

/ * before the following function call calling a function func * / 
void $ Sub $$ func ( void ) 
{ 
    int var2 = 0 ; 
    var2 + = 2 ; 
    
    / * called after the end of the return to the original point func code can not execute the code following the original mask code function func * / 
    extern  void $ Super $$ func ( void ); 
    $ Super $$ func (); 
} 

uint8_t var = 0 ;

int main(void)
{
    var = func();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/yeshenmeng/p/11578664.html