Path: blob/master/arch/cris/arch-v32/kernel/head.S
15125 views
/*1* CRISv32 kernel startup code.2*3* Copyright (C) 2003, Axis Communications AB4*/56#define ASSEMBLER_MACROS_ONLY78/*9* The macros found in mmu_defs_asm.h uses the ## concatenation operator, so10* -traditional must not be used when assembling this file.11*/12#include <arch/memmap.h>13#include <hwregs/reg_rdwr.h>14#include <hwregs/intr_vect.h>15#include <hwregs/asm/mmu_defs_asm.h>16#include <hwregs/asm/reg_map_asm.h>17#include <mach/startup.inc>1819#define CRAMFS_MAGIC 0x28cd3d4520#define JHEAD_MAGIC 0x1FF528A621#define JHEAD_SIZE 822#define RAM_INIT_MAGIC 0x5690238723#define COMMAND_LINE_MAGIC 0x8710956324#define NAND_BOOT_MAGIC 0x9a9db0012526;; NOTE: R8 and R9 carry information from the decompressor (if the27;; kernel was compressed). They must not be used in the code below28;; until they are read!2930;; Exported symbols.31.global etrax_irv32.global romfs_start33.global romfs_length34.global romfs_in_flash35.global nand_boot36.global swapper_pg_dir3738;; Dummy section to make it bootable with current VCS simulator39#ifdef CONFIG_ETRAX_VCS_SIM40.section ".boot", "ax"41ba tstart42nop43#endif4445.text46tstart:47;; This is the entry point of the kernel. The CPU is currently in48;; supervisor mode.49;;50;; 0x00000000 if flash.51;; 0x40004000 if DRAM.52;;53di5455START_CLOCKS5657SETUP_WAIT_STATES5859GIO_INIT6061#ifdef CONFIG_SMP62secondary_cpu_entry: /* Entry point for secondary CPUs */63di64#endif6566;; Setup and enable the MMU. Use same configuration for both the data67;; and the instruction MMU.68;;69;; Note; 3 cycles is needed for a bank-select to take effect. Further;70;; bank 1 is the instruction MMU, bank 2 is the data MMU.7172#ifdef CONFIG_CRIS_MACH_ARTPEC373move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \74| REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \75| REG_FIELD(mmu, rw_mm_kbase_hi, base_d, 5) \76| REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r077#elif !defined(CONFIG_ETRAX_VCS_SIM)78move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \79| REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \80| REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r081#else82;; Map the virtual DRAM to the RW eprom area at address 0.83;; Also map 0xa for the hook calls,84move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \85| REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \86| REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb) \87| REG_FIELD(mmu, rw_mm_kbase_hi, base_a, 0xa), $r088#endif8990;; Temporary map of 0x40 -> 0x40 and 0x00 -> 0x00.91move.d REG_FIELD(mmu, rw_mm_kbase_lo, base_4, 4) \92| REG_FIELD(mmu, rw_mm_kbase_lo, base_0, 0), $r19394;; Enable certain page protections and setup linear mapping95;; for f,e,c,b,4,0.9697;; ARTPEC-3:98;; c,d used for linear kernel mapping, up to 512 MB99;; e used for vmalloc100;; f unused, but page mapped to get page faults101102;; ETRAX FS:103;; c used for linear kernel mapping, up to 256 MB104;; d used for vmalloc105;; e,f used for memory-mapped NOR flash106107#ifdef CONFIG_CRIS_MACH_ARTPEC3108move.d REG_STATE(mmu, rw_mm_cfg, we, on) \109| REG_STATE(mmu, rw_mm_cfg, acc, on) \110| REG_STATE(mmu, rw_mm_cfg, ex, on) \111| REG_STATE(mmu, rw_mm_cfg, inv, on) \112| REG_STATE(mmu, rw_mm_cfg, seg_f, page) \113| REG_STATE(mmu, rw_mm_cfg, seg_e, page) \114| REG_STATE(mmu, rw_mm_cfg, seg_d, linear) \115| REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \116| REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \117| REG_STATE(mmu, rw_mm_cfg, seg_a, page) \118| REG_STATE(mmu, rw_mm_cfg, seg_9, page) \119| REG_STATE(mmu, rw_mm_cfg, seg_8, page) \120| REG_STATE(mmu, rw_mm_cfg, seg_7, page) \121| REG_STATE(mmu, rw_mm_cfg, seg_6, page) \122| REG_STATE(mmu, rw_mm_cfg, seg_5, page) \123| REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \124| REG_STATE(mmu, rw_mm_cfg, seg_3, page) \125| REG_STATE(mmu, rw_mm_cfg, seg_2, page) \126| REG_STATE(mmu, rw_mm_cfg, seg_1, page) \127| REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2128#elif !defined(CONFIG_ETRAX_VCS_SIM)129move.d REG_STATE(mmu, rw_mm_cfg, we, on) \130| REG_STATE(mmu, rw_mm_cfg, acc, on) \131| REG_STATE(mmu, rw_mm_cfg, ex, on) \132| REG_STATE(mmu, rw_mm_cfg, inv, on) \133| REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \134| REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \135| REG_STATE(mmu, rw_mm_cfg, seg_d, page) \136| REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \137| REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \138| REG_STATE(mmu, rw_mm_cfg, seg_a, page) \139| REG_STATE(mmu, rw_mm_cfg, seg_9, page) \140| REG_STATE(mmu, rw_mm_cfg, seg_8, page) \141| REG_STATE(mmu, rw_mm_cfg, seg_7, page) \142| REG_STATE(mmu, rw_mm_cfg, seg_6, page) \143| REG_STATE(mmu, rw_mm_cfg, seg_5, page) \144| REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \145| REG_STATE(mmu, rw_mm_cfg, seg_3, page) \146| REG_STATE(mmu, rw_mm_cfg, seg_2, page) \147| REG_STATE(mmu, rw_mm_cfg, seg_1, page) \148| REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2149#else150move.d REG_STATE(mmu, rw_mm_cfg, we, on) \151| REG_STATE(mmu, rw_mm_cfg, acc, on) \152| REG_STATE(mmu, rw_mm_cfg, ex, on) \153| REG_STATE(mmu, rw_mm_cfg, inv, on) \154| REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \155| REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \156| REG_STATE(mmu, rw_mm_cfg, seg_d, page) \157| REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \158| REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \159| REG_STATE(mmu, rw_mm_cfg, seg_a, linear) \160| REG_STATE(mmu, rw_mm_cfg, seg_9, page) \161| REG_STATE(mmu, rw_mm_cfg, seg_8, page) \162| REG_STATE(mmu, rw_mm_cfg, seg_7, page) \163| REG_STATE(mmu, rw_mm_cfg, seg_6, page) \164| REG_STATE(mmu, rw_mm_cfg, seg_5, page) \165| REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \166| REG_STATE(mmu, rw_mm_cfg, seg_3, page) \167| REG_STATE(mmu, rw_mm_cfg, seg_2, page) \168| REG_STATE(mmu, rw_mm_cfg, seg_1, page) \169| REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2170#endif171172;; Update instruction MMU.173move 1, $srs174nop175nop176nop177move $r0, $s2 ; kbase_hi.178move $r1, $s1 ; kbase_lo.179move $r2, $s0 ; mm_cfg, virtual memory configuration.180181;; Update data MMU.182move 2, $srs183nop184nop185nop186move $r0, $s2 ; kbase_hi.187move $r1, $s1 ; kbase_lo188move $r2, $s0 ; mm_cfg, virtual memory configuration.189190;; Enable data and instruction MMU.191move 0, $srs192moveq 0xf, $r0 ; IMMU, DMMU, DCache, Icache on193nop194nop195nop196move $r0, $s0197nop198nop199nop200201#ifdef CONFIG_SMP202;; Read CPU ID203move 0, $srs204nop205nop206nop207move $s12, $r0208cmpq 0, $r0209beq master_cpu210nop211slave_cpu:212; Time to boot-up. Get stack location provided by master CPU.213move.d smp_init_current_idle_thread, $r1214move.d [$r1], $sp215add.d 8192, $sp216move.d ebp_start, $r0 ; Defined in linker-script.217move $r0, $ebp218jsr smp_callin219nop220master_cpu:221/* Set up entry point for secondary CPUs. The boot ROM has set up222* EBP at start of internal memory. The CPU will get there223* later when we issue an IPI to them... */224move.d MEM_INTMEM_START + IPI_INTR_VECT * 4, $r0225move.d secondary_cpu_entry, $r1226move.d $r1, [$r0]227#endif228#ifndef CONFIG_ETRAX_VCS_SIM229; Check if starting from DRAM (network->RAM boot or unpacked230; compressed kernel), or directly from flash.231lapcq ., $r0232and.d 0x7fffffff, $r0 ; Mask off the non-cache bit.233cmp.d 0x10000, $r0 ; Arbitrary, something above this code.234blo _inflash0235nop236#endif237238jump _inram ; Jump to cached RAM.239nop240241;; Jumpgate.242_inflash0:243jump _inflash244nop245246;; Put the following in a section so that storage for it can be247;; reclaimed after init is finished.248.section ".init.text", "ax"249250_inflash:251252;; Initialize DRAM.253cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?254beq _dram_initialized255nop256257#if defined CONFIG_ETRAXFS258#include "../mach-fs/dram_init.S"259#elif defined CONFIG_CRIS_MACH_ARTPEC3260#include "../mach-a3/dram_init.S"261#else262#error Only ETRAXFS and ARTPEC-3 supported!263#endif264265266_dram_initialized:267;; Copy the text and data section to DRAM. This depends on that the268;; variables used below are correctly set up by the linker script.269;; The calculated value stored in R4 is used below.270;; Leave the cramfs file system (piggybacked after the kernel) in flash.271moveq 0, $r0 ; Source.272move.d text_start, $r1 ; Destination.273move.d __vmlinux_end, $r2274move.d $r2, $r4275sub.d $r1, $r42761: move.w [$r0+], $r3277move.w $r3, [$r1+]278cmp.d $r2, $r1279blo 1b280nop281282;; Check for cramfs.283moveq 0, $r0284move.d romfs_length, $r1285move.d $r0, [$r1]286move.d [$r4], $r0 ; cramfs_super.magic287cmp.d CRAMFS_MAGIC, $r0288bne 1f289nop290291;; Set length and start of cramfs, set romfs_in_flash flag292addoq +4, $r4, $acr293move.d [$acr], $r0294move.d romfs_length, $r1295move.d $r0, [$r1]296add.d 0xf0000000, $r4 ; Add cached flash start in virtual memory.297move.d romfs_start, $r1298move.d $r4, [$r1]2991: moveq 1, $r0300move.d romfs_in_flash, $r1301move.d $r0, [$r1]302303jump _start_it ; Jump to cached code.304nop305306_inram:307;; Check if booting from NAND flash; if so, set appropriate flags308;; and move on.309cmp.d NAND_BOOT_MAGIC, $r12310bne move_cramfs ; not nand, jump311moveq 1, $r0312move.d nand_boot, $r1 ; tell axisflashmap we're booting from NAND313move.d $r0, [$r1]314moveq 0, $r0 ; tell axisflashmap romfs is not in315move.d romfs_in_flash, $r1 ; (directly accessed) flash316move.d $r0, [$r1]317jump _start_it ; continue with boot318nop319320move_cramfs:321;; kernel is in DRAM.322;; Must figure out if there is a piggybacked rootfs image or not.323;; Set romfs_length to 0 => no rootfs image available by default.324moveq 0, $r0325move.d romfs_length, $r1326move.d $r0, [$r1]327328#ifndef CONFIG_ETRAX_VCS_SIM329;; The kernel could have been unpacked to DRAM by the loader, but330;; the cramfs image could still be in the flash immediately331;; following the compressed kernel image. The loader passes the address332;; of the byte succeeding the last compressed byte in the flash in333;; register R9 when starting the kernel.334cmp.d 0x0ffffff8, $r9335bhs _no_romfs_in_flash ; R9 points outside the flash area.336nop337#else338ba _no_romfs_in_flash339nop340#endif341;; cramfs rootfs might to be in flash. Check for it.342move.d [$r9], $r0 ; cramfs_super.magic343cmp.d CRAMFS_MAGIC, $r0344bne _no_romfs_in_flash345nop346347;; found cramfs in flash. set address and size, and romfs_in_flash flag.348addoq +4, $r9, $acr349move.d [$acr], $r0350move.d romfs_length, $r1351move.d $r0, [$r1]352add.d 0xf0000000, $r9 ; Add cached flash start in virtual memory.353move.d romfs_start, $r1354move.d $r9, [$r1]355moveq 1, $r0356move.d romfs_in_flash, $r1357move.d $r0, [$r1]358359jump _start_it ; Jump to cached code.360nop361362_no_romfs_in_flash:363;; No romfs in flash, so look for cramfs, or jffs2 with jhead,364;; after kernel in RAM, as is the case with network->RAM boot.365;; For cramfs, partition starts with magic and length.366;; For jffs2, a jhead is prepended which contains with magic and length.367;; The jhead is not part of the jffs2 partition however.368#ifndef CONFIG_ETRAXFS_SIM369move.d __bss_start, $r0370#else371move.d __end, $r0372#endif373move.d [$r0], $r1374cmp.d CRAMFS_MAGIC, $r1 ; cramfs magic?375beq 2f ; yes, jump376nop377cmp.d JHEAD_MAGIC, $r1 ; jffs2 (jhead) magic?378bne 4f ; no, skip copy379nop380addq 4, $r0 ; location of jffs2 size381move.d [$r0+], $r2 ; fetch jffs2 size -> r2382; r0 now points to start of jffs2383ba 3f384nop3852:386addoq +4, $r0, $acr ; location of cramfs size387move.d [$acr], $r2 ; fetch cramfs size -> r2388; r0 still points to start of cramfs3893:390;; Now, move the root fs to after kernel's BSS391392move.d _end, $r1 ; start of cramfs -> r1393move.d romfs_start, $r3394move.d $r1, [$r3] ; store at romfs_start (for axisflashmap)395move.d romfs_length, $r3396move.d $r2, [$r3] ; store size at romfs_length397398#ifndef CONFIG_ETRAX_VCS_SIM399add.d $r2, $r0 ; copy from end and downwards400add.d $r2, $r1401402lsrq 1, $r2 ; Size is in bytes, we copy words.403addq 1, $r24041:405move.w [$r0], $r3406move.w $r3, [$r1]407subq 2, $r0408subq 2, $r1409subq 1, $r2410bne 1b411nop412#endif4134144:415;; BSS move done.416;; Clear romfs_in_flash flag, as we now know romfs is in DRAM417;; Also clear nand_boot flag; if we got here, we know we've not418;; booted from NAND flash.419moveq 0, $r0420move.d romfs_in_flash, $r1421move.d $r0, [$r1]422moveq 0, $r0423move.d nand_boot, $r1424move.d $r0, [$r1]425426jump _start_it ; Jump to cached code.427nop428429_start_it:430431;; Check if kernel command line is supplied432cmp.d COMMAND_LINE_MAGIC, $r10433bne no_command_line434nop435436move.d 256, $r13437move.d cris_command_line, $r10438or.d 0x80000000, $r11 ; Make it virtual4391:440move.b [$r11+], $r1441move.b $r1, [$r10+]442subq 1, $r13443bne 1b444nop445446no_command_line:447448;; The kernel stack contains a task structure for each task. This449;; the initial kernel stack is in the same page as the init_task,450;; but starts at the top of the page, i.e. + 8192 bytes.451move.d init_thread_union + 8192, $sp452move.d ebp_start, $r0 ; Defined in linker-script.453move $r0, $ebp454move.d etrax_irv, $r1 ; Set the exception base register and pointer.455move.d $r0, [$r1]456457#ifndef CONFIG_ETRAX_VCS_SIM458;; Clear the BSS region from _bss_start to _end.459move.d __bss_start, $r0460move.d _end, $r14611: clear.d [$r0+]462cmp.d $r1, $r0463blo 1b464nop465#endif466467#ifdef CONFIG_ETRAX_VCS_SIM468/* Set the watchdog timeout to something big. Will be removed when */469/* watchdog can be disabled with command line option */470move.d 0x7fffffff, $r10471jsr CPU_WATCHDOG_TIMEOUT472nop473#endif474475; Initialize registers to increase determinism476move.d __bss_start, $r0477movem [$r0], $r13478479#ifdef CONFIG_ETRAX_L2CACHE480jsr l2cache_init481nop482#endif483484jump start_kernel ; Jump to start_kernel() in init/main.c.485nop486487.data488etrax_irv:489.dword 0490491; Variables for communication with the Axis flash map driver (axisflashmap),492; and for setting up memory in arch/cris/kernel/setup.c .493494; romfs_start is set to the start of the root file system, if it exists495; in directly accessible memory (i.e. NOR Flash when booting from Flash,496; or RAM when booting directly from a network-downloaded RAM image)497romfs_start:498.dword 0499500; romfs_length is set to the size of the root file system image, if it exists501; in directly accessible memory (see romfs_start). Otherwise it is set to 0.502romfs_length:503.dword 0504505; romfs_in_flash is set to 1 if the root file system resides in directly506; accessible flash memory (i.e. NOR flash). It is set to 0 for RAM boot507; or NAND flash boot.508romfs_in_flash:509.dword 0510511; nand_boot is set to 1 when the kernel has been booted from NAND flash512nand_boot:513.dword 0514515swapper_pg_dir = 0xc0002000516517.section ".init.data", "aw"518519#if defined CONFIG_ETRAXFS520#include "../mach-fs/hw_settings.S"521#elif defined CONFIG_CRIS_MACH_ARTPEC3522#include "../mach-a3/hw_settings.S"523#else524#error Only ETRAXFS and ARTPEC-3 supported!525#endif526527528