Learn Linux Kernel Programming, Hands-On: a Uniquely Effective Top-Down Approach
Total Page:16
File Type:pdf, Size:1020Kb
The Linux® Kernel Primer: A Top-Down Approach for x86 and PowerPC Architectures By Claudia Salzberg Rodriguez, Gordon Fischer, Steven Smolski ............................................... Publisher: Prentice Hall PTR Pub Date: September 21, 2005 ISBN: 0-13-118163-7 Pages: 648 Table of Contents | Index Learn Linux kernel programming, hands-on: a uniquely effective top-down approach The Linux® Kernel Primer is the definitive guide to Linux kernel programming. The authors' unique top-down approach makes kernel programming easier to understand by systematically tracing functionality from user space into the kernel and carefully associating kernel internals with user-level programming fundamentals. Their approach helps you build on what you already know about Linux, gaining a deep understanding of how the kernel works and how its elements fit together. One step at a time, the authors introduce all the tools and assembly language programming techniques required to understand kernel code and control its behavior. They compare x86 and PowerPC implementations side-by-side, illuminating cryptic functionality through carefully- annotated source code examples and realistic projects. The Linux® Kernel Primer is the first book to offer in-depth coverage of the rapidly growing PowerPC Linux development platform, and the only book to thoroughly discuss kernel configuration with the Linux build system. Coverage includes Data structures x86 and PPC assembly language Viewing kernel internals Linux process model User and kernel space Interrupts and exceptions Memory allocation and tracking Tracing subsystem behavior I/O interactions Filesystems and file operations Scheduling and synchronization Kernel boot process Kernel build system Configuration options Device drivers And more... If you know C, this book teaches you all the skills and techniques you need to succeed with Linux kernel programming. Whether you're a systems programmer, software engineer, systems analyst, test professional, open source project contributor, or simply a Linux enthusiast, you'll find it indispensable. © Copyright Pearson Education. All rights reserved. The Linux® Kernel Primer: A Top-Down Approach for x86 and PowerPC Architectures By Claudia Salzberg Rodriguez, Gordon Fischer, Steven Smolski ............................................... Publisher: Prentice Hall PTR Pub Date: September 21, 2005 ISBN: 0-13-118163-7 Pages: 648 Table of Contents | Index Copyright Prentice Hall: Open Source Software Development Series Foreword Acknowledgments About the Authors Preface Intended Audience Organization of Material Our Approach Conventions Chapter 1. Overview Section 1.1. History of UNIX Section 1.2. Standards and Common Interfaces Section 1.3. Free Software and Open Source Section 1.4. A Quick Survey of Linux Distributions Section 1.5. Kernel Release Information Section 1.6. Linux on Power Section 1.7. What Is an Operating System? Section 1.8. Kernel Organization Section 1.9. Overview of the Linux Kernel Section 1.10. Portability and Architecture Dependence Summary Exercises Chapter 2. Exploration Toolkit Section 2.1. Common Kernel Datatypes Section 2.2. Assembly Section 2.3. Assembly Language Example Section 2.4. Inline Assembly Section 2.5. Quirky C Language Usage Section 2.6. A Quick Tour of Kernel Exploration Tools Section 2.7. Kernel Speak: Listening to Kernel Messages Section 2.8. Miscellaneous Quirks Summary Project: Hellomod Exercises Chapter 3. Processes: The Principal Model of Execution Section 3.1. Introducing Our Program Section 3.2. Process Descriptor Section 3.3. Process Creation: fork(), vfork(), and clone() System Calls Section 3.4. Process Lifespan Section 3.5. Process Termination Section 3.6. Keeping Track of Processes: Basic Scheduler Construction Section 3.7. Wait Queues Section 3.8. Asynchronous Execution Flow Summary Project: current System Variable Exercises Chapter 4. Memory Management Section 4.1. Pages Section 4.2. Memory Zones Section 4.3. Page Frames Section 4.4. Slab Allocator Section 4.5. Slab Allocator's Lifecycle Section 4.6. Memory Request Path Section 4.7. Linux Process Memory Structures Section 4.8. Process Image Layout and Linear Address Space Section 4.9. Page Tables Section 4.10. Page Fault Summary Project: Process Memory Map Exercises Chapter 5. Input/Output Section 5.1. How Hardware Does It: Busses, Bridges, Ports, and Interfaces Section 5.2. Devices Summary Project: Building a Parallel Port Driver Exercises Chapter 6. Filesystems Section 6.1. General Filesystem Concepts Section 6.2. Linux Virtual Filesystem Section 6.3. Structures Associated with VFS Section 6.4. Page Cache Section 6.5. VFS System Calls and the Filesystem Layer Summary Exercises Chapter 7. Scheduling and Kernel Synchronization Section 7.1. Linux Scheduler Section 7.2. Preemption Section 7.3. Spinlocks and Semaphores Section 7.4. System Clock: Of Time and Timers Summary Exercises Chapter 8. Booting the Kernel Section 8.1. BIOS and Open Firmware Section 8.2. Boot Loaders Section 8.3. Architecture-Dependent Memory Initialization Section 8.4. Initial RAM Disk Section 8.5. The Beginning: start_kernel() Section 8.6. The init Thread (or Process 1) Summary Exercises Chapter 9. Building the Linux Kernel Section 9.1. Toolchain Section 9.2. Kernel Source Build Summary Exercises Chapter 10. Adding Your Code to the Kernel Section 10.1. Traversing the Source Section 10.2. Writing the Code Section 10.3. Building and Debugging Summary Exercises Bibliography Index Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U. S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the U. S., please contact: International Sales [email protected] Visit us on the Web: www.phptr.com Library of Congress Cataloging-in-Publication Data: Salzberg Rodriguez, Claudia. The Linux Kernel primer : a top- down approach for x86 and PowerPC architectures / Claudia Salzberg Rodriguez, Gordon Fischer, Steven Smolski. p. cm. ISBN 0-13-118163- 7 (pbk. : alk. paper) 1. Linux. 2. Operating systems (Computers) I. Fischer, Gordon. II. Smolski, Steven. III. Title. QA76.76.O63R633 2005 005.4'32dc22 2005016702 Copyright © 2006 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department One Lake Street Upper Saddle River, NJ 07458 Text printed in the United States on recycled paper at R.R. Donnelly in Crawfordsville, IN. First printing, September 2005 Dedication To my parents, Pablo & Maria, por ser trigo, escudo, viento y bandera. Claudia Salzberg Rodriguez To Lisa, To Jan & Hart. Gordon Fischer To my dear friend Wes, whose wisdom and friendship I will cherish forever. Steven Smolski Prentice Hall: Open Source Software Development Series Arnold Robbins, Series Editor "Real world code from real world applications" Open Source technology has revolutionized the computing world. Many large-scale projects are in production use worldwide, such as Apache, MySQL, and Postgres, with programmers writing applications in a variety of languages including Perl, Python, and PHP. These technologies are in use on many different systems, ranging from proprietary systems, to Linux systems, to traditional UNIX systems, to mainframes. The Prentice Hall Open Source Software Development Series is designed to bring you the best of these Open Source technologies. Not only will you learn how to use them for your projects, but you will learn from them. By seeing real code from real applications, you will learn the best practices of Open Source developers the world over. Titles currently in the series include: Linux® Debugging and Performance Tuning: Tips and Techniques Steve Best 0131492470, Paper, 10/14/2005 The book is not only a high-level strategy guide but also a book that combines strategy with hands-on debugging sessions and performance tuning tools and techniques. Linux Programming by Example: The Fundamentals Arnold Robbins 0131429647, Paper, 4/12/2004 Gradually, one step at a time, Robbins teaches both high level principles and "under the hood" techniques. This book will help the reader master the fundamentals needed to build serious Linux software. The Linux® Kernel Primer: A Top-Down Approach for x86 and PowerPC Architectures Claudia Salzberg, Gordon Fischer, Steven Smolski 0131181637, Paper,