Initial commit

This commit is contained in:
2025-09-03 14:56:28 +03:00
commit 3087975833
28 changed files with 1550 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
[target.riscv32i-unknown-none-elf]
rustflags = ["-Clink-arg=-Tlink.ld"]
[build]
target = "riscv32i-unknown-none-elf"
[unstable]
build-std = ["core"]
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "firmware"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "firmware"
version = "0.1.0"
edition = "2024"
[dependencies]
+35
View File
@@ -0,0 +1,35 @@
ENTRY(__entry);
SECTIONS {
. = 0x1000;
.text : {
*(.text.entry)
*(.text*)
}
. = ALIGN(4);
.rodata : {
*(.rodata*)
. = ALIGN(4);
}
. = 0x20000;
.vectors : {
*(.text.vectors)
}
. = 0x20000000;
.data : {
*(.data*)
}
. = ALIGN(16);
.bss : {
*(.bss*)
}
}
+22
View File
@@ -0,0 +1,22 @@
.global __entry
.pushsection .text.entry
.option push
.option norvc
__entry:
la sp, stack_top
jal {firmware_main}
.option pop
.popsection // .text.entry
.pushsection .text.vectors
__vector:
j .
.popsection // .text.vectors
.pushsection .bss
stack_bottom:
.skip 2048
stack_top:
.popsection // .bss
+42
View File
@@ -0,0 +1,42 @@
#![allow(unsafe_op_in_unsafe_fn)]
#![no_std]
#![no_main]
use core::{arch::global_asm, fmt, panic::PanicInfo};
#[panic_handler]
fn panic_handler(_pi: &PanicInfo) -> ! {
loop {}
}
struct D;
const DEBUG_BASE: usize = 0x1000_0000;
impl fmt::Write for D {
fn write_str(&mut self, s: &str) -> fmt::Result {
let ptr: *mut u32 = core::ptr::with_exposed_provenance_mut(DEBUG_BASE);
for byte in s.bytes() {
unsafe { ptr.write_volatile(byte as u32) };
}
Ok(())
}
}
unsafe extern "C" fn firmware_main() -> ! {
use fmt::Write;
let mut d = D;
for i in 0..10 {
write!(d, "Hello {i}").ok();
write!(d, "\n").ok();
}
loop {
// TODO pause/system/fence instruction not implemented
// core::hint::spin_loop();
core::arch::asm!("nop");
}
}
global_asm!(include_str!("entry.S"), firmware_main = sym firmware_main);