From owner-freebsd-chat Fri Jun 22 14:10:59 2001 Delivered-To: freebsd-chat@freebsd.org Received: from smtp04.primenet.com (smtp04.primenet.com [64.211.219.53]) by hub.freebsd.org (Postfix) with ESMTP id 5E0E437B401 for ; Fri, 22 Jun 2001 14:10:56 -0700 (PDT) (envelope-from tlambert@usr06.primenet.com) Received: (from daemon@localhost) by smtp04.primenet.com (8.9.3/8.9.3) id OAA10297; Fri, 22 Jun 2001 14:10:53 -0700 (MST) Received: from usr06.primenet.com(206.165.6.206) via SMTP by smtp04.primenet.com, id smtpdAAAO1a4eu; Fri Jun 22 14:10:49 2001 Received: (from tlambert@localhost) by usr06.primenet.com (8.8.5/8.8.5) id OAA28441; Fri, 22 Jun 2001 14:14:56 -0700 (MST) From: Terry Lambert Message-Id: <200106222114.OAA28441@usr06.primenet.com> Subject: Re: most complex code in BSD? To: mwlucas@blackhelicopters.org (Michael Lucas) Date: Fri, 22 Jun 2001 21:14:56 +0000 (GMT) Cc: des@ofug.org (Dag-Erling Smorgrav), jcm@FreeBSD-uk.eu.org (j mckitrick), freebsd-chat@FreeBSD.ORG In-Reply-To: <20010622062238.A45123@blackhelicopters.org> from "Michael Lucas" at Jun 22, 2001 06:22:38 AM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > When I took the two-day FreeBSD Internals course McKusick taught, he > brought up the context-switching code. > > The original UNIX authors were not much on comments. When they put a > comment, it was to explain something really, really, *really* difficult. > > Apparently there was a seven-word comment in the context switching > code that gave him a bit of a start: "You are not expected to > understand this." Don't know if it's still there, but it's still > probably pretty scary. That's the startup code following relocation, where they push a return address value on the stack, and then return to start running on a different stack. In FreeBSD, this is in /sys/i386/i386/locore.s: ------------------------------------------------------------------------- /* Now enable paging */ movl R(_IdlePTD), %eax movl %eax,%cr3 /* load ptd addr into mmu */ movl %cr0,%eax /* get control word */ orl $CR0_PE|CR0_PG,%eax /* enable paging */ movl %eax,%cr0 /* and let's page NOW! */ #ifdef BDE_DEBUGGER /* * Complete the adjustments for paging so that we can keep tracing through * initi386() after the low (physical) addresses for the gdt and idt become * invalid. */ call bdb_commit_paging #endif pushl $begin /* jump to high virtualized address */ ret ------------------------------------------------------------------------- It's not that hard to understand, since it's in assembly language; the original stack-SPAM from C was much, much dirtier, and ended up being non-portable. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message