2019-2020-1 20199327 "Linux kernel principle and Analysis" in the third week of work

How the operating system works

Computer three magic weapons:

1. stored program computer;

2. The function call stack mechanism;

3. interrupt mechanism;

Function call stack

The role of the stack

1. Record function call frame;

2. The transfer function parameters, methods: from left to right;

3. Save the value of the return address;

4. The function of the internal memory space to provide local variables;

Of registers and operations

ESP: stack pointer;

EBP: base pointer;

push: 4 bytes reduce stack address, and the operand stack into a storage unit;

pop: 4 bytes stack address is incremented, and the top of stack operand into the storage unit;

Stack is from high address to the low address increased.

Other key register

CS: EIP always point to the address of the next instruction.

Sequentially performed: consecutive addresses always points to the next instruction;

Jump / branch: performing such a command, CS: EIP values ​​may need to be modified in accordance with a program;

call: the current CS: EIP values ​​in onto stack, CS: EIP points to the entry address of the called function.

ret: pop from the stack to save the original CS: EIP value, and put CS: EIP in;

Inline assembly

Keyword

asm : GCC macro definition is asm keyword is a keyword inline assembly. asm _asm_ and can be used interchangeably, # DEFINE asm asm;

volatile : the volatile keyword is GCC macro definition, do not optimizing compiler code, assembly instructions intact. asm _asm_ and can be used interchangeably, # DEFINE volatile volatile;

grammar

asm volatile

汇编语言模板:

输出部分:

输入部分:

破坏描述部分

experiment

patch -pl < ../mykernel_for_linux3.9.4sc.patch4

qemu -kernel arch/x86/boot/bzImage

After the experimental platform kernel boot effect

Guess you like

Origin www.cnblogs.com/waxxx/p/11610272.html