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

Ch3 coop #2

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/*
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.idea/*
os/target/*
os/.idea/*
os/Cargo.lock
os/src/link_app.S
user/target/*
user/.idea/*
user/.idea/*
user/Cargo.lock
tools/
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:18.04
LABEL maintainer="dinghao188" \
version="1.1" \
description="ubuntu 18.04 with tools for tsinghua's rCore-Tutorial-V3"

#install some deps
RUN set -x \
&& apt-get update \
&& apt-get install -y curl wget autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
gawk build-essential bison flex texinfo gperf libtool patchutils bc xz-utils \
zlib1g-dev libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev git tmux python3

#install rust and qemu
RUN set -x; \
RUSTUP='/root/rustup.sh' \
&& cd $HOME \
#install rust
&& curl https://sh.rustup.rs -sSf > $RUSTUP && chmod +x $RUSTUP \
&& $RUSTUP -y --default-toolchain nightly --profile minimal \

#compile qemu
&& wget https://ftp.osuosl.org/pub/blfs/conglomeration/qemu/qemu-5.0.0.tar.xz \
&& tar xvJf qemu-5.0.0.tar.xz \
&& cd qemu-5.0.0 \
&& ./configure --target-list=riscv64-softmmu,riscv64-linux-user \
&& make -j$(nproc) install \
&& cd $HOME && rm -rf qemu-5.0.0 qemu-5.0.0.tar.xz

#for chinese network
RUN set -x; \
APT_CONF='/etc/apt/sources.list'; \
CARGO_CONF='/root/.cargo/config'; \
BASHRC='/root/.bashrc' \
&& echo 'export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static' >> $BASHRC \
&& echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup' >> $BASHRC \
&& touch $CARGO_CONF \
&& echo '[source.crates-io]' > $CARGO_CONF \
&& echo "replace-with = 'ustc'" >> $CARGO_CONF \
&& echo '[source.ustc]' >> $CARGO_CONF \
&& echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> $CARGO_CONF
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DOCKER_NAME ?= dinghao188/rcore-tutorial
.PHONY: docker build_docker

docker:
docker run --rm -it --mount type=bind,source=$(shell pwd),destination=/mnt ${DOCKER_NAME}

build_docker:
docker build -t ${DOCKER_NAME} .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# rCore-Tutorial-v3
rCore-Tutorial version 3.
rCore-Tutorial version 3.
Binary file modified bootloader/rustsbi-k210.bin
Binary file not shown.
Binary file modified bootloader/rustsbi-qemu.bin
Binary file not shown.
132 changes: 0 additions & 132 deletions os/Cargo.lock

This file was deleted.

29 changes: 24 additions & 5 deletions os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ TARGET := riscv64gc-unknown-none-elf
MODE := release
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
KERNEL_BIN := $(KERNEL_ELF).bin
KERNEL_ENTRY_PA := 0x80020000
DISASM_TMP := target/$(TARGET)/$(MODE)/asm

# BOARD
BOARD ?= qemu
SBI ?= rustsbi
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
K210_BOOTLOADER_SIZE := 131072

# KERNEL ENTRY
ifeq ($(BOARD), qemu)
KERNEL_ENTRY_PA := 0x80200000
else ifeq ($(BOARD), k210)
KERNEL_ENTRY_PA := 0x80020000
endif

# Run K210
K210-SERIALPORT = /dev/ttyUSB0
Expand All @@ -22,14 +29,23 @@ OBJCOPY := rust-objcopy --binary-architecture=riscv64
# Disassembly
DISASM ?= -x

build: $(KERNEL_BIN)
build: env $(KERNEL_BIN)

env:
rustup component add rust-src
rustup component add llvm-tools-preview
cargo install cargo-binutils
rustup target add riscv64gc-unknown-none-elf

$(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@

kernel:
@cd ../user && make build
@echo Platform: $(BOARD)
@cp src/linker-$(BOARD).ld src/linker.ld
@cargo build --release
@rm src/linker.ld

clean:
@cargo clean
Expand All @@ -42,7 +58,10 @@ disasm-vim: kernel
@vim $(DISASM_TMP)
@rm $(DISASM_TMP)

run: run-inner
run: tools run-inner

tools:
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)

run-inner: build
ifeq ($(BOARD),qemu)
Expand All @@ -53,7 +72,7 @@ ifeq ($(BOARD),qemu)
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA)
else
@cp $(BOOTLOADER) $(BOOTLOADER).copy
@dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=128K seek=1
@dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(K210_BOOTLOADER_SIZE) seek=1
@mv $(BOOTLOADER).copy $(KERNEL_BIN)
@sudo chmod 777 $(K210-SERIALPORT)
python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(KERNEL_BIN)
Expand All @@ -66,4 +85,4 @@ debug: build
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
tmux -2 attach-session -d

.PHONY: build kernel clean disasm disasm-vim run-inner
.PHONY: build env kernel clean disasm disasm-vim run-inner tools
21 changes: 8 additions & 13 deletions os/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::io::{Result, Write};
use std::fs::{File, read_dir};

fn main() {
println!("cargo:rerun-if-changed=../user/src/bin/");
println!("cargo:rerun-if-changed=../user/src/");
println!("cargo:rerun-if-changed={}", TARGET_PATH);
insert_app_data().unwrap();
}

static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/debug/";
static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/";

fn insert_app_data() -> Result<()> {
let mut f = File::create("src/link_app.S").unwrap();
Expand All @@ -22,21 +23,16 @@ fn insert_app_data() -> Result<()> {
apps.sort();

writeln!(f, r#"
.align 4
.align 3
.section .data
.global _num_app
_num_app:
.quad {}
"#, apps.len())?;
.quad {}"#, apps.len())?;

for i in 0..apps.len() {
writeln!(f, r#"
.quad app_{}_start
"#, i)?;
writeln!(f, r#" .quad app_{}_start"#, i)?;
}
writeln!(f, r#"
.quad app_{}_end
"#, apps.len() - 1)?;
writeln!(f, r#" .quad app_{}_end"#, apps.len() - 1)?;

for (idx, app) in apps.iter().enumerate() {
println!("app_{}: {}", idx, app);
Expand All @@ -46,8 +42,7 @@ _num_app:
.global app_{0}_end
app_{0}_start:
.incbin "{2}{1}.bin"
app_{0}_end:
"#, idx, app, TARGET_PATH)?;
app_{0}_end:"#, idx, app, TARGET_PATH)?;
}
Ok(())
}
2 changes: 1 addition & 1 deletion os/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const USER_STACK_SIZE: usize = 4096 * 2;
pub const KERNEL_STACK_SIZE: usize = 4096 * 2;
pub const MAX_APP_NUM: usize = 4;
pub const APP_BASE_ADDRESS: usize = 0x80100000;
pub const APP_BASE_ADDRESS: usize = 0x80400000;
pub const APP_SIZE_LIMIT: usize = 0x20000;
File renamed without changes.
45 changes: 45 additions & 0 deletions os/src/linker-qemu.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
BASE_ADDRESS = 0x80200000;

SECTIONS
{
. = BASE_ADDRESS;
skernel = .;

stext = .;
.text : {
*(.text.entry)
*(.text .text.*)
}

. = ALIGN(4K);
etext = .;
srodata = .;
.rodata : {
*(.rodata .rodata.*)
}

. = ALIGN(4K);
erodata = .;
sdata = .;
.data : {
*(.data .data.*)
}

. = ALIGN(4K);
edata = .;
.bss : {
*(.bss.stack)
sbss = .;
*(.bss .bss.*)
}

. = ALIGN(4K);
ebss = .;
ekernel = .;

/DISCARD/ : {
*(.eh_frame)
}
}
Loading