Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1096 Compiler does not initialize static data

closed-duplicate
nobody
5
2006-04-12
2006-04-12
Anonymous
No

I'm using the DS80C400 and dallas evaluation card.

At first, there are a couple of small bugs in the main
makefile (has been there for some months now)

1-wire > diff sdcc/Makefile sdcc.patched/Makefile
79c79
< $(MAKE) -C device/lib modelDS390
---
> $(MAKE) -C device/lib model-ds390 model-ds400
107c107
< $(MAKE) -C device/lib installDS390
---
> $(MAKE) -C device/lib install

Then what is more problemous is when im compiling this
file:
1-wire > cat foo.c
extern int printf (const char *,...);

int main (void)
{
static unsigned char dscrc_table[256] = {
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83};

int i;

printf ("\n\nFOO\tBAAR\n");

for (i = 0; i < 8; i++)
printf ("0x%x ", dscrc_table[i]);

printf ("\n\nFOO\tBAAR\n");

return 0;
}

And the resulting assembler-file:
1-wire > cat foo.lst
1
;--------------------------------------------------------
2 ; File Created by SDCC
: FreeWare ANSI-C Compiler
3 ; Version 2.5.6 #1246
(Apr 12 2006)
4 ; This file generated
Wed Apr 12 18:39:40 2006
5
;--------------------------------------------------------
6 .module main
7 .optsdcc -mds400
--model-flat24
8
9
;--------------------------------------------------------
10 ; CPU specific extensions
11
;--------------------------------------------------------
12 .flat24 on ; 24 bit
flat addressing
0084 13 dpl1 = 0x84
0085 14 dph1 = 0x85
0086 15 dps = 0x86
0093 16 dpx = 0x93
0095 17 dpx1 = 0x95
009B 18 esp = 0x9B
009C 19 ap = 0x9C
009C 20 _ap = 0x9C
00D1 21 mcnt0 = 0xD1
00D2 22 mcnt1 = 0xD2
00D3 23 ma = 0xD3
00D4 24 mb = 0xD4
00D5 25 mc = 0xD5
00D1 26 F1 = 0xD1 ; user flag
27
;--------------------------------------------------------
28 ; Public variables in
this module
29
;--------------------------------------------------------
30 .globl _main
31
;--------------------------------------------------------
32 ; special function
registers
33
;--------------------------------------------------------
34
;--------------------------------------------------------
35 ; special function bits
36
;--------------------------------------------------------
37
;--------------------------------------------------------
38 ; overlayable register
banks
39
;--------------------------------------------------------
40 .area REG_BANK_0
(REL,OVR,DATA)
0000 41 .ds 8
42 .area REG_BANK_3
(REL,OVR,DATA)
0000 43 .ds 8
44
;--------------------------------------------------------
45 ; internal ram data
46
;--------------------------------------------------------
47 .area DSEG (DATA)
48
;--------------------------------------------------------
49 ; overlayable items in
internal ram
50
;--------------------------------------------------------
51 .area OSEG (OVR,DATA)
52
;--------------------------------------------------------
53 ; Stack segment in
internal ram
54
;--------------------------------------------------------
55 .area SSEG (DATA)
0000 56 __start__stack:
0000 57 .ds 1
58
59
;--------------------------------------------------------
60 ; indirectly
addressable internal ram data
61
;--------------------------------------------------------
62 .area ISEG (DATA)
63
;--------------------------------------------------------
64 ; bit data
65
;--------------------------------------------------------
66 .area BSEG (BIT)
67
;--------------------------------------------------------
68 ; paged external ram data
69
;--------------------------------------------------------
70 .area PSEG (PAG,XDATA)
71
;--------------------------------------------------------
72 ; external ram data
73
;--------------------------------------------------------
74 .area XSEG (XDATA)
0000 75 _main_dscrc_table_1_1:
0000 76 .ds 256
77
;--------------------------------------------------------
78 ; external initialized
ram data
79
;--------------------------------------------------------
80
;--------------------------------------------------------
81 ; the direct data area
used by the DS80c400 ROM code.
82
;--------------------------------------------------------
83 .area ROMSEG (ABS,CON,DATA)
84
0000 85 .ds 24 ; 24 bytes of
directs used starting at 0x68
86
87
;--------------------------------------------------------
88 ; interrupt vector
89
;--------------------------------------------------------
90 .area HOME (CODE)
0000 91 __interrupt_vect:
92 ; DS80C400 IVT must be
generated at runtime.
0000 80 05 93 sjmp __sdcc_400boot
0002 54 49 4E 49 94 .ascii 'TINI' ;
required signature for 400 boot loader.
0006 00 95 .db 0 ; selected bank:
zero *should* work...
0007 02s00r00r00 96 __sdcc_400boot: ljmp
__sdcc_gsinit_startup
97
;--------------------------------------------------------
98 ; global & static
initialisations
99
;--------------------------------------------------------
100 .area HOME (CODE)
101 .area GSINIT (CODE)
102 .area GSFINAL (CODE)
103 .area GSINIT (CODE)
0000 104 __sdcc_gsinit_startup:
0000 12s00r00r00 105 lcall
__sdcc_external_startup
0004 E5 82 106 mov a,dpl
0006 60 04 107 jz __sdcc_init_data
0008 02s00r00r00 108 ljmp
__sdcc_program_startup
000C 109 __sdcc_init_data:
110
;------------------------------------------------------------
111 ;Allocation info for
local variables in function 'main'
112
;------------------------------------------------------------
113 ;dscrc_table
Allocated with name '_main_dscrc_table_1_1'
114 ;i
Allocated to registers
115
;------------------------------------------------------------
116 ; main.c:5: static
unsigned char dscrc_table[256] = {
117 .area GSFINAL (CODE)
0000 02s00r00r00 118 ljmp
__sdcc_program_startup
119
;--------------------------------------------------------
120 ; Home
121
;--------------------------------------------------------
122 .area HOME (CODE)
123 .area CSEG (CODE)
0000 124 __sdcc_program_startup:
0000 12s00r00r06 125 lcall _main
126 ; return from main will
lock up
0004 80 FE 127 sjmp .
128
;--------------------------------------------------------
129 ; code
130
;--------------------------------------------------------
131 .area CSEG (CODE)
132
;------------------------------------------------------------
133 ;Allocation info for
local variables in function 'main'
134
;------------------------------------------------------------
135 ;dscrc_table
Allocated with name '_main_dscrc_table_1_1'
136 ;i
Allocated to registers
137
;------------------------------------------------------------
138 ; main.c:3: int main (void)
139 ; genFunction
140 ;
-----------------------------------------
141 ; function main
142 ;
-----------------------------------------
0006 143 _main:
0002 144 ar2 = 0x02
0003 145 ar3 = 0x03
0004 146 ar4 = 0x04
0005 147 ar5 = 0x05
0006 148 ar6 = 0x06
0007 149 ar7 = 0x07
0000 150 ar0 = 0x00
0001 151 ar1 = 0x01
152 ; main.c:10: printf
("\n\nFOO\tBAAR\n");
153 ; genIpush
0006 74r00 154 mov a,#__str_0
0008 C0 E0 155 push acc
000A 74s00 156 mov a,#(__str_0 >> 8)
000C C0 E0 157 push acc
000E 74s00 158 mov a,#(__str_0 >> 16)
0010 C0 E0 159 push acc
0012 74 80 160 mov a,#0x80
0014 C0 E0 161 push acc
162 ; genCall
0016 12s00r00r00 163 lcall _printf
164 ; stack adjustment for
parms
001A D0 E0 165 pop acc
001C D0 E0 166 pop acc
001E D0 E0 167 pop acc
0020 D0 E0 168 pop acc
169 ; main.c:12: for (i =
0; i < 8; i++)
170 ; genAssign
171 ; genAssign:
resultIsFar = FALSE
0022 7A 00 172 mov r2,#0x00
0024 7B 00 173 mov r3,#0x00
174 ; genLabel
0026 175 00101$:
176 ; genCmpLt
177 ; genCmp
0026 C3 178 clr c
0027 EA 179 mov a,r2
0028 94 08 180 subb a,#0x08
002A EB 181 mov a,r3
002B 64 80 182 xrl a,#0x80
002D 94 80 183 subb a,#0x80
184 ; genIfxJump
185 ; Peephole 108
removed ljmp by inverse jump logic
002F 50 46 186 jnc 00104$
0031 187 00110$:
188 ; main.c:13: printf
("0x%x ", dscrc_table[i]);
189 ; genPlus
0031 EA 190 mov a,r2
0032 24r00 191 add
a,#_main_dscrc_table_1_1
0034 F5 82 192 mov dpl,a
0036 EB 193 mov a,r3
0037 34s00 194 addc
a,#(_main_dscrc_table_1_1 >> 8)
0039 F5 83 195 mov dph,a
196 ; Peephole 3.d
changed mov to clr
003B E4 197 clr a
003C 34s00 198 addc
a,#(_main_dscrc_table_1_1 >> 16)
003E F5 93 199 mov dpx,a
200 ; genPointerGet
201 ; genFarPointerGet
0040 E0 202 movx a,@dptr
0041 FC 203 mov r4,a
204 ; genCast
0042 7D 00 205 mov r5,#0
206 ; genIpush
0044 C0 02 207 push ar2
0046 C0 03 208 push ar3
0048 C0 04 209 push ar4
004A C0 05 210 push ar5
211 ; genIpush
004C 74r0C 212 mov a,#__str_1
004E C0 E0 213 push acc
0050 74s00 214 mov a,#(__str_1 >> 8)
0052 C0 E0 215 push acc
0054 74s00 216 mov a,#(__str_1 >> 16)
0056 C0 E0 217 push acc
0058 74 80 218 mov a,#0x80
005A C0 E0 219 push acc
220 ; genCall
005C 12s00r00r00 221 lcall _printf
222 ; stack adjustment for
parms
0060 D0 E0 223 pop acc
0062 D0 E0 224 pop acc
0064 D0 E0 225 pop acc
0066 D0 E0 226 pop acc
0068 D0 E0 227 pop acc
006A D0 E0 228 pop acc
006C D0 03 229 pop ar3
006E D0 02 230 pop ar2
231 ; main.c:12: for (i =
0; i < 8; i++)
232 ; genPlus
0070 0A 233 inc r2
0071 BA 00 01 234 cjne r2,#0,00111$
0074 0B 235 inc r3
0075 236 00111$:
237 ; did genPlusIncr
238 ; genGoto
239 ; genLabel
240 ; Peephole 132
changed ljmp to sjmp
0075 80 AF 241 sjmp 00101$
0077 242 00104$:
243 ; main.c:15: printf
("\n\nFOO\tBAAR\n");
244 ; genIpush
0077 74r00 245 mov a,#__str_0
0079 C0 E0 246 push acc
007B 74s00 247 mov a,#(__str_0 >> 8)
007D C0 E0 248 push acc
007F 74s00 249 mov a,#(__str_0 >> 16)
0081 C0 E0 250 push acc
0083 74 80 251 mov a,#0x80
0085 C0 E0 252 push acc
253 ; genCall
0087 12s00r00r00 254 lcall _printf
255 ; stack adjustment for
parms
008B D0 E0 256 pop acc
008D D0 E0 257 pop acc
008F D0 E0 258 pop acc
0091 D0 E0 259 pop acc
260 ; main.c:17: return 0;
261 ; genRet
262 ; Peephole 181 used
16 bit load of dptr
0093 90 00 00 00 263 mov dptr,#0x0000
264 ; genLabel
0097 265 00105$:
266 ; genEndFunction
0097 22 267 ret
268 .area CSEG (CODE)
269 .area CONST (CODE)
0000 270 __str_0:
0000 0A 271 .db 0x0A
0001 0A 272 .db 0x0A
0002 46 4F 4F 273 .ascii "FOO"
0005 09 274 .db 0x09
0006 42 41 41 52 275 .ascii "BAAR"
000A 0A 276 .db 0x0A
000B 00 277 .db 0x00
000C 278 __str_1:
000C 30 78 25 78 20 279 .ascii "0x%x "
0011 00 280 .db 0x00

The cmd-line:
sdcc -c -mds400 --model-flat24 --stack-10bit
--no-xinit-opt main.c

BUT!! When i use this cmd-line, all data are
initialized OK!
sdcc -c -mds390 --model-flat24 --stack-10bit
--no-xinit-opt main.c

Somewhere the static initializing-code is dropped, when
i compile for the ds400..

If You need more info, mail me. anders.bjork@vattnet.com

Keep up Your good work!
/Anders

Discussion

  • Maarten Brock
    Maarten Brock
    2006-04-12

    • status: open --> closed-duplicate