DSPRelated.com
Forums

SHARC 21065

Started by wadsworth_bob February 28, 2005


Hello,

I am using the SHARC 21065 processor. At the end of some of the code
I have inherited, the following code exists:

_exit:
i12=dm(m7,i6);
jump (m14,i12) (db);
rframe;
nop;
.ENDSEG;

Can anyone tell me what this is for?



On Mon, 28 Feb 2005, wadsworth_bob wrote:

> I am using the SHARC 21065 processor. At the end of some of the code
> I have inherited, the following code exists:
>
> _exit:
> i12=dm(m7,i6);
> jump (m14,i12) (db);
> rframe;
> nop;
> .ENDSEG;
>
> Can anyone tell me what this is for?

The manual says the following:

CJUMP |function | (PC, <reladdr24>) | (DB);
RFRAME;

Function:
The CJUMP instruction is generated by the C compiler for function calls,
and is not intended for use in assembly language programs. CJUMP combines
a direct or PC-relative jump with register transfer operations that save
the frame and stack pointers. The RFRAME instruction reversed the
register transfers to restore the frame and stack pointers.

...

instruction what it does

CJUMP function(DB) JUMP function (DB), R2=I6, I6=I7;

RFRAME; I7 = I6, I6 = DM(0,I6)

So it looks like you do a look up into a table, then jump to some offset
from that address, and fix the registers i6 and i7 along the way. It's
from a C compiler, so you may want to find the original source code to
figure out what is really going on.

Patience, persistence, truth,
Dr. mike



Mike Rosing wrote:

>On Mon, 28 Feb 2005, wadsworth_bob wrote: >
>>I am using the SHARC 21065 processor. At the end of
some of the code
>>I have inherited, the following code exists:
>>
>>_exit:
>> i12=dm(m7,i6);
>> jump (m14,i12) (db);
>> rframe;
>> nop;
>>.ENDSEG;
>>
>>Can anyone tell me what this is for?
>>
>>
>
>The manual says the following:
>
>CJUMP |function | (PC, <reladdr24>) | (DB);
>RFRAME;
>
>Function:
>The CJUMP instruction is generated by the C compiler
for function calls,
>and is not intended for use in assembly language
programs. CJUMP combines
>a direct or PC-relative jump with register transfer
operations that save
>the frame and stack pointers. The RFRAME instruction
reversed the
>register transfers to restore the frame and stack
pointers.
>
>...
>
>instruction what it does
>
>CJUMP function(DB) JUMP function (DB),
R2=I6, I6=I7;
>
>RFRAME; I7 = I6, I6 = DM(0,I6)
>
>So it looks like you do a look up into a table, then
jump to some offset
>from that address, and fix the registers i6 and i7
along the way. It's
>from a C compiler, so you may want to find the
original source code to
>figure out what is really going on.
>
>Patience, persistence, truth,
>Dr. mike >
>
This is the "exit" macro used to maintain the run-time
stack on return
from a function call. I7 is the stack pointer and I6
is the frame
pointer. The frame pointer points to the bottom of the
current functions
stack and the stack pointer points to the top where
the free space is.
The bottom of the current functions stack always
contains the previous
functions frame pointer.

In the first instruction i6 contains the previous
functions frame
pointer and m7 contains the offset required to access
the return address
from the function, should be -1. The second
instruction jumps to the
return address + 1, as the return address is pointing
to the second
instruction of the delayed branch of the original
function call, so m14
should contain a modifier of 1.

The RFRAME instruction makes the stack pointer equal
to the frame
pointer. This releases the memory used for the current
functions stack.
As mentioned I6 points to the previous functions frame
pointer. Thus the
second part of the RFRAME instruction modifies the
frame pointer. So
the stack and frame pointers are now set up for the
original calling
function.

Send instant messages to your online friends http://uk.messenger.yahoo.com



--On Monday, February 28, 2005 8:02 PM -0800 Mike Rosing
<> wrote:

>> _exit:
>> i12=dm(m7,i6);
>> jump (m14,i12) (db);
>> rframe;
>> nop;
>> .ENDSEG;
>
> CJUMP function(DB) JUMP function (DB), R2=I6, I6=I7;
>
> RFRAME; I7 = I6, I6 = DM(0,I6)

It's been awhile and this is from memory: I7 is used as the C stack
pointer. I6 is the frame pointer (which is used as a base pointer to access
local variables and procedure arguments on the stack. CJUMP copies the
frame pointer to R2 (a temporary) and another instruction will push it onto
the stack, typically in the delay slots after the CJUMP.

The code in _exit is a typical C return sequence. I12 is a temporary that
can be used to address PM space. The return address is fetched using the
frame pointer, the frame pointer and stack pointer are restored (using
rframe), and the code jumps back to the caller. Take a look at the C manual
to see the fixed values it puts in the M registers. I'm guessing that M7 is
+1 and M14 is 0. I think the saved PC is stored just above (+1) the frame
pointer (hence "(m7,i6)") and its value is the address of the next
instruction in the calling code to execute (hence "(m14,i12)").



--On Monday, February 28, 2005 8:02 PM -0800 Mike Rosing
<> wrote:

>> _exit:
>> i12=dm(m7,i6);
>> jump (m14,i12) (db);
>> rframe;
>> nop;
>> .ENDSEG;
>
> CJUMP function(DB) JUMP function (DB), R2=I6, I6=I7;
>
> RFRAME; I7 = I6, I6 = DM(0,I6)

It's been awhile and this is from memory: I7 is used as the C stack
pointer. I6 is the frame pointer (which is used as a base pointer to access
local variables and procedure arguments on the stack. CJUMP copies the
frame pointer to R2 (a temporary) and another instruction will push it onto
the stack, typically in the delay slots after the CJUMP.

The code in _exit is a typical C return sequence. I12 is a temporary that
can be used to address PM space. The return address is fetched using the
frame pointer, the frame pointer and stack pointer are restored (using
rframe), and the code jumps back to the caller. Take a look at the C manual
to see the fixed values it puts in the M registers. I'm guessing that M7 is
+1 and M14 is 0. I think the saved PC is stored just above (+1) the frame
pointer (hence "(m7,i6)") and its value is the address of the next
instruction in the calling code to execute (hence "(m14,i12)").