//================================================================
//
//  IAR XLINK command file for the IAR C/C++ Compiler for 
//  Renesas M16C/R8C
//
//  This is an example XLINK command file for use with the
//  M30627FHP derivative.
// 
//  Derivative group: m16c 62p 
//  
//
//  Usage:  xlink  your_file(s)  -f this_file  clm16c*.r48
//
//  Copyright 2001-2008 IAR Systems AB.
//
//  $Revision: 2144 $ 
//
//================================================================

//================================================================
// The M16C IAR C/EC++ Compiler places code and data into named
// segments which are referred to by the IAR XLINK Linker. The
// table below shows the available segments.
//
// SEGMENT REFERENCE
// =================
//
// Segment   Description                                             
// -------   -----------                                             
// BITVARS      Bit variables.                                          
// CODE         The program code.                                       
// CSTACK       The stack used by C or Embedded C++ programs.           
// CSTART       The startup code.        
// DATA16_HEAP  Heap data used by malloc and free. Used by CLib and DLib
// FAR_HEAP     Heap used by malloc and free in DLib
// DATA20_HEAP  Heap used by malloc and free in DLib
//
// x_AC         Non-initialized located const objects.         
// x_AN         Non-initialized located non-const objects.     
// x_C          Constant data, including string literals.      
// x_I          Initialized data.                              
// x_ID         Data that is copied to x_I by cstartup.   
// x_N          Uninitialized data.                            
// x_Z          zero initialized data.                         
//
// Where x can be one of:
//    DATA13  (Range: 0-0x1FFF)
//    DATA16  (Range: 0-0xFFFF, except DATA16_ID)
//    DATA20  (Range: 0-0xFFFFF)
//    FAR     (Range: 0-0xFFFFF)
//
// DIFUNCT      Pointers to code, typically EC++ constructors           
// FLIST        Jump table for __tiny_func functions.
// INTVEC       Contains reset and interrupt vectors.                   
// INTVEC1      Contains the fixed reset and interrupt vectors.         
// ISTACK       The stack used by interrupts and exceptions.            
//================================================================

// Define CPU
-cm16c

//================================================================
// USER DEFINITIONS
// Please customize according to your preferences.
//================================================================

// Size of the user stack 
// Uncomment for command line use
//-D_CSTACK_SIZE=100

// Size of the interrupt stack
// Uncomment for command line use
//-D_ISTACK_SIZE=40

// Size of the heap
// Uncomment for command line use
//-D_DATA16_HEAP_SIZE=400
//-D_FAR_HEAP_SIZE=400
//-D_DATA20_HEAP_SIZE=400

// Reserved memory
// Reservation of RAM and ROM memory not to be used by the application.
// Preset for use with the E8 emulator.
// NOTE! Set these values to zero to utilize the whole RAM and ROM memory.
-D_RESERVED_RAM_SIZE=80
-D_RESERVED_ROM_SIZE=800

//================================================================
// Memory Definitions
//================================================================

// Memory areas available for the application
-D_USER_RAM_BEGIN=(00400+_RESERVED_RAM_SIZE)
-D_USER_RAM_END=07FFF
-D_DATA_FLASH_BEGIN=0F000
-D_DATA_FLASH_END=0FFFF
-D_USER_ROM_BEGIN=(A0000+_RESERVED_ROM_SIZE)
-D_USER_ROM_END=FFFFF

// Relocatable "bit" segment (must be in near area).
// As BITVARS contains bit addresses, the address has to be recalculated. 
// Byte address 400 --> 400 * 8 = bit address 2000
-D_BITVAR_BEGIN=2000 // address 400
-D_BITVAR_END=FFFF   // address 1FFF

// ID code and OFS value written to ROM memory
-D_ID_CODE_1=FF
-D_ID_CODE_2=FF
-D_ID_CODE_3=FF
-D_ID_CODE_4=FF
-D_ID_CODE_5=FF
-D_ID_CODE_6=FF
-D_ID_CODE_7=FF
-D_OFS_VALUE=FF

// _OFS2_VALUE has to be defined. It is only used in some R8C devices and will
// not result in any additional code or data for any other device.
-D_OFS2_VALUE=FF

// =======================
//      DATA13 RAM
// =======================

-Z(NEAR)DATA13_AN=0-01FFF
-Z(NEAR)DATA13_I=_USER_RAM_BEGIN-01FFF
-Z(NEAR)DATA13_Z,DATA13_N=_USER_RAM_BEGIN-01FFF

// Relocatable "bit" segment. As BITVARS contains bit addresses,
// the desired (byte) address has to be multiplied by 8.
-Z(BIT)BITVARS=_BITVAR_BEGIN-_BITVAR_END

// =======================
//       DATA16 RAM
// =======================

// Set up interrupt stack
-Z(NEAR)ISTACK+_ISTACK_SIZE#_USER_RAM_BEGIN-_USER_RAM_END

// Set up user stack
-Z(NEAR)CSTACK+_CSTACK_SIZE#_USER_RAM_BEGIN-_USER_RAM_END

// Set up near heap
-Z(NEAR)DATA16_HEAP+_DATA16_HEAP_SIZE=_USER_RAM_BEGIN-_USER_RAM_END

// Near variables
-Z(NEAR)DATA16_I,DATA16_Z,DATA16_N,DATA16_AN=_USER_RAM_BEGIN-_USER_RAM_END

// User defined near DATA segments


// =======================
//       DATA16 ROM
// =======================
// Data flash
-Z(CONST)DATA_FLASH=_DATA_FLASH_BEGIN-_DATA_FLASH_END

// Constant segments (in ROM), reachable for near pointers
// (Use declaration -Z(CONST)DATA16_C if near ROM exists)

// User defined near CONST segments

// =======================
//     FAR/DATA20 RAM
// =======================

// Far and huge data segments
-Z(FAR)FAR_I,FAR_Z,FAR_N,FAR_AN=_USER_RAM_BEGIN-_USER_RAM_END
-Z(FAR)FAR_HEAP+_FAR_HEAP_SIZE=_USER_RAM_BEGIN-_USER_RAM_END
-Z(HUGE)DATA20_I,DATA20_Z,DATA20_N,DATA20_AN=_USER_RAM_BEGIN-_USER_RAM_END
-Z(HUGE)DATA20_HEAP+_DATA20_HEAP_SIZE=_USER_RAM_BEGIN-_USER_RAM_END

// User defined far & huge DATA segments

// =======================
//     FAR/DATA20 ROM
// =======================

// Fixed interrupt vector table 
-Z(CONST)INTVEC1=FFFDC-FFFFF

 
// Special page table
-Z(CONST)FLIST=FFE00-FFFDB

// Variable vector table (growing downwards from _USER_ROM_END)
// The added -1 is too assure that all vectors start at even
// addresses.
-Z(CONST)INTVEC=D0000-(_USER_ROM_END-1)

// Constant and initializer segments (in ROM)
-Z(FARCONST)FAR_ID=_USER_ROM_BEGIN-_USER_ROM_END
-Z(FARCONST)FAR_C=_USER_ROM_BEGIN-_USER_ROM_END
-Z(HUGECONST)DATA20_C,DATA20_ID,CHECKSUM=_USER_ROM_BEGIN-_USER_ROM_END
-Z(FARCONST)DATA16_ID,DATA13_ID,DIFUNCT=_USER_ROM_BEGIN-_USER_ROM_END

// User defined far & huge CONST segments

// CODE segments 
// TINYFUNC code must be located above 0xF0000
-P(CODE)TINYFUNC=F0000-_USER_ROM_END

// Startup code 
-P(CODE)CSTART=D0000-_USER_ROM_END

// "Regular" code
-P(CODE)CODE=_USER_ROM_BEGIN-_USER_ROM_END
// User defined CODE segments

// ========================
// IAR C library formatting
// ========================

// Uncomment for command line use
//-e_small_write=_formatted_write
//-e_medium_read=_formatted_read 

// ========================
// Output files
// ========================
// Use the -O option to create one or more output files
// at the same link session. Formats flags, file name and
// extension is optional. Please un-comment the wanted
// output formats below.
//
// CAUTION: Do not combine other output formats with -rt (special
// UBROF for Terminal I/O in C-SPY). Output files are valid but
// contain code that expects to be run under C-SPY.

// Motorola output
//-Omotorola=.mot

// IEEE-695 output with format flags for the Renesas debugger
//-Oieee695,lbm=.x30

// ELF/DWARF output with format flags for the Renesas debugger
//-Oelf,spc=.elf
