Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Russell King | 4baa992 | 2008-08-02 10:55:55 +0100 | [diff] [blame] | 3 | * arch/arm/include/asm/processor.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1995-1999 Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __ASM_ARM_PROCESSOR_H |
| 9 | #define __ASM_ARM_PROCESSOR_H |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #ifdef __KERNEL__ |
| 12 | |
Will Deacon | 864232f | 2010-09-03 10:42:55 +0100 | [diff] [blame] | 13 | #include <asm/hw_breakpoint.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/types.h> |
Will Deacon | 27a8479 | 2013-07-02 12:10:42 +0100 | [diff] [blame] | 16 | #include <asm/unified.h> |
Vincenzo Frascino | 78c8516 | 2020-03-20 14:53:49 +0000 | [diff] [blame] | 17 | #include <asm/vdso/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
David Howells | 922a70d | 2008-02-08 04:19:26 -0800 | [diff] [blame] | 19 | #ifdef __KERNEL__ |
Lennert Buytenhek | 794baba | 2008-12-05 03:25:47 +0100 | [diff] [blame] | 20 | #define STACK_TOP ((current->personality & ADDR_LIMIT_32BIT) ? \ |
David Howells | 922a70d | 2008-02-08 04:19:26 -0800 | [diff] [blame] | 21 | TASK_SIZE : TASK_SIZE_26) |
| 22 | #define STACK_TOP_MAX TASK_SIZE |
| 23 | #endif |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | struct debug_info { |
Will Deacon | 864232f | 2010-09-03 10:42:55 +0100 | [diff] [blame] | 26 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 27 | struct perf_event *hbp[ARM_MAX_HBP_SLOTS]; |
| 28 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct 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 Cook | 08626a6 | 2017-08-16 14:09:13 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Everything usercopied to/from thread_struct is statically-sized, so |
| 42 | * no hardened usercopy whitelist is needed. |
| 43 | */ |
| 44 | static inline void arch_thread_struct_whitelist(unsigned long *offset, |
| 45 | unsigned long *size) |
| 46 | { |
| 47 | *offset = *size = 0; |
| 48 | } |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define INIT_THREAD { } |
| 51 | |
| 52 | #define start_thread(regs,pc,sp) \ |
| 53 | ({ \ |
Nicolas Pitre | 5e58811 | 2017-07-28 18:48:48 -0400 | [diff] [blame] | 54 | 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 King | 59f0cb0 | 2008-10-27 11:24:09 +0000 | [diff] [blame] | 61 | memset(regs->uregs, 0, sizeof(regs->uregs)); \ |
Nicolas Pitre | 5e58811 | 2017-07-28 18:48:48 -0400 | [diff] [blame] | 62 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 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 Marinas | 2658485 | 2009-05-30 14:00:18 +0100 | [diff] [blame] | 76 | regs->ARM_cpsr |= PSR_ENDSTATE; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | regs->ARM_pc = pc & ~1; /* pc */ \ |
| 78 | regs->ARM_sp = sp; /* sp */ \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }) |
| 80 | |
| 81 | /* Forward declaration, a strange C thing */ |
| 82 | struct task_struct; |
| 83 | |
| 84 | /* Free all resources held by a thread. */ |
| 85 | extern void release_thread(struct task_struct *); |
| 86 | |
Kees Cook | 42a20f8 | 2021-09-29 15:02:14 -0700 | [diff] [blame] | 87 | unsigned long __get_wchan(struct task_struct *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Al Viro | 815d5ec | 2006-01-12 01:05:57 -0800 | [diff] [blame] | 89 | #define task_pt_regs(p) \ |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 90 | ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1) |
Al Viro | 815d5ec | 2006-01-12 01:05:57 -0800 | [diff] [blame] | 91 | |
| 92 | #define KSTK_EIP(tsk) task_pt_regs(tsk)->ARM_pc |
| 93 | #define KSTK_ESP(tsk) task_pt_regs(tsk)->ARM_sp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Will Deacon | 27a8479 | 2013-07-02 12:10:42 +0100 | [diff] [blame] | 95 | #ifdef CONFIG_SMP |
| 96 | #define __ALT_SMP_ASM(smp, up) \ |
| 97 | "9998: " smp "\n" \ |
| 98 | " .pushsection \".alt.smp.init\", \"a\"\n" \ |
Ard Biesheuvel | 450abd3 | 2020-09-14 11:48:20 +0300 | [diff] [blame] | 99 | " .long 9998b - .\n" \ |
Will Deacon | 27a8479 | 2013-07-02 12:10:42 +0100 | [diff] [blame] | 100 | " " up "\n" \ |
| 101 | " .popsection\n" |
| 102 | #else |
| 103 | #define __ALT_SMP_ASM(smp, up) up |
| 104 | #endif |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* |
| 107 | * Prefetching support - only ARMv5. |
| 108 | */ |
| 109 | #if __LINUX_ARM_ARCH__ >= 5 |
| 110 | |
| 111 | #define ARCH_HAS_PREFETCH |
Nicolas Pitre | 0282884 | 2006-12-13 18:39:26 +0100 | [diff] [blame] | 112 | static inline void prefetch(const void *ptr) |
| 113 | { |
| 114 | __asm__ __volatile__( |
Nicolas Pitre | 16f719d | 2008-08-12 22:10:59 +0100 | [diff] [blame] | 115 | "pld\t%a0" |
Will Deacon | e744dff | 2013-06-26 16:47:35 +0100 | [diff] [blame] | 116 | :: "p" (ptr)); |
Nicolas Pitre | 0282884 | 2006-12-13 18:39:26 +0100 | [diff] [blame] | 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Will Deacon | d8f57aa | 2013-06-26 17:03:40 +0100 | [diff] [blame] | 119 | #if __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #define ARCH_HAS_PREFETCHW |
Will Deacon | d8f57aa | 2013-06-26 17:03:40 +0100 | [diff] [blame] | 121 | static inline void prefetchw(const void *ptr) |
| 122 | { |
| 123 | __asm__ __volatile__( |
| 124 | ".arch_extension mp\n" |
| 125 | __ALT_SMP_ASM( |
Stefan Agner | 43947b8 | 2019-03-23 12:13:14 +0100 | [diff] [blame] | 126 | "pldw\t%a0", |
| 127 | "pld\t%a0" |
Will Deacon | d8f57aa | 2013-06-26 17:03:40 +0100 | [diff] [blame] | 128 | ) |
| 129 | :: "p" (ptr)); |
| 130 | } |
| 131 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #endif |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #endif |
| 135 | |
| 136 | #endif /* __ASM_ARM_PROCESSOR_H */ |