Skip to content

Commit a91eda1

Browse files
committed
Merge pull request #74 from hawkw/new-rust-boot
Pure-Rust boot sequence
2 parents cd0d5de + efde010 commit a91eda1

22 files changed

+452
-347
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Created by https://www.gitignore.io/api/assembler,rust,emacs,osx,sublimetext,tags,vagrant,vim,linux
33

44
### Kernel binaries ###
5-
/build/
65
*.iso
76
*.bin
87
*.elf
@@ -156,6 +155,8 @@ Session.vim
156155
tags
157156
.tags1
158157

158+
### GDB ###
159+
.gdb_history
159160

160161
### Linux ###
161162
*~

.travis.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ before_install: |
4141
brew update && brew tap homebrew/bundle &&
4242
travis_wait 120 brew bundle;
4343
printf "\n\n[target.x86_64-sos-kernel-gnu]\nlinker = \"/usr/local/bin/x86_64-pc-elf-gcc\"" >> $HOME/.cargo/config;
44+
elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
45+
objcopy=$(which objcopy) &&
46+
strip=$(which strip) &&
47+
mkdir -p $HOME/bin &&
48+
ln -s $objcopy $HOME/bin/x86_64-elf-objcopy &&
49+
ln -s $strip $HOME/bin/x86_64-elf-strip
4450
fi
4551
4652
install:
@@ -74,7 +80,7 @@ install:
7480

7581
script:
7682
- make test
77-
- xargo build --target x86_64-sos-kernel-gnu
83+
- make kernel
7884

7985
# after_success:
8086
# - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then travis-cargo doc && travis-cargo doc-upload; fi
@@ -92,4 +98,5 @@ env:
9298
global:
9399
# override the default `--features unstable` used for the nightly branch (optional)
94100
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
101+
- PATH="$PATH:$HOME/bin"
95102
- secure: Vv4bFCkxM3o7FpKjcxTzQRWdkp5aSfrkmFcxSRLYFhm8tyeh+TRiC2+ucNfscFeOzPTC/hTwatbbpdTIaAZKpyrD/gB4hNiGFdKV1x1pw23KQkiPmQdFKxAHtIS20jeIa44q6kPltTQtZXXuM8s0xc6r+C14Q6igd4HkD0nLhAlKIQpcS/srXoeMheL3vNIroasHUwFgpv1LLJnMqYhCHzNk2Y6CaxYygg5Cy2gS9G1nfxdNVfF4iaUXYZKgU0s3C1GL0ApTtUxW0uT/NS0UBZwttsq9NvwmZSZQIXpfTnn0wHd4cl8MhokUQNEumFouU5rlEIcFS9ulohxaHnn50cqfos+seblKs2E+MJoX8rBO5Kz3dNE3+otZw9CpImskO4EKA2MYwtTC3Ds4uVoleS9PskCMz32jKXqp6WqZkJgpimHrdv0jNBy2ucTMdw91XjRXLA557GPRa/28TPpKkMYrSB02c2IadftexWKDP5Q9uMsfTEgIpXzx/XRQvPoxtJo+rOn9hTbyHWexKEMAuic12FBoYFOMSbRKtpT8kjtd8WeBzc1RmXZYpg5td5EN3v/2fmvM6F6Sz/db4HgNZIccC/j/fWvXN7njRl8bgMC002/tkQs0Ugl1aE5onaK9DTMHquqCLnd9CADwXdQf1YsfxryjhhBfd1WIfuqe1Ww=

Cargo.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = [ # hacked around by
88
]
99

1010
build = "build.rs"
11-
11+
# build = false
1212
# [[bin]]
1313
# name = "sos_kernel_full"
1414

@@ -62,7 +62,7 @@ features = ["spin_no_std"]
6262

6363
[dependencies.vga]
6464
path = "vga"
65-
features = ["kinfo"]
65+
features = ["kinfo", "system_term"]
6666

6767
[dependencies.alloc]
6868
path = "alloc"
@@ -71,6 +71,3 @@ features = ["buddy_as_system"]
7171
[dependencies.clippy]
7272
version = "0.0.60"
7373
optional = true
74-
75-
[build-dependencies]
76-
nasm-rs = { git = "https://github.com/medek/nasm-rs" }

Makefile

+40-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
arch ?= x86_64
22
target ?= $(arch)-sos-kernel-gnu
33

4+
boot_target := x86_32-sos-bootstrap-gnu
5+
boot_outdir := boot/target/$(boot_target)
6+
47
iso := target/$(target)/debug/sos-$(arch).iso
58
kernel := target/$(target)/debug/sos_kernel
9+
isofiles := target/$(target)/debug/isofiles
10+
boot := $(boot_outdir)/debug/libboot.a
11+
612

713
release_iso := target/$(target)/release/sos-$(arch).iso
814
release_kernel := target/$(target)/release/sos_kernel
15+
release_isofiles := target/$(target)/release/isofiles
16+
release_boot := $(boot_outdir)/release/libboot.a
917

1018
grub_cfg := src/arch/$(arch)/grub.cfg
1119

@@ -39,6 +47,9 @@ HELP_FUN = \
3947

4048
.PHONY: all clean kernel run iso cargo help gdb test doc release-iso release-run release-kernel
4149

50+
exception: $(iso) ##@build Run the kernel, dumping the state from QEMU if an exception occurs
51+
@qemu-system-x86_64 -s -hda $(iso) -d int -no-reboot
52+
4253
doc: ##@utilities Make RustDoc documentation
4354
@xargo doc
4455

@@ -52,7 +63,7 @@ env: ##@utilities Install dev environment dependencies
5263

5364
clean: ##@utilities Delete all build artefacts.
5465
@xargo clean
55-
66+
@cd boot && xargo clean
5667

5768
kernel: $(kernel).bin ##@build Compile the debug kernel binary
5869

@@ -67,7 +78,7 @@ release-iso: $(release_iso) ##@release Compile the release kernel binary and mak
6778
release-run: run-release ##@release Make the release kernel ISO image and boot QEMU from it.
6879

6980
debug: $(iso) ##@build Run the kernel, redirecting serial output to a logfile.
70-
@qemu-system-x86_64 -s -hda $(iso) -serial file:$(CURDIR)/target/$(target)/serial-$(TIMESTAMP).log
81+
@qemu-system-x86_64 -s -S -hda $(iso) -serial file:$(CURDIR)/target/$(target)/serial-$(TIMESTAMP).log
7182

7283
test: ##@build Test crate dependencies
7384
@cargo test -p sos_intrusive
@@ -86,13 +97,37 @@ $(wild_iso): $(wild_kernel).bin $(wild_isofiles) $(grub_cfg)
8697
$(wild_isofiles):
8798
@mkdir -p $@/boot/grub
8899

89-
$(release_kernel):
100+
$(boot):
101+
@cd boot && xargo rustc --target $(boot_target) -- \
102+
--emit=obj=target/$(boot_target)/debug/boot32.o
103+
# # Place 32-bit bootstrap code into a 64-bit ELF
104+
@x86_64-elf-objcopy -O elf64-x86-64 $(boot_outdir)/debug/boot32.o \
105+
$(boot_outdir)/debug/boot.o
106+
# @x86_64-elf-objcopy --strip-debug -G _start boot/target/boot.o
107+
@cd $(boot_outdir)/debug && ar -crus libboot.a boot.o
108+
109+
$(release_boot):
110+
@cd boot && xargo rustc --target $(boot_target) -- --release \
111+
--emit=obj=target/$(boot_target)release/boot32.o
112+
# # Place 32-bit bootstrap code into a 64-bit ELF
113+
@x86_64-elf-objcopy -O elf64-x86-64 $(boot_outdir)/release/boot32.o $(boot_outdir)/release/boot.o
114+
@x86_64-elf-objcopy --strip-debug -G _start $(boot_outdir)/release/boot.o
115+
@cd $(boot_outdir)/release && ar -crus libboot.a boot.o
116+
117+
$(release_kernel): $(release_boot)
90118
@xargo build --target $(target) --release
91119

92120
$(release_kernel).bin: $(release_kernel)
93121
@cp $(release_kernel) $(release_kernel).bin
94122

95-
$(kernel):
123+
$(release_iso): $(release_kernel).bin $(grub_cfg)
124+
@mkdir -p $(release_isofiles)/boot/grub
125+
@cp $(release_kernel).bin $(release_isofiles)/boot/
126+
@cp $(grub_cfg) $(release_isofiles)/boot/grub
127+
@grub-mkrescue -o $(release_iso) $(release_isofiles)/
128+
@rm -r $(release_isofiles)
129+
130+
$(kernel): $(boot)
96131
@xargo build --target $(target)
97132

98133
$(kernel).debug: $(kernel)
@@ -103,4 +138,4 @@ $(kernel).bin: $(kernel) $(kernel).debug
103138
@x86_64-elf-objcopy --add-gnu-debuglink=$(kernel).debug $(kernel)
104139

105140
gdb: $(kernel).bin $(kernel).debug ##@utilities Connect to a running QEMU instance with gdb.
106-
@rust-gdb -ex "target remote tcp:127.0.0.1:1234" $(kernel)
141+
@rust-os-gdb -ex "target remote tcp:127.0.0.1:1234" $(kernel)

boot/Cargo.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "boot"
3+
version = "0.1.0"
4+
authors = ["Eliza Weisman <hi@hawkweisman.me>"]
5+
6+
# [lib]
7+
# crate-type = ["staticlib"]
8+
9+
# [[bin]]
10+
# name = "libboot.a"
11+
12+
[features]
13+
default = ["log"]
14+
log = []
15+
16+
[profile.dev]
17+
opt-level = 3
18+
debug = true
19+
rpath = false
20+
lto = false
21+
debug-assertions = true
22+
codegen-units = 1
23+
panic = "abort"
24+
25+
[profile.release]
26+
opt-level = 3
27+
debug = true
28+
rpath = false
29+
lto = false
30+
panic = "abort"
31+
32+
[dependencies]
33+
rlibc = "0.1.4"

0 commit comments

Comments
 (0)