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.

HalCoGen and GCC

Other Parts Discussed in Thread: HALCOGEN, TMS570LS3137

Curent code generated by HalCoGen can't work with GCC compiler. Problem is assembler files. Here is sniplet:

@ Enable interrupts - CPU IRQ & FIQ

	.weak _enable_interrupt_
   
_enable_interrupt_:

        cpsie if
        bx    lr

But exporting function name by ".weak" keyword don't inform compiller about ARM/thumb function type. With this code compiler will use "BX" instruction to call and it's mistake. Minimal change to get working code is this here:

@ Enable interrupts - CPU IRQ & FIQ

	.weak _enable_interrupt_
	.type _enable_interrupt_, function
   
_enable_interrupt_:

        cpsie if
        bx    lr

And formally perfect code is:

@ Enable interrupts - CPU IRQ & FIQ

	.global _enable_interrupt_
	.type   _enable_interrupt_, function
        .func   _enable_interrupt_

_enable_interrupt_:

        cpsie if
        bx    lr

        .endfunc

  • Ops. I make fault in my text. Without ".type _enable_interrupt_, function" part compiler use "BL" (not BX) call and it is problem. From thumb compiled code we need "BX" instruction. This is core of problem.
  • Hi Jiri,

    I agree to your recommended fix. I will let HALCoGen team know this. 

    Looks like you have good hold with GCC, if you have some suggestion for below question Please do let me know.. Thanks!

    Is there a function level attribute with in the same "C" file, by which we can force certain function to be in ARM mode and certain function to be in Thumb mode? .

    I think HALCoGen does not do this, I am new to GCC, but CCS, IAR, KEIL supports this feature. Not sure how it's done in GCC. 

    If you have some suggestions, I can certainly recommend this to HALCoGen because the ISR's are part of individual module C files, so if you compile with thumb the ISR's is also forced to thumb, which we do not want, ISR's must be in ARM mode.

  • Hi,

    ARM/thumb interworking is not problem on C. It simpy works :-)

    When we talking about GCC, I have some one more suggestion.  Function _c_int00 can't have preamble with register manipulation because SP is not initialized. I another words it must  be "naked"

    void _c_int00(void) __attribute__ ((naked));
    void _c_int00(void) {
    ....
    }
  • Hi Jiri,

    ARM/thumb interworking in same source is possible in ARM GCC? Have you used them? 

    Below link mentions that it's a Bug / feature Miss... If you have pls share a simple code snippet with the attribute that can be used for this. 

    "http://gcc.1065356.n5.nabble.com/Bug-target-52144-New-ARM-should-support-arm-thumb-function-attribute-to-permit-different-instructione-td448145.html"

    I could see the attribute"naked" is present for c_int00 function. is the way it was placed is wrong? 

  • Here is part of source generated from HalCoGen 4.2.0 for TMS570LC435 and GCC7. It realy not contain "naked" attribute:

    /* USER CODE BEGIN (3) */
    /* USER CODE END */
    
    /* Startup Routine */
    void _c_int00(void);
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    
    
    void _c_int00(void)
    {
    

    We don't have any problem with ARM/thumb interworking. All sources is compiled and linked with "-mthumb -mthumb-interwork" 
    At this moment we have all "C" code compiled into thumb. And asm files is mixed. Sometime we are using both instruction sets in one asm file. (SVC and interrupts  start in ARM and we need T2 only instructions to optimize following code.  -ex.  CBZ, TBH)

    Thumb functions in asm need one aditional attribute ".thumb_func"

    cc

  • Sorry, I did not check TMS570LC435, I did with TMS570LS3137... I will raise a ticket to HALCoGen team adding this too.
  • Additional info: We also try compile some C files into ARM (interrupt handler). It works without problem include calls from ARM -> thumb C code and back.
    ARM/thumb compilation type for "C" sources is defined by compiler command line parameter. This mean that we can't combine ARM/thumb compilation in one C file. But we can compile different C files by different instruction set and combine objects in one project.
    Combine ARM/thumb in one ASM (not C) file is not problem.
    (We have experience with GCC 4.6, 4.7, 4.8, 4.9. Now we are using patched 4.8 2014q4 compiler based on https://launchpad.net/gcc-arm-embedded )