Example: bankruptcy

Linux Kernel Internals - whigg.ac.cn

Linux Kernel Internals Table of ContentsLinux Kernel Aivazian and Interrupt Filesystem (VFS).. Building the Linux Kernel Booting: Booting: BIOS Booting: bootsector and Using LILO as a bootloader .. High level initialisation .. SMP Bootup on Freeing initialisation data and Processing Kernel command and Interrupt Task Structure and Process Creation and termination of tasks and Kernel Linux Linux linked list Wait Kernel Bottom Task How System Calls Are Implemented on i386 Architecture?.. Atomic Spinlocks, Read write Spinlocks and Big Reader Semaphores and read/write Kernel Support for Loading Filesystem (VFS).. Inode Caches and Interaction with Filesystem File Descriptor File Structure Superblock and Mountpoint Example Virtual Filesystem: Example Disk Filesystem: Execution Domains and Binary Linux Kernel Internals iLinux Kernel InternalsTigran Aivazian August 2000 Introduction to the Linux Kernel .

Linux Kernel Internals Tigran Aivazian tigran@veritas.com 22 August 2000 Introduction to the Linux 2.4 kernel. The latest copy of this document can be always downloaded from:

Tags:

  Linux, Kernel, Linux kernel

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Linux Kernel Internals - whigg.ac.cn

1 Linux Kernel Internals Table of ContentsLinux Kernel Aivazian and Interrupt Filesystem (VFS).. Building the Linux Kernel Booting: Booting: BIOS Booting: bootsector and Using LILO as a bootloader .. High level initialisation .. SMP Bootup on Freeing initialisation data and Processing Kernel command and Interrupt Task Structure and Process Creation and termination of tasks and Kernel Linux Linux linked list Wait Kernel Bottom Task How System Calls Are Implemented on i386 Architecture?.. Atomic Spinlocks, Read write Spinlocks and Big Reader Semaphores and read/write Kernel Support for Loading Filesystem (VFS).. Inode Caches and Interaction with Filesystem File Descriptor File Structure Superblock and Mountpoint Example Virtual Filesystem: Example Disk Filesystem: Execution Domains and Binary Linux Kernel Internals iLinux Kernel InternalsTigran Aivazian August 2000 Introduction to the Linux Kernel .

2 The latest copy of this document can be always downloaded from: This documentation is free software; you can redistribute itand/or modify it under the terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any later version. The author is working assenior Linux Kernel engineer at VERITAS Software Ltd and wrote this book for the purpose of supporting theshort training course/lectures he gave on this subject, internally at Building the Linux Kernel Image Booting: Overview Booting: BIOS POST Booting: bootsector and setup Using LILO as a bootloader High level initialisation SMP Bootup on x86 Freeing initialisation data and code Processing Kernel command and Interrupt Management Task Structure and Process Table Creation and termination of tasks and Kernel threads Linux Scheduler Linux linked list implementation Wait Queues Kernel Timers Bottom Halves Task Queues Tasklets Softirqs How System Calls Are Implemented on i386 Architecture?

3 Atomic Operations Spinlocks, Read write Spinlocks and Big Reader Spinlocks Semaphores and read/write SemaphoresLinux Kernel Internals1 Kernel Support for Loading Filesystem (VFS) Inode Caches and Interaction with Dcache Filesystem Registration/Unregistration File Descriptor Management File Structure Management Superblock and Mountpoint Management Example Virtual Filesystem: pipefs Example Disk Filesystem: BFS Execution Domains and Binary Building the Linux Kernel ImageThis section explains the steps taken during compilation of the Linux Kernel and the output produced at eachstage. The build process depends on the architecture so I would like to emphasize that we only considerbuilding a Linux /x86 the user types 'make zImage' or 'make bzImage' the resulting bootable Kernel image is stored asarch/i386/boot/zImage or arch/i386/boot/bzImage respectively.

4 Here is how the image isbuilt:1. C and assembly source files are compiled into ELF relocatable object format (.o) and some of themare grouped logically into archives (.a) using ar(1)2. Using ld(1), the above .o and .a are linked into 'vmlinux' which is a statically linked, non strippedELF 32 bit LSB 80386 executable file3. is produced by 'nm vmlinux', irrelevant or uninteresting symbols are grepped Enter directory arch/i386/boot5. Bootsector asm code is preprocessed either with or without D__BIG_KERNEL__,depending on whether the target is bzImage or zImage, into or respectively6. is assembled and then converted into 'raw binary' form called bbootsect (or and raw converted into bootsect for zImage)7. Setup code setup,S ( includes ) is preprocessed into for bzImage or forzImage.

5 In the same way as the bootsector code, the difference is marked by D__BIG_KERNEL__present for bzImage. The result is then converted into 'raw binary' form called bsetup8. Enter directory arch/i386/boot/compressed and convert /usr/src/ Linux /vmlinux to $tmppiggy (tmpfilename) in raw binary format, removing .note and .comment ELF sections9. gzip 9 < $tmppiggy > $ Link $ into ELF relocatable (ld r) Compile compression routines and (still in arch/i386/boot/compressed directory) intoELF objects and Linux Kernel Internals Filesystem (VFS)212. Link together into bvmlinux (or vmlinux for zImage, don't mistake this for/usr/src/ Linux /vmlinux!). Note the difference between Ttext 0x1000 used for vmlinux and Ttext0x100000 for bvmlinux, for bzImage compression loader is high loaded13.

6 Convert bvmlinux to 'raw binary' removing .note and .comment ELF sections14. Go back to arch/i386/boot directory and using the program tools/build cat together bbootsect +bsetup + into bzImage (delete extra 'b' above for zImage). This writesimportant variables like setup_sects and root_dev at the end of the size of the bootsector is always 512 bytes. The size of the setup must be greater than 4 sectors but islimited above by about 12K the rule is:0x4000 bytes >= 512 + setup_sects * 512 + room for stack while running bootsector/setupWe will see later where this limitation comes upper limit on the bzImage size produced at this step is about for booting with LILO and 0xFFFF paragraphs (0xFFFF0 = 1048560 bytes) for booting raw image, from floppy disk or CD ROM(El Torito emulation mode).

7 Note, that tools/build validates the size of the boot sector, of the Kernel image and lower bound on the size ofsetup but not the upper bound of setup so it is easy to build a broken Kernel by adding some large ".space" atthe end of Booting: OverviewThe boot process details are architecture specific so we shall focus our attention on the IBM PC/IA32architecture. Due to old design and backward compatibility, the PC firmware boots the operating system in anold fashioned manner. This process can be separated into the following six logical stages:1. BIOS selects the boot device2. BIOS loads the bootsector from the boot device3. Bootsector loads setup, decompression routines and compressed Kernel image4. The Kernel is uncompressed in protected mode5. Low level initialisation performed by asm code6.

8 High level C Booting: BIOS POST1. The power supply starts the clock generator and asserts #POWERGOOD signal on the bus2. CPU #RESET line is asserted (CPU now in real 8086 mode)3. %ds=%es=%fs=%gs=%ss=0, %cs:%eip = 0xFFFF:0000 (ROM BIOS POST code)4. All the checks performed by POST with interrupts disabled5. IVT initialised at address 0 Linux Kernel Internals Booting: Overview36. The BIOS Bootstrap Loader function is invoked via int 0x19 with %dl containing the boot device'drive number'. This loads track 0, sector 1 at physical address 0x7C00 (0x07C0:0000). Booting: bootsector and setupThe bootsector used to boot Linux Kernel could be either: Linux bootsector, arch/i386/ LILO (or other bootloader's) bootsector No bootsector (loadlin etc)We consider here the Linux bootsector in detail.

9 The first few lines initialize the convenience macros to beused for segment values:29 SETUPSECS = 4 /* default nr of setup sectors */30 BOOTSEG = 0x07C0 /* original address of boot sector */31 INITSEG = DEF_INITSEG /* we move boot here out of the way */32 SETUPSEG = DEF_SETUPSEG /* setup starts here */33 SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */34 SYSSIZE = DEF_SYSSIZE /* system size: # of 16 byte clicks */(the numbers on the left are the line numbers of file) The values of DEF_INITSEG,DEF_SETUPSEG, DEF_SYSSEG, DEF_SYSSIZE are taken from include/ :/* Don't touch these, unless you really know what you're doing. */#define DEF_INITSEG 0x9000#define DEF_SYSSEG 0x1000#define DEF_SETUPSEG 0x9020#define DEF_SYSSIZE 0x7F00 Now, let us consider the actual code of : 54 movw $BOOTSEG, %ax 55 movw %ax, %ds 56 movw $INITSEG, %ax 57 movw %ax, %es 58 movw $256, %cx 59 subw %si, %si 60 subw %di, %di Linux Kernel Internals Booting: bootsector and setup4 61 cld 62 rep 63 movsw 64 ljmp $INITSEG, $go 65 # bde changed 0xff00 to 0x4000 to use debugger at 0x6400 up (bde).

10 We 66 # wouldn't have to worry about this if we checked the top of memory. Also 67 # my BIOS can be configured to put the wini drive tables in high memory 68 # instead of in the vector table. The old stack might have clobbered the 69 # drive table. 70 go: movw $0x4000 12, %di # 0x4000 is an arbitrary value >= 71 # length of bootsect + length of 72 # setup + room for stack; 73 # 12 is disk parm size. 74 movw %ax, %ds # ax and es already contain INITSEG 75 movw %ax, %ss 76 movw %di, %sp # put stack at INITSEG:0x4000 lines 54 63 move the bootsector code from address 0x7C00 to 0x90000.


Related search queries