FreeBSD/sys/amd64/amd64/machdep.c
/*
 * Reset registers to default values on exec.
 */
Reset registers to default values on exec.
Reset registers to default values on exec .
void
exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
{
	struct trapframe *regs = td->td_frame;
	struct pcb *pcb = td->td_pcb;
	mtx_lock(&dt_lock);
	if (td->td_proc->p_md.md_ldt != NULL)
		user_ldt_free(td);
	else
		mtx_unlock(&dt_lock);
	pcb->pcb_fsbase = 0;
	pcb->pcb_gsbase = 0;
	clear_pcb_flags(pcb, PCB_32BIT);
	pcb->pcb_initial_fpucw = __INITIAL_FPUCW__;
	set_pcb_flags(pcb, PCB_FULL_IRET);
	bzero((char *)regs, sizeof(struct trapframe));
	regs->tf_rip = imgp->entry_addr;
	regs->tf_rsp = ((stack - 8) & ~0xFul) + 8;
	regs->tf_rdi = stack;		
	regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
	regs->tf_ss = _udatasel;
	regs->tf_cs = _ucodesel;
	regs->tf_ds = _udatasel;
	regs->tf_es = _udatasel;
	regs->tf_fs = _ufssel;
	regs->tf_gs = _ugssel;
	regs->tf_flags = TF_HASSEGS;
	td->td_retval[1] = 0;
	if (pcb->pcb_flags & PCB_DBREGS) {
		pcb->pcb_dr0 = 0;
		pcb->pcb_dr1 = 0;
		pcb->pcb_dr2 = 0;
		pcb->pcb_dr3 = 0;
		pcb->pcb_dr6 = 0;
		pcb->pcb_dr7 = 0;
		if (pcb == curpcb) {
			reset_dbregs();
		}
		clear_pcb_flags(pcb, PCB_DBREGS);
	}
	fpstate_drop(td);
}
void exec_setregs ( struct thread * td , struct image_params * imgp , u_long stack ) { struct trapframe * regs = td -> td_frame ; struct pcb * pcb = td -> td_pcb ; mtx_lock ( & dt_lock ) ; if ( td -> td_proc -> p_md . md_ldt != NULL ) user_ldt_free ( td ) ; else mtx_unlock ( & dt_lock ) ; pcb -> pcb_fsbase = 0 ; pcb -> pcb_gsbase = 0 ; clear_pcb_flags ( pcb , PCB_32BIT ) ; pcb -> pcb_initial_fpucw = __INITIAL_FPUCW__ ; set_pcb_flags ( pcb , PCB_FULL_IRET ) ; bzero ( ( char * ) regs , sizeof ( struct trapframe ) ) ; regs -> tf_rip = imgp -> entry_addr ; regs -> tf_rsp = ( ( stack - 8 ) & ~ 0xFul ) + 8 ; regs -> tf_rdi = stack ; regs -> tf_rflags = PSL_USER | ( regs -> tf_rflags & PSL_T ) ; regs -> tf_ss = _udatasel ; regs -> tf_cs = _ucodesel ; regs -> tf_ds = _udatasel ; regs -> tf_es = _udatasel ; regs -> tf_fs = _ufssel ; regs -> tf_gs = _ugssel ; regs -> tf_flags = TF_HASSEGS ; td -> td_retval [ 1 ] = 0 ; if ( pcb -> pcb_flags & PCB_DBREGS ) { pcb -> pcb_dr0 = 0 ; pcb -> pcb_dr1 = 0 ; pcb -> pcb_dr2 = 0 ; pcb -> pcb_dr3 = 0 ; pcb -> pcb_dr6 = 0 ; pcb -> pcb_dr7 = 0 ; if ( pcb == curpcb ) { reset_dbregs ( ) ; } clear_pcb_flags ( pcb , PCB_DBREGS ) ; } fpstate_drop ( td ) ; }
Reset registers to default values on exec.
Reset registers to default values on exec .
/* argv */ /*
	 * Reset the hardware debug registers if they were in use.
	 * They won't have any meaning for the newly exec'd process.
	 */ /*
			 * Clear the debug registers on the running
			 * CPU, otherwise they will end up affecting
			 * the next process we switch to.
			 */ /*
	 * Drop the FP state if we hold it, so that the process gets a
	 * clean FP state if it uses the FPU again.
	 */