2 * arch/sh/kernel/head_64.S
4 * Copyright (C) 2000, 2001 Paolo Alberelli
5 * Copyright (C) 2003, 2004 Paul Mundt
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
12 #include <linux/init.h>
15 #include <asm/cache.h>
17 #include <cpu/registers.h>
18 #include <cpu/mmu_context.h>
19 #include <asm/thread_info.h>
22 * MMU defines: TLB boundaries.
25 #define MMUIR_FIRST ITLB_FIXED
26 #define MMUIR_END ITLB_LAST_VAR_UNRESTRICTED+TLB_STEP
27 #define MMUIR_STEP TLB_STEP
29 #define MMUDR_FIRST DTLB_FIXED
30 #define MMUDR_END DTLB_LAST_VAR_UNRESTRICTED+TLB_STEP
31 #define MMUDR_STEP TLB_STEP
33 /* Safety check : CONFIG_PAGE_OFFSET has to be a multiple of 512Mb */
34 #if (CONFIG_PAGE_OFFSET & ((1UL<<29)-1))
35 #error "CONFIG_PAGE_OFFSET must be a multiple of 512Mb"
39 * MMU defines: Fixed TLBs.
41 /* Deal safely with the case where the base of RAM is not 512Mb aligned */
43 #define ALIGN_512M_MASK (0xffffffffe0000000)
44 #define ALIGNED_EFFECTIVE ((CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START) & ALIGN_512M_MASK)
45 #define ALIGNED_PHYSICAL (CONFIG_MEMORY_START & ALIGN_512M_MASK)
47 #define MMUIR_TEXT_H (0x0000000000000003 | ALIGNED_EFFECTIVE)
48 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
50 #define MMUIR_TEXT_L (0x000000000000009a | ALIGNED_PHYSICAL)
51 /* 512 Mb, Cacheable, Write-back, execute, Not User, Ph. Add. */
53 #define MMUDR_CACHED_H 0x0000000000000003 | ALIGNED_EFFECTIVE
54 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
55 #define MMUDR_CACHED_L 0x000000000000015a | ALIGNED_PHYSICAL
56 /* 512 Mb, Cacheable, Write-back, read/write, Not User, Ph. Add. */
58 #ifdef CONFIG_CACHE_OFF
59 #define ICCR0_INIT_VAL ICCR0_OFF /* ICACHE off */
61 #define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */
63 #define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */
65 #if defined (CONFIG_CACHE_OFF)
66 #define OCCR0_INIT_VAL OCCR0_OFF /* D-cache: off */
67 #elif defined (CONFIG_CACHE_WRITETHROUGH)
68 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WT /* D-cache: on, */
70 #elif defined (CONFIG_CACHE_WRITEBACK)
71 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* D-cache: on, */
74 #error preprocessor flag CONFIG_CACHE_... not recognized!
77 #define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */
79 .section .empty_zero_page, "aw"
80 .global empty_zero_page
83 .long 1 /* MOUNT_ROOT_RDONLY */
84 .long 0 /* RAMDISK_FLAGS */
85 .long 0x0200 /* ORIG_ROOT_DEV */
86 .long 1 /* LOADER_TYPE */
87 .long 0x00800000 /* INITRD_START */
88 .long 0x00800000 /* INITRD_SIZE */
100 .global mmu_pdtp_cache
104 .global empty_bad_page
108 .global empty_bad_pte_table
117 .balign L1_CACHE_BYTES
119 * Condition at the entry of __stext:
121 * . SR.FD = 1 (FPU disabled)
122 * . SR.BL = 1 (Exceptions disabled)
123 * . SR.MD = 1 (Privileged Mode)
124 * . SR.MMU = 0 (MMU Disabled)
125 * . SR.CD = 0 (CTC User Visible)
126 * . SR.IMASK = Undefined (Interrupt Mask)
128 * Operations supposed to be performed by __stext:
129 * . prevent speculative fetch onto device memory while MMU is off
130 * . reflect as much as possible SH5 ABI (r15, r26, r27, r18)
131 * . first, save CPU state and set it to something harmless
132 * . any CPU detection and/or endianness settings (?)
133 * . initialize EMI/LMI (but not TMU/RTC/INTC/SCIF): TBD
134 * . set initial TLB entries for cached and uncached regions
135 * (no fine granularity paging)
136 * . set initial cache state
137 * . enable MMU and caches
138 * . set CPU to a consistent state
139 * . registers (including stack pointer and current/KCR0)
140 * . NOT expecting to set Exception handling nor VBR/RESVEC/DCR
141 * at this stage. This is all to later Linux initialization steps.
144 * . jump into start_kernel()
145 * . be prepared to hopeless start_kernel() returns.
151 * Prevent speculative fetch on device memory due to
152 * uninitialized target registers.
165 * Read/Set CPU state. After this block:
169 movi SR_HARMLESS, r20
173 * Initialize EMI/LMI. To Be Done.
177 * CPU detection and/or endianness settings (?). To Be Done.
178 * Pure PIC code here, please ! Just save state into r30.
180 * r30 = CPU type/Platform Endianness
184 * Set initial TLB entries for cached and uncached regions.
185 * Note: PTA/BLINK is PIC code, PTABS/BLINK isn't !
189 movi MMUIR_FIRST, r21
192 putcfg r21, 0, ZERO /* Clear MMUIR[n].PTEH.V */
193 addi r21, MMUIR_STEP, r21
198 movi MMUDR_FIRST, r21
201 putcfg r21, 0, ZERO /* Clear MMUDR[n].PTEH.V */
202 addi r21, MMUDR_STEP, r21
205 /* Map one big (512Mb) page for ITLB */
206 movi MMUIR_FIRST, r21
207 movi MMUIR_TEXT_L, r22 /* PTEL first */
208 add.l r22, r63, r22 /* Sign extend */
209 putcfg r21, 1, r22 /* Set MMUIR[0].PTEL */
210 movi MMUIR_TEXT_H, r22 /* PTEH last */
211 add.l r22, r63, r22 /* Sign extend */
212 putcfg r21, 0, r22 /* Set MMUIR[0].PTEH */
214 /* Map one big CACHED (512Mb) page for DTLB */
215 movi MMUDR_FIRST, r21
216 movi MMUDR_CACHED_L, r22 /* PTEL first */
217 add.l r22, r63, r22 /* Sign extend */
218 putcfg r21, 1, r22 /* Set MMUDR[0].PTEL */
219 movi MMUDR_CACHED_H, r22 /* PTEH last */
220 add.l r22, r63, r22 /* Sign extend */
221 putcfg r21, 0, r22 /* Set MMUDR[0].PTEH */
224 * Setup a DTLB translation for SCIF phys.
226 addi r21, MMUDR_STEP, r21
227 movi 0x0a03, r22 /* SCIF phys */
229 putcfg r21, 1, r22 /* PTEL first */
230 movi 0xfa03, r22 /* 0xfa030000, fixed SCIF virt */
232 putcfg r21, 0, r22 /* PTEH last */
235 * Set cache behaviours.
239 movi ICCR0_INIT_VAL, r22
240 movi ICCR1_INIT_VAL, r23
241 putcfg r21, ICCR_REG0, r22
242 putcfg r21, ICCR_REG1, r23
246 movi OCCR0_INIT_VAL, r22
247 movi OCCR1_INIT_VAL, r23
248 putcfg r21, OCCR_REG0, r22
249 putcfg r21, OCCR_REG1, r23
253 * Enable Caches and MMU. Do the first non-PIC jump.
254 * Now head.S global variables, constants and externs
258 movi SR_ENABLE_MMU, r22
262 ori r22, 1, r22 /* Make it SHmedia, not required but..*/
265 rte /* And now go into the hyperspace ... */
266 hyperspace: /* ... that's the next instruction ! */
269 * Set CPU to a consistent state.
270 * r31 = FPU support flag
271 * tr0/tr7 in use. Others give a chance to loop somewhere safe
273 movi start_kernel, r32
276 ptabs r32, tr0 /* r32 = _start_kernel address */
284 gettr tr1, r28 /* r28 = hopeless address */
286 /* Set initial stack pointer */
287 movi init_thread_union, SP
288 putcon SP, KCR0 /* Set current to init_task */
289 movi THREAD_SIZE, r22 /* Point to the end */
294 * Keep FPU flag in r31. After this block:
297 movi fpu_in_use, r31 /* Temporary */
301 movi SR_ENABLE_FPU, r22
303 putcon r22, SR /* Try to enable */
306 shlri r21, 15, r21 /* Supposedly 0/1 */
307 st.q r31, 0 , r21 /* Set fpu_in_use */
310 st.q r31, 0 , r21 /* Set fpu_in_use */
312 or r21, ZERO, r31 /* Set FPU flag at last */
314 #ifndef CONFIG_SH_NO_BSS_INIT
315 /* Don't clear BSS if running on slow platforms such as an RTL simulation,
316 remote memory via SHdebug link, etc. For these the memory can be guaranteed
317 to be all zero on boot anyway. */
322 movi __bss_start, r22
327 bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
331 /* Say bye to head.S but be prepared to wrongly get back ... */
334 /* If we ever get back here through LINK/tr1-tr7 */
339 * Something's badly wrong here. Loop endlessly,
340 * there's nothing more we can do about it.
342 * Note on hopeless: it can be jumped into invariably
343 * before or after jumping into hyperspace. The only
344 * requirement is to be PIC called (PTA) before and
345 * any way (PTA/PTABS) after. According to Virtual
346 * to Physical mapping a simulator/emulator can easily
347 * tell where we came here from just looking at hopeless
350 * For debugging purposes:
351 * (r28) hopeless/loop address
353 * (r30) CPU type/Platform endianness
355 * (r32) _start_kernel address