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

Ch6 #4

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
30a0de2
Add env.
wyfcyx Jan 2, 2021
87a3500
Remove meaningless sstatus::set_sie() when initializing.
wyfcyx Jan 3, 2021
5730bac
Move some variable name to task_cx to task_cx_ptr2(ch5 ver).
wyfcyx Jan 4, 2021
45a17c1
rust-toochain --> nightly
chyyuu Jan 16, 2021
fad341d
Fix os/Makefile: Support macOS
wyfcyx Jan 20, 2021
77ba429
Fix k210 CLOCK_FREQ
wyfcyx Jan 26, 2021
375b787
Do not clone KERNEL_SPACE in mm::init
wyfcyx Jan 26, 2021
588ea61
Fix CLOCK_FREQ.
wyfcyx Jan 30, 2021
f4611d1
Update os/Makefile && Update rust to 2021-01-30
wyfcyx Feb 2, 2021
58897f4
Fix exit_code in user
wyfcyx Feb 6, 2021
982b369
Bump rustsbi to 0.1.1 && make config of qemu/k210 different
wyfcyx Feb 7, 2021
0ecf88a
Move kflash.py out of proj.
wyfcyx Feb 8, 2021
5e79802
Fix user_shell
wyfcyx Feb 8, 2021
f1e772a
Fix other usertests: xstate -> exit_code
wyfcyx Feb 8, 2021
fb8a24f
Replace TCB.inner.block with TCB::acquire_inner_lock
wyfcyx Feb 11, 2021
66d7723
Update app loader.
wyfcyx Feb 12, 2021
e769804
Fix alignment in os/build.rs
wyfcyx Feb 13, 2021
a15a76e
Mutex -> RefCell in Processor.
wyfcyx Feb 15, 2021
946b37a
Fix lock uses in ch5
wyfcyx Feb 16, 2021
d6056ef
Remove Any Trait of File
wyfcyx Feb 18, 2021
3a81928
Close all pipes in pipetest.
wyfcyx Feb 21, 2021
291d5b2
Fix overflow bug when ceiling va
wyfcyx Feb 23, 2021
b11082f
Add Ubuntu18.04 docker
wyfcyx Feb 27, 2021
0f6d02f
Do not fetch tools when running on qemu.
wyfcyx Mar 5, 2021
0b33985
Link small sections in linker
wyfcyx Mar 7, 2021
7132f24
Bump rustsbi to 0.2.0-alpha.1[81d53d8]
wyfcyx Mar 9, 2021
1aa2e4f
pass lab6 tests
zhaiqiming Sep 22, 2021
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ os/Cargo.lock
user/target/*
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.
37 changes: 28 additions & 9 deletions os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ 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
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
K210-BURNER = ../tools/kflash.py
K210-BURNER = ../tools/kflash.py

# Binutils
OBJDUMP := rust-objdump --arch-name=riscv64
Expand All @@ -22,14 +29,23 @@ OBJCOPY := rust-objcopy --binary-architecture=riscv64
# Disassembly
DISASM ?= -x

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

env:
(rustup target list | grep "riscv64gc-unknown-none-elf (installed)") || rustup target add $(TARGET)
cargo install cargo-binutils --vers ~0.2
rustup component add rust-src
rustup component add llvm-tools-preview

$(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 --features "board_$(BOARD)"
@rm src/linker.ld

clean:
@cargo clean
Expand All @@ -44,6 +60,8 @@ disasm-vim: kernel

run: run-inner



run-inner: build
ifeq ($(BOARD),qemu)
@qemu-system-riscv64 \
Expand All @@ -52,12 +70,13 @@ ifeq ($(BOARD),qemu)
-bios $(BOOTLOADER) \
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA)
else
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)
@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)
miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210-SERIALPORT) 115200
python3 -m serial.tools.miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210-SERIALPORT) 115200
endif

debug: build
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
6 changes: 3 additions & 3 deletions os/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn insert_app_data() -> Result<()> {
apps.sort();

writeln!(f, r#"
.align 4
.align 3
.section .data
.global _num_app
_num_app:
Expand All @@ -38,7 +38,7 @@ _num_app:
.global _app_names
_app_names:"#)?;
for app in apps.iter() {
writeln!(f, r#" .string "{}\n""#, app)?;
writeln!(f, r#" .string "{}""#, app)?;
}

for (idx, app) in apps.iter().enumerate() {
Expand All @@ -47,7 +47,7 @@ _app_names:"#)?;
.section .data
.global app_{0}_start
.global app_{0}_end
.align 12
.align 3
app_{0}_start:
.incbin "{2}{1}"
app_{0}_end:"#, idx, app, TARGET_PATH)?;
Expand Down
12 changes: 10 additions & 2 deletions os/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
pub const USER_STACK_SIZE: usize = 4096 * 2;
pub const KERNEL_STACK_SIZE: usize = 4096 * 2;
pub const KERNEL_HEAP_SIZE: usize = 0x20_0000;
pub const MAIL_BOX_SIZE: usize = 16;
pub const MAIL_BOX_MESSAGE_SIZE: usize = 256;

#[cfg(feature = "board_k210")]
pub const MEMORY_END: usize = 0x80600000;

#[cfg(feature = "board_qemu")]
pub const MEMORY_END: usize = 0x80800000;

pub const PAGE_SIZE: usize = 0x1000;
pub const PAGE_SIZE_BITS: usize = 0xc;

pub const TRAMPOLINE: usize = usize::MAX - PAGE_SIZE + 1;
pub const TRAP_CONTEXT: usize = TRAMPOLINE - PAGE_SIZE;

#[cfg(feature = "board_k210")]
pub const CPU_FREQ: usize = 10000000;
pub const CLOCK_FREQ: usize = 403000000 / 62;

#[cfg(feature = "board_qemu")]
pub const CPU_FREQ: usize = 12500000;
pub const CLOCK_FREQ: usize = 12500000;
12 changes: 1 addition & 11 deletions os/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@ mod pipe;
mod stdio;

use crate::mm::UserBuffer;
use core::any::Any;

pub trait File : Any + Send + Sync {
pub trait File : Send + Sync {
fn read(&self, buf: UserBuffer) -> usize;
fn write(&self, buf: UserBuffer) -> usize;
fn as_any_ref(&self) -> &dyn Any;
}

impl dyn File {
#[allow(unused)]
pub fn downcast_ref<T: File>(&self) -> Option<&T> {
self.as_any_ref().downcast_ref::<T>()
}
}

pub use pipe::{Pipe, make_pipe};
Expand Down
2 changes: 0 additions & 2 deletions os/src/fs/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::mm::{
UserBuffer,
};
use crate::task::suspend_current_and_run_next;
use core::any::Any;

pub struct Pipe {
readable: bool,
Expand Down Expand Up @@ -163,5 +162,4 @@ impl File for Pipe {
}
}
}
fn as_any_ref(&self) -> &dyn Any { self }
}
3 changes: 0 additions & 3 deletions os/src/fs/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::File;
use crate::mm::{UserBuffer};
use crate::sbi::console_getchar;
use crate::task::suspend_current_and_run_next;
use core::any::Any;

pub struct Stdin;

Expand All @@ -29,7 +28,6 @@ impl File for Stdin {
fn write(&self, _user_buf: UserBuffer) -> usize {
panic!("Cannot write to stdin!");
}
fn as_any_ref(&self) -> &dyn Any { self }
}

impl File for Stdout {
Expand All @@ -42,5 +40,4 @@ impl File for Stdout {
}
user_buf.len()
}
fn as_any_ref(&self) -> &dyn Any { self }
}
3 changes: 3 additions & 0 deletions os/src/linker.ld → os/src/linker-k210.ld
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ SECTIONS
srodata = .;
.rodata : {
*(.rodata .rodata.*)
*(.srodata .srodata.*)
}

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

. = ALIGN(4K);
Expand All @@ -38,6 +40,7 @@ SECTIONS
*(.bss.stack)
sbss = .;
*(.bss .bss.*)
*(.sbss .sbss.*)
}

. = ALIGN(4K);
Expand Down
53 changes: 53 additions & 0 deletions os/src/linker-qemu.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
BASE_ADDRESS = 0x80200000;

SECTIONS
{
. = BASE_ADDRESS;
skernel = .;

stext = .;
.text : {
*(.text.entry)
. = ALIGN(4K);
strampoline = .;
*(.text.trampoline);
. = ALIGN(4K);
*(.text .text.*)
}

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

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

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

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

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