Hello SDCC-users,

   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 (Attributes)
--------------------------------   ----   ----   ------- ----- ------------
HOME                               0000   00AC =    172. bytes 
(REL,CON,CODE)

       Value  Global
    --------  --------------------------------
   0C:0000    __sdcc_banked_call
   0C:0016    __sdcc_banked_ret
   0C:009F    __sdcc_program_startup
   0C:00A4    __sdcc_call_dptr
   0C:00A6    _hello_world


** 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 
at 0000.

** 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 
is unassigned
   - 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)

__sdcc_banked_call::
         push    _PSBANK         ;save return bank
         xch     a,r0            ;save Acc in r0, do not assume any 
register bank
         push    acc             ;push LSB address
         mov     a,r1
         push    acc             ;push MSB address
         mov     a,r2            ;get new bank
         anl     a,#0x0F         ;remove storage class indicator
         anl     _PSBANK,#0xF0
         orl     _PSBANK,a       ;select bank
         xch     a,r0            ;restore Acc
         ret                     ;make the call

__sdcc_banked_ret::
         pop     _PSBANK         ;restore bank
         ret                     ;return to caller


Generated assembly code for a banked call:

;       demo.c:82: abc=hello_world();
         mov     r0,#_hello_world
         mov     r1,#(_hello_world >> 8)
         mov     r2,#(_hello_world >> 16)
         lcall   __sdcc_banked_call
         mov     r2,dpl
         mov     r3,dph



;       hello_world.c:15: return 123;
         mov     dptr,#0x007B
         ljmp    __sdcc_banked_ret


Questions:

   - 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 parameters.




------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to