Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Godones committed May 5, 2022
1 parent af5bb0a commit a95f3e5
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 0 deletions.
Empty file added .gitignore
Empty file.
Binary file added loongrCoreOs/loongarch_bios_0310.bin
Binary file not shown.
16 changes: 16 additions & 0 deletions loongrCoreOs/loongrCore/.cargo/config
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
1 change: 1 addition & 0 deletions loongrCoreOs/loongrCore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
8 changes: 8 additions & 0 deletions loongrCoreOs/loongrCore/.idea/.gitignore

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

11 changes: 11 additions & 0 deletions loongrCoreOs/loongrCore/.idea/loongrCore.iml

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

8 changes: 8 additions & 0 deletions loongrCoreOs/loongrCore/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions loongrCoreOs/loongrCore/.idea/vcs.xml

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

7 changes: 7 additions & 0 deletions loongrCoreOs/loongrCore/Cargo.lock

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

8 changes: 8 additions & 0 deletions loongrCoreOs/loongrCore/Cargo.toml
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]
74 changes: 74 additions & 0 deletions loongrCoreOs/loongrCore/Makefile
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
17 changes: 17 additions & 0 deletions loongrCoreOs/loongrCore/build.rs
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 added loongrCoreOs/loongrCore/efi-virtio.rom
Binary file not shown.
29 changes: 29 additions & 0 deletions loongrCoreOs/loongrCore/linker.ld
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 added loongrCoreOs/loongrCore/os.bin
Binary file not shown.
18 changes: 18 additions & 0 deletions loongrCoreOs/loongrCore/src/main.rs
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(){
//
// }

0 comments on commit a95f3e5

Please sign in to comment.