Skip to content

Commit

Permalink
Sync with the newest Embedonomicon
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-richter committed Aug 12, 2018
1 parent 1b8b78d commit 0bd363f
Show file tree
Hide file tree
Showing 80 changed files with 874 additions and 647 deletions.
44 changes: 24 additions & 20 deletions 01_bareminimum/link.ld
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
/*
* Copyright (C) 2018 bzt (bztsrc@github)
* MIT License
*
* Copyright (c) 2018 Andre Richter <andre.o.richter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

ENTRY(_boot_cores);

SECTIONS
{
. = 0x80000;
.text : { KEEP(*(.text.boot)) }

/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
.text :
{
KEEP(*(.text.boot)) *(.text .text.*)
}

/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
}
29 changes: 27 additions & 2 deletions 02_multicore_rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 02_multicore_rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
authors = ["Andre Richter <andre.o.richter@gmail.com>"]

[dependencies]
raspi3_glue = { path = "raspi3_glue" }
raspi3_boot = { path = "raspi3_boot" }
12 changes: 6 additions & 6 deletions 02_multicore_rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Now let's try something more complex, shall we? By complex I mean stopping the
CPU cores just like in the first tutorial, but this time stop one of them from
**Rust**!

## Glue code
## Boot code

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

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

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

### Changes to `boot_cores.S`
Expand All @@ -36,7 +36,7 @@ CPU core.

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

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

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

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

Expand Down
Binary file modified 02_multicore_rust/kernel8.img
Binary file not shown.
66 changes: 40 additions & 26 deletions 02_multicore_rust/link.ld
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
/*
* Copyright (C) 2018 bzt (bztsrc@github)
* MIT License
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Copyright (c) 2018 Andre Richter <andre.o.richter@gmail.com>
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

ENTRY(_boot_cores);

SECTIONS
{
. = 0x80000;
.text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) }
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) }

.text :
{
KEEP(*(.text.boot)) *(.text .text.*)
}

.rodata :
{
*(.rodata .rodata.*)
}

PROVIDE(_data = .);
.data : { *(.data .data.* .gnu.linkonce.d*) }
.bss (NOLOAD) : {
.data :
{
*(.data .data.*)
}

.bss (NOLOAD) :
{
. = ALIGN(16);
__bss_start = .;
*(.bss .bss.*)
*(COMMON)
__bss_end = .;
}
_end = .;

/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
}
__bss_size = (__bss_end - __bss_start)>>3;

__bss_start = ADDR(.bss);
__bss_end = ADDR(.bss) + SIZEOF(.bss);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "raspi3_glue"
name = "raspi3_boot"
version = "0.1.0"
authors = ["Andre Richter <andre.o.richter@gmail.com>"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,49 @@
* SOFTWARE.
*/

#![feature(lang_items)]
#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]
#![feature(global_asm)]

//! Low-level boot of the Raspberry's processor

extern crate cortex_a;
extern crate panic_abort;
extern crate r0;

#[lang = "start"]
extern "C" fn start<T>(user_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize
where
T: Termination,
{
user_main().report() as isize
}

#[lang = "termination"]
trait Termination {
fn report(self) -> i32;
}
#[macro_export]
macro_rules! entry {
($path:path) => {
#[export_name = "main"]
pub unsafe fn __main() -> ! {
// type check the given path
let f: fn() -> ! = $path;

impl Termination for () {
fn report(self) -> i32 {
0
}
f()
}
};
}

/// Reset function.
///
/// Initializes the bss section before calling into the user's `main()`.
#[no_mangle]
pub unsafe extern "C" fn reset() -> ! {
use core::ptr;

extern "C" {
fn main(argc: isize, argv: *const *const u8) -> isize;

// Boundaries of the .bss section
static mut __bss_start: u32;
static mut __bss_end: u32;
// Boundaries of the .bss section, provided by the linker script
static mut __bss_start: u64;
static mut __bss_end: u64;
}

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

main(0, ptr::null());
extern "Rust" {
fn main() -> !;
}

loop {}
main();
}

// Disable all cores except core 0, and then jump to reset()
Expand Down
8 changes: 0 additions & 8 deletions 02_multicore_rust/raspi3_glue/Cargo.toml

This file was deleted.

8 changes: 6 additions & 2 deletions 02_multicore_rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
*/

#![no_std]
#![no_main]

extern crate raspi3_glue;
#[macro_use]
extern crate raspi3_boot;

fn main() {
entry!(kernel_entry);

fn kernel_entry() -> ! {
loop {}
}
14 changes: 12 additions & 2 deletions 03_uart1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 03_uart1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version = "0.1.0"
authors = ["Andre Richter <andre.o.richter@gmail.com>"]

[dependencies]
raspi3_glue = { path = "raspi3_glue" }
raspi3_boot = { path = "raspi3_boot" }
register = "0.1.1"
Binary file modified 03_uart1/kernel8.img
Binary file not shown.

0 comments on commit 0bd363f

Please sign in to comment.