Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/head.S |
| 3 | * |
| 4 | * Copyright (C) 1994-2002 Russell King |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 5 | * Copyright (c) 2003 ARM Limited |
| 6 | * All Rights Reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * Kernel startup code for all 32-bit CPUs |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/linkage.h> |
| 15 | #include <linux/init.h> |
| 16 | |
| 17 | #include <asm/assembler.h> |
| 18 | #include <asm/domain.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/ptrace.h> |
Sam Ravnborg | e6ae744 | 2005-09-09 21:08:59 +0200 | [diff] [blame] | 20 | #include <asm/asm-offsets.h> |
Nicolas Pitre | f09b997 | 2005-10-29 21:44:55 +0100 | [diff] [blame] | 21 | #include <asm/memory.h> |
Russell King | 4f7a181 | 2005-05-05 13:11:00 +0100 | [diff] [blame] | 22 | #include <asm/thread_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/system.h> |
| 24 | |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 25 | #ifdef CONFIG_DEBUG_LL |
| 26 | #include <mach/debug-macro.S> |
| 27 | #endif |
| 28 | |
Linus Walleij | d4e1c88 | 2007-01-21 20:08:33 +0100 | [diff] [blame] | 29 | #if (PHYS_OFFSET & 0x001fffff) |
| 30 | #error "PHYS_OFFSET must be at an even 2MiB boundary!" |
| 31 | #endif |
| 32 | |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 33 | #define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET) |
| 34 | #define KERNEL_RAM_PADDR (PHYS_OFFSET + TEXT_OFFSET) |
Russell King | 9d4f13e | 2006-01-03 17:28:33 +0000 | [diff] [blame] | 35 | |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /* |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 38 | * swapper_pg_dir is the virtual address of the initial page table. |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 39 | * We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we must |
| 40 | * make sure that KERNEL_RAM_VADDR is correctly set. Currently, we expect |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 41 | * the least significant 16 bits to be 0x8000, but we could probably |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 42 | * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | */ |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 44 | #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000 |
| 45 | #error KERNEL_RAM_VADDR must start at 0xXXXX8000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | .globl swapper_pg_dir |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 49 | .equ swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 51 | .macro pgtbl, rd |
Russell King | f06b97f | 2006-12-11 22:29:16 +0000 | [diff] [blame] | 52 | ldr \rd, =(KERNEL_RAM_PADDR - 0x4000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | .endm |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 54 | |
| 55 | #ifdef CONFIG_XIP_KERNEL |
Nicolas Pitre | e98ff7f | 2007-02-22 16:18:09 +0100 | [diff] [blame] | 56 | #define KERNEL_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) |
| 57 | #define KERNEL_END _edata_loc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #else |
Nicolas Pitre | e98ff7f | 2007-02-22 16:18:09 +0100 | [diff] [blame] | 59 | #define KERNEL_START KERNEL_RAM_VADDR |
| 60 | #define KERNEL_END _end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif |
| 62 | |
| 63 | /* |
| 64 | * Kernel startup entry point. |
| 65 | * --------------------------- |
| 66 | * |
| 67 | * This is normally called from the decompressor code. The requirements |
| 68 | * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0, |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 69 | * r1 = machine nr, r2 = atags pointer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * |
| 71 | * This code is mostly position independent, so if you link the kernel at |
| 72 | * 0xc0008000, you call this at __pa(0xc0008000). |
| 73 | * |
| 74 | * See linux/arch/arm/tools/mach-types for the complete list of machine |
| 75 | * numbers for r1. |
| 76 | * |
| 77 | * We're trying to keep crap to a minimum; DO NOT add any machine specific |
| 78 | * crap here - that's what the boot loader (or in extreme, well justified |
| 79 | * circumstances, zImage) is for. |
| 80 | */ |
Tim Abbott | 2abc1c5 | 2009-10-02 16:32:46 -0400 | [diff] [blame] | 81 | __HEAD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | ENTRY(stext) |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 83 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | @ and irqs disabled |
Russell King | 0f44ba1 | 2006-02-24 21:04:56 +0000 | [diff] [blame] | 85 | mrc p15, 0, r9, c0, c0 @ get processor id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | bl __lookup_processor_type @ r5=procinfo r9=cpuid |
| 87 | movs r10, r5 @ invalid processor (r5=0)? |
Dave Martin | a75e524 | 2010-11-29 19:43:28 +0100 | [diff] [blame] | 88 | THUMB( it eq ) @ force fixup-able long branch encoding |
Russell King | 3c0bdac | 2005-11-25 15:43:22 +0000 | [diff] [blame] | 89 | beq __error_p @ yes, error 'p' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | bl __lookup_machine_type @ r5=machinfo |
| 91 | movs r8, r5 @ invalid machine (r5=0)? |
Dave Martin | a75e524 | 2010-11-29 19:43:28 +0100 | [diff] [blame] | 92 | THUMB( it eq ) @ force fixup-able long branch encoding |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | beq __error_a @ yes, error 'a' |
Russell King | 0eb0511d | 2010-11-22 12:06:28 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * r1 = machine no, r2 = atags, |
| 97 | * r8 = machinfo, r9 = cpuid, r10 = procinfo |
| 98 | */ |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 99 | bl __vet_atags |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 100 | #ifdef CONFIG_SMP_ON_UP |
| 101 | bl __fixup_smp |
| 102 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | bl __create_page_tables |
| 104 | |
| 105 | /* |
| 106 | * The following calls CPU specific code in a position independent |
| 107 | * manner. See arch/arm/mm/proc-*.S for details. r10 = base of |
| 108 | * xxx_proc_info structure selected by __lookup_machine_type |
| 109 | * above. On return, the CPU will be ready for the MMU to be |
| 110 | * turned on, and r0 will hold the CPU control register value. |
| 111 | */ |
Russell King | a4ae413 | 2010-10-04 16:22:34 +0100 | [diff] [blame] | 112 | ldr r13, =__mmap_switched @ address to jump to after |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | @ mmu has been enabled |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 114 | adr lr, BSYM(1f) @ return (PIC) address |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 115 | ARM( add pc, r10, #PROCINFO_INITFUNC ) |
| 116 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 117 | THUMB( mov pc, r12 ) |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 118 | 1: b __enable_mmu |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 119 | ENDPROC(stext) |
Russell King | a4ae413 | 2010-10-04 16:22:34 +0100 | [diff] [blame] | 120 | .ltorg |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * Setup the initial page tables. We only setup the barest |
| 124 | * amount which are required to get the kernel running, which |
| 125 | * generally means mapping in the kernel code. |
| 126 | * |
| 127 | * r8 = machinfo |
| 128 | * r9 = cpuid |
| 129 | * r10 = procinfo |
| 130 | * |
| 131 | * Returns: |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 132 | * r0, r3, r5-r7 corrupted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | * r4 = physical page table address |
| 134 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | __create_page_tables: |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 136 | pgtbl r4 @ page table address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * Clear the 16K level 1 swapper page table |
| 140 | */ |
| 141 | mov r0, r4 |
| 142 | mov r3, #0 |
| 143 | add r6, r0, #0x4000 |
| 144 | 1: str r3, [r0], #4 |
| 145 | str r3, [r0], #4 |
| 146 | str r3, [r0], #4 |
| 147 | str r3, [r0], #4 |
| 148 | teq r0, r6 |
| 149 | bne 1b |
| 150 | |
Russell King | 8799ee9 | 2006-06-29 18:24:21 +0100 | [diff] [blame] | 151 | ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 154 | * Create identity mapping to cater for __enable_mmu. |
| 155 | * This identity mapping will be removed by paging_init(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | */ |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 157 | adr r0, __enable_mmu_loc |
| 158 | ldmia r0, {r3, r5, r6} |
| 159 | sub r0, r0, r3 @ virt->phys offset |
| 160 | add r5, r5, r0 @ phys __enable_mmu |
| 161 | add r6, r6, r0 @ phys __enable_mmu_end |
| 162 | mov r5, r5, lsr #20 |
| 163 | mov r6, r6, lsr #20 |
| 164 | |
| 165 | 1: orr r3, r7, r5, lsl #20 @ flags + kernel base |
| 166 | str r3, [r4, r5, lsl #2] @ identity mapping |
| 167 | teq r5, r6 |
| 168 | addne r5, r5, #1 @ next section |
| 169 | bne 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Now setup the pagetables for our kernel direct |
Lennert Buytenhek | 2552fc2 | 2006-09-29 21:14:05 +0100 | [diff] [blame] | 173 | * mapped region. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | */ |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 175 | mov r3, pc |
| 176 | mov r3, r3, lsr #20 |
| 177 | orr r3, r7, r3, lsl #20 |
Nicolas Pitre | e98ff7f | 2007-02-22 16:18:09 +0100 | [diff] [blame] | 178 | add r0, r4, #(KERNEL_START & 0xff000000) >> 18 |
| 179 | str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]! |
| 180 | ldr r6, =(KERNEL_END - 1) |
| 181 | add r0, r0, #4 |
| 182 | add r6, r4, r6, lsr #18 |
| 183 | 1: cmp r0, r6 |
| 184 | add r3, r3, #1 << 20 |
| 185 | strls r3, [r0], #4 |
| 186 | bls 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 188 | #ifdef CONFIG_XIP_KERNEL |
| 189 | /* |
| 190 | * Map some ram to cover our .data and .bss areas. |
| 191 | */ |
| 192 | orr r3, r7, #(KERNEL_RAM_PADDR & 0xff000000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 193 | .if (KERNEL_RAM_PADDR & 0x00f00000) |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 194 | orr r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 195 | .endif |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 196 | add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> 18 |
| 197 | str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]! |
| 198 | ldr r6, =(_end - 1) |
| 199 | add r0, r0, #4 |
| 200 | add r6, r4, r6, lsr #18 |
| 201 | 1: cmp r0, r6 |
| 202 | add r3, r3, #1 << 20 |
| 203 | strls r3, [r0], #4 |
| 204 | bls 1b |
| 205 | #endif |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* |
| 208 | * Then map first 1MB of ram in case it contains our boot params. |
| 209 | */ |
Nicolas Pitre | f09b997 | 2005-10-29 21:44:55 +0100 | [diff] [blame] | 210 | add r0, r4, #PAGE_OFFSET >> 18 |
Linus Walleij | d4e1c88 | 2007-01-21 20:08:33 +0100 | [diff] [blame] | 211 | orr r6, r7, #(PHYS_OFFSET & 0xff000000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 212 | .if (PHYS_OFFSET & 0x00f00000) |
| 213 | orr r6, r6, #(PHYS_OFFSET & 0x00f00000) |
| 214 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | str r6, [r0] |
| 216 | |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 217 | #ifdef CONFIG_DEBUG_LL |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 218 | #ifndef CONFIG_DEBUG_ICEDCC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /* |
| 220 | * Map in IO space for serial debugging. |
| 221 | * This allows debug messages to be output |
| 222 | * via a serial console before paging_init. |
| 223 | */ |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 224 | addruart r7, r3 |
| 225 | |
| 226 | mov r3, r3, lsr #20 |
| 227 | mov r3, r3, lsl #2 |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | add r0, r4, r3 |
| 230 | rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long) |
| 231 | cmp r3, #0x0800 @ limit to 512MB |
| 232 | movhi r3, #0x0800 |
| 233 | add r6, r0, r3 |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 234 | mov r3, r7, lsr #20 |
| 235 | ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags |
| 236 | orr r3, r7, r3, lsl #20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 1: str r3, [r0], #4 |
| 238 | add r3, r3, #1 << 20 |
| 239 | teq r0, r6 |
| 240 | bne 1b |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 241 | |
| 242 | #else /* CONFIG_DEBUG_ICEDCC */ |
| 243 | /* we don't need any serial debugging mappings for ICEDCC */ |
| 244 | ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags |
| 245 | #endif /* !CONFIG_DEBUG_ICEDCC */ |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | #if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS) |
| 248 | /* |
Russell King | 3c0bdac | 2005-11-25 15:43:22 +0000 | [diff] [blame] | 249 | * If we're using the NetWinder or CATS, we also need to map |
| 250 | * in the 16550-type serial port for the debug messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | */ |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 252 | add r0, r4, #0xff000000 >> 18 |
| 253 | orr r3, r7, #0x7c000000 |
| 254 | str r3, [r0] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | #ifdef CONFIG_ARCH_RPC |
| 257 | /* |
| 258 | * Map in screen at 0x02000000 & SCREEN2_BASE |
| 259 | * Similar reasons here - for debug. This is |
| 260 | * only for Acorn RiscPC architectures. |
| 261 | */ |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 262 | add r0, r4, #0x02000000 >> 18 |
| 263 | orr r3, r7, #0x02000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | str r3, [r0] |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 265 | add r0, r4, #0xd8000000 >> 18 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | str r3, [r0] |
| 267 | #endif |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 268 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 270 | ENDPROC(__create_page_tables) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | .ltorg |
Dave Martin | 4f79a5d | 2010-11-29 19:43:24 +0100 | [diff] [blame] | 272 | .align |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 273 | __enable_mmu_loc: |
| 274 | .long . |
| 275 | .long __enable_mmu |
| 276 | .long __enable_mmu_end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 278 | #if defined(CONFIG_SMP) |
| 279 | __CPUINIT |
| 280 | ENTRY(secondary_startup) |
| 281 | /* |
| 282 | * Common entry point for secondary CPUs. |
| 283 | * |
| 284 | * Ensure that we're in SVC mode, and IRQs are disabled. Lookup |
| 285 | * the processor type - there is no need to check the machine type |
| 286 | * as it has already been validated by the primary processor. |
| 287 | */ |
| 288 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 |
| 289 | mrc p15, 0, r9, c0, c0 @ get processor id |
| 290 | bl __lookup_processor_type |
| 291 | movs r10, r5 @ invalid processor? |
| 292 | moveq r0, #'p' @ yes, error 'p' |
Dave Martin | a75e524 | 2010-11-29 19:43:28 +0100 | [diff] [blame] | 293 | THUMB( it eq ) @ force fixup-able long branch encoding |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 294 | beq __error_p |
| 295 | |
| 296 | /* |
| 297 | * Use the page tables supplied from __cpu_up. |
| 298 | */ |
| 299 | adr r4, __secondary_data |
| 300 | ldmia r4, {r5, r7, r12} @ address to jump to after |
| 301 | sub r4, r4, r5 @ mmu has been enabled |
| 302 | ldr r4, [r7, r4] @ get secondary_data.pgdir |
| 303 | adr lr, BSYM(__enable_mmu) @ return address |
| 304 | mov r13, r12 @ __secondary_switched address |
| 305 | ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor |
| 306 | @ (return control reg) |
| 307 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 308 | THUMB( mov pc, r12 ) |
| 309 | ENDPROC(secondary_startup) |
| 310 | |
| 311 | /* |
| 312 | * r6 = &secondary_data |
| 313 | */ |
| 314 | ENTRY(__secondary_switched) |
| 315 | ldr sp, [r7, #4] @ get secondary_data.stack |
| 316 | mov fp, #0 |
| 317 | b secondary_start_kernel |
| 318 | ENDPROC(__secondary_switched) |
| 319 | |
Dave Martin | 4f79a5d | 2010-11-29 19:43:24 +0100 | [diff] [blame] | 320 | .align |
| 321 | |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 322 | .type __secondary_data, %object |
| 323 | __secondary_data: |
| 324 | .long . |
| 325 | .long secondary_data |
| 326 | .long __secondary_switched |
| 327 | #endif /* defined(CONFIG_SMP) */ |
| 328 | |
| 329 | |
| 330 | |
| 331 | /* |
| 332 | * Setup common bits before finally enabling the MMU. Essentially |
| 333 | * this is just loading the page table pointer and domain access |
| 334 | * registers. |
Russell King | 865a4fa | 2010-10-04 18:02:59 +0100 | [diff] [blame] | 335 | * |
| 336 | * r0 = cp#15 control register |
| 337 | * r1 = machine ID |
| 338 | * r2 = atags pointer |
| 339 | * r4 = page table pointer |
| 340 | * r9 = processor ID |
| 341 | * r13 = *virtual* address to jump to upon completion |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 342 | */ |
| 343 | __enable_mmu: |
| 344 | #ifdef CONFIG_ALIGNMENT_TRAP |
| 345 | orr r0, r0, #CR_A |
| 346 | #else |
| 347 | bic r0, r0, #CR_A |
| 348 | #endif |
| 349 | #ifdef CONFIG_CPU_DCACHE_DISABLE |
| 350 | bic r0, r0, #CR_C |
| 351 | #endif |
| 352 | #ifdef CONFIG_CPU_BPREDICT_DISABLE |
| 353 | bic r0, r0, #CR_Z |
| 354 | #endif |
| 355 | #ifdef CONFIG_CPU_ICACHE_DISABLE |
| 356 | bic r0, r0, #CR_I |
| 357 | #endif |
| 358 | mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \ |
| 359 | domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \ |
| 360 | domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \ |
| 361 | domain_val(DOMAIN_IO, DOMAIN_CLIENT)) |
| 362 | mcr p15, 0, r5, c3, c0, 0 @ load domain access register |
| 363 | mcr p15, 0, r4, c2, c0, 0 @ load page table pointer |
| 364 | b __turn_mmu_on |
| 365 | ENDPROC(__enable_mmu) |
| 366 | |
| 367 | /* |
| 368 | * Enable the MMU. This completely changes the structure of the visible |
| 369 | * memory space. You will not be able to trace execution through this. |
| 370 | * If you have an enquiry about this, *please* check the linux-arm-kernel |
| 371 | * mailing list archives BEFORE sending another post to the list. |
| 372 | * |
| 373 | * r0 = cp#15 control register |
Russell King | 865a4fa | 2010-10-04 18:02:59 +0100 | [diff] [blame] | 374 | * r1 = machine ID |
| 375 | * r2 = atags pointer |
| 376 | * r9 = processor ID |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 377 | * r13 = *virtual* address to jump to upon completion |
| 378 | * |
| 379 | * other registers depend on the function called upon completion |
| 380 | */ |
| 381 | .align 5 |
| 382 | __turn_mmu_on: |
| 383 | mov r0, r0 |
| 384 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
| 385 | mrc p15, 0, r3, c0, c0, 0 @ read id reg |
| 386 | mov r3, r3 |
| 387 | mov r3, r13 |
| 388 | mov pc, r3 |
| 389 | __enable_mmu_end: |
| 390 | ENDPROC(__turn_mmu_on) |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 393 | #ifdef CONFIG_SMP_ON_UP |
Russell King | 4a9cb36 | 2011-02-10 15:25:18 +0000 | [diff] [blame^] | 394 | __INIT |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 395 | __fixup_smp: |
Russell King | e98ff0f | 2011-01-30 16:40:20 +0000 | [diff] [blame] | 396 | and r3, r9, #0x000f0000 @ architecture version |
| 397 | teq r3, #0x000f0000 @ CPU ID supported? |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 398 | bne __fixup_smp_on_up @ no, assume UP |
| 399 | |
Russell King | e98ff0f | 2011-01-30 16:40:20 +0000 | [diff] [blame] | 400 | bic r3, r9, #0x00ff0000 |
| 401 | bic r3, r3, #0x0000000f @ mask 0xff00fff0 |
| 402 | mov r4, #0x41000000 |
Russell King | 0eb0511d | 2010-11-22 12:06:28 +0000 | [diff] [blame] | 403 | orr r4, r4, #0x0000b000 |
Russell King | e98ff0f | 2011-01-30 16:40:20 +0000 | [diff] [blame] | 404 | orr r4, r4, #0x00000020 @ val 0x4100b020 |
| 405 | teq r3, r4 @ ARM 11MPCore? |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 406 | moveq pc, lr @ yes, assume SMP |
| 407 | |
| 408 | mrc p15, 0, r0, c0, c0, 5 @ read MPIDR |
Russell King | e98ff0f | 2011-01-30 16:40:20 +0000 | [diff] [blame] | 409 | and r0, r0, #0xc0000000 @ multiprocessing extensions and |
| 410 | teq r0, #0x80000000 @ not part of a uniprocessor system? |
| 411 | moveq pc, lr @ yes, assume SMP |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 412 | |
| 413 | __fixup_smp_on_up: |
| 414 | adr r0, 1f |
Russell King | 0eb0511d | 2010-11-22 12:06:28 +0000 | [diff] [blame] | 415 | ldmia r0, {r3 - r5} |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 416 | sub r3, r0, r3 |
Russell King | 0eb0511d | 2010-11-22 12:06:28 +0000 | [diff] [blame] | 417 | add r4, r4, r3 |
| 418 | add r5, r5, r3 |
Russell King | 4a9cb36 | 2011-02-10 15:25:18 +0000 | [diff] [blame^] | 419 | b __do_fixup_smp_on_up |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 420 | ENDPROC(__fixup_smp) |
| 421 | |
Dave Martin | 4f79a5d | 2010-11-29 19:43:24 +0100 | [diff] [blame] | 422 | .align |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 423 | 1: .word . |
| 424 | .word __smpalt_begin |
| 425 | .word __smpalt_end |
| 426 | |
| 427 | .pushsection .data |
| 428 | .globl smp_on_up |
| 429 | smp_on_up: |
| 430 | ALT_SMP(.long 1) |
| 431 | ALT_UP(.long 0) |
| 432 | .popsection |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 433 | #endif |
| 434 | |
Russell King | 4a9cb36 | 2011-02-10 15:25:18 +0000 | [diff] [blame^] | 435 | .text |
| 436 | __do_fixup_smp_on_up: |
| 437 | cmp r4, r5 |
| 438 | movhs pc, lr |
| 439 | ldmia r4!, {r0, r6} |
| 440 | ARM( str r6, [r0, r3] ) |
| 441 | THUMB( add r0, r0, r3 ) |
| 442 | #ifdef __ARMEB__ |
| 443 | THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian. |
| 444 | #endif |
| 445 | THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords |
| 446 | THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3. |
| 447 | THUMB( strh r6, [r0] ) |
| 448 | b __do_fixup_smp_on_up |
| 449 | ENDPROC(__do_fixup_smp_on_up) |
| 450 | |
| 451 | ENTRY(fixup_smp) |
| 452 | stmfd sp!, {r4 - r6, lr} |
| 453 | mov r4, r0 |
| 454 | add r5, r0, r1 |
| 455 | mov r3, #0 |
| 456 | bl __do_fixup_smp_on_up |
| 457 | ldmfd sp!, {r4 - r6, pc} |
| 458 | ENDPROC(fixup_smp) |
| 459 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 460 | #include "head-common.S" |