os-workshop

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

commit 9768a2b62981aacbd0e9a92087cb7116d5ec8e17
parent 21ef5111f4ced2aa63a2c18c97d47750b966e3dc
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 22 Apr 2022 11:16:11 -0700

samples: mandelbrot and info

Diffstat:
Amisc/info.c | 19+++++++++++++++++++
Amisc/mandelbrot.c | 32++++++++++++++++++++++++++++++++
Aproject/info.mk | 5+++++
Aproject/mandelbrot.mk | 5+++++
4 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/misc/info.c b/misc/info.c @@ -0,0 +1,19 @@ +// Copyright 2022, Brian Swetland <swetland@frotz.net> +// Licensed under the Apache License, Version 2.0 + +#include <hw/debug.h> +#include <hw/riscv.h> + +void main(void) { + 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)); + + uint32_t n = csr_read(CSR_MISA); + xprintf("ISA: RV32"); + for (int i = 0; i < 26; i++) { + if (n & (1<<i)) xputc('A'+i); + } + xputc('\n'); +} diff --git a/misc/mandelbrot.c b/misc/mandelbrot.c @@ -0,0 +1,32 @@ +// Copyright 2022, Brian Swetland <swetland@frotz.net> +// Licensed under the Apache License, Version 2.0 + +#include <hw/debug.h> + +int main(int argc, char** argv) { + int top = 1000, bottom = -1000, ystep = 50; + int left = -2500, right = 1000, xstep = 30; + int maxiter = 1000; + + for (int y0 = top; y0 > bottom; y0 -= ystep) { + for (int x0 = left; x0 < right; x0 += xstep) { + int i = 0, x = 0, y = 0, ch = ' '; + while (i < maxiter) { + int x2 = x * x / 1000; + int y2 = y * y / 1000; + if ((x2 + y2) > 4000) { + ch = (i > 9) ? '@' : (i + '0'); + break; + } + y = 2 * x * y / 1000 + y0; + x = x2 - y2 + x0; + i++; + } + xputc(ch); + } + xputc('\n'); + } + + xprintf("Hello, Mandlebrot!\n"); + return 0; +} diff --git a/project/info.mk b/project/info.mk @@ -0,0 +1,5 @@ + +APP := info +SRC := hw/src/start.S misc/info.c +SRC += hw/src/debug.c $(LIBC_SRC) +include make/app.mk diff --git a/project/mandelbrot.mk b/project/mandelbrot.mk @@ -0,0 +1,5 @@ + +APP := mandelbrot +SRC := hw/src/start.S misc/mandelbrot.c +SRC += hw/src/debug.c $(LIBC_SRC) +include make/app.mk