Documentkc

  • View
    117

  • Download
    0

Embed Size (px)

Text of Documentkc

The Linux Kernel 0.01 Commentary

Mobiuz Technologies

Pramode C.E

Gopakumar C.ECisco Systems

The Linux Kernel 0.01 Commentary by Pramode C.E and Gopakumar C.E This document describes the structure of a prehistoric Linux kernel as understood by the authors. Operating system newbies, hardware hackers or people with too much time in their hands than they would care to admit can use this document to learn more about 80386 architecture and the simple skeleton from which a great Operating Sytem (and a greater movement) was built. The authors are NOT kernel hackers, and as such, the document is not guaranteed to be technically perfect. Reports of errors will be gratefully received and, time permitting, corrections would be incorporated in later versions. Flames will be redirected to /dev/null. Happy Hacking!

Table of Contents1. Getting Started ...................................................................................................................1 1.1. Introduction...............................................................................................................1 1.1.1. Copyright and License ...................................................................................1 1.1.2. Feedback and Corrections..............................................................................1 1.1.3. Acknowledgements........................................................................................1 1.1.4. Reading 0.01 source.......................................................................................1 1.1.5. Things you must know...................................................................................1 1.1.6. How to read this document ............................................................................2 2. Building Kernel 0.01 ..........................................................................................................5 2.1. Getting 0.01 Up And Running ..................................................................................5 3. Processor Architecture ......................................................................................................9 3.1. The 386 Architecture ................................................................................................9 3.1.1. Segmentation in 386 ......................................................................................9 3.1.2. Paging in 386 ...............................................................................................13 3.1.3. Interrupts and Exceptions. ...........................................................................17 3.1.4. Tasks in 386 .................................................................................................20 3.1.5. Privilege Levels And The Stack...................................................................22 4. The Big Picture.................................................................................................................25 4.1. Step Wise Renement Of The 0.01 Kernel - Step 1 ...............................................25 4.1.1. The Source Tree ...........................................................................................25 4.1.2. The Makeles...............................................................................................25 4.1.3. The Big Picture ............................................................................................25 5. Flow of control through the Kernel ................................................................................33 5.1. Step Wise Renement Of The 0.01 Kernel - Step 2 ...............................................33 5.1.1. Normal Activities In a Running OS.............................................................33 5.1.2. linux/boot Directory.....................................................................................33 5.1.3. linux/init Directory.......................................................................................34 5.1.4. linux/kernel Directory..................................................................................34 5.1.5. linux/mm Directory......................................................................................36 5.1.6. linux/fs Directory .........................................................................................36 5.1.7. linux/lib Directory........................................................................................38 5.1.8. linux/include Directory ................................................................................38 5.1.9. linux/tools Directory ....................................................................................38 6. Journey to the Center of the Code..................................................................................39 6.1. Step Wise Renement Of The 0.01 Kernel - Step 3 ...............................................39 6.1.1. linux/boot .....................................................................................................39 6.1.2. linux/kernel ..................................................................................................54 6.1.3. linux/mm ......................................................................................................82 6.1.4. linux/fs .........................................................................................................91 6.2. The End.................................................................................................................103 6.2.1. Do try and get 0.01 up and kicking............................................................103

iii

iv

Chapter 1. Getting Started1.1. Introduction1.1.1. Copyright and LicenseCopyright (C) 2003 Gopakumar C.E, Pramode C.E This document is free; you can redistribute and/or modify this under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation. A copy of the license is available at www.gnu.org/copyleft/fdl.html .

1.1.2. Feedback and CorrectionsKindly forward feedback and corrections to gopakumar_ce@yahoo.com.

1.1.3. AcknowledgementsGopakumar would like to thank the faculty and friends at the Government Engineering College, Trichur for introducing him to GNU/Linux and initiating a Free Software Drive which ultimately resulted in the whole Computer Science curriculum being taught without the use of propreitary tools and platforms. We express our gratitude towards those countless individuals who answer our queries on Internet newsgroups and mailing lists, those people who maintain this infrastructure, the hackers who write cool code just for the fun of writing it and everyone else who is a part of the great Free Software movement.

1.1.4. Reading 0.01 sourceThe Linux kernel version 0.01 is a tiny program (compared to the size of the current kernel). A newbie is faced with a problem - whether to read and understand a part of a big, sophisticated program or whether to read and understand almost in full a smaller and MUCH less sophisticated version. If you have of plenty of time at hand, you can do both! We started off by learning a bit of 80386 architecture and then poking around an ancient Linux kernel (you know, Linus too was a newbie!), trying to compile it on our modern Red Hat Linux system (RH version 6.2 - we did these experiments some time back) and getting frustrated reading huge Intel manuals describing the mysteries of the 386 processor. This document might be useful for those sufciently crazy folks out there (we know there would be many) who would like to conduct similar experiments.

1.1.5. Things you must knowWe expect that you have/know:

Programming experience in any UNIX environment, familiarity with UNIX system calls. 1

Chapter 1. Getting Started

Simple theoretical concepts about Operating Systems - like layers of an OS, scheduling, memory management etc. Good Knowledge of 8086 architecture, how interfacing is done etc. Basic idea about 80386 architecture - like switching to protected mode, how is protection enforced, how is paging done, etc. Basic concepts about what the output of assemblers, compilers, linkers etc will look like (ie their headers, symbol tables etc).

Well, it is quite difcult to enumerate exactly what you have to know and how much to know. The only way is to proceed with this book and learn the things that you dont know whenever you nd it necessary. Please dont do the reverse process of learning the required things rst and then proceeding with the actual intention. Learning for the sake of learning is boring and inefcient. The chapter on 80386 may not provide all the information that you need, it is presented just as a quick tour of 80386 which will greatly help you when you read any other detailed books on 80386. Anything else that you need to know about which you dont nd in this book can be found in one of the below mentioned reference material. 1. The C programming language by K & R 2. Design of the Unix Operating System by Maurice.J.Bach 3. Advanced Programming in the Unix environment by W. Richard Stevens 4. The info and man pages (mainly on gcc, as, ld, as86, ld86) 5. The Intel 80386 manuals 6. The Indispensable PC Hardware Book by Hans-Peter Messmer The book 2. is extremely essential because Linus has based the design of 0.01 along the lines specied by the author of the book. The book 3. is needed just for reference on UNIX programming. You can do even without it. The book 6. is simply a must if you dont have any other reference on the interfacing chips in a PC;It is worth having a copy. Also it is better to refer the 80386 manuals for information rather than any 80386 text books. If you have a pretty good net connection, you can download the Intel Manuals from the URL we have mentioned at the end of this sub-section. We just want architecture rel