How does the operating system work?
First, summary: three magic Weapon
1. Stored program computer + function call stack + interrupt mechanism
2. Stack: C language Program run time must be a record call path and parameter space (function call frame/provide local variable/pass parameter/save return address)
Different instructions may implement the same functionality
3. Stack-Related: ESP EBP; operation: Push pop;
EBP is used in the C language to record the base address of the current function call
Cs:eip always points to the next instruction address: order; Jump/Branch
Build the stack frame of the callee function
PUSHL%EBP
MOVL%esp%EBP
Remove the stack frame of the callee function
MOVL%EBP%esp
POPL%EBP
Ret
Second, with the Linux kernel part of the source code simulation storage program computer work model and clock interrupt
1. Both the storage site and the dangerous scene are implemented by CPU and kernel code.
2. Lab building virtual machine, open shell
Experiment:
Third, construct a simple operating system kernel on the basis of Mykernel
1. How to embed assembly code in C language
Qualifier "m" Memory variable "=" Write only "+" read and write
2. Simple Kernel source code
Thread (storage IP SP)
PCB (define process management-related data structures)
My_schedule (Scheduler)
Kernel initialization number No. 0 Dispatch
Initialize process number No. 0
Create more processes
Start Process # No. 0
RET after No. 0 process start
Loop 10 million times to get a chance to determine if scheduling is required
Set the time slice size, set the schedule flag when the time slice runs out.
Two running processes for context switching
PUSHL%%EBP
MOVL%esp
MOVL $1f%1\n\t
1f indicates the position of the next label 1
Linux kernel Analysis (second week)