Skip to content

Commit bd5a9b4

Browse files
committed
release: v0.14.0
1 parent 131af9c commit bd5a9b4

Some content is hidden

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

53 files changed

+1406
-768
lines changed

Cargo.lock

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

pkg/app/brk/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "ggos_brk"
3+
version = "0.0.1"
4+
edition = "2021"
5+
authors = ["GZTime <Time.GZ@outlook.com>"]
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
lib = { path="../../lib", package="gglib", default-features=false, features=["kernel_alloc"] }

pkg/app/brk/src/main.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
extern crate alloc;
5+
6+
use alloc::vec::Vec;
7+
use lib::*;
8+
9+
extern crate lib;
10+
11+
fn main() -> isize {
12+
println!("Welcome to Brk Test!");
13+
14+
pre_test();
15+
16+
loop {
17+
print!("$ ");
18+
let command = stdin().read_line();
19+
let line: Vec<&str> = command.trim().split(' ').collect();
20+
21+
match line[0] {
22+
"brk" => {
23+
if line.len() != 2 {
24+
println!("Usage: brk <addr>");
25+
continue;
26+
}
27+
28+
let addr = if line[1].starts_with("0x") {
29+
usize::from_str_radix(&line[1][2..], 16)
30+
} else {
31+
line[1].parse::<usize>()
32+
};
33+
34+
let addr = match addr {
35+
Ok(addr) => addr,
36+
Err(_) => {
37+
println!("Invalid address: {}", line[1]);
38+
continue;
39+
}
40+
};
41+
42+
match sys_brk(Some(addr)) {
43+
Some(new_brk) => {
44+
println!("Brk to {:#x} success, new brk addr: {:#x}", addr, new_brk)
45+
}
46+
None => println!("Brk to {:#x} failed", addr),
47+
}
48+
49+
sys_stat();
50+
}
51+
"cur" => match sys_brk(None) {
52+
Some(brk) => println!("Current brk addr: {:#x}", brk),
53+
None => println!("Failed to get current brk addr"),
54+
},
55+
"exit" => {
56+
break;
57+
}
58+
_ => {
59+
println!("Unknown command: {}", line[0]);
60+
}
61+
}
62+
}
63+
64+
0
65+
}
66+
67+
fn pre_test() {
68+
println!("Pre-test: Brk Test");
69+
70+
let brk = sys_brk(None);
71+
72+
let brk = match brk {
73+
Some(brk) => {
74+
println!("Current brk addr: {:#x}", brk);
75+
brk
76+
}
77+
None => {
78+
println!("Failed to get current brk addr");
79+
sys_exit(1);
80+
}
81+
};
82+
83+
let new_brk = sys_brk(Some(brk + 0x1000));
84+
85+
match new_brk {
86+
Some(new_brk) => {
87+
println!(
88+
"Brk to {:#x} success, new brk addr: {:#x}",
89+
brk + 0x1000,
90+
new_brk
91+
);
92+
sys_stat();
93+
}
94+
None => {
95+
println!("Brk to {:#x} failed", brk + 0x1000);
96+
sys_exit(1);
97+
}
98+
}
99+
100+
let new_brk = sys_brk(Some(brk));
101+
102+
match new_brk {
103+
Some(new_brk) => {
104+
println!("Brk to {:#x} success, new brk addr: {:#x}", brk, new_brk);
105+
sys_stat();
106+
}
107+
None => {
108+
println!("Brk to {:#x} failed", brk);
109+
sys_exit(1);
110+
}
111+
}
112+
113+
println!("Pre-test finished");
114+
}
115+
116+
entry!(main);

pkg/app/clock/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Dimensions for SysDisplay {
1212
}
1313
}
1414

15-
impl<'a> DrawTarget for SysDisplay {
15+
impl DrawTarget for SysDisplay {
1616
type Color = Rgb888;
1717
type Error = ();
1818

pkg/app/clock/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22
#![no_main]
33
#![allow(unreachable_code)]
4+
#![allow(clippy::diverging_sub_expression)]
45

56
use embedded_graphics::pixelcolor::Rgb888;
67
use lib::*;
@@ -39,7 +40,7 @@ fn clock() -> ! {
3940
let value = angle / 180f32 * core::f32::consts::PI;
4041

4142
let len = 24i32;
42-
let (cx, cy) = (cx as i32 - len - 10, len + 8);
43+
let (cx, cy) = (cx - len - 10, len + 8);
4344

4445
let (dx, dy) = (
4546
(len as f32 * value.cos()) as i32,

pkg/app/dining/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ggos_dining"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["GZTime <Time.GZ@outlook.com>"]
66

pkg/app/dining/src/main.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ use lib::*;
66
extern crate lib;
77

88
static CHOPSTICK: [Semaphore; 5] = semaphore_array![0, 1, 2, 3, 4];
9+
static WAITER: Semaphore = Semaphore::new(64);
910

10-
fn main() -> usize {
11+
fn main() -> isize {
1112
let mut pids = [0u16; 5];
1213

13-
for i in 0..5 {
14-
CHOPSTICK[i].init(1);
14+
// allow 4 philosophers to eat at the same time
15+
WAITER.init(4);
16+
17+
for chop in &CHOPSTICK {
18+
chop.init(1);
1519
}
1620

17-
for i in 0..5 {
21+
for (i, item) in pids.iter_mut().enumerate() {
1822
let pid = sys_fork();
1923
if pid == 0 {
2024
philosopher(i);
2125
} else {
22-
pids[i] = pid;
26+
*item = pid;
2327
}
2428
}
2529

@@ -29,33 +33,40 @@ fn main() -> usize {
2933

3034
sys_stat();
3135

32-
for i in 0..5 {
33-
println!("#{} Waiting for #{}...", cpid, pids[i]);
34-
sys_wait_pid(pids[i]);
36+
for pid in pids {
37+
println!("#{} Waiting for #{}...", cpid, pid);
38+
sys_wait_pid(pid);
3539
}
3640

3741
0
3842
}
3943

4044
fn philosopher(id: usize) -> ! {
4145
let pid = sys_get_pid();
42-
for _ in 0..20 {
43-
if id == 0 {
44-
println!("philosopher #{}({}) is sleeping...", id, pid);
45-
core::hint::spin_loop();
46-
}
47-
48-
println!("philosopher #{}({}) is thinking...", id, pid);
49-
50-
CHOPSTICK[id].acquire();
51-
CHOPSTICK[(id + 1) % 5].acquire();
5246

53-
println!("philosopher #{}({}) is eating...", id, pid);
54-
55-
CHOPSTICK[(id + 1) % 5].release();
56-
CHOPSTICK[id].release();
47+
for _ in 0..100 {
48+
// thinking
49+
println!("philosopher #{} ({}) is thinking...", id, pid);
50+
delay();
51+
52+
// hungry
53+
WAITER.wait();
54+
CHOPSTICK[id].wait();
55+
CHOPSTICK[(id + 1) % 5].wait();
56+
println!("philosopher #{} ({}) is eating...", id, pid);
57+
CHOPSTICK[(id + 1) % 5].signal();
58+
CHOPSTICK[id].signal();
59+
WAITER.signal();
5760
}
5861
sys_exit(0);
5962
}
6063

64+
#[inline(never)]
65+
#[no_mangle]
66+
fn delay() {
67+
for _ in 0..100 {
68+
core::hint::spin_loop();
69+
}
70+
}
71+
6172
entry!(main);

pkg/app/fact/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn factorial(n: u64) -> u64 {
1515
}
1616
}
1717

18-
fn main() -> usize {
18+
fn main() -> isize {
1919
print!("Input n: ");
2020

2121
let input = lib::stdin().read_line();

pkg/app/fork/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ggos_fork"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["GZTime <Time.GZ@outlook.com>"]
66

pkg/app/fork/src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,53 @@
33

44
extern crate alloc;
55
extern crate lib;
6+
67
use lib::*;
78

89
static mut M: u64 = 0xdeadbeef;
910

10-
fn main() -> usize {
11+
fn main() -> isize {
1112
let mut c = 32;
1213

1314
// do not alloc heap before `fork`
1415
// which may cause unexpected behavior since we won't copy the heap in `fork`
15-
let ret = sys_fork();
16+
let pid = sys_fork();
1617

17-
if ret == 0 {
18+
if pid == 0 {
1819
println!("I am the child process");
20+
21+
assert_eq!(c, 32);
22+
1923
unsafe {
2024
println!("child read value of M: {:#x}", M);
2125
M = 0x2333;
2226
println!("child changed the value of M: {:#x}", M);
2327
}
28+
2429
c += 32;
2530
} else {
2631
println!("I am the parent process");
2732

2833
sys_stat();
2934

35+
assert_eq!(c, 32);
36+
3037
println!("Waiting for child to exit...");
3138

32-
let ret = sys_wait_pid(ret);
39+
let ret = sys_wait_pid(pid);
3340

3441
println!("Child exited with status {}", ret);
3542

43+
assert_eq!(ret, 64);
44+
3645
unsafe {
3746
println!("parent read value of M: {:#x}", M);
47+
assert_eq!(M, 0x2333);
3848
}
3949

4050
c += 1024;
51+
52+
assert_eq!(c, 1056);
4153
}
4254

4355
c

0 commit comments

Comments
 (0)