
119
Chapter 2 Applications Programming
ing preparation of the relevant RAM regions. The new COFF file produced by
romc-
off
must be relinked with the originally linked modules. Additionally, a call to
RA-
MInit()
must be placed in
crt0.s
or in the processor boot–up code (cold–start code) if
the linked executable is intended to control the processor during the processor RE-
SET code sequence.
When
romcoff
is not used with the “–r” option, it assumes that the ROM
memory is not readable. This results in a
RAMInit()
function which uses CONST
and CONSTH instructions to produce the data values to be initialized in RAM. This
results in extra ROM memory requirements to contain the very much larger
RAMI-
nit()
routine, but ensures that 3–bus architectures which do not incorporate a bridge
can initialize their RAM memory.
2.4
LIBRARY SUPPORT
2.4.1 Memory Allocation
The HIF specification requires that conforming operating systems maintain a
memory heap. An application program can acquire memory during execution by us-
ing the
malloc()
library routine. This routine makes use of the underlying
sysalloc
HIF service. The
malloc()
call is passed the number of consecutive memory bytes
required; it returns a pointer to the start of the memory allocated from the heap.
Calls to
malloc()
should be matched with calls to library routine
free()
. This
routine is passed the start address of the previously allocated memory along with the
number of bytes acquired. The
free()
routine is supported by the
sysfree
HIF service.
The HIF specification states “no dynamic memory allocation structure is implied by
this service”. This means the
sysfree
may do nothing; in fact, this service with OS–
boot (version 0.5) simply returns. Continually using memory without ever releasing
it and thus making it reusable, will be a serious problem for some application pro-
grams, in particular C++ which frequently constructs and destructs objects in heap
memory.
For this reason the library routines which interface to the HIF services perform
their own heap management. The first call to
malloc()
results in a
sysalloc
HIF re-
quest for 8k bytes, even in the
malloc()
was for only a few bytes. Further
malloc()
calls do not result in a
sysalloc
request until the 8k byte pool is used up. Calls to
free()
enable previously allocated memory to be returned to the pool maintained by the li-
brary.
The
alloca()
library routine provides a means of acquiring memory from the
memory stack rather than the heap. A pointer to the memory region within the calling
procedure’s memory stack frame, is returned by
alloca()
. The advantage of this
method is that there is no need to call a corresponding
free
routine. The temporary
memory space is automatically freed when the calling procedure returns. Users of the