1. Classification of addresses
In the past, programs were very small and could be loaded into memory and run. With the development of technology, the following two situations have emerged:
1) Some programs are very large and require more memory space than the total memory capacity, so they cannot be loaded into memory at one time;
2) There are many programs in a multitasking system that need to run at the same time, and the memory space they require exceeds the total memory capacity, so all programs cannot be loaded into memory.
In fact, before a program is run, it is not necessary to load all of it into memory. Instead, only the parts that are currently to be run need to be loaded into memory first, and the rest can be loaded from the disk when needed. When the memory is exhausted, the temporarily unused parts can be loaded out to the disk. This allows a large program to run in a smaller memory space, and also allows more programs to be loaded into memory and executed concurrently. From the user's perspective, the system has a much larger memory capacity than the actual memory capacity. People call such memory virtual memory.
Virtual memory logically expands the memory capacity, and the large capacity seen by the user is just a feeling, which is virtual. In a 32-bit CPU system, the address range of this virtual memory is 0~0xffff_ffff. We call this address range the virtual address space, and one of the addresses is called a virtual address. Corresponding to the virtual address space and virtual address is the physical address space and physical address, which correspond to the actual memory.
The virtual address must be converted into a physical address to read and write the actual data. This is done by dividing the virtual address space and physical address space into small spaces of the same size (called segments or pages), and then establishing a mapping relationship between the two types of small spaces. Since the virtual address space is much larger than the physical space, it is possible that multiple virtual address spaces are mapped to the same physical address space, or some virtual address spaces are not mapped to specific physical address spaces (they can be mapped when used). The address conversion process of the ARM CPU involves three concepts: virtual address (VA, Virtual Address), modified virtual address (MVA, Modified Virtual Address), and physical address (PA, Physical Address).
When the MMU is not started, all components such as the CPU core, cache, MMU, and peripherals use physical addresses.
After starting the MMU, the CPU core sends out the virtual address VA; VA is converted to MVA for use by the cache and MMU, where MVA is converted to PA; finally, PA is used to read and write the actual device (internal registers of S3C2410/S3C2440 or external devices):
1) The CPU core sees and uses the virtual address VA, and the CPU core does not care how VA is finally implemented on the physical address PA.
2) The cache and MMU cannot see VA either, and they use the PA obtained by MVA conversion.
3) The actual device cannot see VA and MVA, and the physical address PA is used when reading and writing them.
MVA is the virtual address seen by other parts except the CPU core.
If VA<32M, the process identification number PID (obtained by reading C13 of CP15) needs to be used to convert it to MVA. The conversion method between VA and MVA is as follows: if
(VA<32M) then
MVA=VA | (PID<<25) //VA<32M
else
MVA=VA //VA>=32M
The purpose of using PID to generate MVA is to reduce the cost of switching processes: if VA is used directly instead of MVA, when the virtual address space (VA) used by two processes overlaps, in order to map the overlapping VA to the unreachable PA when switching processes, it is necessary to rebuild the page table, invalidate caches and TLBS, etc., which is very costly. After using MVA, process switching is much easier; suppose the VAs of two processes 1 and 2 are both 0~(32M-1), but their MVAs do not overlap, namely 0x0200_0000~0x03ff_ffff and 0x0400_0000~0x05ff_ffff, respectively, so there is no need to rebuild the page table and other work.
2. The conversion process from virtual address to physical address
There are generally two ways to convert a virtual address to a physical address: use a certain mathematical formula to convert or use a table to store the physical address corresponding to the virtual address. This type of table is called a page table, which consists of entries; each entry stores the physical address corresponding to a virtual address and its access rights, or the address of the next level page table. The
second method is used in ARM CPU. S3C2410/S3C2440 will use at most two levels of page tables: only one level of page table is used when converting in the form of segments (Section, 1MB), and two levels of page tables are used when converting in the form of pages. There are three page sizes: large page (64KB), small page (4KB), and very small page (1KB). Entries are also called "descriptors", including: segment descriptors, large page descriptors, small page descriptors, and tiny page descriptors - they store the starting physical addresses of segments, large pages, small pages, or tiny pages; coarse page table descriptors and fine page table descriptors - they store the physical addresses of secondary page tables.
The general conversion process is as follows:
1) Find the entry in the primary page table according to the given virtual address;
2) If this descriptor is a segment descriptor, the physical address is returned and the conversion ends;
3) Otherwise, if this descriptor is a secondary page table descriptor, continue to use the virtual address to find the next entry in this secondary page table;
4) If this second entry is a page descriptor, the physical address is returned and the conversion ends;
5) Errors occur in other cases.
Previous article:[ARM Notes] Device Driver Overview
Next article:[ARM Notes] How to use the registers of the storage controller
Recommended ReadingLatest update time:2024-11-16 14:53
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Bicycle computer based on GD32E231C8T6
- This week's highlights
- STM device I2C drives 0.96 OLED display
- How to choose between different chips in TI's Sub-1GHz product line?
- EEWORLD University ---- Motor Control
- Component packaging,
- 5 Key Considerations for IoT Devices
- NUCLEO_G431RB Review Add UART
- A must-read summary of drone principles (II) Major systems of drones
- CC2640R2: TI BLE OAD (OTA) protocol APP process and code interpretation on Android and iOS