Inside Linux Kernel

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[edit] What is this book about?

This book explores the Linux kernel, an open-source operating system kernel for many different architectures. What does it do? How does it do things?

[edit] Linux kernel development

First things first. How is the Linux kernel developed?

There are thousands of hackers working on the Linux kernel, spread over the world. These people are also called Linux hackers. At the top of the Linux kernel development is Linus Torvalds, the starter of the Linux kernel. The kernel is written in C, with some architecture-specific parts written in assembler.

[edit] Version numbering

The Linux kernel's version number is split up like so: major.status.minor. Major (currently 2) is only incremented for big kernel changes. If status is an odd number, it is a test kernel, and isn't production ready. An even status number signifies that the kernel is stable enough for general use, and minor revision numbers are incremented with each release. Recently, Linus himself proposed a light variation (or a rationalization, as you prefer) of this model. In the new system, an odd number always means that the system isn't recommended for production. In detail, a kernel whose minor number is odd is considered to be a version that adds some minor features to the previous release and thus might introduce some bugs. After some time (generally a month or two), when the bugfixes are ready they get merged and we have a new release with an even minor. A status odd number means that the kernel is facing big changes from the previous branch and it will need some time to reach the stable point (and thus became a new, even version). When the major number is an odd one, to quote Linus, this will mean he "went crazy and tried to turn Linux into a microkernel using a message passing version of Visual Basic". By this, he meant that the kernel will face revolutionary changes once in this stage.

[edit] Licensing

The Linux kernel is licensed under the GPL, a free software license devised by Richard Stallman. This allows the Linux kernel to be freely shared by all its users, with no restrictions on its use apart from the fact that any derivations of the source must be under the same licence.

[edit] Booting

What does the kernel do when you boot your computer? There are several major steps that happen prior to the logon screen appearing when you boot the GNU/Linux system. In order they are:

[edit] Firmware/Post

Your computer Firmware/BIOS (Basic Input Output System) is a small computer program whose starting address is loaded into the Program Counter register of your computers CPU when power is applied to your system. The Firmware/Post (Power-On Self Test) performs a few rudimentary tests on your computer system (usually memory checks, including possibly a barber-pole memory sieve routine to check your memory, checks to see if you have a keyboard, mouse, hard drive, etc. on your system. It then goes through a user defined list of devices, looking for a small program called a bootloader. The list of devices could be a cdrom, dvd drive, hard disk, etc. When it finds a bootloader, it loads the bootloader's starting address into the CPU's Program Counter register.


[edit] Bootloader

The Linux bootloader may be LILO, or now more commonly GRUB. The bootloader may have only one operating system to boot, or it may have several, and if it has several, it presents a list of which system to load. The operating system need not be Linux.

If the Linux operating system is selected, and the system is on Intel X86/32 hardware, then the bootloader is running in "real" x86 mode (running as if the CPU is an 8086), even though the processor may be a Pentium 4/Celeron/Xeon.

The job of the bootloader is to reset all CPU registers, load an operating system into memory and start it running by loading the starting address into the CPU's Program Counter. Since the Intel 8086 couldn't support more than 640k of memory and the modern Linux kernel is bigger than 640k, special jump instructions (trampoline) are used to load the compressed Linux kernel called the zImage into memory.

The bootloader loads several programs to help it do this job, including setup.S and system which the bootloader loads into low memory.

setup.s is responsible for getting the system data from the BIOS, and putting it into appropriate places in system memory. setup.S asks the BIOS for memory/disk/other parameters, and relocates itself and system from the low memory location where it was loaded, to a "safe" place: 0x90000-0x901FF (INITSEG), where the boot-block used to be. setup.S then uncompresses the compressed (zImage) kernel image at starting address 0x10000 or 64K, just beyond the firmware's data space (SYSSEG). setup.S then moves the uncompressed kernel from address 0x10000 to address 0x1000 (4k, leaving one page of low memory free) switches from "real" x86 mode to emm386 mode, and loads the kernels' starting address into the CPU's Program Counter register (starts the kernel running).

One of the last things setup.S does is run the video setup and detection code, video.S. The shuffling of the kernel back and forth in memory is to overcome limitations of the PC bios memory addressability (640k), and free up several hundred kilobytes of system memory (the actual amount freed is reported by the system). The 4k is used for handling virtual memory. The special load instructions (trampoline) are required to 'cheat' the system, as the instructions load part of the kernel into memory locations beyond the 640k barrier that the (then currently running "real mode") system knows about. In the process of shuffling the kernel around, the memory originally written to by the BIOS, and also where the setup and system programs were loaded are overwritten by the kernel image, hence the need for moving them to a safe place, beyond where the uncompressed kernel image is loaded. The actual load is slightly more complicated on x86 systems as not all BIOS's report their memory on the same registers, report information in different ways, or map their memory/system resources in unconventional ways, and also some BIOS's must be prodded for information several times or have A20 Gate problems.

Other computer architectures may not have the limitations of the Intel x86 processor, and so loading the Linux kernel is done in a much more straightforward manner.

[edit] The Running Kernel

Start Kernel.

[edit] Hardware

How does it communicate with the hardware?

[edit] CPU Support

The Linux kernel supports various types of CPU instruction sets, such as x86, x86-64 (AMD64/EM64T), 68000, PowerPC, Xscale(base on ARM), ARM, and more. It is one of the most widely ported operating systems.

[edit] Mainboard

The Mainboard, aka Motherboard, is not so special to the OS, but the OS only know what cpu, what chipset, and what peripher..

[edit] Memory

[edit] Harddisks

[edit] Other

[edit] Filesystems

Linux uses ext2, ext3 and ReiserFS as native filesystems (along with XFS and JFS), although other filesystems such as FAT are supported in the interests of backwards compatibility.

[edit] Time (system ticks)

The kernel measures time based on its HZ setting, which can be specified at the time of kernel compilation. HZ is usually set to a value between 100 and 1000 (tick period of 10 ms to 1 ms). The value of the current number of ticks since the system was last booted are called "jiffies".

[edit] tty

tty is an acronym for TeleTYpe writer. This is UNIX terminology for any text screen that is presented to the user, for example a console (perhaps through a serial line) or a telnet or ssh session.

[edit] Kernel panic

A kernel panic is a kernel error from which the kernel is not able to recover. The only immediate remedy to this problem is a system reboot.

[edit] Kernel programming model

[edit] Introduction

->Unix theory See books Like "Operating Systems Design and Implementation, 3/E" by Andrew S. Tanenbaum and Albert S. Woodhull ,or "[Operating System Concepts]http://os-book.com/" by Avi Silberschatz, Peter Baer Galvin, and Greg Gagne.

[edit] kernel modularization

(about kernel modules)

[edit] kernel call

(example printk)

[edit] Kernel code

->premptible code

->security considerations

Personal tools