Basic System Problem Analysis - August 2003
49
Procedure Calling Convention: Stack Frame
The illustration shows the first things that FREAD does when it is called. These steps are
roughly the same for all OS procedures;
1. the current value of R2 (RP) is saved at SP-#20, that will be picked up at the end of
the procedure to return to the caller. The caller will have had to be sure that R2 does
contain a pointer back to it!
2. if necessary a stack frame is built. One way is using a “store word and modify”
instruction (STWM) which in this particular form saves the register R3 on top of
stack and then adds the offset value to R30 moving SP out that many words.
Occasionally you may find the LDO (load offset) being used for this purpose.
3. the procedure then saves any of the “callee save” registers it needs to as well as any
of the register-passed parameters that it needs to.
What you will notice in this case is that FREAD is not saving R26, which holds the file
number.
It does not need to because all FREAD does is call “fread_nm” which also defines file
number as the first parameter. This is impossible to know without the source code so you
may be forced to make a few scientific guesses for other routines.
The key point being that you cannot expect that arguments passed in registers 26..23 will
be saved off to the stack so that you can conveniently level down to them and find what
you want.