mirror of
				https://github.com/openhwgroup/cvw
				synced 2025-02-11 06:05:49 +00:00 
			
		
		
		
	Added functions to read registers and print information on failure. Also added a getTime function for a pretty boot display.
This commit is contained in:
		
							parent
							
								
									906fa73747
								
							
						
					
					
						commit
						3fde6c13f7
					
				
							
								
								
									
										19
									
								
								fpga/zsbl/fail.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								fpga/zsbl/fail.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
#include "fail.h"
 | 
			
		||||
#include "uart.h"
 | 
			
		||||
#include "riscv.h"
 | 
			
		||||
#include "time.h"
 | 
			
		||||
 | 
			
		||||
void fail() {
 | 
			
		||||
  // Get address that led to failure
 | 
			
		||||
  register uint64_t addr;
 | 
			
		||||
  asm volatile ("mv %0, ra" : "=r"(addr) : : "memory"); 
 | 
			
		||||
 | 
			
		||||
  // Print message
 | 
			
		||||
  print_time();
 | 
			
		||||
  println_with_addr("Failed at: 0x", addr);
 | 
			
		||||
  
 | 
			
		||||
  // Loop forever
 | 
			
		||||
  while(1) {
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										4
									
								
								fpga/zsbl/fail.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								fpga/zsbl/fail.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
void fail();
 | 
			
		||||
							
								
								
									
										29
									
								
								fpga/zsbl/riscv.S
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								fpga/zsbl/riscv.S
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
.section .text
 | 
			
		||||
.globl read_mcycle
 | 
			
		||||
.type read_mcycle, @function
 | 
			
		||||
read_mcycle:
 | 
			
		||||
    csrr a0, mcycle
 | 
			
		||||
    ret
 | 
			
		||||
 | 
			
		||||
.section .text
 | 
			
		||||
.globl get_ra
 | 
			
		||||
.type get_ra, @function
 | 
			
		||||
get_ra:
 | 
			
		||||
    mv a0, ra
 | 
			
		||||
    ret
 | 
			
		||||
 | 
			
		||||
.section .text
 | 
			
		||||
.globl set_status_fs
 | 
			
		||||
.type set_status_fs, @function    
 | 
			
		||||
set_status_fs:
 | 
			
		||||
    lui t1, 0x6
 | 
			
		||||
    csrs mstatus, t1
 | 
			
		||||
    ret
 | 
			
		||||
 | 
			
		||||
.section .text
 | 
			
		||||
.globl clear_status_fs
 | 
			
		||||
.type clear_status_fs, @function 
 | 
			
		||||
clear_status_fs:
 | 
			
		||||
    lui t1, 0x6
 | 
			
		||||
    csrc mstatus, t1
 | 
			
		||||
    ret
 | 
			
		||||
							
								
								
									
										7
									
								
								fpga/zsbl/riscv.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								fpga/zsbl/riscv.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
uint64_t read_mcycle();
 | 
			
		||||
uint64_t get_ra();
 | 
			
		||||
void set_status_fs();
 | 
			
		||||
void clear_status_fs();
 | 
			
		||||
							
								
								
									
										20
									
								
								fpga/zsbl/time.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								fpga/zsbl/time.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
#include "time.h"
 | 
			
		||||
#include "boot.h"
 | 
			
		||||
#include "riscv.h"
 | 
			
		||||
#include "uart.h"
 | 
			
		||||
 | 
			
		||||
float getTime() {
 | 
			
		||||
  set_status_fs();
 | 
			
		||||
  float numCycles = (float)read_mcycle();
 | 
			
		||||
  float ret = numCycles/SYSTEMCLOCK;
 | 
			
		||||
  // clear_status_fs();
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void print_time() {
 | 
			
		||||
  print_uart("[");
 | 
			
		||||
  set_status_fs();
 | 
			
		||||
  print_uart_float(getTime(),5);
 | 
			
		||||
  clear_status_fs();
 | 
			
		||||
  print_uart("] ");
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								fpga/zsbl/time.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								fpga/zsbl/time.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
float getTime();
 | 
			
		||||
void print_time();
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user