Merge branch 'x86-boot'

# Conflicts:
#	crate/riscv
#	kernel/Makefile
master
WangRunji 6 years ago
commit 924c061d64

@ -22,7 +22,7 @@ In fact, it's more complicated than we expected to write an OS starting from scr
### Environment
* Rust toolchain at nightly-2018-08-03
* Rust toolchain at nightly-2018-09-03
* `cargo-xbuild`
* `QEMU` >= 2.12.0
* riscv32
@ -37,6 +37,7 @@ In fact, it's more complicated than we expected to write an OS starting from scr
```bash
git clone https://github.com/wangrunji0408/RustOS.git --recursive
cd RustOS/kernel
rustup override set nightly-2018-09-03
make run arch=riscv32|x86_64
# For FPGA:
# make run arch=riscv32 board=1

@ -1 +1 @@
Subproject commit 48dffe3f9aa6404a1bfe53de6645b53401d7499e
Subproject commit 50d2008d7579e24fc4f29889b73831acdd9aa830

@ -1 +0,0 @@
PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[1;35m\]<$IMAGE_NAME>\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "

@ -1,40 +0,0 @@
FROM rustlang/rust:nightly
ENV IMAGE_NAME=blog_os-docker
RUN apt-get update && \
apt-get install -q -y --no-install-recommends \
nasm \
binutils \
grub-common \
xorriso \
grub-pc-bin && \
apt-get autoremove -q -y && \
apt-get clean -q -y && \
rm -rf /var/lib/apt/lists/* && \
cargo install xargo && \
rustup component add rust-src
ENV GOSU_VERSION 1.10
RUN set -ex; \
\
fetchDeps=' \
ca-certificates \
wget \
'; \
apt-get update; \
apt-get install -y --no-install-recommends $fetchDeps; \
rm -rf /var/lib/apt/lists/*; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
chmod +x /usr/local/bin/gosu; \
# verify that the binary works
gosu nobody true;
COPY entrypoint.sh /usr/local/bin/
COPY .bash_aliases /etc/skel/
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash"]

@ -1,18 +0,0 @@
# Building Blog OS using Docker
Inspired by [redox].
You just need `git`, `make`, and `docker`.
It is beter to use a non-privileged user to run the `docker` command, which is usually achieved by adding the user to the `docker` group.
## Run the container to build Blog OS
You can build the docker image using `make docker_build` and run it using `make docker_run`.
## Run the container interactively
You can use the `make` target `docker_interactive` to get a shell in the container.
## Clear the toolchain caches (Cargo & Rustup)
To clean the docker volumes used by the toolchain, you just need to run `make docker_clean`.
[redox]: https://github.com/redox-os/redox
## License
The source code is dual-licensed under MIT or the Apache License (Version 2.0). This excludes the `blog` directory.

@ -1,19 +0,0 @@
#!/bin/sh
USER_NAME=blogos
USER_UID=${LOCAL_UID:-9001}
USER_GID=${LOCAL_GID:-9001}
groupadd --non-unique --gid $USER_GID $USER_NAME
useradd --non-unique --create-home --uid $USER_UID --gid $USER_GID $USER_NAME
export HOME=/home/$USER_NAME
TESTFILE=$RUSTUP_HOME/settings.toml
CACHED_UID=$(stat -c "%u" $TESTFILE)
CACHED_GID=$(stat -c "%g" $TESTFILE)
if [ $CACHED_UID != $USER_UID ] || [ $USER_GID != $CACHED_GID ]; then
chown $USER_UID:$USER_GID -R $CARGO_HOME $RUSTUP_HOME
fi
exec gosu $USER_NAME "$@"

203
kernel/Cargo.lock generated

@ -1,6 +1,6 @@
[[package]]
name = "bare-metal"
version = "0.1.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -26,49 +26,88 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bootloader"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cc"
version = "1.0.18"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.2"
name = "fixedvec"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "linked_list_allocator"
version = "0.6.3"
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.4.3"
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getopts"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "multiboot2"
version = "0.7.1"
name = "libc"
version = "0.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "linked_list_allocator"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -81,18 +120,44 @@ name = "os_bootinfo"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pulldown-cmark"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "remove_dir_all"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "riscv"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -104,9 +169,18 @@ dependencies = [
"static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "skeptic"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "spin"
version = "0.4.8"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -114,12 +188,21 @@ name = "static_assertions"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tempdir"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "uart_16550"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -130,17 +213,17 @@ dependencies = [
"bbl 0.1.0",
"bit-allocator 0.1.0",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bootloader 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"multiboot2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"riscv 0.2.0",
"riscv 0.3.0",
"simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)",
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ucore-memory 0.1.0",
"ucore-process 0.1.0",
@ -157,9 +240,14 @@ version = "0.1.0"
name = "ucore-process"
version = "0.1.0"
dependencies = [
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "usize_conversions"
version = "0.2.0"
@ -170,18 +258,42 @@ name = "ux"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "version_check"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "volatile"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x86_64"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -201,26 +313,41 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eda0f54b2d49f18f3867a5e6d458299bb886db6e64c34d319d6b1aa0839ac31c"
"checksum bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1bdcf9294ed648c7cd29b11db06ea244005aeef50ae8f605b1a3af2940bf8f92"
"checksum bit-vec 0.5.0 (git+https://github.com/AltSysrq/bit-vec.git)" = "<none>"
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e"
"checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum bootloader 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f1721ced9efc102309bc218c7934d642f60567858faf8d5dd90c0cc6722d97b9"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6c16d316ccdac21a4dd648e314e76facbbaf316e83ca137d0857a9c07419d0"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "655d57c71827fe0891ce72231b6aa5e14033dae3f604609e6a6f807267c1678d"
"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2"
"checksum multiboot2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebbe89ab663a65cab341428d5fc7013b0eab5543ace92a401a86581e50fdd81"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
"checksum once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "931fb7a4cf34610cf6cbe58d52a8ca5ef4c726d4e2e178abd0dc13a6551c6d73"
"checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a"
"checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)" = "<none>"
"checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f"
"checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c"
"checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4"
"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "269f953d8de3226f7c065c589c7b4a3e83d10a419c7c3b5e2e0f197e6acc966e"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5"
"checksum ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53d8df5dd8d07fedccd202de1887d94481fadaea3db70479f459e8163a1fab41"
"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
"checksum volatile 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37c5d76c0f40ba4f8ac10ec4717d4e98ce3e58c5607eea36e9464226fc5e0a95"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "466c2002e38edde7ebbaae6656793d4f71596634971c7e8cbf7afa4827968445"
"checksum xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22678df5df766e8d1e5d609da69f0c3132d794edf6ab5e75e7abcd2270d4cf58"
"checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5"

@ -3,9 +3,6 @@ name = "ucore"
version = "0.1.0"
authors = ["Runji Wang <wangrunji0408@163.com>"]
[lib]
crate-type = ["staticlib", "rlib"]
[features]
use_apic = []
link_user_program = []
@ -21,7 +18,7 @@ debug = true
[dependencies]
log = "0.4"
spin = "0.4.8"
spin = "0.4.9"
once = "0.3.3"
xmas-elf = "0.6"
bitflags = "1.0"
@ -35,7 +32,7 @@ ucore-process = { path = "../crate/process" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
[target.'cfg(target_arch = "x86_64")'.dependencies]
multiboot2 = "0.7"
bootloader = "0.3"
x86_64 = "0.2.11"
redox_syscall = "0.1"
uart_16550 = "0.1"
@ -44,5 +41,19 @@ uart_16550 = "0.1"
riscv = { path = "../crate/riscv" }
bbl = { path = "../crate/bbl" }
[package.metadata.bootimage]
default-target = "x86_64-blog_os.json"
output = "target/x86_64-blog_os/bootimage.bin"
minimum-image-size = 0 # The minimum output file size (in MiB)
# The command invoked on `bootimage run`
# (the "{}" will be replaced with the path to the bootable disk image)
run-command = ["qemu-system-x86_64",
"-drive", "format=raw,file={}",
"-drive", "format=raw,file=../user/ucore32.img,media=disk,cache=writeback",
"-serial", "mon:stdio",
"-device", "isa-debug-exit",
"-smp", "4"
]
[build-dependencies]
cc = "1.0"

@ -18,26 +18,25 @@ arch ?= riscv32
mode ?= debug
LOG ?= debug
kernel := build/$(arch)/kernel.bin
iso := build/$(arch)/os.iso
target := $(arch)-blog_os
rust_lib := target/$(target)/$(mode)/ucore
boot_src := src/arch/$(arch)/boot
linker_script := $(boot_src)/linker.ld
grub_cfg := $(boot_src)/grub.cfg
assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/$(arch)/boot/%.o, $(assembly_source_files))
kernel := target/$(target)/$(mode)/ucore
bin := target/$(target)/$(mode)/kernel.bin
bootimage := target/$(target)/bootimage.bin
user_bin_path := ../user/target/$(arch)-ucore/debug
user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(user_bin_path)/*.d))
user_obj := build/$(arch)/user.o
SFSIMG := ../user/ucore32.img
ifeq ($(arch), x86_64)
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback -device isa-debug-exit
qemu_opts := \
-drive format=raw,file=$(bootimage) \
-drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \
-smp 4 \
-serial mon:stdio \
-device isa-debug-exit
endif
ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic
qemu_opts := -machine virt -kernel $(bin) -nographic
endif
features := use_apic
@ -61,11 +60,6 @@ ifeq ($(mode), release)
build_args := $(build_args) --release
endif
ifeq ($(arch), x86_64)
build_args := $(build_args) --lib
endif
ifeq ($(OS),Windows_NT)
uname := Win32
else
@ -84,27 +78,29 @@ objdump := $(prefix)objdump
cc := $(prefix)gcc
as := $(prefix)as
.PHONY: all clean run iso build asm doc justrun kernel
.PHONY: all clean run build asm doc justrun
all: $(kernel)
clean:
@rm -r build target
@cargo clean
doc:
@cargo rustdoc -- --document-private-items
run: $(iso) justrun
run: build justrun
justrun:
@qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11
debug: $(iso)
debug: $(bin)
@qemu-system-$(arch) $(qemu_opts) -s -S &
iso: $(iso)
build: iso
ifeq ($(arch), x86_64)
build: $(kernel)
else
build: $(bin)
endif
asm:
@$(objdump) -dS $(kernel) | less
@ -112,19 +108,10 @@ asm:
elf-h:
@$(objdump) -h $(kernel)
build/x86_64/os.iso: $(kernel) $(grub_cfg)
@mkdir -p build/isofiles/boot/grub
@cp $(kernel) build/isofiles/boot/kernel.bin
@cp $(grub_cfg) build/isofiles/boot/grub
@grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
@rm -r build/isofiles
build/riscv32/os.iso: kernel
@cp $(rust_lib) $(kernel)
$(bin): $(kernel)
ifdef board
@cp $(rust_lib) $@
@cp $(kernel) $@
else
@mkdir -p build/riscv32
@cd ../riscv-pk && \
mkdir -p build && \
cd build && \
@ -133,23 +120,17 @@ else
--enable-logo \
--disable-fp-emulation \
--host=riscv64-unknown-elf \
--with-payload=$(abspath $(rust_lib)) && \
--with-payload=$(abspath $(kernel)) && \
make && \
cp bbl ../../kernel/$@
endif
$(kernel): kernel $(assembly_object_files) $(linker_script)
@$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \
$(assembly_object_files) target/x86_64-blog_os/$(mode)/libucore.a
kernel:
@mkdir build/$(arch) -p
@CC=$(cc) cargo xbuild $(build_args)
# compile assembly files
build/x86_64/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
$(kernel):
ifeq ($(arch), x86_64)
@bootimage build $(build_args)
else
@cargo xbuild $(build_args)
endif
# make user.o from binary files
$(user_obj): $(user_bins)

@ -5,11 +5,11 @@ use std::io::{Write, Result};
fn main() {
if std::env::var("TARGET").unwrap().find("x86_64").is_some() {
cc::Build::new()
.file("src/arch/x86_64/driver/apic/lapic.c")
.file("src/arch/x86_64/driver/keyboard/keyboard.c")
.flag("-mcmodel=large")
.compile("cobj");
// cc::Build::new()
// .file("src/arch/x86_64/driver/apic/lapic.c")
// .file("src/arch/x86_64/driver/keyboard/keyboard.c")
// .flag("-mcmodel=large")
// .compile("cobj");
gen_vector_asm().unwrap();
}
}

@ -46,7 +46,6 @@ fn remap_the_kernel() {
ms.push(MemoryArea::new_identity(sdata as usize, edata as usize, MemoryAttr::default(), "data"));
ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata"));
ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss"));
ms.push(MemoryArea::new_identity(KERNEL_HEAP_OFFSET, KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MemoryAttr::default(), "kernel_heap"));
unsafe { ms.activate(); }
use core::mem::forget;
forget(ms);

@ -8,11 +8,14 @@ pub mod paging;
pub mod memory;
pub mod compiler_rt;
pub fn init() {
#[no_mangle]
pub extern fn rust_main() -> ! {
println!("Hello RISCV! {}", 123);
::logging::init();
interrupt::init();
memory::init();
timer::init();
::kmain();
}
#[cfg(feature = "no_bbl")]

@ -1,173 +0,0 @@
global start
global stack_bottom
global stack_top
extern long_mode_start
section .text
bits 32
start:
mov esp, stack_top
push ebx ; push Multiboot info pointer to stack_top
call check_multiboot
call check_cpuid
call check_long_mode
call set_up_page_tables
call enable_paging
; load the 64-bit GDT
lgdt [gdt64.pointer]
jmp gdt64.code:long_mode_start
; print `OK` to screen
mov dword [0xb8000], 0x2f4b2f4f
hlt
check_multiboot:
cmp eax, 0x36d76289
jne .no_multiboot
ret
.no_multiboot:
mov al, "0"
jmp error
check_cpuid:
; Check if CPUID is supported by attempting to flip the ID bit (bit 21)
; in the FLAGS register. If we can flip it, CPUID is available.
; Copy FLAGS in to EAX via stack
pushfd
pop eax
; Copy to ECX as well for comparing later on
mov ecx, eax
; Flip the ID bit
xor eax, 1 << 21
; Copy EAX to FLAGS via the stack
push eax
popfd
; Copy FLAGS back to EAX (with the flipped bit if CPUID is supported)
pushfd
pop eax
; Restore FLAGS from the old version stored in ECX (i.e. flipping the
; ID bit back if it was ever flipped).
push ecx
popfd
; Compare EAX and ECX. If they are equal then that means the bit
; wasn't flipped, and CPUID isn't supported.
cmp eax, ecx
je .no_cpuid
ret
.no_cpuid:
mov al, "1"
jmp error
check_long_mode:
; test if extended processor info in available
mov eax, 0x80000000 ; implicit argument for cpuid
cpuid ; get highest supported argument
cmp eax, 0x80000001 ; it needs to be at least 0x80000001
jb .no_long_mode ; if it's less, the CPU is too old for long mode
; use extended info to test if long mode is available
mov eax, 0x80000001 ; argument for extended processor info
cpuid ; returns various feature bits in ecx and edx
test edx, 1 << 29 ; test if the LM-bit is set in the D-register
jz .no_long_mode ; If it's not set, there is no long mode
ret
.no_long_mode:
mov al, "2"
jmp error
set_up_page_tables:
; map P4 table recursively
mov eax, p4_table
or eax, 0b11 ; present + writable
mov [p4_table + 511 * 8], eax
; map first & 510th P4 entry to P3 table
mov eax, p3_table
or eax, 0b11 ; present + writable
mov [p4_table], eax
mov [p4_table + 510 * 8], eax
; map first P3 entry to P2 table
mov eax, p2_table
or eax, 0b11 ; present + writable
mov [p3_table], eax
; map each P2 entry to a huge 2MiB page
mov ecx, 0 ; counter variable
.map_p2_table:
; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx
mov eax, 0x200000 ; 2MiB
mul ecx ; start address of ecx-th page
or eax, 0b10000011 ; present + writable + huge
mov [p2_table + ecx * 8], eax ; map ecx-th entry
inc ecx ; increase counter
cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped
jne .map_p2_table ; else map the next entry
ret
enable_paging:
; load P4 to cr3 register (cpu uses this to access the P4 table)
mov eax, p4_table
mov cr3, eax
; enable PAE-flag in cr4 (Physical Address Extension)
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; set the long mode bit & no execute bit in the EFER MSR (model specific register)
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8 | 1 << 11
wrmsr
; enable paging & write protect in the cr0 register
mov eax, cr0
or eax, 1 << 31 | 1 << 16
mov cr0, eax
ret
; Prints `ERR: ` and the given error code to screen and hangs.
; parameter: error code (in ascii) in al
error:
mov dword [0xb8000], 0x4f524f45
mov dword [0xb8004], 0x4f3a4f52
mov dword [0xb8008], 0x4f204f20
mov byte [0xb800a], al
hlt
section .bss
align 4096
p4_table:
resb 4096
p3_table:
resb 4096
p2_table:
resb 4096
stack_bottom:
resb 4096 * 8
stack_top:
section .rodata
gdt64:
dq 0 ; zero entry
.code: equ $ - gdt64 ; new
dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment
.pointer:
dw $ - gdt64 - 1
dq gdt64

@ -1,141 +0,0 @@
; xv6 x86_64 entryother.S
; Each non-boot CPU ("AP") is started up in response to a STARTUP
; IPI from the boot CPU. Section B.4.2 of the Multi-Processor
; Specification says that the AP will start in real mode with CS:IP
; set to XY00:0000, where XY is an 8-bit value sent with the
; STARTUP. Thus this code must start at a 4096-byte boundary.
;
; Because this code sets DS to zero, it must sit
; at an address in the low 2^16 bytes.
;
; Startothers (in main.c) sends the STARTUPs one at a time.
; It copies this code (start) at 0x7000. It puts the address of
; a newly allocated per-core stack in start-4,the address of the
; place to jump to (mpenter) in start-8, and the physical address
; of entrypgdir in start-12.
;
; This code is identical to bootasm.S except:
; - it does not need to enable A20
; - it uses the address at start-4, start-8, and start-12
%define CR0_PE 1
%define STA_X 0x8 ; Executable segment
%define STA_E 0x4 ; Expand down (non-executable segments)
%define STA_C 0x4 ; Conforming code segment (executable only)
%define STA_W 0x2 ; Writeable (non-executable segments)
%define STA_R 0x2 ; Readable (executable segments)
%define STA_A 0x1 ; Accessed
extern other_main
section .text
bits 16
start:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
lgdt [gdt.desc]
mov eax, cr0
or eax, CR0_PE
mov cr0, eax
jmp gdt.code: start32
bits 32
start32:
mov ax, gdt.data
mov ds, ax
mov es, ax
mov ss, ax
mov ax, 0
mov fs, ax
mov gs, ax
; Switch to the stack allocated by startothers()
mov esp, [top - 4]
call enable_paging
; load the 64-bit GDT
lgdt [gdt64.pointer]
jmp gdt64.code: start64
error:
mov ax, 0x8a00
mov dx, ax
out dx, ax
mov ax, 0x8ae0
out dx, ax
spin:
jmp spin
enable_paging:
; load P4 to cr3 register (cpu uses this to access the P4 table)
mov eax, [top - 8]
mov cr3, eax
; enable PAE-flag in cr4 (Physical Address Extension)
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; set the long mode bit & no execute bit in the EFER MSR (model specific register)
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8 | 1 << 11
wrmsr
; enable paging & write protect in the cr0 register
mov eax, cr0
or eax, 1 << 31 | 1 << 16
mov cr0, eax
ret
bits 64
start64:
; load 0 into all data segment registers
mov ax, 0
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; obtain kstack from data block before entryother
mov rsp, [top - 16]
mov rax, other_main
call rax
; section .rodata
align 4
gdt:
; NULL
dw 0, 0
db 0, 0, 0, 0
.code: equ $ - gdt
dw 0xffff, 0
db 0, (0x90 | STA_X | STA_R), 0xcf, 0
.data: equ $ - gdt
dw 0xffff, 0
db 0, (0x90 | STA_W), 0xcf, 0
.desc:
dw $ - gdt - 1
dq gdt
gdt64:
dq 0 ; zero entry
.code: equ $ - gdt64 ; new
dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment
.pointer:
dw $ - gdt64 - 1
dq gdt64
top: equ start + 0x1000

@ -1,7 +0,0 @@
set timeout=0
set default=0
menuentry "my os" {
multiboot2 /boot/kernel.bin
boot
}

@ -1,104 +0,0 @@
ENTRY(start)
OTHER_OFFSET = 0x7000;
BOOT_OFFSET = 0x100000;
KERNEL_OFFSET = 0xffffff0000000000;
SECTIONS {
/* ensure that the multiboot header is at the beginning */
.multiboot_header :
{
KEEP(*(.multiboot_header))
}
/* bootloader for other processors */
. = OTHER_OFFSET;
.text.other : AT(OTHER_OFFSET)
{
KEEP(*/entryother.o (.text))
. = ALIGN(4K);
}
/* bootloader for first processor */
. = BOOT_OFFSET;
.rodata.32 :
{
*/boot.o (.rodata)
. = ALIGN(4K);
}
.text.32 :
{
*/boot.o (.text)
*/long_mode_init.o (.text)
. = ALIGN(4K);
}
.bss.32 :
{
*/boot.o (.bss)
. = ALIGN(4K);
}
/* kernel */
. += KERNEL_OFFSET;
.user ALIGN(4K): AT(ADDR(.user) - KERNEL_OFFSET)
{
KEEP(user/*.o (.data))
. = ALIGN(4K);
}
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
{
*(.rodata .rodata.*)
. = ALIGN(4K);
}
.text : AT(ADDR(.text) - KERNEL_OFFSET)
{
*(.text .text.*)
. = ALIGN(4K);
}
.data : AT(ADDR(.data) - KERNEL_OFFSET)
{
*(.data .data.*)
. = ALIGN(4K);
}
.bss ALIGN(4K): AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(.bss .bss.*)
. = ALIGN(4K);
}
.got ALIGN(4K): AT(ADDR(.got) - KERNEL_OFFSET)
{
*(.got)
. = ALIGN(4K);
}
.got.plt : AT(ADDR(.got.plt) - KERNEL_OFFSET)
{
*(.got.plt)
. = ALIGN(4K);
}
.data.rel.ro : AT(ADDR(.data.rel.ro) - KERNEL_OFFSET)
{
*(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*)
. = ALIGN(4K);
}
.gcc_except_table : AT(ADDR(.gcc_except_table) - KERNEL_OFFSET)
{
*(.gcc_except_table)
. = ALIGN(4K);
}
}

@ -1,29 +0,0 @@
global long_mode_start
extern rust_main
KERNEL_OFFSET equ 0xffff_ff00_0000_0000
section .text
bits 64
long_mode_start:
; load 0 into all data segment registers
mov ax, 0
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; translate rsp to virtual address
mov rax, KERNEL_OFFSET
add rsp, rax
; call the rust main
extern rust_main
mov rax, rust_main
call rax
; print `OKAY` to screen
mov rax, 0x2f592f412f4b2f4f
mov qword [0xb8000], rax
hlt

@ -1,15 +0,0 @@
section .multiboot_header
header_start:
dd 0xe85250d6 ; magic number (multiboot 2)
dd 0 ; architecture 0 (protected mode i386)
dd header_end - header_start ; header length
; checksum
dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))
; insert optional multiboot tags here
; required end tag
dw 0 ; type
dw 0 ; flags
dd 8 ; size
header_end:

@ -1,61 +0,0 @@
// Migrate from xv6-x86_64 acpi.c
mod structs;
use self::structs::*;
use consts::*;
pub fn init(rsdt_addr: usize) -> Result<AcpiResult, AcpiError> {
let rsdt = unsafe { &*(rsdt_addr as *const Rsdt) };
let mut madt: Option<&'static Madt> = None;
for i in 0 .. rsdt.entry_count() {
let entry = rsdt.entry_at(i);
let header = unsafe{ &*(entry as *const Header) };
trace!("{:?}", header);
if &header.signature == b"APIC" {
madt = Some(unsafe{ &*(entry as *const Madt) });
}
}
trace!("{:?}", madt);
config_smp(madt.expect("acpi: madt not found."))
}
#[derive(Debug)]
pub struct AcpiResult {
pub cpu_num: u8,
pub cpu_acpi_ids: [u8; MAX_CPU_NUM],
pub ioapic_id: u8,
pub lapic_addr: *const (),
}
#[derive(Debug)]
pub enum AcpiError {
NotMapped,
IoacpiNotFound,
}
fn config_smp(madt: &'static Madt) -> Result<AcpiResult, AcpiError> {
let lapic_addr = madt.lapic_address as *const ();
let mut cpu_num = 0u8;
let mut cpu_acpi_ids: [u8; MAX_CPU_NUM] = [0; MAX_CPU_NUM];
let mut ioapic_id: Option<u8> = None;
for entry in madt.entry_iter() {
trace!("{:?}", entry);
match &entry {
&MadtEntry::LocalApic(ref lapic) => {
cpu_acpi_ids[cpu_num as usize] = lapic.id;
cpu_num += 1;
},
&MadtEntry::IoApic(ref ioapic) => {
ioapic_id = Some(ioapic.id);
},
_ => {},
}
}
if ioapic_id.is_none() {
return Err(AcpiError::IoacpiNotFound);
}
let ioapic_id = ioapic_id.unwrap();
Ok(AcpiResult { cpu_num, cpu_acpi_ids, ioapic_id, lapic_addr })
}

@ -1,141 +0,0 @@
// Reference: xv6-x86_64 acpi.h
// Copy from crate 'acpica-sys'
use util::{Checkable, bytes_sum};
use core::mem::size_of;
#[repr(C)]
#[derive(Debug)]
pub struct Rsdp {
pub signature: [u8; 8],
pub checksum: u8,
pub oem_id: [i8; 6],
pub revision: u8,
pub rsdt_physical_address: u32,
pub length: u32,
pub xsdt_physical_address: u64,
pub extended_checksum: u8,
pub reserved: [u8; 3],
}
impl Checkable for Rsdp {
fn check(&self) -> bool {
&self.signature == b"RSD PTR " && bytes_sum(self) == 0
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Header {
pub signature: [u8; 4],
pub length: u32,
pub revision: u8,
pub checksum: u8,
pub oem_id: [i8; 6],
pub oem_table_id: [i8; 8],
pub oem_revision: u32,
pub asl_compiler_id: [i8; 4],
pub asl_compiler_revision: u32,
}
#[repr(C)]
#[derive(Debug)]
pub struct Rsdt {
pub header: Header,
table_offset_entry: [u32; 0],
}
impl Rsdt {
pub fn entry_count(&self) -> usize {
(self.header.length as usize - size_of::<Self>()) / 4
}
pub fn entry_at(&self, id: usize) -> u32 {
assert!(id < self.entry_count());
unsafe {
let p = (self as *const Self).offset(1) as *const u32;
*(p.offset(id as isize))
}
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Madt {
pub header: Header,
pub lapic_address: u32,
pub flags: u32,
table: [u32; 0],
}
impl Checkable for Madt {
fn check(&self) -> bool {
&self.header.signature == b"APIC" && self.header.length >= size_of::<Self>() as u32
}
}
#[derive(Debug)]
pub enum MadtEntry {
Unknown(MadtEntryUnknown),
LocalApic(MadtEntryLocalApic),
IoApic(MadtEntryIoApic),
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct MadtEntryUnknown {
pub type_: u8,
pub length: u8,
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct MadtEntryLocalApic {
pub type_: u8, // 0
pub length: u8,
pub processor_id: u8,
pub id: u8,
pub lapic_flags: u32,
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct MadtEntryIoApic {
pub type_: u8, // 1
pub length: u8,
pub id: u8,
pub reserved: u8,
pub address: u32,
pub global_irq_base: u32,
}
#[derive(Debug)]
pub struct MadtEntryIter<'a> {
madt: &'a Madt,
ptr: *const u8,
end_ptr: *const u8,
}
impl Madt {
pub fn entry_iter(&self) -> MadtEntryIter {
let ptr = unsafe{ (self as *const Self).offset(1) } as *const u8;
let end_ptr = unsafe{ ptr.offset(self.header.length as isize) };
MadtEntryIter { madt: self, ptr, end_ptr }
}
}
impl<'a> Iterator for MadtEntryIter<'a> {
type Item = MadtEntry;
fn next(&mut self) -> Option<Self::Item> {
if self.ptr >= self.end_ptr {
return None;
}
unsafe {
let type_id = *self.ptr.offset(0);
let len = *self.ptr.offset(1);
let ret = Some(match type_id {
0 => MadtEntry::LocalApic( (&*(self.ptr as *const MadtEntryLocalApic)).clone() ),
1 => MadtEntry::IoApic( (&*(self.ptr as *const MadtEntryIoApic)).clone() ),
_ => MadtEntry::Unknown( (&*(self.ptr as *const MadtEntryUnknown)).clone() ),
});
self.ptr = self.ptr.offset(len as isize);
ret
}
}
}

@ -9,10 +9,9 @@ use bit_field::BitField;
use arch::interrupt::consts::T_IRQ0;
use spin::Mutex;
pub fn init(ioapic_id: u8)
pub fn init()
{
let mut ioapic = IOAPIC.lock();
assert_eq!(ioapic.id(), ioapic_id, "ioapic.init: id isn't equal to ioapicid; not a MP");
// Mark all interrupts edge-triggered, active high, disabled,
// and not routed to any CPUs.

@ -6,40 +6,41 @@ extern {
fn lapicstartap(apicid: u8, addr: u32);
}
pub fn set_addr(lapic_addr: *const ()) {
pub fn set_addr(lapic_addr: usize) {
unsafe {
lapic = lapic_addr;
// lapic = lapic_addr;
}
}
pub fn init() {
warn!("lapic::init use C lib");
unsafe {
lapicinit();
// lapicinit();
}
info!("lapic: init end");
}
pub fn ack(_irq: u8) {
unsafe {
lapiceoi();
// lapiceoi();
}
}
pub fn start_ap(apicid: u8, addr: u32) {
warn!("lapic::start_ap use C lib");
unsafe {
lapicstartap(apicid, addr);
// lapicstartap(apicid, addr);
}
}
pub fn lapic_id() -> u8 {
unsafe{
if lapic.is_null() {
warn!("lapic is null. return lapic id = 0");
return 0;
}
let ptr = (lapic as *const u32).offset(0x0020 / 4);
(ptr.read_volatile() >> 24) as u8
}
0
// unsafe{
// if lapic.is_null() {
// warn!("lapic is null. return lapic id = 0");
// return 0;
// }
// let ptr = (lapic as *const u32).offset(0x0020 / 4);
// (ptr.read_volatile() >> 24) as u8
// }
}

@ -4,11 +4,12 @@ pub use self::lapic::{ack, start_ap, lapic_id};
mod lapic;
mod ioapic;
pub fn init(lapic_addr: *const (), ioapic_id: u8) {
pub fn init() {
assert_has_not_been_called!("apic::init must be called only once");
self::lapic::set_addr(lapic_addr);
use consts::KERNEL_OFFSET;
self::lapic::set_addr(KERNEL_OFFSET + 0xfee00000);
self::lapic::init();
self::ioapic::init(ioapic_id);
self::ioapic::init();
}
pub fn other_init() {

@ -6,6 +6,7 @@ use spin::Mutex;
lazy_static! {
pub static ref DISK0: LockedIde = LockedIde(Mutex::new(DmaController::new(0)));
pub static ref DISK1: LockedIde = LockedIde(Mutex::new(DmaController::new(1)));
}
pub const BLOCK_SIZE: usize = 512;

@ -7,7 +7,7 @@ pub fn init() {
}
pub fn get() -> i32 {
unsafe{ kbdgetc() }
0
}
extern {

@ -1,31 +1,23 @@
extern crate syscall as redox_syscall;
pub mod vga;
pub mod acpi;
pub mod apic;
pub mod mp;
pub mod serial;
pub mod pic;
pub mod keyboard;
pub mod pit;
pub mod ide;
pub fn init(rsdt_addr: usize) -> acpi::AcpiResult {
pub fn init() {
assert_has_not_been_called!();
let acpi = acpi::init(rsdt_addr).expect("Failed to init ACPI");
assert_eq!(acpi.lapic_addr as usize, 0xfee00000);
trace!("acpi = {:?}", acpi);
if cfg!(feature = "use_apic") {
pic::disable();
use consts::KERNEL_OFFSET;
apic::init((KERNEL_OFFSET + 0xfee00000) as *const (), acpi.ioapic_id);
apic::init();
} else {
pic::init();
}
pit::init();
serial::init();
keyboard::init();
acpi
}

@ -1,113 +0,0 @@
// Migrate from xv6 mp.c
// Multiprocessor support
// Search memory for MP description structures.
// http://developer.intel.com/design/pentium/datashts/24201606.pdf
mod structs;
use self::structs::*;
/// Search for the MP Floating Pointer Structure, which according to the
/// spec is in one of the following three locations:
/// 1) in the first KB of the EBDA;
/// 2) in the last KB of system base memory;
/// 3) in the BIOS ROM address space between 0F0000h and 0FFFFFh.
pub fn find_mp() -> Option<*const MP>
{
use core::mem::size_of;
use util::find_in_memory;
let ebda = unsafe { *(0x40E as *const u16) as usize } << 4;
if ebda != 0 {
let res = unsafe{ find_in_memory::<MP>(ebda, 1024, size_of::<MP>()) };
if let Some(addr) = res {
return Some(addr as *const MP);
}
}
let p = unsafe { *(0x413 as *const u16) as usize } << 10;
let res = unsafe{ find_in_memory::<MP>(p-1024, 1024, size_of::<MP>()) };
if let Some(addr) = res {
return Some(addr as *const MP);
}
let res = unsafe{ find_in_memory::<MP>(0xF0000, 0x10000, size_of::<MP>()) };
res.map(|addr| addr as *const MP)
}
/*
struct cpu cpus[NCPU];
int ncpu;
uchar ioapicid;
// Search for an MP configuration table. For now,
// don't accept the default configurations (physaddr == 0).
// Check for correct signature, calculate the checksum and,
// if correct, check the version.
// To do: check extended table checksum.
static struct mpconf*
mpconfig(struct mp **pmp)
{
struct mpconf *conf;
struct mp *mp;
if((mp = mpsearch()) == 0 || mp->physaddr == 0)
return 0;
conf = (struct mpconf*) P2V((uint) mp->physaddr);
if(memcmp(conf, "PCMP", 4) != 0)
return 0;
if(conf->version != 1 && conf->version != 4)
return 0;
if(sum((uchar*)conf, conf->length) != 0)
return 0;
*pmp = mp;
return conf;
}
void
mpinit(void)
{
uchar *p, *e;
int ismp;
struct mp *mp;
struct mpconf *conf;
struct mpproc *proc;
struct mpioapic *ioapic;
if((conf = mpconfig(&mp)) == 0)
panic("Expect to run on an SMP");
ismp = 1;
lapic = (uint*)conf->lapicaddr;
for(p=(uchar*)(conf+1), e=(uchar*)conf+conf->length; p<e; ){
switch(*p){
case MPPROC:
proc = (struct mpproc*)p;
if(ncpu < NCPU) {
cpus[ncpu].apicid = proc->apicid; // apicid may differ from ncpu
ncpu++;
}
p += sizeof(struct mpproc);
continue;
case MPIOAPIC:
ioapic = (struct mpioapic*)p;
ioapicid = ioapic->apicno;
p += sizeof(struct mpioapic);
continue;
case MPBUS:
case MPIOINTR:
case MPLINTR:
p += 8;
continue;
default:
ismp = 0;
break;
}
}
if(!ismp)
panic("Didn't find a suitable machine");
if(mp->imcrp){
// Bochs doesn't support IMCR, so this doesn't run on Bochs.
// But it would on real hardware.
outb(0x22, 0x70); // Select IMCR
outb(0x23, inb(0x23) | 1); // Mask external interrupts.
}
}
*/

@ -1,74 +0,0 @@
// Migrate from xv6 mp.h
// See MultiProcessor Specification Version 1.[14]
use util::{Checkable, bytes_sum};
#[repr(C)]
#[derive(Debug)]
pub struct MP { // floating pointer
signature: [u8; 4], // "_MP_"
physaddr: u32, // phys addr of MP config table
length: u8, // 1
specrev: u8, // [14]
checksum: u8, // all bytes must add up to 0
type_: u8, // MP system config type
imcrp: u8,
reserved: [u8; 3],
}
impl Checkable for MP {
fn check(&self) -> bool {
&self.signature == b"_MP_" && bytes_sum(self) == 0
}
}
/*
#[repr(C)]
struct mpconf { // configuration table header
signature: [byte; 4]; // "PCMP"
length: u16, // total table length
version: u8, // [14]
checksum: u8, // all bytes must add up to 0
product: [u8; 20], // product id
uint *oemtable, // OEM table pointer
ushort oemlength, // OEM table length
ushort entry, // entry count
uint *lapicaddr, // address of local APIC
ushort xlength, // extended table length
u8 xchecksum, // extended table checksum
u8 reserved,
}
#[repr(C)]
struct mpproc { // processor table entry
u8 type; // entry type (0)
u8 apicid; // local APIC id
u8 version; // local APIC verison
u8 flags; // CPU flags
#define MPBOOT 0x02 // This proc is the bootstrap processor.
u8 signature[4]; // CPU signature
uint feature; // feature flags from CPUID instruction
u8 reserved[8];
}
struct mpioapic { // I/O APIC table entry
u8 type; // entry type (2)
u8 apicno; // I/O APIC id
u8 version; // I/O APIC version
u8 flags; // I/O APIC flags
uint *addr; // I/O APIC address
}
// Table entry types
const MPPROC : u8 = 0x00; // One per processor
const MPBUS : u8 = 0x01; // One per bus
const MPIOAPIC : u8 = 0x02; // One per I/O APIC
const MPIOINTR : u8 = 0x03; // One per bus interrupt source
const MPLINTR : u8 = 0x04; // One per system interrupt source
//PAGEBREAK!
// Blank page.
*/

@ -85,7 +85,8 @@ pub extern fn rust_trap(tf: &mut TrapFrame) {
IRQ_KBD => keyboard(),
IRQ_COM1 => com1(),
IRQ_COM2 => com2(),
_ => panic!("Invalid IRQ number."),
IRQ_IDE => ide(),
_ => panic!("Invalid IRQ number: {}", irq),
}
#[cfg(feature = "use_apic")]
use arch::driver::apic::ack;
@ -143,6 +144,10 @@ fn com2() {
COM2.lock().receive();
}
fn ide() {
trace!("\nInterupt: IDE");
}
fn to_user(tf: &mut TrapFrame) {
use arch::gdt;
info!("\nInterupt: To User");

@ -0,0 +1,33 @@
ENTRY(_start)
KERNEL_BEGIN = 0xffffff0000000000;
SECTIONS {
. = KERNEL_BEGIN;
.rodata ALIGN(4K):
{
*(.rodata .rodata.*)
}
.text ALIGN(4K):
{
*(.text .text.*)
}
.data ALIGN(4K):
{
*(.data .data.*)
}
.got ALIGN(4K):
{
*(.got .got.*)
}
.bss ALIGN(4K):
{
*(.bss .bss.*)
}
}

@ -1,112 +1,24 @@
use bit_allocator::{BitAlloc, BitAlloc64K};
use bit_allocator::BitAlloc;
use consts::KERNEL_OFFSET;
// Depends on kernel
use memory::{active_table, FRAME_ALLOCATOR, init_heap, MemoryArea, MemoryAttr, MemorySet, Stack};
use super::multiboot2::{ElfSection, ElfSectionFlags, ElfSectionsTag};
use super::multiboot2::BootInformation;
use memory::{FRAME_ALLOCATOR, init_heap};
use super::{BootInfo, MemoryRegionType};
use ucore_memory::PAGE_SIZE;
use ucore_memory::paging::PageTable;
// BootInformation may trigger page fault after kernel remap
// So just take its ownership
pub fn init(boot_info: BootInformation) {
pub fn init(boot_info: &BootInfo) {
assert_has_not_been_called!("memory::init must be called only once");
info!("{:?}", boot_info);
init_frame_allocator(&boot_info);
remap_the_kernel(&boot_info);
init_frame_allocator(boot_info);
init_heap();
info!("memory: init end");
}
fn init_frame_allocator(boot_info: &BootInformation) {
let memory_areas = boot_info.memory_map_tag().expect("Memory map tag required")
.memory_areas();
let elf_sections = boot_info.elf_sections_tag().expect("Elf sections tag required")
.sections().filter(|s| s.is_allocated());
/// Init FrameAllocator and insert all 'Usable' regions from BootInfo.
fn init_frame_allocator(boot_info: &BootInfo) {
let mut ba = FRAME_ALLOCATOR.lock();
for area in memory_areas {
ba.insert(to_range(area.start_address() as usize, area.end_address() as usize));
}
for section in elf_sections {
ba.remove(to_range(section.start_address() as usize, section.end_address() as usize));
}
ba.remove(to_range(boot_info.start_address(), boot_info.end_address()));
use core::ops::Range;
fn to_range(mut start_addr: usize, mut end_addr: usize) -> Range<usize> {
use consts::KERNEL_OFFSET;
if start_addr >= KERNEL_OFFSET {
start_addr -= KERNEL_OFFSET;
}
if end_addr >= KERNEL_OFFSET {
end_addr -= KERNEL_OFFSET;
for region in boot_info.memory_map.iter() {
if region.region_type == MemoryRegionType::Usable {
ba.insert(region.range.start_frame_number as usize..region.range.end_frame_number as usize);
}
let page_start = start_addr / PAGE_SIZE;
let mut page_end = (end_addr - 1) / PAGE_SIZE + 1;
if page_end >= BitAlloc64K::CAP {
warn!("page num {:#x} out of range {:#x}", page_end, BitAlloc64K::CAP);
page_end = BitAlloc64K::CAP;
}
page_start..page_end
}
}
fn remap_the_kernel(boot_info: &BootInformation) {
extern { fn stack_bottom(); }
extern { fn stack_top(); }
let kstack = Stack {
top: stack_top as usize + KERNEL_OFFSET,
bottom: stack_bottom as usize + PAGE_SIZE + KERNEL_OFFSET,
};
let mut memory_set = memory_set_from(boot_info.elf_sections_tag().unwrap(), kstack);
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
use super::smp::ENTRYOTHER_ADDR;
memory_set.push(MemoryArea::new_physical(0xb8000, 0xb9000, KERNEL_OFFSET, MemoryAttr::default(), "VGA"));
memory_set.push(MemoryArea::new_physical(0xfee00000, 0xfee01000, KERNEL_OFFSET, MemoryAttr::default(), "LAPIC"));
memory_set.push(MemoryArea::new_identity(0x07fe1000, 0x07fe1000 + PAGE_SIZE, MemoryAttr::default(), "RSDT"));
memory_set.push(MemoryArea::new_identity(0xfec00000, 0xfec00000 + PAGE_SIZE, MemoryAttr::default(), "IOAPIC"));
memory_set.push(MemoryArea::new(KERNEL_HEAP_OFFSET, KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MemoryAttr::default(), "kernel_heap"));
memory_set.push(MemoryArea::new_identity(ENTRYOTHER_ADDR, ENTRYOTHER_ADDR + PAGE_SIZE, MemoryAttr::default().execute(), "entry_other.text"));
memory_set.push(MemoryArea::new_physical(0, 4096, KERNEL_OFFSET, MemoryAttr::default(), "entry_other.ctrl"));
debug!("{:#x?}", memory_set);
unsafe { memory_set.activate(); }
info!("NEW TABLE!!!");
use core::mem::forget;
forget(memory_set);
}
fn memory_set_from(sections: ElfSectionsTag, kstack: Stack) -> MemorySet {
assert_has_not_been_called!();
// WARNING: must ensure it's large enough
static mut SPACE: [u8; 0x1000] = [0; 0x1000];
let mut set = unsafe { MemorySet::new_from_raw_space(&mut SPACE, kstack) };
for section in sections.sections().filter(|s| s.is_allocated()) {
set.push(memory_area_from(section));
}
set
}
fn memory_area_from(section: ElfSection) -> MemoryArea {
let mut start_addr = section.start_address() as usize;
let mut end_addr = section.end_address() as usize;
assert_eq!(start_addr % PAGE_SIZE, 0, "sections need to be page aligned");
let name = unsafe { &*(section.name() as *const str) };
if start_addr >= KERNEL_OFFSET {
start_addr -= KERNEL_OFFSET;
end_addr -= KERNEL_OFFSET;
}
MemoryArea::new_physical(start_addr, end_addr, KERNEL_OFFSET, memory_attr_from(section.flags()), name)
}
fn memory_attr_from(elf_flags: ElfSectionFlags) -> MemoryAttr {
let mut flags = MemoryAttr::default();
if !elf_flags.contains(ElfSectionFlags::ALLOCATED) { flags = flags.hide(); }
if !elf_flags.contains(ElfSectionFlags::WRITABLE) { flags = flags.readonly(); }
if elf_flags.contains(ElfSectionFlags::EXECUTABLE) { flags = flags.execute(); }
flags
}

@ -1,6 +1,6 @@
extern crate multiboot2;
extern crate bootloader;
use memory::MemorySet;
use self::bootloader::bootinfo::{BootInfo, MemoryRegionType};
pub mod driver;
pub mod cpu;
@ -8,25 +8,31 @@ pub mod interrupt;
pub mod paging;
pub mod gdt;
pub mod idt;
pub mod smp;
// TODO: Move multi-core init to bootloader
//pub mod smp;
pub mod memory;
pub mod io;
pub fn init() {
/// The entry point of kernel
#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
// First init log mod, so that we can print log info.
::logging::init();
info!("Hello world!");
info!("{:#?}", boot_info);
// Init trap handling.
idt::init();
// Load boot info address from stack_top.
// See `boot.asm`
extern {
fn stack_top();
}
let boot_info_addr = unsafe { *(stack_top as *const u32).offset(-1) } as usize;
let boot_info = unsafe { multiboot2::load(boot_info_addr) };
let rsdt_addr = boot_info.rsdp_v1_tag().unwrap().rsdt_address();
// Init physical memory management and heap.
memory::init(boot_info);
// Now heap is available
gdt::init();
let acpi = driver::init(rsdt_addr);
smp::start_other_cores(&acpi);
driver::init();
::kmain();
}
/// The entry point for another processors
@ -36,7 +42,7 @@ pub extern "C" fn other_main() -> ! {
gdt::init();
driver::apic::other_init();
let cpu_id = driver::apic::lapic_id();
let ms = unsafe { smp::notify_started(cpu_id) };
// let ms = unsafe { smp::notify_started(cpu_id) };
println!("Hello world! from CPU {}!", cpu_id);
// unsafe{ let a = *(0xdeadbeaf as *const u8); } // Page fault
loop {}

@ -231,11 +231,13 @@ impl InactivePageTable for InactivePageTable0 {
impl InactivePageTable0 {
fn map_kernel(&mut self) {
let mut table = unsafe { &mut *(0xffffffff_fffff000 as *mut x86PageTable) };
// Kernel at 0xffff_ff00_0000_0000
// Kernel stack at 0x0000_57ac_0000_0000 (defined in bootloader crate)
let e510 = table[510].clone();
let e509 = table[509].clone();
let estack = table[175].clone();
self.edit(|_| {
table[510].set_addr(e510.addr(), e510.flags() | EF::GLOBAL);
table[509].set_addr(e509.addr(), e509.flags() | EF::GLOBAL);
table[175].set_addr(estack.addr(), estack.flags() | EF::GLOBAL);
});
}
}

@ -24,8 +24,8 @@ pub fn shell() {
Box::new(unsafe { MemBuf::new(_binary_user_riscv_img_start, _binary_user_riscv_img_end) })
};
#[cfg(target_arch = "x86_64")]
let device = Box::new(&ide::DISK0);
let sfs = SimpleFileSystem::open(device).unwrap();
let device = Box::new(&ide::DISK1);
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");
let root = sfs.root_inode();
let files = root.borrow().list().unwrap();
println!("Available programs: {:?}", files);
@ -79,7 +79,7 @@ impl Device for MemBuf {
use core::slice;
#[cfg(target_arch = "x86_64")]
impl BlockedDevice for &'static ide::DISK0 {
impl BlockedDevice for &'static ide::DISK1 {
const BLOCK_SIZE_LOG2: u8 = 9;
fn read_at(&mut self, block_id: usize, buf: &mut [u8]) -> bool {
assert!(buf.len() >= ide::BLOCK_SIZE);

@ -7,7 +7,7 @@ use core::alloc::Layout;
extern fn eh_personality() {
}
#[panic_implementation]
#[panic_handler]
#[no_mangle]
pub fn panic(info: &PanicInfo) -> ! {
let location = info.location().unwrap();

@ -2,16 +2,10 @@
#![feature(lang_items)]
#![feature(const_fn)]
#![feature(alloc)]
#![feature(const_unique_new, const_atomic_usize_new)]
#![feature(unique)]
#![feature(allocator_api)]
#![feature(abi_x86_interrupt)]
#![feature(iterator_step_by)]
#![feature(unboxed_closures)]
#![feature(naked_functions)]
#![feature(asm)]
#![feature(optin_builtin_traits)]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![feature(panic_info_message)]
#![feature(global_asm)]
#![feature(compiler_builtins_lib)]
@ -66,14 +60,7 @@ pub mod arch;
#[path = "arch/riscv32/mod.rs"]
pub mod arch;
/// The entry point of Rust kernel
#[no_mangle]
pub extern "C" fn rust_main() -> ! {
// ATTENTION: we have a very small stack and no guard page
println!("Hello World{}", "!");
logging::init();
arch::init();
pub fn kmain() -> ! {
process::init();
unsafe { arch::interrupt::enable(); }

@ -1,5 +1,5 @@
pub use arch::paging::*;
use bit_allocator::{BitAlloc, BitAlloc4K};
use bit_allocator::{BitAlloc, BitAlloc4K, BitAlloc64K};
use consts::MEMORY_OFFSET;
use spin::{Mutex, MutexGuard};
use super::HEAP_ALLOCATOR;
@ -9,8 +9,16 @@ pub use ucore_memory::memory_set::{MemoryArea, MemoryAttr, MemorySet as MemorySe
pub type MemorySet = MemorySet_<InactivePageTable0>;
// x86_64 support up to 256M memory
#[cfg(target_arch = "x86_64")]
pub type FrameAlloc = BitAlloc64K;
// RISCV only have 8M memory
#[cfg(target_arch = "riscv32")]
pub type FrameAlloc = BitAlloc4K;
lazy_static! {
pub static ref FRAME_ALLOCATOR: Mutex<BitAlloc4K> = Mutex::new(BitAlloc4K::default());
pub static ref FRAME_ALLOCATOR: Mutex<FrameAlloc> = Mutex::new(FrameAlloc::default());
}
pub fn alloc_frame() -> Option<usize> {
@ -52,8 +60,9 @@ pub fn page_fault_handler(addr: usize) -> bool {
}
pub fn init_heap() {
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
unsafe { HEAP_ALLOCATOR.lock().init(KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE); }
use consts::KERNEL_HEAP_SIZE;
static mut HEAP: [u8; KERNEL_HEAP_SIZE] = [0; KERNEL_HEAP_SIZE];
unsafe { HEAP_ALLOCATOR.lock().init(HEAP.as_ptr() as usize, KERNEL_HEAP_SIZE); }
info!("heap init end");
}

@ -1,26 +1,5 @@
use core::fmt::Debug;
pub fn bytes_sum<T>(p: &T) -> u8 {
use core::mem::size_of_val;
let len = size_of_val(p);
let p = p as *const T as *const u8;
(0..len).map(|i| unsafe { &*p.offset(i as isize) })
.fold(0, |a, &b| a.overflowing_add(b).0)
}
///
pub trait Checkable {
fn check(&self) -> bool;
}
/// Scan memory to find the struct
pub unsafe fn find_in_memory<T: Checkable>
(begin: usize, len: usize, step: usize) -> Option<usize> {
(begin .. begin + len).step_by(step)
.find(|&addr| { (&*(addr as *const T)).check() })
}
/// Convert C string to Rust string
pub unsafe fn from_cstr(s: *const u8) -> &'static str {
use core::{str, slice};

@ -7,6 +7,13 @@
"target-c-int-width": "32",
"arch": "x86_64",
"os": "none",
"executables": true,
"linker": "rust-lld",
"pre-link-args": {
"ld.lld": [
"-Tsrc/arch/x86_64/linker.ld"
]
},
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"panic-strategy": "abort"

@ -1,11 +0,0 @@
# MacOS environment
* x86_64_elf_*:
<https://github.com/altkatz/homebrew-gcc_cross_compilers>
* grub.rb:
<https://github.com/nativeos/homebrew-i386-elf-toolchain/blob/master/Formula/i386-elf-grub.rb>
* objconv.rb:
<https://github.com/hawkw/homebrew-grub/blob/master/Formula/objconv.rb>
Change SHA256

@ -1,31 +0,0 @@
class Grub < Formula
desc "GNU GRUB 2 targetting i386-elf"
homepage "https://www.gnu.org/software/grub/"
url "https://ftp.gnu.org/gnu/grub/grub-2.02.tar.xz"
version "2.02"
sha256 "810b3798d316394f94096ec2797909dbf23c858e48f7b3830826b8daa06b7b0f"
depends_on "i386-elf-gcc"
def install
mkdir "grub-build" do
system "../configure",
"--disable-nls",
"--disable-werror",
"--disable-efiemu",
"--target=i386-elf",
"--prefix=#{prefix}",
"TARGET_CC=i386-elf-gcc",
"TARGET_NM=i386-elf-nm",
"TARGET_OBJCOPY=i386-elf-objcopy",
"TARGET_RANLIB=i386-elf-ranlib",
"TARGET_STRIP=i386-elf-strip"
system "make", "install"
end
end
test do
system "grub-shell", "--version"
end
end

@ -1,23 +0,0 @@
class Objconv < Formula
desc "Object file converter and disassembler"
homepage "http://www.agner.org/optimize/#objconv"
url "http://www.agner.org/optimize/objconv.zip"
version "2.44"
sha256 "f2c0c4cd6ff227e76ffed5796953cd9ae9eb228847ca9a14dba6392c573bb7a4"
def install
system "unzip", "source.zip",
"-dsrc"
# objconv doesn't have a Makefile, so we have to call
# the C++ compiler ourselves
system ENV.cxx, "-o", "objconv",
"-O2",
*Dir["src/*.cpp"],
"--prefix=#{prefix}"
bin.install "objconv"
end
test do
system "#{bin}/objconv", "-h"
# TODO: write better tests
end
end

@ -1,38 +0,0 @@
# Environment for RustOS-RISCV
# NOT ubuntu 18.04: libmpfr.so.4 error
FROM ubuntu:17.10
WORKDIR /rust
# Rust toolchain bins
# https://github.com/riscv-rust/rust/releases/download/riscv-rust-1.26.0-1-dev/rust-1.26.0-dev-x86_64-unknown-linux-gnu.tar.xz
ADD rust-1.26.0-dev-x86_64-unknown-linux-gnu.tar.xz .
# Rust src
# https://github.com/riscv-rust/rust/archive/riscv-rust-1.26.0-1-dev.zip
# with submodule: libcompiler_builtins, stdsimd
ADD rust-riscv-rust-1.26.0-1-dev.tar.gz .
# RISCV32 toolchain
# From tencent cloud for OS2018: ssh 2015011279@140.143.187.14
ADD rv32-toolchains-prebuild.tar.bz2 .
# Dependencies
RUN apt-get update && apt-get install -q -y --no-install-recommends libssl1.0.0 libssh2-1 gcc make git libc6-dev \
autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
# Rust bins need this
RUN mkdir -p /gnu/store/n6acaivs0jwiwpidjr551dhdni5kgpcr-glibc-2.26.105-g0890d5379c/lib \
&& ln -s /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /gnu/store/n6acaivs0jwiwpidjr551dhdni5kgpcr-glibc-2.26.105-g0890d5379c/lib/ld-linux-x86-64.so.2
# Install Rust toolchains
RUN ./rust-1.26.0-dev-x86_64-unknown-linux-gnu/install.sh && rm -rf ./rust-1.26.0-dev-x86_64-unknown-linux-gnu
# Install xargo
RUN apt-get install -q -y ca-certificates
RUN cargo install xargo
# Dependencies for qemu-system-riscv32
RUN apt-get install -q -y libglib2.0-0 libjpeg8 libpng16-16 libnuma1 libpixman-1-0 libaio1
# Env
ENV RISCV=/rust/install-rv32
ENV PATH=~/.cargo/bin:$RISCV/bin:$PATH
ENV XARGO_RUST_SRC=/rust/rust-riscv-rust-1.26.0-1-dev/src
RUN ln -s ~/.cargo/bin/xargo /usr/local/bin/xargo
Loading…
Cancel
Save