From owner-freebsd-current@FreeBSD.ORG Mon Sep 27 06:04:38 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6DDBC16A4CE; Mon, 27 Sep 2004 06:04:38 +0000 (GMT) Received: from dglawrence.com (dsl-230-156.ipns.com [209.210.230.156]) by mx1.FreeBSD.org (Postfix) with ESMTP id E23C043D2F; Mon, 27 Sep 2004 06:04:37 +0000 (GMT) (envelope-from dg@nexus.dglawrence.com) Received: from nexus.dglawrence.com (localhost [127.0.0.1]) by dglawrence.com (8.12.10/8.12.6) with ESMTP id i8R64MrW079861; Sun, 26 Sep 2004 23:04:22 -0700 (PDT) (envelope-from dg@nexus.dglawrence.com) Received: (from dg@localhost) by nexus.dglawrence.com (8.12.10/8.12.3/Submit) id i8R64MnP079860; Sun, 26 Sep 2004 23:04:22 -0700 (PDT) Date: Sun, 26 Sep 2004 23:04:22 -0700 From: "David G. Lawrence" To: Jon Passki Message-ID: <20040927060422.GC16205@nexus.dglawrence.com> References: <41565673.7050504@freebsd.org> <20040926144632.70365.qmail@web50305.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040926144632.70365.qmail@web50305.mail.yahoo.com> cc: freebsd-current@freebsd.org cc: David Xu Subject: Re: Interesting code in exec_setregs X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2004 06:04:38 -0000 > > --- David Xu wrote: > > > I found following code in sys/i386/i386/machdep.c: > > function exec_setregs: > > > > bzero((char *)regs, sizeof(struct trapframe)); > > regs->tf_eip = entry; > > regs->tf_esp = stack; > > regs->tf_eflags = PSL_USER | (regs->tf_eflags & PSL_T); > > > > the regs is cleared to zero, why do we bother to test it > > again ? regs->tf_eflags & PSL_T is useless code. > > > > AMD64 also has this, I also found it in releng_4, why ? > > FYI, it's first incarnation was in v1.87 [1] (1994-11-06): > > ! 864: ? ? ? ?bzero(regs, sizeof(struct > trapframe)); > ! 865: ? ? ? ?regs[tEIP] = entry; > ! 866: ? ? ? ?regs[tESP] = stack; > ! 867: ? ? ? ?regs[tEFLAGS] = PSL_USERSET | > (regs[tEFLAGS] & PSL_T); > ! 868: ? ? ? ?regs[tSS] = _udatasel; > ! 869: ? ? ? ?regs[tDS] = _udatasel; > ! 870: ? ? ? ?regs[tES] = _udatasel; > ! 871: ? ? ? ?regs[tCS] = _ucodesel; > > Same issue, it seems. Hmmm. That would make it my bug. :-/ My only excuse is that things were pretty crazy back then - this would have happened when John Dyson and I were working on the x86 port of 4.4-lite which became FreeBSD 2.0. We did the port in 10 days. :-) My best explaination is that the bzero got added after the tEFLAGS stuff - probably to solve some other issue, and the test of PSL_T (actually should be called TF bit to match Intel literature, which stands for "trap flag") a few lines lower was overlooked. The bit enables debug traps after every instruction in order to facilitate instruction single stepping. It's not clear to me if instruction single stepping should be preserved after an exec. I'd defer to Bruce Evans on this since he's the expert on debuggers. -DG David G. Lawrence President Download Technologies, Inc. - http://www.downloadtech.com - (866) 399 8500 TeraSolutions, Inc. - http://www.terasolutions.com - (888) 346 7175 The FreeBSD Project - http://www.freebsd.org Pave the road of life with opportunities.