| Preface |
|
xi | |
| Author |
|
xiii | |
| 1 From Power-Up to the Main Function |
|
1 | (44) |
|
1.1 Loading BIOS, Constructing Interrupt Vector Table, and Activating Interrupt Service Routines in the Real Mode |
|
|
2 | (2) |
|
1.1.1 Procedure for Starting BIOS |
|
|
2 | (1) |
|
1.1.2 BIOS Loads the Interrupt Vector Table and Interrupt Service Routines into Memory |
|
|
3 | (1) |
|
1.2 Loading the OS Kernel and Preparing for the Protected Mode |
|
|
4 | (12) |
|
|
|
5 | (2) |
|
1.2.2 Loading the Second Part of Code-Setup |
|
|
7 | (5) |
|
1.2.3 Load the System Module |
|
|
12 | (4) |
|
1.3 Transfer to 32-Bit Mode and Prepare for the Main Function |
|
|
16 | (27) |
|
1.3.1 Disable Interrupts and Move System to 0x00000 |
|
|
16 | (2) |
|
1.3.2 Set the Interrupt Descriptor Table and Global Descriptor Table |
|
|
18 | (2) |
|
1.3.3 Open A20 and Achieve 32-Bit Addressing |
|
|
20 | (1) |
|
1.3.4 Prepare for the Implementation of head.s in the Protected Mode |
|
|
21 | (2) |
|
1.3.5 CPU Starts to Execute heads |
|
|
23 | (20) |
|
|
|
43 | (2) |
| 2 Device Initialization and Process 0 Activation |
|
45 | (40) |
|
2.1 Set Root Device 2 and Hard Disk |
|
|
46 | (1) |
|
2.2 Set Up Physical Memory Layout, Buffer Memory, Ramdisk, and Main Memory |
|
|
46 | (3) |
|
2.3 Ramdisk Setup and Initialization |
|
|
49 | (3) |
|
2.4 Initialization of the Memory Management Structure mem_map |
|
|
52 | (1) |
|
2.5 Binding the Interrupt Service Routine |
|
|
53 | (5) |
|
2.6 Initialize the Request Structure of the Block Device |
|
|
58 | (3) |
|
2.7 Binding with the Interrupt Service Routine of Peripherals and Establishing the Human-Computer Interaction Interface |
|
|
61 | (5) |
|
2.7.1 Set the Serial Port |
|
|
61 | (1) |
|
|
|
62 | (1) |
|
|
|
62 | (4) |
|
|
|
66 | (1) |
|
|
|
67 | (8) |
|
2.9.1 Initialization of Process 0 |
|
|
71 | (2) |
|
2.9.2 Set the Timer Interrupt |
|
|
73 | (1) |
|
2.9.3 Set the Entrance of System Call |
|
|
74 | (1) |
|
2.10 Initialize the Buffer Management Structure |
|
|
75 | (3) |
|
2.11 Initialize the Hard Disk |
|
|
78 | (2) |
|
2.12 Initialize the Floppy Disk |
|
|
80 | (1) |
|
2.13 Enable the Interrupt |
|
|
80 | (1) |
|
2.14 Process 0 Moves from Privilege Level 0 to 3 and Becomes a Real Process |
|
|
81 | (4) |
| 3 Creation and Execution of Process 1 |
|
85 | (80) |
|
3.1 Creation of Process 1 |
|
|
85 | (24) |
|
3.1.1 Preparation for Creating Process 1 |
|
|
85 | (6) |
|
3.1.2 Apply for an Idle Position and a Process Number for Process 1 |
|
|
91 | (1) |
|
3.1.3 Call Copy_process() |
|
|
92 | (6) |
|
3.1.4 Set the Page Management of Process 1 |
|
|
98 | (5) |
|
3.1.4.1 Set the Code Segment and Data Segment in the Linear Address Space of Process 1 |
|
|
99 | (2) |
|
3.1.4.2 Create the First Page Table for Process 1 and Set the Corresponding Page Directory Entry |
|
|
101 | (2) |
|
3.1.5 Process 1 Shares Files of Process 0 |
|
|
103 | (1) |
|
3.1.6 Set the Table Item in the GDT of Process 1 |
|
|
104 | (1) |
|
3.1.7 Process 1 Is in Ready State to Complete the Creation of Process 1 |
|
|
105 | (4) |
|
3.2 Kernel Schedules a Process for the First Time |
|
|
109 | (4) |
|
3.3 Turn to Process 1 to Execute |
|
|
113 | (52) |
|
3.3.1 Preparing to Install the Hard Disk File System by Process 1 |
|
|
115 | (31) |
|
3.3.1.1 Process 1 Set hd_info of Hard Disk |
|
|
115 | (1) |
|
3.3.1.2 Read the Hard Disk Boot Blocks to the Buffer |
|
|
116 | (9) |
|
3.3.1.3 Bind the Buffer Block with Request |
|
|
125 | (4) |
|
3.3.1.4 Read the Hard Disk |
|
|
129 | (5) |
|
3.3.1.5 Wait for Hard Disk Reading Data, Process Scheduling, and Switch to Process 0 to Execute |
|
|
134 | (3) |
|
3.3.1.6 Hard Disk Interruption Occurs during the Execution of Process 0 |
|
|
137 | (6) |
|
3.3.1.7 After Reading the Disk, Switch Process Scheduling to Process 1 |
|
|
143 | (3) |
|
3.3.2 Process 1 Formats the Ramdisk and Replaces the Root Device as the Ramdisk |
|
|
146 | (3) |
|
3.3.3 Process 1 Loads the Root File System into the Root Device |
|
|
149 | (16) |
|
3.3.3.1 Copying the Super Block of the Root Device to the super_block[ 8] |
|
|
152 | (5) |
|
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.3 Associate the Root File System with Process 1 |
|
|
160 | (5) |
| 4 Creation and Execution of Process 2 |
|
165 | (66) |
|
4.1 Open the Terminal Device File and Copy the File Handle |
|
|
165 | (22) |
|
4.1.1 Open the Standard Input Device File |
|
|
165 | (17) |
|
4.1.1.1 File_table[ 0] is Mounted to Filp[ 0] in Process 1 |
|
|
165 | (2) |
|
4.1.1.2 Determine the Starting Point of Absolute Path |
|
|
167 | (5) |
|
4.1.1.3 Acquiring the i node of Dev |
|
|
172 | (3) |
|
4.1.1.4 Determine the i node of Dev as the Topmost i node |
|
|
175 | (2) |
|
4.1.1.5 Acquire the i node of the tty0 File |
|
|
177 | (3) |
|
4.1.1.6 Determine tty0 as the Character Device File |
|
|
180 | (1) |
|
4.1.1.7 Set file_table[ 0] |
|
|
181 | (1) |
|
4.1.2 Open the Standard Output and Standard Error Output Device File |
|
|
182 | (5) |
|
4.2 Fork Process 2 and Switch to Process 2 to Execute |
|
|
187 | (11) |
|
4.3 Load the Shell Program |
|
|
198 | (21) |
|
4.3.1 Close the Standard Input File and Open the rc File |
|
|
198 | (3) |
|
4.3.2 Detect the Shell File |
|
|
201 | (5) |
|
4.3.2.1 Detect the Attribute of the i node |
|
|
201 | (1) |
|
4.3.2.2 Test File Header's Attributes |
|
|
202 | (4) |
|
4.3.3 Prepare to Execute the Shell Program |
|
|
206 | (8) |
|
4.3.3.1 Load Parameters and Environment Variables |
|
|
206 | (4) |
|
4.3.3.2 Adjust the Management Structure of Process 2 |
|
|
210 | (2) |
|
4.3.3.3 Adjust EIP and ESP to Execute Shell |
|
|
212 | (2) |
|
4.3.4 Execute the Shell Program |
|
|
214 | (5) |
|
4.3.4.1 Execute the First Page Program Loading by the Shell |
|
|
214 | (4) |
|
4.3.4.2 Map the Physical Address and Linear Address of the Loading Page |
|
|
218 | (1) |
|
4.4 The System Gets to the Idle State |
|
|
219 | (12) |
|
4.4.1 Create the Update Process |
|
|
219 | (1) |
|
4.4.2 Switch to the Shell Process |
|
|
220 | (8) |
|
4.4.3 Reconstruction of the Shell |
|
|
228 | (3) |
| 5 File Operation |
|
231 | (52) |
|
5.1 Install the File System |
|
|
231 | (5) |
|
5.1.1 Get the Super Block of Peripherals |
|
|
232 | (2) |
|
5.1.2 Confirm the Mount Point of the Root File System |
|
|
234 | (1) |
|
5.1.3 Mount the Super Block with the Root File System |
|
|
235 | (1) |
|
|
|
236 | (14) |
|
5.2.1 Mount *Filp[ 20] in the User Process to File_table[ 64] |
|
|
238 | (1) |
|
5.2.2 Get the File's i node |
|
|
239 | (10) |
|
5.2.2.1 Get the i node of the Directory File |
|
|
239 | (9) |
|
5.2.2.2 Get the i node of the Target File |
|
|
248 | (1) |
|
5.2.3 Bind File i node with File_table[ 64] |
|
|
249 | (1) |
|
|
|
250 | (6) |
|
5.3.1 Locate the Position of the Data Block in the Peripherals |
|
|
250 | (4) |
|
5.3.2 Data Block Is Read into the Buffer Block |
|
|
254 | (1) |
|
5.3.3 Copy Data from the Buffer into the Process Memory |
|
|
255 | (1) |
|
|
|
256 | (9) |
|
|
|
256 | (2) |
|
5.4.2 Create a New i node for a File |
|
|
258 | (2) |
|
5.4.3 Create a New Content Item |
|
|
260 | (5) |
|
|
|
265 | (7) |
|
5.5.1 Locate the Position of the File to Be Written In |
|
|
265 | (2) |
|
5.5.2 Apply for a Buffer Block |
|
|
267 | (1) |
|
5.5.3 Copy Specified Data from the Process Memory to the Buffer Block |
|
|
268 | (1) |
|
5.5.4 Two Ways to Synchronize Data from the Buffer to the Hard Disk |
|
|
269 | (3) |
|
|
|
272 | (3) |
|
5.6.1 Reposition the Current Operation Pointer of the File |
|
|
273 | (1) |
|
|
|
273 | (2) |
|
|
|
275 | (2) |
|
5.7.1 Disconnecting Filp and File_table[ 64] in the Current Process |
|
|
275 | (2) |
|
5.7.2 Releasing the Files' i node |
|
|
277 | (1) |
|
|
|
277 | (6) |
|
5.8.1 Checking the Deleting Conditions of Files |
|
|
278 | (1) |
|
5.8.2 Specific Deleting Work |
|
|
279 | (4) |
| 6 The User Process and Memory Management |
|
283 | (60) |
|
6.1 Linear Address Protection |
|
|
284 | (3) |
|
6.1.1 Patterns of the Process Linear Address Space |
|
|
284 | (1) |
|
6.1.2 Segment Base Addresses, Segment Limit, GDT, LDT, and Privilege Level |
|
|
284 | (3) |
|
|
|
287 | (15) |
|
6.2.1 Linear Address to Physical Address |
|
|
287 | (2) |
|
6.2.2 Process Execution Paging |
|
|
289 | (6) |
|
6.2.3 Process Sharing the Page |
|
|
295 | (4) |
|
|
|
299 | (3) |
|
6.3 Complete Process of User Process from Creation to Exit |
|
|
302 | (29) |
|
6.3.1 Create Process strl |
|
|
302 | (13) |
|
6.3.2 Preparation to Load strl |
|
|
315 | (5) |
|
6.3.3 Running and Loading of Process strl |
|
|
320 | (5) |
|
6.3.4 Exiting of Process strl |
|
|
325 | (6) |
|
6.4 Multiple User Processes Run Concurrently |
|
|
331 | (12) |
|
|
|
331 | (5) |
|
|
|
336 | (7) |
| 7 Buffer and Multiprocess File |
|
343 | (88) |
|
|
|
343 | (2) |
|
|
|
345 | (1) |
|
7.3 The Function of b_dev, b_blocknr, and Request |
|
|
346 | (13) |
|
7.3.1 Ensure the Correctness of the Data Interaction between Processes and Buffer Block |
|
|
346 | (7) |
|
7.3.2 Let the Data Stay in the Buffer as Long as Possible |
|
|
353 | (6) |
|
7.4 Function of Uptodate and Dirt |
|
|
359 | (11) |
|
7.4.1 Function of b_uptodate |
|
|
359 | (6) |
|
7.4.2 Function of the b_dirt |
|
|
365 | (3) |
|
7.4.3 Function of the i_update, i_dirt, and s_dirt |
|
|
368 | (2) |
|
7.5 Function of the Count, Lock, Wait, Request |
|
|
370 | (13) |
|
7.5.1 Function of b_count |
|
|
370 | (2) |
|
7.5.2 Function of i_count |
|
|
372 | (3) |
|
7.5.3 Function of block and *b_wait |
|
|
375 | (3) |
|
7.5.4 Function of i_lock, i_wait, s_lock, and *s_wait |
|
|
378 | (3) |
|
7.5.5 Function of Request |
|
|
381 | (2) |
|
7.6 Example 1: Process Waiting Queue of Buffer Block |
|
|
383 | (25) |
|
7.7 Overall Look at the Buffer Block and the Request Item |
|
|
408 | (3) |
|
7.8 Example 2: Comprehensive Examples of Multiprocess Operating File |
|
|
411 | (20) |
| 8 Inter-Process Communication |
|
431 | (50) |
|
|
|
431 | (23) |
|
8.1.1 The Creation Process of the Pipe |
|
|
433 | (6) |
|
|
|
439 | (15) |
|
|
|
454 | (25) |
|
|
|
458 | (11) |
|
8.2.2 The Influence of Signal on the Process Execution State |
|
|
469 | (10) |
|
|
|
479 | (2) |
| 9 Operating System's Design Guidelines |
|
481 | (26) |
|
9.1 Run a Simple Program to See What the Operating System Has Done |
|
|
481 | (5) |
|
9.2 Thoughts on the Design of the Operating System: Master-Slave Mechanism |
|
|
486 | (4) |
|
9.2.1 Process and Its Creation Mechanism in the Master-Slave Mechanism |
|
|
486 | (1) |
|
9.2.1.1 Program Boundary and Process |
|
|
486 | (1) |
|
|
|
487 | (1) |
|
9.2.2 How Does the Designing of Operating System Display the Master-Slave Mechanism? |
|
|
487 | (3) |
|
9.2.2.1 Master-Slave Mechanism That the Operating System Reflects in Process Scheduling |
|
|
487 | (1) |
|
9.2.2.2 Master-Slave Mechanism That the Operating System Adopts in Memory Management |
|
|
488 | (1) |
|
9.2.2.3 Master-Slave Mechanism Is Reflected by OS File System |
|
|
489 | (1) |
|
9.3 Three Key Techniques in Realizing the Master-Slave Mechanism |
|
|
490 | (7) |
|
9.3.1 Protection and Paging |
|
|
490 | (3) |
|
|
|
493 | (1) |
|
|
|
494 | (3) |
|
9.4 Decisive Factor in Establishing the Master-Slave Mechanism: The Initiative |
|
|
497 | (1) |
|
9.5 Relationship between Software and Hardware |
|
|
498 | (9) |
|
9.5.1 Nonuser Process: Process 0, Process 1, Shell Process |
|
|
498 | (1) |
|
9.5.2 Storage of File and Data |
|
|
499 | (6) |
|
9.5.2.1 Memory, Hard Disk, Buffer: Computing Storage, Storing Storage, Transition State Storage |
|
|
500 | (2) |
|
9.5.2.2 Guiding Ideology of Designing Buffer |
|
|
502 | (3) |
|
9.5.2.3 Use the File System to Implement Interprocess Communication: Pipe |
|
|
505 | (1) |
|
9.6 Parent and Child Processes Sharing Page |
|
|
505 | (1) |
|
9.7 Operating System's Global Interrupt and the Process's Local Interrupt: Signal |
|
|
506 | (1) |
|
|
|
507 | (1) |
| Conclusion |
|
507 | (2) |
| Index |
|
509 | |