From owner-freebsd-hackers Fri Sep 18 20:27:22 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA09647 for freebsd-hackers-outgoing; Fri, 18 Sep 1998 20:27:22 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ceia.nordier.com (slip139-92-122-85.joh.za.ibm.net [139.92.122.85]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA09632 for ; Fri, 18 Sep 1998 20:27:12 -0700 (PDT) (envelope-from rnordier@nordier.com) Received: (from rnordier@localhost) by ceia.nordier.com (8.8.7/8.6.12) id FAA12252; Sat, 19 Sep 1998 05:24:20 +0200 (SAT) From: Robert Nordier Message-Id: <199809190324.FAA12252@ceia.nordier.com> Subject: Re: PC memory usage (what is PIC?) In-Reply-To: from Charles Youse at "Sep 18, 98 06:53:50 pm" To: cyouse@artemis.syncom.net (Charles Youse) Date: Sat, 19 Sep 1998 05:24:18 +0200 (SAT) Cc: bf20761@binghamton.edu, freebsd-hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Charles Youse wrote: > On Fri, 18 Sep 1998, zhihuizhang wrote: > > > Since it has been linked for another (high) address, it will have to > > execute PIC until the page table and page directory stuff is setup > > properly, at which point paging will be enabled and the kernel will > > finally run at the address for which it was linked. > > > > Can anyone explain to me what is PIC and the two different linked > > addresses mentioned here? In the standard i386 kernel, the first few hundred bytes of startup code execute at 0x100000 before the virtual address changes to 0xf0100000 (though the code remains at the same physical location). > > PIC refers to Position-Independent Code, which requires that all > references to memory be relative to the IP register. Code written in > this way will execute correctly no matter where it is loaded into the > address space. Actually, calling the kernel startup code PIC is a merely a convenient distortion of the truth, at least as far as the i386 FreeBSD kernel startup is concerned. Writing truly IP-independent i386 assembly code by hand (and the initial portion is pure assembly code), requires completely unnatural practices. > Because the kernel is linked to run at a different address than it's > loaded, references to absolute addresses will fetch invalid data from > a [nonexistent] random memory location. The solution is to restrict > the kernel to PIC (which has no such absolute references) until the > vm subsystem is initialized to redirect those absolute [virtual] > addresses to the proper physical addresses. The actual i386 solution is to pre-bias each actual absolute address reference in the initial startup section. This macros is used: #define R(foo) ((foo)-KERNBASE) The resultant code is not really position-independent in any sense, but it is correct for its execution address. -- Robert Nordier To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message