os-workshop

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

commit 287dae4eb9d2945c6497426486676e5a8a0071f5
parent 8f4ca9f20812474b2a1ddad67296c89b920b1015
Author: Brian Swetland <swetland@frotz.net>
Date:   Thu, 12 May 2022 15:59:40 -0700

ex00-hello: hello world program

Diffstat:
Aexample/ex00-hello.c | 32++++++++++++++++++++++++++++++++
Aproject/ex00-hello.app.mk | 6++++++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/example/ex00-hello.c b/example/ex00-hello.c @@ -0,0 +1,32 @@ +// Copyright 2022, Brian Swetland <swetland@frotz.net> +// Licensed under the Apache License, Version 2.0 + +#include <hw/riscv.h> +#include <hw/context.h> +#include <hw/debug.h> +#include <hw/intrinsics.h> + +// if an exception occurs, dump register state and halt +void exception_handler(eframe_t *ef) { + xprintf("\n** SUPERVISOR EXCEPTION **\n"); + xprint_s_exception(ef); + xprintf("\nHALT\n"); + for (;;) ; +} + +// no interrupts to handle +void interrupt_handler(void) { + xprintf("WAT?"); + for (;;) ; +} + +void start(void) { + xprintf("Example 00 - Hello\n"); + + // set trap vector to trap_entry() in trap-entry-single.S + // it will call exception_handler() or interrupt_handler() + csr_write(CSR_STVEC, (uintptr_t) trap_entry); + + // this is illegal in supervisor mode + csr_write(CSR_MTVEC, 42); +} diff --git a/project/ex00-hello.app.mk b/project/ex00-hello.app.mk @@ -0,0 +1,6 @@ +MOD_NAME := ex00-hello +MOD_SRC := hw/src/start.S hw/src/trap-entry-single-stack.S +MOD_SRC += example/ex00-hello.c +MOD_SRC += hw/src/print-exception.c hw/src/debug-printf.c hw/src/debug-io.c +MOD_LIB := c +include make/app.mk