add klib header

This commit is contained in:
bingo 2017-05-31 16:52:40 +08:00
parent d934243b85
commit 574bb24f92
2 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,7 @@ DST_DIR ?= $(LIB_DIR)/build/$(ARCH)/
ARCHIVE ?= $(LIB_DIR)/build/$(NAME)-$(ARCH).a
INC_DIR += $(addsuffix /include/, $(addprefix $(AM_HOME)/libs/, $(LIBS)))
INC_DIR += $(AM_HOME)/libs/klib/include/
$(shell mkdir -p $(DST_DIR))

View File

@ -0,0 +1,32 @@
#include <am.h>
#include <klib.h>
uint get_cause() {
uint ret;
asm volatile("mfc0 %0, $13\n\t":"=r"(ret));
return ret;
}
uint get_epc() {
uint ret;
asm volatile("mfc0 %0, $14\n\t":"=r"(ret));
return ret;
}
void exception_handle() {
uint cause = get_cause();
uint epc = get_epc();
uint exccode = (cause >> 2) & 0x1f;
switch(exccode) {
case 4: printf("BadVAddr when loading @PC= 0x%x", epc); break;
case 5: printf("BadVAddr when storing @PC= 0x%x", epc); break;
case 10: printf("Invalid OPCODE @PC= 0x%x", epc); break;
default: printf("Unhandled exception, ExcCode = %d", exccode);
}
_halt(1);
}