This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430-GCC-OPENSOURCE: __crt0_call_just_main and CLR R12

Part Number: MSP430-GCC-OPENSOURCE

If specify "-minrt", "__crt0_call_just_main" does CLR R12 then CALL main. Is there any special reason to CLR R12?

  • I don't know, but I suppose it's just in case someone's main() looks for "argc".

  • So if I need to blink an LED argc is useless. Hacking the ld script is tedious and it will be better to have a "-nort" option. Or some function attribute will work?

  • I've never referenced argc on an MSP430 either.

    I can't seem to find my MSPGCC book, but the TI CC User Guide (SLAU132S) Sec J.3.2 suggests that this is a standards thing. I'm not quite sure what "alternate" means in the second sentence there -- my copy of C99 (N1256) Sec 5.1.2.2.1 says either void or argc/argv is OK. Since crt0 doesn't know, I suppose the CLR is cheap (1 MCLK) insurance.

    Since crt_mumble is the function of interest, I'm not sure what you can do to main to get rid of the CLR. I suppose you can always write your own crt0.

  • slau646e says: "This option is deprecated. The toolchain now dynamically decides which start up and initialization/termination functions are required."

  • The CRT startup code can call functions such as memset() and memmove(), which will return a non-zero value in R12.

    Since, these functions are called from different phases of the startup code (which may not be included in every program), it saves code size overall to only clear R12 immediately before calling main, rather than clearing it at the end of each of the phases of the startup procedure.

    I do agree that argc is unlikely to be checked in main() of MSP430 programs though, but technically it should be 0 on entry to main.

    You can override the default definition of __crt0_call_main from the startup code using the following code snippet. This removes the "CLR R12" whilst keeping any other phases intact e.g. the setting of the stack pointer.

    void __attribute__((naked, section (".crt_0800call_main")))
    __crt0_call_main (void)
    {
      main ();
    }

  • Bruce McKenney47378 said:
    I'm not quite sure what "alternate" means in the second sentence there -- my copy of C99 (N1256) Sec 5.1.2.2.1 says either void or argc/argv is OK.

    I believe that the "standard" ANSI C allows both "int main (void)" and "int main (argc, argv)". The "alternate" non-ANSI types return void instead of int.

  • Ah, I missed that. Thanks.

**Attention** This is a public forum