Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Dec 2001 21:16:41 +0100
From:      Bernd Walter <ticso@cicely9.cicely.de>
To:        Daniel Eischen <eischen@pcnet1.pcnet.com>
Cc:        Dan Eischen <eischen@vigrid.com>, Andrew Gallatin <gallatin@cs.duke.edu>, freebsd-alpha@FreeBSD.ORG
Subject:   Re: Munging jmp_bufs on alpha
Message-ID:  <20011221201641.GE97006@cicely9.cicely.de>
In-Reply-To: <Pine.SUN.3.91.1011221130251.12980B-100000@pcnet1.pcnet.com>
References:  <20011221164636.GC97006@cicely9.cicely.de> <Pine.SUN.3.91.1011221130251.12980B-100000@pcnet1.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Dec 21, 2001 at 01:41:08PM -0500, Daniel Eischen wrote:
> On Fri, 21 Dec 2001, Bernd Walter wrote:
> > On Fri, Dec 21, 2001 at 10:47:25AM -0500, Dan Eischen wrote:
> > > Bernd Walter wrote:
> > > > 
> > > > My first explanation was a bit wrong but nevertheless here are the
> > > > patches for libc and Daniels testprogramm.
> > > 
> > > Hmm, as long as we're going to restore T12 with the return
> > > address, shouldn't we just save and restore T12 in _setjmp
> > > and _longjmp respectively?  And then let the threads library
> > > put the return address in T12 like it already does?
> > 
> > _setjmp and _longjmp are functions and the caller should not expect
> > any temporary register to keep it's contents after calling any function.
> > There is no need to save/restore them.
> > The point is with overwriting the return address to a function address
> > _longjmp does not return but call a function without knowing it and
> > a function caller needs to initialise t12 first.
> 
> OK, but by the same token, making _setjmp/_longjmp account for
> libc_r's jmp_buf munging seems wrong too.  Playing the devil's

That's exactly my opinion.
Having an MD function to call another function with an exchanged stack
would be a much cleaner way and removes the MD part of libc_r.
But I don't know which functions you exactly need and I'm not shure
if it's worth to make such a change with an SMPng perpective.

> advocate, why should _longjmp stuff the return address into
> a temporary register?  It seems more general to just save and
> restore any necessary register, whether it's temporary or not.
> T12 seems like it fits that category.

It's not the return address - actually it's the call address.
I see it saves some memory access and commands in every situation
these functions are used.

> What is T12 suppose to contain in a normal function call?  Is
> it always the return address?  Is that dependent on our compiler?

T12 contains the start address of a function on call.
Here is the typical function start:
0000000120000980 <scheduler>:
   120000980:   02 00 bb 27     ldah    gp,2(t12)
   120000984:   90 85 bd 23     lda     gp,-31344(gp)

With the help of t12 the function get gp which is used as a base for
all static/global resources.
Alpha needs a base address because there is no way to use a 64bit
const value in a single operation.

Here is a function call:
        _longjmp (retjb, 1);
   1200009b0:   b8 80 1d a6     ldq     a0,-32584(gp)
   1200009b4:   01 00 3f 22     lda     a1,1(zero)
   1200009b8:   08 80 7d a7     ldq     t12,-32760(gp)
   1200009bc:   41 41 5b 6b     jsr     ra,(t12),120000ec4 <_fini+0x2e4>
   1200009c0:   02 00 ba 27     ldah    gp,2(ra)
   1200009c4:   50 85 bd 23     lda     gp,-31408(gp)

It sets a0 and a1 as arguments and t12 then calls the function.
It then restores gp but never use the value of t12 without initialising
it first after the first function call.
You also see that this time it uses it's own ra as the starting point
instead of t12.
Setting t12 for the return case of _longjmp is simply a nop just as it
would be to store/restore it.

It has to be the same for all compilers otherwise they can't call
library functions build with another compiler.

-- 
B.Walter              COSMO-Project         http://www.cosmo-project.de
ticso@cicely.de         Usergroup           info@cosmo-project.de


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011221201641.GE97006>