To avoid excessive code duplication create wrapper for fill regs

from stack frame. Change the trap() code to use newly created function
instead of explicit regs assignment.
This commit is contained in:
Dmitry Chagin 2011-02-16 17:50:21 +00:00
parent 4fd8408ae7
commit dc4f0a9e11
6 changed files with 18 additions and 48 deletions

View File

@ -1842,6 +1842,12 @@ fill_regs(struct thread *td, struct reg *regs)
struct trapframe *tp;
tp = td->td_frame;
return (fill_frame_regs(tp, regs));
}
int
fill_frame_regs(struct trapframe *tp, struct reg *regs)
{
regs->r_r15 = tp->tf_r15;
regs->r_r14 = tp->tf_r14;
regs->r_r13 = tp->tf_r13;

View File

@ -249,38 +249,8 @@ trap(struct trapframe *frame)
if (type == T_DTRACE_PROBE || type == T_DTRACE_RET ||
type == T_BPTFLT) {
struct reg regs;
regs.r_r15 = frame->tf_r15;
regs.r_r14 = frame->tf_r14;
regs.r_r13 = frame->tf_r13;
regs.r_r12 = frame->tf_r12;
regs.r_r11 = frame->tf_r11;
regs.r_r10 = frame->tf_r10;
regs.r_r9 = frame->tf_r9;
regs.r_r8 = frame->tf_r8;
regs.r_rdi = frame->tf_rdi;
regs.r_rsi = frame->tf_rsi;
regs.r_rbp = frame->tf_rbp;
regs.r_rbx = frame->tf_rbx;
regs.r_rdx = frame->tf_rdx;
regs.r_rcx = frame->tf_rcx;
regs.r_rax = frame->tf_rax;
regs.r_rip = frame->tf_rip;
regs.r_cs = frame->tf_cs;
regs.r_rflags = frame->tf_rflags;
regs.r_rsp = frame->tf_rsp;
regs.r_ss = frame->tf_ss;
if (frame->tf_flags & TF_HASSEGS) {
regs.r_ds = frame->tf_ds;
regs.r_es = frame->tf_es;
regs.r_fs = frame->tf_fs;
regs.r_gs = frame->tf_gs;
} else {
regs.r_ds = 0;
regs.r_es = 0;
regs.r_fs = 0;
regs.r_gs = 0;
}
fill_frame_regs(frame, &regs);
if (type == T_DTRACE_PROBE &&
dtrace_fasttrap_probe_ptr != NULL &&
dtrace_fasttrap_probe_ptr(&regs) == 0)

View File

@ -130,6 +130,7 @@ struct dbreg {
* XXX these interfaces are MI, so they should be declared in a MI place.
*/
int fill_regs(struct thread *, struct reg *);
int fill_frame_regs(struct trapframe *, struct reg *);
int set_regs(struct thread *, struct reg *);
int fill_fpregs(struct thread *, struct fpreg *);
int set_fpregs(struct thread *, struct fpreg *);

View File

@ -3122,6 +3122,13 @@ fill_regs(struct thread *td, struct reg *regs)
tp = td->td_frame;
pcb = td->td_pcb;
regs->r_gs = pcb->pcb_gs;
return (fill_frame_regs(tp, regs));
}
int
fill_frame_regs(struct trapframe *tp, struct reg *regs)
{
regs->r_fs = tp->tf_fs;
regs->r_es = tp->tf_es;
regs->r_ds = tp->tf_ds;
@ -3137,7 +3144,6 @@ fill_regs(struct thread *td, struct reg *regs)
regs->r_eflags = tp->tf_eflags;
regs->r_esp = tp->tf_esp;
regs->r_ss = tp->tf_ss;
regs->r_gs = pcb->pcb_gs;
return (0);
}

View File

@ -271,21 +271,7 @@ trap(struct trapframe *frame)
type == T_BPTFLT) {
struct reg regs;
regs.r_fs = frame->tf_fs;
regs.r_es = frame->tf_es;
regs.r_ds = frame->tf_ds;
regs.r_edi = frame->tf_edi;
regs.r_esi = frame->tf_esi;
regs.r_ebp = frame->tf_ebp;
regs.r_ebx = frame->tf_ebx;
regs.r_edx = frame->tf_edx;
regs.r_ecx = frame->tf_ecx;
regs.r_eax = frame->tf_eax;
regs.r_eip = frame->tf_eip;
regs.r_cs = frame->tf_cs;
regs.r_eflags = frame->tf_eflags;
regs.r_esp = frame->tf_esp;
regs.r_ss = frame->tf_ss;
fill_frame_regs(frame, &regs);
if (type == T_DTRACE_PROBE &&
dtrace_fasttrap_probe_ptr != NULL &&
dtrace_fasttrap_probe_ptr(&regs) == 0)

View File

@ -161,6 +161,7 @@ struct dbreg {
* XXX these interfaces are MI, so they should be declared in a MI place.
*/
int fill_regs(struct thread *, struct reg *);
int fill_frame_regs(struct trapframe *, struct reg *);
int set_regs(struct thread *, struct reg *);
int fill_fpregs(struct thread *, struct fpreg *);
int set_fpregs(struct thread *, struct fpreg *);