When initializing globals, it looks like the register
bank is selected only for the first variable, however
they may not all be in the same bank when they are
allocated (particularly as you start to use more data).
sdcc version:
2.5.4 #1183 (Dec 10 2005)
command used:
sdcc/bin/sdcc -c -mpic14 -p16f627 bug5.c && gplink -m
-c -o bug.hex bug5.o
Sample code (bug5.c):
------------------------
#define __16f627
#include <pic/pic16f627.h>
char x1 = 1;
char stuff1[49];
char x9 = 9;
char stuff1a[29];
char x2 = 2;
char stuff2[62];
char x3 = 3;
char stuff3[46];
char x4 = 4;
char stuff4[6];
char x5 = 5;
void main()
{
}
------------------------
Looking at the map file produced by the linker, the
data is spanning a few banks:
_x1 0x0000ee data
extern bug5.asm
_stuff1 0x0000a0 data
extern bug5.asm
_x9 0x00014e data
extern bug5.asm
_stuff1a 0x0000d1 data
extern bug5.asm
_x2 0x000064 data
extern bug5.asm
_stuff2 0x000020 data
extern bug5.asm
_x3 0x000065 data
extern bug5.asm
_stuff3 0x000120 data
extern bug5.asm
_x4 0x000066 data
extern bug5.asm
_stuff4 0x00005e data
extern bug5.asm
_x5 0x000067 data
extern bug5.asm
The initialisation code only sets the bank at the
start, however it can't do that because some of them
will be allocated to different banks at link time.
MOVLW 0x01
BANKSEL _x1
MOVWF _x1
MOVLW 0x09
MOVWF _x9
MOVLW 0x02
MOVWF _x2
MOVLW 0x03
MOVWF _x3
MOVLW 0x04
MOVWF _x4
MOVLW 0x05
MOVWF _x5
This may be a more general problem than just global
initialization, but I haven't checked.
Logged In: YES
user_id=1304410
Oh, also, here is the include file referred to by the code.
Logged In: YES
user_id=849691
> This may be a more general problem than just global
> initialization, but I haven't checked.
Correct it is.
The SDCC PIC 14 port does not support the ability to
allocate data into named data sections. Where the linker
places the data is not known to the compiler, it only
assumes that it will be in the same bank for that C file.
In this example the data is too big to fit into a single
bank and the linker then decides to place it across
multiple banks, of course the compiler has not provided any
BANKSEL statements so the code will not run correctly.
Although I am puzzled as I had believed that all the data
from a separate 'C' file went into an individual data bank,
which sould mean the linker ought to give an error and not
separate the data.
It is possible however to use multiple ram banks with SDCC
PIC 14 port. It require carefully placing the data into
different C files and declaring them static. When a global
(non static) function is called the complier will generate
a BANKSEL when it first accesses it's local variable (as in
this example where function main as generated a BANKSEL).
Supporting named data section within the PIC 14 port will
require some effort to achieve - volunteers needed. (The
linker should then keep all named data sections in one
bank, generating an error if it does not fit.) This will
allow code in a single C file to refer to data that are in
different RAM banks and generate correct the BANKSEL code.
Logged In: YES
user_id=1304410
Oh, sorry, I knew that from previous occasions (and the
documentation), but had a brain outage and forgot. I had to
remove my statics and carefully allocated variables because
I was having some other new problems with sdcc and statics.
I'll see if I can find that problem instead. Thanks.
Logged In: YES
user_id=1115835
Fixed in r4411.