Hello, I'm Duck.
Continuing from last time, this is about memory conversion, a function of the MMU.
We will look at what address translation is and what the benefits of having an MMU are.
Basics of Address Conversion
Let's start by looking at the basic mechanism. To perform address translation, a table (page table) is needed that compares the address before and after the translation.
The MMU has a buffer called the TLB (translation lookaside buffer), where it stores the page table. The MMU refers to the TLB to translate memory.
Conversion method
Let's look at this in more detail. For example, let's consider translating a 32-bit address.
A virtual address is divided into upper bits (virtual page number) and lower bits (page offset).
This retrieves the upper bits of the physical page address that matches the virtual page number. The lower bits are used as is without conversion.
We will now access the data at this translated physical address.
The bit width will vary depending on the device and system settings.
Memory protection feature
Actually, there's another advantage to MMUs: their protection function.
This prevents data from being read or written to the wrong memory area.
If program B is running and attempts to access program A's memory by mistake, the MMU will throw an exception.
The mechanism involves swapping the TLB (Top Level Block) for each program. The TLB keeps a page table that only includes the range used by the current program, so if an address translation is attempted in the wrong area, the MMU (Mechanical Memory Unit) detects it and notifies the CPU.
Typically, protection features are not used for individual programs; they are mainly used to separate the kernel area used by the OS from other user areas.
This is to prevent accidentally overwriting the memory used by the operating system.
There are also MPUs (memory protection units) that are separate components solely for memory protection.
I want to remember + α
In reality, the TLB (Top Level Loader) does not have enough memory to cover all the address translations in a program.
Therefore, exceptions due to no TLB match (page faults) can occur even within the same program.
Therefore, the program needs to be written to handle different situations depending on the cause of the page fault.
Duck's "Even SoCs play a big role!? What is the role of the MMU??" series
The MMU is practically essential for advanced embedded systems! We'll introduce its role in two parts!
What is an MMU? What is an address space? Let's start by understanding the basics of address translation!
This article explains the actual mechanism of address translation using TLB!