forked from Godones/rCoreloongArch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[build] | ||
target = "loongarch64-unknown-linux-gnu" | ||
[target.loongarch64-unknown-linux-gnu] | ||
linker = "loongarch64-unknown-linux-gnu-gcc" | ||
##rustflags = ["-C", "target-feature=+crt-static"] | ||
# | ||
#[target.'cfg(target_os = "linux")'] | ||
##rustflags = ["-C", "link-arg=-nostartfiles"] | ||
#rustflags = [ | ||
# "-Clink-arg=-Tsrc/linker.ld", "-Cforce-frame-pointers=yes" | ||
#] | ||
[profile.dev] | ||
panic = "abort" #关闭默认的panic栈回溯功能,裸机环境没有这个功能,直接abort | ||
|
||
[profile.release] | ||
panic = "abort" #关闭默认的panic栈回溯功能,裸机环境没有这个功能,直接abort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "loongrCore" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
TARGET := mips64el-unknown-linux-muslabi64 | ||
MODE := release | ||
|
||
KERNEL_ELF := target/$(TARGET)/$(MODE)/loongrCore | ||
KERNEL_BIN := $(KERNEL_ELF).bin | ||
DISASM_TMP := target/$(TARGET)/$(MODE)/asm | ||
INFO := DEBUG | ||
#文件模拟块设备 | ||
FS_IMG := ../user/target/$(TARGET)/$(MODE)/fs.img | ||
# BOARD | ||
BOARD ?= qemu | ||
SBI ?= rustsbi | ||
BOOTLOADER := ../loongarch_bios_0310.bin | ||
|
||
#内核入口地址 | ||
|
||
|
||
# 二进制数据转化 | ||
OBJDUMP := rust-objdump --arch-name=riscv64 | ||
OBJCOPY := rust-objcopy --binary-architecture=riscv64 | ||
|
||
# Disassembly | ||
DISASM ?= -x | ||
|
||
build: $(KERNEL_BIN) | ||
|
||
env: | ||
(rustup target list | grep "mips64el-unknown-linux-muslabi64 (installed)") || rustup target add $(TARGET) | ||
cargo install cargo-binutils | ||
rustup component add rust-src | ||
rustup component add llvm-tools-preview | ||
|
||
$(KERNEL_BIN): kernel | ||
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@ | ||
|
||
kernel: | ||
@#cd ../user && make build | ||
@#cd ../fs-test && make run | ||
@echo Platform: $(BOARD) | ||
@cargo build --release | ||
|
||
|
||
clean: | ||
@cargo clean | ||
|
||
disasm: kernel | ||
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) | less | ||
|
||
disasm-vim: kernel | ||
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) > $(DISASM_TMP) | ||
@vim $(DISASM_TMP) | ||
@rm $(DISASM_TMP) | ||
|
||
run: run-inner | ||
|
||
doc: | ||
@cargo doc --open --features "board_$(BOARD)" --features"$(INFO)" --no-deps | ||
|
||
run-inner: build | ||
ifeq ($(BOARD),qemu) | ||
qemu-system-loongarch64 \ | ||
-nographic \ | ||
-vga none \ | ||
-bios $(BOOTLOADER) | ||
-kernel $(KERNEL_BIN) | ||
endif | ||
|
||
debug: build | ||
@tmux new-session -d \ | ||
"qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -s -S" && \ | ||
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \ | ||
tmux -2 attach-session -d | ||
|
||
.PHONY: build env kernel clean disasm disasm-vim run-inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::env; | ||
use std::path::Path; | ||
use std::fs; | ||
use std::include_bytes; | ||
use std::io::Write; | ||
|
||
fn main() { | ||
let outdir = env::var("OUT_DIR").unwrap(); | ||
let link_script = Path::new(&outdir).join("link.lds"); | ||
let mut script = fs::File::create(&link_script).unwrap(); | ||
script.write_all(include_bytes!("linker.ld")).unwrap(); | ||
println!("cargo:rustc-link-arg=-T{}", &link_script.display()); | ||
println!("cargo:rustc-link-arg=-nostdlib");//关闭gcc的默认链接 | ||
// println!("cargo:rustc-link-arg=-no-pie"); //rust默认连接到Scrt1.o,使用动态链接 | ||
//println!("cargo:rustc-link-arg=-Wl,-Map=rust.map"); | ||
println!("cargo:rerun-if-change=linker.ld"); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ENTRY(_start) | ||
|
||
KERNEL_BEGIN = 0x10000000000; | ||
|
||
SECTIONS { | ||
. = KERNEL_BEGIN; | ||
|
||
.rodata ALIGN(4K): { | ||
*(.rodata .rodata.*) | ||
} | ||
|
||
.text ALIGN(4K): { | ||
*(.text .text.*) | ||
} | ||
|
||
.data ALIGN(4K): { | ||
*(.data .data.*) | ||
*(.sdata .sdata.*) | ||
} | ||
|
||
.got ALIGN(4K): { | ||
*(.got .got.*) | ||
} | ||
|
||
.bss ALIGN(4K): { | ||
*(.bss .bss.*) | ||
*(.sbss .sbss.*) | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::panic::PanicInfo; | ||
|
||
/// 这个函数将在 panic 时被调用 | ||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
loop {} | ||
} | ||
#[no_mangle] | ||
pub extern "C" fn _start() -> ! { | ||
loop {} | ||
} | ||
|
||
// fn main(){ | ||
// | ||
// } |