xref: /kvm-unit-tests/lib/arm/asm/processor.h (revision d95bd8f6c804027984dec6468a57cb47de556d19)
1 #ifndef _ASMARM_PROCESSOR_H_
2 #define _ASMARM_PROCESSOR_H_
3 /*
4  * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
5  *
6  * This work is licensed under the terms of the GNU LGPL, version 2.
7  */
8 #include <asm/ptrace.h>
9 
10 enum vector {
11 	EXCPTN_RST,
12 	EXCPTN_UND,
13 	EXCPTN_SVC,
14 	EXCPTN_PABT,
15 	EXCPTN_DABT,
16 	EXCPTN_ADDREXCPTN,
17 	EXCPTN_IRQ,
18 	EXCPTN_FIQ,
19 	EXCPTN_MAX,
20 };
21 
22 typedef void (*exception_fn)(struct pt_regs *);
23 extern void install_exception_handler(enum vector v, exception_fn fn);
24 
25 extern void show_regs(struct pt_regs *regs);
26 
27 static inline unsigned long current_cpsr(void)
28 {
29 	unsigned long cpsr;
30 	asm volatile("mrs %0, cpsr" : "=r" (cpsr));
31 	return cpsr;
32 }
33 
34 #define current_mode() (current_cpsr() & MODE_MASK)
35 
36 static inline unsigned int get_mpidr(void)
37 {
38 	unsigned int mpidr;
39 	asm volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (mpidr));
40 	return mpidr;
41 }
42 
43 /* Only support Aff0 for now, up to 4 cpus */
44 #define mpidr_to_cpu(mpidr) ((int)((mpidr) & 0xff))
45 
46 extern void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr);
47 extern bool is_user(void);
48 
49 #endif /* _ASMARM_PROCESSOR_H_ */
50