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-elf-gcc uses wrong -mhwmult default for chips without hardware multiply

Other Parts Discussed in Thread: MSP430G2553

It appears msp430-elf-gcc 4.9.1 defaults to hardware multiply support for the msp430g2553 if you don't provide a choice to the command line. I didn't check other chips that lack hardware multiply. I compiled some code written for the msp430g2553 which worked fine with msp430-gcc. However, when I compiled with msp430-elf-gcc it failed to run properly on the device.  Looking at the generated code I noticed it was trying use the multiply hardware.

Here is the code it generates:

0000f088 <__mulhi2>:
    f088:       02 12           push    r2              ;
    f08a:       32 c2           dint                    
    f08c:       03 43           nop                     
    f08e:       82 4c 30 01     mov     r12,    &0x0130 ;
    f092:       82 4d 38 01     mov     r13,    &0x0138 ;
    f096:       1c 42 3a 01     mov     &0x013a,r12     ;0x013a
    f09a:       00 13           reti                    

0000f09c <__mulsihi2>:
    f09c:       02 12           push    r2              ;
    f09e:       32 c2           dint                    
    f0a0:       03 43           nop                     
    f0a2:       82 4c 32 01     mov     r12,    &0x0132 ;
    f0a6:       82 4d 38 01     mov     r13,    &0x0138 ;
    f0aa:       1c 42 3a 01     mov     &0x013a,r12     ;0x013a
    f0ae:       1d 42 3c 01     mov     &0x013c,r13     ;0x013c
    f0b2:       00 13           reti                    

0000f0b4 <__umulsihi2>:
    f0b4:       02 12           push    r2              ;
    f0b6:       32 c2           dint                    
    f0b8:       03 43           nop                     
    f0ba:       82 4c 30 01     mov     r12,    &0x0130 ;
    f0be:       82 4d 38 01     mov     r13,    &0x0138 ;
    f0c2:       1c 42 3a 01     mov     &0x013a,r12     ;0x013a
    f0c6:       1d 42 3c 01     mov     &0x013c,r13     ;0x013c
    f0ca:       00 13           reti                    

0000f0cc <__mulsi2>:
    f0cc:       02 12           push    r2              ;
    f0ce:       32 c2           dint                    
    f0d0:       03 43           nop                     
    f0d2:       82 4c 30 01     mov     r12,    &0x0130 ;
    f0d6:       82 4e 38 01     mov     r14,    &0x0138 ;
    f0da:       82 4c 34 01     mov     r12,    &0x0134 ;
    f0de:       1c 42 3a 01     mov     &0x013a,r12     ;0x013a
    f0e2:       92 42 3c 01     mov     &0x013c,&0x013a ;0x013c
    f0e6:       3a 01 
    f0e8:       82 4f 38 01     mov     r15,    &0x0138 ;
    f0ec:       82 4d 34 01     mov     r13,    &0x0134 ;
    f0f0:       82 4e 38 01     mov     r14,    &0x0138 ;

If I explicitly add the hardware multiply option to the command line argument,

 $ msp430-elf-gcc -Wall -Os -g -mmcu=msp430g2553 -mhwmult=none ...

the code works as expected.

I tested with both the CCS supplied msp430-elf-gcc and one I built from source with the same results.

-rick