Skip to content

Commit 6ae05fa

Browse files
authored
Try #164:
2 parents 4d27d24 + b2680dd commit 6ae05fa

27 files changed

+123
-162
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ license = "MIT/Apache-2.0"
66
edition = "2018"
77

88
[features]
9-
alloc = [ "linked_list_allocator" ]
9+
alloc = ["libtock-core/alloc"]
1010

1111
[dependencies]
1212
core = { package = "async-support", path = "async-support" }
13+
libtock-core = { path = "core" }
1314
libtock_codegen = { path = "codegen" }
14-
linked_list_allocator = { optional = true, version = "=0.6.5", default-features = false }
1515
futures = { version = "0.3.1", default-features = false, features = ["unstable", "cfg-target-has-atomic"] }
1616

1717
[dev-dependencies]
@@ -52,4 +52,5 @@ lto = true
5252
members = [
5353
"async-support",
5454
"codegen",
55+
"core"
5556
]

core/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
12+
[dependencies]
13+
linked_list_allocator = { optional = true, version = "=0.6.5", default-features = false }

core/src/alloc.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::syscalls;
2+
use core::alloc::GlobalAlloc;
3+
use core::alloc::Layout;
4+
use core::ptr;
5+
use core::ptr::NonNull;
6+
use linked_list_allocator::Heap;
7+
8+
pub static mut HEAP: Heap = Heap::empty();
9+
10+
struct TockAllocator;
11+
12+
unsafe impl GlobalAlloc for TockAllocator {
13+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
14+
HEAP.allocate_first_fit(layout)
15+
.ok()
16+
.map_or(ptr::null_mut(), NonNull::as_ptr)
17+
}
18+
19+
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
20+
HEAP.deallocate(NonNull::new_unchecked(ptr), layout)
21+
}
22+
}
23+
24+
#[global_allocator]
25+
static ALLOCATOR: TockAllocator = TockAllocator;
26+
27+
#[alloc_error_handler]
28+
unsafe fn alloc_error_handler(_: Layout) -> ! {
29+
loop {
30+
syscalls::raw::yieldk();
31+
}
32+
}
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)