1 /* SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/head_64.S
5 * Copyright (C) 2000, 2001 Paolo Alberelli
6 * Copyright (C) 2003, 2004 Paul Mundt
9 #include <linux/init.h>
12 #include <asm/cache.h>
14 #include <cpu/registers.h>
15 #include <cpu/mmu_context.h>
16 #include <asm/thread_info.h>
19 * MMU defines: TLB boundaries.
22 #define MMUIR_FIRST ITLB_FIXED
23 #define MMUIR_END ITLB_LAST_VAR_UNRESTRICTED+TLB_STEP
24 #define MMUIR_STEP TLB_STEP
26 #define MMUDR_FIRST DTLB_FIXED
27 #define MMUDR_END DTLB_LAST_VAR_UNRESTRICTED+TLB_STEP
28 #define MMUDR_STEP TLB_STEP
30 /* Safety check : CONFIG_PAGE_OFFSET has to be a multiple of 512Mb */
31 #if (CONFIG_PAGE_OFFSET & ((1UL<<29)-1))
32 #error "CONFIG_PAGE_OFFSET must be a multiple of 512Mb"
36 * MMU defines: Fixed TLBs.
38 /* Deal safely with the case where the base of RAM is not 512Mb aligned */
40 #define ALIGN_512M_MASK (0xffffffffe0000000)
41 #define ALIGNED_EFFECTIVE ((CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START) & ALIGN_512M_MASK)
42 #define ALIGNED_PHYSICAL (CONFIG_MEMORY_START & ALIGN_512M_MASK)
44 #define MMUIR_TEXT_H (0x0000000000000003 | ALIGNED_EFFECTIVE)
45 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
47 #define MMUIR_TEXT_L (0x000000000000009a | ALIGNED_PHYSICAL)
48 /* 512 Mb, Cacheable, Write-back, execute, Not User, Ph. Add. */
50 #define MMUDR_CACHED_H 0x0000000000000003 | ALIGNED_EFFECTIVE
51 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
52 #define MMUDR_CACHED_L 0x000000000000015a | ALIGNED_PHYSICAL
53 /* 512 Mb, Cacheable, Write-back, read/write, Not User, Ph. Add. */
55 #ifdef CONFIG_CACHE_OFF
56 #define ICCR0_INIT_VAL ICCR0_OFF /* ICACHE off */
58 #define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */
60 #define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */
62 #if defined (CONFIG_CACHE_OFF)
63 #define OCCR0_INIT_VAL OCCR0_OFF /* D-cache: off */
64 #elif defined (CONFIG_CACHE_WRITETHROUGH)
65 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WT /* D-cache: on, */
67 #elif defined (CONFIG_CACHE_WRITEBACK)
68 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* D-cache: on, */
71 #error preprocessor flag CONFIG_CACHE_... not recognized!
74 #define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */
76 .section .empty_zero_page, "aw"
77 .global empty_zero_page
80 .long 1 /* MOUNT_ROOT_RDONLY */
81 .long 0 /* RAMDISK_FLAGS */
82 .long 0x0200 /* ORIG_ROOT_DEV */
83 .long 1 /* LOADER_TYPE */
84 .long 0x00800000 /* INITRD_START */
85 .long 0x00800000 /* INITRD_SIZE */
97 .global mmu_pdtp_cache
106 .balign L1_CACHE_BYTES
108 * Condition at the entry of __stext:
110 * . SR.FD = 1 (FPU disabled)
111 * . SR.BL = 1 (Exceptions disabled)
112 * . SR.MD = 1 (Privileged Mode)
113 * . SR.MMU = 0 (MMU Disabled)
114 * . SR.CD = 0 (CTC User Visible)
115 * . SR.IMASK = Undefined (Interrupt Mask)
117 * Operations supposed to be performed by __stext:
118 * . prevent speculative fetch onto device memory while MMU is off
119 * . reflect as much as possible SH5 ABI (r15, r26, r27, r18)
120 * . first, save CPU state and set it to something harmless
121 * . any CPU detection and/or endianness settings (?)
122 * . initialize EMI/LMI (but not TMU/RTC/INTC/SCIF): TBD
123 * . set initial TLB entries for cached and uncached regions
124 * (no fine granularity paging)
125 * . set initial cache state
126 * . enable MMU and caches
127 * . set CPU to a consistent state
128 * . registers (including stack pointer and current/KCR0)
129 * . NOT expecting to set Exception handling nor VBR/RESVEC/DCR
130 * at this stage. This is all to later Linux initialization steps.
133 * . jump into start_kernel()
134 * . be prepared to hopeless start_kernel() returns.
140 * Prevent speculative fetch on device memory due to
141 * uninitialized target registers.
154 * Read/Set CPU state. After this block:
158 movi SR_HARMLESS, r20
162 * Initialize EMI/LMI. To Be Done.
166 * CPU detection and/or endianness settings (?). To Be Done.
167 * Pure PIC code here, please ! Just save state into r30.
169 * r30 = CPU type/Platform Endianness
173 * Set initial TLB entries for cached and uncached regions.
174 * Note: PTA/BLINK is PIC code, PTABS/BLINK isn't !
178 movi MMUIR_FIRST, r21
181 putcfg r21, 0, ZERO /* Clear MMUIR[n].PTEH.V */
182 addi r21, MMUIR_STEP, r21
187 movi MMUDR_FIRST, r21
190 putcfg r21, 0, ZERO /* Clear MMUDR[n].PTEH.V */
191 addi r21, MMUDR_STEP, r21
194 /* Map one big (512Mb) page for ITLB */
195 movi MMUIR_FIRST, r21
196 movi MMUIR_TEXT_L, r22 /* PTEL first */
197 add.l r22, r63, r22 /* Sign extend */
198 putcfg r21, 1, r22 /* Set MMUIR[0].PTEL */
199 movi MMUIR_TEXT_H, r22 /* PTEH last */
200 add.l r22, r63, r22 /* Sign extend */
201 putcfg r21, 0, r22 /* Set MMUIR[0].PTEH */
203 /* Map one big CACHED (512Mb) page for DTLB */
204 movi MMUDR_FIRST, r21
205 movi MMUDR_CACHED_L, r22 /* PTEL first */
206 add.l r22, r63, r22 /* Sign extend */
207 putcfg r21, 1, r22 /* Set MMUDR[0].PTEL */
208 movi MMUDR_CACHED_H, r22 /* PTEH last */
209 add.l r22, r63, r22 /* Sign extend */
210 putcfg r21, 0, r22 /* Set MMUDR[0].PTEH */
213 * Setup a DTLB translation for SCIF phys.
215 addi r21, MMUDR_STEP, r21
216 movi 0x0a03, r22 /* SCIF phys */
218 putcfg r21, 1, r22 /* PTEL first */
219 movi 0xfa03, r22 /* 0xfa030000, fixed SCIF virt */
221 putcfg r21, 0, r22 /* PTEH last */
224 * Set cache behaviours.
228 movi ICCR0_INIT_VAL, r22
229 movi ICCR1_INIT_VAL, r23
230 putcfg r21, ICCR_REG0, r22
231 putcfg r21, ICCR_REG1, r23
235 movi OCCR0_INIT_VAL, r22
236 movi OCCR1_INIT_VAL, r23
237 putcfg r21, OCCR_REG0, r22
238 putcfg r21, OCCR_REG1, r23
242 * Enable Caches and MMU. Do the first non-PIC jump.
243 * Now head.S global variables, constants and externs
247 movi SR_ENABLE_MMU, r22
251 ori r22, 1, r22 /* Make it SHmedia, not required but..*/
254 rte /* And now go into the hyperspace ... */
255 hyperspace: /* ... that's the next instruction ! */
258 * Set CPU to a consistent state.
259 * r31 = FPU support flag
260 * tr0/tr7 in use. Others give a chance to loop somewhere safe
262 movi start_kernel, r32
265 ptabs r32, tr0 /* r32 = _start_kernel address */
273 gettr tr1, r28 /* r28 = hopeless address */
275 /* Set initial stack pointer */
276 movi init_thread_union, SP
277 putcon SP, KCR0 /* Set current to init_task */
278 movi THREAD_SIZE, r22 /* Point to the end */
283 * Keep FPU flag in r31. After this block:
286 movi fpu_in_use, r31 /* Temporary */
290 movi SR_ENABLE_FPU, r22
292 putcon r22, SR /* Try to enable */
295 shlri r21, 15, r21 /* Supposedly 0/1 */
296 st.q r31, 0 , r21 /* Set fpu_in_use */
299 st.q r31, 0 , r21 /* Set fpu_in_use */
301 or r21, ZERO, r31 /* Set FPU flag at last */
303 #ifndef CONFIG_SH_NO_BSS_INIT
304 /* Don't clear BSS if running on slow platforms such as an RTL simulation,
305 remote memory via SHdebug link, etc. For these the memory can be guaranteed
306 to be all zero on boot anyway. */
311 movi __bss_start, r22
316 bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
320 /* Say bye to head.S but be prepared to wrongly get back ... */
323 /* If we ever get back here through LINK/tr1-tr7 */
328 * Something's badly wrong here. Loop endlessly,
329 * there's nothing more we can do about it.
331 * Note on hopeless: it can be jumped into invariably
332 * before or after jumping into hyperspace. The only
333 * requirement is to be PIC called (PTA) before and
334 * any way (PTA/PTABS) after. According to Virtual
335 * to Physical mapping a simulator/emulator can easily
336 * tell where we came here from just looking at hopeless
339 * For debugging purposes:
340 * (r28) hopeless/loop address
342 * (r30) CPU type/Platform endianness
344 * (r32) _start_kernel address