initial
This commit is contained in:
commit
5443c61db2
13 changed files with 132 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/build
|
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
project(EOS0 CXX)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
Corrosion
|
||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||
GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here
|
||||
)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
|
||||
corrosion_import_crate(MANIFEST_PATH kernel/Cargo.toml)
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "kernel"
|
||||
version = "0.1.0"
|
2
Cargo.toml
Normal file
2
Cargo.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
workspace.members = ["kernel"]
|
||||
workspace.resolver = "2"
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
References:
|
||||
|
||||
- https://lowenware.com/blog/aarch64-bare-metal-program-in-rust/
|
14
aarch64-qemu.ld
Normal file
14
aarch64-qemu.ld
Normal file
|
@ -0,0 +1,14 @@
|
|||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x40080000;
|
||||
.text.boot : { *(.text.boot) }
|
||||
.text : { *(.text) }
|
||||
.data : { *(.data) }
|
||||
.rodata : { *(.rodata) }
|
||||
.bss : { *(.bss) }
|
||||
|
||||
. = ALIGN(8);
|
||||
. = . + 0x4000;
|
||||
LD_STACK_PTR = .;
|
||||
}
|
33
aarch64-unknown-none.json
Normal file
33
aarch64-unknown-none.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"arch": "aarch64",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
|
||||
"disable-redzone": true,
|
||||
"features": "+v8a,+strict-align,+neon,+fp-armv8",
|
||||
"linker": "rust-lld",
|
||||
"linker-flavor": "gnu-lld",
|
||||
"llvm-target": "aarch64-unknown-none",
|
||||
"max-atomic-width": 128,
|
||||
"panic-strategy": "abort",
|
||||
"pre-link-args": {
|
||||
"gnu": [
|
||||
"--fix-cortex-a53-843419"
|
||||
],
|
||||
"gnu-lld": [
|
||||
"--fix-cortex-a53-843419",
|
||||
"-Taarch64-qemu.ld"
|
||||
],
|
||||
"ld.lld": [
|
||||
"-Taarch64-qemu.ld"
|
||||
]
|
||||
},
|
||||
"relocation-model": "static",
|
||||
"stack-probes": {
|
||||
"kind": "inline"
|
||||
},
|
||||
"supported-sanitizers": [
|
||||
"kcfi",
|
||||
"kernel-address"
|
||||
],
|
||||
"target-pointer-width": "64"
|
||||
}
|
12
kernel/Cargo.toml
Normal file
12
kernel/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "kernel"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
profile.dev.panic = "abort"
|
||||
profile.release.panic = "abort"
|
||||
|
||||
# [lib]
|
||||
# crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
19
kernel/src/main.rs
Normal file
19
kernel/src/main.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::{arch::global_asm, ptr};
|
||||
|
||||
mod panic;
|
||||
|
||||
global_asm!(include_str!("start.s"));
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn not_main() {
|
||||
const UART0: *mut u8 = 0x0900_0000 as *mut u8;
|
||||
let out_str = b"AArch64 Bare Metal";
|
||||
for byte in out_str {
|
||||
unsafe {
|
||||
ptr::write_volatile(UART0, *byte);
|
||||
}
|
||||
}
|
||||
}
|
6
kernel/src/panic.rs
Normal file
6
kernel/src/panic.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use core::panic::PanicInfo;
|
||||
|
||||
#[panic_handler]
|
||||
fn on_panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
15
kernel/src/start.s
Normal file
15
kernel/src/start.s
Normal file
|
@ -0,0 +1,15 @@
|
|||
.globl _start
|
||||
.extern LD_STACK_PTR
|
||||
|
||||
.section ".text.boot"
|
||||
|
||||
_start:
|
||||
ldr x30, =LD_STACK_PTR
|
||||
mov sp, x30
|
||||
bl not_main
|
||||
|
||||
.equ PSCI_SYSTEM_OFF, 0x84000008
|
||||
.globl system_off
|
||||
system_off:
|
||||
ldr x0, =PSCI_SYSTEM_OFF
|
||||
hvc #0
|
5
run.sh
Executable file
5
run.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
exec qemu-system-aarch64 -machine virt \
|
||||
-m 1024M \
|
||||
-cpu cortex-a53 \
|
||||
-nographic \
|
||||
-kernel target/aarch64-unknown-none/debug/kernel
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
|
@ -0,0 +1 @@
|
|||
nightly
|
Loading…
Reference in a new issue