Crossware

Table of Contents        Previous topic       Next topic       

C COMPILER->Code Bank Switching->Setting up the linker

When you compile C source files containing the bank pragma, the program code for the functions affected are placed in special segments.  This enables the linker to identify them and place them in the appropriate banks.

You tell the linker about the available code banks using the /ROM option.

For example the following linker options tell the linker that there are three code banks number 0, 1 and 2 each with an address range from 0X8000 to 0XFFFF:

/ROM:8000:FFFF:0 /ROM:8000:FFFF:1 /ROM:8000:FFFF:2

The bank numbers correspond to the bank numbers used in the bank pragma.

If you are using the Embedded Development Studio, then you can use the Advanced option in the linker settings to set up your code banks.  Build->Settings->Linker->Advanced.

All bank switching code is located in non-banked code space.  Therefore banked code regions must not overlap the address space of non-banked code.  So if code banks are located at addresses 0X8000 to 0XFFFF, non-banked code can only be from 0X0000 to 0X7FFF. Therefore if your target system has a default region of memory from 0X0000 to 0XFFFF, then for this example the region from 0X8000 to 0XFFFF must be setup as a switchable bank.  (If you want both banked and unbanked code detsined for this default region to go into a single program file so that you can program a single eprom in one operation, then make this particular switchable bank bank zero).

If a bank pragma for a particular bank number is used in your C source but the corresponding bank range is not specified to the linker, then the bank pragma will be ignored and the corresponding functions will be located in non-banked code.  The linker will also issue a warning.