Protection of the processor in protected mode

Source: Internet
Author: User

Protection of the processor in protected mode
Preface

Real mode, protection mode, segmentation, paging, virtual memory, kernel state, user State. If you are very familiar with the relationship between these terms, you don't have to continue reading them. This article mainly records my understanding of user/kernel States. If you have any questions, please advise.

All of the following are x86-32 patterns.

Brief Introduction

The segment/paging mechanism converts logical addresses to physical addresses, providing independent virtual memory space for each program and isolating it from other applications to prevent modification of data related to other programs. After the paging mechanism is enabled, the CPU Hardware performs memory ing on all code, regardless of the application or operating system, the virtual memory mechanism is used.

For a 4G linear address space, linux maps a maximum of 1G space to the memory space, excluding small-scale concepts such as high-end memory, basically, the kernel address minus the PAGE_OFFSET offset is the actual physical address. Note that I have not mentioned the subject of a 4G linear address space. Its subject is all processes, even including the kernel itself. Each process has its own, and the highest 1 GB of address ing of each process is the same, which is the general kernel itself.

At the beginning of the startup, the kernel is started as an executable program, but after the startup is complete, when there is a system call, the kernel code starts to be executed, at this time, it is still the original process of, so we will say that a program runs in the kernel state.

Why do we need to switch between user and kernel states?

The user State/kernel state is not the reason, but the result, but the result is not visible. The reason for introducing the user mode/kernel mode is the privilege level. The distinction between the user mode and kernel mode is only one form of implementing privilege protection, and this method relies on segment/page.

Memory isolation and protection ------> segmentation/Paging
Privilege ------> User/kernel

Assume that only segments/pages are supported, and GDT/LDT depends on the page structure pointed to by the GDT/LDT and the register of the third layer. At first glance, isolation is provided, but without privilege level protection, the application can modify its own memory ing directed to f33. this memory protection is also useless, and no risky instructions are required.

If there is only privilege level, it is certainly not good, and it is impossible to even run multiple programs.

Therefore, apart from providing the system call function, the kernel mode and user mode are more protected by privilege. In different modes, only corresponding CPU commands can be run. All codes running in the kernel state share a virtual memory space, that is, the 3G ~ The 4G linear address space points to the same area, that is, the kernel area. From this point of view, the operating system is no longer an executable program at startup, more like a single-instance shared library for all processes. Many images draw the operating system into an independent layer under the application, which should be more symbolic.

Summary

The reason why I wrote this article is that I have doubts about the virtual address configuration of the kernel during the self-made operating system. I do not understand that all programs share 3G ~ The reason for the 4G memory is that many articles will tell you that this is the kernel mode usage. I believe it is easier to learn about the kernel mode and user mode from the concept of privilege level.

This article permanently updates the link address:

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.