On inspection of the UNUSED ADDRESS RANGES in the map file f_sym.map (this file is overwritten later, but has been included as forg_sym.map for reference here), we can determine the amount of RAM that the fixed code requires for all the memory banks. Our example shows that only BANK0 is used. The default memory range available in bank 0 is from 1Ch to FFh. (Look at the -ABANK0 linker option in this file.) The unused BANK0 memory extended from 28h to C5h (see the UNUSED ADDRESS RANGES in this file). This means that the address range 1Ch to 27h was used (Ch locations) and from C6h to FFh was used (3Ah locations). The total memory required is 46h locations. We will now adjust the linker options so that the linker will allocate all the memory at the lower end of the available bank 0 range from 1Ch to 61h. (1Ch + 46h - 1 = 61h) The upper range of this memory will then be available for the replaceable code. The memory allocated to the internal code is changed in the linker file to reflect this. The new bank 0 memory range available to the linker is specified by the options:
-ABANK0=001Ch-0061h
The next step is to localize certain global symbols from the symbol-only object file. The reason for this is that we want to linker to re-link the code/data associated with these symbols rather than using the symbols that were defined in the fixed code. Localizing them tells the linker that it cannot use any
Split code for PICs
globally defined symbols that it may have seen and that it will have to search for a new definition. For example, the copy_data routine is already defined by the internal code to initialize variables that that code uses. But this code will be using the address range applicable for the fixed code and does not know about variables defined elsewhere. To force the linker to link in another copy_data routine specific for the replaceable code we essentially undefine the symbol by localizing it. If there are any routines defined in the fixed code that you do not want the external code to use then include their name here. You must then ensure that you provide the definition for the routines in the external code. The XSTRIP utility can be used as shown.
XSTRIP -start,_exit,intlevel0,intlevel1,copy_data,clear_ram, copy_bank0,clear_bank0 f_sym.obj
Start by copying the symbol-only linker file and renaming it, in our example it has been copied and renamed to f_abs.lnk. The -F and -I options are removed. The map, object and symbol files have been changed to f_abs.map, f_abs.obj and f_abs.sym, respectively (i.e. options -Mf_abs.map Of_abs.obj -H+f_abs.sym).
This file is then used to link the relevant output files.
HLINK < f_abs.lnk
As described in the PICC Manual, copy the picrt66x.as and sfr.h files from the SOURCES subdirectory of your distribution. (You can rename the run-time file so that it is not confused with the standard run-time module - in this case it has been renamed to extrt.as). Now, within this renamed run-time file, replace all references to the symbol _main to the assembler name of the external main function. In our example, the main function of the external code has been called ext_main(), hence all references to _main would be replaced with _ext_main.
Copy and rename the linker file used for the absolute object file (in our example, the f_abs.lnk has been copied and renamed to replace.lnk). The output map, object and symbol files are changed to replace.map, replace.obj and replace.sym, respectively (i.e. options -Mreplace.map Oreplace.obj -H+replace.sym).
As the internal code only used the RAM in the addresses 001Ch - 0061h, we can allocate the remaining addresses to the external code using the following linker option.
-ABANK0=0062h-00FFh
The ROM settings are changed so that only external memory is defined.
PIC Tutorials
-ACODE=4000h-5FFDh
The ROMDATA class is changed so that it only uses the external memory ROM space of 8000h - BFFFh.
-AROMDATA=8000h-BFFFh
Change the init psect’s address.
-pintcode=08h,powerup=00h,init=4100h,end_init,clrtxt
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.