RT-Thread Code startup process - and $ Sub $ $ main and $ Super $ $ main

【转】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:

 

 

Summary: You can use this function to the main patch:

int $ Sub $$ main ( void ) 
{ 
    // add the patched function 
 
    $ Super $$ main (); // Use the sentence directly to the main () Run 
}

 

 Of course, main () function can also be their other functions, operations are the same, like a change in the function name

 

Guess you like

Origin www.cnblogs.com/txqdm/p/11425119.html