Hello Dimy and others Attached is a C file and the listing produced. I was having some problems (MSP430 was crashing, etc) as soon as I tried to pass the address of a struct within a struct. For example in MainFunction() line 36 DoSomeStuffToInnerStruct(&myStruct.correctStruct) produces this code: mov #myStruct, r15 call #DoSomeStuffToInnerStruct which looks fine to me. The next call looks odd though: DoSomeStuffToInnerStruct(&myStruct.incorrectStruct) produces: mov &myStruct+4, r15 call #DoSomeStuffToInnerStruct
I am pretty concerned about the address calculation which seems to be placing into r15 the CONTENTS of myStruct+4 rather than the address of myStruct+4 ie. the '&' should be a '#' like the line above. To compare I made another struct that uses addresses instead of instances and see that there the code is correct and uses the contents of the pointer rather than the address. Please can someone tell me if I have missed something obvious here. Thanks. Colin --------------------------------------------------------------------------------- Colin Domoney Digital Hardware Design Engineer NCipher, Jupiter House, Station Road, Cambridge, CB1 2JD e-mail: [email protected] Telephone: +44-1223-723630
The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.
---- File information -----------
File: buggy.c
Date: 2 Apr 2002, 15:17
Size: 955 bytes.
Type: Program-source
buggy.c
Description: Binary data
GAS LISTING /cygdrive/c/TEMP/ccZ6ezT5.s page 1
1 .file "buggy.c"
2 .arch msp430x149
3
4 /* Hardware multiplier registers: */
5 __MPY=0x130
6 __MPYS=0x132
7 __MAC=0x134
8 __MACS=0x136
9 __OP2=0x138
10 __RESLO=0x13a
11 __RESHI=0x13c
12 __SUMEXT=0x13e
13
14 .stabs
"/cygdrive/e/Design/TamperDetect/Dev/Main/",100,0,0,.Ltext0
15 .stabs "buggy.c",100,0,0,.Ltext0
16 .text
17 .Ltext0:
18 .stabs "gcc2_compiled.",60,0,0,0
19 .stabs
"int:t(0,1)=r(0,1);-32768;32767;",128,0,0,0
20 .stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
21 .stabs "long
int:t(0,3)=...@s32;r(0,3);0020000000000;0017777777777;",128,0,0,0
22 .stabs "unsigned
int:t(0,4)=r(0,4);0000000000000;0000000177777;",128,0,0,0
23 .stabs "long unsigned
int:t(0,5)=...@s32;r(0,5);0000000000000;0037777777777;",128,0,0,0
24 .stabs "long long
int:t(0,6)=...@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,0,
25 .stabs "long long unsigned
int:t(0,7)=...@s64;r(0,7);0000000000000;01777777777777777777777;",128,0,0,
26 .stabs "short
int:t(0,8)=r(0,8);-32768;32767;",128,0,0,0
27 .stabs "short unsigned
int:t(0,9)=r(0,9);0000000000000;0000000177777;",128,0,0,0
28 .stabs "signed
char:t(0,10)=...@s8;r(0,10);-128;127;",128,0,0,0
29 .stabs "unsigned
char:t(0,11)=...@s8;r(0,11);0;255;",128,0,0,0
30 .stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
31 .stabs "double:t(0,13)=r(0,1);4;0;",128,0,0,0
32 .stabs "long
double:t(0,14)=r(0,1);4;0;",128,0,0,0
33 .stabs "complex
int:t(0,15)=s4real:(0,1),0,16;imag:(0,1),16,16;;",128,0,0,0
34 .stabs "complex
float:t(0,16)=r(0,16);8;0;",128,0,0,0
35 .stabs "complex
double:t(0,17)=r(0,17);8;0;",128,0,0,0
36 .stabs "complex long
double:t(0,18)=r(0,18);8;0;",128,0,0,0
37 .stabs
"__builtin_va_list:t(0,19)=*(0,20)=(0,20)",128,0,0,0
38 .stabs "_Bool:t(0,21)=...@s8;-16;",128,0,0,0
39 .stabs
"_INNER_STRUCT:T(0,22)=s4inner_val1:(0,4),0,16;inner_val2:(0,4),16,16;;",128,0,0,0
40 .stabs "INNER_STRUCT:t(0,23)=(0,22)",128,0,5,0
41 .stabs
"_OUTER_STRUCT:T(0,24)=s10correctStruct:(0,23),0,32;incorrectStruct:(0,23),32,32;outer_val1
42 .stabs "OUTER_STRUCT:t(0,25)=(0,24)",128,0,15,0
43 .stabs
"_OUTER_STRUCT_2:T(0,26)=s6correctStruct:(0,27)=*(0,23),0,16;incorrectStruct:(0,27),16,16;o
44 .stabs
"OUTER_STRUCT_2:t(0,28)=(0,26)",128,0,22,0
45 .data
46 .stabs "myStruct2:S(0,28)",38,0,25,myStruct2
47 .p2align 1,0
48 .type myStruct2,@object
49 .size myStruct2,6
50 myStruct2:
51 0000 0000 .word is1
52 0002 0000 .word is2
53 0004 0000 .word 0
54 .text
55 .p2align 1,0
56 .stabs
"MainFunction:F(0,20)",36,0,35,MainFunction
57 .global MainFunction
GAS LISTING /cygdrive/c/TEMP/ccZ6ezT5.s page 2
58 .type MainFunction,@function
59 /***********************
60 * Function `MainFunction'
61 ***********************/
62 MainFunction:
1:buggy.c **** typedef struct _INNER_STRUCT
2:buggy.c **** {
3:buggy.c **** unsigned int inner_val1;
4:buggy.c **** unsigned int inner_val2;
5:buggy.c **** } INNER_STRUCT;
6:buggy.c ****
7:buggy.c **** INNER_STRUCT is1;
8:buggy.c **** INNER_STRUCT is2;
9:buggy.c ****
10:buggy.c **** typedef struct _OUTER_STRUCT
11:buggy.c **** {
12:buggy.c **** INNER_STRUCT correctStruct;
13:buggy.c **** INNER_STRUCT incorrectStruct;
14:buggy.c **** unsigned int outer_val1;
15:buggy.c **** } OUTER_STRUCT;
16:buggy.c ****
17:buggy.c **** typedef struct _OUTER_STRUCT_2
18:buggy.c **** {
19:buggy.c **** INNER_STRUCT *correctStruct;
20:buggy.c **** INNER_STRUCT *incorrectStruct;
21:buggy.c **** unsigned int outer_val1;
22:buggy.c **** } OUTER_STRUCT_2;
23:buggy.c ****
24:buggy.c **** static OUTER_STRUCT myStruct;
25:buggy.c **** static OUTER_STRUCT_2 myStruct2 =
26:buggy.c **** {
27:buggy.c **** &is1,
28:buggy.c **** &is2,
29:buggy.c **** 0x00
30:buggy.c **** };
31:buggy.c ****
32:buggy.c **** static void DoSomeStuffToInnerStruct(INNER_STRUCT *is);
33:buggy.c ****
34:buggy.c **** void MainFunction(void)
35:buggy.c **** {
63 .stabn 68,0,35,.LM1-MainFunction
64 .LM1:
65 /* prologue: frame size = 0; addenum 0; alloca:0,
varargs:0 , fpr:0*/
66 .L__FrameSize_MainFunction=0x0
67 /* prologue end (size=0) */
36:buggy.c ****
DoSomeStuffToInnerStruct(&myStruct.correctStruct);
68 .stabn 68,0,36,.LM2-MainFunction
69 .LM2:
70 0000 3F40 0000 mov #myStruct, r15
71 0004 B012 0000 call #DoSomeStuffToInnerStruct
37:buggy.c ****
DoSomeStuffToInnerStruct(&myStruct.incorrectStruct);
72 .stabn 68,0,37,.LM3-MainFunction
73 .LM3:
74 0008 1F42 0000 mov &myStruct+4, r15
75 000c B012 0000 call #DoSomeStuffToInnerStruct
38:buggy.c ****
39:buggy.c ****
DoSomeStuffToInnerStruct(myStruct2.correctStruct);
GAS LISTING /cygdrive/c/TEMP/ccZ6ezT5.s page 3
76 .stabn 68,0,39,.LM4-MainFunction
77 .LM4:
78 0010 1F42 0000 mov &myStruct2, r15
79 0014 B012 0000 call #DoSomeStuffToInnerStruct
40:buggy.c ****
DoSomeStuffToInnerStruct(myStruct2.incorrectStruct);
80 .stabn 68,0,40,.LM5-MainFunction
81 .LM5:
82 0018 1F42 0000 mov &myStruct2+2, r15
83 001c B012 0000 call #DoSomeStuffToInnerStruct
41:buggy.c **** }
84 .stabn 68,0,41,.LM6-MainFunction
85 .LM6:
86 /* epilogue: frame size=0 */
87 0020 3041 ret
88 /* epilogue end (size=1) */
89 /* function MainFunction size 17 (16) */
90 .Lfe1:
91 .size MainFunction,.Lfe1-MainFunction
92 /********* End of function ******/
93
94 .Lscope0:
95 .stabs "",36,0,0,.Lscope0-MainFunction
96 .p2align 1,0
97 .stabs
"DoSomeStuffToInnerStruct:f(0,20)",36,0,44,DoSomeStuffToInnerStruct
98 .stabs "is:P(0,27)",64,0,43,12
99 .type DoSomeStuffToInnerStruct,@function
100 /***********************
101 * Function `DoSomeStuffToInnerStruct'
102 ***********************/
103 DoSomeStuffToInnerStruct:
42:buggy.c ****
43:buggy.c **** void DoSomeStuffToInnerStruct(INNER_STRUCT *is)
44:buggy.c **** {
104 .stabn 68,0,44,.LM7-DoSomeStuffToInnerStruct
105 .LM7:
106 /* prologue: frame size = 0; addenum 0; alloca:0,
varargs:0 , fpr:0*/
107 .L__FrameSize_DoSomeStuffToInnerStruct=0x0
108 /* prologue end (size=0) */
109 0022 0C4F mov r15, r12
45:buggy.c **** is->inner_val1 = 0x01;
110 .stabn 68,0,45,.LM8-DoSomeStuffToInnerStruct
111 .LM8:
112 0024 9C43 0000 mov #llo(1), @r12
46:buggy.c **** is->inner_val2 = 0x02;
113 .stabn 68,0,46,.LM9-DoSomeStuffToInnerStruct
114 .LM9:
115 0028 AC43 0200 mov #llo(2), 2(r12)
47:buggy.c **** }
116 .stabn 68,0,47,.LM10-DoSomeStuffToInnerStruct
117 .LM10:
118 /* epilogue: frame size=0 */
119 002c 3041 ret
120 /* epilogue end (size=1) */
121 /* function DoSomeStuffToInnerStruct size 6 (5) */
122 .Lfe2:
123 .size
DoSomeStuffToInnerStruct,.Lfe2-DoSomeStuffToInnerStruct
124 /********* End of function ******/
GAS LISTING /cygdrive/c/TEMP/ccZ6ezT5.s page 4
125
126 .Lscope1:
127 .stabs
"",36,0,0,.Lscope1-DoSomeStuffToInnerStruct
128 .stabs "is1:G(0,23)",32,0,7,0
129 .p2align 1,0
130 .comm is1,4,2
131 .stabs "is2:G(0,23)",32,0,8,0
132 .p2align 1,0
133 .comm is2,4,2
134 .stabs "myStruct:S(0,25)",40,0,24,myStruct
135 .p2align 1,0
136 .lcomm myStruct,10
137 .text
138 .stabs "",100,0,0,Letext
139 Letext:
140
141
/*********************************************************************
142 * File buggy.c: code size: 23 words (0x17)
143 * incl. words in prologues: 0, epilogues: 2
144
*********************************************************************/
GAS LISTING /cygdrive/c/TEMP/ccZ6ezT5.s page 5
DEFINED SYMBOLS
*ABS*:00000000 buggy.c
*ABS*:00000130 __MPY
*ABS*:00000132 __MPYS
*ABS*:00000134 __MAC
*ABS*:00000136 __MACS
*ABS*:00000138 __OP2
*ABS*:0000013a __RESLO
*ABS*:0000013c __RESHI
*ABS*:0000013e __SUMEXT
/cygdrive/c/TEMP/ccZ6ezT5.s:50 .data:00000000 myStruct2
*COM*:00000004 is1
*COM*:00000004 is2
/cygdrive/c/TEMP/ccZ6ezT5.s:62 .text:00000000 MainFunction
.bss:00000000 myStruct
/cygdrive/c/TEMP/ccZ6ezT5.s:103 .text:00000022 DoSomeStuffToInnerStruct
/cygdrive/c/TEMP/ccZ6ezT5.s:139 .text:0000002e Letext
*ABS*:00000000 *ABS*
NO UNDEFINED SYMBOLS
