This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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
  • They have been developed by humans to work in a particular way.

    If you want to use them, you have to work with them.

    You don't have to use them - you may do it all yourself, from scratch, if you wish.

    When you do it all yourself from scratch you are, of course, entirely free to do it however you like.

Reply
  • They have been developed by humans to work in a particular way.

    If you want to use them, you have to work with them.

    You don't have to use them - you may do it all yourself, from scratch, if you wish.

    When you do it all yourself from scratch you are, of course, entirely free to do it however you like.

Children
  • @Tamir
    The link is informative.
    as i said, i just want to alter the way. I definitely dont want to disturb the scatter file.

    Dont we have any method by which, we can bring the code to main() after initialization of RTOS

    as per my understanding, __main has some piece of code which copies non-root ro & rw regions, etc and at the end calls main().
    so want to call os_sys_init jus before main or the other way, execute some piece of code (initialisation code in the same way as SystemInit is done in asm code) and then call os_sys_init and finally the main function.

    like, in desktop pcs. Boot up, POST, then kernel is loaded and then windows starts up. Now the user is free to do as he wishes. he can also execute his own codes, other programmer codes etc.

    will i have to read the procedure in which the os are booted up and try to do the same thing on my embedded board?

  • Your fault is that you don't realize that main() can be the function that initializes the OS. And that main() can then call funny_end_user_stupid_main_run_only_after_os_initialized_for_thread_1() and another_funny_end_user_main_run_only_after_os_initialized_for_thread_2().

    As long as your goal is to put the donkey behind the wagon, you are going to have huge issues. The world works much better if you try to follow the normal path instead of going against the stream. Especially since you don't really have anything to gain by mucking up the startup sequence.