STREAMS/UX for the HP 9000 Reference Manual

179
Debugging STREAMS/UX Modules and Drivers
Using adb
The only registers you need to be concerned with for manual stack
back-tracing are r2 (rp) and r30 (sp), although the other registers become
important when trying to determine what arguments a procedure in the trace
was called with.
In order to implement these register roles, at the start of each procedure a
stack frame is allocated and callee save registers which the called procedure
is planning to modify are stored in the stack frame. The stack frame is
allocated simply by incrementing the sp by the size of the stack frame
needed, using either the stwm or ldo instruction. For example, below are the
instructions which create the stack frame for ioctl. Numbers in brackets ([ ])
refer to the notes below.
ioctl: stw rp,-14(sp) [1]
ioctl+4: stwm r3,100(sp) [2]
ioctl+8: stw r4,-0xFC(sp) [3]
ioctl+0xC: stw r5,-0xF8(sp) [4]
ioctl+10: stw r6,-0xF4(sp) [5]
[1] Store return instruction address at 0x14 above the caller's stack pointer.
Note that the return address is stored in the caller's stack frame, not the
callee's stack frame.
[2] Store the contents of r3 at the current sp, then allocate the stack frame by
adding 0x100 to sp. The stwm instruction stands for store word and modify.
[3] Store the contents of r4 at sp - 0xFC, just below where you stored r3.
[4] Store the contents of r5 at sp - 0xF8, just below where you stored r4.
[5] Store the contents of r6 at sp - 0xF4, just below where you stored r5.
The instruction ldo (load offset) can be used instead of stwm for allocating
the stack. For example:
doadump: stw rp,-14(sp) [1]
doadump+4: ldo 30(sp),sp [2]
[1] Store return instruction address in caller's stack frame.
[2] Add 0x30 to the current value in register sp and store the result in sp,
allocating stack frame.