blob: 5d06f75ffad47ab486b43552ca7814d50086cdba [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Russell King4baa9922008-08-02 10:55:55 +01002 * arch/arm/include/asm/processor.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1995-1999 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __ASM_ARM_PROCESSOR_H
12#define __ASM_ARM_PROCESSOR_H
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#ifdef __KERNEL__
15
Will Deacon864232f2010-09-03 10:42:55 +010016#include <asm/hw_breakpoint.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/types.h>
Will Deacon27a84792013-07-02 12:10:42 +010019#include <asm/unified.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
David Howells922a70d2008-02-08 04:19:26 -080021#ifdef __KERNEL__
Lennert Buytenhek794baba2008-12-05 03:25:47 +010022#define STACK_TOP ((current->personality & ADDR_LIMIT_32BIT) ? \
David Howells922a70d2008-02-08 04:19:26 -080023 TASK_SIZE : TASK_SIZE_26)
24#define STACK_TOP_MAX TASK_SIZE
25#endif
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct debug_info {
Will Deacon864232f2010-09-03 10:42:55 +010028#ifdef CONFIG_HAVE_HW_BREAKPOINT
29 struct perf_event *hbp[ARM_MAX_HBP_SLOTS];
30#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070031};
32
33struct thread_struct {
34 /* fault info */
35 unsigned long address;
36 unsigned long trap_no;
37 unsigned long error_code;
38 /* debugging */
39 struct debug_info debug;
40};
41
Kees Cook08626a62017-08-16 14:09:13 -070042/*
43 * Everything usercopied to/from thread_struct is statically-sized, so
44 * no hardened usercopy whitelist is needed.
45 */
46static inline void arch_thread_struct_whitelist(unsigned long *offset,
47 unsigned long *size)
48{
49 *offset = *size = 0;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define INIT_THREAD { }
53
54#define start_thread(regs,pc,sp) \
55({ \
Nicolas Pitre5e588112017-07-28 18:48:48 -040056 unsigned long r7, r8, r9; \
57 \
58 if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC)) { \
59 r7 = regs->ARM_r7; \
60 r8 = regs->ARM_r8; \
61 r9 = regs->ARM_r9; \
62 } \
Russell King59f0cb02008-10-27 11:24:09 +000063 memset(regs->uregs, 0, sizeof(regs->uregs)); \
Nicolas Pitre5e588112017-07-28 18:48:48 -040064 if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC) && \
65 current->personality & FDPIC_FUNCPTRS) { \
66 regs->ARM_r7 = r7; \
67 regs->ARM_r8 = r8; \
68 regs->ARM_r9 = r9; \
69 regs->ARM_r10 = current->mm->start_data; \
70 } else if (!IS_ENABLED(CONFIG_MMU)) \
71 regs->ARM_r10 = current->mm->start_data; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (current->personality & ADDR_LIMIT_32BIT) \
73 regs->ARM_cpsr = USR_MODE; \
74 else \
75 regs->ARM_cpsr = USR26_MODE; \
76 if (elf_hwcap & HWCAP_THUMB && pc & 1) \
77 regs->ARM_cpsr |= PSR_T_BIT; \
Catalin Marinas26584852009-05-30 14:00:18 +010078 regs->ARM_cpsr |= PSR_ENDSTATE; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 regs->ARM_pc = pc & ~1; /* pc */ \
80 regs->ARM_sp = sp; /* sp */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -070081})
82
83/* Forward declaration, a strange C thing */
84struct task_struct;
85
86/* Free all resources held by a thread. */
87extern void release_thread(struct task_struct *);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089unsigned long get_wchan(struct task_struct *p);
90
Will Deacon5dab26a2011-03-04 12:38:54 +010091#if __LINUX_ARM_ARCH__ == 6 || defined(CONFIG_ARM_ERRATA_754327)
Russell King5388a5b2018-04-10 11:35:36 +010092#define cpu_relax() \
93 do { \
94 smp_mb(); \
95 __asm__ __volatile__("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"); \
96 } while (0)
Will Deacon534be1d2010-06-21 15:29:03 +010097#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define cpu_relax() barrier()
Will Deacon534be1d2010-06-21 15:29:03 +010099#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Al Viro815d5ec2006-01-12 01:05:57 -0800101#define task_pt_regs(p) \
Al Viro32d39a92006-01-12 01:05:58 -0800102 ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
Al Viro815d5ec2006-01-12 01:05:57 -0800103
104#define KSTK_EIP(tsk) task_pt_regs(tsk)->ARM_pc
105#define KSTK_ESP(tsk) task_pt_regs(tsk)->ARM_sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Will Deacon27a84792013-07-02 12:10:42 +0100107#ifdef CONFIG_SMP
108#define __ALT_SMP_ASM(smp, up) \
109 "9998: " smp "\n" \
110 " .pushsection \".alt.smp.init\", \"a\"\n" \
111 " .long 9998b\n" \
112 " " up "\n" \
113 " .popsection\n"
114#else
115#define __ALT_SMP_ASM(smp, up) up
116#endif
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/*
119 * Prefetching support - only ARMv5.
120 */
121#if __LINUX_ARM_ARCH__ >= 5
122
123#define ARCH_HAS_PREFETCH
Nicolas Pitre02828842006-12-13 18:39:26 +0100124static inline void prefetch(const void *ptr)
125{
126 __asm__ __volatile__(
Nicolas Pitre16f719d2008-08-12 22:10:59 +0100127 "pld\t%a0"
Will Deacone744dff2013-06-26 16:47:35 +0100128 :: "p" (ptr));
Nicolas Pitre02828842006-12-13 18:39:26 +0100129}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Will Deacond8f57aa2013-06-26 17:03:40 +0100131#if __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#define ARCH_HAS_PREFETCHW
Will Deacond8f57aa2013-06-26 17:03:40 +0100133static inline void prefetchw(const void *ptr)
134{
135 __asm__ __volatile__(
136 ".arch_extension mp\n"
137 __ALT_SMP_ASM(
Stefan Agner43947b82019-03-23 12:13:14 +0100138 "pldw\t%a0",
139 "pld\t%a0"
Will Deacond8f57aa2013-06-26 17:03:40 +0100140 )
141 :: "p" (ptr));
142}
143#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif
145
Rob Herring7dbaa462011-11-22 04:01:07 +0100146#define HAVE_ARCH_PICK_MMAP_LAYOUT
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#endif
149
150#endif /* __ASM_ARM_PROCESSOR_H */