Skip to content

Commit cd77dee

Browse files
authored
Try #164:
2 parents 4d27d24 + 9d9edc9 commit cd77dee

27 files changed

+137
-164
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Cargo.lock
22
layout.ld
3+
platform
34
target

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ license = "MIT/Apache-2.0"
66
edition = "2018"
77

88
[features]
9-
alloc = [ "linked_list_allocator" ]
9+
alloc = ["libtock-core/alloc"]
10+
custom_panic_handler = ["libtock-core/custom_panic_handler"]
11+
custom_alloc_error_handler = ["libtock-core/custom_alloc_error_handler"]
1012

1113
[dependencies]
1214
core = { package = "async-support", path = "async-support" }
15+
libtock-core = { path = "core" }
1316
libtock_codegen = { path = "codegen" }
14-
linked_list_allocator = { optional = true, version = "=0.6.5", default-features = false }
1517
futures = { version = "0.3.1", default-features = false, features = ["unstable", "cfg-target-has-atomic"] }
1618

1719
[dev-dependencies]
@@ -52,4 +54,5 @@ lto = true
5254
members = [
5355
"async-support",
5456
"codegen",
57+
"core"
5558
]

core/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "libtock-core"
3+
version = "0.1.0"
4+
authors = ["torfmaster <briefe@kebes.de>", "Woyten <woyten.tielesch@online.de>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[features]
10+
alloc = [ "linked_list_allocator" ]
11+
custom_panic_handler = []
12+
custom_alloc_error_handler = []
13+
14+
[dependencies]
15+
linked_list_allocator = { optional = true, version = "=0.6.5", default-features = false }

core/src/alloc.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use core::alloc::GlobalAlloc;
2+
use core::alloc::Layout;
3+
use core::ptr;
4+
use core::ptr::NonNull;
5+
use linked_list_allocator::Heap;
6+
7+
pub static mut HEAP: Heap = Heap::empty();
8+
9+
struct TockAllocator;
10+
11+
unsafe impl GlobalAlloc for TockAllocator {
12+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
13+
HEAP.allocate_first_fit(layout)
14+
.ok()
15+
.map_or(ptr::null_mut(), NonNull::as_ptr)
16+
}
17+
18+
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
19+
HEAP.deallocate(NonNull::new_unchecked(ptr), layout)
20+
}
21+
}
22+
23+
#[global_allocator]
24+
static ALLOCATOR: TockAllocator = TockAllocator;
25+
26+
#[cfg(not(feature = "custom_alloc_error_handler"))]
27+
#[alloc_error_handler]
28+
unsafe fn alloc_error_handler(_: Layout) -> ! {
29+
use crate::syscalls;
30+
31+
// Print 0x01 using the LowLevelDebug capsule (if available).
32+
let _ = syscalls::command1_insecure(8, 2, 0x01);
33+
34+
// Signal a panic using the LowLevelDebug capsule (if available).
35+
let _ = syscalls::command1_insecure(8, 1, 0x01);
36+
37+
loop {
38+
syscalls::raw::yieldk();
39+
}
40+
}
File renamed without changes.

core/src/debug/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[cfg_attr(target_arch = "arm", path = "platform_arm.rs")]
2+
#[cfg_attr(target_arch = "riscv32", path = "platform_riscv32.rs")]
3+
mod platform;
4+
5+
pub use platform::*;

core/src/debug/platform.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn get_stack_pointer() -> usize {
2+
panic!("Not implemented yet")
3+
}

core/src/debug/platform_arm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn get_stack_pointer() -> usize {
2+
let stack_pointer;
3+
unsafe { asm!("mov $0, sp" : "=r"(stack_pointer) : : : "volatile") };
4+
stack_pointer
5+
}

core/src/debug/platform_riscv32.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn get_stack_pointer() -> usize {
2+
let stack_pointer;
3+
unsafe { asm!("mv $0, sp" : "=r"(stack_pointer) : : : "volatile") };
4+
stack_pointer
5+
}

src/entry_point/mod.rs renamed to core/src/entry_point/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ use core::ptr;
5757

5858
#[cfg_attr(target_arch = "riscv32", path = "start_item_riscv32.rs")]
5959
#[cfg_attr(target_arch = "arm", path = "start_item_arm.rs")]
60-
#[cfg_attr(
61-
not(any(target_arch = "arm", target_arch = "riscv32")),
62-
path = "start_item_mock.rs"
63-
)]
6460
mod start_item;
6561

6662
/// The header encoded at the beginning of .text by the linker script. It is

0 commit comments

Comments
 (0)