From reading the sdcc documentation, bank switching for the mcs51 is
supported through the sdcc specific keyword __banked, a codeseg
command line switch (or inline pragma) and the trampoline calls
__sdcc_banked_call and __sdcc_banked_ret. The cc2430 chip that I am
using provides a bank switching SFR called FMAP that is functionally
similar to the crtbank.asm examples PSBANK, therefore I expect the
crtbank.asm trampoline should work with no changes. However when I
mark any routine as banked, even if it is in the HOME bank, the code
does not work...
Changes that I notice when using banking:
The trampoline functions get added to final map file (demo.map)
Area Addr Size Decimal Bytes
-------------------------------- ---- ---- ------- -----
HOME 0000 00AC = 172. bytes
** Is the location of __sdcc_banked_call at address 0000 in the HOME
segment a problem? I expected the start up routines would normally go
** From discussions with some other users of the cc2430/sdcc, it seems
the banked mode does not work as described in the documentation.
Specifically, I have been informed of some undocumented requirements...
- generated hex file is in an unusual format that is not compatible
with "commercial" programmers and must converted somehow
- all code must be assigned to a bank, it will not work if any code
- all banks must have some code assigned to it
** Does anyone have the documented approach to bank switching
working? Is there some source code online that I can study?
** If the documented method does not work, I would be willing to help
update the documentation if someone can explain the current
requirements and implementation.
Here are the bank switching assembly routines...
.area HOME (CODE)
push _PSBANK ;save return bank
xch a,r0 ;save Acc in r0, do not assume any
push acc ;push LSB address
push acc ;push MSB address
mov a,r2 ;get new bank
anl a,#0x0F ;remove storage class indicator
orl _PSBANK,a ;select bank
xch a,r0 ;restore Acc
ret ;make the call
pop _PSBANK ;restore bank
ret ;return to caller
Generated assembly code for a banked call:
; demo.c:82: abc=hello_world();
mov r1,#(_hello_world >> 8)
mov r2,#(_hello_world >> 16)
; hello_world.c:15: return 123;
- the parameters passed on the stack to banked routine would come
before _PSBANK. Will the banked routine skip over the stored _PSBANK
to reach them? So far I have only attempted to routines without