Skip to content

Commit f13e6e4

Browse files
committed
Change to new aarch64-unknown-none-softloat target.
Also, add safety docs where demanded by clippy.
1 parent d44dfc5 commit f13e6e4

File tree

92 files changed

+258
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+258
-69
lines changed

Diff for: 01_bareminimum/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 01_bareminimum/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 01_bareminimum/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ much as possible, we are already setting up a Rust crate. This allows us to use
2626

2727
The Raspberry Pi 3 features a processor that uses ARM's `AArch64` architecture.
2828
Conveniently, Rust already provides a generic target for bare-metal aarch64 code
29-
that we can leverage. It is called [aarch64-unknown-none].
29+
that we can leverage. It is called [aarch64-unknown-none-softfloat].
3030

31-
[aarch64-unknown-none]: https://github.com/andre-richter/rust/blob/master/src/librustc_target/spec/aarch64_unknown_none.rs
31+
[aarch64-unknown-none-softfloat]: https://github.com/rust-lang/rust/blob/master/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs
3232

3333
In the `Makefile`, we select this target in various places by passing it to
3434
cargo using the `--target` cmdline argument.
@@ -37,28 +37,28 @@ Additionally, we provide a config file in `.cargo/config` were we make further
3737
specializations:
3838

3939
```toml
40-
[target.aarch64-unknown-none]
40+
[target.aarch64-unknown-none-softfloat]
4141
rustflags = [
4242
"-C", "link-arg=-Tlink.ld",
43-
"-C", "target-feature=-fp-armv8",
4443
"-C", "target-cpu=cortex-a53",
4544
]
4645
```
4746

48-
The first line tells rustc to use our custom `link.ld` linker script. The second
49-
line instructs the compiler to not use floating point operations. This is a
50-
common choice when writing an operating system kernel. If floating point is not
47+
The first line tells rustc to use our custom `link.ld` linker script. The
48+
second argument specifies the exact CPU type that is used on Raspberry Pi 3, so
49+
that the compiler can optimize for it.
50+
51+
The target itself tells the compiler already to not use floating point
52+
operations, which is hinted by the `-softfloat` appendix. This is a common
53+
choice when writing an operating system kernel. If floating point is not
5154
explicitly disabled, it is possible that the compiler uses auto-vectorization to
5255
optimize, for example, operations on array data structures. This would
5356
implicitly result in use of floating point registers and operations. However,
5457
since it is very costly to save and restore floating point registers during
5558
context-switches, use of fp is usually disabled from the get go to save the
5659
cycles and optimize the kernel for fast context switching.
5760

58-
Finally, the third arguments specifies the exact CPU type that is used in
59-
Raspberry Pi 3, so that the compiler can optimize for it.
60-
61-
Since the `aarch64-unknown-none` target is not shipped with an associated
61+
Since the `aarch64-unknown-none-softfloat` target is not shipped with an associated
6262
precompiled standard library, and since we anyways modify the target via the
6363
`.cargo/config` file, we are using [cargo-xbuild][xbuild] to compile our own
6464
standard library. This way, we can ensure that our bare-metal code is optimized

Diff for: 01_bareminimum/kernel8

0 Bytes
Binary file not shown.

Diff for: 02_multicore_rust/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 02_multicore_rust/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 02_multicore_rust/kernel8

0 Bytes
Binary file not shown.

Diff for: 02_multicore_rust/raspi3_boot/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern crate panic_abort;
3636
#[macro_export]
3737
macro_rules! entry {
3838
($path:path) => {
39+
/// # Safety
40+
///
41+
/// - User must ensure to provide a suitable main function for the
42+
/// platform.
3943
#[export_name = "main"]
4044
pub unsafe fn __main() -> ! {
4145
// type check the given path
@@ -49,6 +53,10 @@ macro_rules! entry {
4953
/// Reset function.
5054
///
5155
/// Initializes the bss section before calling into the user's `main()`.
56+
///
57+
/// # Safety
58+
///
59+
/// - Only a single core must be active and running this function.
5260
#[no_mangle]
5361
pub unsafe extern "C" fn reset() -> ! {
5462
extern "C" {

Diff for: 03_uart1/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 03_uart1/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 03_uart1/kernel8

0 Bytes
Binary file not shown.

Diff for: 03_uart1/raspi3_boot/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern crate panic_abort;
3636
#[macro_export]
3737
macro_rules! entry {
3838
($path:path) => {
39+
/// # Safety
40+
///
41+
/// - User must ensure to provide a suitable main function for the
42+
/// platform.
3943
#[export_name = "main"]
4044
pub unsafe fn __main() -> ! {
4145
// type check the given path
@@ -49,6 +53,10 @@ macro_rules! entry {
4953
/// Reset function.
5054
///
5155
/// Initializes the bss section before calling into the user's `main()`.
56+
///
57+
/// # Safety
58+
///
59+
/// - Only a single core must be active and running this function.
5260
#[no_mangle]
5361
pub unsafe extern "C" fn reset() -> ! {
5462
extern "C" {

Diff for: 04_mailboxes/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 04_mailboxes/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 04_mailboxes/kernel8

0 Bytes
Binary file not shown.

Diff for: 04_mailboxes/kernel8.img

0 Bytes
Binary file not shown.

Diff for: 04_mailboxes/raspi3_boot/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern crate panic_abort;
3636
#[macro_export]
3737
macro_rules! entry {
3838
($path:path) => {
39+
/// # Safety
40+
///
41+
/// - User must ensure to provide a suitable main function for the
42+
/// platform.
3943
#[export_name = "main"]
4044
pub unsafe fn __main() -> ! {
4145
// type check the given path
@@ -49,6 +53,10 @@ macro_rules! entry {
4953
/// Reset function.
5054
///
5155
/// Initializes the bss section before calling into the user's `main()`.
56+
///
57+
/// # Safety
58+
///
59+
/// - Only a single core must be active and running this function.
5260
#[no_mangle]
5361
pub unsafe extern "C" fn reset() -> ! {
5462
extern "C" {

Diff for: 05_uart0/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 05_uart0/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 05_uart0/kernel8

0 Bytes
Binary file not shown.

Diff for: 05_uart0/raspi3_boot/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern crate panic_abort;
3636
#[macro_export]
3737
macro_rules! entry {
3838
($path:path) => {
39+
/// # Safety
40+
///
41+
/// - User must ensure to provide a suitable main function for the
42+
/// platform.
3943
#[export_name = "main"]
4044
pub unsafe fn __main() -> ! {
4145
// type check the given path
@@ -49,6 +53,10 @@ macro_rules! entry {
4953
/// Reset function.
5054
///
5155
/// Initializes the bss section before calling into the user's `main()`.
56+
///
57+
/// # Safety
58+
///
59+
/// - Only a single core must be active and running this function.
5260
#[no_mangle]
5361
pub unsafe extern "C" fn reset() -> ! {
5462
extern "C" {

Diff for: 06_raspbootin64/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
"-C", "relocation-model=pic",
76
]

Diff for: 06_raspbootin64/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 06_raspbootin64/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ To enable PIC for our loader, we add the following line to the compiler flags in
9292
the`.cargo/config`:
9393

9494
```toml
95-
[target.aarch64-unknown-none]
95+
[target.aarch64-unknown-none-softfloat]
9696
rustflags = [
9797
"-C", "link-arg=-Tlink.ld",
98-
"-C", "target-feature=-fp-armv8",
9998
"-C", "target-cpu=cortex-a53",
10099
"-C", "relocation-model=pic", # <-- New
101100
]

Diff for: 06_raspbootin64/kernel8

0 Bytes
Binary file not shown.

Diff for: 06_raspbootin64/raspi3_boot/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern crate panic_abort;
3636
#[macro_export]
3737
macro_rules! entry {
3838
($path:path) => {
39+
/// # Safety
40+
///
41+
/// - User must ensure to provide a suitable main function for the
42+
/// platform.
3943
#[export_name = "main"]
4044
pub unsafe fn __main() -> ! {
4145
// type check the given path
@@ -49,6 +53,10 @@ macro_rules! entry {
4953
/// Reset function.
5054
///
5155
/// Trampolines into the user's `main()`.
56+
///
57+
/// # Safety
58+
///
59+
/// - Only a single core must be active and running this function.
5260
#[no_mangle]
5361
pub unsafe extern "C" fn reset() -> ! {
5462
extern "Rust" {

Diff for: 07_abstraction/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 07_abstraction/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 07_abstraction/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ should yield something like the following, where you can see that the stack
9393
pointer is not used apart from ourselves setting it.
9494

9595
```console
96-
ferris@box:~$ cargo objdump --target aarch64-unknown-none -- -disassemble -print-imm-hex kernel8
96+
ferris@box:~$ cargo objdump --target aarch64-unknown-none-softfloat -- -disassemble -print-imm-hex kernel8
9797

9898
[...] (Some output omitted)
9999

Diff for: 07_abstraction/kernel8

0 Bytes
Binary file not shown.

Diff for: 07_abstraction/raspi3_boot/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extern crate panic_abort;
3535
#[macro_export]
3636
macro_rules! entry {
3737
($path:path) => {
38+
/// # Safety
39+
///
40+
/// - User must ensure to provide a suitable main function for the
41+
/// platform.
3842
#[export_name = "main"]
3943
pub unsafe fn __main() -> ! {
4044
// type check the given path
@@ -48,6 +52,10 @@ macro_rules! entry {
4852
/// Reset function.
4953
///
5054
/// Initializes the bss section before calling into the user's `main()`.
55+
///
56+
/// # Safety
57+
///
58+
/// - Only a single core must be active and running this function.
5159
unsafe fn reset() -> ! {
5260
extern "C" {
5361
// Boundaries of the .bss section, provided by the linker script
@@ -69,6 +77,10 @@ unsafe fn reset() -> ! {
6977
///
7078
/// Parks all cores except core0, and then jumps to the internal
7179
/// `reset()` function.
80+
///
81+
/// # Safety
82+
///
83+
/// - Linker script must ensure to place this function at `0x80_000`.
7284
#[link_section = ".text.boot"]
7385
#[no_mangle]
7486
pub unsafe extern "C" fn _boot_cores() -> ! {

Diff for: 08_random/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

Diff for: 08_random/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# SOFTWARE.
2323
#
2424

25-
TARGET = aarch64-unknown-none
25+
TARGET = aarch64-unknown-none-softfloat
2626

2727
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld
2828

Diff for: 08_random/kernel8

0 Bytes
Binary file not shown.

Diff for: 08_random/kernel8.img

0 Bytes
Binary file not shown.

Diff for: 08_random/raspi3_boot/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extern crate panic_abort;
3535
#[macro_export]
3636
macro_rules! entry {
3737
($path:path) => {
38+
/// # Safety
39+
///
40+
/// - User must ensure to provide a suitable main function for the
41+
/// platform.
3842
#[export_name = "main"]
3943
pub unsafe fn __main() -> ! {
4044
// type check the given path
@@ -48,6 +52,10 @@ macro_rules! entry {
4852
/// Reset function.
4953
///
5054
/// Initializes the bss section before calling into the user's `main()`.
55+
///
56+
/// # Safety
57+
///
58+
/// - Only a single core must be active and running this function.
5159
unsafe fn reset() -> ! {
5260
extern "C" {
5361
// Boundaries of the .bss section, provided by the linker script
@@ -69,6 +77,10 @@ unsafe fn reset() -> ! {
6977
///
7078
/// Parks all cores except core0, and then jumps to the internal
7179
/// `reset()` function.
80+
///
81+
/// # Safety
82+
///
83+
/// - Linker script must ensure to place this function at `0x80_000`.
7284
#[link_section = ".text.boot"]
7385
#[no_mangle]
7486
pub unsafe extern "C" fn _boot_cores() -> ! {

Diff for: 09_delays/.cargo/config

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.aarch64-unknown-none]
1+
[target.aarch64-unknown-none-softfloat]
22
rustflags = [
33
"-C", "link-arg=-Tlink.ld",
4-
"-C", "target-feature=-fp-armv8",
54
"-C", "target-cpu=cortex-a53",
65
]

0 commit comments

Comments
 (0)