Path: blob/master/arch/xtensa/boot/boot-redboot/bootstrap.S
10818 views
#include <variant/core.h>1#include <asm/regs.h>2#include <asm/asmmacro.h>3#include <asm/cacheasm.h>4/*5* RB-Data: RedBoot data/bss6* P: Boot-Parameters7* L: Kernel-Loader8*9* The Linux-Kernel image including the loader must be loaded10* to a position so that the kernel and the boot parameters11* can fit in the space before the load address.12* ______________________________________________________13* |_RB-Data_|_P_|__________|_L_|___Linux-Kernel___|______|14* ^15* ^ Load address16* ______________________________________________________17* |___Linux-Kernel___|_P_|_L_|___________________________|18*19* The loader copies the parameter to the position that will20* be the end of the kernel and itself to the end of the21* parameter list.22*/2324/* Make sure we have enough space for the 'uncompressor' */2526#define STACK_SIZE 3276827#define HEAP_SIZE (131072*4)2829# a2: Parameter list30# a3: Size of parameter list3132.section .start, "ax"3334.globl __start35/* this must be the first byte of the loader! */36__start:37entry sp, 32 # we do not intend to return38_call0 _start39__start_a0:40.align 44142.section .text, "ax"43.begin literal_prefix .text4445/* put literals in here! */4647.globl _start48_start:4950/* 'reset' window registers */5152movi a4, 153wsr a4, PS54rsync5556rsr a5, WINDOWBASE57ssl a558sll a4, a459wsr a4, WINDOWSTART60rsync6162movi a4, 0x0004000063wsr a4, PS64rsync6566/* copy the loader to its address67* Note: The loader itself is a very small piece, so we assume we68* don't partially overlap. We also assume (even more important)69* that the kernel image is out of the way. Usually, when the70* load address of this image is not at an arbitrary address,71* but aligned to some 10K's we shouldn't overlap.72*/7374/* Note: The assembler cannot relax "addi a0, a0, ..." to an75l32r, so we load to a4 first. */7677# addi a4, a0, __start - __start_a078# mov a0, a47980movi a4, __start81movi a5, __start_a082add a4, a0, a483sub a0, a4, a58485movi a4, __start86movi a5, __reloc_end8788# a0: address where this code has been loaded89# a4: compiled address of __start90# a5: compiled end address9192mov.n a7, a093mov.n a8, a494951:96l32i a10, a7, 097l32i a11, a7, 498s32i a10, a8, 099s32i a11, a8, 4100l32i a10, a7, 8101l32i a11, a7, 12102s32i a10, a8, 8103s32i a11, a8, 12104addi a8, a8, 16105addi a7, a7, 16106blt a8, a5, 1b107108109/* We have to flush and invalidate the caches here before we jump. */110111#if XCHAL_DCACHE_IS_WRITEBACK112113___flush_dcache_all a5 a6114115#endif116117___invalidate_icache_all a5 a6118isync119120movi a11, _reloc121jx a11122123.globl _reloc124_reloc:125126/* RedBoot is now at the end of the memory, so we don't have127* to copy the parameter list. Keep the code around; in case128* we need it again. */129#if 0130# a0: load address131# a2: start address of parameter list132# a3: length of parameter list133# a4: __start134135/* copy the parameter list out of the way */136137movi a6, _param_start138add a3, a2, a31392:140l32i a8, a2, 0141s32i a8, a6, 0142addi a2, a2, 4143addi a6, a6, 4144blt a2, a3, 2b145#endif146147/* clear BSS section */148movi a6, __bss_start149movi a7, __bss_end150movi.n a5, 01513:152s32i a5, a6, 0153addi a6, a6, 4154blt a6, a7, 3b155156movi a5, -16157movi a1, _stack + STACK_SIZE158and a1, a1, a5159160/* Uncompress the kernel */161162# a0: load address163# a2: boot parameter164# a4: __start165166movi a3, __image_load167sub a4, a3, a4168add a8, a0, a4169170# a1 Stack171# a8(a4) Load address of the image172173movi a6, _image_start174movi a10, _image_end175movi a7, 0x1000000176sub a11, a10, a6177movi a9, complen178s32i a11, a9, 0179180movi a0, 0181182# a6 destination183# a7 maximum size of destination184# a8 source185# a9 ptr to length186187.extern gunzip188movi a4, gunzip189beqz a4, 1f190191callx4 a4192193j 2f194195196# a6 destination start197# a7 maximum size of destination198# a8 source start199# a9 ptr to length200# a10 destination end2012021:203l32i a9, a8, 0204l32i a11, a8, 4205s32i a9, a6, 0206s32i a11, a6, 4207l32i a9, a8, 8208l32i a11, a8, 12209s32i a9, a6, 8210s32i a11, a6, 12211addi a6, a6, 16212addi a8, a8, 16213blt a6, a10, 1b214215216/* jump to the kernel */2172:218#if XCHAL_DCACHE_IS_WRITEBACK219220___flush_dcache_all a5 a6221222#endif223224___invalidate_icache_all a5 a6225226isync227228movi a5, __start229movi a3, boot_initrd_start230movi a4, boot_initrd_end231sub a3, a3, a5232sub a4, a4, a5233add a3, a0, a3234add a4, a0, a4235236# a2 Boot parameter list237# a3 initrd_start (virtual load address)238# a4 initrd_end (virtual load address)239240movi a0, _image_start241jx a0242243.align 16244.data245.globl avail_ram246avail_ram:247.long _heap248.globl end_avail249end_avail:250.long _heap + HEAP_SIZE251252.comm _stack, STACK_SIZE253.comm _heap, HEAP_SIZE254255.globl end_avail256.comm complen, 4257258.end literal_prefix259260261