Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jun 2001 21:14:56 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        mwlucas@blackhelicopters.org (Michael Lucas)
Cc:        des@ofug.org (Dag-Erling Smorgrav), jcm@FreeBSD-uk.eu.org (j mckitrick), freebsd-chat@FreeBSD.ORG
Subject:   Re: most complex code in BSD?
Message-ID:  <200106222114.OAA28441@usr06.primenet.com>
In-Reply-To: <20010622062238.A45123@blackhelicopters.org> from "Michael Lucas" at Jun 22, 2001 06:22:38 AM

next in thread | previous in thread | raw e-mail | index | archive | help
> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106222114.OAA28441>