Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new command ldr and str to load/store to memory #121

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ members = [
"apps/task/yield",
"apps/task/priority",
"apps/task/tls",
"apps/cli",
"apps/boards/raspi4",
]


[profile.release]
lto = true

Expand Down
12 changes: 12 additions & 0 deletions apps/boards/raspi4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "arceos-raspi4"
version = "0.1.0"
edition = "2021"
authors = ["Yuekai Jia <equation618@gmail.com>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axstd = { path = "../../../ulib/axstd", optional = true }

arm_pl011 = { version = "0.1.0", path = "../../../crates/arm_pl011" }
149 changes: 149 additions & 0 deletions apps/boards/raspi4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

### 编译生成 img 文件的命令
```
make A=apps/boards/raspi4 ARCH=aarch64 PLATFORM=aarch64-raspi4 LOG=debug SMP=4 run
cat ../rust-raspberrypi-OS-tutorials/06_uart_chainloader/kernel8.img apps/boards/raspi4/raspi4_aarch64-raspi4.bin > kernel8.img
```

### 编译过程记录
```
# make A=apps/boards/raspi4 ARCH=aarch64 PLATFORM=aarch64-raspi4 LOG=debug SMP=4 run
Building App: raspi4, Arch: aarch64, Platform: aarch64-raspi4, App type: rust
cargo build --target aarch64-unknown-none-softfloat --target-dir /root/Github/Chenlong/arceos/target --release --manifest-path apps/boards/raspi4/Cargo.toml --features "axstd/log-level-debug axstd/smp"
Compiling axconfig v0.1.0 (/root/Github/Chenlong/arceos/modules/axconfig)
Compiling spinlock v0.1.0 (/root/Github/Chenlong/arceos/crates/spinlock)
Compiling axhal v0.1.0 (/root/Github/Chenlong/arceos/modules/axhal)
Compiling axlog v0.1.0 (/root/Github/Chenlong/arceos/modules/axlog)
Compiling axruntime v0.1.0 (/root/Github/Chenlong/arceos/modules/axruntime)
Compiling axfeat v0.1.0 (/root/Github/Chenlong/arceos/api/axfeat)
Compiling arceos_api v0.1.0 (/root/Github/Chenlong/arceos/api/arceos_api)
Compiling axstd v0.1.0 (/root/Github/Chenlong/arceos/ulib/axstd)
Compiling arceos-raspi4 v0.1.0 (/root/Github/Chenlong/arceos/apps/boards/raspi4)
Finished release [optimized] target(s) in 1.59s
rust-objcopy --binary-architecture=aarch64 apps/boards/raspi4/raspi4_aarch64-raspi4.elf --strip-all -O binary apps/boards/raspi4/raspi4_aarch64-raspi4.bin
Running on qemu...
emu-system-aarch64 -m 2G -smp 4 -cpu cortex-a72 -machine raspi4b2g -kernel apps/boards/raspi4/raspi4_aarch64-raspi4.bin -nographic

d8888 .d88888b. .d8888b.
d88888 d88P" "Y88b d88P Y88b
d88P888 888 888 Y88b.
d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b.
d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b.
d88P 888 888 888 88888888 888 888 "888
d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P
d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P"

arch = aarch64
platform = aarch64-raspi4
target = aarch64-unknown-none-softfloat
smp = 4
build_mode = release
log_level = debug

[ 0.013401 axruntime:126] Logging is enabled.
[ 0.017938 axruntime:127] Primary CPU 0 started, dtb = 0x100.
[ 0.020174 axruntime:129] Found physcial memory regions:
[ 0.022343 axruntime:131] [PA:0x80000, PA:0x87000) .text (READ | EXECUTE | RESERVED)
[ 0.025306 axruntime:131] [PA:0x87000, PA:0x89000) .rodata (READ | RESERVED)
[ 0.027690 axruntime:131] [PA:0x89000, PA:0x8d000) .data .tdata .tbss .percpu (READ | WRITE | RESERVED)
[ 0.029109 axruntime:131] [PA:0x8d000, PA:0x18d000) boot stack (READ | WRITE | RESERVED)
[ 0.030433 axruntime:131] [PA:0x18d000, PA:0x18e000) .bss (READ | WRITE | RESERVED)
[ 0.031586 axruntime:131] [PA:0x0, PA:0x1000) spintable (READ | WRITE | RESERVED)
[ 0.032880 axruntime:131] [PA:0x18e000, PA:0xfc000000) free memory (READ | WRITE | FREE)
[ 0.034360 axruntime:131] [PA:0xfe201000, PA:0xfe202000) mmio (READ | WRITE | DEVICE | RESERVED)
[ 0.035648 axruntime:131] [PA:0xff841000, PA:0xff849000) mmio (READ | WRITE | DEVICE | RESERVED)
[ 0.036969 axruntime:149] Initialize platform devices...
[ 0.038219 axruntime::mp:18] starting CPU 1...
[ 0.040891 axruntime::mp:35] Secondary CPU 1 started.
[ 0.045548 axruntime::mp:18] starting CPU 2...
[ 0.046443 axruntime::mp:45] Secondary CPU 1 init OK.
[ 0.055724 axruntime::mp:35] Secondary CPU 2 started.
[ 0.056580 axruntime::mp:18] starting CPU 3...
[ 0.058083 axruntime::mp:45] Secondary CPU 2 init OK.
[ 0.063700 axruntime::mp:35] Secondary CPU 3 started.
[ 0.064109 axruntime::mp:45] Secondary CPU 3 init OK.
[ 0.068492 axruntime:185] Primary CPU 0 init OK.
Hello, world!
start
??`g1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1
turn left
??d?1
forward
??d~1
2
3
4
stop
??1

```
159 changes: 159 additions & 0 deletions apps/boards/raspi4/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#![cfg_attr(feature = "axstd", no_std)]
#![cfg_attr(feature = "axstd", no_main)]

#[cfg(feature = "axstd")]
use axstd::println;
use arm_pl011::pl011::Pl011Uart;

#[cfg_attr(feature = "axstd", no_mangle)]
fn main() {
println!("Hello, world!");

fn delay(seconds: u64) {
for i in 1..seconds+1 {
println!("{} ", i);

fn fibonacci_recursive(n: u64) -> u64 {
if n == 0 {
return 0;
}
if n == 1 {
return 1;
}
return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2);
}

fibonacci_recursive(34 + (i % 2));
}
}

let uart_base = 0xffff_0000_fe20_1000 as *mut u8;
let mut uart = Pl011Uart::new(uart_base);

println!("start");
{
// 鸣笛:0xFF_FC_05_02_60_00_67
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x05);
uart.putchar(0x02);
uart.putchar(0x60);
uart.putchar(0x00);
uart.putchar(0x67);
}
delay(1);

loop {
println!("forward");
{
// 前进:0xff_fc_07_11_01_01_64_00_7e
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x07);
uart.putchar(0x11);
uart.putchar(0x01);
uart.putchar(0x01);
uart.putchar(0x64);
uart.putchar(0x00);
uart.putchar(0x7e);
}
delay(6);

println!("stop");
{
// 停止:0xff_fc_07_11_01_00_00_00_19
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x07);
uart.putchar(0x11);
uart.putchar(0x01);
uart.putchar(0x00);
uart.putchar(0x00);
uart.putchar(0x00);
uart.putchar(0x19);
}
delay(1);

println!("turn right");
{
// // 左转:0xff_fc_07_11_01_05_64_00_82
// uart.putchar(0xff);
// uart.putchar(0xfc);
// uart.putchar(0x07);
// uart.putchar(0x11);
// uart.putchar(0x01);
// uart.putchar(0x05);
// uart.putchar(0x64);
// uart.putchar(0x00);
// uart.putchar(0x82);

// 右转:0xff_fc_07_11_01_06_64_00_83
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x07);
uart.putchar(0x11);
uart.putchar(0x01);
uart.putchar(0x06);
uart.putchar(0x64);
uart.putchar(0x00);
uart.putchar(0x83);
}
delay(1);
// println!("forward");
// {
// // 前进:0xff_fc_07_11_01_01_64_00_7e
// uart.putchar(0xff);
// uart.putchar(0xfc);
// uart.putchar(0x07);
// uart.putchar(0x11);
// uart.putchar(0x01);
// uart.putchar(0x01);
// uart.putchar(0x64);
// uart.putchar(0x00);
// uart.putchar(0x7e);
// }
// delay(4);

println!("stop");
{
// 停止:0xff_fc_07_11_01_00_00_00_19
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x07);
uart.putchar(0x11);
uart.putchar(0x01);
uart.putchar(0x00);
uart.putchar(0x00);
uart.putchar(0x00);
uart.putchar(0x19);
}
delay(1);

println!("turn right");
{
// // 左转:0xff_fc_07_11_01_05_64_00_82
// uart.putchar(0xff);
// uart.putchar(0xfc);
// uart.putchar(0x07);
// uart.putchar(0x11);
// uart.putchar(0x01);
// uart.putchar(0x05);
// uart.putchar(0x64);
// uart.putchar(0x00);
// uart.putchar(0x82);

// 右转:0xff_fc_07_11_01_06_64_00_83
uart.putchar(0xff);
uart.putchar(0xfc);
uart.putchar(0x07);
uart.putchar(0x11);
uart.putchar(0x01);
uart.putchar(0x06);
uart.putchar(0x64);
uart.putchar(0x00);
uart.putchar(0x83);
}
delay(1);
}

}
19 changes: 19 additions & 0 deletions apps/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "arceos-cli"
version = "0.1.0"
edition = "2021"
authors = ["Yuekai Jia <equation618@gmail.com>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# use-ramfs = ["axstd/myfs", "dep:axfs_vfs", "dep:axfs_ramfs", "dep:crate_interface"]
default = []

[dependencies]
# axfs_vfs = { path = "../../../crates/axfs_vfs", optional = true }
# axfs_ramfs = { path = "../../../crates/axfs_ramfs", optional = true }
# crate_interface = { path = "../../../crates/crate_interface", optional = true }
# axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs"], optional = true }

axstd = { path = "../../ulib/axstd", optional = true }
Loading