TMS34010
C
Run-Time
Environment
5.5.5
Restoration
of
the
Caller's
Environment
It
is the responsibility
of
the called
function
to
restore the environment
of
the
caller before returning. In general, this involves restoration
of
the caller's reg-
isters and
deletion
of
the local frame
(including
arguments).
The first task
is
to
restore the caller's registers. This can be done
with
an
MMFM
instruction, corresponding
to
the
MMTM
given at function entry.
Note
that
the status register need
not
be saved
or
restored.
If
local variables
were allocated, the frame pointer must also be restored and shouid
be
included
in the register list
for
the register save instructions.
There
are
two
methods for deletion
of
local variables and arguments:
• Function returns value
on
stack,
or
has arguments. In the latter the old
program stack pointer
is
pushed on the stack
(below
the old value). To
restore the
caller's stack,
copy
this value from the system stack (SP)
to
the program stack pointer,
A14
(STK).
•
No
arguments, no return value on stack.
If
a local frame was allocated,
decrement
A14
by
the size
of
the local frame and return.
If
no frame was
allocated,
just
return.
Note
that
the
old
program stack pointer
is
not
saved for either
(1
) the case
of
values returned on the stack
or
(2)
the case
of
no arguments.
5.5.6
Return
from
Function
The last instruction executed
by
the function
is
a
RETS.
Normally, the'
in-
struction has
an
argument
of
zero,
but
if
the function had arguments
or
re-
turned a
value on the stack, the instruction
RETS
2 must be executed
to
pop
the caller's
old
program stack pointer
off
the stack,
5.6
Interrupt
Handling
Interrupts can be handled directly
with
C functions through the use
of
re-
served function names. These names
are
of
the form: .
c-
int##
where
two
pound
signs
(##)
indicate a
two-digit
interrupt number. For ex-
ample:
c-intOO
(system
reset
interrupt)
c-intOl
.,.
c-int99
By naming a
function
in this way, the user specifies
that
the function is to be
used
to
handle
an
interrupt, and the codegen generates special code
for
an
interrupt routine.
Any
register used
(with
the exception
of
SP and STK)
is
saved by the interrupt
handler,
including
AB.
In a normal
function,
A8
need
not
be saved; however,
in the case
of
an
interrupt,
A8
must
be
saved.
To return from the interrupt, use the
RETI
instruction. This restores the status
of
the interrupted function, .
5-11