Hi,
I have some code that does not seem to work.
I'm using gcc-3.2.3 patched with the latest CVS source for the msp-430.
The problem seems to be when we want a pointer to a structure and it
gets put into R14.
My test code is,
------------------------------------------------------------------
/* struct problem
*/
typedef struct SensorTypeTableStruct
{
const char *strSensorType;
const char *strFormat;
void (*const ReadFunction)(void);
void (*const initFunction)(void);
const char *strText;
} SensorTypeTable;
void init (void)
{
}
const SensorTypeTable SensorTypeTab[] =
{
// Type Fmt readFunction InitFunction
Description
{"AT1", "%d" , init , init , "AAD Precision Temperature"}
};
const char SensorTypeTableLength =
sizeof(SensorTypeTab)/sizeof(SensorTypeTable);
int putchar(int c)
{
return c;
}
int get(void)
{
return 3;
}
void Find(char *s)
{
strcpy(s, "XX");
}
char i;
void prob(void)
{
char str[5];
// char *p;
// p = SensorTypeTab[i].strFormat; /* using this line works ok */
Find(str);
// printf(p, str);
printf(SensorTypeTab[i].strFormat, str);
}
main()
{
i = get();
prob();
}
-----------------------------------------------------------------
the compile line and output is
[peter_...@sts-cvs test]$ msp430-gcc -O2 -o struct struct.c
-mmcu=msp430x149 -v
Reading specs from /usr/local/lib/gcc-lib/msp430/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --target=msp430
Thread model: single
gcc version 3.2.3
/usr/local/lib/gcc-lib/msp430/3.2.3/cc1 -lang-c -v -D__GNUC__=3
-D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102
-DMSP430 -D__MSP430__ -D__MSP430 -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-DMSP430_HAS_HW_MUL -D__MSP430_149__ -DMSP430_HAS_HWMUL
-D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int -D__INT_MAX__=32767
struct.c -quiet -dumpbase struct.c -mmcu=msp430x149 -O2 -version -o
/tmp/ccdwmRd4.s
GNU CPP version 3.2.3 (cpplib) (GNU assembler syntax)
GNU C version 3.2.3 (msp430)
compiled by GNU C version 3.2 20020903 (Red Hat Linux 8.0 3.2-7).
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/msp430/sys-include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc-lib/msp430/3.2.3/include
/usr/local/msp430/include
End of search list.
/usr/local/lib/gcc-lib/msp430/3.2.3/../../../../msp430/bin/as -o
/tmp/ccGFP3x8.o /tmp/ccdwmRd4.s
msp430-ld -m msp430x149 -o struct
/usr/local/lib/gcc-lib/msp430/3.2.3/../../../../msp430/lib/crt430x149.o
-L/usr/local/lib/gcc-lib/msp430/3.2.3/msp2
-L/usr/local/lib/gcc-lib/msp430/3.2.3
-L/usr/local/lib/gcc-lib/msp430/3.2.3/../../../../msp430/lib/msp2
-L/usr/local/lib/gcc-lib/msp430/3.2.3/../../../../msp430/lib
/tmp/ccGFP3x8.o -lgcc -lc -lgcc
The offending code is for the prob function, the generated code is
00001190 <prob>:
1190: 04 12 push r4 ;
1192: 31 80 06 00 sub #6, r1 ;#0x0006
1196: 04 41 mov r1, r4 ;
1198: 0f 44 mov r4, r15 ;
119a: b0 12 7c 11 call #4476 ;#0x117c
119e: 04 12 push r4 ;
11a0: 5e 42 04 02 mov.b &0x0204,r14 ;0x0204
11a4: 8e 11 sxt r14 ;
11a6: 0e 5e rla r14 ;
11a8: 0e 5e rla r14 ;
/* where is the value of R15 comming from ? */
11aa: 0f 5f rla r15 ;
11ac: 0e 5f add r15, r14 ;
11ae: 0e 5f add r15, r14 ;
11b0: 0e 5f add r15, r14 ;
11b2: 1e 12 66 11 push 4454(r14) ;
11b6: b0 12 d8 11 call #4568 ;#0x11d8
11ba: 21 52 add #4, r1 ;r2 As==10
11bc: 31 50 06 00 add #6, r1 ;#0x0006
11c0: 34 41 pop r4 ;
11c2: 30 41 ret
The un-optimised code seems ok (aka)
000011ca <prob>:
11ca: 05 12 push r5 ;
11cc: 04 12 push r4 ;
11ce: 05 41 mov r1, r5 ;
11d0: 35 50 06 00 add #6, r5 ;#0x0006
11d4: 31 80 06 00 sub #6, r1 ;#0x0006
11d8: 04 41 mov r1, r4 ;
11da: 0f 44 mov r4, r15 ;
11dc: b0 12 a6 11 call #4518 ;#0x11a6
11e0: 04 12 push r4 ;
11e2: 5e 42 04 02 mov.b &0x0204,r14 ;0x0204
11e6: 8e 11 sxt r14 ;
11e8: 0f 4e mov r14, r15 ;
11ea: 0f 5f rla r15 ;
11ec: 0f 5f rla r15 ;
11ee: 0e 5e rla r14 ;
11f0: 0f 5e add r14, r15 ;
11f2: 0f 5e add r14, r15 ;
11f4: 0f 5e add r14, r15 ;
11f6: 3f 50 6e 11 add #4462, r15 ;#0x116e
11fa: 2f 12 push @r15 ;
11fc: b0 12 22 12 call #4642 ;#0x1222
1200: 21 52 add #4, r1 ;r2 As==10
1202: 31 50 06 00 add #6, r1 ;#0x0006
1206: 34 41 pop r4 ;
1208: 35 41 pop r5 ;
120a: 30 41 ret
Any Ideas?
Thanks,
--
Peter Jansen
STS
Australian Antarctic Division
Channel Highway
Kingston
TAS 7050
AUSTRALIA
Ph (03) 62 323 533
Fax (03) 62 323 351