Linux kernel Analysis (second week)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.