User`s manual

Rabbit 4000 Designer’s Handbook rabbit.com 27
5.2.2 The Base (or Root) Segment
The base segment has a typical size of 24 KB. The larger the base segment, the smaller the data segment
and vice-versa. Base segment address zero is always mapped to physical address zero. Sometimes the base
segment is mapped to flash memory since root code and root constants do not change except when the sys-
tem is reprogrammed. It may be mapped to RAM for debugging, or to take advantage of the faster access
time offered by RAM. Serial flash boot configurations always map the base segment to RAM since there is
no parallel flash.
With separate I&D space disabled, the base segment holds a mixture of code and constants. C functions or
assembly language programs that are compiled to the base segment are interspersed with data constants.
Data constants are inserted between blocks of code. Data constants defined inside a C function are placed
after the end of the code belonging to the function. Data constants defined outside of C functions are
placed in memory where they are encountered in the source code.
Except in small programs, the bulk of the code in a program is executed using the extended memory
(xmem) segment. Code operates at the same speed whether addressed through the base segment or the
xmem segment, except that calling and returning from xmem functions takes a few extra clock cycles. It
just takes a few cycles longer to call xmem functions and return from them.
5.2.2.1 Types of Code Best-Suited for the Base Segment
Short subroutines of about 20 instructions or less that are called frequently will use less execution
time if placed in root memory because of the faster calling linkage for 16-bit versus 20-bit addresses.
For a call and return, 20 clocks are used compared to 32 clocks for xmem calls and returns. This reduc-
tion in execution time becomes more significant when the call/return sequence is a substantial portion of
the total execution time.
Interrupt routines. Interrupt vectors use 16-bit addressing so the entry to an interrupt routine must be
in the base segment.
The BIOS core. The initialization code of the BIOS must be at the start of the base segment.
A function that modifies the XPC must always be executed from root memory.
5.2.3 The Data Segment
The data segment has a typical size of 28 KB, starting at 24 KB (0x6000 above root code) and ending at 52
KB (0xCFFF). The data segment is mapped to RAM and contains C variables. Data allocation starts at or
near the top and proceeds in a downward direction. It is also possible to place executable code in the data
segment if it is copied from flash to the data segment. This can be desirable for code that is self modifying,
code to implement debugging aids or code that controls writes to the flash memory.
In separate I&D space, the data segment is twice as big (~54 KB), but code cannot be executed from it.
5.2.4 The Stack Segment
Usually the stack segment is assigned to the range of logical addresses 0xD000 to 0xDFFF. It is always
mapped to RAM and holds the system stack. Multiple stacks may be implemented by defining them in the
4 KB space, by remapping the 4 KB space to different locations in physical RAM memory, or by using
both approaches. Multiple stack allocation is handled by µC/OS-II internally. For example, if sixteen 1 KB
stacks are needed then four stacks can be placed in each 4 KB mapping and four different mappings for the
window can be used.