The second week how the operating system works the first section of the function call stack
Stored program computers: A framework for all computer infrastructures
Stack: A basic part of a computer that has a stack when the computer has only machine languages and assembly language. The stack mechanism is the basis for high-level languages to work.
Computer "Sambo": Stored program computer, function call stack and interrupt mechanism.
- A stack is a space that the C language program must run with a record call path and parameters
- Function call Framework (Eg:enter, leave)
- Passing parameters (32 bits, passing parameters through the stack)
- Save return address (with EAX)
- Provides local variable space
- Wait a minute
The ♦c language compiler uses a set of rules for the stack, and in different systems, the compiled C code will have different assembly codes.
♦ Understanding the purpose of the stack and the rules used by the compiler on the stack are fundamental to understanding some of the key code of the operating system.
One, stack registers and stack operations
Pop: from high address to low address
Push: From low address to high address
Second, using the stack implementation function call and return 1. Other key registers
- CS:EIP: Always point to the next instruction address
• Sequential execution: Always point to the next instruction in consecutive addresses • Jump/branch: When executing such an instruction, the value of CS:EIP is modified according to the program needs call: Press the value of the current CS:EIP into the top of the stack, CS:EIP the entry address of the called function · RET: Eject from the top of the stack the value of the CS:EIP that was originally saved here, put into the CS:EIP
How does the interrupt mechanism work?
Call command: 1 ) Save address A of the next instruction in the EIP at the top of the stack 2) set the EIP to point at the beginning of the called Program code
Third, the formation of the function stack frame
- Call XXX
- Before you execute call
- When you execute call, the original value of Cs:eip points to the next instruction of call, which is saved to the top of the stack, and then the value of CS:EIP points to the entry address of XXX
2. Enter XXX
- First instruction: PUSHL%EBP
- Second instruction: Movl%esp,%EBP
- General operations in the body of a function, which may be stacked, stacked
3. Exit XXX
- MOVL%ebp,%esp
- POPL%EBP
- Ret
Section II Simulation of the storage program computer working model and clock interruption with the Linux kernel part source code
When an interrupt signal occurs, the CPU presses the current EIP,ESP,EBP into the kernel stack and points the EIP to the entry of the interrupt handler.
C code embedded in the assembly code section III constructs a simple operating system kernel experiment based on Mykernel: complete a simple time slice rotation multi-channel program kernel code
Linux Kernel Analysis--second week of study notes