Swap the syscall caller frame info (i.e. the return pointer and

frame marker) and the syscall stub frame info in the trap frame.
Previously we stored the stub frame info in (rp,pfs) and the
caller frame info in (iip,cfm). This ends up being suboptimal
for the following reasons:
1. When we create a new context, such as for an execve(2), we had
   to set the (rp,pfs) pair for the entry point when using the
   syscall path out of the kernel but we need to set the (iip,cfm)
   pair when we take the interrupt way out. This is mostly just
   an inconsistency from the kernel's point of view, but an ugly
   irregularity from gdb(1)'s point of view.
2. The getcontext(2) and setcontext(2) syscalls had to swap the
   (rp,pfs) and (iip,cfm) pairs to make the context compatible
   with one created purely in userland.

Swapping the (rp,pfs) and (iip,cfm) pairs is visible to signal
handlers that actually peek at the mcontext_t and to gdb(1).
Since this change is made for gdb(1) and we don't care about
signal handlers that peek at the mcontext_t because we're still
a tier 2 platform, this ABI breakage is academic at this moment
in time.

Note that there was no real reason to save the caller frame info
in (iip,cfm) and the stub frame info in (rp,pfs).
This commit is contained in:
Marcel Moolenaar 2003-10-03 03:50:29 +00:00
parent 0cc7c160e2
commit 5bf2d2b6b4
3 changed files with 37 additions and 40 deletions

View File

@ -933,7 +933,7 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
tf->tf_special.iip = ia64_get_k5() +
((uint64_t)break_sigtramp - (uint64_t)ia64_gateway_page);
} else
tf->tf_special.rp = ia64_get_k5() +
tf->tf_special.iip = ia64_get_k5() +
((uint64_t)epc_sigtramp - (uint64_t)ia64_gateway_page);
/*
@ -1095,9 +1095,6 @@ get_mcontext(struct thread *td, mcontext_t *mc, int clear_ret)
s.bspstore = (uintptr_t)ustk;
}
if (tf->tf_flags & FRAME_SYSCALL) {
s.pfs = s.cfm;
s.rp = s.iip;
s.cfm = s.iip = 0;
/*
* Put the syscall return values in the context. We need this
* for swapcontext() to work. Note that we don't use gr11 in
@ -1152,10 +1149,8 @@ set_mcontext(struct thread *td, const mcontext_t *mc)
/* XXX High FP */
} else {
KASSERT((tf->tf_flags & FRAME_SYSCALL) != 0, ("foo"));
s.cfm = s.pfs;
s.pfs = tf->tf_special.pfs;
s.iip = s.rp;
s.rp = tf->tf_special.rp;
s.cfm = tf->tf_special.cfm;
s.iip = tf->tf_special.iip;
if ((mc->mc_flags & _MC_FLAGS_SCRATCH_VALID) == 0) {
if (mc->mc_flags & _MC_FLAGS_RETURN_VALID) {
tf->tf_scratch.gr8 = mc->mc_scratch.gr8;
@ -1204,7 +1199,6 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
if ((tf->tf_flags & FRAME_SYSCALL) == 0) { /* break syscalls. */
bzero(&tf->tf_scratch, sizeof(tf->tf_scratch));
bzero(&tf->tf_scratch_fp, sizeof(tf->tf_scratch_fp));
tf->tf_special.iip = entry;
tf->tf_special.cfm = (1UL<<63) | (3UL<<7) | 3UL;
tf->tf_special.bspstore = td->td_md.md_bspstore;
/*
@ -1224,8 +1218,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
*kst = stack;
tf->tf_special.ndirty = (ksttop - kst) << 3;
} else { /* epc syscalls (default). */
tf->tf_special.rp = entry;
tf->tf_special.pfs = (3UL<<62) | (3UL<<7) | 3UL;
tf->tf_special.cfm = (3UL<<62) | (3UL<<7) | 3UL;
tf->tf_special.bspstore = td->td_md.md_bspstore + 24;
/*
* Write values for out0, out1 and out2 to the user's backing
@ -1238,6 +1231,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
suword((caddr_t)tf->tf_special.bspstore - 8, 0);
}
tf->tf_special.iip = entry;
tf->tf_special.sp = (stack & ~15) - 16;
tf->tf_special.rsc = 0xf;
tf->tf_special.fpsr = IA64_FPSR_DEFAULT;

View File

@ -93,11 +93,11 @@ gw_ret:
mov ar.rnat=r22
;;
mov ar.rsc=r24
mov ar.pfs=r28
mov ar.pfs=r20
}
{ .mib
mov ar.fpsr=r25
mov b0=r29
mov b0=r18
br.sptk b6
;;
}
@ -196,24 +196,24 @@ ENTRY(epc_sigtramp, 0)
{ .mmi
mov r17=ar.bsp
mov r18=ar.rnat
add r14=32,r16
add r14=14*8,r16
;;
}
{ .mmi
(p15) mov ar.bspstore=gp
ld8 r19=[r14],8
add r15=48,r16
ld8 r19=[r14],-9*8 // cfm
add r15=6*8,r16
;;
}
{ .mmi
st8 [r14]=r17,64 // bspstore
st8 [r15]=r18,-16 // rnat
st8 [r14]=r17,8*8 // bspstore
st8 [r15]=r18,8*8 // rnat
dep r19=r19,r19,7,7
;;
}
{ .mmi
st8 [r14]=r0 // ndirty
st8 [r15]=r19 // pfs
st8 [r15]=r19 // cfm
nop 0
;;
}
@ -300,13 +300,13 @@ ENTRY(epc_syscall, 8)
;;
}
{ .mmi
st8 [r30]=r24,16 // rp (syscall stub)
st8 [r30]=r10,16 // rp (syscall caller)
st8 [r31]=r25,16 // pr
mov r26=ar.pfs
;;
}
{ .mmi
st8 [r30]=r26,16 // pfs (syscall stub)
st8 [r30]=r9,16 // pfs (syscall caller)
st8 [r31]=r18,16 // bspstore
sub r27=r23,r15
;;
@ -336,8 +336,8 @@ ENTRY(epc_syscall, 8)
;;
}
{ .mmi
st8 [r30]=r9,16 // pfs (syscall caller)
st8 [r31]=r10,16 // rp (syscall caller)
st8 [r30]=r26,16 // pfs (syscall stub)
st8 [r31]=r24,16 // rp (syscall stub)
nop 0
;;
}
@ -425,14 +425,14 @@ epc_syscall_return:
}
{ .mmi
ld8 r17=[r15],16 // unat (before)
ld8 r18=[r14],16 // rp (syscall stub)
ld8 r18=[r14],16 // rp (syscall caller)
add r31=r31,sp
;;
}
{ .mmi
{ .mmb
ld8 r19=[r15],16 // pr
ld8 r20=[r14],16 // pfs (syscall stub)
mov b6=r18
ld8 r20=[r14],16 // pfs (syscall caller)
nop 0
;;
}
{ .mmi
@ -450,7 +450,7 @@ epc_syscall_return:
{ .mmi
ld8 r25=[r15],16 // fpsr
ld8 r26=[r14],16 // psr
mov ar.pfs=r20
nop 0
;;
}
{ .mmi
@ -460,15 +460,15 @@ epc_syscall_return:
;;
}
{ .mmi
ld8 r28=[r15],56 // pfs (syscall caller)
ld8 r29=[r14],56 // rp (syscall caller)
ld8 r28=[r15],56 // pfs (syscall stub)
ld8 r29=[r14],56 // rp (syscall stub)
shl r27=r27,16
;;
}
{ .mmb
{ .mmi
ld8 r8=[r15],16 // r8
mov ar.rsc=r27
nop 0
mov b6=r29
;;
}
{ .mmb
@ -485,21 +485,25 @@ epc_syscall_return:
}
{ .mmi
mov r30=ar.bspstore
;;
mov r14=ar.k5
dep r30=0,r30,0,13 // 8KB aligned.
mov ar.pfs=r28
;;
}
{ .mmi
mov ar.k6=r30
mov ar.bspstore=r21
mov r13=r23
add r14=gw_ret-ia64_gateway_page,r14
dep r30=0,r30,0,13 // 8KB aligned.
;;
}
{ .mib
mov ar.k6=r30
mov r13=r23
nop 0
}
{ .mmi
mov psr.l=r26
mov ar.unat=r17
add r14=gw_ret-ia64_gateway_page,r14
nop 0
;;
}
{ .mib

View File

@ -191,6 +191,7 @@ cpu_set_upcall_kse(struct thread *td, struct kse_upcall *ku)
stack = (uint64_t)ku->ku_stack.ss_sp;
bzero(&tf->tf_special, sizeof(tf->tf_special));
tf->tf_special.iip = fuword(&fd->func);
tf->tf_special.gp = fuword(&fd->gp);
tf->tf_special.sp = (stack + ku->ku_stack.ss_size - 16) & ~15;
tf->tf_special.rsc = 0xf;
@ -200,12 +201,10 @@ cpu_set_upcall_kse(struct thread *td, struct kse_upcall *ku)
IA64_PSR_CPL_USER;
if (tf->tf_flags & FRAME_SYSCALL) {
tf->tf_special.rp = fuword(&fd->func);
tf->tf_special.pfs = (3UL<<62) | (1UL<<7) | 1UL;
tf->tf_special.cfm = (3UL<<62) | (1UL<<7) | 1UL;
tf->tf_special.bspstore = stack + 8;
suword((caddr_t)stack, (uint64_t)ku->ku_mailbox);
} else {
tf->tf_special.iip = fuword(&fd->func);
tf->tf_special.cfm = (1UL<<63) | (1UL<<7) | 1UL;
tf->tf_special.bspstore = stack;
tf->tf_special.ndirty = 8;