Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app04.tex V1 - 09/04/2008 6:12pm Page 1227

Appendix D: System Startup


First, the location of the kernel in physical and virtual memory is noted. This is done using constants
inserted by the linker when the kernel was compiled. These constants specify the start and end addresses
of the various segments as shown here (see also Appendix E):

arch/x86/kernel/setup_32.c
init_mm.start_code = (unsigned long) _text;
init_mm.end_code = (unsigned long) _etext;
init_mm.end_data = (unsigned long) _edata;
init_mm.brk = init_pg_tables_end + PAGE_OFFSET;

code_resource.start = virt_to_phys(_text);
code_resource.end = virt_to_phys(_etext)-1;
data_resource.start = virt_to_phys(_etext);
data_resource.end = virt_to_phys(_edata)-1;
bss_resource.start = virt_to_phys(&__bss_start);
bss_resource.end = virt_to_phys(&__bss_stop)-1;

parse_early_paramperforms partial interpretation of the command-line parameters. It does this only
for arguments relating to memory management setup; for example, the total size of available physi-
cal memory, or the position of specific ACPI and BIOS memory areas. Users can overwrite values that
the kernel has detected incorrectly. Armed with this information,setup_memorydetects the number
of physical memory pages in the low-memory and high-memory areas. It also initializes the bootmem
allocator.

paging_initthen sets up the kernel’s reference page table. This is used not only to map physical mem-
ory but also to manage thevmallocareas, as discussed in Chapter 3. The new page table is enabled
by inserting the address ofswapper_pg_dir— the variable in which the page table data structures are
saved — into the CR3 register of the processor.

Thebuild_all_zonelistsfunction (which was discussed in Chapter 3 and which is responsible for cre-
ating the memory management zone lists) is invoked bystart_kernelto complete memory management
initialization and to put the bootmem allocator in control of the rest of the boot procedure.

InterpretingCommand-LineArguments


parse_argsis invoked byparse_early_paraminstart_kerneland assumes responsibility for inter-
preting the command-line parameters passed to the kernel at boot time. The same inherent problem is
encountered as in userspace — a string containing key/value pairs in the formkey1=val1 key2=val2
must be broken down into its constituent parts. The options set must be saved in the kernel or specific
responses must be triggered.

The kernel is faced with this parameter problem not only at boot time but also when modules are inserted.
It therefore makes good sense to use the same mechanism to solve the problem in order to avoid the
unnecessary duplication of code.

The binary file contains an instance ofkernel_paramfor each kernel parameter — both in dynamically
loaded modules and in the static kernel binary. This instance is structured as follows:

<moduleparam.h>
/* Returns 0, or -errno. arg is in kp->arg. */
typedef int (*param_set_fn)(const char *val, struct kernel_param *kp);
/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
Free download pdf