Simple hello world

This commit is contained in:
2023-10-28 16:46:38 +02:00
commit a179a01270
7 changed files with 98 additions and 0 deletions

6
.cargo/config Normal file
View File

@@ -0,0 +1,6 @@
[build]
target = "aarch64-unknown-none"
rustflags = [
"-C", "link-arg=-Taarch64-gem5.ld",
]

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

14
Cargo.toml Normal file
View File

@@ -0,0 +1,14 @@
[package]
name = "aarch64"
version = "0.1.0"
edition = "2021"
[dependencies]
aarch64-cpu = "9.4.0"
half = { version = "2.3.1", default-features = false }
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

14
aarch64-gem5.ld Normal file
View File

@@ -0,0 +1,14 @@
ENTRY(_start)
SECTIONS
{
. = 0x80000000;
.text.boot : { *(.text.boot) }
.text : { *(.text) }
.data : { *(.data) }
.rodata : { *(.rodata) }
.bss : { *(.bss) }
. = ALIGN(8);
. = . + 0x8000;
LD_STACK_PTR = .;
}

32
src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
#![no_std]
#![no_main]
use crate::uart::Uart0;
use core::sync::atomic::{self, Ordering};
use core::{arch::global_asm, fmt::Write, panic::PanicInfo};
mod uart;
global_asm!(include_str!("start.s"));
#[no_mangle]
pub extern "C" fn entry() -> ! {
let mut uart = Uart0 {};
for i in 0..3 {
writeln!(&mut uart, "Hello from Rust {i}!").unwrap();
}
loop {
atomic::compiler_fence(Ordering::SeqCst);
}
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
writeln!(Uart0, "{info}").unwrap();
loop {
atomic::compiler_fence(Ordering::SeqCst);
}
}

15
src/start.s Normal file
View File

@@ -0,0 +1,15 @@
.globl _start
.extern LD_STACK_PTR
.section ".text.boot"
_start:
ldr x30, =LD_STACK_PTR
mov sp, x30
bl entry
.equ PSCI_SYSTEM_OFF, 0x84000008
.globl system_off
system_off:
ldr x0, =PSCI_SYSTEM_OFF
hvc #0

16
src/uart.rs Normal file
View File

@@ -0,0 +1,16 @@
use core::{fmt::Write, ptr::write_volatile};
const UART0_ADDR: *mut u32 = 0x1c090000 as _;
pub struct Uart0;
impl Write for Uart0 {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
for &byte in s.as_bytes() {
unsafe {
write_volatile(UART0_ADDR, byte as _);
}
}
Ok(())
}
}