riscv_baremetal.git
2 months agoREADME.md: created README
Kit Rhett Aultman [Sun, 30 Jun 2024 05:26:12 +0000 (01:26 -0400)]
README.md: created README

Basic statement of goals, current requirements to run, and some notes.

2 months agomain/console: console abstraction and print macros
Kit Rhett Aultman [Sun, 30 Jun 2024 05:00:43 +0000 (01:00 -0400)]
main/console: console abstraction and print macros

This commit does a bit of a cleanup and re-org of the UART code so that
code doesn't need to create and carry around a reference to the UART to
print to the console.  This is now available through print!() and
println!()

As with the prior commit, this was heavily informed by Meyer Zinn's
excellent blog posts on bare-metal Rust, specifically this one:
https://meyerzinn.tech/posts/2023/03/08/p1-printing-and-allocating/

The idea here is to basically create a singleton Console object and then
only access it behind the print!() and println!() macros.  Since the
macros are designed to be used anywhere, they hide the interactions with
a global singleton which performs the debug outputs.

Even though I likely shouldn't have, I also did a rustfmt to clean up
syntax here.  Ah, well.

2 months agoHello world for qemu serial
Kit Rhett Aultman [Mon, 24 Jun 2024 04:06:17 +0000 (00:06 -0400)]
Hello world for qemu serial

This commit establishes the overall project structure needed for doing a bare
metal executive on RISC-V.  This currently supports the qemu risc64 emulator
because that is a target I can develop across multiple environments as I have
the free time.

This contains:
* Basic project structure
* rustc cross-compilation to riscv64-unknown-none-elf target
* Cargo integration for running qemu
* linking scripts for the qemu riscv64 virt "board" memory layout
* do-nothing panic handler
* _start function that contains the minimal RISC-V initialization: setting up
  the global pointer (gp), reserving a stack, and clearing the bss region
* Very simple use of the uart_16550 crate to print a "Hello world" message

This all came together mostly in an afternoon's work and wouldn't have been
possible without these exceptional resources:

"Running Rust code on RISC-V in Qemu"
https://meyerzinn.tech/posts/2023/03/05/running-rust-code-on-risc-v-in-qemu/

"RISC-V from scratch 2: Hardware layouts, linker scripts, and C runtimes"
https://twilco.github.io/riscv-from-scratch/2019/04/27/riscv-from-scratch-2.html