/* SPDX-License-Identifier: GPL-2.0 */1/*****************************************************************************/23/*4* head.S -- common startup code for ColdFire CPUs.5*6* (C) Copyright 1999-2011, Greg Ungerer <[email protected]>.7*/89/*****************************************************************************/1011#include <linux/linkage.h>12#include <linux/init.h>13#include <asm/asm-offsets.h>14#include <asm/coldfire.h>15#include <asm/mcfsim.h>16#include <asm/mcfmmu.h>17#include <asm/thread_info.h>1819/*****************************************************************************/2021/*22* If we don't have a fixed memory size, then lets build in code23* to auto detect the DRAM size. Obviously this is the preferred24* method, and should work for most boards. It won't work for those25* that do not have their RAM starting at address 0, and it only26* works on SDRAM (not boards fitted with SRAM).27*/28#if CONFIG_RAMSIZE != 029.macro GET_MEM_SIZE30movel #CONFIG_RAMSIZE,%d0 /* hard coded memory size */31.endm3233#elif defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \34defined(CONFIG_M5249) || defined(CONFIG_M525x) || \35defined(CONFIG_M527x) || defined(CONFIG_M528x) || \36defined(CONFIG_M5307) || defined(CONFIG_M5407)37/*38* Not all these devices have exactly the same DRAM controller,39* but the DCMR register is virtually identical - give or take40* a couple of bits. The only exception is the 5272 devices, their41* DRAM controller is quite different.42*/43.macro GET_MEM_SIZE44movel MCFSIM_DMR0,%d0 /* get mask for 1st bank */45btst #0,%d0 /* check if region enabled */46beq 1f47andl #0xfffc0000,%d048beq 1f49addl #0x00040000,%d0 /* convert mask to size */501:51movel MCFSIM_DMR1,%d1 /* get mask for 2nd bank */52btst #0,%d1 /* check if region enabled */53beq 2f54andl #0xfffc0000,%d155beq 2f56addl #0x00040000,%d157addl %d1,%d0 /* total mem size in d0 */582:59.endm6061#elif defined(CONFIG_M5272)62.macro GET_MEM_SIZE63movel MCFSIM_CSOR7,%d0 /* get SDRAM address mask */64andil #0xfffff000,%d0 /* mask out chip select options */65negl %d0 /* negate bits */66.endm6768#elif defined(CONFIG_M520x)69.macro GET_MEM_SIZE70clrl %d071movel MCFSIM_SDCS0, %d2 /* Get SDRAM chip select 0 config */72andl #0x1f, %d2 /* Get only the chip select size */73beq 3f /* Check if it is enabled */74addql #1, %d2 /* Form exponent */75moveql #1, %d076lsll %d2, %d0 /* 2 ^ exponent */773:78movel MCFSIM_SDCS1, %d2 /* Get SDRAM chip select 1 config */79andl #0x1f, %d2 /* Get only the chip select size */80beq 4f /* Check if it is enabled */81addql #1, %d2 /* Form exponent */82moveql #1, %d183lsll %d2, %d1 /* 2 ^ exponent */84addl %d1, %d0 /* Total size of SDRAM in d0 */854:86.endm8788#else89#error "ERROR: I don't know how to probe your boards memory size?"90#endif9192/*****************************************************************************/9394/*95* Boards and platforms can do specific early hardware setup if96* they need to. Most don't need this, define away if not required.97*/98#ifndef PLATFORM_SETUP99#define PLATFORM_SETUP100#endif101102/*****************************************************************************/103104.global _start105.global _rambase106.global _ramvec107.global _ramstart108.global _ramend109#if defined(CONFIG_UBOOT)110.global _init_sp111#endif112113/*****************************************************************************/114115.data116117/*118* During startup we store away the RAM setup. These are not in the119* bss, since their values are determined and written before the bss120* has been cleared.121*/122_rambase:123.long 0124_ramvec:125.long 0126_ramstart:127.long 0128_ramend:129.long 0130#if defined(CONFIG_UBOOT)131_init_sp:132.long 0133#endif134135/*****************************************************************************/136137__HEAD138139#ifdef CONFIG_MMU140_start0:141jmp _start142.global kernel_pg_dir143.equ kernel_pg_dir,_start0144.equ .,_start0+0x1000145#endif146147/*148* This is the codes first entry point. This is where it all149* begins...150*/151152_start:153nop /* filler */154movew #0x2700, %sr /* no interrupts */155movel #CACHE_INIT,%d0 /* disable cache */156movec %d0,%CACR157nop158#if defined(CONFIG_UBOOT)159movel %sp,_init_sp /* save initial stack pointer */160#endif161#ifdef CONFIG_MBAR162movel #CONFIG_MBAR+1,%d0 /* configured MBAR address */163movec %d0,%MBAR /* set it */164#endif165166/*167* Do any platform or board specific setup now. Most boards168* don't need anything. Those exceptions are define this in169* their board specific includes.170*/171PLATFORM_SETUP172173/*174* Create basic memory configuration. Set VBR accordingly,175* and size memory.176*/177movel #CONFIG_VECTORBASE,%a7178movec %a7,%VBR /* set vectors addr */179movel %a7,_ramvec180181movel #CONFIG_RAMBASE,%a7 /* mark the base of RAM */182movel %a7,_rambase183184GET_MEM_SIZE /* macro code determines size */185addl %a7,%d0186movel %d0,_ramend /* set end ram addr */187188/*189* Now that we know what the memory is, lets enable cache190* and get things moving. This is Coldfire CPU specific. Not191* all version cores have identical cache register setup. But192* it is very similar. Define the exact settings in the headers193* then the code here is the same for all.194*/195movel #ACR0_MODE,%d0 /* set RAM region for caching */196movec %d0,%ACR0197movel #ACR1_MODE,%d0 /* anything else to cache? */198movec %d0,%ACR1199#ifdef ACR2_MODE200movel #ACR2_MODE,%d0201movec %d0,%ACR2202movel #ACR3_MODE,%d0203movec %d0,%ACR3204#endif205movel #CACHE_MODE,%d0 /* enable cache */206movec %d0,%CACR207nop208209#ifdef CONFIG_MMU210/*211* Identity mapping for the kernel region.212*/213movel #(MMUBASE+1),%d0 /* enable MMUBAR registers */214movec %d0,%MMUBAR215movel #MMUOR_CA,%d0 /* clear TLB entries */216movel %d0,MMUOR217movel #0,%d0 /* set ASID to 0 */218movec %d0,%asid219220movel #MMUCR_EN,%d0 /* Enable the identity map */221movel %d0,MMUCR222nop /* sync i-pipeline */223224movel #_vstart,%a0 /* jump to "virtual" space */225jmp %a0@226_vstart:227#endif /* CONFIG_MMU */228229#ifdef CONFIG_ROMFS_FS230/*231* Move ROM filesystem above bss :-)232*/233lea __bss_start,%a0 /* get start of bss */234lea __bss_stop,%a1 /* set up destination */235movel %a0,%a2 /* copy of bss start */236237movel 8(%a0),%d0 /* get size of ROMFS */238addql #8,%d0 /* allow for rounding */239andl #0xfffffffc, %d0 /* whole words */240241addl %d0,%a0 /* copy from end */242addl %d0,%a1 /* copy from end */243movel %a1,_ramstart /* set start of ram */244245_copy_romfs:246movel -(%a0),%d0 /* copy dword */247movel %d0,-(%a1)248cmpl %a0,%a2 /* check if at end */249bne _copy_romfs250251#else /* CONFIG_ROMFS_FS */252lea __bss_stop,%a1253movel %a1,_ramstart254#endif /* CONFIG_ROMFS_FS */255256257/*258* Zero out the bss region.259*/260lea __bss_start,%a0 /* get start of bss */261lea __bss_stop,%a1 /* get end of bss */262clrl %d0 /* set value */263_clear_bss:264movel %d0,(%a0)+ /* clear each word */265cmpl %a0,%a1 /* check if at end */266bne _clear_bss267268/*269* Load the current task pointer and stack.270*/271lea init_thread_union,%a0272lea THREAD_SIZE(%a0),%sp273274#ifdef CONFIG_MMU275.global m68k_cputype276.global m68k_mmutype277.global m68k_fputype278.global m68k_machtype279movel #CPU_COLDFIRE,%d0280movel %d0,m68k_cputype /* Mark us as a ColdFire */281movel #MMU_COLDFIRE,%d0282movel %d0,m68k_mmutype283movel #FPUTYPE,%d0284movel %d0,m68k_fputype /* Mark FPU type */285movel #MACHINE,%d0286movel %d0,m68k_machtype /* Mark machine type */287lea init_task,%a2 /* Set "current" init task */288#endif289290/*291* Assembler start up done, start code proper.292*/293jsr start_kernel /* start Linux kernel */294295_exit:296jmp _exit /* should never get here */297298/*****************************************************************************/299300301