79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
 | 
						|
 | 
						|
#include "context.h"
 | 
						|
#include "head.h"
 | 
						|
 | 
						|
void interrupt_entry(uint32_t irq_num) {
 | 
						|
  my_printf("interrupt_entry %d\n", irq_num);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
static const char *g_fault_cause[]={
 | 
						|
  "Instruction address misaligned",// 0
 | 
						|
  "Instruction access fault",// 1
 | 
						|
  "Illegal instruction",// 2
 | 
						|
  "Breakpoint",// 3
 | 
						|
  "Load address misaligned",// 4
 | 
						|
  "Load access fault",// 5
 | 
						|
  "Store address misaligned",// 6
 | 
						|
  "Store access fault",// 7
 | 
						|
  "Environment call from U-mode",// 8
 | 
						|
  "Environment call from S-mode",// 9
 | 
						|
  "",
 | 
						|
  "Environment call from M-mode",// 11
 | 
						|
  "Instruction page fault",// 12
 | 
						|
  "Load page fault",// 13
 | 
						|
  "",
 | 
						|
  "Store page fault",// 15
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void trap_entry(uint32_t irq_num, stack_context *stack) {
 | 
						|
  my_printf("fault reason is %s\n", g_fault_cause[irq_num]);
 | 
						|
  my_printf("x1(ra):    %08x\n", stack->ra);
 | 
						|
  my_printf("x2(sp):    %08x\n", stack->sp);
 | 
						|
  my_printf("x3(gp):    %08x\n", stack->gp);
 | 
						|
  my_printf("x4(tp):    %08x\n", stack->tp);
 | 
						|
  my_printf("x5(t0):    %08x\n", stack->t0);
 | 
						|
  my_printf("x6(t1):    %08x\n", stack->t1);
 | 
						|
  my_printf("x7(t2):    %08x\n", stack->t2);
 | 
						|
  my_printf("x8(s0|fp): %08x\n", stack->s0);
 | 
						|
  my_printf("x9(s1):    %08x\n", stack->s1);
 | 
						|
  my_printf("x10(a0):   %08x\n", stack->a0);
 | 
						|
  my_printf("x11(a1):   %08x\n", stack->a1);
 | 
						|
  my_printf("x12(a2):   %08x\n", stack->a2);
 | 
						|
  my_printf("x13(a3):   %08x\n", stack->a3);
 | 
						|
  my_printf("x14(a4):   %08x\n", stack->a4);
 | 
						|
  my_printf("x15(a5):   %08x\n", stack->a5);
 | 
						|
  my_printf("x16(a6):   %08x\n", stack->a6);
 | 
						|
  my_printf("x17(a7):   %08x\n", stack->a7);
 | 
						|
  my_printf("x18(s2):   %08x\n", stack->s2);
 | 
						|
  my_printf("x19(s3):   %08x\n", stack->s3);
 | 
						|
  my_printf("x20(s4):   %08x\n", stack->s4);
 | 
						|
  my_printf("x21(s5):   %08x\n", stack->s5);
 | 
						|
  my_printf("x22(s6):   %08x\n", stack->s6);
 | 
						|
  my_printf("x23(s7):   %08x\n", stack->s7);
 | 
						|
  my_printf("x24(s8):   %08x\n", stack->s8);
 | 
						|
  my_printf("x25(s9):   %08x\n", stack->s9);
 | 
						|
  my_printf("x26(s10):  %08x\n", stack->s10);
 | 
						|
  my_printf("x27(s11):  %08x\n", stack->s11);
 | 
						|
  my_printf("x28(t3):   %08x\n", stack->t3);
 | 
						|
  my_printf("x29(t4):   %08x\n", stack->t4);
 | 
						|
  my_printf("x30(t5):   %08x\n", stack->t5);
 | 
						|
  my_printf("x31(t6):   %08x\n", stack->t6);
 | 
						|
  my_printf("mstatus:   %08x\n", stack->mstatus);
 | 
						|
  my_printf("mepc:      %08x\n", stack->mepc);
 | 
						|
  // my_printf("mtval:     %08x\n", read_csr(mtval));
 | 
						|
 | 
						|
  // 函数调用错误,直接跳过这个函数
 | 
						|
  if(irq_num==1){
 | 
						|
    my_printf("skip the function call, return to %08x\n", stack->ra);
 | 
						|
    stack->mepc = stack->ra;
 | 
						|
  }
 | 
						|
 | 
						|
  // write_csr(mscratch, 0xffffffff);
 | 
						|
}
 |