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)? |
Russell King | 3c0bdac | 2005-11-25 15:43:22 +0000 | [diff] [blame] | 88 | beq __error_p @ yes, error 'p' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | bl __lookup_machine_type @ r5=machinfo |
| 90 | movs r8, r5 @ invalid machine (r5=0)? |
| 91 | beq __error_a @ yes, error 'a' |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 92 | bl __vet_atags |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 93 | #ifdef CONFIG_SMP_ON_UP |
| 94 | bl __fixup_smp |
| 95 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | bl __create_page_tables |
| 97 | |
| 98 | /* |
| 99 | * The following calls CPU specific code in a position independent |
| 100 | * manner. See arch/arm/mm/proc-*.S for details. r10 = base of |
| 101 | * xxx_proc_info structure selected by __lookup_machine_type |
| 102 | * above. On return, the CPU will be ready for the MMU to be |
| 103 | * turned on, and r0 will hold the CPU control register value. |
| 104 | */ |
Russell King | a4ae413 | 2010-10-04 16:22:34 +0100 | [diff] [blame] | 105 | ldr r13, =__mmap_switched @ address to jump to after |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | @ mmu has been enabled |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 107 | adr lr, BSYM(1f) @ return (PIC) address |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 108 | ARM( add pc, r10, #PROCINFO_INITFUNC ) |
| 109 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 110 | THUMB( mov pc, r12 ) |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 111 | 1: b __enable_mmu |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 112 | ENDPROC(stext) |
Russell King | a4ae413 | 2010-10-04 16:22:34 +0100 | [diff] [blame] | 113 | .ltorg |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* |
| 116 | * Setup the initial page tables. We only setup the barest |
| 117 | * amount which are required to get the kernel running, which |
| 118 | * generally means mapping in the kernel code. |
| 119 | * |
| 120 | * r8 = machinfo |
| 121 | * r9 = cpuid |
| 122 | * r10 = procinfo |
| 123 | * |
| 124 | * Returns: |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 125 | * r0, r3, r5-r7 corrupted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | * r4 = physical page table address |
| 127 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | __create_page_tables: |
Nicolas Pitre | 37d07b7 | 2005-10-29 21:44:56 +0100 | [diff] [blame] | 129 | pgtbl r4 @ page table address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Clear the 16K level 1 swapper page table |
| 133 | */ |
| 134 | mov r0, r4 |
| 135 | mov r3, #0 |
| 136 | add r6, r0, #0x4000 |
| 137 | 1: str r3, [r0], #4 |
| 138 | str r3, [r0], #4 |
| 139 | str r3, [r0], #4 |
| 140 | str r3, [r0], #4 |
| 141 | teq r0, r6 |
| 142 | bne 1b |
| 143 | |
Russell King | 8799ee9 | 2006-06-29 18:24:21 +0100 | [diff] [blame] | 144 | ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 147 | * Create identity mapping to cater for __enable_mmu. |
| 148 | * This identity mapping will be removed by paging_init(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | */ |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 150 | adr r0, __enable_mmu_loc |
| 151 | ldmia r0, {r3, r5, r6} |
| 152 | sub r0, r0, r3 @ virt->phys offset |
| 153 | add r5, r5, r0 @ phys __enable_mmu |
| 154 | add r6, r6, r0 @ phys __enable_mmu_end |
| 155 | mov r5, r5, lsr #20 |
| 156 | mov r6, r6, lsr #20 |
| 157 | |
| 158 | 1: orr r3, r7, r5, lsl #20 @ flags + kernel base |
| 159 | str r3, [r4, r5, lsl #2] @ identity mapping |
| 160 | teq r5, r6 |
| 161 | addne r5, r5, #1 @ next section |
| 162 | bne 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Now setup the pagetables for our kernel direct |
Lennert Buytenhek | 2552fc2 | 2006-09-29 21:14:05 +0100 | [diff] [blame] | 166 | * mapped region. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 168 | mov r3, pc |
| 169 | mov r3, r3, lsr #20 |
| 170 | orr r3, r7, r3, lsl #20 |
Nicolas Pitre | e98ff7f | 2007-02-22 16:18:09 +0100 | [diff] [blame] | 171 | add r0, r4, #(KERNEL_START & 0xff000000) >> 18 |
| 172 | str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]! |
| 173 | ldr r6, =(KERNEL_END - 1) |
| 174 | add r0, r0, #4 |
| 175 | add r6, r4, r6, lsr #18 |
| 176 | 1: cmp r0, r6 |
| 177 | add r3, r3, #1 << 20 |
| 178 | strls r3, [r0], #4 |
| 179 | bls 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 181 | #ifdef CONFIG_XIP_KERNEL |
| 182 | /* |
| 183 | * Map some ram to cover our .data and .bss areas. |
| 184 | */ |
| 185 | orr r3, r7, #(KERNEL_RAM_PADDR & 0xff000000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 186 | .if (KERNEL_RAM_PADDR & 0x00f00000) |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 187 | orr r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 188 | .endif |
Nicolas Pitre | ec3622d | 2007-02-21 15:32:28 +0100 | [diff] [blame] | 189 | add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> 18 |
| 190 | str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]! |
| 191 | ldr r6, =(_end - 1) |
| 192 | add r0, r0, #4 |
| 193 | add r6, r4, r6, lsr #18 |
| 194 | 1: cmp r0, r6 |
| 195 | add r3, r3, #1 << 20 |
| 196 | strls r3, [r0], #4 |
| 197 | bls 1b |
| 198 | #endif |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* |
| 201 | * Then map first 1MB of ram in case it contains our boot params. |
| 202 | */ |
Nicolas Pitre | f09b997 | 2005-10-29 21:44:55 +0100 | [diff] [blame] | 203 | add r0, r4, #PAGE_OFFSET >> 18 |
Linus Walleij | d4e1c88 | 2007-01-21 20:08:33 +0100 | [diff] [blame] | 204 | orr r6, r7, #(PHYS_OFFSET & 0xff000000) |
Nicolas Pitre | 4043579 | 2007-02-21 15:58:13 +0100 | [diff] [blame] | 205 | .if (PHYS_OFFSET & 0x00f00000) |
| 206 | orr r6, r6, #(PHYS_OFFSET & 0x00f00000) |
| 207 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | str r6, [r0] |
| 209 | |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 210 | #ifdef CONFIG_DEBUG_LL |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 211 | #ifndef CONFIG_DEBUG_ICEDCC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* |
| 213 | * Map in IO space for serial debugging. |
| 214 | * This allows debug messages to be output |
| 215 | * via a serial console before paging_init. |
| 216 | */ |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 217 | addruart r7, r3 |
| 218 | |
| 219 | mov r3, r3, lsr #20 |
| 220 | mov r3, r3, lsl #2 |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | add r0, r4, r3 |
| 223 | rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long) |
| 224 | cmp r3, #0x0800 @ limit to 512MB |
| 225 | movhi r3, #0x0800 |
| 226 | add r6, r0, r3 |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 227 | mov r3, r7, lsr #20 |
| 228 | ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags |
| 229 | orr r3, r7, r3, lsl #20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | 1: str r3, [r0], #4 |
| 231 | add r3, r3, #1 << 20 |
| 232 | teq r0, r6 |
| 233 | bne 1b |
Jeremy Kerr | c293393 | 2010-07-07 11:19:48 +0800 | [diff] [blame] | 234 | |
| 235 | #else /* CONFIG_DEBUG_ICEDCC */ |
| 236 | /* we don't need any serial debugging mappings for ICEDCC */ |
| 237 | ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags |
| 238 | #endif /* !CONFIG_DEBUG_ICEDCC */ |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | #if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS) |
| 241 | /* |
Russell King | 3c0bdac | 2005-11-25 15:43:22 +0000 | [diff] [blame] | 242 | * If we're using the NetWinder or CATS, we also need to map |
| 243 | * in the 16550-type serial port for the debug messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | */ |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 245 | add r0, r4, #0xff000000 >> 18 |
| 246 | orr r3, r7, #0x7c000000 |
| 247 | str r3, [r0] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | #ifdef CONFIG_ARCH_RPC |
| 250 | /* |
| 251 | * Map in screen at 0x02000000 & SCREEN2_BASE |
| 252 | * Similar reasons here - for debug. This is |
| 253 | * only for Acorn RiscPC architectures. |
| 254 | */ |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 255 | add r0, r4, #0x02000000 >> 18 |
| 256 | orr r3, r7, #0x02000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | str r3, [r0] |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 258 | add r0, r4, #0xd8000000 >> 18 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | str r3, [r0] |
| 260 | #endif |
Russell King | c77b042 | 2005-07-01 11:56:55 +0100 | [diff] [blame] | 261 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 263 | ENDPROC(__create_page_tables) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .ltorg |
Russell King | 786f1b7 | 2010-10-04 17:51:54 +0100 | [diff] [blame] | 265 | __enable_mmu_loc: |
| 266 | .long . |
| 267 | .long __enable_mmu |
| 268 | .long __enable_mmu_end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 270 | #if defined(CONFIG_SMP) |
| 271 | __CPUINIT |
| 272 | ENTRY(secondary_startup) |
| 273 | /* |
| 274 | * Common entry point for secondary CPUs. |
| 275 | * |
| 276 | * Ensure that we're in SVC mode, and IRQs are disabled. Lookup |
| 277 | * the processor type - there is no need to check the machine type |
| 278 | * as it has already been validated by the primary processor. |
| 279 | */ |
| 280 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 |
| 281 | mrc p15, 0, r9, c0, c0 @ get processor id |
| 282 | bl __lookup_processor_type |
| 283 | movs r10, r5 @ invalid processor? |
| 284 | moveq r0, #'p' @ yes, error 'p' |
| 285 | beq __error_p |
| 286 | |
| 287 | /* |
| 288 | * Use the page tables supplied from __cpu_up. |
| 289 | */ |
| 290 | adr r4, __secondary_data |
| 291 | ldmia r4, {r5, r7, r12} @ address to jump to after |
| 292 | sub r4, r4, r5 @ mmu has been enabled |
| 293 | ldr r4, [r7, r4] @ get secondary_data.pgdir |
| 294 | adr lr, BSYM(__enable_mmu) @ return address |
| 295 | mov r13, r12 @ __secondary_switched address |
| 296 | ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor |
| 297 | @ (return control reg) |
| 298 | THUMB( add r12, r10, #PROCINFO_INITFUNC ) |
| 299 | THUMB( mov pc, r12 ) |
| 300 | ENDPROC(secondary_startup) |
| 301 | |
| 302 | /* |
| 303 | * r6 = &secondary_data |
| 304 | */ |
| 305 | ENTRY(__secondary_switched) |
| 306 | ldr sp, [r7, #4] @ get secondary_data.stack |
| 307 | mov fp, #0 |
| 308 | b secondary_start_kernel |
| 309 | ENDPROC(__secondary_switched) |
| 310 | |
| 311 | .type __secondary_data, %object |
| 312 | __secondary_data: |
| 313 | .long . |
| 314 | .long secondary_data |
| 315 | .long __secondary_switched |
| 316 | #endif /* defined(CONFIG_SMP) */ |
| 317 | |
| 318 | |
| 319 | |
| 320 | /* |
| 321 | * Setup common bits before finally enabling the MMU. Essentially |
| 322 | * this is just loading the page table pointer and domain access |
| 323 | * registers. |
Russell King | 865a4fa | 2010-10-04 18:02:59 +0100 | [diff] [blame] | 324 | * |
| 325 | * r0 = cp#15 control register |
| 326 | * r1 = machine ID |
| 327 | * r2 = atags pointer |
| 328 | * r4 = page table pointer |
| 329 | * r9 = processor ID |
| 330 | * r13 = *virtual* address to jump to upon completion |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 331 | */ |
| 332 | __enable_mmu: |
| 333 | #ifdef CONFIG_ALIGNMENT_TRAP |
| 334 | orr r0, r0, #CR_A |
| 335 | #else |
| 336 | bic r0, r0, #CR_A |
| 337 | #endif |
| 338 | #ifdef CONFIG_CPU_DCACHE_DISABLE |
| 339 | bic r0, r0, #CR_C |
| 340 | #endif |
| 341 | #ifdef CONFIG_CPU_BPREDICT_DISABLE |
| 342 | bic r0, r0, #CR_Z |
| 343 | #endif |
| 344 | #ifdef CONFIG_CPU_ICACHE_DISABLE |
| 345 | bic r0, r0, #CR_I |
| 346 | #endif |
| 347 | mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \ |
| 348 | domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \ |
| 349 | domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \ |
| 350 | domain_val(DOMAIN_IO, DOMAIN_CLIENT)) |
| 351 | mcr p15, 0, r5, c3, c0, 0 @ load domain access register |
| 352 | mcr p15, 0, r4, c2, c0, 0 @ load page table pointer |
| 353 | b __turn_mmu_on |
| 354 | ENDPROC(__enable_mmu) |
| 355 | |
| 356 | /* |
| 357 | * Enable the MMU. This completely changes the structure of the visible |
| 358 | * memory space. You will not be able to trace execution through this. |
| 359 | * If you have an enquiry about this, *please* check the linux-arm-kernel |
| 360 | * mailing list archives BEFORE sending another post to the list. |
| 361 | * |
| 362 | * r0 = cp#15 control register |
Russell King | 865a4fa | 2010-10-04 18:02:59 +0100 | [diff] [blame] | 363 | * r1 = machine ID |
| 364 | * r2 = atags pointer |
| 365 | * r9 = processor ID |
Russell King | 0094501 | 2010-10-04 17:56:13 +0100 | [diff] [blame] | 366 | * r13 = *virtual* address to jump to upon completion |
| 367 | * |
| 368 | * other registers depend on the function called upon completion |
| 369 | */ |
| 370 | .align 5 |
| 371 | __turn_mmu_on: |
| 372 | mov r0, r0 |
| 373 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
| 374 | mrc p15, 0, r3, c0, c0, 0 @ read id reg |
| 375 | mov r3, r3 |
| 376 | mov r3, r13 |
| 377 | mov pc, r3 |
| 378 | __enable_mmu_end: |
| 379 | ENDPROC(__turn_mmu_on) |
| 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 382 | #ifdef CONFIG_SMP_ON_UP |
| 383 | __fixup_smp: |
| 384 | mov r7, #0x00070000 |
| 385 | orr r6, r7, #0xff000000 @ mask 0xff070000 |
| 386 | orr r7, r7, #0x41000000 @ val 0x41070000 |
| 387 | and r0, r9, r6 |
| 388 | teq r0, r7 @ ARM CPU and ARMv6/v7? |
| 389 | bne __fixup_smp_on_up @ no, assume UP |
| 390 | |
| 391 | orr r6, r6, #0x0000ff00 |
| 392 | orr r6, r6, #0x000000f0 @ mask 0xff07fff0 |
| 393 | orr r7, r7, #0x0000b000 |
| 394 | orr r7, r7, #0x00000020 @ val 0x4107b020 |
| 395 | and r0, r9, r6 |
| 396 | teq r0, r7 @ ARM 11MPCore? |
| 397 | moveq pc, lr @ yes, assume SMP |
| 398 | |
| 399 | mrc p15, 0, r0, c0, c0, 5 @ read MPIDR |
| 400 | tst r0, #1 << 31 |
| 401 | movne pc, lr @ bit 31 => SMP |
| 402 | |
| 403 | __fixup_smp_on_up: |
| 404 | adr r0, 1f |
| 405 | ldmia r0, {r3, r6, r7} |
| 406 | sub r3, r0, r3 |
| 407 | add r6, r6, r3 |
| 408 | add r7, r7, r3 |
| 409 | 2: cmp r6, r7 |
| 410 | ldmia r6!, {r0, r4} |
| 411 | strlo r4, [r0, r3] |
| 412 | blo 2b |
| 413 | mov pc, lr |
| 414 | ENDPROC(__fixup_smp) |
| 415 | |
| 416 | 1: .word . |
| 417 | .word __smpalt_begin |
| 418 | .word __smpalt_end |
| 419 | |
| 420 | .pushsection .data |
| 421 | .globl smp_on_up |
| 422 | smp_on_up: |
| 423 | ALT_SMP(.long 1) |
| 424 | ALT_UP(.long 0) |
| 425 | .popsection |
| 426 | |
| 427 | #endif |
| 428 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 429 | #include "head-common.S" |