1 /* SPDX-License-Identifier: GPL-2.0
2 * $Id: head.S,v 1.7 2003/09/01 17:58:19 lethal Exp $
4 * arch/sh/kernel/head.S
6 * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
7 * Copyright (C) 2010 Matt Fleming
9 * Head.S contains the SH exception handlers and startup code.
11 #include <linux/init.h>
12 #include <linux/linkage.h>
13 #include <asm/thread_info.h>
15 #include <cpu/mmu_context.h>
17 #ifdef CONFIG_CPU_SH4A
20 #define PREFI(label, reg) \
25 #define PREFI(label, reg)
28 .section .empty_zero_page, "aw"
29 ENTRY(empty_zero_page)
30 .long 1 /* MOUNT_ROOT_RDONLY */
31 .long 0 /* RAMDISK_FLAGS */
32 .long 0x0200 /* ORIG_ROOT_DEV */
33 .long 1 /* LOADER_TYPE */
34 .long 0x00000000 /* INITRD_START */
35 .long 0x00000000 /* INITRD_SIZE */
37 .long 0x53453f00 + 32 /* "SE?" = 32 bit */
39 .long 0x53453f00 + 29 /* "SE?" = 29 bit */
42 .skip PAGE_SIZE - empty_zero_page - 1b
47 * Condition at the entry of _stext:
49 * BSC has already been initialized.
50 * INTC may or may not be initialized.
51 * VBR may or may not be initialized.
52 * MMU may or may not be initialized.
53 * Cache may or may not be initialized.
54 * Hardware (including on-chip modules) may or may not be initialized.
58 ! Initialize Status Register
59 mov.l 1f, r0 ! MD=1, RB=0, BL=0, IMASK=0xF
61 ! Initialize global interrupt mask
62 #ifdef CONFIG_CPU_HAS_SR_RB
67 #ifdef CONFIG_OF_FLATTREE
68 mov r4, r12 ! Store device tree blob pointer in r12
72 * Prefetch if possible to reduce cache miss penalty.
74 * We do this early on for SH-4A as a micro-optimization,
75 * as later on we will have speculative execution enabled
76 * and this will become less of an issue.
83 mov r0, r15 ! Set initial r15 (stack pointer)
84 #ifdef CONFIG_CPU_HAS_SR_RB
86 ldc r0, r7_bank ! ... and initial thread_info
91 * Reconfigure the initial PMB mappings setup by the hardware.
93 * When we boot in 32-bit MMU mode there are 2 PMB entries already
96 * Entry VPN PPN V SZ C UB WT
97 * ---------------------------------------------------------------
98 * 0 0x80000000 0x00000000 1 512MB 1 0 1
99 * 1 0xA0000000 0x00000000 1 512MB 0 0 0
101 * But we reprogram them here because we want complete control over
102 * our address space and the initial mappings may not map PAGE_OFFSET
103 * to __MEMORY_START (or even map all of our RAM).
105 * Once we've setup cached and uncached mappings we clear the rest of the
106 * PMB entries. This clearing also deals with the fact that PMB entries
107 * can persist across reboots. The PMB could have been left in any state
108 * when the reboot occurred, so to be safe we clear all entries and start
109 * with with a clean slate.
111 * The uncached mapping is constructed using the smallest possible
112 * mapping with a single unbufferable page. Only the kernel text needs to
113 * be covered via the uncached mapping so that certain functions can be
116 * Drivers and the like that have previously abused the 1:1 identity
117 * mapping are unsupported in 32-bit mode and must specify their caching
118 * preference when page tables are constructed.
120 * This frees up the P2 space for more nefarious purposes.
122 * Register utilization is as follows:
124 * r0 = PMB_DATA data field
125 * r1 = PMB_DATA address field
126 * r2 = PMB_ADDR data field
127 * r3 = PMB_ADDR address field
129 * r5 = remaining amount of RAM to map
130 * r6 = PMB mapping size we're trying to use
131 * r7 = cached_to_uncached
132 * r8 = scratch register
133 * r9 = scratch register
134 * r10 = number of PMB entries we've setup
135 * r11 = scratch register
138 mov.l .LMMUCR, r1 /* Flush the TLB */
143 mov.l .LMEMORY_SIZE, r5
149 mov.l .LFIRST_DATA_ENTRY, r0
151 mov.l .LFIRST_ADDR_ENTRY, r2
155 * First we need to walk the PMB and figure out if there are any
156 * existing mappings that match the initial mappings VPN/PPN.
157 * If these have already been established by the bootloader, we
158 * don't bother setting up new entries here, and let the late PMB
159 * initialization take care of things instead.
161 * Note that we may need to coalesce and merge entries in order
162 * to reclaim more available PMB slots, which is much more than
163 * we want to do at this early stage.
166 mov #NR_PMB_ENTRIES, r9
168 mov r1, r7 /* temporary PMB_DATA iter */
170 .Lvalidate_existing_mappings:
172 mov.l .LPMB_DATA_MASK, r11
175 cmp/eq r0, r8 /* Check for valid __MEMORY_START mappings */
178 add #1, r10 /* Increment the loop counter */
180 bf/s .Lvalidate_existing_mappings
181 add r4, r7 /* Increment to the next PMB_DATA entry */
184 * If we've fallen through, continue with setting up the initial
188 mov r5, r7 /* cached_to_uncached */
191 #ifdef CONFIG_UNCACHED_MAPPING
195 mov #(PMB_SZ_16M >> 2), r9
198 mov #(PMB_UB >> 8), r8
214 * Iterate over all of the available sizes from largest to
215 * smallest for constructing the cached mapping.
217 #define __PMB_ITER_BY_SIZE(size) \
219 mov #(size >> 4), r6; \
226 mov #(PMB_SZ_##size##M >> 2), r9; \
238 /* Increment to the next PMB_DATA entry */ \
240 /* Increment to the next PMB_ADDR entry */ \
242 /* Increment number of PMB entries */ \
252 __PMB_ITER_BY_SIZE(512)
253 __PMB_ITER_BY_SIZE(128)
254 __PMB_ITER_BY_SIZE(64)
255 __PMB_ITER_BY_SIZE(16)
257 #ifdef CONFIG_UNCACHED_MAPPING
259 * Now that we can access it, update cached_to_uncached and
262 mov.l .Lcached_to_uncached, r0
265 mov.l .Luncached_size, r0
273 * Clear the remaining PMB entries.
275 * r3 = entry to begin clearing from
276 * r10 = number of entries we've setup so far
279 mov #NR_PMB_ENTRIES, r0
282 mov.l r1, @r3 /* Clear PMB_ADDR entry */
283 add #1, r10 /* Increment the loop counter */
286 add r4, r3 /* Increment to the next PMB_ADDR entry */
292 #endif /* CONFIG_PMB */
294 #ifndef CONFIG_SH_NO_BSS_INIT
296 * Don't clear BSS if running on slow platforms such as an RTL simulation,
297 * remote memory via SHdebug link, etc. For these the memory can be guaranteed
298 * to be all zero on boot anyway.
303 cmp/eq #0, r0 ! skip clear if set to zero
312 bf/s 9b ! while (r1 < r2)
318 #ifdef CONFIG_OF_FLATTREE
319 mov.l 8f, r0 ! Make flat device tree available early.
324 ! Additional CPU initialization
329 SYNCO() ! Wait for pending instructions..
337 #if defined(CONFIG_CPU_SH2)
338 1: .long 0x000000F0 ! IMASK=0xF
340 1: .long 0x500080F0 ! MD=1, RB=0, BL=1, FD=1, IMASK=0xF
343 2: .long init_thread_union+THREAD_SIZE
346 5: .long start_kernel
348 7: .long init_thread_union
349 #if defined(CONFIG_OF_FLATTREE)
354 .LPMB_ADDR: .long PMB_ADDR
355 .LPMB_DATA: .long PMB_DATA
356 .LPMB_DATA_MASK: .long PMB_PFN_MASK | PMB_V
357 .LFIRST_ADDR_ENTRY: .long PAGE_OFFSET | PMB_V
358 .LFIRST_DATA_ENTRY: .long __MEMORY_START | PMB_V
360 .LMEMORY_SIZE: .long __MEMORY_SIZE
361 #ifdef CONFIG_UNCACHED_MAPPING
362 .Lcached_to_uncached: .long cached_to_uncached
363 .Luncached_size: .long uncached_size