2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * arch/sh64/kernel/head.S
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003, 2004 Paul Mundt
12 * benedict.gaster@superh.com: 2nd May 2002
13 * Moved definition of empty_zero_page to its own section allowing
14 * it to be placed at an absolute address known at load time.
16 * lethal@linux-sh.org: 9th May 2003
17 * Kill off GLOBAL_NAME() usage.
19 * lethal@linux-sh.org: 8th May 2004
20 * Add early SCIF console DTLB mapping.
23 #include <asm/cache.h>
25 #include <asm/cpu/registers.h>
26 #include <asm/cpu/mmu_context.h>
27 #include <asm/thread_info.h>
30 * MMU defines: TLB boundaries.
33 #define MMUIR_FIRST ITLB_FIXED
34 #define MMUIR_END ITLB_LAST_VAR_UNRESTRICTED+TLB_STEP
35 #define MMUIR_STEP TLB_STEP
37 #define MMUDR_FIRST DTLB_FIXED
38 #define MMUDR_END DTLB_LAST_VAR_UNRESTRICTED+TLB_STEP
39 #define MMUDR_STEP TLB_STEP
41 /* Safety check : CONFIG_PAGE_OFFSET has to be a multiple of 512Mb */
42 #if (CONFIG_PAGE_OFFSET & ((1UL<<29)-1))
43 #error "CONFIG_PAGE_OFFSET must be a multiple of 512Mb"
47 * MMU defines: Fixed TLBs.
49 /* Deal safely with the case where the base of RAM is not 512Mb aligned */
51 #define ALIGN_512M_MASK (0xffffffffe0000000)
52 #define ALIGNED_EFFECTIVE ((CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START) & ALIGN_512M_MASK)
53 #define ALIGNED_PHYSICAL (CONFIG_MEMORY_START & ALIGN_512M_MASK)
55 #define MMUIR_TEXT_H (0x0000000000000003 | ALIGNED_EFFECTIVE)
56 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
58 #define MMUIR_TEXT_L (0x000000000000009a | ALIGNED_PHYSICAL)
59 /* 512 Mb, Cacheable, Write-back, execute, Not User, Ph. Add. */
61 #define MMUDR_CACHED_H 0x0000000000000003 | ALIGNED_EFFECTIVE
62 /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
63 #define MMUDR_CACHED_L 0x000000000000015a | ALIGNED_PHYSICAL
64 /* 512 Mb, Cacheable, Write-back, read/write, Not User, Ph. Add. */
66 #ifdef CONFIG_CACHE_OFF
67 #define ICCR0_INIT_VAL ICCR0_OFF /* ICACHE off */
69 #define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */
71 #define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */
73 #if defined (CONFIG_CACHE_OFF)
74 #define OCCR0_INIT_VAL OCCR0_OFF /* D-cache: off */
75 #elif defined (CONFIG_CACHE_WRITETHROUGH)
76 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WT /* D-cache: on, */
78 #elif defined (CONFIG_CACHE_WRITEBACK)
79 #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* D-cache: on, */
82 #error preprocessor flag CONFIG_CACHE_... not recognized!
85 #define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */
87 .section .empty_zero_page, "aw"
88 .global empty_zero_page
91 .long 1 /* MOUNT_ROOT_RDONLY */
92 .long 0 /* RAMDISK_FLAGS */
93 .long 0x0200 /* ORIG_ROOT_DEV */
94 .long 1 /* LOADER_TYPE */
95 .long 0x00800000 /* INITRD_START */
96 .long 0x00800000 /* INITRD_SIZE */
108 .global mmu_pdtp_cache
112 .global empty_bad_page
116 .global empty_bad_pte_table
124 .section .text.head, "ax"
125 .balign L1_CACHE_BYTES
127 * Condition at the entry of __stext:
129 * . SR.FD = 1 (FPU disabled)
130 * . SR.BL = 1 (Exceptions disabled)
131 * . SR.MD = 1 (Privileged Mode)
132 * . SR.MMU = 0 (MMU Disabled)
133 * . SR.CD = 0 (CTC User Visible)
134 * . SR.IMASK = Undefined (Interrupt Mask)
136 * Operations supposed to be performed by __stext:
137 * . prevent speculative fetch onto device memory while MMU is off
138 * . reflect as much as possible SH5 ABI (r15, r26, r27, r18)
139 * . first, save CPU state and set it to something harmless
140 * . any CPU detection and/or endianness settings (?)
141 * . initialize EMI/LMI (but not TMU/RTC/INTC/SCIF): TBD
142 * . set initial TLB entries for cached and uncached regions
143 * (no fine granularity paging)
144 * . set initial cache state
145 * . enable MMU and caches
146 * . set CPU to a consistent state
147 * . registers (including stack pointer and current/KCR0)
148 * . NOT expecting to set Exception handling nor VBR/RESVEC/DCR
149 * at this stage. This is all to later Linux initialization steps.
152 * . jump into start_kernel()
153 * . be prepared to hopeless start_kernel() returns.
159 * Prevent speculative fetch on device memory due to
160 * uninitialized target registers.
173 * Read/Set CPU state. After this block:
177 movi SR_HARMLESS, r20
181 * Initialize EMI/LMI. To Be Done.
185 * CPU detection and/or endianness settings (?). To Be Done.
186 * Pure PIC code here, please ! Just save state into r30.
188 * r30 = CPU type/Platform Endianness
192 * Set initial TLB entries for cached and uncached regions.
193 * Note: PTA/BLINK is PIC code, PTABS/BLINK isn't !
197 movi MMUIR_FIRST, r21
200 putcfg r21, 0, ZERO /* Clear MMUIR[n].PTEH.V */
201 addi r21, MMUIR_STEP, r21
206 movi MMUDR_FIRST, r21
209 putcfg r21, 0, ZERO /* Clear MMUDR[n].PTEH.V */
210 addi r21, MMUDR_STEP, r21
213 /* Map one big (512Mb) page for ITLB */
214 movi MMUIR_FIRST, r21
215 movi MMUIR_TEXT_L, r22 /* PTEL first */
216 add.l r22, r63, r22 /* Sign extend */
217 putcfg r21, 1, r22 /* Set MMUIR[0].PTEL */
218 movi MMUIR_TEXT_H, r22 /* PTEH last */
219 add.l r22, r63, r22 /* Sign extend */
220 putcfg r21, 0, r22 /* Set MMUIR[0].PTEH */
222 /* Map one big CACHED (512Mb) page for DTLB */
223 movi MMUDR_FIRST, r21
224 movi MMUDR_CACHED_L, r22 /* PTEL first */
225 add.l r22, r63, r22 /* Sign extend */
226 putcfg r21, 1, r22 /* Set MMUDR[0].PTEL */
227 movi MMUDR_CACHED_H, r22 /* PTEH last */
228 add.l r22, r63, r22 /* Sign extend */
229 putcfg r21, 0, r22 /* Set MMUDR[0].PTEH */
231 #ifdef CONFIG_EARLY_PRINTK
233 * Setup a DTLB translation for SCIF phys.
235 addi r21, MMUDR_STEP, r21
236 movi 0x0a03, r22 /* SCIF phys */
238 putcfg r21, 1, r22 /* PTEL first */
239 movi 0xfa03, r22 /* 0xfa030000, fixed SCIF virt */
241 putcfg r21, 0, r22 /* PTEH last */
245 * Set cache behaviours.
249 movi ICCR0_INIT_VAL, r22
250 movi ICCR1_INIT_VAL, r23
251 putcfg r21, ICCR_REG0, r22
252 putcfg r21, ICCR_REG1, r23
256 movi OCCR0_INIT_VAL, r22
257 movi OCCR1_INIT_VAL, r23
258 putcfg r21, OCCR_REG0, r22
259 putcfg r21, OCCR_REG1, r23
263 * Enable Caches and MMU. Do the first non-PIC jump.
264 * Now head.S global variables, constants and externs
268 movi SR_ENABLE_MMU, r22
272 ori r22, 1, r22 /* Make it SHmedia, not required but..*/
275 rte /* And now go into the hyperspace ... */
276 hyperspace: /* ... that's the next instruction ! */
279 * Set CPU to a consistent state.
280 * r31 = FPU support flag
281 * tr0/tr7 in use. Others give a chance to loop somewhere safe
283 movi start_kernel, r32
286 ptabs r32, tr0 /* r32 = _start_kernel address */
294 gettr tr1, r28 /* r28 = hopeless address */
296 /* Set initial stack pointer */
297 movi init_thread_union, SP
298 putcon SP, KCR0 /* Set current to init_task */
299 movi THREAD_SIZE, r22 /* Point to the end */
304 * Keep FPU flag in r31. After this block:
307 movi fpu_in_use, r31 /* Temporary */
311 movi SR_ENABLE_FPU, r22
313 putcon r22, SR /* Try to enable */
316 shlri r21, 15, r21 /* Supposedly 0/1 */
317 st.q r31, 0 , r21 /* Set fpu_in_use */
320 st.q r31, 0 , r21 /* Set fpu_in_use */
322 or r21, ZERO, r31 /* Set FPU flag at last */
324 #ifndef CONFIG_SH_NO_BSS_INIT
325 /* Don't clear BSS if running on slow platforms such as an RTL simulation,
326 remote memory via SHdebug link, etc. For these the memory can be guaranteed
327 to be all zero on boot anyway. */
332 movi __bss_start, r22
337 bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
341 /* Say bye to head.S but be prepared to wrongly get back ... */
344 /* If we ever get back here through LINK/tr1-tr7 */
349 * Something's badly wrong here. Loop endlessly,
350 * there's nothing more we can do about it.
352 * Note on hopeless: it can be jumped into invariably
353 * before or after jumping into hyperspace. The only
354 * requirement is to be PIC called (PTA) before and
355 * any way (PTA/PTABS) after. According to Virtual
356 * to Physical mapping a simulator/emulator can easily
357 * tell where we came here from just looking at hopeless
360 * For debugging purposes:
361 * (r28) hopeless/loop address
363 * (r30) CPU type/Platform endianness
365 * (r32) _start_kernel address