%
When the PC is powered up, the 80x86 processor finds itself in real
mode and executes the code at address 0xFFFF0, which corresponds
to a ROM-BIOS address. The PC BIOS performs some tests on the system
and initializes the interrupt vector at physical address 0. After that
it loads the first sector of a bootable device to 0x7C00, and jumps to it.
The device is usually the floppy or the hard drive. The preceding
description is quite a simplified one, but it's all that's needed to
understand the kernel initial workings.
The very first part of the \ kernel is written in 8086 assembly
language (<#2408#> boot/bootsect.S<#2408#>). When run, it moves itself to
absolute address 0x90000, loads the next 2 kBytes of code from the
boot device to address 0x90200, and the rest of the kernel to address
0x10000. The message ``<#2409#> Loading...<#2409#>'' is displayed during system
load. Control is then passed to the code in <#2410#> boot/Setup.S<#2410#>, another real-mode
assembly source.
The setup portion identifies some features of the host system and the
type of
vga board. If requested to, it asks the user to choose the video mode for the
console. It then moves the whole system from address 0x10000 to address 0x1000,
enters protected mode and jumps to the rest of the system (at 0x1000).
The next step is kernel decompression. The code at 0x1000 comes from
<#2411#> zBoot/head.S<#2411#> which initializes registers and invokes
<#2412#> decompress_kernel()<#2412#>, which in turn is made up of <#2413#> zBoot/inflate.c<#2413#>,
<#2414#> zBoot/unzip.c<#2414#> and <#2415#> zBoot/misc.c<#2415#>. The decompressed data goes to
address 0x100000 (1 Meg), and this is the main reason why \ can't run
with less than 2 megs ram.
#tex2html_wrap2948#
#tex2html_wrap2950#
Decompressed code is executed at address 0x1010000 <#2421#> [Maybe I've
lost track of physical addresses, here, as I don't know very well gas
source code]<#2421#>, where all the 32-bit setup is accomplished: IDT, GDT
and LDT are loaded, the processor and coprocessor are identified, and
paging is setup; eventually, the routine <#2422#> start_kernel<#2422#> is
invoked. The source for the above operations is in <#2423#> boot/head.S<#2423#>. It is
probably the trickiest code in the whole kernel.
Note that if an error occurs during any of the preceding steps, the
computer will lockup. The OS can't deal with errors when it isn't yet
fully operative.
<#2424#> start_kernel()<#2424#> resides in <#2425#> init/main.c<#2425#>, and never
returns. Anything from now on is coded in C language, left aside
interrupt management and system call enter/leave (well, most of the
macros embed assembly code, too).