Skip to content

Commit 0bd363f

Browse files
committed
Sync with the newest Embedonomicon
https://github.com/rust-embedded/embedonomicon Closes #3
1 parent 1b8b78d commit 0bd363f

Some content is hidden

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

80 files changed

+874
-647
lines changed

01_bareminimum/link.ld

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
/*
2-
* Copyright (C) 2018 bzt (bztsrc@github)
2+
* MIT License
3+
*
34
* Copyright (c) 2018 Andre Richter <andre.o[email protected]>
45
*
5-
* Permission is hereby granted, free of charge, to any person
6-
* obtaining a copy of this software and associated documentation
7-
* files (the "Software"), to deal in the Software without
8-
* restriction, including without limitation the rights to use, copy,
9-
* modify, merge, publish, distribute, sublicense, and/or sell copies
10-
* of the Software, and to permit persons to whom the Software is
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
1111
* furnished to do so, subject to the following conditions:
1212
*
13-
* The above copyright notice and this permission notice shall be
14-
* included in all copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21-
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23-
* DEALINGS IN THE SOFTWARE.
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
2415
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
2523
*/
2624

25+
ENTRY(_boot_cores);
26+
2727
SECTIONS
2828
{
2929
. = 0x80000;
30-
.text : { KEEP(*(.text.boot)) }
3130

32-
/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
31+
.text :
32+
{
33+
KEEP(*(.text.boot)) *(.text .text.*)
34+
}
35+
36+
/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
3337
}

02_multicore_rust/Cargo.lock

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

02_multicore_rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version = "0.1.0"
44
authors = ["Andre Richter <[email protected]>"]
55

66
[dependencies]
7-
raspi3_glue = { path = "raspi3_glue" }
7+
raspi3_boot = { path = "raspi3_boot" }

02_multicore_rust/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Now let's try something more complex, shall we? By complex I mean stopping the
44
CPU cores just like in the first tutorial, but this time stop one of them from
55
**Rust**!
66

7-
## Glue code
7+
## Boot code
88

99
In order to conveniently incorporate Rust code, we are restructuring our crate a
1010
bit.
@@ -15,16 +15,16 @@ can compare to the files in this crate and see what we actually kept to get our
1515
Raspberry Pi 3 tutorial going. Here's a short summary of the new structure of
1616
the crate:
1717

18-
- `raspi3_glue/`: The extern crate containing glue code as presented in the
18+
- `raspi3_boot/`: The extern crate containing boot code as presented in the
1919
Embedonomicon.
2020
- In a small deviation to the Embedonomicon, `lib.rs` also includes
2121
`boot_cores.S` from the previous tutorial, still with the
2222
[global_asm!][gasm] macro.
23-
- Therefore, `boot_cores.S` has been moved into `raspi3_glue/src/`.
23+
- Therefore, `boot_cores.S` has been moved into `raspi3_boot/src/`.
2424
- `src`: Source code of our actual Rust code, currently only containing
2525
`main.rs` executing an endless loop.
2626

27-
[nom]: https://japaric.github.io/embedonomicon/
27+
[nom]: https://rust-embedded.github.io/embedonomicon/
2828
[gasm]: https://doc.rust-lang.org/unstable-book/language-features/global-asm.html
2929

3030
### Changes to `boot_cores.S`
@@ -36,7 +36,7 @@ CPU core.
3636

3737
If the result of the read from `mpidr_el1` is zero, which means we are
3838
executing on core0, we set up the stack for that core, and afterwards call the
39-
Rust `reset()` function of the glue code in `raspi3_glue/src/lib.rs`. In case
39+
Rust `reset()` function of the boot code in `raspi3_boot/src/lib.rs`. In case
4040
the Rust code returns (which it never should), we also jump to the same
4141
infinite loop the other CPU cores are running.
4242

@@ -58,7 +58,7 @@ allocated in the Rust code.
5858

5959
Therefore, we added the `bss` segment to the linker script and export its
6060
properties via `__bss_start` and `__bss_size`, which will be picked up and
61-
zeroed out by the glue code in `raspi3_glue/src/lib.rs`.
61+
zeroed out by the boot code in `raspi3_boot/src/lib.rs`.
6262

6363
Additionally, there is a [data segment][data] now.
6464

02_multicore_rust/kernel8.img

-24 Bytes
Binary file not shown.

02_multicore_rust/link.ld

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
11
/*
2-
* Copyright (C) 2018 bzt (bztsrc@github)
2+
* MIT License
33
*
4-
* Permission is hereby granted, free of charge, to any person
5-
* obtaining a copy of this software and associated documentation
6-
* files (the "Software"), to deal in the Software without
7-
* restriction, including without limitation the rights to use, copy,
8-
* modify, merge, publish, distribute, sublicense, and/or sell copies
9-
* of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
4+
* Copyright (c) 2018 Andre Richter <andre.o[email protected]>
115
*
12-
* The above copyright notice and this permission notice shall be
13-
* included in all copies or substantial portions of the Software.
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
1412
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20-
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22-
* DEALINGS IN THE SOFTWARE.
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
2315
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
2423
*/
2524

25+
ENTRY(_boot_cores);
26+
2627
SECTIONS
2728
{
2829
. = 0x80000;
29-
.text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) }
30-
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) }
30+
31+
.text :
32+
{
33+
KEEP(*(.text.boot)) *(.text .text.*)
34+
}
35+
36+
.rodata :
37+
{
38+
*(.rodata .rodata.*)
39+
}
40+
3141
PROVIDE(_data = .);
32-
.data : { *(.data .data.* .gnu.linkonce.d*) }
33-
.bss (NOLOAD) : {
42+
.data :
43+
{
44+
*(.data .data.*)
45+
}
46+
47+
.bss (NOLOAD) :
48+
{
3449
. = ALIGN(16);
35-
__bss_start = .;
3650
*(.bss .bss.*)
3751
*(COMMON)
38-
__bss_end = .;
3952
}
40-
_end = .;
4153

4254
/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
4355
}
44-
__bss_size = (__bss_end - __bss_start)>>3;
56+
57+
__bss_start = ADDR(.bss);
58+
__bss_end = ADDR(.bss) + SIZEOF(.bss);

07_abstraction/raspi3_glue/Cargo.toml renamed to 02_multicore_rust/raspi3_boot/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "raspi3_glue"
2+
name = "raspi3_boot"
33
version = "0.1.0"
44
authors = ["Andre Richter <[email protected]>"]
55

04_mailboxes/raspi3_glue/src/lib.rs renamed to 02_multicore_rust/raspi3_boot/src/lib.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,49 @@
2323
* SOFTWARE.
2424
*/
2525

26-
#![feature(lang_items)]
26+
#![deny(missing_docs)]
27+
#![deny(warnings)]
2728
#![no_std]
2829
#![feature(global_asm)]
2930

31+
//! Low-level boot of the Raspberry's processor
32+
33+
extern crate cortex_a;
3034
extern crate panic_abort;
3135
extern crate r0;
3236

33-
#[lang = "start"]
34-
extern "C" fn start<T>(user_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize
35-
where
36-
T: Termination,
37-
{
38-
user_main().report() as isize
39-
}
40-
41-
#[lang = "termination"]
42-
trait Termination {
43-
fn report(self) -> i32;
44-
}
37+
#[macro_export]
38+
macro_rules! entry {
39+
($path:path) => {
40+
#[export_name = "main"]
41+
pub unsafe fn __main() -> ! {
42+
// type check the given path
43+
let f: fn() -> ! = $path;
4544

46-
impl Termination for () {
47-
fn report(self) -> i32 {
48-
0
49-
}
45+
f()
46+
}
47+
};
5048
}
5149

50+
/// Reset function.
51+
///
52+
/// Initializes the bss section before calling into the user's `main()`.
5253
#[no_mangle]
5354
pub unsafe extern "C" fn reset() -> ! {
54-
use core::ptr;
55-
5655
extern "C" {
57-
fn main(argc: isize, argv: *const *const u8) -> isize;
58-
59-
// Boundaries of the .bss section
60-
static mut __bss_start: u32;
61-
static mut __bss_end: u32;
56+
// Boundaries of the .bss section, provided by the linker script
57+
static mut __bss_start: u64;
58+
static mut __bss_end: u64;
6259
}
6360

6461
// Zeroes the .bss section
6562
r0::zero_bss(&mut __bss_start, &mut __bss_end);
6663

67-
main(0, ptr::null());
64+
extern "Rust" {
65+
fn main() -> !;
66+
}
6867

69-
loop {}
68+
main();
7069
}
7170

7271
// Disable all cores except core 0, and then jump to reset()

02_multicore_rust/raspi3_glue/Cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

02_multicore_rust/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
*/
2424

2525
#![no_std]
26+
#![no_main]
2627

27-
extern crate raspi3_glue;
28+
#[macro_use]
29+
extern crate raspi3_boot;
2830

29-
fn main() {
31+
entry!(kernel_entry);
32+
33+
fn kernel_entry() -> ! {
3034
loop {}
3135
}

03_uart1/Cargo.lock

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

03_uart1/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ version = "0.1.0"
44
authors = ["Andre Richter <[email protected]>"]
55

66
[dependencies]
7-
raspi3_glue = { path = "raspi3_glue" }
7+
raspi3_boot = { path = "raspi3_boot" }
88
register = "0.1.1"

03_uart1/kernel8.img

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)