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 | /* |
| 3 | * linux/arch/arm/boot/compressed/head.S |
| 4 | * |
| 5 | * Copyright (C) 1996-2002 Russell King |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 6 | * Copyright (C) 2004 Hyok S. Choi (MPU support) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/linkage.h> |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 9 | #include <asm/assembler.h> |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 10 | #include <asm/v7m.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 12 | #include "efi-header.S" |
| 13 | |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 14 | AR_CLASS( .arch armv7-a ) |
| 15 | M_CLASS( .arch armv7-m ) |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* |
| 18 | * Debugging stuff |
| 19 | * |
| 20 | * Note that these macros must not contain any code which is not |
| 21 | * 100% relocatable. Any attempt to do so will result in a crash. |
| 22 | * Please select one of the following when turning on debugging. |
| 23 | */ |
| 24 | #ifdef DEBUG |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 25 | |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 26 | #if defined(CONFIG_DEBUG_ICEDCC) |
Tony Lindgren | 7d95ded | 2006-09-20 13:03:34 +0100 | [diff] [blame] | 27 | |
Stephen Boyd | dfad549 | 2011-03-23 22:46:15 +0100 | [diff] [blame] | 28 | #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7) |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 29 | .macro loadsp, rb, tmp1, tmp2 |
Tony Lindgren | 7d95ded | 2006-09-20 13:03:34 +0100 | [diff] [blame] | 30 | .endm |
| 31 | .macro writeb, ch, rb |
| 32 | mcr p14, 0, \ch, c0, c5, 0 |
| 33 | .endm |
Jean-Christop PLAGNIOL-VILLARD | c633c3c | 2009-02-25 04:20:40 +0100 | [diff] [blame] | 34 | #elif defined(CONFIG_CPU_XSCALE) |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 35 | .macro loadsp, rb, tmp1, tmp2 |
Jean-Christop PLAGNIOL-VILLARD | c633c3c | 2009-02-25 04:20:40 +0100 | [diff] [blame] | 36 | .endm |
| 37 | .macro writeb, ch, rb |
| 38 | mcr p14, 0, \ch, c8, c0, 0 |
| 39 | .endm |
Tony Lindgren | 7d95ded | 2006-09-20 13:03:34 +0100 | [diff] [blame] | 40 | #else |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 41 | .macro loadsp, rb, tmp1, tmp2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | .endm |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 43 | .macro writeb, ch, rb |
Uwe Kleine-König | 41a9e68 | 2007-12-13 09:31:34 +0100 | [diff] [blame] | 44 | mcr p14, 0, \ch, c1, c0, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | .endm |
Tony Lindgren | 7d95ded | 2006-09-20 13:03:34 +0100 | [diff] [blame] | 46 | #endif |
| 47 | |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 48 | #else |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 49 | |
Shawn Guo | 4beba08 | 2012-12-11 07:06:37 +0100 | [diff] [blame] | 50 | #include CONFIG_DEBUG_LL_INCLUDE |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 51 | |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 52 | .macro writeb, ch, rb |
| 53 | senduart \ch, \rb |
| 54 | .endm |
| 55 | |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 56 | #if defined(CONFIG_ARCH_SA1100) |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 57 | .macro loadsp, rb, tmp1, tmp2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | mov \rb, #0x80000000 @ physical base address |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_DEBUG_LL_SER3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | add \rb, \rb, #0x00050000 @ Ser3 |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 61 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | add \rb, \rb, #0x00010000 @ Ser1 |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 63 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .endm |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #else |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 66 | .macro loadsp, rb, tmp1, tmp2 |
| 67 | addruart \rb, \tmp1, \tmp2 |
Russell King | 224b5be | 2005-11-16 14:59:51 +0000 | [diff] [blame] | 68 | .endm |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #endif |
| 70 | #endif |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 71 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | .macro kputc,val |
| 74 | mov r0, \val |
| 75 | bl putc |
| 76 | .endm |
| 77 | |
| 78 | .macro kphex,val,len |
| 79 | mov r0, \val |
| 80 | mov r1, #\len |
| 81 | bl phex |
| 82 | .endm |
| 83 | |
| 84 | .macro debug_reloc_start |
| 85 | #ifdef DEBUG |
| 86 | kputc #'\n' |
| 87 | kphex r6, 8 /* processor id */ |
| 88 | kputc #':' |
| 89 | kphex r7, 8 /* architecture id */ |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 90 | #ifdef CONFIG_CPU_CP15 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | kputc #':' |
| 92 | mrc p15, 0, r0, c1, c0 |
| 93 | kphex r0, 8 /* control reg */ |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 94 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | kputc #'\n' |
| 96 | kphex r5, 8 /* decompressed kernel start */ |
| 97 | kputc #'-' |
Russell King | f461902 | 2006-01-12 17:17:57 +0000 | [diff] [blame] | 98 | kphex r9, 8 /* decompressed kernel end */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | kputc #'>' |
| 100 | kphex r4, 8 /* kernel execution address */ |
| 101 | kputc #'\n' |
| 102 | #endif |
| 103 | .endm |
| 104 | |
| 105 | .macro debug_reloc_end |
| 106 | #ifdef DEBUG |
| 107 | kphex r5, 8 /* end of kernel */ |
| 108 | kputc #'\n' |
| 109 | mov r0, r4 |
| 110 | bl memdump /* dump 256 bytes at start of kernel */ |
| 111 | #endif |
| 112 | .endm |
| 113 | |
Fabrizio Castro | f3c8999 | 2018-08-21 18:54:13 +0100 | [diff] [blame] | 114 | /* |
| 115 | * Debug kernel copy by printing the memory addresses involved |
| 116 | */ |
| 117 | .macro dbgkc, begin, end, cbegin, cend |
| 118 | #ifdef DEBUG |
| 119 | kputc #'\n' |
| 120 | kputc #'C' |
| 121 | kputc #':' |
| 122 | kputc #'0' |
| 123 | kputc #'x' |
| 124 | kphex \begin, 8 /* Start of compressed kernel */ |
| 125 | kputc #'-' |
| 126 | kputc #'0' |
| 127 | kputc #'x' |
| 128 | kphex \end, 8 /* End of compressed kernel */ |
| 129 | kputc #'-' |
| 130 | kputc #'>' |
| 131 | kputc #'0' |
| 132 | kputc #'x' |
| 133 | kphex \cbegin, 8 /* Start of kernel copy */ |
| 134 | kputc #'-' |
| 135 | kputc #'0' |
| 136 | kputc #'x' |
| 137 | kphex \cend, 8 /* End of kernel copy */ |
| 138 | kputc #'\n' |
| 139 | kputc #'\r' |
| 140 | #endif |
| 141 | .endm |
| 142 | |
Ard Biesheuvel | 8239fc7 | 2019-11-22 12:59:00 +0100 | [diff] [blame] | 143 | .macro enable_cp15_barriers, reg |
| 144 | mrc p15, 0, \reg, c1, c0, 0 @ read SCTLR |
| 145 | tst \reg, #(1 << 5) @ CP15BEN bit set? |
| 146 | bne .L_\@ |
| 147 | orr \reg, \reg, #(1 << 5) @ CP15 barrier instructions |
| 148 | mcr p15, 0, \reg, c1, c0, 0 @ write SCTLR |
| 149 | ARM( .inst 0xf57ff06f @ v7+ isb ) |
| 150 | THUMB( isb ) |
| 151 | .L_\@: |
| 152 | .endm |
| 153 | |
Nick Desaulniers | 790756c | 2019-11-04 19:31:45 +0100 | [diff] [blame] | 154 | .section ".start", "ax" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* |
| 156 | * sort out different calling conventions |
| 157 | */ |
| 158 | .align |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 159 | /* |
| 160 | * Always enter in ARM state for CPUs that support the ARM ISA. |
| 161 | * As of today (2014) that's exactly the members of the A and R |
| 162 | * classes. |
| 163 | */ |
| 164 | AR_CLASS( .arm ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | start: |
| 166 | .type start,#function |
Linus Walleij | 20699a4 | 2019-07-16 12:32:37 +0100 | [diff] [blame] | 167 | /* |
| 168 | * These 7 nops along with the 1 nop immediately below for |
| 169 | * !THUMB2 form 8 nops that make the compressed kernel bootable |
| 170 | * on legacy ARM systems that were assuming the kernel in a.out |
| 171 | * binary format. The boot loaders on these systems would |
| 172 | * jump 32 bytes into the image to skip the a.out header. |
| 173 | * with these 8 nops filling exactly 32 bytes, things still |
| 174 | * work as expected on these legacy systems. Thumb2 mode keeps |
| 175 | * 7 of the nops as it turns out that some boot loaders |
| 176 | * were patching the initial instructions of the kernel, i.e |
| 177 | * had started to exploit this "patch area". |
| 178 | */ |
Nicolas Pitre | b11fe38 | 2011-02-12 22:25:27 +0100 | [diff] [blame] | 179 | .rept 7 |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 180 | __nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | .endr |
Ard Biesheuvel | 06a4b6d | 2017-05-24 15:31:57 +0100 | [diff] [blame] | 182 | #ifndef CONFIG_THUMB2_KERNEL |
Linus Walleij | 6583d82 | 2019-07-16 12:33:14 +0100 | [diff] [blame] | 183 | __nop |
Ard Biesheuvel | 06a4b6d | 2017-05-24 15:31:57 +0100 | [diff] [blame] | 184 | #else |
| 185 | AR_CLASS( sub pc, pc, #3 ) @ A/R: switch to Thumb2 mode |
| 186 | M_CLASS( nop.w ) @ M: already in Thumb2 mode |
| 187 | .thumb |
| 188 | #endif |
| 189 | W(b) 1f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Nicolas Pitre | 33656d5 | 2014-06-02 17:32:25 +0100 | [diff] [blame] | 191 | .word _magic_sig @ Magic numbers to help the loader |
| 192 | .word _magic_start @ absolute load/run zImage address |
| 193 | .word _magic_end @ zImage end address |
Nicolas Pitre | 9696fca | 2014-06-19 22:44:32 +0100 | [diff] [blame] | 194 | .word 0x04030201 @ endianness flag |
Russell King | c772568 | 2017-09-21 18:10:19 +0100 | [diff] [blame] | 195 | .word 0x45454545 @ another magic number to indicate |
| 196 | .word _magic_table @ additional data table |
Nicolas Pitre | 33656d5 | 2014-06-02 17:32:25 +0100 | [diff] [blame] | 197 | |
Ard Biesheuvel | 06a4b6d | 2017-05-24 15:31:57 +0100 | [diff] [blame] | 198 | __EFI_HEADER |
| 199 | 1: |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 200 | ARM_BE8( setend be ) @ go BE8 if compiled for BE8 |
| 201 | AR_CLASS( mrs r9, cpsr ) |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 202 | #ifdef CONFIG_ARM_VIRT_EXT |
| 203 | bl __hyp_stub_install @ get into SVC mode, reversibly |
| 204 | #endif |
| 205 | mov r7, r1 @ save architecture ID |
Russell King | f461902 | 2006-01-12 17:17:57 +0000 | [diff] [blame] | 206 | mov r8, r2 @ save atags pointer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 208 | #ifndef CONFIG_CPU_V7M |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* |
| 210 | * Booting from Angel - need to enter SVC mode and disable |
| 211 | * FIQs/IRQs (numeric definitions from angel arm.h source). |
| 212 | * We only do this if we were in user mode on entry. |
| 213 | */ |
| 214 | mrs r2, cpsr @ get current mode |
| 215 | tst r2, #3 @ not user? |
| 216 | bne not_angel |
| 217 | mov r0, #0x17 @ angel_SWIreason_EnterSVC |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 218 | ARM( swi 0x123456 ) @ angel_SWI_ARM |
| 219 | THUMB( svc 0xab ) @ angel_SWI_THUMB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | not_angel: |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 221 | safe_svcmode_maskall r0 |
| 222 | msr spsr_cxsf, r9 @ Save the CPU boot mode in |
| 223 | @ SPSR |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 224 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /* |
| 226 | * Note that some cache flushing and other stuff may |
| 227 | * be needed here - is there an Angel SWI call for this? |
| 228 | */ |
| 229 | |
| 230 | /* |
| 231 | * some architecture specific code can be inserted |
Russell King | f461902 | 2006-01-12 17:17:57 +0000 | [diff] [blame] | 232 | * by the linker here, but it should preserve r7, r8, and r9. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | */ |
| 234 | |
| 235 | .text |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 236 | |
Eric Miao | e69edc79 | 2010-07-05 15:56:50 +0200 | [diff] [blame] | 237 | #ifdef CONFIG_AUTO_ZRELADDR |
Russell King | 0a6a78b | 2015-03-26 09:41:33 +0000 | [diff] [blame] | 238 | /* |
| 239 | * Find the start of physical memory. As we are executing |
| 240 | * without the MMU on, we are in the physical address space. |
| 241 | * We just need to get rid of any offset by aligning the |
| 242 | * address. |
| 243 | * |
| 244 | * This alignment is a balance between the requirements of |
| 245 | * different platforms - we have chosen 128MB to allow |
| 246 | * platforms which align the start of their physical memory |
| 247 | * to 128MB to use this feature, while allowing the zImage |
| 248 | * to be placed within the first 128MB of memory on other |
| 249 | * platforms. Increasing the alignment means we place |
| 250 | * stricter alignment requirements on the start of physical |
| 251 | * memory, but relaxing it means that we break people who |
| 252 | * are already placing their zImage in (eg) the top 64MB |
| 253 | * of this range. |
| 254 | */ |
Dave Martin | bfa64c4 | 2010-11-29 19:43:26 +0100 | [diff] [blame] | 255 | mov r4, pc |
| 256 | and r4, r4, #0xf8000000 |
Russell King | 0a6a78b | 2015-03-26 09:41:33 +0000 | [diff] [blame] | 257 | /* Determine final kernel image address. */ |
Eric Miao | e69edc79 | 2010-07-05 15:56:50 +0200 | [diff] [blame] | 258 | add r4, r4, #TEXT_OFFSET |
| 259 | #else |
Russell King | 9e84ed6 | 2010-09-09 22:39:41 +0100 | [diff] [blame] | 260 | ldr r4, =zreladdr |
Eric Miao | e69edc79 | 2010-07-05 15:56:50 +0200 | [diff] [blame] | 261 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 263 | /* |
| 264 | * Set up a page table only if it won't overwrite ourself. |
Masahiro Yamada | 7d57909 | 2015-01-20 03:44:26 +0100 | [diff] [blame] | 265 | * That means r4 < pc || r4 - 16k page directory > &_end. |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 266 | * Given that r4 > &_end is most unfrequent, we add a rough |
| 267 | * additional 1MB of room for a possible appended DTB. |
| 268 | */ |
| 269 | mov r0, pc |
| 270 | cmp r0, r4 |
| 271 | ldrcc r0, LC0+32 |
| 272 | addcc r0, r0, pc |
| 273 | cmpcc r4, r0 |
| 274 | orrcc r4, r4, #1 @ remember we skipped cache_on |
| 275 | blcs cache_on |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 276 | |
| 277 | restart: adr r0, LC0 |
Nicolas Pitre | 34cc1a8 | 2011-04-19 15:42:43 -0400 | [diff] [blame] | 278 | ldmia r0, {r1, r2, r3, r6, r10, r11, r12} |
Nicolas Pitre | adcc259 | 2011-04-27 16:15:11 -0400 | [diff] [blame] | 279 | ldr sp, [r0, #28] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 282 | * We might be running at a different address. We need |
| 283 | * to fix up various pointers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | */ |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 285 | sub r0, r0, r1 @ calculate the delta offset |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 286 | add r6, r6, r0 @ _edata |
Nicolas Pitre | 34cc1a8 | 2011-04-19 15:42:43 -0400 | [diff] [blame] | 287 | add r10, r10, r0 @ inflated kernel size location |
| 288 | |
| 289 | /* |
| 290 | * The kernel build system appends the size of the |
| 291 | * decompressed kernel at the end of the compressed data |
| 292 | * in little-endian form. |
| 293 | */ |
| 294 | ldrb r9, [r10, #0] |
| 295 | ldrb lr, [r10, #1] |
| 296 | orr r9, r9, lr, lsl #8 |
| 297 | ldrb lr, [r10, #2] |
| 298 | ldrb r10, [r10, #3] |
| 299 | orr r9, r9, lr, lsl #16 |
| 300 | orr r9, r9, r10, lsl #24 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 301 | |
| 302 | #ifndef CONFIG_ZBOOT_ROM |
| 303 | /* malloc space is above the relocated stack (64k max) */ |
| 304 | add sp, sp, r0 |
| 305 | add r10, sp, #0x10000 |
| 306 | #else |
| 307 | /* |
| 308 | * With ZBOOT_ROM the bss/stack is non relocatable, |
| 309 | * but someone could still run this code from RAM, |
| 310 | * in which case our reference is _edata. |
| 311 | */ |
| 312 | mov r10, r6 |
| 313 | #endif |
| 314 | |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 315 | mov r5, #0 @ init dtb size to 0 |
| 316 | #ifdef CONFIG_ARM_APPENDED_DTB |
| 317 | /* |
| 318 | * r0 = delta |
| 319 | * r2 = BSS start |
| 320 | * r3 = BSS end |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 321 | * r4 = final kernel address (possibly with LSB set) |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 322 | * r5 = appended dtb size (still unknown) |
| 323 | * r6 = _edata |
| 324 | * r7 = architecture ID |
| 325 | * r8 = atags/device tree pointer |
| 326 | * r9 = size of decompressed image |
| 327 | * r10 = end of this image, including bss/stack/malloc space if non XIP |
| 328 | * r11 = GOT start |
| 329 | * r12 = GOT end |
| 330 | * sp = stack pointer |
| 331 | * |
| 332 | * if there are device trees (dtb) appended to zImage, advance r10 so that the |
| 333 | * dtb data will get relocated along with the kernel if necessary. |
| 334 | */ |
| 335 | |
| 336 | ldr lr, [r6, #0] |
| 337 | #ifndef __ARMEB__ |
| 338 | ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian |
| 339 | #else |
| 340 | ldr r1, =0xd00dfeed |
| 341 | #endif |
| 342 | cmp lr, r1 |
| 343 | bne dtb_check_done @ not found |
| 344 | |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 345 | #ifdef CONFIG_ARM_ATAG_DTB_COMPAT |
| 346 | /* |
| 347 | * OK... Let's do some funky business here. |
| 348 | * If we do have a DTB appended to zImage, and we do have |
| 349 | * an ATAG list around, we want the later to be translated |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 350 | * and folded into the former here. No GOT fixup has occurred |
| 351 | * yet, but none of the code we're about to call uses any |
| 352 | * global variable. |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 353 | */ |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 354 | |
| 355 | /* Get the initial DTB size */ |
| 356 | ldr r5, [r6, #4] |
| 357 | #ifndef __ARMEB__ |
| 358 | /* convert to little endian */ |
| 359 | eor r1, r5, r5, ror #16 |
| 360 | bic r1, r1, #0x00ff0000 |
| 361 | mov r5, r5, ror #8 |
| 362 | eor r5, r5, r1, lsr #8 |
| 363 | #endif |
| 364 | /* 50% DTB growth should be good enough */ |
| 365 | add r5, r5, r5, lsr #1 |
| 366 | /* preserve 64-bit alignment */ |
| 367 | add r5, r5, #7 |
| 368 | bic r5, r5, #7 |
| 369 | /* clamp to 32KB min and 1MB max */ |
| 370 | cmp r5, #(1 << 15) |
| 371 | movlo r5, #(1 << 15) |
| 372 | cmp r5, #(1 << 20) |
| 373 | movhi r5, #(1 << 20) |
| 374 | /* temporarily relocate the stack past the DTB work space */ |
| 375 | add sp, sp, r5 |
| 376 | |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 377 | stmfd sp!, {r0-r3, ip, lr} |
| 378 | mov r0, r8 |
| 379 | mov r1, r6 |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 380 | mov r2, r5 |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 381 | bl atags_to_fdt |
| 382 | |
| 383 | /* |
| 384 | * If returned value is 1, there is no ATAG at the location |
| 385 | * pointed by r8. Try the typical 0x100 offset from start |
| 386 | * of RAM and hope for the best. |
| 387 | */ |
| 388 | cmp r0, #1 |
Nicolas Pitre | 531a6a9 | 2011-10-24 13:30:32 +0100 | [diff] [blame] | 389 | sub r0, r4, #TEXT_OFFSET |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 390 | bic r0, r0, #1 |
Nicolas Pitre | 531a6a9 | 2011-10-24 13:30:32 +0100 | [diff] [blame] | 391 | add r0, r0, #0x100 |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 392 | mov r1, r6 |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 393 | mov r2, r5 |
Marc Zyngier | 9c5fd9e | 2012-04-11 14:52:55 +0100 | [diff] [blame] | 394 | bleq atags_to_fdt |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 395 | |
| 396 | ldmfd sp!, {r0-r3, ip, lr} |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 397 | sub sp, sp, r5 |
Nicolas Pitre | b90b9a3 | 2011-09-13 22:37:07 -0400 | [diff] [blame] | 398 | #endif |
| 399 | |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 400 | mov r8, r6 @ use the appended device tree |
| 401 | |
Nicolas Pitre | 5ffb04f | 2011-06-12 01:07:33 -0400 | [diff] [blame] | 402 | /* |
| 403 | * Make sure that the DTB doesn't end up in the final |
| 404 | * kernel's .bss area. To do so, we adjust the decompressed |
| 405 | * kernel size to compensate if that .bss size is larger |
| 406 | * than the relocated code. |
| 407 | */ |
| 408 | ldr r5, =_kernel_bss_size |
| 409 | adr r1, wont_overwrite |
| 410 | sub r1, r6, r1 |
| 411 | subs r1, r5, r1 |
| 412 | addhi r9, r9, r1 |
| 413 | |
Nicolas Pitre | c2607f7 | 2015-01-27 16:10:42 +0100 | [diff] [blame] | 414 | /* Get the current DTB size */ |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 415 | ldr r5, [r6, #4] |
| 416 | #ifndef __ARMEB__ |
| 417 | /* convert r5 (dtb size) to little endian */ |
| 418 | eor r1, r5, r5, ror #16 |
| 419 | bic r1, r1, #0x00ff0000 |
| 420 | mov r5, r5, ror #8 |
| 421 | eor r5, r5, r1, lsr #8 |
| 422 | #endif |
| 423 | |
| 424 | /* preserve 64-bit alignment */ |
| 425 | add r5, r5, #7 |
| 426 | bic r5, r5, #7 |
| 427 | |
| 428 | /* relocate some pointers past the appended dtb */ |
| 429 | add r6, r6, r5 |
| 430 | add r10, r10, r5 |
| 431 | add sp, sp, r5 |
| 432 | dtb_check_done: |
| 433 | #endif |
| 434 | |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 435 | /* |
| 436 | * Check to see if we will overwrite ourselves. |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 437 | * r4 = final kernel address (possibly with LSB set) |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 438 | * r9 = size of decompressed image |
| 439 | * r10 = end of this image, including bss/stack/malloc space if non XIP |
| 440 | * We basically want: |
Nicolas Pitre | ea9df3b | 2011-04-21 22:52:06 -0400 | [diff] [blame] | 441 | * r4 - 16k page directory >= r10 -> OK |
Nicolas Pitre | 5ffb04f | 2011-06-12 01:07:33 -0400 | [diff] [blame] | 442 | * r4 + image length <= address of wont_overwrite -> OK |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 443 | * Note: the possible LSB in r4 is harmless here. |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 444 | */ |
Nicolas Pitre | ea9df3b | 2011-04-21 22:52:06 -0400 | [diff] [blame] | 445 | add r10, r10, #16384 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 446 | cmp r4, r10 |
| 447 | bhs wont_overwrite |
| 448 | add r10, r4, r9 |
Nicolas Pitre | 5ffb04f | 2011-06-12 01:07:33 -0400 | [diff] [blame] | 449 | adr r9, wont_overwrite |
| 450 | cmp r10, r9 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 451 | bls wont_overwrite |
| 452 | |
| 453 | /* |
| 454 | * Relocate ourselves past the end of the decompressed kernel. |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 455 | * r6 = _edata |
| 456 | * r10 = end of the decompressed kernel |
| 457 | * Because we always copy ahead, we need to do it from the end and go |
| 458 | * backward in case the source and destination overlap. |
| 459 | */ |
Nicolas Pitre | adcc259 | 2011-04-27 16:15:11 -0400 | [diff] [blame] | 460 | /* |
| 461 | * Bump to the next 256-byte boundary with the size of |
| 462 | * the relocation code added. This avoids overwriting |
| 463 | * ourself when the offset is small. |
| 464 | */ |
| 465 | add r10, r10, #((reloc_code_end - restart + 256) & ~255) |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 466 | bic r10, r10, #255 |
| 467 | |
Nicolas Pitre | adcc259 | 2011-04-27 16:15:11 -0400 | [diff] [blame] | 468 | /* Get start of code we want to copy and align it down. */ |
| 469 | adr r5, restart |
| 470 | bic r5, r5, #31 |
| 471 | |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 472 | /* Relocate the hyp vector base if necessary */ |
| 473 | #ifdef CONFIG_ARM_VIRT_EXT |
| 474 | mrs r0, spsr |
| 475 | and r0, r0, #MODE_MASK |
| 476 | cmp r0, #HYP_MODE |
| 477 | bne 1f |
| 478 | |
Marc Zyngier | 4897e36 | 2017-04-03 19:38:02 +0100 | [diff] [blame] | 479 | /* |
| 480 | * Compute the address of the hyp vectors after relocation. |
| 481 | * This requires some arithmetic since we cannot directly |
| 482 | * reference __hyp_stub_vectors in a PC-relative way. |
| 483 | * Call __hyp_set_vectors with the new address so that we |
| 484 | * can HVC again after the copy. |
| 485 | */ |
| 486 | 0: adr r0, 0b |
| 487 | movw r1, #:lower16:__hyp_stub_vectors - 0b |
| 488 | movt r1, #:upper16:__hyp_stub_vectors - 0b |
| 489 | add r0, r0, r1 |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 490 | sub r0, r0, r5 |
| 491 | add r0, r0, r10 |
| 492 | bl __hyp_set_vectors |
| 493 | 1: |
| 494 | #endif |
| 495 | |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 496 | sub r9, r6, r5 @ size to copy |
| 497 | add r9, r9, #31 @ rounded up to a multiple |
| 498 | bic r9, r9, #31 @ ... of 32 bytes |
| 499 | add r6, r9, r5 |
| 500 | add r9, r9, r10 |
| 501 | |
Fabrizio Castro | f3c8999 | 2018-08-21 18:54:13 +0100 | [diff] [blame] | 502 | #ifdef DEBUG |
| 503 | sub r10, r6, r5 |
| 504 | sub r10, r9, r10 |
| 505 | /* |
| 506 | * We are about to copy the kernel to a new memory area. |
| 507 | * The boundaries of the new memory area can be found in |
| 508 | * r10 and r9, whilst r5 and r6 contain the boundaries |
| 509 | * of the memory we are going to copy. |
| 510 | * Calling dbgkc will help with the printing of this |
| 511 | * information. |
| 512 | */ |
| 513 | dbgkc r5, r6, r10, r9 |
| 514 | #endif |
| 515 | |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 516 | 1: ldmdb r6!, {r0 - r3, r10 - r12, lr} |
| 517 | cmp r6, r5 |
| 518 | stmdb r9!, {r0 - r3, r10 - r12, lr} |
| 519 | bhi 1b |
| 520 | |
| 521 | /* Preserve offset to relocated code. */ |
| 522 | sub r6, r9, r6 |
| 523 | |
Tony Lindgren | 7c2527f | 2011-04-26 05:37:46 -0700 | [diff] [blame] | 524 | #ifndef CONFIG_ZBOOT_ROM |
| 525 | /* cache_clean_flush may use the stack, so relocate it */ |
| 526 | add sp, sp, r6 |
| 527 | #endif |
| 528 | |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 529 | bl cache_clean_flush |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 530 | |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 531 | badr r0, restart |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 532 | add r0, r0, r6 |
| 533 | mov pc, r0 |
| 534 | |
| 535 | wont_overwrite: |
| 536 | /* |
| 537 | * If delta is zero, we are running at the address we were linked at. |
| 538 | * r0 = delta |
| 539 | * r2 = BSS start |
| 540 | * r3 = BSS end |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 541 | * r4 = kernel execution address (possibly with LSB set) |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 542 | * r5 = appended dtb size (0 if not present) |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 543 | * r7 = architecture ID |
| 544 | * r8 = atags pointer |
| 545 | * r11 = GOT start |
| 546 | * r12 = GOT end |
| 547 | * sp = stack pointer |
| 548 | */ |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 549 | orrs r1, r0, r5 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 550 | beq not_relocated |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 551 | |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 552 | add r11, r11, r0 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 553 | add r12, r12, r0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | #ifndef CONFIG_ZBOOT_ROM |
| 556 | /* |
| 557 | * If we're running fully PIC === CONFIG_ZBOOT_ROM = n, |
| 558 | * we need to fix up pointers into the BSS region. |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 559 | * Note that the stack pointer has already been fixed up. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | */ |
| 561 | add r2, r2, r0 |
| 562 | add r3, r3, r0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * Relocate all entries in the GOT table. |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 566 | * Bump bss entries to _edata + dtb size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | */ |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 568 | 1: ldr r1, [r11, #0] @ relocate entries in the GOT |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 569 | add r1, r1, r0 @ This fixes up C references |
| 570 | cmp r1, r2 @ if entry >= bss_start && |
| 571 | cmphs r3, r1 @ bss_end > entry |
| 572 | addhi r1, r1, r5 @ entry += dtb size |
| 573 | str r1, [r11], #4 @ next entry |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 574 | cmp r11, r12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | blo 1b |
John Bonesio | e2a6a3a | 2011-05-27 18:45:50 -0400 | [diff] [blame] | 576 | |
| 577 | /* bump our bss pointers too */ |
| 578 | add r2, r2, r5 |
| 579 | add r3, r3, r5 |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | #else |
| 582 | |
| 583 | /* |
| 584 | * Relocate entries in the GOT table. We only relocate |
| 585 | * the entries that are outside the (relocated) BSS region. |
| 586 | */ |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 587 | 1: ldr r1, [r11, #0] @ relocate entries in the GOT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | cmp r1, r2 @ entry < bss_start || |
| 589 | cmphs r3, r1 @ _end < entry |
| 590 | addlo r1, r1, r0 @ table. This fixes up the |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 591 | str r1, [r11], #4 @ C references. |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 592 | cmp r11, r12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | blo 1b |
| 594 | #endif |
| 595 | |
| 596 | not_relocated: mov r0, #0 |
| 597 | 1: str r0, [r2], #4 @ clear bss |
| 598 | str r0, [r2], #4 |
| 599 | str r0, [r2], #4 |
| 600 | str r0, [r2], #4 |
| 601 | cmp r2, r3 |
| 602 | blo 1b |
| 603 | |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 604 | /* |
| 605 | * Did we skip the cache setup earlier? |
| 606 | * That is indicated by the LSB in r4. |
| 607 | * Do it now if so. |
| 608 | */ |
| 609 | tst r4, #1 |
| 610 | bic r4, r4, #1 |
| 611 | blne cache_on |
| 612 | |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 613 | /* |
| 614 | * The C runtime environment should now be setup sufficiently. |
| 615 | * Set up some pointers, and start decompressing. |
| 616 | * r4 = kernel execution address |
| 617 | * r7 = architecture ID |
| 618 | * r8 = atags pointer |
| 619 | */ |
| 620 | mov r0, r4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | mov r1, sp @ malloc space above stack |
| 622 | add r2, sp, #0x10000 @ 64k max |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | mov r3, r7 |
| 624 | bl decompress_kernel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | bl cache_clean_flush |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 626 | bl cache_off |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 627 | |
| 628 | #ifdef CONFIG_ARM_VIRT_EXT |
| 629 | mrs r0, spsr @ Get saved CPU boot mode |
| 630 | and r0, r0, #MODE_MASK |
| 631 | cmp r0, #HYP_MODE @ if not booted in HYP mode... |
| 632 | bne __enter_kernel @ boot kernel directly |
| 633 | |
| 634 | adr r12, .L__hyp_reentry_vectors_offset |
| 635 | ldr r0, [r12] |
| 636 | add r0, r0, r12 |
| 637 | |
| 638 | bl __hyp_set_vectors |
| 639 | __HVC(0) @ otherwise bounce to hyp mode |
| 640 | |
| 641 | b . @ should never be reached |
| 642 | |
| 643 | .align 2 |
| 644 | .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - . |
| 645 | #else |
| 646 | b __enter_kernel |
| 647 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Catalin Marinas | 88987ef | 2009-07-24 12:32:52 +0100 | [diff] [blame] | 649 | .align 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | .type LC0, #object |
| 651 | LC0: .word LC0 @ r1 |
| 652 | .word __bss_start @ r2 |
| 653 | .word _end @ r3 |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 654 | .word _edata @ r6 |
Nicolas Pitre | 34cc1a8 | 2011-04-19 15:42:43 -0400 | [diff] [blame] | 655 | .word input_data_end - 4 @ r10 (inflated size location) |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 656 | .word _got_start @ r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | .word _got_end @ ip |
Nicolas Pitre | 8d7e4cc | 2011-04-27 14:54:39 -0400 | [diff] [blame] | 658 | .word .L_user_stack_end @ sp |
Nicolas Pitre | 2874865 | 2013-06-06 05:13:48 +0100 | [diff] [blame] | 659 | .word _end - restart + 16384 + 1024*1024 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | .size LC0, . - LC0 |
| 661 | |
| 662 | #ifdef CONFIG_ARCH_RPC |
| 663 | .globl params |
Eric Miao | db7b2b4 | 2010-06-03 15:36:49 +0800 | [diff] [blame] | 664 | params: ldr r0, =0x10000100 @ params_phys for RPC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | mov pc, lr |
| 666 | .ltorg |
| 667 | .align |
| 668 | #endif |
| 669 | |
| 670 | /* |
| 671 | * Turn on the cache. We need to setup some page tables so that we |
| 672 | * can have both the I and D caches on. |
| 673 | * |
| 674 | * We place the page tables 16k down from the kernel execution address, |
| 675 | * and we hope that nothing else is using it. If we're using it, we |
| 676 | * will go pop! |
| 677 | * |
| 678 | * On entry, |
| 679 | * r4 = kernel execution address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | * r7 = architecture number |
Russell King | f461902 | 2006-01-12 17:17:57 +0000 | [diff] [blame] | 681 | * r8 = atags pointer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | * On exit, |
Uwe Kleine-König | 21b2841 | 2010-01-26 22:08:09 +0100 | [diff] [blame] | 683 | * r0, r1, r2, r3, r9, r10, r12 corrupted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | * This routine must preserve: |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 685 | * r4, r7, r8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | */ |
| 687 | .align 5 |
| 688 | cache_on: mov r3, #8 @ cache_on function |
| 689 | b call_cache_fn |
| 690 | |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 691 | /* |
| 692 | * Initialize the highest priority protection region, PR7 |
| 693 | * to cover all 32bit address and cacheable and bufferable. |
| 694 | */ |
| 695 | __armv4_mpu_cache_on: |
| 696 | mov r0, #0x3f @ 4G, the whole |
| 697 | mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting |
| 698 | mcr p15, 0, r0, c6, c7, 1 |
| 699 | |
| 700 | mov r0, #0x80 @ PR7 |
| 701 | mcr p15, 0, r0, c2, c0, 0 @ D-cache on |
| 702 | mcr p15, 0, r0, c2, c0, 1 @ I-cache on |
| 703 | mcr p15, 0, r0, c3, c0, 0 @ write-buffer on |
| 704 | |
| 705 | mov r0, #0xc000 |
| 706 | mcr p15, 0, r0, c5, c0, 1 @ I-access permission |
| 707 | mcr p15, 0, r0, c5, c0, 0 @ D-access permission |
| 708 | |
| 709 | mov r0, #0 |
| 710 | mcr p15, 0, r0, c7, c10, 4 @ drain write buffer |
| 711 | mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache |
| 712 | mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache |
| 713 | mrc p15, 0, r0, c1, c0, 0 @ read control reg |
| 714 | @ ...I .... ..D. WC.M |
| 715 | orr r0, r0, #0x002d @ .... .... ..1. 11.1 |
| 716 | orr r0, r0, #0x1000 @ ...1 .... .... .... |
| 717 | |
| 718 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
| 719 | |
| 720 | mov r0, #0 |
| 721 | mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache |
| 722 | mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache |
| 723 | mov pc, lr |
| 724 | |
| 725 | __armv3_mpu_cache_on: |
| 726 | mov r0, #0x3f @ 4G, the whole |
| 727 | mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting |
| 728 | |
| 729 | mov r0, #0x80 @ PR7 |
| 730 | mcr p15, 0, r0, c2, c0, 0 @ cache on |
| 731 | mcr p15, 0, r0, c3, c0, 0 @ write-buffer on |
| 732 | |
| 733 | mov r0, #0xc000 |
| 734 | mcr p15, 0, r0, c5, c0, 0 @ access permission |
| 735 | |
| 736 | mov r0, #0 |
| 737 | mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3 |
Uwe Kleine-König | 4a8d57a | 2010-01-26 22:14:23 +0100 | [diff] [blame] | 738 | /* |
| 739 | * ?? ARMv3 MMU does not allow reading the control register, |
| 740 | * does this really work on ARMv3 MPU? |
| 741 | */ |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 742 | mrc p15, 0, r0, c1, c0, 0 @ read control reg |
| 743 | @ .... .... .... WC.M |
| 744 | orr r0, r0, #0x000d @ .... .... .... 11.1 |
Uwe Kleine-König | 4a8d57a | 2010-01-26 22:14:23 +0100 | [diff] [blame] | 745 | /* ?? this overwrites the value constructed above? */ |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 746 | mov r0, #0 |
| 747 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
| 748 | |
Uwe Kleine-König | 4a8d57a | 2010-01-26 22:14:23 +0100 | [diff] [blame] | 749 | /* ?? invalidate for the second time? */ |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 750 | mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3 |
| 751 | mov pc, lr |
| 752 | |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 753 | #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH |
| 754 | #define CB_BITS 0x08 |
| 755 | #else |
| 756 | #define CB_BITS 0x0c |
| 757 | #endif |
| 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | __setup_mmu: sub r3, r4, #16384 @ Page directory size |
| 760 | bic r3, r3, #0xff @ Align the pointer |
| 761 | bic r3, r3, #0x3f00 |
| 762 | /* |
| 763 | * Initialise the page tables, turning on the cacheable and bufferable |
| 764 | * bits for the RAM area only. |
| 765 | */ |
| 766 | mov r0, r3 |
Russell King | f461902 | 2006-01-12 17:17:57 +0000 | [diff] [blame] | 767 | mov r9, r0, lsr #18 |
| 768 | mov r9, r9, lsl #18 @ start of RAM |
| 769 | add r10, r9, #0x10000000 @ a reasonable RAM size |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 770 | mov r1, #0x12 @ XN|U + section mapping |
| 771 | orr r1, r1, #3 << 10 @ AP=11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | add r2, r3, #16384 |
Nicolas Pitre | 265d5e4 | 2006-01-18 22:38:51 +0000 | [diff] [blame] | 773 | 1: cmp r1, r9 @ if virt > start of RAM |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 774 | cmphs r10, r1 @ && end of RAM > virt |
| 775 | bic r1, r1, #0x1c @ clear XN|U + C + B |
| 776 | orrlo r1, r1, #0x10 @ Set XN|U for non-RAM |
| 777 | orrhs r1, r1, r6 @ set RAM section settings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | str r1, [r0], #4 @ 1:1 mapping |
| 779 | add r1, r1, #1048576 |
| 780 | teq r0, r2 |
| 781 | bne 1b |
| 782 | /* |
| 783 | * If ever we are running from Flash, then we surely want the cache |
| 784 | * to be enabled also for our execution instance... We map 2MB of it |
| 785 | * so there is no map overlap problem for up to 1 MB compressed kernel. |
| 786 | * If the execution is in RAM then we would only be duplicating the above. |
| 787 | */ |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 788 | orr r1, r6, #0x04 @ ensure B is set for this |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | orr r1, r1, #3 << 10 |
Dave Martin | bfa64c4 | 2010-11-29 19:43:26 +0100 | [diff] [blame] | 790 | mov r2, pc |
| 791 | mov r2, r2, lsr #20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | orr r1, r1, r2, lsl #20 |
| 793 | add r0, r3, r2, lsl #2 |
| 794 | str r1, [r0], #4 |
| 795 | add r1, r1, #1048576 |
| 796 | str r1, [r0] |
| 797 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 798 | ENDPROC(__setup_mmu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Dave Martin | 5010192 | 2012-11-22 12:50:43 +0100 | [diff] [blame] | 800 | @ Enable unaligned access on v6, to allow better code generation |
| 801 | @ for the decompressor C code: |
| 802 | __armv6_mmu_cache_on: |
| 803 | mrc p15, 0, r0, c1, c0, 0 @ read SCTLR |
| 804 | bic r0, r0, #2 @ A (no unaligned access fault) |
| 805 | orr r0, r0, #1 << 22 @ U (v6 unaligned access model) |
| 806 | mcr p15, 0, r0, c1, c0, 0 @ write SCTLR |
| 807 | b __armv4_mmu_cache_on |
| 808 | |
Mark A. Greer | af3e4fd | 2011-04-01 15:41:26 +0100 | [diff] [blame] | 809 | __arm926ejs_mmu_cache_on: |
| 810 | #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH |
| 811 | mov r0, #4 @ put dcache in WT mode |
| 812 | mcr p15, 7, r0, c15, c0, 0 |
| 813 | #endif |
| 814 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 815 | __armv4_mmu_cache_on: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | mov r12, lr |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 817 | #ifdef CONFIG_MMU |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 818 | mov r6, #CB_BITS | 0x12 @ U |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | bl __setup_mmu |
| 820 | mov r0, #0 |
| 821 | mcr p15, 0, r0, c7, c10, 4 @ drain write buffer |
| 822 | mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs |
| 823 | mrc p15, 0, r0, c1, c0, 0 @ read control reg |
| 824 | orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement |
| 825 | orr r0, r0, #0x0030 |
Ben Dooks | 457c240 | 2013-02-12 18:59:57 +0000 | [diff] [blame] | 826 | ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 827 | bl __common_mmu_cache_on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | mov r0, #0 |
| 829 | mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 830 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | mov pc, r12 |
| 832 | |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 833 | __armv7_mmu_cache_on: |
Ard Biesheuvel | 8239fc7 | 2019-11-22 12:59:00 +0100 | [diff] [blame] | 834 | enable_cp15_barriers r11 |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 835 | mov r12, lr |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 836 | #ifdef CONFIG_MMU |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 837 | mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0 |
| 838 | tst r11, #0xf @ VMSA |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 839 | movne r6, #CB_BITS | 0x02 @ !XN |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 840 | blne __setup_mmu |
| 841 | mov r0, #0 |
| 842 | mcr p15, 0, r0, c7, c10, 4 @ drain write buffer |
| 843 | tst r11, #0xf @ VMSA |
| 844 | mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 845 | #endif |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 846 | mrc p15, 0, r0, c1, c0, 0 @ read control reg |
Matthew Leach | e1e5b7e | 2012-09-11 17:56:57 +0100 | [diff] [blame] | 847 | bic r0, r0, #1 << 28 @ clear SCTLR.TRE |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 848 | orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement |
| 849 | orr r0, r0, #0x003c @ write buffer |
Dave Martin | 5010192 | 2012-11-22 12:50:43 +0100 | [diff] [blame] | 850 | bic r0, r0, #2 @ A (no unaligned access fault) |
| 851 | orr r0, r0, #1 << 22 @ U (v6 unaligned access model) |
| 852 | @ (needed for ARM1176) |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 853 | #ifdef CONFIG_MMU |
Ben Dooks | 457c240 | 2013-02-12 18:59:57 +0000 | [diff] [blame] | 854 | ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables |
Will Deacon | dbece45 | 2012-08-24 15:20:59 +0100 | [diff] [blame] | 855 | mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 856 | orrne r0, r0, #1 @ MMU enabled |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 857 | movne r1, #0xfffffffd @ domain 0 = client |
Will Deacon | dbece45 | 2012-08-24 15:20:59 +0100 | [diff] [blame] | 858 | bic r6, r6, #1 << 31 @ 32-bit translation system |
Srinivas Ramana | 117e5e9 | 2016-09-30 15:03:31 +0100 | [diff] [blame] | 859 | bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0 |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 860 | mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer |
| 861 | mcrne p15, 0, r1, c3, c0, 0 @ load domain access control |
Will Deacon | dbece45 | 2012-08-24 15:20:59 +0100 | [diff] [blame] | 862 | mcrne p15, 0, r6, c2, c0, 2 @ load ttb control |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 863 | #endif |
Will Deacon | d675d0b | 2011-11-22 17:30:28 +0000 | [diff] [blame] | 864 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 865 | mcr p15, 0, r0, c1, c0, 0 @ load control register |
| 866 | mrc p15, 0, r0, c1, c0, 0 @ and read it back |
| 867 | mov r0, #0 |
| 868 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
| 869 | mov pc, r12 |
| 870 | |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 871 | __fa526_cache_on: |
| 872 | mov r12, lr |
Russell King | 1fdc08a | 2012-05-10 09:48:34 +0100 | [diff] [blame] | 873 | mov r6, #CB_BITS | 0x12 @ U |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 874 | bl __setup_mmu |
| 875 | mov r0, #0 |
| 876 | mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache |
| 877 | mcr p15, 0, r0, c7, c10, 4 @ drain write buffer |
| 878 | mcr p15, 0, r0, c8, c7, 0 @ flush UTLB |
| 879 | mrc p15, 0, r0, c1, c0, 0 @ read control reg |
| 880 | orr r0, r0, #0x1000 @ I-cache enable |
| 881 | bl __common_mmu_cache_on |
| 882 | mov r0, #0 |
| 883 | mcr p15, 0, r0, c8, c7, 0 @ flush UTLB |
| 884 | mov pc, r12 |
| 885 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 886 | __common_mmu_cache_on: |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 887 | #ifndef CONFIG_THUMB2_KERNEL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | #ifndef DEBUG |
| 889 | orr r0, r0, #0x000d @ Write buffer, mmu |
| 890 | #endif |
| 891 | mov r1, #-1 |
| 892 | mcr p15, 0, r3, c2, c0, 0 @ load page table pointer |
| 893 | mcr p15, 0, r1, c3, c0, 0 @ load domain access control |
Nicolas Pitre | 2dc7667 | 2006-07-01 21:29:32 +0100 | [diff] [blame] | 894 | b 1f |
| 895 | .align 5 @ cache line aligned |
| 896 | 1: mcr p15, 0, r0, c1, c0, 0 @ load control register |
| 897 | mrc p15, 0, r0, c1, c0, 0 @ and read it back to |
| 898 | sub pc, lr, r0, lsr #32 @ properly flush pipeline |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 899 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Dave Martin | 946a105 | 2011-06-14 14:20:44 +0100 | [diff] [blame] | 901 | #define PROC_ENTRY_SIZE (4*5) |
| 902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | * Here follow the relocatable cache support functions for the |
| 905 | * various processors. This is a generic hook for locating an |
| 906 | * entry and jumping to an instruction at the specified offset |
| 907 | * from the start of the block. Please note this is all position |
| 908 | * independent code. |
| 909 | * |
| 910 | * r1 = corrupted |
| 911 | * r2 = corrupted |
| 912 | * r3 = block offset |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 913 | * r9 = corrupted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | * r12 = corrupted |
| 915 | */ |
| 916 | |
| 917 | call_cache_fn: adr r12, proc_types |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 918 | #ifdef CONFIG_CPU_CP15 |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 919 | mrc p15, 0, r9, c0, c0 @ get processor ID |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 920 | #elif defined(CONFIG_CPU_V7M) |
| 921 | /* |
| 922 | * On v7-M the processor id is located in the V7M_SCB_CPUID |
| 923 | * register, but as cache handling is IMPLEMENTATION DEFINED on |
| 924 | * v7-M (if existant at all) we just return early here. |
| 925 | * If V7M_SCB_CPUID were used the cpu ID functions (i.e. |
| 926 | * __armv7_mmu_cache_{on,off,flush}) would be selected which |
| 927 | * use cp15 registers that are not implemented on v7-M. |
| 928 | */ |
| 929 | bx lr |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 930 | #else |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 931 | ldr r9, =CONFIG_PROCESSOR_ID |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 932 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | 1: ldr r1, [r12, #0] @ get value |
| 934 | ldr r2, [r12, #4] @ get mask |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 935 | eor r1, r1, r9 @ (real ^ match) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | tst r1, r2 @ & mask |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 937 | ARM( addeq pc, r12, r3 ) @ call cache function |
| 938 | THUMB( addeq r12, r3 ) |
| 939 | THUMB( moveq pc, r12 ) @ call cache function |
Dave Martin | 946a105 | 2011-06-14 14:20:44 +0100 | [diff] [blame] | 940 | add r12, r12, #PROC_ENTRY_SIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | b 1b |
| 942 | |
| 943 | /* |
| 944 | * Table for cache operations. This is basically: |
| 945 | * - CPU ID match |
| 946 | * - CPU ID mask |
| 947 | * - 'cache on' method instruction |
| 948 | * - 'cache off' method instruction |
| 949 | * - 'cache flush' method instruction |
| 950 | * |
| 951 | * We match an entry using: ((real_id ^ match) & mask) == 0 |
| 952 | * |
| 953 | * Writethrough caches generally only need 'on' and 'off' |
| 954 | * methods. Writeback caches _must_ have the flush method |
| 955 | * defined. |
| 956 | */ |
Catalin Marinas | 88987ef | 2009-07-24 12:32:52 +0100 | [diff] [blame] | 957 | .align 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | .type proc_types,#object |
| 959 | proc_types: |
Marc C | ced2a3b | 2013-06-05 22:02:23 +0100 | [diff] [blame] | 960 | .word 0x41000000 @ old ARM ID |
| 961 | .word 0xff00f000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 963 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 965 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 967 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
| 969 | .word 0x41007000 @ ARM7/710 |
| 970 | .word 0xfff8fe00 |
Russell King | 4cdfc2e | 2012-05-09 15:18:19 +0100 | [diff] [blame] | 971 | mov pc, lr |
| 972 | THUMB( nop ) |
| 973 | mov pc, lr |
| 974 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 976 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | .word 0x41807200 @ ARM720T (writethrough) |
| 979 | .word 0xffffff00 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 980 | W(b) __armv4_mmu_cache_on |
| 981 | W(b) __armv4_mmu_cache_off |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 983 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 985 | .word 0x41007400 @ ARM74x |
| 986 | .word 0xff00ff00 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 987 | W(b) __armv3_mpu_cache_on |
| 988 | W(b) __armv3_mpu_cache_off |
| 989 | W(b) __armv3_mpu_cache_flush |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 990 | |
| 991 | .word 0x41009400 @ ARM94x |
| 992 | .word 0xff00ff00 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 993 | W(b) __armv4_mpu_cache_on |
| 994 | W(b) __armv4_mpu_cache_off |
| 995 | W(b) __armv4_mpu_cache_flush |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 996 | |
Mark A. Greer | af3e4fd | 2011-04-01 15:41:26 +0100 | [diff] [blame] | 997 | .word 0x41069260 @ ARM926EJ-S (v5TEJ) |
| 998 | .word 0xff0ffff0 |
Nicolas Pitre | 720c60e | 2011-06-09 05:05:27 +0100 | [diff] [blame] | 999 | W(b) __arm926ejs_mmu_cache_on |
| 1000 | W(b) __armv4_mmu_cache_off |
| 1001 | W(b) __armv5tej_mmu_cache_flush |
Mark A. Greer | af3e4fd | 2011-04-01 15:41:26 +0100 | [diff] [blame] | 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | .word 0x00007000 @ ARM7 IDs |
| 1004 | .word 0x0000f000 |
| 1005 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1006 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1008 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1010 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | @ Everything from here on will be the new ID system. |
| 1013 | |
| 1014 | .word 0x4401a100 @ sa110 / sa1100 |
| 1015 | .word 0xffffffe0 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1016 | W(b) __armv4_mmu_cache_on |
| 1017 | W(b) __armv4_mmu_cache_off |
| 1018 | W(b) __armv4_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
| 1020 | .word 0x6901b110 @ sa1110 |
| 1021 | .word 0xfffffff0 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1022 | W(b) __armv4_mmu_cache_on |
| 1023 | W(b) __armv4_mmu_cache_off |
| 1024 | W(b) __armv4_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Haojian Zhuang | 4157d31 | 2010-03-12 05:47:55 -0500 | [diff] [blame] | 1026 | .word 0x56056900 |
| 1027 | .word 0xffffff00 @ PXA9xx |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1028 | W(b) __armv4_mmu_cache_on |
| 1029 | W(b) __armv4_mmu_cache_off |
| 1030 | W(b) __armv4_mmu_cache_flush |
Eric Miao | 59c7bcd | 2008-11-29 21:42:39 +0800 | [diff] [blame] | 1031 | |
Eric Miao | 49cbe78 | 2009-01-20 14:15:18 +0800 | [diff] [blame] | 1032 | .word 0x56158000 @ PXA168 |
| 1033 | .word 0xfffff000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1034 | W(b) __armv4_mmu_cache_on |
| 1035 | W(b) __armv4_mmu_cache_off |
| 1036 | W(b) __armv5tej_mmu_cache_flush |
Eric Miao | 49cbe78 | 2009-01-20 14:15:18 +0800 | [diff] [blame] | 1037 | |
Nicolas Pitre | 2e2023f | 2008-06-03 23:06:21 +0200 | [diff] [blame] | 1038 | .word 0x56050000 @ Feroceon |
| 1039 | .word 0xff0f0000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1040 | W(b) __armv4_mmu_cache_on |
| 1041 | W(b) __armv4_mmu_cache_off |
| 1042 | W(b) __armv5tej_mmu_cache_flush |
Nicolas Pitre | 3ebb5a2 | 2007-10-31 15:31:48 -0400 | [diff] [blame] | 1043 | |
Joonyoung Shim | 5587931 | 2009-06-16 20:05:57 +0900 | [diff] [blame] | 1044 | #ifdef CONFIG_CPU_FEROCEON_OLD_ID |
| 1045 | /* this conflicts with the standard ARMv5TE entry */ |
| 1046 | .long 0x41009260 @ Old Feroceon |
| 1047 | .long 0xff00fff0 |
| 1048 | b __armv4_mmu_cache_on |
| 1049 | b __armv4_mmu_cache_off |
| 1050 | b __armv5tej_mmu_cache_flush |
| 1051 | #endif |
| 1052 | |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 1053 | .word 0x66015261 @ FA526 |
| 1054 | .word 0xff01fff1 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1055 | W(b) __fa526_cache_on |
| 1056 | W(b) __armv4_mmu_cache_off |
| 1057 | W(b) __fa526_cache_flush |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 1058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | @ These match on the architecture ID |
| 1060 | |
| 1061 | .word 0x00020000 @ ARMv4T |
| 1062 | .word 0x000f0000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1063 | W(b) __armv4_mmu_cache_on |
| 1064 | W(b) __armv4_mmu_cache_off |
| 1065 | W(b) __armv4_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
| 1067 | .word 0x00050000 @ ARMv5TE |
| 1068 | .word 0x000f0000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1069 | W(b) __armv4_mmu_cache_on |
| 1070 | W(b) __armv4_mmu_cache_off |
| 1071 | W(b) __armv4_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | .word 0x00060000 @ ARMv5TEJ |
| 1074 | .word 0x000f0000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1075 | W(b) __armv4_mmu_cache_on |
| 1076 | W(b) __armv4_mmu_cache_off |
Sascha Hauer | 7521685 | 2010-03-15 15:14:50 +0100 | [diff] [blame] | 1077 | W(b) __armv5tej_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Catalin Marinas | 45a7b9c | 2006-06-18 16:21:50 +0100 | [diff] [blame] | 1079 | .word 0x0007b000 @ ARMv6 |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1080 | .word 0x000ff000 |
Dave Martin | 5010192 | 2012-11-22 12:50:43 +0100 | [diff] [blame] | 1081 | W(b) __armv6_mmu_cache_on |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1082 | W(b) __armv4_mmu_cache_off |
| 1083 | W(b) __armv6_mmu_cache_flush |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1085 | .word 0x000f0000 @ new CPU Id |
| 1086 | .word 0x000f0000 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1087 | W(b) __armv7_mmu_cache_on |
| 1088 | W(b) __armv7_mmu_cache_off |
| 1089 | W(b) __armv7_mmu_cache_flush |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | .word 0 @ unrecognised type |
| 1092 | .word 0 |
| 1093 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1094 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1096 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | mov pc, lr |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1098 | THUMB( nop ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | .size proc_types, . - proc_types |
| 1101 | |
Dave Martin | 946a105 | 2011-06-14 14:20:44 +0100 | [diff] [blame] | 1102 | /* |
| 1103 | * If you get a "non-constant expression in ".if" statement" |
| 1104 | * error from the assembler on this line, check that you have |
| 1105 | * not accidentally written a "b" instruction where you should |
| 1106 | * have written W(b). |
| 1107 | */ |
| 1108 | .if (. - proc_types) % PROC_ENTRY_SIZE != 0 |
| 1109 | .error "The size of one or more proc_types entries is wrong." |
| 1110 | .endif |
| 1111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | /* |
| 1113 | * Turn off the Cache and MMU. ARMv3 does not support |
| 1114 | * reading the control register, but ARMv4 does. |
| 1115 | * |
Uwe Kleine-König | 21b2841 | 2010-01-26 22:08:09 +0100 | [diff] [blame] | 1116 | * On exit, |
| 1117 | * r0, r1, r2, r3, r9, r12 corrupted |
| 1118 | * This routine must preserve: |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 1119 | * r4, r7, r8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | */ |
| 1121 | .align 5 |
| 1122 | cache_off: mov r3, #12 @ cache_off function |
| 1123 | b call_cache_fn |
| 1124 | |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 1125 | __armv4_mpu_cache_off: |
| 1126 | mrc p15, 0, r0, c1, c0 |
| 1127 | bic r0, r0, #0x000d |
| 1128 | mcr p15, 0, r0, c1, c0 @ turn MPU and cache off |
| 1129 | mov r0, #0 |
| 1130 | mcr p15, 0, r0, c7, c10, 4 @ drain write buffer |
| 1131 | mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache |
| 1132 | mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache |
| 1133 | mov pc, lr |
| 1134 | |
| 1135 | __armv3_mpu_cache_off: |
| 1136 | mrc p15, 0, r0, c1, c0 |
| 1137 | bic r0, r0, #0x000d |
| 1138 | mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off |
| 1139 | mov r0, #0 |
| 1140 | mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3 |
| 1141 | mov pc, lr |
| 1142 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 1143 | __armv4_mmu_cache_off: |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1144 | #ifdef CONFIG_MMU |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | mrc p15, 0, r0, c1, c0 |
| 1146 | bic r0, r0, #0x000d |
| 1147 | mcr p15, 0, r0, c1, c0 @ turn MMU and cache off |
| 1148 | mov r0, #0 |
| 1149 | mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4 |
| 1150 | mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4 |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1151 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | mov pc, lr |
| 1153 | |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1154 | __armv7_mmu_cache_off: |
| 1155 | mrc p15, 0, r0, c1, c0 |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1156 | #ifdef CONFIG_MMU |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1157 | bic r0, r0, #0x000d |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1158 | #else |
| 1159 | bic r0, r0, #0x000c |
| 1160 | #endif |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1161 | mcr p15, 0, r0, c1, c0 @ turn MMU and cache off |
| 1162 | mov r12, lr |
| 1163 | bl __armv7_mmu_cache_flush |
| 1164 | mov r0, #0 |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1165 | #ifdef CONFIG_MMU |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1166 | mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB |
Catalin Marinas | 8bdca0a | 2009-07-24 12:35:06 +0100 | [diff] [blame] | 1167 | #endif |
Catalin Marinas | c30c2f9 | 2008-11-06 13:23:07 +0000 | [diff] [blame] | 1168 | mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC |
| 1169 | mcr p15, 0, r0, c7, c10, 4 @ DSB |
| 1170 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1171 | mov pc, r12 |
| 1172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | /* |
| 1174 | * Clean and flush the cache to maintain consistency. |
| 1175 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | * On exit, |
Uwe Kleine-König | 21b2841 | 2010-01-26 22:08:09 +0100 | [diff] [blame] | 1177 | * r1, r2, r3, r9, r10, r11, r12 corrupted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | * This routine must preserve: |
Nicolas Pitre | 6d7d0ae | 2011-02-21 07:06:45 +0100 | [diff] [blame] | 1179 | * r4, r6, r7, r8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | */ |
| 1181 | .align 5 |
| 1182 | cache_clean_flush: |
| 1183 | mov r3, #16 |
| 1184 | b call_cache_fn |
| 1185 | |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 1186 | __armv4_mpu_cache_flush: |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1187 | tst r4, #1 |
| 1188 | movne pc, lr |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 1189 | mov r2, #1 |
| 1190 | mov r3, #0 |
| 1191 | mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache |
| 1192 | mov r1, #7 << 5 @ 8 segments |
| 1193 | 1: orr r3, r1, #63 << 26 @ 64 entries |
| 1194 | 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index |
| 1195 | subs r3, r3, #1 << 26 |
| 1196 | bcs 2b @ entries 63 to 0 |
| 1197 | subs r1, r1, #1 << 5 |
| 1198 | bcs 1b @ segments 7 to 0 |
| 1199 | |
| 1200 | teq r2, #0 |
| 1201 | mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache |
| 1202 | mcr p15, 0, ip, c7, c10, 4 @ drain WB |
| 1203 | mov pc, lr |
| 1204 | |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 1205 | __fa526_cache_flush: |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1206 | tst r4, #1 |
| 1207 | movne pc, lr |
Paulius Zaleckas | 28853ac | 2009-03-25 13:10:01 +0200 | [diff] [blame] | 1208 | mov r1, #0 |
| 1209 | mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache |
| 1210 | mcr p15, 0, r1, c7, c5, 0 @ flush I cache |
| 1211 | mcr p15, 0, r1, c7, c10, 4 @ drain WB |
| 1212 | mov pc, lr |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 1213 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 1214 | __armv6_mmu_cache_flush: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | mov r1, #0 |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1216 | tst r4, #1 |
| 1217 | mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1219 | mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | mcr p15, 0, r1, c7, c10, 4 @ drain WB |
| 1221 | mov pc, lr |
| 1222 | |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1223 | __armv7_mmu_cache_flush: |
Ard Biesheuvel | 8239fc7 | 2019-11-22 12:59:00 +0100 | [diff] [blame] | 1224 | enable_cp15_barriers r10 |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1225 | tst r4, #1 |
| 1226 | bne iflush |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1227 | mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1 |
| 1228 | tst r10, #0xf << 16 @ hierarchical cache (ARMv7) |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1229 | mov r10, #0 |
Catalin Marinas | c30c2f9 | 2008-11-06 13:23:07 +0000 | [diff] [blame] | 1230 | beq hierarchical |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1231 | mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D |
| 1232 | b iflush |
| 1233 | hierarchical: |
Catalin Marinas | c30c2f9 | 2008-11-06 13:23:07 +0000 | [diff] [blame] | 1234 | mcr p15, 0, r10, c7, c10, 5 @ DMB |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1235 | stmfd sp!, {r0-r7, r9-r11} |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1236 | mrc p15, 1, r0, c0, c0, 1 @ read clidr |
| 1237 | ands r3, r0, #0x7000000 @ extract loc from clidr |
| 1238 | mov r3, r3, lsr #23 @ left align loc bit field |
| 1239 | beq finished @ if loc is 0, then no need to clean |
| 1240 | mov r10, #0 @ start clean at cache level 0 |
| 1241 | loop1: |
| 1242 | add r2, r10, r10, lsr #1 @ work out 3x current cache level |
| 1243 | mov r1, r0, lsr r2 @ extract cache type bits from clidr |
| 1244 | and r1, r1, #7 @ mask of the bits for current cache only |
| 1245 | cmp r1, #2 @ see what cache we have at this level |
| 1246 | blt skip @ skip if no cache, or just i-cache |
| 1247 | mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr |
| 1248 | mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr |
| 1249 | mrc p15, 1, r1, c0, c0, 0 @ read the new csidr |
| 1250 | and r2, r1, #7 @ extract the length of the cache lines |
| 1251 | add r2, r2, #4 @ add 4 (line length offset) |
| 1252 | ldr r4, =0x3ff |
| 1253 | ands r4, r4, r1, lsr #3 @ find maximum number on the way size |
Catalin Marinas | 000b502 | 2008-10-03 11:09:10 +0100 | [diff] [blame] | 1254 | clz r5, r4 @ find bit position of way size increment |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1255 | ldr r7, =0x7fff |
| 1256 | ands r7, r7, r1, lsr #13 @ extract max number of the index size |
| 1257 | loop2: |
| 1258 | mov r9, r4 @ create working copy of max way size |
| 1259 | loop3: |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1260 | ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11 |
| 1261 | ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11 |
| 1262 | THUMB( lsl r6, r9, r5 ) |
| 1263 | THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11 |
| 1264 | THUMB( lsl r6, r7, r2 ) |
| 1265 | THUMB( orr r11, r11, r6 ) @ factor index number into r11 |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1266 | mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way |
| 1267 | subs r9, r9, #1 @ decrement the way |
| 1268 | bge loop3 |
| 1269 | subs r7, r7, #1 @ decrement the index |
| 1270 | bge loop2 |
| 1271 | skip: |
| 1272 | add r10, r10, #2 @ increment cache number |
| 1273 | cmp r3, r10 |
| 1274 | bgt loop1 |
| 1275 | finished: |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1276 | ldmfd sp!, {r0-r7, r9-r11} |
Masahiro Yamada | 08a7e62 | 2017-02-27 14:28:41 -0800 | [diff] [blame] | 1277 | mov r10, #0 @ switch back to cache level 0 |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1278 | mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1279 | iflush: |
Catalin Marinas | c30c2f9 | 2008-11-06 13:23:07 +0000 | [diff] [blame] | 1280 | mcr p15, 0, r10, c7, c10, 4 @ DSB |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1281 | mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB |
Catalin Marinas | c30c2f9 | 2008-11-06 13:23:07 +0000 | [diff] [blame] | 1282 | mcr p15, 0, r10, c7, c10, 4 @ DSB |
| 1283 | mcr p15, 0, r10, c7, c5, 4 @ ISB |
Catalin Marinas | 7d09e85 | 2007-06-01 17:14:53 +0100 | [diff] [blame] | 1284 | mov pc, lr |
| 1285 | |
Nicolas Pitre | 15754bf | 2007-10-31 15:15:29 -0400 | [diff] [blame] | 1286 | __armv5tej_mmu_cache_flush: |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1287 | tst r4, #1 |
| 1288 | movne pc, lr |
Stefan Agner | 9f1984c6 | 2019-11-03 19:22:06 +0100 | [diff] [blame] | 1289 | 1: mrc p15, 0, APSR_nzcv, c7, c14, 3 @ test,clean,invalidate D cache |
Nicolas Pitre | 15754bf | 2007-10-31 15:15:29 -0400 | [diff] [blame] | 1290 | bne 1b |
| 1291 | mcr p15, 0, r0, c7, c5, 0 @ flush I cache |
| 1292 | mcr p15, 0, r0, c7, c10, 4 @ drain WB |
| 1293 | mov pc, lr |
| 1294 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 1295 | __armv4_mmu_cache_flush: |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1296 | tst r4, #1 |
| 1297 | movne pc, lr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | mov r2, #64*1024 @ default: 32K dcache size (*2) |
| 1299 | mov r11, #32 @ default: 32 byte line size |
| 1300 | mrc p15, 0, r3, c0, c0, 1 @ read cache type |
Russell King | 98e12b5 | 2010-02-25 23:56:38 +0000 | [diff] [blame] | 1301 | teq r3, r9 @ cache ID register present? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | beq no_cache_id |
| 1303 | mov r1, r3, lsr #18 |
| 1304 | and r1, r1, #7 |
| 1305 | mov r2, #1024 |
| 1306 | mov r2, r2, lsl r1 @ base dcache size *2 |
| 1307 | tst r3, #1 << 14 @ test M bit |
| 1308 | addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1 |
| 1309 | mov r3, r3, lsr #12 |
| 1310 | and r3, r3, #3 |
| 1311 | mov r11, #8 |
| 1312 | mov r11, r11, lsl r3 @ cache line size in bytes |
| 1313 | no_cache_id: |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1314 | mov r1, pc |
| 1315 | bic r1, r1, #63 @ align to longest cache line |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | add r2, r1, r2 |
Catalin Marinas | 0e056f2 | 2009-07-24 12:32:58 +0100 | [diff] [blame] | 1317 | 1: |
| 1318 | ARM( ldr r3, [r1], r11 ) @ s/w flush D cache |
| 1319 | THUMB( ldr r3, [r1] ) @ s/w flush D cache |
| 1320 | THUMB( add r1, r1, r11 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | teq r1, r2 |
| 1322 | bne 1b |
| 1323 | |
| 1324 | mcr p15, 0, r1, c7, c5, 0 @ flush I cache |
| 1325 | mcr p15, 0, r1, c7, c6, 0 @ flush D cache |
| 1326 | mcr p15, 0, r1, c7, c10, 4 @ drain WB |
| 1327 | mov pc, lr |
| 1328 | |
Hyok S. Choi | c76b6b4 | 2006-03-24 09:53:18 +0000 | [diff] [blame] | 1329 | __armv3_mmu_cache_flush: |
Hyok S. Choi | 10c2df6 | 2006-03-27 10:21:34 +0100 | [diff] [blame] | 1330 | __armv3_mpu_cache_flush: |
Will Deacon | 238962a | 2014-11-04 11:40:46 +0100 | [diff] [blame] | 1331 | tst r4, #1 |
| 1332 | movne pc, lr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | mov r1, #0 |
Uwe Kleine-König | 63fa718 | 2010-01-26 22:18:09 +0100 | [diff] [blame] | 1334 | mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | mov pc, lr |
| 1336 | |
| 1337 | /* |
| 1338 | * Various debugging routines for printing hex characters and |
| 1339 | * memory, which again must be relocatable. |
| 1340 | */ |
| 1341 | #ifdef DEBUG |
Catalin Marinas | 88987ef | 2009-07-24 12:32:52 +0100 | [diff] [blame] | 1342 | .align 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | .type phexbuf,#object |
| 1344 | phexbuf: .space 12 |
| 1345 | .size phexbuf, . - phexbuf |
| 1346 | |
Uwe Kleine-König | be6f9f0 | 2010-01-26 22:22:20 +0100 | [diff] [blame] | 1347 | @ phex corrupts {r0, r1, r2, r3} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | phex: adr r3, phexbuf |
| 1349 | mov r2, #0 |
| 1350 | strb r2, [r3, r1] |
| 1351 | 1: subs r1, r1, #1 |
| 1352 | movmi r0, r3 |
| 1353 | bmi puts |
| 1354 | and r2, r0, #15 |
| 1355 | mov r0, r0, lsr #4 |
| 1356 | cmp r2, #10 |
| 1357 | addge r2, r2, #7 |
| 1358 | add r2, r2, #'0' |
| 1359 | strb r2, [r3, r1] |
| 1360 | b 1b |
| 1361 | |
Uwe Kleine-König | be6f9f0 | 2010-01-26 22:22:20 +0100 | [diff] [blame] | 1362 | @ puts corrupts {r0, r1, r2, r3} |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 1363 | puts: loadsp r3, r2, r1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | 1: ldrb r2, [r0], #1 |
| 1365 | teq r2, #0 |
| 1366 | moveq pc, lr |
Russell King | 5cd0c34 | 2005-05-03 12:18:46 +0100 | [diff] [blame] | 1367 | 2: writeb r2, r3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | mov r1, #0x00020000 |
| 1369 | 3: subs r1, r1, #1 |
| 1370 | bne 3b |
| 1371 | teq r2, #'\n' |
| 1372 | moveq r2, #'\r' |
| 1373 | beq 2b |
| 1374 | teq r0, #0 |
| 1375 | bne 1b |
| 1376 | mov pc, lr |
Uwe Kleine-König | be6f9f0 | 2010-01-26 22:22:20 +0100 | [diff] [blame] | 1377 | @ putc corrupts {r0, r1, r2, r3} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | putc: |
| 1379 | mov r2, r0 |
Łukasz Stelmach | e07e3c3 | 2018-04-03 09:04:57 +0100 | [diff] [blame] | 1380 | loadsp r3, r1, r0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | mov r0, #0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | b 2b |
| 1383 | |
Uwe Kleine-König | be6f9f0 | 2010-01-26 22:22:20 +0100 | [diff] [blame] | 1384 | @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | memdump: mov r12, r0 |
| 1386 | mov r10, lr |
| 1387 | mov r11, #0 |
| 1388 | 2: mov r0, r11, lsl #2 |
| 1389 | add r0, r0, r12 |
| 1390 | mov r1, #8 |
| 1391 | bl phex |
| 1392 | mov r0, #':' |
| 1393 | bl putc |
| 1394 | 1: mov r0, #' ' |
| 1395 | bl putc |
| 1396 | ldr r0, [r12, r11, lsl #2] |
| 1397 | mov r1, #8 |
| 1398 | bl phex |
| 1399 | and r0, r11, #7 |
| 1400 | teq r0, #3 |
| 1401 | moveq r0, #' ' |
| 1402 | bleq putc |
| 1403 | and r0, r11, #7 |
| 1404 | add r11, r11, #1 |
| 1405 | teq r0, #7 |
| 1406 | bne 1b |
| 1407 | mov r0, #'\n' |
| 1408 | bl putc |
| 1409 | cmp r11, #64 |
| 1410 | blt 2b |
| 1411 | mov pc, r10 |
| 1412 | #endif |
| 1413 | |
Catalin Marinas | 92c83ff1 | 2007-06-22 14:27:50 +0100 | [diff] [blame] | 1414 | .ltorg |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 1415 | |
| 1416 | #ifdef CONFIG_ARM_VIRT_EXT |
| 1417 | .align 5 |
| 1418 | __hyp_reentry_vectors: |
| 1419 | W(b) . @ reset |
| 1420 | W(b) . @ undef |
| 1421 | W(b) . @ svc |
| 1422 | W(b) . @ pabort |
| 1423 | W(b) . @ dabort |
| 1424 | W(b) __enter_kernel @ hyp |
| 1425 | W(b) . @ irq |
| 1426 | W(b) . @ fiq |
| 1427 | #endif /* CONFIG_ARM_VIRT_EXT */ |
| 1428 | |
| 1429 | __enter_kernel: |
| 1430 | mov r0, #0 @ must be 0 |
Łukasz Stelmach | f2ae9de | 2018-04-04 08:46:58 +0100 | [diff] [blame] | 1431 | mov r1, r7 @ restore architecture number |
| 1432 | mov r2, r8 @ restore atags pointer |
Joachim Eastwood | c20611d | 2015-03-25 08:47:18 +0100 | [diff] [blame] | 1433 | ARM( mov pc, r4 ) @ call kernel |
| 1434 | M_CLASS( add r4, r4, #1 ) @ enter in Thumb mode for M class |
| 1435 | THUMB( bx r4 ) @ entry point is always ARM for A/R classes |
Dave Martin | 424e599 | 2012-02-10 18:07:07 -0800 | [diff] [blame] | 1436 | |
Nicolas Pitre | adcc259 | 2011-04-27 16:15:11 -0400 | [diff] [blame] | 1437 | reloc_code_end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 1439 | #ifdef CONFIG_EFI_STUB |
| 1440 | .align 2 |
| 1441 | _start: .long start - . |
| 1442 | |
| 1443 | ENTRY(efi_stub_entry) |
| 1444 | @ allocate space on stack for passing current zImage address |
| 1445 | @ and for the EFI stub to return of new entry point of |
| 1446 | @ zImage, as EFI stub may copy the kernel. Pointer address |
| 1447 | @ is passed in r2. r0 and r1 are passed through from the |
| 1448 | @ EFI firmware to efi_entry |
| 1449 | adr ip, _start |
| 1450 | ldr r3, [ip] |
| 1451 | add r3, r3, ip |
| 1452 | stmfd sp!, {r3, lr} |
| 1453 | mov r2, sp @ pass zImage address in r2 |
| 1454 | bl efi_entry |
| 1455 | |
| 1456 | @ Check for error return from EFI stub. r0 has FDT address |
| 1457 | @ or error code. |
| 1458 | cmn r0, #1 |
| 1459 | beq efi_load_fail |
| 1460 | |
| 1461 | @ Preserve return value of efi_entry() in r4 |
| 1462 | mov r4, r0 |
Ard Biesheuvel | e951a1f | 2020-02-19 00:09:48 +0100 | [diff] [blame^] | 1463 | add r1, r4, #SZ_2M @ DT end |
| 1464 | bl cache_clean_flush |
| 1465 | |
| 1466 | ldr r0, [sp] @ relocated zImage |
| 1467 | ldr r1, =_edata @ size of zImage |
| 1468 | add r1, r1, r0 @ end of zImage |
Ard Biesheuvel | cf17a1e | 2019-11-22 13:01:17 +0100 | [diff] [blame] | 1469 | bl cache_clean_flush |
Ard Biesheuvel | c722549 | 2020-02-18 12:34:05 +0100 | [diff] [blame] | 1470 | |
| 1471 | @ The PE/COFF loader might not have cleaned the code we are |
| 1472 | @ running beyond the PoU, and so calling cache_off below from |
| 1473 | @ inside the PE/COFF loader allocated region is unsafe. Let's |
| 1474 | @ assume our own zImage relocation code did a better job, and |
| 1475 | @ jump into its version of this routine before proceeding. |
| 1476 | ldr r0, [sp] @ relocated zImage |
| 1477 | ldr r1, .Ljmp |
| 1478 | sub r1, r0, r1 |
| 1479 | mov pc, r1 @ no mode switch |
| 1480 | 0: |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 1481 | bl cache_off |
| 1482 | |
| 1483 | @ Set parameters for booting zImage according to boot protocol |
| 1484 | @ put FDT address in r2, it was returned by efi_entry() |
| 1485 | @ r1 is the machine type, and r0 needs to be 0 |
| 1486 | mov r0, #0 |
| 1487 | mov r1, #0xFFFFFFFF |
| 1488 | mov r2, r4 |
Ard Biesheuvel | c722549 | 2020-02-18 12:34:05 +0100 | [diff] [blame] | 1489 | b __efi_start |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 1490 | |
| 1491 | efi_load_fail: |
| 1492 | @ Return EFI_LOAD_ERROR to EFI firmware on error. |
| 1493 | ldr r0, =0x80000001 |
| 1494 | ldmfd sp!, {ip, pc} |
| 1495 | ENDPROC(efi_stub_entry) |
Ard Biesheuvel | c722549 | 2020-02-18 12:34:05 +0100 | [diff] [blame] | 1496 | .align 2 |
| 1497 | .Ljmp: .long start - 0b |
Roy Franz | 81a0bc3 | 2015-09-23 20:17:54 -0700 | [diff] [blame] | 1498 | #endif |
| 1499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | .align |
Russell King | b0c4d4e | 2010-11-22 12:00:59 +0000 | [diff] [blame] | 1501 | .section ".stack", "aw", %nobits |
Nicolas Pitre | 8d7e4cc | 2011-04-27 14:54:39 -0400 | [diff] [blame] | 1502 | .L_user_stack: .space 4096 |
| 1503 | .L_user_stack_end: |