ebook img

The art of Linux kernel design: illustrating the operating system design principle and implementation PDF

524 Pages·2014·9.66 MB·English
by  DazhaoChenKeFengLiuTianhouQiSongRuobingWuWenfengLiangYangLixiang
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The art of Linux kernel design: illustrating the operating system design principle and implementation

Art The of Linux KerneL Design Illustrating the Operating System Design Principle and Implementation TThhiiss ppaaggee iinntteennttiioonnaallllyy lleefftt bbllaannkk Art The of Linux KerneL Design Illustrating the Operating System Design Principle and Implementation Yang Lixiang • Liang Wenfeng Chen Dazhao • Liu Tianhou, Wu Ruobing • Song Qi • Feng Ke CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2014 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Version Date: 20140224 International Standard Book Number-13: 978-1-4665-1804-9 (eBook - PDF) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com Contents Preface xi Author xiii 1. From Power-Up to the Main Function 1 1.1 Loading BIOS, Constructing Interrupt Vector Table, and Activating Interrupt Service Routines in the Real Mode.............................2 1.1.1 Procedure for Starting BIOS..................................2 1.1.2 BIOS Loads the Interrupt Vector Table and Interrupt Service Routines into Memory.......................................3 1.2 Loading the OS Kernel and Preparing for the Protected Mode .............4 1.2.1 Loading Bootsect............................................5 1.2.2 Loading the Second Part of Code— —Setup ....................7 1.2.3 Load the System Module ....................................12 1.3 Transfer to 32-Bit Mode and Prepare for the Main Function..............16 1.3.1 Disable Interrupts and Move System to 0x00000 ...............16 1.3.2 Set the Interrupt Descriptor Table and Global Descriptor Table .................................................18 1.3.3 Open A20 and Achieve 32-Bit Addressing.....................20 v 1.3.4 Prepare for the Implementation of head.s in the Protected Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..21 1.3.5 CPU Starts to Execute head.s ................................23 1.4 Summary ..........................................................43 2. Device Initialization and Process 0 Activation 45 2.1 Set Root Device 2 and Hard Disk......................................46 2.2 Set Up Physical Memory Layout, Buffer Memory, Ramdisk, and Main Memory......................................................46 2.3 Ramdisk Setup and Initialization .....................................49 2.4 Initialization of the Memory Management Structure mem_map ..........52 2.5 Binding the Interrupt Service Routine .................................53 2.6 Initialize the Request Structure of the Block Device .....................58 2.7 Binding with the Interrupt Service Routine of Peripherals and Establishing the Human–Computer Interaction Interface . . . . . . . . . . . . . . . .61 2.7.1 Set the Serial Port ..........................................61 2.7.2 Set the Display.............................................62 2.7.3 Set the Keyboard...........................................62 2.8 Time Setting .......................................................66 2.9 Initialize Process 0 ..................................................67 2.9.1 Initialization of Process 0 ...................................71 2.9.2 Set the Timer Interrupt .....................................73 2.9.3 Set the Entrance of System Call ..............................74 2.10 Initialize the Buffer Management Structure ............................75 2.11 Initialize the Hard Disk..............................................78 2.12 Initialize the Floppy Disk ............................................80 2.13 Enable the Interrupt.................................................80 2.14 Process 0 Moves from Privilege Level 0 to 3 and Becomes a Real Process .................................................81 3. Creation and Execution of Process 1 85 3.1 Creation of Process 1 ................................................85 3.1.1 Preparation for Creating Process 1 ...........................85 3.1.2 Apply for an Idle Position and a Process Number for Process 1...91 3.1.3 Call Copy_process()........................................92 3.1.4 Set the Page Management of Process 1 ........................98 3.1.4.1 Set the Code Segment and Data Segment in the Linear Address Space of Process 1..................99 3.1.4.2 Create the First Page Table for Process 1 and Set the Corresponding Page Directory Entry........101 3.1.5 Process 1 Shares Files of Process 0...........................103 3.1.6 Set the Table Item in the GDT of Process 1 ...................104 3.1.7 Process 1 Is in Ready State to Complete the Creation of Process 1.................................................105 vi Contents 3.2 Kernel Schedules a Process for the First Time..........................109 3.3 Turn to Process 1 to Execute.........................................113 3.3.1 Preparing to Install the Hard Disk File System by Process 1.....115 3.3.1.1 Process 1 Set hd_info of Hard Disk................115 3.3.1.2 Read the Hard Disk Boot Blocks to the Buffer.......116 3.3.1.3 Bind the Buffer Block with Request................125 3.3.1.4 Read the Hard Disk .............................129 3.3.1.5 Wait for Hard Disk Reading Data, Process Scheduling, and Switch to Process 0 to Execute .....134 3.3.1.6 Hard Disk Interruption Occurs during the Execution of Process 0...........................137 3.3.1.7 After Reading the Disk, Switch Process Scheduling to Process 1..........................143 3.3.2 Process 1 Formats the Ramdisk and Replaces the Root Device as the Ramdisk............................................146 3.3.3 Process 1 Loads the Root File System into the Root Device......149 3.3.3.1 Copying the Super Block of the Root Device to the super_block[8]..................................152 3.3.3.2 Mount the i node of the Root Device to the Root Device Super Block in super_block[8]..............157 3.3.3.3 Associate the Root File System with Process 1.......160 4. Creation and Execution of Process 2 165 4.1 Open the Terminal Device File and Copy the File Handle ...............165 4.1.1 Open the Standard Input Device File ........................165 4.1.1.1 File_table[0] is Mounted to Filp[0] in Process 1 .....165 4.1.1.2 Determine the Starting Point of Absolute Path......167 4.1.1.3 Acquiring the i node of Dev ......................172 4.1.1.4 Determine the i node of Dev as the Topmost i node ......................................175 4.1.1.5 Acquire the i node of the tty0 File .................177 4.1.1.6 Determine tty0 as the Character Device File........180 4.1.1.7 Set file_table[0] .................................181 4.1.2 Open the Standard Output and Standard Error Output Device File ...............................................182 4.2 Fork Process 2 and Switch to Process 2 to Execute......................187 4.3 Load the Shell Program.............................................198 4.3.1 Close the Standard Input File and Open the rc File ............198 4.3.2 Detect the Shell File .......................................201 4.3.2.1 Detect the Attribute of the i node .................201 4.3.2.2 Test File Header’s Attributes......................202 4.3.3 Prepare to Execute the Shell Program........................206 4.3.3.1 Load Parameters and Environment Variables.......206 4.3.3.2 Adjust the Management Structure of Process 2......210 4.3.3.3 Adjust EIP and ESP to Execute Shell...............212 Contents vii 4.3.4 Execute the Shell Program..................................214 4.3.4.1 Execute the First Page Program Loading by the Shell....................................214 4.3.4.2 Map the Physical Address and Linear Address of the Loading Page................................218 4.4 The System Gets to the Idle State.....................................219 4.4.1 Create the Update Process..................................219 4.4.2 Switch to the Shell Process..................................220 4.4.3 Reconstruction of the Shell.................................228 5. File Operation 231 5.1 Install the File System ..............................................231 5.1.1 Get the Super Block of Peripherals...........................232 5.1.2 Confirm the Mount Point of the Root File System .............234 5.1.3 Mount the Super Block with the Root File System .............235 5.2 Opening a File.....................................................236 5.2.1 Mount *Filp[20] in the User Process to File_table[64] ..........238 5.2.2 Get the File’s i node........................................239 5.2.2.1 Get the i node of the Directory File................239 5.2.2.2 Get the i node of the Target File...................248 5.2.3 Bind File i node with File_table[64]..........................249 5.3 Reading a File .....................................................250 5.3.1 Locate the Position of the Data Block in the Peripherals ........250 5.3.2 Data Block Is Read into the Buffer Block .....................254 5.3.3 Copy Data from the Buffer into the Process Memory...........255 5.4 Creating a New File ................................................256 5.4.1 Searching a File ...........................................256 5.4.2 Create a New i node for a File ...............................258 5.4.3 Create a New Content Item.................................260 5.5 Writing a File......................................................265 5.5.1 Locate the Position of the File to Be Written In................265 5.5.2 Apply for a Buffer Block....................................267 5.5.3 Copy Specified Data from the Process Memory to the Buffer Block ..............................................268 5.5.4 Two Ways to Synchronize Data from the Buffer to the Hard Disk................................................269 5.6 Modifying a File ...................................................272 5.6.1 Reposition the Current Operation Pointer of the File...........273 5.6.2 Modifying Files...........................................273 5.7 Closing a File......................................................275 5.7.1 Disconnecting Filp and File_table[64] in the Current Process......275 5.7.2 Releasing the Files’ i node ..................................277 5.8 Deleting a File .....................................................277 5.8.1 Checking the Deleting Conditions of Files....................278 5.8.2 Specific Deleting Work.....................................279 viii Contents 6. The User Process and Memory Management 283 6.1 Linear Address Protection ..........................................284 6.1.1 Patterns of the Process Linear Address Space .................284 6.1.2 Segment Base Addresses, Segment Limit, GDT, LDT, and Privilege Level ............................................284 6.2 Paging............................................................287 6.2.1 Linear Address to Physical Address..........................287 6.2.2 Process Execution Paging ..................................289 6.2.3 Process Sharing the Page...................................295 6.2.4 Kernel Paging.............................................299 6.3 Complete Process of User Process from Creation to Exit ................302 6.3.1 Create Process str1.........................................302 6.3.2 Preparation to Load str1. ...................................315 6.3.3 Running and Loading of Process str1 ........................320 6.3.4 Exiting of Process str1......................................325 6.4 Multiple User Processes Run Concurrently............................331 6.4.1 Process Scheduling........................................331 6.4.2 Page Protection ...........................................336 7. Buffer and Multiprocess File 343 7.1 Function of Buffer..................................................343 7.2 Structure of Buffer .................................................345 7.3 The Function of b_dev, b_blocknr, and Request........................346 7.3.1 Ensure the Correctness of the Data Interaction between Processes and Buffer Block .................................346 7.3.2 Let the Data Stay in the Buffer as Long as Possible .............353 7.4 Function of Uptodate and Dirt.......................................359 7.4.1 Function of b_uptodate ....................................359 7.4.2 Function of the b_dirt .....................................365 7.4.3 Function of the i_update, i_dirt, and s_dirt...................368 7.5 Function of the Count, Lock, Wait, Request ...........................370 7.5.1 Function of b_count.......................................370 7.5.2 Function of i_count .......................................372 7.5.3 Function of b_lock and *b_wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . .375 7.5.4 Function of i_lock, i_wait, s_lock, and *s_wait................378 7.5.5 Function of Request .......................................381 7.6 Example 1: Process Waiting Queue of Buffer Block .....................383 7.7 Overall Look at the Buffer Block and the Request Item..................408 7.8 Example 2: Comprehensive Examples of Multiprocess Operating File.....411 8. Inter-Process Communication 431 8.1 Pipe Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .431 8.1.1 The Creation Process of the Pipe ............................433 8.1.2 Operation of Pipe .........................................439 Contents ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.