Skip to content

Commit 2bb13e5

Browse files
authored
Use aarch64-rt in bare metal AP section and exercise (#2751)
Also use `global_asm!` rather than `cc::Build` to build assembly files. This avoids a dependency and some build scripts.
1 parent 3b63068 commit 2bb13e5

File tree

21 files changed

+319
-662
lines changed

21 files changed

+319
-662
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@
361361
- [Logging](bare-metal/aps/logging.md)
362362
- [Using It](bare-metal/aps/logging/using.md)
363363
- [Exceptions](bare-metal/aps/exceptions.md)
364+
- [aarch64-rt](bare-metal/aps/aarch64-rt.md)
364365
- [Other Projects](bare-metal/aps/other-projects.md)
365366
- [Useful Crates](bare-metal/useful-crates.md)
366367
- [`zerocopy`](bare-metal/useful-crates/zerocopy.md)

src/bare-metal/aps/aarch64-rt.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# aarch64-rt
2+
3+
The `aarch64-rt` crate provides the assembly entry point and exception vector
4+
that we implemented before. We just need to mark our main function with the
5+
`entry!` macro.
6+
7+
It also provides the `initial_pagetable!` macro to let us define an initial
8+
static pagetable in Rust, rather than in assembly code like we did before.
9+
10+
We can also use the UART driver from the `arm-pl011-uart` crate rather than
11+
writing our own.
12+
13+
```rust,editable,compile_fail
14+
{{#include examples/src/main_rt.rs:main}}
15+
```

src/bare-metal/aps/entry-point.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Before we can start running Rust code, we need to do some initialisation.
44

55
```armasm
6-
{{#include examples/entry.S:entry}}
6+
{{#include examples/src/entry.S:entry}}
77
```
88

99
<details>
1010

11-
This code is in `src/bare-metal/aps/examples/entry.S`. It's not necessary to
11+
This code is in `src/bare-metal/aps/examples/src/entry.S`. It's not necessary to
1212
understand this in detail -- the takeaway is that typically some low-level setup
1313
is needed to meet Rust's expectations of the system.
1414

src/bare-metal/aps/examples/Cargo.lock

Lines changed: 97 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bare-metal/aps/examples/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ edition = "2021"
77
publish = false
88

99
[dependencies]
10+
aarch64-paging = { version = "0.9.1", default-features = false }
11+
aarch64-rt = "0.1.3"
12+
arm-pl011-uart = "0.3.1"
1013
bitflags = "2.9.0"
1114
log = "0.4.27"
1215
smccc = "0.2.0"
1316
spin = "0.10.0"
1417

15-
[build-dependencies]
16-
cc = "1.2.20"
17-
1818
[[bin]]
1919
name = "improved"
2020
path = "src/main_improved.rs"
@@ -27,6 +27,10 @@ path = "src/main_logger.rs"
2727
name = "minimal"
2828
path = "src/main_minimal.rs"
2929

30+
[[bin]]
31+
name = "rt"
32+
path = "src/main_rt.rs"
33+
3034
[[bin]]
3135
name = "psci"
3236
path = "src/main_psci.rs"

src/bare-metal/aps/examples/build.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,16 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use cc::Build;
16-
use std::env;
15+
use core::arch::global_asm;
1716

18-
fn main() {
19-
env::set_var("CROSS_COMPILE", "aarch64-none-elf");
20-
env::set_var("CC", "clang");
21-
22-
Build::new()
23-
.file("entry.S")
24-
.file("exceptions.S")
25-
.file("idmap.S")
26-
.compile("empty")
27-
}
17+
global_asm!(include_str!("entry.S"));
18+
global_asm!(include_str!("exceptions.S"));
19+
global_asm!(include_str!("idmap.S"));

0 commit comments

Comments
 (0)