Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/head-nommu.S |
| 3 | * |
| 4 | * Copyright (C) 1994-2002 Russell King |
| 5 | * Copyright (C) 2003-2006 Hyok S. Choi |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * Common kernel startup code (non-paged MM) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 12 | * |
| 13 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 14 | #include <linux/linkage.h> |
| 15 | #include <linux/init.h> |
| 16 | |
| 17 | #include <asm/assembler.h> |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 18 | #include <asm/ptrace.h> |
Uwe Zeisberger | 2eb9d31 | 2006-05-05 15:11:14 +0100 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame^] | 20 | #include <asm/memory.h> |
Russell King | 15d07dc | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 21 | #include <asm/cp15.h> |
Hyok S. Choi | 3b920ce | 2006-04-24 09:45:35 +0100 | [diff] [blame] | 22 | #include <asm/thread_info.h> |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 23 | #include <asm/v7m.h> |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame^] | 24 | #include <asm/mpu.h> |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 25 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Kernel startup entry point. |
| 28 | * --------------------------- |
| 29 | * |
| 30 | * This is normally called from the decompressor code. The requirements |
| 31 | * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0, |
| 32 | * r1 = machine nr. |
| 33 | * |
| 34 | * See linux/arch/arm/tools/mach-types for the complete list of machine |
| 35 | * numbers for r1. |
| 36 | * |
| 37 | */ |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 38 | |
Tim Abbott | 2abc1c5 | 2009-10-02 16:32:46 -0400 | [diff] [blame] | 39 | __HEAD |
Uwe Kleine-König | bc7dea0 | 2011-12-09 20:52:10 +0100 | [diff] [blame] | 40 | |
| 41 | #ifdef CONFIG_CPU_THUMBONLY |
| 42 | .thumb |
| 43 | ENTRY(stext) |
| 44 | #else |
| 45 | .arm |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 46 | ENTRY(stext) |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 47 | |
| 48 | THUMB( adr r9, BSYM(1f) ) @ Kernel is always entered in ARM. |
| 49 | THUMB( bx r9 ) @ If this is a Thumb-2 kernel, |
| 50 | THUMB( .thumb ) @ switch to Thumb now. |
| 51 | THUMB(1: ) |
Uwe Kleine-König | bc7dea0 | 2011-12-09 20:52:10 +0100 | [diff] [blame] | 52 | #endif |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 53 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 54 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 55 | @ and irqs disabled |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 56 | #if defined(CONFIG_CPU_CP15) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 57 | mrc p15, 0, r9, c0, c0 @ get processor id |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 58 | #elif defined(CONFIG_CPU_V7M) |
| 59 | ldr r9, =BASEADDR_V7M_SCB |
| 60 | ldr r9, [r9, V7M_SCB_CPUID] |
| 61 | #else |
| 62 | ldr r9, =CONFIG_PROCESSOR_ID |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 63 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 64 | bl __lookup_processor_type @ r5=procinfo r9=cpuid |
| 65 | movs r10, r5 @ invalid processor (r5=0)? |
| 66 | beq __error_p @ yes, error 'p' |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 67 | |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame^] | 68 | #ifdef CONFIG_ARM_MPU |
| 69 | /* Calculate the size of a region covering just the kernel */ |
| 70 | ldr r5, =PHYS_OFFSET @ Region start: PHYS_OFFSET |
| 71 | ldr r6, =(_end) @ Cover whole kernel |
| 72 | sub r6, r6, r5 @ Minimum size of region to map |
| 73 | clz r6, r6 @ Region size must be 2^N... |
| 74 | rsb r6, r6, #31 @ ...so round up region size |
| 75 | lsl r6, r6, #MPU_RSR_SZ @ Put size in right field |
| 76 | orr r6, r6, #(1 << MPU_RSR_EN) @ Set region enabled bit |
| 77 | bl __setup_mpu |
| 78 | #endif |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 79 | ldr r13, =__mmap_switched @ address to jump to after |
| 80 | @ initialising sctlr |
| 81 | adr lr, BSYM(1f) @ return (PIC) address |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 82 | ARM( add pc, r10, #PROCINFO_INITFUNC ) |
| 83 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 84 | THUMB( mov pc, r12 ) |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 85 | 1: b __after_proc_init |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 86 | ENDPROC(stext) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 87 | |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 88 | #ifdef CONFIG_SMP |
| 89 | __CPUINIT |
| 90 | ENTRY(secondary_startup) |
| 91 | /* |
| 92 | * Common entry point for secondary CPUs. |
| 93 | * |
| 94 | * Ensure that we're in SVC mode, and IRQs are disabled. Lookup |
| 95 | * the processor type - there is no need to check the machine type |
| 96 | * as it has already been validated by the primary processor. |
| 97 | */ |
| 98 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 |
| 99 | #ifndef CONFIG_CPU_CP15 |
| 100 | ldr r9, =CONFIG_PROCESSOR_ID |
| 101 | #else |
| 102 | mrc p15, 0, r9, c0, c0 @ get processor id |
| 103 | #endif |
| 104 | bl __lookup_processor_type @ r5=procinfo r9=cpuid |
| 105 | movs r10, r5 @ invalid processor? |
| 106 | beq __error_p @ yes, error 'p' |
| 107 | |
| 108 | adr r4, __secondary_data |
| 109 | ldmia r4, {r7, r12} |
| 110 | adr lr, BSYM(__after_proc_init) @ return address |
| 111 | mov r13, r12 @ __secondary_switched address |
| 112 | ARM( add pc, r10, #PROCINFO_INITFUNC ) |
| 113 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 114 | THUMB( mov pc, r12 ) |
| 115 | ENDPROC(secondary_startup) |
| 116 | |
| 117 | ENTRY(__secondary_switched) |
| 118 | ldr sp, [r7, #8] @ set up the stack pointer |
| 119 | mov fp, #0 |
| 120 | b secondary_start_kernel |
| 121 | ENDPROC(__secondary_switched) |
| 122 | |
| 123 | .type __secondary_data, %object |
| 124 | __secondary_data: |
| 125 | .long secondary_data |
| 126 | .long __secondary_switched |
| 127 | #endif /* CONFIG_SMP */ |
| 128 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 129 | /* |
| 130 | * Set the Control Register and Read the process ID. |
| 131 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 132 | __after_proc_init: |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 133 | #ifdef CONFIG_CPU_CP15 |
Catalin Marinas | 05efde9 | 2009-07-24 12:34:59 +0100 | [diff] [blame] | 134 | /* |
| 135 | * CP15 system control register value returned in r0 from |
| 136 | * the CPU init function. |
| 137 | */ |
Armando Visconti | 76e0920 | 2012-12-04 10:34:39 +0100 | [diff] [blame] | 138 | #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 139 | orr r0, r0, #CR_A |
| 140 | #else |
| 141 | bic r0, r0, #CR_A |
| 142 | #endif |
| 143 | #ifdef CONFIG_CPU_DCACHE_DISABLE |
| 144 | bic r0, r0, #CR_C |
| 145 | #endif |
| 146 | #ifdef CONFIG_CPU_BPREDICT_DISABLE |
| 147 | bic r0, r0, #CR_Z |
| 148 | #endif |
| 149 | #ifdef CONFIG_CPU_ICACHE_DISABLE |
| 150 | bic r0, r0, #CR_I |
| 151 | #endif |
Hyok S. Choi | 6afd6fa | 2006-09-28 21:46:34 +0900 | [diff] [blame] | 152 | #ifdef CONFIG_CPU_HIGH_VECTOR |
| 153 | orr r0, r0, #CR_V |
| 154 | #else |
| 155 | bic r0, r0, #CR_V |
| 156 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 157 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 158 | #endif /* CONFIG_CPU_CP15 */ |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 159 | mov pc, r13 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 160 | ENDPROC(__after_proc_init) |
Hyok S. Choi | 3b920ce | 2006-04-24 09:45:35 +0100 | [diff] [blame] | 161 | .ltorg |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 162 | |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame^] | 163 | #ifdef CONFIG_ARM_MPU |
| 164 | |
| 165 | |
| 166 | /* Set which MPU region should be programmed */ |
| 167 | .macro set_region_nr tmp, rgnr |
| 168 | mov \tmp, \rgnr @ Use static region numbers |
| 169 | mcr p15, 0, \tmp, c6, c2, 0 @ Write RGNR |
| 170 | .endm |
| 171 | |
| 172 | /* Setup a single MPU region, either D or I side (D-side for unified) */ |
| 173 | .macro setup_region bar, acr, sr, side = MPU_DATA_SIDE |
| 174 | mcr p15, 0, \bar, c6, c1, (0 + \side) @ I/DRBAR |
| 175 | mcr p15, 0, \acr, c6, c1, (4 + \side) @ I/DRACR |
| 176 | mcr p15, 0, \sr, c6, c1, (2 + \side) @ I/DRSR |
| 177 | .endm |
| 178 | |
| 179 | /* |
| 180 | * Setup the MPU and initial MPU Regions. We create the following regions: |
| 181 | * Region 0: Use this for probing the MPU details, so leave disabled. |
| 182 | * Region 1: Background region - covers the whole of RAM as strongly ordered |
| 183 | * Region 2: Normal, Shared, cacheable for RAM. From PHYS_OFFSET, size from r6 |
| 184 | * |
| 185 | * r6: Value to be written to DRSR (and IRSR if required) for MPU_RAM_REGION |
| 186 | */ |
| 187 | |
| 188 | ENTRY(__setup_mpu) |
| 189 | |
| 190 | /* Probe for v7 PMSA compliance */ |
| 191 | mrc p15, 0, r0, c0, c1, 4 @ Read ID_MMFR0 |
| 192 | and r0, r0, #(MMFR0_PMSA) @ PMSA field |
| 193 | teq r0, #(MMFR0_PMSAv7) @ PMSA v7 |
| 194 | bne __error_p @ Fail: ARM_MPU on NOT v7 PMSA |
| 195 | |
| 196 | /* Determine whether the D/I-side memory map is unified. We set the |
| 197 | * flags here and continue to use them for the rest of this function */ |
| 198 | mrc p15, 0, r0, c0, c0, 4 @ MPUIR |
| 199 | ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU |
| 200 | beq __error_p @ Fail: ARM_MPU and no MPU |
| 201 | tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified |
| 202 | |
| 203 | /* Setup second region first to free up r6 */ |
| 204 | set_region_nr r0, #MPU_RAM_REGION |
| 205 | isb |
| 206 | /* Full access from PL0, PL1, shared for CONFIG_SMP, cacheable */ |
| 207 | ldr r0, =PHYS_OFFSET @ RAM starts at PHYS_OFFSET |
| 208 | ldr r5,=(MPU_AP_PL1RW_PL0RW | MPU_RGN_NORMAL) |
| 209 | |
| 210 | setup_region r0, r5, r6, MPU_DATA_SIDE @ PHYS_OFFSET, shared, enabled |
| 211 | beq 1f @ Memory-map not unified |
| 212 | setup_region r0, r5, r6, MPU_INSTR_SIDE @ PHYS_OFFSET, shared, enabled |
| 213 | 1: isb |
| 214 | |
| 215 | /* First/background region */ |
| 216 | set_region_nr r0, #MPU_BG_REGION |
| 217 | isb |
| 218 | /* Execute Never, strongly ordered, inaccessible to PL0, rw PL1 */ |
| 219 | mov r0, #0 @ BG region starts at 0x0 |
| 220 | ldr r5,=(MPU_ACR_XN | MPU_RGN_STRONGLY_ORDERED | MPU_AP_PL1RW_PL0NA) |
| 221 | mov r6, #MPU_RSR_ALL_MEM @ 4GB region, enabled |
| 222 | |
| 223 | setup_region r0, r5, r6, MPU_DATA_SIDE @ 0x0, BG region, enabled |
| 224 | beq 2f @ Memory-map not unified |
| 225 | setup_region r0, r5, r6, MPU_INSTR_SIDE @ 0x0, BG region, enabled |
| 226 | 2: isb |
| 227 | |
| 228 | /* Enable the MPU */ |
| 229 | mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR |
| 230 | bic r0, r0, #CR_BR @ Disable the 'default mem-map' |
| 231 | orr r0, r0, #CR_M @ Set SCTRL.M (MPU on) |
| 232 | mcr p15, 0, r0, c1, c0, 0 @ Enable MPU |
| 233 | isb |
| 234 | mov pc,lr |
| 235 | ENDPROC(__setup_mpu) |
| 236 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 237 | #include "head-common.S" |