os-workshop

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 2f3b11ec75c68279c91046161facfda8bc5ef638
parent 7d0ab3714f20e5cab1081cec8645f77c17f75a44
Author: Brian Swetland <swetland@frotz.net>
Date:   Sat, 23 Apr 2022 18:19:34 -0700

start: don't clobber device tree, don't be main

- qemu arranges for the device tree to be in a1
- pass that on to start and throw the sp in a0
- main() usually expects argc/argv

Diffstat:
Mhw/src/start.S | 5++---
Mmisc/info.c | 3++-
Mmisc/mandelbrot.c | 3+--
3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/src/start.S b/hw/src/start.S @@ -4,9 +4,8 @@ .globl _start _start: li sp, 0x81000000 - li a0, 0 - li a1, 0 - jal main + mv a0, sp + jal start .globl exit exit: diff --git a/misc/info.c b/misc/info.c @@ -4,11 +4,12 @@ #include <hw/debug.h> #include <hw/riscv.h> -void main(void) { +void start(uint32_t sp, uint32_t dtb) { xprintf("Hello?\n"); xprintf("MSTATUS %08x\n", csr_read(CSR_MSTATUS)); xprintf("MISA %08x\n", csr_read(CSR_MISA)); xprintf("MCYCLE %08x\n", csr_read(CSR_MCYCLE)); + xprintf("DeviceTree %08x\n", dtb); uint32_t n = csr_read(CSR_MISA); xprintf("ISA: RV32"); diff --git a/misc/mandelbrot.c b/misc/mandelbrot.c @@ -3,7 +3,7 @@ #include <hw/debug.h> -int main(int argc, char** argv) { +void start(void) { int top = 1000, bottom = -1000, ystep = 50; int left = -2500, right = 1000, xstep = 30; int maxiter = 1000; @@ -28,5 +28,4 @@ int main(int argc, char** argv) { } xprintf("Hello, Mandlebrot!\n"); - return 0; }