2019-2020-1 20199314 <Linux kernel principle and analysis> second week of work

1. Basic learning content

1.1 Von Neumann architecture

The computer controller consists of five parts, the arithmetic unit, memory, input devices, output devices.

1.1.1 Characteristics von Neumann computer
(1) using the stored program mode, indiscriminate mixing instructions and data stored in the same memory.
(2) is a one-dimensional structure memory address accessed by linear addressing, the number of bits per cell is fixed.
(3) instruction opcode and an address. The operation code indicates the type of operation of the present instruction, and an operand address code indicates an address. Itself has no operand data type flag, its data type is determined by the operation code.
(4) issues an operation control signal directly to a computer by executing instructions. Their order of execution of instructions stored in a memory, counter means specified by the instruction address of the instruction to be executed resides.
(5) in the center operator, data transfer between I / O devices go through memory and calculator.
(6) represented in binary data.

Register compilation 1.2 - 32bit system, for example in

1.2.1 Classification register

Four data registers (EAX, EBX, ECX, and EDX)
2 variant addresses and pointer register (ESI and EDI)
2 pointer register (ESP and EBP)
. 6 segment registers (ES, CS, SS, DS , FS , and GS )
an instruction pointer register (the EIP)
a flag register (EFLAGS)

1.2.2 General details and instruction pointer register

CPU has four 32-bit general registers EAX, EBX, ECX, and EDX. Access to the lower 16-bit data, 16-bit high will not affect the data. These low 16-bit register named: AX, BX, CX, and DX.
4 16-bit registers in turn divided into eight separate 8-bit registers (AX: AH-AL, BX : BH-BL, CX: CH-CL, DX: DH-DL), each register has its own name , independently accessible. As shown below.

1.3 computer executing the instruction,

The PC (program counter, the system 32 is EIP) fetch -> instruction decoding -> operand fetch -> instruction execution -> write the result back -> modify the value of the PC -> continue the next instruction. As shown in FIG.

1.4 Addressing

  • Immediate addressing mode (immediate addressing)
    operands directly included in the instruction, the addressing mode immediately after the operation code is called immediate addressing mode, the operand is called the immediate.
  • Register Addressing

  • Immediate addressing

  • Direct addressing

  • Indirect addressing

  • Indexed addressing

2. Assembly language learning

2.1 Assembler language Basic concepts

  • Assembler instructions: machine code mnemonic, a corresponding machine code
  • Directive: no corresponding machine code, executed by a compiler, the computer does not perform
  • Other symbols: such as: +, -, *, /, etc., identified by the compiler, there is no corresponding machine code
  • Assembly language features:
    ① footprint, speed of execution and the machine language similar
    ② direct, simple, can fully control the computer's hardware functionality

    2.2 Stack

    2.2.1 Basic Concepts stack
    data structure of a data item that is stacked in sequence, only one end (referred to as a top of the stack (Top)) to insert and delete data items. As shown in FIG.

2.2.2 stack grows upward and downward growth
assumed stack size of 256, 32-bit general system stack grows downwards direction.

  • Down growth, the growth is from high address to low address. The stack is the & Taskstk [255].
  • Grow up, that grows from lower to higher addresses. The stack is the & Taskstk [0].

2.2.3 Basic operation of the stack and the corresponding assembly language

  • Push instruction PUSH

  • Pop instruction POP

  • CALL calling process

  • RET return process

  • Clear process LEAVE

2.3 challenges

In the laboratory building environment using vim editor, write a simple c program, and explore the content and format conversion c language in assembly language. C language into the assembler language file 32, function call kernel code, the stack changes.

2.3.1 Step
written in C language program

  • gcc compiled code

  • Converted into assembly language

  • Remove the auxiliary information

2.3.2 Code Analysis
call flow main function

Call stack assembly language change process

  • Initial stage, esp, ebp pointers are pointing to the position of 1000 (assuming stack size of 1000)

  • Perform the main function

  • carried out

  • Execution jumps to perform the function f

  • carried out

- execution jumps to the function g

  • carried out

  • carried out

  • carried out

  • carried out


  • carried out

  • carried out

  • carried out

Above illustrates the process a simple piece of code that calls the function.
Shows the entire stack from occupied -> release process.

to sum up

This week's study with respect to Linux is an advanced foundation last week, begin to understand the Linux kernel, studied 32 and 16, the difference between 64-bit systems, learned classification registers, as well as the usefulness of registers. Studied Some low-level calls, any c language will be converted into assembly language in the bottom layer, before learning the simple addition program is written by a high-level language, assembly language and then interpreted as the underlying call, which can be found though high-level language syntax is simple \ strong visibility, but it can not directly identify the hardware, so the speed \ reliability is not as assembly language, but the future trend is the growing language package, coming more and more knowledge \ learning less and less time \ good use before artificial parts to assemble cars this behavior is increasingly being accepted, popular python language is not in line with future trends do?

Guess you like

Origin www.cnblogs.com/morvalhe/p/11567506.html