Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Apr 1995 10:43:29 +0200 (MET DST)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        freebsd-hackers@FreeBSD.org (FreeBSD hackers)
Subject:   Memory usage (Was Re: Memory init pattern)
Message-ID:  <199504160843.KAA16160@uriah.heep.sax.de>
In-Reply-To: <m0s0IWA-0004vvC@nemesis.lonestar.org> from "Frank Durda IV" at Apr 15, 95 07:48:00 pm

next in thread | previous in thread | raw e-mail | index | archive | help
[Audience extended to -hackers, since it's a general topic.]

As Frank Durda IV wrote:
> 
> By the way, I have seen no description of how FreeBSD uses PC memory, ie
> what 0-640K gets used for, does the kernel load there or higher,
> is the kernel relocated, etc.  Is there a paper on this?

Since i've just digged through the boot code, i can tell you what's
going there. :)  [Someone going to collect this sort of messages
and making a kernel hackers manual?]

The boot sector will be loaded at 0:0x7c00, and relocates itself
immediately to 0x7c0:0.  (This is nothing magic, just an adjustment
for the %cs selector, done by an ljmp.)

It then loads the first 15 sectors at 0x10000 (segment BOOTSEG in the
biosboot Makefile), and sets up the stack to work below 0x1fff0.
After this, it jumps to the entry of boot2 within that code.  I.e., it
jumps over itself and the (dummy) partition table, and it's going to
adjust the %cs selector -- we are still in 16-bit mode there.

boot2 asks for the boot file, and examines the a.out header.  It masks
the file entry point (usually 0xf0100000) by 0x00ffffff, and loads the
file there.  Hence the usual load point is 1 MB (0x00100000).  During
load, the boot code toggles back and forth between real and protected
mode, to use the BIOS in real mode.

The boot code itself uses segment selectors 0x18 and 0x20 for %cs and
%ds/%es in protected mode, and 0x28 to jump back into real mode.  The
kernel is finally started with %cs 0x08 and %ds/%es/%ss 0x10, which
refer to dummy descriptors covering the whole address space.

The kernel will be started at its load point.  Since it's 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 finally runs at the address
where it has been linked to.

The kernel still skips over the first 0x500 bytes of code, in the
assumption this were valuable BIOS data space (back from old days
where it has been loaded low).


The later memory usage (once paging is enabled) could better be
explained by the VM folks.

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)



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