Path: blob/master/arch/tile/kernel/relocate_kernel.S
10818 views
/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*13* copy new kernel into place and then call hv_reexec14*15*/1617#include <linux/linkage.h>18#include <arch/chip.h>19#include <asm/page.h>20#include <hv/hypervisor.h>2122#define ___hvb MEM_SV_INTRPT + HV_GLUE_START_CPA2324#define ___hv_dispatch(f) (___hvb + (HV_DISPATCH_ENTRY_SIZE * f))2526#define ___hv_console_putc ___hv_dispatch(HV_DISPATCH_CONSOLE_PUTC)27#define ___hv_halt ___hv_dispatch(HV_DISPATCH_HALT)28#define ___hv_reexec ___hv_dispatch(HV_DISPATCH_REEXEC)29#define ___hv_flush_remote ___hv_dispatch(HV_DISPATCH_FLUSH_REMOTE)3031#undef RELOCATE_NEW_KERNEL_VERBOSE3233STD_ENTRY(relocate_new_kernel)3435move r30, r0 /* page list */36move r31, r1 /* address of page we are on */37move r32, r2 /* start address of new kernel */3839shri r1, r1, PAGE_SHIFT40addi r1, r1, 141shli sp, r1, PAGE_SHIFT42addi sp, sp, -843/* we now have a stack (whether we need one or not) */4445moveli r40, lo16(___hv_console_putc)46auli r40, r40, ha16(___hv_console_putc)4748#ifdef RELOCATE_NEW_KERNEL_VERBOSE49moveli r0, 'r'50jalr r405152moveli r0, '_'53jalr r405455moveli r0, 'n'56jalr r405758moveli r0, '_'59jalr r406061moveli r0, 'k'62jalr r406364moveli r0, '\n'65jalr r4066#endif6768/*69* Throughout this code r30 is pointer to the element of page70* list we are working on.71*72* Normally we get to the next element of the page list by73* incrementing r30 by four. The exception is if the element74* on the page list is an IND_INDIRECTION in which case we use75* the element with the low bits masked off as the new value76* of r30.77*78* To get this started, we need the value passed to us (which79* will always be an IND_INDIRECTION) in memory somewhere with80* r30 pointing at it. To do that, we push the value passed81* to us on the stack and make r30 point to it.82*/8384sw sp, r3085move r30, sp86addi sp, sp, -88788#if CHIP_HAS_CBOX_HOME_MAP()89/*90* On TILEPro, we need to flush all tiles' caches, since we may91* have been doing hash-for-home caching there. Note that we92* must do this _after_ we're completely done modifying any memory93* other than our output buffer (which we know is locally cached).94* We want the caches to be fully clean when we do the reexec,95* because the hypervisor is going to do this flush again at that96* point, and we don't want that second flush to overwrite any memory.97*/98{99move r0, zero /* cache_pa */100move r1, zero101}102{103auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */104movei r3, -1 /* cache_cpumask; -1 means all client tiles */105}106{107move r4, zero /* tlb_va */108move r5, zero /* tlb_length */109}110{111move r6, zero /* tlb_pgsize */112move r7, zero /* tlb_cpumask */113}114{115move r8, zero /* asids */116moveli r20, lo16(___hv_flush_remote)117}118{119move r9, zero /* asidcount */120auli r20, r20, ha16(___hv_flush_remote)121}122123jalr r20124#endif125126/* r33 is destination pointer, default to zero */127128moveli r33, 0129130.Lloop: lw r10, r30131132andi r9, r10, 0xf /* low 4 bits tell us what type it is */133xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */134135seqi r0, r9, 0x1 /* IND_DESTINATION */136bzt r0, .Ltry2137138move r33, r10139140#ifdef RELOCATE_NEW_KERNEL_VERBOSE141moveli r0, 'd'142jalr r40143#endif144145addi r30, r30, 4146j .Lloop147148.Ltry2:149seqi r0, r9, 0x2 /* IND_INDIRECTION */150bzt r0, .Ltry4151152move r30, r10153154#ifdef RELOCATE_NEW_KERNEL_VERBOSE155moveli r0, 'i'156jalr r40157#endif158159j .Lloop160161.Ltry4:162seqi r0, r9, 0x4 /* IND_DONE */163bzt r0, .Ltry8164165mf166167#ifdef RELOCATE_NEW_KERNEL_VERBOSE168moveli r0, 'D'169jalr r40170moveli r0, '\n'171jalr r40172#endif173174move r0, r32175moveli r1, 0 /* arg to hv_reexec is 64 bits */176177moveli r41, lo16(___hv_reexec)178auli r41, r41, ha16(___hv_reexec)179180jalr r41181182/* we should not get here */183184moveli r0, '?'185jalr r40186moveli r0, '\n'187jalr r40188189j .Lhalt190191.Ltry8: seqi r0, r9, 0x8 /* IND_SOURCE */192bz r0, .Lerr /* unknown type */193194/* copy page at r10 to page at r33 */195196move r11, r33197198moveli r0, lo16(PAGE_SIZE)199auli r0, r0, ha16(PAGE_SIZE)200add r33, r33, r0201202/* copy word at r10 to word at r11 until r11 equals r33 */203204/* We know page size must be multiple of 16, so we can unroll205* 16 times safely without any edge case checking.206*207* Issue a flush of the destination every 16 words to avoid208* incoherence when starting the new kernel. (Now this is209* just good paranoia because the hv_reexec call will also210* take care of this.)211*/2122131:214{ lw r0, r10; addi r10, r10, 4 }215{ sw r11, r0; addi r11, r11, 4 }216{ lw r0, r10; addi r10, r10, 4 }217{ sw r11, r0; addi r11, r11, 4 }218{ lw r0, r10; addi r10, r10, 4 }219{ sw r11, r0; addi r11, r11, 4 }220{ lw r0, r10; addi r10, r10, 4 }221{ sw r11, r0; addi r11, r11, 4 }222{ lw r0, r10; addi r10, r10, 4 }223{ sw r11, r0; addi r11, r11, 4 }224{ lw r0, r10; addi r10, r10, 4 }225{ sw r11, r0; addi r11, r11, 4 }226{ lw r0, r10; addi r10, r10, 4 }227{ sw r11, r0; addi r11, r11, 4 }228{ lw r0, r10; addi r10, r10, 4 }229{ sw r11, r0; addi r11, r11, 4 }230{ lw r0, r10; addi r10, r10, 4 }231{ sw r11, r0; addi r11, r11, 4 }232{ lw r0, r10; addi r10, r10, 4 }233{ sw r11, r0; addi r11, r11, 4 }234{ lw r0, r10; addi r10, r10, 4 }235{ sw r11, r0; addi r11, r11, 4 }236{ lw r0, r10; addi r10, r10, 4 }237{ sw r11, r0; addi r11, r11, 4 }238{ lw r0, r10; addi r10, r10, 4 }239{ sw r11, r0; addi r11, r11, 4 }240{ lw r0, r10; addi r10, r10, 4 }241{ sw r11, r0; addi r11, r11, 4 }242{ lw r0, r10; addi r10, r10, 4 }243{ sw r11, r0; addi r11, r11, 4 }244{ lw r0, r10; addi r10, r10, 4 }245{ sw r11, r0 }246{ flush r11 ; addi r11, r11, 4 }247248seq r0, r33, r11249bzt r0, 1b250251#ifdef RELOCATE_NEW_KERNEL_VERBOSE252moveli r0, 's'253jalr r40254#endif255256addi r30, r30, 4257j .Lloop258259260.Lerr: moveli r0, 'e'261jalr r40262moveli r0, 'r'263jalr r40264moveli r0, 'r'265jalr r40266moveli r0, '\n'267jalr r40268.Lhalt:269moveli r41, lo16(___hv_halt)270auli r41, r41, ha16(___hv_halt)271272jalr r41273STD_ENDPROC(relocate_new_kernel)274275.section .rodata,"a"276277.globl relocate_new_kernel_size278relocate_new_kernel_size:279.long .Lend_relocate_new_kernel - relocate_new_kernel280281282