Skip to content

Commit 2432c0d

Browse files
committed
Revert to assembly boot code
It is too risky to rely on the compiler to not insert any operations using the stack. Having a stack-setting call in Rust using the cortex-a crate as the first action in a Rust-only _start() function does not work if you're subsequently using the stack, because the compiler often inserts the operations to make room on the stack to prepare a function call BEFORE the call to set the stack, which crashes the boot process. Hence, keep on using a small piece of assembly boot code throughout.
1 parent 6a9af3c commit 2432c0d

File tree

191 files changed

+2586
-3695
lines changed

Some content is hidden

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

191 files changed

+2586
-3695
lines changed

.editorconfig

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ indent_size = 4
2323
[*.rs]
2424
indent_size = 4
2525

26-
[*.S]
27-
indent_size = 4
26+
[*.s]
27+
indent_style = tab
28+
indent_size = 8
2829

2930
[*.sh]
3031
indent_size = 4

01_wait_forever/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
authors = ["Andre Richter <[email protected]>"]
55
edition = "2018"
66

7+
[profile.release]
8+
lto = true
9+
710
[features]
811
default = []
912
bsp_rpi3 = []

01_wait_forever/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Only `.text` section.
2424
- `main.rs`: Important [inner attributes]:
2525
- `#![no_std]`, `#![no_main]`
26-
- `boot.S`: Assembly `_start()` function that executes `wfe` (Wait For Event), halting all cores
26+
- `boot.s`: Assembly `_start()` function that executes `wfe` (Wait For Event), halting all cores
2727
that are executing `_start()`.
2828
- We (have to) define a `#[panic_handler]` function to make the compiler happy.
2929
- Make it `unimplemented!()` because it will be stripped out since it is not used.

01_wait_forever/src/_arch/aarch64/cpu/boot.S

-11
This file was deleted.

01_wait_forever/src/_arch/aarch64/cpu/boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
//!
1212
//! crate::cpu::boot::arch_boot
1313
14-
// Assembly counterpart to this file. Includes function _start().
15-
global_asm!(include_str!("boot.S"));
14+
// Assembly counterpart to this file.
15+
global_asm!(include_str!("boot.s"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
//
3+
// Copyright (c) 2021 Andre Richter <[email protected]>
4+
5+
//--------------------------------------------------------------------------------------------------
6+
// Public Code
7+
//--------------------------------------------------------------------------------------------------
8+
.section .text._start
9+
10+
//------------------------------------------------------------------------------
11+
// fn _start()
12+
//------------------------------------------------------------------------------
13+
_start:
14+
// Infinitely wait for events (aka "park the core").
15+
1: wfe
16+
b 1b
17+
18+
.size _start, . - _start
19+
.type _start, function
20+
.global _start

01_wait_forever/src/bsp/raspberrypi/link.ld

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ SECTIONS
2323
.text :
2424
{
2525
KEEP(*(.text._start))
26-
*(.text*)
2726
} :segment_rx
2827
}

01_wait_forever/src/main.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@
100100
//!
101101
//! # Boot flow
102102
//!
103-
//! 1. The kernel's entry point is the function [`cpu::boot::arch_boot::_start()`].
104-
//! - It is implemented in `src/_arch/__arch_name__/cpu/boot.S`.
105-
//!
106-
//! [`cpu::boot::arch_boot::_start()`]: ../src/kernel/cpu/up/_arch/aarch64/cpu/boot.rs.html
103+
//! 1. The kernel's entry point is the function `cpu::boot::arch_boot::_start()`.
104+
//! - It is implemented in `src/_arch/__arch_name__/cpu/boot.s`.
107105
108106
#![feature(asm)]
109107
#![feature(global_asm)]

02_runtime_init/Cargo.lock

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

02_runtime_init/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ bsp_rpi4 = []
1717
##--------------------------------------------------------------------------------------------------
1818

1919
[dependencies]
20+
21+
# Platform specific dependencies
22+
[target.'cfg(target_arch = "aarch64")'.dependencies]
23+
cortex-a = { version = "5.x.x" }

0 commit comments

Comments
 (0)