xref: /kvm-unit-tests/lib/powerpc/processor.c (revision 52266791750d89b7f4ab6bad4d42de0056e4fb32)
1 /*
2  * processor control and status function
3  */
4 
5 #include <libcflat.h>
6 #include <asm/processor.h>
7 #include <asm/ptrace.h>
8 
9 static struct {
10 	void (*func)(struct pt_regs *, void *data);
11 	void *data;
12 } handlers[16];
13 
14 void handle_exception(int trap, void (*func)(struct pt_regs *, void *),
15 		      void * data)
16 {
17 	trap >>= 8;
18 
19 	if (trap < 16) {
20 		handlers[trap].func = func;
21 		handlers[trap].data = data;
22 	}
23 }
24 
25 void do_handle_exception(struct pt_regs *regs)
26 {
27 	unsigned char v;
28 
29 	v = regs->trap >> 8;
30 
31 	if (v < 16 && handlers[v].func) {
32 		handlers[v].func(regs, handlers[v].data);
33 		return;
34 	}
35 
36 	printf("unhandled cpu exception 0x%lx\n", regs->trap);
37 	abort();
38 }
39