// File: 16f570_g.lkr
// Generic linker script for the PIC16F570 processor

#DEFINE _CODEEND _DEBUGCODESTART - 1
#DEFINE _CEND _CODEEND + _DEBUGCODELEN
#DEFINE _DATAEND _DEBUGDATASTART - 1
#DEFINE _DEND _DATAEND + _DEBUGDATALEN

LIBPATH .

CODEPAGE   NAME=page0      START=0x0               END=0x1FF                    
CODEPAGE   NAME=page1      START=0x200             END=0x3FF                    
CODEPAGE   NAME=page2      START=0x400             END=0x5FF                    

#IFDEF _DEBUGCODESTART
  CODEPAGE   NAME=page3      START=0x600             END=_CODEEND
  CODEPAGE   NAME=debug      START=_DEBUGCODESTART   END=_CEND        PROTECTED
#ELSE
  CODEPAGE   NAME=page3      START=0x600             END=0x7FF                    
#FI

CODEPAGE   NAME=flashdata  START=0x800             END=0x83F          PROTECTED 
CODEPAGE   NAME=.idlocs    START=0x840             END=0x843          PROTECTED 
CODEPAGE   NAME=.config    START=0xFFF             END=0xFFF          PROTECTED 

DATABANK   NAME=sfr0       START=0x0               END=0xB            PROTECTED
DATABANK   NAME=sfr1       START=0x20              END=0x2B           PROTECTED
DATABANK   NAME=sfr2       START=0x40              END=0x4B           PROTECTED
DATABANK   NAME=sfr3       START=0x60              END=0x6B           PROTECTED
DATABANK   NAME=sfr4       START=0x80              END=0x8B           PROTECTED
DATABANK   NAME=sfr5       START=0xA0              END=0xAB           PROTECTED
DATABANK   NAME=sfr6       START=0xC0              END=0xCB           PROTECTED
DATABANK   NAME=sfr7       START=0xE0              END=0xEB           PROTECTED

DATABANK   NAME=gpr0b      START=0x10              END=0x1F           
DATABANK   NAME=gpr1b      START=0x30              END=0x3F           
DATABANK   NAME=gpr2b      START=0x50              END=0x5F           
DATABANK   NAME=gpr3b      START=0x70              END=0x7F           
DATABANK   NAME=gpr4a      START=0x8C              END=0x8F           
DATABANK   NAME=gpr4b      START=0x90              END=0x9F           
DATABANK   NAME=gpr5a      START=0xAC              END=0xAF           
DATABANK   NAME=gpr5b      START=0xB0              END=0xBF           
DATABANK   NAME=gpr6a      START=0xCC              END=0xCF           
DATABANK   NAME=gpr6b      START=0xD0              END=0xDF           
DATABANK   NAME=gpr7a      START=0xEC              END=0xEF           

#IFDEF _DEBUGDATASTART
  DATABANK   NAME=gpr7b      START=0xF0              END=_DATAEND     
  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND        PROTECTED
#ELSE //no debug
  DATABANK   NAME=gpr7b      START=0xF0              END=0xFF           
#FI


#IFDEF _DEBUGDATASTART
  SHAREBANK  NAME=dbgnobnk   START=0xC             END=0xC            PROTECTED
  SHAREBANK  NAME=dbgnobnk   START=0x2C            END=0x2C           PROTECTED
  SHAREBANK  NAME=dbgnobnk   START=0x4C            END=0x4C           PROTECTED
  SHAREBANK  NAME=dbgnobnk   START=0x6C            END=0x6C           PROTECTED

  SHAREBANK  NAME=gpr0a      START=0xD             END=0xF            
  SHAREBANK  NAME=gpr0a      START=0x2D            END=0x2F           PROTECTED
  SHAREBANK  NAME=gpr0a      START=0x4D            END=0x4F           PROTECTED
  SHAREBANK  NAME=gpr0a      START=0x6D            END=0x6F           PROTECTED
#ELSE
  SHAREBANK  NAME=gpr0a      START=0xC             END=0xF            
  SHAREBANK  NAME=gpr0a      START=0x2C            END=0x2F           PROTECTED
  SHAREBANK  NAME=gpr0a      START=0x4C            END=0x4F           PROTECTED
  SHAREBANK  NAME=gpr0a      START=0x6C            END=0x6F           PROTECTED
#FI

SECTION    NAME=PROG0      ROM=page0           // ROM code space
SECTION    NAME=PROG1      ROM=page1           // ROM code space
SECTION    NAME=PROG2      ROM=page2           // ROM code space
SECTION    NAME=PROG3      ROM=page3           // ROM code space
SECTION    NAME=FLASHDATA  ROM=flashdata       // Writable Flash Data Memory
SECTION    NAME=IDLOCS     ROM=.idlocs         // ID locations

