1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-21 23:56:18 +04:00

x86_64: switch from legacy BIOS to UEFI. use rboot as new bootloader

- remove dependencies: rust-osdev/{bootloader, bootimage}
- remove kernel stack segment
- find a bug: IDT should be initialized after GDT
This commit is contained in:
Runji Wang 2019-09-03 16:23:57 +08:00
parent 977c0badcb
commit c2a80c54f9
14 changed files with 187 additions and 265 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "user"]
path = user
url = https://github.com/rcore-os/rcore-user.git
[submodule "rboot"]
path = rboot
url = https://github.com/rcore-os/rboot.git

View File

@ -1,6 +0,0 @@
[workspace]
members = [
"crate/memory",
"crate/sync",
]
exclude = ["kernel", "bootloader", "user/rust", "modules"]

View File

@ -16,14 +16,12 @@ Tested boards: QEMU, HiFive Unleashed, x86_64 PC (i5/i7), Raspberry Pi 3B+, Kend
### Environment
* [Rust](https://www.rust-lang.org) toolchain at nightly-2019-03-05
* [Rust](https://www.rust-lang.org) toolchain at nightly-2019-06-15
* Cargo tools: [cargo-xbuild](https://github.com/rust-osdev/cargo-xbuild)
* [QEMU](https://www.qemu.org) >= 3.1.0
* [bootimage](https://github.com/rust-osdev/bootimage) (for x86_64)
* [RISCV64 GNU toolchain](https://www.sifive.com/boards) (for riscv32/64)
* [AArch64 GNU toolchain](https://cs140e.sergio.bz/assignments/0-blinky/) (for aarch64)
* [musl-cross-make](https://github.com/richfelker/musl-cross-make) (for userland musl, or download prebuilt toolchain from [musl.cc](https://musl.cc/))
* [libfuse-dev](https://github.com/libfuse/libfuse) (for userland image generation)
See [Travis script](./.travis.yml) for details.
@ -33,7 +31,6 @@ See [Travis script](./.travis.yml) for details.
$ rustup component add rust-src llvm-tools-preview
$ cargo install cargo-binutils
$ cargo install cargo-xbuild
$ cargo install bootimage --version 0.6.6
```
```bash

41
docs/x86_64.md Normal file
View File

@ -0,0 +1,41 @@
# x86_64
## 运行
### QEMU
```
make run arch=x86_64 LOG=info
```
使用开源 UEFI 固件实现 [OVMF](https://github.com/tianocore/tianocore.github.io/wiki/OVMF),预编译镜像已包含在 rboot 项目中。
### 真机
```
make build arch=x86_64 LOG=error board=pc graphic=console
```
需要一个支持 UEFI 的启动 U 盘,可使用“老毛桃”“大白菜”等工具制作。
完成后将 `target/release/esp/EFI `文件夹复制到启动 U盘 的 EFI 系统分区ESP中。注意备份
将 U 盘插入电脑,进入 BIOS 设置,关闭安全启动,从 U 盘启动即可。
注:目前真机模式与 QEMU 的区别:
* 文本输出到图形显示,而不是串口
* 用户程序镜像直接链接在内核中,而不是从 AHCI 磁盘读取
## Boot
rCore x86_64 基于 UEFI 标准,使用自己编写的 rBoot 作为 Bootloader。
[rBoot](https://github.com/rcore-os/rboot) 是一个标准的 UEFI OS Loader 程序。它完成以下主要工作:
* 加载 kernel ELF 文件到内存,建立虚拟内存映射。
* 设置图形显示模式
* 启动多核处理器
* 跳转到 ELF 入口点,并传递 BootInfo 信息
更多参考:[uefi-rs 文档](https://github.com/rust-osdev/uefi-rs/blob/master/BUILDING.md)

242
kernel/Cargo.lock generated
View File

@ -110,19 +110,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "bootinfo"
version = "0.1.0"
[[package]]
name = "bootloader"
version = "0.4.0"
source = "git+https://github.com/rcore-os/bootloader?branch=vga#485addfdd7dc348aaba4cc99391d04070effd8fa"
dependencies = [
"apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)",
"fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"font8x8 0.2.4 (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.3.6 (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 = "buddy_system_allocator"
version = "0.3.5"
@ -180,32 +167,6 @@ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fixedvec"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "font8x8"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getopts"
version = "0.2.19"
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 = "isomorphic_drivers"
version = "0.1.0"
@ -226,11 +187,6 @@ dependencies = [
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.9"
@ -330,14 +286,6 @@ dependencies = [
"unicode-xid 0.1.0 (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.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.6.12"
@ -346,31 +294,6 @@ dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "raw-cpuid"
version = "6.1.0"
@ -381,6 +304,17 @@ dependencies = [
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rboot"
version = "0.1.0"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"uefi 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
"uefi-services 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
"x86_64 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"xmas-elf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rcore"
version = "0.2.0"
@ -395,7 +329,6 @@ dependencies = [
"bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)",
"bitvec 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bootinfo 0.1.0",
"bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=vga)",
"buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"compression 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -408,6 +341,7 @@ dependencies = [
"pc-keyboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pci 0.0.1 (git+https://github.com/rcore-os/pci-rs)",
"raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rboot 0.1.0",
"rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=18402290)",
"rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=33f86c47)",
"rcore-fs-devfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=33f86c47)",
@ -502,14 +436,6 @@ dependencies = [
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "register"
version = "0.2.1"
@ -518,14 +444,6 @@ dependencies = [
"tock-registers 0.2.0 (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.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "riscv"
version = "0.5.0"
@ -537,6 +455,11 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rlibc"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -558,15 +481,6 @@ name = "semver-parser"
version = "0.7.0"
source = "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 = "smoltcp"
version = "0.5.0"
@ -603,15 +517,6 @@ dependencies = [
"unicode-xid 0.1.0 (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.6 (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 = "tock-registers"
version = "0.2.0"
@ -632,10 +537,61 @@ dependencies = [
]
[[package]]
name = "unicode-width"
version = "0.1.5"
name = "ucs2"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "uefi"
version = "0.1.0"
source = "git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a#3b80c89acf75df0457cf103da246d2c6cbdc3c09"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ucs2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uefi-macros 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
]
[[package]]
name = "uefi-alloc"
version = "0.1.0"
source = "git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a#3b80c89acf75df0457cf103da246d2c6cbdc3c09"
dependencies = [
"uefi 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
]
[[package]]
name = "uefi-logger"
version = "0.1.0"
source = "git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a#3b80c89acf75df0457cf103da246d2c6cbdc3c09"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"uefi 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
]
[[package]]
name = "uefi-macros"
version = "0.1.0"
source = "git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a#3b80c89acf75df0457cf103da246d2c6cbdc3c09"
dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "uefi-services"
version = "0.1.0"
source = "git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a#3b80c89acf75df0457cf103da246d2c6cbdc3c09"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uefi 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
"uefi-alloc 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
"uefi-logger 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)",
"x86_64 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
@ -669,25 +625,6 @@ dependencies = [
"utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.3.7"
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"
version = "0.15.1"
@ -699,10 +636,9 @@ dependencies = [
[[package]]
name = "x86_64"
version = "0.3.6"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"array-init 0.0.4 (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.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -735,14 +671,6 @@ dependencies = [
"ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xmas-elf"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xmas-elf"
version = "0.7.0"
@ -771,7 +699,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)" = "<none>"
"checksum bitvec 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9633b74910e1870f50f5af189b08487195cdb83c0e27a71d6f64d5e09dd0538b"
"checksum bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cfadef5c4e2c2e64067b9ecc061179f12ac7ec65ba613b1f60f3972bbada1f5b"
"checksum bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=vga)" = "<none>"
"checksum buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59da15ef556589ee78370281d75b67f2d69ed26465ec0e0f3961e2021502426f"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
@ -781,13 +708,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum deque 0.3.2 (git+https://github.com/rcore-os/deque.git?branch=no_std)" = "<none>"
"checksum device_tree 1.0.3 (git+https://github.com/rcore-os/device_tree-rs)" = "<none>"
"checksum embedded-graphics 0.6.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdd39e1355cea15798e58ab59676d1559c324bb3ec22cfc36eff8bc99a22b05"
"checksum fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6c16d316ccdac21a4dd648e314e76facbbaf316e83ca137d0857a9c07419d0"
"checksum font8x8 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b81d84c3c978af7d05d31a2198af4b9ba956d819d15d8f6d58fc150e33f8dc1f"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450"
"checksum isomorphic_drivers 0.1.0 (git+https://github.com/rcore-os/isomorphic_drivers)" = "<none>"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6"
@ -801,11 +723,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum pci 0.0.1 (git+https://github.com/rcore-os/pci-rs)" = "<none>"
"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07"
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d"
"checksum rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=18402290)" = "<none>"
"checksum rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=33f86c47)" = "<none>"
@ -814,37 +732,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=33f86c47)" = "<none>"
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=33f86c47)" = "<none>"
"checksum rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread)" = "<none>"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum riscv 0.5.0 (git+https://github.com/rcore-os/riscv)" = "<none>"
"checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c"
"checksum smoltcp 0.5.0 (git+https://github.com/rcore-os/smoltcp)" = "<none>"
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
"checksum static_assertions 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ec3c2cbd19f2033005f463529553273cdcb3e91b3281346007adc7967b6789af"
"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tock-registers 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a385d94f3f62e60445a0adb9ff8d9621faa272234530d4c0f848ec98f88e316"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum uart_16550 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b9392f60931fe3bf8f24e0a15ee4f51528770f1d64c48768ab66571334d95b0"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum ucs2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e583483194b07714e09e7f72ae3ed447d17fe6855f66a2ccbf6751e52df82e0"
"checksum uefi 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)" = "<none>"
"checksum uefi-alloc 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)" = "<none>"
"checksum uefi-logger 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)" = "<none>"
"checksum uefi-macros 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)" = "<none>"
"checksum uefi-services 0.1.0 (git+https://github.com/rust-osdev/uefi-rs.git?rev=3b80c89a)" = "<none>"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5"
"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d"
"checksum ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f"
"checksum volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29"
"checksum vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"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 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f21eecbd666e3a8edbf0b26d36f270f7a613d8986ca0eafb8205e324f7336dab"
"checksum x86_64 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f9258d7e2dd25008d69e8c9e9ee37865887a5e1e3d06a62f1cb3f6c209e6f177"
"checksum x86_64 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd647af1614659e1febec1d681231aea4ebda4818bf55a578aff02f3e4db4b4"
"checksum x86_64 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bb8f09c32a991cc758ebcb9b7984f530095d32578a4e7b85db6ee1f0bbe4c9c6"
"checksum x86_64 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad37c1665071808d64e65f7cdae32afcdc90fd7ae7fa402bbda36b824f1add6"
"checksum xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22678df5df766e8d1e5d609da69f0c3132d794edf6ab5e75e7abcd2270d4cf58"
"checksum xmas-elf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e74de9a366f6ab8c405fa6b371d9ac24943921fa14b3d64afcb202065c405f11"
"checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5"

View File

@ -73,7 +73,7 @@ compression = { version = "0.1.4", default-features = false, features = ["gzip"]
[target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = { git = "https://github.com/rcore-os/bootloader", branch = "vga" }
rboot = { path = "../rboot" }
apic = { git = "https://github.com/rcore-os/apic-rs" }
x86_64 = "0.7"
raw-cpuid = "6.0"

View File

@ -45,7 +45,8 @@ target := $(arch)
build_path := target/$(target)/$(mode)
kernel := $(build_path)/rcore
kernel_img := $(build_path)/kernel.img
bootimage := $(build_path)/bootimage.bin
ESP := $(build_path)/esp
OVMF := ../rboot/OVMF.fd
bootloader_dir = ../bootloader
bootloader := $(bootloader_dir)/target/$(target)/$(mode)/rcore-bootloader
user_dir := ../user
@ -58,7 +59,6 @@ export USER_QCOW2 = $(user_dir)/build/$(arch).qcow2
ifeq ($(arch), aarch64)
board := raspi3
need_bootloader := true
endif
# currently only mipsel architecture and rocket-chip need DTB linked to the kernel
@ -88,7 +88,8 @@ qemu_ui_opts :=
ifeq ($(arch), x86_64)
qemu_opts += \
-drive format=raw,file=$(bootimage) \
-drive if=pflash,format=raw,file=$(OVMF),readonly=on \
-drive format=raw,file=fat:rw:$(ESP) \
-serial mon:stdio \
-m 4G \
-device isa-debug-exit
@ -288,20 +289,26 @@ sym:
### bootloader and kernel image ###
$(bootloader): $(kernel)
ifeq ($(need_bootloader), true)
bootloader: $(kernel)
ifeq ($(arch), x86_64)
@cd ../rboot && make build
endif
ifeq ($(arch), aarch64)
@echo "Patching symbols into kernel."
@../tools/fill_symbols/aarch64.sh target/aarch64/$(mode)/rcore $(prefix)
endif
@echo Building $(arch) bootloader
@$(strip) $(kernel) -o $(kernel)_stripped
@cd $(bootloader_dir) && make arch=$(arch) mode=$(mode) payload=../kernel/$(kernel)_stripped
@rm $(kernel)_stripped
endif
$(kernel_img): kernel $(bootloader)
ifeq ($(arch), $(filter $(arch), riscv32 riscv64))
$(kernel_img): kernel bootloader
ifeq ($(arch), x86_64)
@mkdir -p $(ESP)/EFI/rCore $(ESP)/EFI/Boot
@cp ../rboot/target/x86_64-unknown-uefi/release/rboot.efi $(ESP)/EFI/Boot/BootX64.efi
@cp ../rboot/rboot.conf $(ESP)/EFI/Boot/rboot.conf
@cp $(kernel) $(ESP)/EFI/rCore/kernel.elf
else ifeq ($(arch), $(filter $(arch), riscv32 riscv64))
@$(objcopy) $(kernel) --strip-all -O binary $@
else ifeq ($(arch), aarch64)
@$(objcopy) $(bootloader) --strip-all -O binary $@
@ -313,12 +320,9 @@ endif
kernel: $(dtb)
@echo Building $(arch) kernel
ifeq ($(arch), x86_64)
@bootimage build $(build_args)
@cargo xbuild $(build_args)
@echo "Now patching kernel symbols onto kernel."
@../tools/fill_symbols/x86_64.sh target/x86_64/$(mode)/rcore
@echo "Generate bootimage again."
@bootimage build $(build_args)
@mv target/x86_64/bootimage.bin $(bootimage)
else ifeq ($(arch), $(filter $(arch), riscv32 riscv64))
ifeq ($(board), k210)
@cp src/arch/riscv32/board/k210/linker.ld src/arch/riscv32/boot/linker64.ld

View File

@ -19,7 +19,6 @@ pub mod board;
global_asm!(include_str!("boot/entry.S"));
/// The entry point of kernel
#[no_mangle] // don't mangle the name of this function
pub extern "C" fn rust_main(boot_info: &'static BootInfo) -> ! {

View File

@ -3,65 +3,25 @@ pub mod fb;
use crate::consts::KERNEL_OFFSET;
use crate::memory::phys_to_virt;
use bootloader::bootinfo::{BootInfo, VbeModeInfo};
use core::mem::zeroed;
use fb::{ColorFormat, ColorDepth, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
use fb::{ColorDepth, ColorFormat, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
use rboot::{BootInfo, GraphicInfo};
static mut VBE_MODE: VbeModeInfo = VbeModeInfo {
attributes: 0,
win_a: 0,
win_b: 0,
granularity: 0,
window_size: 0,
segment_a: 0,
segment_b: 0,
_1: 0,
pitch: 0,
width: 0,
height: 0,
w_char: 0,
y_char: 0,
planes: 0,
bpp: 0,
banks: 0,
memory_model: 0,
bank_size: 0,
image_pages: 0,
_2: 0,
red_mask: 0,
red_position: 0,
green_mask: 0,
green_position: 0,
blue_mask: 0,
blue_position: 0,
rsv_mask: 0,
rsv_position: 0,
directcolor_attributes: 0,
framebuffer: 0,
};
static mut GRAPHIC_INFO: Option<GraphicInfo> = None;
pub fn init_driver(boot_info: &BootInfo) {
unsafe {
VBE_MODE = boot_info.vbe_info;
GRAPHIC_INFO = Some(boot_info.graphic_info);
}
#[cfg(not(feature = "nographic"))]
fb::init();
}
pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> FramebufferResult {
let width = unsafe { VBE_MODE.width as u32 };
let height = unsafe { VBE_MODE.height as u32 };
let pitch = unsafe { VBE_MODE.pitch as u32 };
let framebuffer = unsafe { VBE_MODE.framebuffer as usize };
let depth = unsafe { VBE_MODE.bpp as u32 };
let format = if depth == 8 {
fb::ColorFormat::RGB332
} else if depth == 16 {
fb::ColorFormat::RGB565
} else {
// assume BGRA8888 for now
fb::ColorFormat::RGBA8888
};
let info = unsafe { GRAPHIC_INFO.as_ref().unwrap() };
let width = info.mode.resolution().0 as u32;
let height = info.mode.resolution().1 as u32;
let format = fb::ColorFormat::RGBA8888;
Ok(FramebufferInfo {
xres: width,
yres: height,
@ -69,10 +29,10 @@ pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> FramebufferResul
yres_virtual: height,
xoffset: 0,
yoffset: 0,
depth: ColorDepth::try_from(depth)?,
depth: ColorDepth::ColorDepth32,
format: format,
paddr: framebuffer,
vaddr: phys_to_virt(framebuffer),
screen_size: (width * height * (depth / 8)) as usize,
paddr: info.fb_addr as usize,
vaddr: phys_to_virt(info.fb_addr as usize),
screen_size: info.fb_size as usize,
})
}

View File

@ -1,7 +1,12 @@
pub const MEMORY_OFFSET: usize = 0;
pub const KERNEL_OFFSET: usize = 0xffffff00_00000000;
pub const KSEG2_OFFSET: usize = 0xfffffe80_00000000;
pub const PHYSICAL_MEMORY_OFFSET: usize = 0xffff8000_00000000;
pub const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024; // 8 MB
pub const PHYSICAL_MEMORY_OFFSET: usize = 0xfffffc00_00000000;
pub const KERNEL_PM4: usize = (KERNEL_OFFSET >> 39) & 0o777;
pub const KSEG2_PM4: usize = (KSEG2_OFFSET >> 39) & 0o777;
pub const PHYSICAL_MEMORY_PM4: usize = (PHYSICAL_MEMORY_OFFSET >> 39) & 0o777;
pub const USER_STACK_OFFSET: usize = 0x00008000_00000000 - USER_STACK_SIZE;
pub const USER_STACK_SIZE: usize = 8 * 1024 * 1024; // 8 MB, the default config of Linux

View File

@ -1,8 +1,10 @@
use super::paging::PageTableImpl;
use super::{BootInfo, MemoryRegionType};
use crate::memory::{init_heap, FRAME_ALLOCATOR};
use bitmap_allocator::BitAlloc;
use rboot::{BootInfo, MemoryType};
use rcore_memory::paging::*;
use rcore_memory::PAGE_SIZE;
pub fn init(boot_info: &BootInfo) {
init_frame_allocator(boot_info);
init_heap();
@ -12,11 +14,11 @@ pub fn init(boot_info: &BootInfo) {
/// Init FrameAllocator and insert all 'Usable' regions from BootInfo.
fn init_frame_allocator(boot_info: &BootInfo) {
let mut ba = FRAME_ALLOCATOR.lock();
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,
);
for region in boot_info.memory_map.clone().iter {
if region.ty == MemoryType::CONVENTIONAL {
let start_frame = region.phys_start as usize / PAGE_SIZE;
let end_frame = start_frame + region.page_count as usize;
ba.insert(start_frame..end_frame);
}
}
}

View File

@ -1,6 +1,6 @@
use bootloader::bootinfo::{BootInfo, MemoryRegionType};
use core::sync::atomic::*;
use log::*;
use rboot::BootInfo;
pub mod acpi;
pub mod board;
@ -22,7 +22,7 @@ static AP_CAN_INIT: AtomicBool = AtomicBool::new(false);
/// The entry point of kernel
#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
pub extern "C" fn _start(boot_info: *const BootInfo) -> ! {
let cpu_id = cpu::id();
println!("Hello world! from CPU {}!", cpu_id);
@ -35,14 +35,15 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
// First init log mod, so that we can print log info.
crate::logging::init();
// check BootInfo from bootloader
let boot_info = unsafe { &*boot_info };
info!("{:#x?}", boot_info);
assert_eq!(
boot_info.physical_memory_offset as usize,
consts::PHYSICAL_MEMORY_OFFSET
);
// Init trap handling.
idt::init();
// setup fast syscall in x86_64
interrupt::fast_syscall::init();
@ -53,9 +54,13 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
// Init GDT
gdt::init();
// Init trap handling
// WARN: IDT must be initialized after GDT.
// Because x86_64::IDT will use current CS segment in IDT entry.
idt::init();
// Init virtual space
memory::init_kernel_kseg2_map();
//get local apic id of cpu
// get local apic id of cpu
cpu::init();
// now we can start LKM.
crate::lkm::manager::ModuleManager::init();
@ -77,10 +82,10 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
/// The entry point for other processors
fn other_start() -> ! {
// init trap handling.
idt::init();
// init gdt
gdt::init();
// init trap handling
idt::init();
// init local apic
cpu::init();
// setup fast syscall in x86_64

View File

@ -1,3 +1,4 @@
use super::consts::*;
use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt};
use core::mem::ManuallyDrop;
use core::sync::atomic::Ordering;
@ -21,7 +22,6 @@ pub trait PageExt {
impl PageExt for Page {
fn of_addr(address: usize) -> Self {
use x86_64;
Page::containing_address(VirtAddr::new(address as u64))
}
fn range_of(begin: usize, end: usize) -> PageRange {
@ -231,18 +231,13 @@ impl PageTableExt for PageTableImpl {
fn map_kernel(&mut self) {
let table = unsafe { &mut *frame_to_page_table(Cr3::read().0) };
// Kernel at 0xffff_ff00_0000_0000
// Kernel stack at 0x0000_57ac_0000_0000 (defined in bootloader crate)
// Kseg2 at 0xffff_fe80_0000_0000
let ekernel = table[510].clone();
let ephysical = table[0x1f8].clone();
let estack = table[175].clone();
let ekseg2 = table[509].clone();
let ekernel = table[KERNEL_PM4].clone();
let ephysical = table[PHYSICAL_MEMORY_PM4].clone();
let ekseg2 = table[KSEG2_PM4].clone();
let table = unsafe { &mut *frame_to_page_table(self.2) };
table[510].set_addr(ekernel.addr(), ekernel.flags() | EF::GLOBAL);
table[0x1f8].set_addr(ephysical.addr(), ephysical.flags() | EF::GLOBAL);
table[175].set_addr(estack.addr(), estack.flags() | EF::GLOBAL);
table[509].set_addr(ekseg2.addr(), ekseg2.flags() | EF::GLOBAL);
table[KERNEL_PM4].set_addr(ekernel.addr(), ekernel.flags() | EF::GLOBAL);
table[PHYSICAL_MEMORY_PM4].set_addr(ephysical.addr(), ephysical.flags() | EF::GLOBAL);
table[KSEG2_PM4].set_addr(ekseg2.addr(), ekseg2.flags() | EF::GLOBAL);
}
fn token(&self) -> usize {

1
rboot Submodule

@ -0,0 +1 @@
Subproject commit aa1d4afe9734a87c7148c07bb75c48bfa3653466