The previous article mainly focused on data structures related to specific systems, and left a question at the end:
So, how do these data structures work? In particular, how does the ARM-Linux kernel establish address mappings based on these data structures?
1. Let's start with the initialization of the system. After the system is booted, the CPU enters the main entrance of the kernel, which is the starting point of the code segment stext. In stext, the CPU first reads the CPU model and the machine model from itself, stores the relevant information in the two global variables processor_id and machine_arch_type, and then goes to start_kernel().
asmlinkage void __init start_kernel(void)
{
......
setup_arch(&command_line);
The code of this function depends on the specific CPU model, and it mainly completes the following operations during the system initialization phase:
......
mem_init();
kmem_cache_sizes_init();
.......
}
For the MMU, a specific page directory is a specific mapping, but for the kernel some additional information is needed. From the kernel's perspective, a specific mapping is described and managed by an mm_struct data structure, among which the kernel's mm_struct data structure init_mm has special importance:
struct mm_struct init_mm = INIT_MM(init_mm);
#define INIT_MM(name)
{
mm_rb: RB_ROOT,
pgd: swapper_pg_dir,
mm_users: ATOMIC_INIT(2),
mm_count: ATOMIC_INIT(1),
mmap_sem: __RWSEM_INITIALIZER(name.mmap_sem),
page_table_lock: SPIN_LOCK_UNLOCKED,
mmlist: LIST_HEAD_INIT(name.mmlist),
}
The correct term should be the mm_struct data structure of the kernel thread, or the mapping of the kernel thread, because this mapping does not contain any user space mappings. All kernel threads in the system share the same mapping, which is init_mm. In particular, the mm_struct data structure of the kernel thread init is init_mm.
Each process or thread has a process control block, which contains a pointer mm pointing to its own mm_struct data structure. In the mm_struct structure, there is a pointer pgd pointing to its first-level page directory.
/*
* We place the page tables 16K below TEXTADDR. Therefore, we must make sure
* that TEXTADDR is correctly set. Currently, we expect the least significant
* "short" to be 0x8000, but we could probably relax this restriction to
* TEXTADDR > PAGE_OFFSET + 0x4000
*
* Note that swapper_pg_dir is the virtual address of the page tables, and
* pgtbl gives us a position-independent reference to these tables. We can
* do this because stext == TEXTADDR
*
* swapper_pg_dir, pgtbl and krnladr are all closely related.
*/
#if (TEXTADDR & 0xffff) != 0x8000
#error TEXTADDR must start at 0xXXXX8000
#endif
.globl SYMBOL_NAME(swapper_pg_dir)
.equ SYMBOL_NAME(swapper_pg_dir), TEXTADDR - 0x4000
.macro pgtbl, reg, rambase
adr reg, stext
sub reg, reg, #0x4000
.endm
/*
Previous article:Analysis of nandflash driver under Linux (1)——Based on s3c6410 platform
Next article:Linux serial terminal ttySAC, Linux serial terminal driver - S3C6410 platform
Recommended ReadingLatest update time:2024-11-16 14:32
- Popular Resources
- Popular amplifiers
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
- Has anyone used Bosch's PM sensor?
- [NXP Rapid IoT Review] +1. Unboxing and Getting to Know the Rapid IoT Kit
- HFSS simulation software field strength pattern and 3D diagram
- Embedded software squeezes out the lowest power mode
- Sharing of experience in single board circuit design (2) -- Power socket selection
- Discover Schottky diodes in daily life
- TCP protocol requires restarting the circuit board for each connection
- EETALK: What products might be reshaped in the 5G era? (Give away 10-100 Chip Coins)
- How to layout the PCB of photovoltaic power supply?
- Questions and Answers about bq24650 and BQ25601