Section 14.3. Kernel Initialization

   


14.3. Kernel Initialization

When the FreeBSD kernel is started by the boot program, it does an initialization in preparation for the execution of application programs. The initialization process is divided into roughly three stages. The first stage requires handcrafted assembly-language code to set up the hardware for the more generic non-assembly-language code to operate. The second stage loads and initializes kernel modules that implement all the kernel's internal services, including configuring and initializing the I/O devices on the machine. The third stage starts up the system-resident processes that compose the foundation for the normal FreeBSD run-time environment and then executes the user-level-startup scripts.

Assembly-Language Startup

The first steps taken by the system during initialization are carried out by assembly-language code. This work is highly machine dependent and includes the following:

  • Setting up the run-time stack

  • Identifying the type of CPU on which the system is executing

  • Calculating the amount of physical memory on the machine

  • Enabling the virtual-address-translation hardware

  • Initializing the memory-management hardware

  • Setting up tables for SMP operation, if necessary

  • Crafting the hardware context for process 0

  • Invoking the initial C-based entry point of the system

Although the details of these steps vary from architecture to architecture, the broad outline described here is applicable to any machine on which FreeBSD runs.

When the boot program starts the FreeBSD kernel running, it sets up only two components of the machine state:

  1. All interrupts are blocked.

  2. The hardware address-translation facility is disabled so that all memory references are to physical memory locations.

The boot program also passes to the kernel the identity of the boot device and a set of boot flags. The FreeBSD kernel presumes nothing else about the state of the machine on which it is running.

The kernel is loaded into physical memory at a known location often, at the lowest physical address. In normal operation, the address-translation hardware is enabled, and the kernel image is mapped into virtual memory starting at an address near the top of the address space. Before the address translation has been enabled, the assembly-language startup code must convert all absolute addresses from their virtual-memory location to their physical-memory location. The kernel is usually loaded into contiguous physical memory, so the translation is simply a constant offset that can be saved in an index register.

A second task of the startup code is to identify the type of CPU on which the system is executing. Often, older versions of the CPU support only a subset of the complete instruction set. For these machines, the kernel must emulate the missing hardware instructions in software. For most architectures, FreeBSD can be configured such that a single kernel load image can support all the models in an architecture family. The startup code may also call machine-dependent code to initialize the CPU or virtual-memory subsystem.


   
 


The Design and Implementation of the FreeBSD Operating System
The Design and Implementation of the FreeBSD Operating System
ISBN: 0201702452
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net