1 /* 2 * processor control and status function 3 */ 4 5 #include <libcflat.h> 6 #include <asm/processor.h> 7 #include <asm/ptrace.h> 8 #include <asm/setup.h> 9 #include <asm/barrier.h> 10 11 static struct { 12 void (*func)(struct pt_regs *, void *data); 13 void *data; 14 } handlers[16]; 15 16 void handle_exception(int trap, void (*func)(struct pt_regs *, void *), 17 void * data) 18 { 19 trap >>= 8; 20 21 if (trap < 16) { 22 handlers[trap].func = func; 23 handlers[trap].data = data; 24 } 25 } 26 27 void do_handle_exception(struct pt_regs *regs) 28 { 29 unsigned char v; 30 31 v = regs->trap >> 8; 32 33 if (v < 16 && handlers[v].func) { 34 handlers[v].func(regs, handlers[v].data); 35 return; 36 } 37 38 printf("unhandled cpu exception 0x%lx\n", regs->trap); 39 abort(); 40 } 41 42 void delay(uint64_t cycles) 43 { 44 uint64_t start = get_tb(); 45 46 while ((get_tb() - start) < cycles) 47 cpu_relax(); 48 } 49 50 void udelay(uint64_t us) 51 { 52 delay((us * tb_hz) / 1000000); 53 } 54