xref: /kvm-unit-tests/lib/arm/asm/thread_info.h (revision 10594e42ecdda42e5eff703439b7079a0c93e8e5)
1 #ifndef _ASMARM_THREAD_INFO_H_
2 #define _ASMARM_THREAD_INFO_H_
3 /*
4  * Adapted from arch/arm64/include/asm/thread_info.h
5  *
6  * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@redhat.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2.
9  */
10 #include <asm/page.h>
11 
12 #define MIN_THREAD_SHIFT	14	/* THREAD_SIZE == 16K */
13 #if PAGE_SHIFT > MIN_THREAD_SHIFT
14 #define THREAD_SHIFT		PAGE_SHIFT
15 #define THREAD_SIZE		PAGE_SIZE
16 #define THREAD_MASK		PAGE_MASK
17 #else
18 #define THREAD_SHIFT		MIN_THREAD_SHIFT
19 #define THREAD_SIZE		(_AC(1,UL) << THREAD_SHIFT)
20 #define THREAD_MASK		(~(THREAD_SIZE-1))
21 #endif
22 
23 #ifndef __ASSEMBLY__
24 #include <asm/processor.h>
25 #include <alloc.h>
26 
27 #ifdef __arm__
28 #include <asm/ptrace.h>
29 /*
30  * arm needs room left at the top for the exception stacks,
31  * and the stack needs to be 8-byte aligned
32  */
33 #define THREAD_START_SP \
34 	((THREAD_SIZE - (sizeof(struct pt_regs) * 8)) & ~7)
35 #else
36 #define THREAD_START_SP		(THREAD_SIZE - 16)
37 #endif
38 
39 static inline void *thread_stack_alloc(void)
40 {
41 	void *sp = memalign(THREAD_SIZE, THREAD_SIZE);
42 	return sp + THREAD_START_SP;
43 }
44 
45 #define TIF_USER_MODE		(1U << 0)
46 
47 struct thread_info {
48 	int cpu;
49 	unsigned int flags;
50 #ifdef __arm__
51 	exception_fn exception_handlers[EXCPTN_MAX];
52 #else
53 	vector_fn vector_handlers[VECTOR_MAX];
54 	exception_fn exception_handlers[VECTOR_MAX][EC_MAX];
55 #endif
56 	char ext[0];		/* allow unit tests to add extended info */
57 };
58 
59 static inline struct thread_info *thread_info_sp(unsigned long sp)
60 {
61 	return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
62 }
63 
64 register unsigned long current_stack_pointer asm("sp");
65 
66 static inline struct thread_info *current_thread_info(void)
67 {
68 	return thread_info_sp(current_stack_pointer);
69 }
70 
71 extern void thread_info_init(struct thread_info *ti, unsigned int flags);
72 
73 #endif /* !__ASSEMBLY__ */
74 #endif /* _ASMARM_THREAD_INFO_H_ */
75