Rewrite longjmp() and _longjmp() to directly restore the saved frame,

instead of unwinding the call stack. This makes them usable to switch
stacks, e.g. for libc_r.
Do not save the frame pointer in setjmp() and _setjmp(), it is not needed
any more.
Rename _longjmp() to ___longjmp(), with a weak alias to _longjmp(), like
the other architectures did.
This commit is contained in:
Thomas Moestl 2003-01-05 22:17:32 +00:00
parent c58d580e70
commit e506034ec1
2 changed files with 19 additions and 55 deletions

View File

@ -58,42 +58,26 @@ __FBSDID("$FreeBSD$");
* will generate a "return(v?v:1)" from
* the last call to
* _setjmp(a)
* by unwinding the call stack.
* by restoring the previous context.
* The previous signal state is NOT restored.
*/
ENTRY(_setjmp)
stx %sp, [%o0 + _JB_SP]
stx %o7, [%o0 + _JB_PC]
stx %fp, [%o0 + _JB_FP]
retl
clr %o0
END(_setjmp)
ENTRY(_longjmp)
mov 1, %g1
movrnz %o1, %o1, %g1 ! compute v ? v : 1
mov %o0, %g2
ldx [%g2 + _JB_FP], %g3 ! fetch callers frame
1: cmp %fp, %g3 ! compare against desired frame
bl,a 1b ! if below,
restore ! pop frame and loop
be,a 2f ! if there,
ldx [%g2 + _JB_SP], %o0 ! fetch return %sp
.Lbotch:
call CNAME(longjmperror)
nop
call CNAME(abort)
nop
illtrap
2: cmp %o0, %sp ! %sp must not decrease
bge,a 3f
mov %o0, %sp ! it is OK, put it in place
b,a .Lbotch
nop
3: ldx [%g2 + _JB_PC], %o7 ! fetch return address
retl
mov %g1, %o0 ! return v ? v : 1;
END(_longjmp)
.weak CNAME(_longjmp)
.set CNAME(_longjmp),CNAME(___longjmp)
ENTRY(___longjmp)
save %sp, -CCFSZ, %sp
flushw
ldx [%i0 + _JB_SP], %fp
ldx [%i0 + _JB_PC], %i7
mov 1, %i0
movrnz %i1, %i1, %i0
ret
restore
END(___longjmp)

View File

@ -70,7 +70,6 @@ ENTRY(setjmp)
restore
stx %sp, [%o0 + _JB_SP]
stx %o7, [%o0 + _JB_PC]
stx %fp, [%o0 + _JB_FP]
retl
clr %o0
END(setjmp)
@ -79,34 +78,15 @@ END(setjmp)
.set CNAME(longjmp),CNAME(__longjmp)
ENTRY(__longjmp)
save %sp, -CCFSZ, %sp
flushw
mov SIG_SETMASK, %o0
add %i0, _JB_SIGMASK, %o1
call CNAME(sigprocmask)
clr %o2
restore
mov 1, %g1
movrnz %o1, %o1, %g1
mov %o0, %g2
ldx [%g2 + _JB_FP], %g3
1: cmp %fp, %g3
bl,a 1b
ldx [%i0 + _JB_SP], %fp
ldx [%i0 + _JB_PC], %i7
mov 1, %i0
movrnz %i1, %i1, %i0
ret
restore
be,a 2f
ldx [%g2 + _JB_SP], %o0
.Lbotch:
call CNAME(longjmperror)
nop
call CNAME(abort)
nop
illtrap
2: cmp %o0, %sp
bge,a 3f
mov %o0, %sp
b,a .Lbotch
nop
3: ldx [%g2 + _JB_PC], %o7
retl
mov %g1, %o0
END(__longjmp)