Specifications
In the remaining sections of this chapter, we explain each supported calling protocol and how
Bound-T interprets it. Note that a calling protocol usually contains some rules that Bound-T
does not rely on for its analysis; thus we in fact support a superset of the calling protocol in
which these irrelevant rules need not be followed. In particular, the rules that govern how a
compiler chooses a parameter-passing mechanism for a given source-language parameter are
usually not significant to Bound-T.
6.2 The GNU calling protocol
Introduction
This section explains how Bound-T supports the procedure calling protocol used by the GNU
H8/300 C compiler, using the default compilation options. This section is based on the H8/300
GCC Application Binary Interface description [8] and on observation of compiled code.
The GCC calling protocol has the following features:
• The native instructions BSR/JSR and RTS are used.
• Parameters are passed in registers and (if many) on the stack.
• The callee can alter the values of registers R0, R1, R2, R3.
• The callee must not alter the values of registers R4, R5, R6, R7 or must save the original
value and restore it before returning to the caller.
Parameter passing
Up to three parameters are passed in R0, R1 and R2. The rest of the parameters are passed on
the stack, pushed there before the call. Parameter sizes on the stack are rounded to an even
number of octets. For example, an octet parameter is held in one word of stack space.
Subprogram call
The subprogram call sequence consists of pushing the stack-based parameters on the stack,
loading register-based parameters into registers, and executing a BSR or JSR.
Use of the stack in the callee
The callee subprogram usually allocates stack space for its local and temporary variables. It can
do this by PUSH instructions or by decreasing the SP in some other way (eg. by subtraction).
The callee uses the stack also to save the values of the callee-save registers R4-R6 when
necessary. The exact lay-out of the stack frame in the callee depends on the GCC version
(see [8]) and is not relevant to Bound-T.
Of course, if the callee itself performs calls to other subprograms, it may use the stack for
parameters to these other subprograms. This means that SP can vary quite dynamically during
the execution of a subprogram.
Access to stacked parameters and locals
Under the GCC option -fomit-frame-pointer there is no frame pointer. This means that all stack-
based data must be accessed using SP-relative addressing (register indirect based on SP).
However, as the value of SP can vary during the execution of the subprogram, so must the
offset (displacement) be varied. For example, if the address SP + 8 accesses a given local
variable before a PUSH instruction, the same variable must be accessed with SP + 10 after the
PUSH instruction decreases SP by two.
Bound-T for H8/300 Calling Protocols 33