os-workshop

same materials and sample source for RV32 OS projects
git clone http://frotz.net/git/os-workshop.git
Log | Files | Refs

ex00-hello.c (783B)


      1 // Copyright 2022, Brian Swetland <swetland@frotz.net>
      2 // Licensed under the Apache License, Version 2.0
      3 
      4 #include <hw/riscv.h>
      5 #include <hw/context.h>
      6 #include <hw/debug.h>
      7 #include <hw/intrinsics.h>
      8 
      9 // if an exception occurs, dump register state and halt
     10 void exception_handler(eframe_t *ef) {
     11 	xprintf("\n** SUPERVISOR EXCEPTION **\n");
     12 	xprint_s_exception(ef);
     13 	xprintf("\nHALT\n");
     14 	for (;;) ;
     15 }
     16 
     17 // no interrupts to handle
     18 void interrupt_handler(void) {
     19 	xprintf("WAT?");
     20 	for (;;) ;
     21 }
     22 
     23 void start(void) {
     24 	xprintf("Example 00 - Hello\n");
     25 
     26 	// set trap vector to trap_entry() in trap-entry-single.S
     27 	// it will call exception_handler() or interrupt_handler()
     28 	csr_write(CSR_STVEC, (uintptr_t) trap_entry);
     29 
     30 	// this is illegal in supervisor mode
     31 	csr_write(CSR_MTVEC, 42);
     32 }