blob: 6af68edfa53abc7a72789f23eb7f90efb8a6b0b5 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Russell King4baa9922008-08-02 10:55:55 +01003 * arch/arm/include/asm/processor.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Copyright (C) 1995-1999 Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#ifndef __ASM_ARM_PROCESSOR_H
9#define __ASM_ARM_PROCESSOR_H
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#ifdef __KERNEL__
12
Will Deacon864232f2010-09-03 10:42:55 +010013#include <asm/hw_breakpoint.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/types.h>
Will Deacon27a84792013-07-02 12:10:42 +010016#include <asm/unified.h>
Vincenzo Frascino78c85162020-03-20 14:53:49 +000017#include <asm/vdso/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
David Howells922a70d2008-02-08 04:19:26 -080019#ifdef __KERNEL__
Lennert Buytenhek794baba2008-12-05 03:25:47 +010020#define STACK_TOP ((current->personality & ADDR_LIMIT_32BIT) ? \
David Howells922a70d2008-02-08 04:19:26 -080021 TASK_SIZE : TASK_SIZE_26)
22#define STACK_TOP_MAX TASK_SIZE
23#endif
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025struct debug_info {
Will Deacon864232f2010-09-03 10:42:55 +010026#ifdef CONFIG_HAVE_HW_BREAKPOINT
27 struct perf_event *hbp[ARM_MAX_HBP_SLOTS];
28#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070029};
30
31struct thread_struct {
32 /* fault info */
33 unsigned long address;
34 unsigned long trap_no;
35 unsigned long error_code;
36 /* debugging */
37 struct debug_info debug;
38};
39
Kees Cook08626a62017-08-16 14:09:13 -070040/*
41 * Everything usercopied to/from thread_struct is statically-sized, so
42 * no hardened usercopy whitelist is needed.
43 */
44static inline void arch_thread_struct_whitelist(unsigned long *offset,
45 unsigned long *size)
46{
47 *offset = *size = 0;
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define INIT_THREAD { }
51
52#define start_thread(regs,pc,sp) \
53({ \
Nicolas Pitre5e588112017-07-28 18:48:48 -040054 unsigned long r7, r8, r9; \
55 \
56 if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC)) { \
57 r7 = regs->ARM_r7; \
58 r8 = regs->ARM_r8; \
59 r9 = regs->ARM_r9; \
60 } \
Russell King59f0cb02008-10-27 11:24:09 +000061 memset(regs->uregs, 0, sizeof(regs->uregs)); \
Nicolas Pitre5e588112017-07-28 18:48:48 -040062 if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC) && \
63 current->personality & FDPIC_FUNCPTRS) { \
64 regs->ARM_r7 = r7; \
65 regs->ARM_r8 = r8; \
66 regs->ARM_r9 = r9; \
67 regs->ARM_r10 = current->mm->start_data; \
68 } else if (!IS_ENABLED(CONFIG_MMU)) \
69 regs->ARM_r10 = current->mm->start_data; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 if (current->personality & ADDR_LIMIT_32BIT) \
71 regs->ARM_cpsr = USR_MODE; \
72 else \
73 regs->ARM_cpsr = USR26_MODE; \
74 if (elf_hwcap & HWCAP_THUMB && pc & 1) \
75 regs->ARM_cpsr |= PSR_T_BIT; \
Catalin Marinas26584852009-05-30 14:00:18 +010076 regs->ARM_cpsr |= PSR_ENDSTATE; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 regs->ARM_pc = pc & ~1; /* pc */ \
78 regs->ARM_sp = sp; /* sp */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -070079})
80
81/* Forward declaration, a strange C thing */
82struct task_struct;
83
84/* Free all resources held by a thread. */
85extern void release_thread(struct task_struct *);
86
Kees Cook42a20f82021-09-29 15:02:14 -070087unsigned long __get_wchan(struct task_struct *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Al Viro815d5ec2006-01-12 01:05:57 -080089#define task_pt_regs(p) \
Al Viro32d39a92006-01-12 01:05:58 -080090 ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
Al Viro815d5ec2006-01-12 01:05:57 -080091
92#define KSTK_EIP(tsk) task_pt_regs(tsk)->ARM_pc
93#define KSTK_ESP(tsk) task_pt_regs(tsk)->ARM_sp
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Will Deacon27a84792013-07-02 12:10:42 +010095#ifdef CONFIG_SMP
96#define __ALT_SMP_ASM(smp, up) \
97 "9998: " smp "\n" \
98 " .pushsection \".alt.smp.init\", \"a\"\n" \
Ard Biesheuvel450abd32020-09-14 11:48:20 +030099 " .long 9998b - .\n" \
Will Deacon27a84792013-07-02 12:10:42 +0100100 " " up "\n" \
101 " .popsection\n"
102#else
103#define __ALT_SMP_ASM(smp, up) up
104#endif
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/*
107 * Prefetching support - only ARMv5.
108 */
109#if __LINUX_ARM_ARCH__ >= 5
110
111#define ARCH_HAS_PREFETCH
Nicolas Pitre02828842006-12-13 18:39:26 +0100112static inline void prefetch(const void *ptr)
113{
114 __asm__ __volatile__(
Nicolas Pitre16f719d2008-08-12 22:10:59 +0100115 "pld\t%a0"
Will Deacone744dff2013-06-26 16:47:35 +0100116 :: "p" (ptr));
Nicolas Pitre02828842006-12-13 18:39:26 +0100117}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Will Deacond8f57aa2013-06-26 17:03:40 +0100119#if __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define ARCH_HAS_PREFETCHW
Will Deacond8f57aa2013-06-26 17:03:40 +0100121static inline void prefetchw(const void *ptr)
122{
123 __asm__ __volatile__(
124 ".arch_extension mp\n"
125 __ALT_SMP_ASM(
Stefan Agner43947b82019-03-23 12:13:14 +0100126 "pldw\t%a0",
127 "pld\t%a0"
Will Deacond8f57aa2013-06-26 17:03:40 +0100128 )
129 :: "p" (ptr));
130}
131#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
136#endif /* __ASM_ARM_PROCESSOR_H */