Skip to content

Commit 9f6952f

Browse files
committed
test: add: integration with std
Signed-off-by: squeakbug <[email protected]>
1 parent 5cf5943 commit 9f6952f

File tree

10 files changed

+63
-26
lines changed

10 files changed

+63
-26
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# j4fos
22

33
Realtime microkernel for ALINX ZYNQ 7020 SoC (or Sipeed Gowin GW5AST devboard) projects
4+
5+
## Run on QEMU
6+
7+
```sh
8+
# Artifacts auto scanning are disabled now
9+
# So use -B key
10+
make qemu -B
11+
```

crates/fs/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![no_main]
21
#![no_std]
32

43
use core::panic::PanicInfo;

crates/kernel/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ fs.workspace = true
1515
mm.workspace = true
1616
net.workspace = true
1717
types.workspace = true
18+
19+
[features]
20+
with_std = [ "mm/with_std" ]

crates/mm/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ edition = "2021"
77
spin.workspace = true
88
bitflags.workspace = true
99
types.workspace = true
10-
dev.workspace = true
10+
dev.workspace = true
11+
12+
jemallocator = { version = "0.5.4" , optional = true }
13+
14+
[features]
15+
with_std = [ "jemallocator" ]

crates/mm/README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# Memory management
22

3-
## Page allocators
3+
## Run tests
4+
5+
```sh
6+
cargo test --package mm --features with_std
7+
```
8+
9+
## References
10+
11+
### Page allocators
412

513
https://github.com/Ko-oK-OS/buddy-allocator
614

7-
## SLAB allocators
15+
### SLAB allocators

crates/mm/src/lib.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
#![no_main]
21
#![no_std]
32

4-
pub mod page;
5-
pub mod zone;
63
pub mod layout;
4+
pub mod page;
75

8-
use layout::PHYSTOP;
6+
pub mod zone;
97
pub use zone::Zone;
108

119
pub mod locked_zone;
1210
pub use locked_zone::LockedZone;
13-
use zone::{next_aligned_by, PAGE_SIZE};
14-
15-
#[global_allocator]
16-
pub static KMEM: LockedZone = LockedZone::new();
1711

18-
unsafe extern "C" {
19-
// first address after kernel, defined by kernel.ld
20-
unsafe static mut end: [u8; 0];
21-
}
12+
#[cfg(not(feature = "with_std"))]
13+
pub mod nostdlib;
14+
#[cfg(not(feature = "with_std"))]
15+
pub use nostdlib::*;
2216

23-
pub fn init() {
24-
unsafe {
25-
KMEM.lock().add_to_heap(
26-
next_aligned_by(end.as_ptr() as usize, PAGE_SIZE),
27-
next_aligned_by(PHYSTOP, PAGE_SIZE)
28-
)
29-
}
30-
}
17+
#[cfg(feature = "with_std")]
18+
pub mod stdlib;
19+
#[cfg(feature = "with_std")]
20+
pub use stdlib::*;

crates/mm/src/nostdlib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::layout::PHYSTOP;
2+
use crate::zone::{next_aligned_by, PAGE_SIZE};
3+
use crate::locked_zone::LockedZone;
4+
5+
unsafe extern "C" {
6+
// first address after kernel, defined by kernel.ld
7+
unsafe static mut end: [u8; 0];
8+
}
9+
10+
#[global_allocator]
11+
pub static KMEM: LockedZone = LockedZone::new();
12+
13+
pub fn init() {
14+
unsafe {
15+
KMEM.lock().add_to_heap(
16+
next_aligned_by(end.as_ptr() as usize, PAGE_SIZE),
17+
next_aligned_by(PHYSTOP, PAGE_SIZE)
18+
)
19+
}
20+
}

crates/mm/src/stdlib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use jemallocator::Jemalloc;
2+
3+
#[global_allocator]
4+
static GLOBAL: Jemalloc = Jemalloc;
5+
6+
pub fn init() { }

crates/net/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![no_main]
21
#![no_std]
32

43
use core::panic::PanicInfo;

crates/types/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![no_main]
21
#![no_std]
32

43
pub mod linked_list;

0 commit comments

Comments
 (0)