1
1
# Getting Ready to Rust
2
2
3
- Before we can start running Rust code, we need to do some initialisation .
3
+ Before we can start running Rust code, we need to do some initialization .
4
4
5
5
``` armasm
6
6
{{#include examples/src/entry.S:entry}}
@@ -12,36 +12,36 @@ This code is in `src/bare-metal/aps/examples/src/entry.S`. It's not necessary to
12
12
understand this in detail -- the takeaway is that typically some low-level setup
13
13
is needed to meet Rust's expectations of the system.
14
14
15
- - This is the same as it would be for C: initialising the processor state,
15
+ - This is the same as it would be for C: initializing the processor state,
16
16
zeroing the BSS, and setting up the stack pointer.
17
17
- The BSS (block starting symbol, for historical reasons) is the part of the
18
- object file which containing statically allocated variables which are
19
- initialised to zero. They are omitted from the image, to avoid wasting space
18
+ object file that contains statically allocated variables that are
19
+ initialized to zero. They are omitted from the image, to avoid wasting space
20
20
on zeroes. The compiler assumes that the loader will take care of zeroing
21
21
them.
22
- - The BSS may already be zeroed, depending on how memory is initialised and the
22
+ - The BSS may already be zeroed, depending on how memory is initialized and the
23
23
image is loaded, but we zero it to be sure.
24
24
- We need to enable the MMU and cache before reading or writing any memory. If
25
25
we don't:
26
26
- Unaligned accesses will fault. We build the Rust code for the
27
- ` aarch64-unknown-none ` target which sets ` +strict-align ` to prevent the
28
- compiler generating unaligned accesses, so it should be fine in this case,
29
- but this is not necessarily the case in general.
27
+ ` aarch64-unknown-none ` target that sets ` +strict-align ` to prevent the
28
+ compiler from generating unaligned accesses, so it should be fine in this
29
+ case, but this is not necessarily the case in general.
30
30
- If it were running in a VM, this can lead to cache coherency issues. The
31
31
problem is that the VM is accessing memory directly with the cache disabled,
32
32
while the host has cacheable aliases to the same memory. Even if the host
33
33
doesn't explicitly access the memory, speculative accesses can lead to cache
34
34
fills, and then changes from one or the other will get lost when the cache
35
35
is cleaned or the VM enables the cache. (Cache is keyed by physical address,
36
36
not VA or IPA.)
37
- - For simplicity, we just use a hardcoded pagetable (see ` idmap.S ` ) which
37
+ - For simplicity, we just use a hardcoded pagetable (see ` idmap.S ` ) that
38
38
identity maps the first 1 GiB of address space for devices, the next 1 GiB for
39
39
DRAM, and another 1 GiB higher up for more devices. This matches the memory
40
40
layout that QEMU uses.
41
41
- We also set up the exception vector (` vbar_el1 ` ), which we'll see more about
42
42
later.
43
43
- All examples this afternoon assume we will be running at exception level 1
44
- (EL1). If you need to run at a different exception level you'll need to modify
45
- ` entry.S ` accordingly.
44
+ (EL1). If you need to run at a different exception level, you'll need to
45
+ modify ` entry.S ` accordingly.
46
46
47
47
</details >
0 commit comments