Technical information

AN2216/D
CodeWarrior Compiler
MOTOROLA MC9S12DP256 Software Development Using Metrowerk’s Codewarrior 3
While all 256K of Flash memory can be accessed through the 16K PPAGE
window, two of the 16K byte pages can also be accessed at fixed address
locations as shown in Figure 1. The fixed page at $4000
$7FFF is the same
block of memory that can be accessed through the page window when the
PPAGE register contains $3E. The fixed page from $C000
$FFFF is the same
block of memory that can be accessed through the page window when the
PPAGE register contains $3F. These two fixed page areas are provided to
overcome some of the restrictions of the M68HC12 memory paging design.
Because of the manner in which the memory paging mechanism is
implemented, functions residing in paged memory cannot directly access
constant data residing in a different memory page. This restriction is necessary
because the PPAGE register would have to be written with a different value in
order to access the data. Clearly, writing the PPAGE register with a new value
would result in problem because the code that was being executed would
disappear from the page window as soon as the new PPAGE value was written.
Any constant data such as lookup tables, string or numeric constants that are
shared by functions residing on different pages must either be placed in one of
the two fixed Flash memory pages or must be accessed through a runtime
routine that is located in the fixed Flash memory.
Finally, because the reset and interrupt vectors are only 16-bits, all interrupt
service routines and the initial reset routine must begin in one of the fixed page
memory areas. This does not mean that the entire initialization or interrupt
service routines must reside in the fixed memory areas, however, they must
begin there. If it is desired to place the bulk of the interrupt service routine or
initialization code in paged memory, the portion of the interrupt service routine
in the fixed page area could consist of a CALL to the paged functions followed
by an RTI instruction.
CodeWarrior Compiler
To efficiently handle the paged memory architecture, the Codewarrior compiler
introduces two non-ANSI keywords: near and far. A near function is called with
a JSR or BSR instruction, whereas a far function is called with a CALL
instruction. For example,
void far func1(void);
declares a far function which will be located in paged memory and which may
be called by a function in a different page.
The near and far keywords may also be used with data pointers. For example,