Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

109350078 lab4 #137

Open
wants to merge 34 commits into
base: 109350078
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9955373
KAF is very very cute.
Mar 14, 2024
4c01332
Mailbox Ok, KAF is cute.
cfmc30 Mar 14, 2024
2265a6e
New Project Layout, 今日もかわいい!
cfmc30 Mar 23, 2024
041b93a
Driver
cfmc30 Mar 23, 2024
8ef4c75
bootloader ok, KAF still cute
cfmc30 Mar 25, 2024
d233978
bootloader ok, KAF still cute
cfmc30 Mar 25, 2024
9b87637
utils
cfmc30 Mar 25, 2024
0b78b5c
clean
cfmc30 Mar 25, 2024
b95fc31
Fix: Relo, cpio
cfmc30 Mar 28, 2024
e38b565
README
cfmc30 Mar 28, 2024
372bc5d
rm
cfmc30 Mar 28, 2024
9fde5bd
initramfs
cfmc30 Mar 28, 2024
ef607aa
cat
cfmc30 Mar 28, 2024
9990018
rm
cfmc30 Mar 28, 2024
93262a3
println!("KAF is very kawaii.")
cfmc30 Mar 29, 2024
de782ad
Fix: kernelsender.py
cfmc30 Mar 29, 2024
8f2b8a8
Device Tree
cfmc30 Apr 4, 2024
5adee87
Fix something
cfmc30 Apr 6, 2024
77cea39
New CPIO, KAF is very kawaii!
cfmc30 Apr 8, 2024
4b1ed00
New exception handler and user program
cfmc30 Apr 9, 2024
a7889f7
Exception
cfmc30 Apr 11, 2024
523117a
Adv timer!, KAF, kawaii!
cfmc30 Apr 24, 2024
7b31fe7
Fix some bugs in timer
cfmc30 Apr 25, 2024
ca6f38d
Fix some bugs in timer
cfmc30 Apr 25, 2024
9bdc1ca
Allocator
cfmc30 May 8, 2024
adff83b
Rsv
cfmc30 May 9, 2024
6a46caa
dfree
cfmc30 May 9, 2024
def7c63
Lab 5 Process
cfmc30 Jun 6, 2024
9e98b3e
Directory Operation, かふかふかわいい!
cfmc30 Jun 13, 2024
6d46899
VFS is very strange, but かふかふかわいい
cfmc30 Jun 15, 2024
0ea7a9c
VFS good, but かふかふかわいい
cfmc30 Jun 17, 2024
0083199
喜多郁代かわいい
cfmc30 Jun 20, 2024
47c56b5
devfs, 喜多郁代かわいい
cfmc30 Jun 26, 2024
adb3d2f
devfs, 喜多郁代かわいい
cfmc30 Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target
*/target
*.img
.vscode
rootfs
.gdbinit
initramfs.cpio
*.dtb
*.txt
.idea
initramfs/prog
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = [
"driver",
"kernel",
"bootloader",
]

104 changes: 104 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
BSP = rpi3

TARGET = aarch64-unknown-none-softfloat

KERNEL_BIN = kernel8.img
BOOTLOADER_BIN = bootloader.img

include ./utils/format.mk
include ./utils/os.mk

# QEMU
QEMU_BINARY = qemu-system-aarch64
QEMU_MACHINE_TYPE = raspi3b
QEMU_RELEASE_ARGS = -display none -serial null -serial stdio
QEMU_DISPLAY_ARGS = -display gtk -serial null -serial stdio
QEMU_DEBUG_ARGS = -display none -S -s -serial null -serial stdio
QEMU_TTY_ARGS = -display none -serial null -serial pty
QEMU_TTY_DEBUG_ARGS = -display none -S -s -serial null -serial pty
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

QEMU_DTB_PATH = $(shell pwd)/bcm2710-rpi-3-b-plus.dtb

OBJDUMP_BINARY = aarch64-none-elf-objdump
NM_BINARY = aarch64-none-elf-mn
READELF_BINARY = aarch64-none-elf-readelf
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53

KERNEL_PATH = $(shell pwd)/kernel
BOOTLOADER_PATH = $(shell pwd)/bootloader
INITRD_PATH = $(shell pwd)/initramfs.cpio

KERNEL_ELF = target/$(TARGET)/release/kernel
BOOTLOADER_ELF = target/$(TARGET)/release/bootloader

USER_PROG_IMG = userprog/prog/target/prog
USER_PROG = userprog/prog

OBJCOPY_CMD = rust-objcopy \
--strip-all \
-O binary

.PHONY: all doc qemu clippy clean readelf objdump nm check

all: $(KERNEL_BIN) $(BOOTLOADER_BIN)

$(KERNEL_BIN): kernel_elf
$(call color_header, "Generating stripped binary")
$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
$(call disk_usage_KiB, $(KERNEL_BIN))

$(BOOTLOADER_BIN): bootloader_elf
$(call color_header, "Generating stripped binary")
$(OBJCOPY_CMD) $(BOOTLOADER_ELF) $(BOOTLOADER_BIN)
$(call color_progress_prefix, "Name")
@echo $(BOOTLOADER_BIN)
$(call color_progress_prefix, "Size")
$(call disk_usage_KiB, $(BOOTLOADER_BIN))

kernel_elf:
make -C $(KERNEL_PATH) all

bootloader_elf:
make -C $(BOOTLOADER_PATH) all

kernel_gtk: $(KERNEL_BIN) cpio
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_DISPLAY_ARGS) -initrd $(INITRD_PATH) -dtb $(QEMU_DTB_PATH) -kernel $(KERNEL_BIN)

kernel_qemu: $(KERNEL_BIN) cpio
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -initrd $(INITRD_PATH) -dtb $(QEMU_DTB_PATH) -kernel $(KERNEL_BIN)



kernel_gdb: $(KERNEL_BIN) cpio
$(call color_header, "Launching QEMU in background")
$(EXEC_QEMU) $(QEMU_DEBUG_ARGS) -initrd $(INITRD_PATH) -dtb $(QEMU_DTB_PATH) -kernel $(KERNEL_BIN)

bootloader_qemu:$(BOOTLOADER_BIN) $(KERNEL_BIN) cpio
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_TTY_ARGS) -dtb $(QEMU_DTB_PATH) -kernel $(BOOTLOADER_BIN) -initrd $(INITRD_PATH)

bootloader_gdb: $(BOOTLOADER_BIN) $(KERNEL_BIN) cpio
$(call color_header, "Launching QEMU in background")
$(EXEC_QEMU) $(QEMU_TTY_DEBUG_ARGS) $(QEMU_DTB_PATH) -kernel $(BOOTLOADER_BIN) -initrd $(INITRD_PATH)

$(USER_PROG_IMG):
make -C $(USER_PROG) all

cpio: initramfs/* $(USER_PROG_IMG)
$(call color_header, "Creating initramfs")
cp $(USER_PROG_IMG) initramfs/
cd initramfs && find . | cpio -H newc -o > ../initramfs.cpio

clean:
make -C $(KERNEL_PATH) clean
make -C $(KERNEL_PATH) clean
-rm -r target
-rm $(KERNEL_BIN)
-rm $(BOOTLOADER_BIN)
-rm $(INITRD_PATH)
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# OSC2024

| Github Account | Student ID | Name |
|----------------|------------|---------------|
| cfmc30 | 109350078 | Erh-Tai Huang |

## Requirements

- Install Rust
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```

- Tool Chain
```
cargo install cargo-binutils rustfilt
```

- Others are specified in [rust-toolchain.toml](rust-toolchain.toml) which will be configured by cargo.

## Things that can be improved

- The structure of the project
- Rust code but with C style
- String with fixed size

## Build

```
make
```

## Test With QEMU

```
make kernel_qemu
```
25 changes: 25 additions & 0 deletions bootloader/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions bootloader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "bootloader"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.release]
lto = true


[features]
default = []
bsp_rpi3 = []

# specify bin
[[bin]]
name = "bootloader"
path = "src/main.rs"

[dependencies]
driver = { path = "../driver" }


# Platform specific dependencies
[target.'cfg(target_arch = "aarch64")'.dependencies]
aarch64-cpu = {version = "9.x.x"}

64 changes: 64 additions & 0 deletions bootloader/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
BSP = rpi3

TARGET = aarch64-unknown-none-softfloat
BL_BIN = bootloader.img

OBJDUMP_BINARY = aarch64-none-elf-objdump
NM_BINARY = aarch64-none-elf-mn
READELF_BINARY = aarch64-none-elf-readelf

LD_SCRIPT_PATH = $(shell pwd)/src/bsp/raspberrypi
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53

export LD_SCRIPT_PATH

BL_MANIFEST = Cargo.toml
BL_LINKER_SCRIPT = bootloader.ld
LAST_BUILD_CONFIG = target/$(TARGET).build_config

BL_ELF = ../target/$(TARGET)/release/bootloader

# parses cargo's dep-info file.
BL_ELF_DEPS = $(filter-out %: ,$(file < $(BL_ELF).d)) $(BL_MANIFEST) $(LAST_BUILD_CONFIG)


# command building blocks

RUSTFLAGS = $(RUSTC_MISC_ARGS) \
-C link-arg=--library-path=$(LD_SCRIPT_PATH) \
-C link-arg=--script=$(BL_LINKER_SCRIPT)


#RUSTFLAGS_PEDANTIC = $(RUSTFLAGS) \
# -D warnings \
# -D missing_docs

RUSTFLAGS_PEDANTIC = $(RUSTFLAGS)
# -D warnings \
# -D missing_docs

FEATURES = --features bsp_$(BSP)
COMPILER_ARGS = --target=$(TARGET) \
$(FEATURES) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS) --bin bootloader
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)


.PHONY: all doc qemu clippy clean readelf objdump nm check

all: $(BL_ELF)

$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)

$(BL_ELF): $(BL_ELF_DEPS)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

clean:
-rm -r target
-rm $(BL_BIN)

39 changes: 39 additions & 0 deletions bootloader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# OSC2024

| Github Account | Student ID | Name |
|----------------|------------|---------------|
| cfmc30 | 109350078 | Erh-Tai Huang |

## Requirements

- Install Rust
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```

- Tool Chain
```
cargo install cargo-binutils rustfilt
```

- Others are specified in [rust-toolchain.toml](rust-toolchain.toml) which will be configured by cargo.

## Things that can be improved

- The structure of the project
- Rust code but with C style
- String with fixed size

## Build

```
make
```

## Test With QEMU

```
make qemu
```
21 changes: 21 additions & 0 deletions bootloader/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::{env, fs, process};

fn main() {
let ld_script_path = match env::var("LD_SCRIPT_PATH") {
Ok(var) => var,
_ => process::exit(0),
};

let files = fs::read_dir(ld_script_path).unwrap();
files
.filter_map(Result::ok)
.filter(|d| {
if let Some(e) = d.path().extension() {
e == "ld"
}
else {
false
}
})
.for_each(|f| println!("cargo:rerun-if-changed={}", f.path().display()));
}
Loading