Skip to content

Commit 49dc18d

Browse files
committed
Added post on MMU support.
1 parent fd0bc18 commit 49dc18d

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

_posts/mm/2013-07-19-mmu-support.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
layout: posts
3+
category: memory
4+
title: Memory Management and Virtual Memory Support
5+
author: James Walmsley
6+
7+
---
8+
9+
Today, BitThunder officially became a "real" operating system.
10+
I now managed to add basic MMU (memory management unit) support. Its not, and never will be
11+
a requirement of course, but for those projects that can support this you'll get a lot!
12+
13+
# Memory Map
14+
During boot, the kernel now sets up a default set of page tables. (Section entries on ARM).
15+
This mirrors the inital executable at address 0xC000_0000 (just like Linux), and then the
16+
boot code carefully jumps to the "next" instruction but in its true address space.
17+
18+
{% highlight c %}
19+
+-------------------------+ 0xFFFF_FFFF
20+
| | \
21+
| | |
22+
| | |
23+
| Remapped I/O regions | |
24+
| | }- High-Memory (Permanent Kernel Region).
25+
| Allocatable Mem Pages | |
26+
| | |
27+
| BT Kernel Text Section |/
28+
+-------------------------+ 0xC000_0000
29+
| |
30+
| |
31+
| |
32+
| |
33+
| |
34+
| |
35+
| |
36+
| |
37+
| Unmapped |
38+
| Process Address Space |
39+
| |
40+
| |
41+
| |
42+
| |
43+
| |
44+
| |
45+
| |
46+
| |
47+
| |
48+
+-------------------------+ 0x0000_0000
49+
{% endhighlight %}
50+
51+
# IO Remapping
52+
53+
Turning on the MMU with an initial mapping on the ARM was trivial. (I'll blog about this later).
54+
The biggest issue now was that the entire kernel was running completely isolated, there
55+
was no-longer any access to hardware. That means none of the drivers could be utilised
56+
to create a kernel tick or print anything to stdout.
57+
58+
To solve this issue I created a bt_ioremap() api function. The function is used just like the ioremap
59+
function in the linux kernel. bt_ioremap() can only create section mappings, (e.g. 1MB regions).
60+
This might be over-simple, but it reduces the page-table walk dramatically, something that is important
61+
when using hardware in a real-time system.
62+
63+
After all a real-time process in BitThunder may use any driver in the system, and those drivers
64+
must not alter the real-time characteristics of the calling process.
65+
66+
# Page Allocation
67+
68+
Currently I have not had time to implement page allocation, but this is coming very soon!
69+
I am currently planning to have a distinction between hard real-time and soft real-time processes,
70+
of which both will come in 2 flavours.
71+
72+
## Hard Real-time
73+
74+
All processes that are hard-realtime based will only be able to map section sized (top-level page entries)
75+
into their respective memory spaces. This is to prevent table walking, and reduce TLB misses.
76+
77+
### Hard Kernel Bound Processes
78+
79+
This variation uses kernel address space, these processes will have full system access, and a bug in these
80+
will cause the entire system to kernel panic. The advantage is that this process address space is permanently
81+
mapped. TLB misses are therefore less likely, especially if the process is regularly active.
82+
83+
These processes can call the Kernel level API's directly, and reduce the overhead of system calls.
84+
Of course system calls will also work in this mode.
85+
86+
### Hard Isolated processes
87+
88+
This variation creates a full process address space, and completely isolates the process from
89+
other processes and the kernel's internal data. These processes can only use devices or OS services
90+
through a system call mechanism.
91+
92+
## Soft Real-time
93+
94+
These processes are very much like those on a standard linux system. The scheduler is still real-time
95+
but here we have a full page table, therefore increased page walking and TLB misses will occur.
96+
97+
### Soft Kernel Bound
98+
99+
The same as hard kernel bound processes, except a normal page table is used allowing PAGE_SIZE memory
100+
allocation granularity.
101+
102+
### Soft Isolated processes
103+
104+
These are the same as the hard isolated processes, but with a full page table for fine-grained memory
105+
control. These are just like Linux processes but on a real-time scheduler.
106+
Again they must use system calls to utilise OS services etc.
107+
108+
Most processes should be soft isolated process variants.
109+
110+

0 commit comments

Comments
 (0)