modifying the reset handler asm code

question 1:
This is the original reset handler that is in the startup file (*.s)

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  __main
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP

which i modify to

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  OSInit
                IMPORT  __main
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =OSInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP

Here the OSInit is a function. This works fine.

But when i modify the original to following, I get a hard fault.

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  main
                IMPORT  OSInit
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =main
                BLX     R0                    ;getting hardfault here
                LDR     R0, =OSInit
                BX      R0
                ENDP


Irrespective of whether the OSInit is a function or a task, i get Hardfault.

question 2:
does the '__' (two underscores) before 'main' have any significance. Because when i write __OSInit, the compiler is unable to locate OSInit function (Error L6218E: undefined symbol).
but for '__main' the function name is always 'main' and compiler locates it.

Parents
  • Note that code normally is written based on a number of assumptions. You are breaking these assumptions when you try to do things differently.
    Why assumptions...
    This ain't gonna work, OK
    It should.

    Why we dont have a RTOS in which the user only has to design only an executable file and run it (just as in desktop OS)?

    Let us think in this direction...
    We dont have RTOS where, we can only patch up the new code on to the device already running. We have to load the whole code. (increases the service cost for the company as it has to regulate site visits. site visits are avoidable if i have an ethernet based boot-loader, then too i have to flash the whole code!!)
    Like for example, an application on my mobile-phone has a new update. the application gets updated without switching off the phone or for that matter even the application.

    also the coders from all around the world can develop the applications.

    similarly, my colleagues dont have to bother what is going on (eg: about the interrupt functions and data generated from there. they just have the locations [or mailboxes or any other method] form where they get the values captured in the interrupt functions).
    they have the starting point and they just have to start from there.

    Hence i need some more initialization before main.

Reply
  • Note that code normally is written based on a number of assumptions. You are breaking these assumptions when you try to do things differently.
    Why assumptions...
    This ain't gonna work, OK
    It should.

    Why we dont have a RTOS in which the user only has to design only an executable file and run it (just as in desktop OS)?

    Let us think in this direction...
    We dont have RTOS where, we can only patch up the new code on to the device already running. We have to load the whole code. (increases the service cost for the company as it has to regulate site visits. site visits are avoidable if i have an ethernet based boot-loader, then too i have to flash the whole code!!)
    Like for example, an application on my mobile-phone has a new update. the application gets updated without switching off the phone or for that matter even the application.

    also the coders from all around the world can develop the applications.

    similarly, my colleagues dont have to bother what is going on (eg: about the interrupt functions and data generated from there. they just have the locations [or mailboxes or any other method] form where they get the values captured in the interrupt functions).
    they have the starting point and they just have to start from there.

    Hence i need some more initialization before main.

Children
More questions in this forum