BSD FreeBSD Architecture Handbook (2003).pdf

(1219 KB) Pobierz
29870998 UNPDF
FreeBSD Architecture Handbook
The FreeBSD Documentation Project
FreeBSD Architecture Handbook
by The FreeBSD Documentation Project
Published August 2000
Copyright © 2000, 2001, 2002, 2003 The FreeBSD Documentation Project
Welcome to the FreeBSD Architecture Handbook. This manual is a work in progress and is the work of many
individuals. Many sections do not yet exist and some of those that do exist need to be updated. If you are interested
in helping with this project, send email to the FreeBSD documentation project mailing list
(http://lists.FreeBSD.org/mailman/listinfo/freebsd-doc).
The latest version of this document is always available from the FreeBSD World Wide Web server
(../../../../index.html). It may also be downloaded in a variety of formats and compression options from the FreeBSD
FTP server (ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/) or one of the numerous mirror sites
(../handbook/mirrors-ftp.html).
FreeBSD is a registered trademark of Wind River Systems, Inc. This is expected to change soon.
UNIX is a registered trademark of The Open Group in the US and other countries.
Sun, Sun Microsystems, SunOS, Solaris, and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and
other countries.
Apple and QuickTime are trademarks of Apple Computer, Inc., registered in the U.S. and other countries.
Macromedia and Flash are trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other countries.
Microsoft, Windows, and Windows Media are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or
other countries.
PartitionMagic is a registered trademark of PowerQuest Corporation in the United States and/or other countries.
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 FreeBSD Project was aware of the trademark claim, the designations have been followed by the ’™’ symbol.
Redistribution and use in source (SGML DocBook) and ’compiled’ forms (SGML, HTML, PDF, PostScript, RTF and so forth) with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code (SGML DocBook) must retain the above copyright notice, this list of conditions
and the following disclaimer as the first lines of this file unmodified.
2. Redistributions in compiled form (transformed to other DTDs, converted to PDF, PostScript, RTF and other
formats) must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Important: THIS DOCUMENTATION IS PROVIDED BY THE FREEBSD DOCUMENTATION PROJECT "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE FREEBSD DOCUMENTATION PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
Table of Contents
I. Kernel ..................................................................................................................................................................... viii
1 Bootstrapping and kernel initialization ..............................................................................................................1
1.1 Synopsis .................................................................................................................................................1
1.2 Overview................................................................................................................................................1
1.3 BIOS POST ...........................................................................................................................................2
1.4 boot0 stage ...........................................................................................................................................2
1.5 boot2 stage ...........................................................................................................................................3
1.6 loader stage ...........................................................................................................................................6
1.7 Kernel initialization ...............................................................................................................................6
2 Locking Notes ..................................................................................................................................................15
2.1 Mutexes................................................................................................................................................15
2.2 Shared Exclusive Locks.......................................................................................................................18
2.3 Atomically Protected Variables ...........................................................................................................18
3 Kernel Objects ..................................................................................................................................................19
3.1 Terminology.........................................................................................................................................19
3.2 Kobj Operation ....................................................................................................................................19
3.3 Using Kobj ...........................................................................................................................................19
4 The Jail Subsystem...........................................................................................................................................23
4.1 Architecture .........................................................................................................................................23
4.2 Restrictions ..........................................................................................................................................26
5 The Sysinit Framework ....................................................................................................................................31
5.1 Terminology.........................................................................................................................................31
5.2 Sysinit Operation .................................................................................................................................31
5.3 Using Sysinit........................................................................................................................................31
6 The TrustedBSD MAC Framework..................................................................................................................33
6.1 MAC Documentation Copyright..........................................................................................................33
6.2 Synopsis ...............................................................................................................................................33
6.3 Introduction..........................................................................................................................................33
6.4 Policy Background...............................................................................................................................34
6.5 MAC Framework Kernel Architecture ................................................................................................34
6.6 MAC Policy Architecture ....................................................................................................................37
6.7 MAC Policy Entry Point Reference.....................................................................................................39
6.8 Userland Architecture ..........................................................................................................................93
6.9 Conclusion ...........................................................................................................................................94
7 Virtual Memory System ...................................................................................................................................95
7.1 Management of physical memory— vm_page_t ................................................................................95
7.2 The unified buffer cache— vm_object_t ...........................................................................................95
7.3 Filesystem I/O— struct buf ............................................................................................................96
7.4 Mapping Page Tables— vm_map_t, vm_entry_t ............................................................................96
7.5 KVM Memory Mapping......................................................................................................................96
7.6 Tuning the FreeBSD VM system.........................................................................................................97
8 SMPng Design Document ................................................................................................................................99
8.1 Introduction..........................................................................................................................................99
8.2 Basic Tools and Locking Fundamentals ..............................................................................................99
8.3 General Architecture and Design.......................................................................................................100
iv
8.4 Specific Locking Strategies ...............................................................................................................103
8.5 Implementation Notes........................................................................................................................107
8.6 Miscellaneous Topics.........................................................................................................................107
Glossary ...................................................................................................................................................108
9 * UFS..............................................................................................................................................................110
10 * AFS............................................................................................................................................................111
11 * Syscons......................................................................................................................................................112
12 * Compatibility Layers.................................................................................................................................113
12.1 * Linux.............................................................................................................................................113
II. Device Drivers ......................................................................................................................................................114
13 Writing FreeBSD Device Drivers.................................................................................................................115
13.1 Introduction......................................................................................................................................115
13.2 Dynamic Kernel Linker Facility - KLD...........................................................................................115
13.3 Accessing a device driver ................................................................................................................116
13.4 Character Devices ............................................................................................................................117
13.5 Network Drivers...............................................................................................................................120
14 ISA device drivers ........................................................................................................................................122
14.1 Synopsis ...........................................................................................................................................122
14.2 Basic information.............................................................................................................................122
14.3 Device_t pointer...............................................................................................................................124
14.4 Configuration file and the order of identifying and probing during auto-configuration..................124
14.5 Resources .........................................................................................................................................126
14.6 Bus memory mapping......................................................................................................................129
14.7 DMA ................................................................................................................................................136
14.8 xxx_isa_probe..................................................................................................................................138
14.9 xxx_isa_attach .................................................................................................................................143
14.10 xxx_isa_detach ..............................................................................................................................146
14.11 xxx_isa_shutdown .........................................................................................................................147
14.12 xxx_intr..........................................................................................................................................147
15 PCI Devices ..................................................................................................................................................149
15.1 Probe and Attach..............................................................................................................................149
15.2 Bus Resources..................................................................................................................................152
16 Common Access Method SCSI Controllers.................................................................................................156
16.1 Synopsis ...........................................................................................................................................156
16.2 General architecture.........................................................................................................................156
16.3 Polling..............................................................................................................................................174
16.4 Asynchronous Events ......................................................................................................................174
16.5 Interrupts..........................................................................................................................................175
16.6 Errors Summary...............................................................................................................................181
16.7 Timeout Handling ............................................................................................................................182
17 USB Devices ................................................................................................................................................184
17.1 Introduction......................................................................................................................................184
17.2 Host Controllers...............................................................................................................................185
17.3 USB Device Information .................................................................................................................187
17.4 Device probe and attach...................................................................................................................188
17.5 USB Drivers Protocol Information ..................................................................................................189
18 Newbus .........................................................................................................................................................192
v
Zgłoś jeśli naruszono regulamin