Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 2005 Thiemo Seufer
0007  * Copyright (C) 2005  MIPS Technologies, Inc.  All rights reserved.
0008  *  Author: Maciej W. Rozycki <macro@mips.com>
0009  */
0010 
0011 
0012 #include <asm/addrspace.h>
0013 #include <asm/bug.h>
0014 #include <asm/cacheflush.h>
0015 
0016 #ifndef CKSEG2
0017 #define CKSEG2 CKSSEG
0018 #endif
0019 #ifndef TO_PHYS_MASK
0020 #define TO_PHYS_MASK -1
0021 #endif
0022 
0023 /*
0024  * FUNC is executed in one of the uncached segments, depending on its
0025  * original address as follows:
0026  *
0027  * 1. If the original address is in CKSEG0 or CKSEG1, then the uncached
0028  *    segment used is CKSEG1.
0029  * 2. If the original address is in XKPHYS, then the uncached segment
0030  *    used is XKPHYS(2).
0031  * 3. Otherwise it's a bug.
0032  *
0033  * The same remapping is done with the stack pointer.  Stack handling
0034  * works because we don't handle stack arguments or more complex return
0035  * values, so we can avoid sharing the same stack area between a cached
0036  * and the uncached mode.
0037  */
0038 unsigned long run_uncached(void *func)
0039 {
0040     register long ret __asm__("$2");
0041     long lfunc = (long)func, ufunc;
0042     long usp;
0043     long sp;
0044 
0045     __asm__("move %0, $sp" : "=r" (sp));
0046 
0047     if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
0048         usp = CKSEG1ADDR(sp);
0049 #ifdef CONFIG_64BIT
0050     else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0) &&
0051          (long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))
0052         usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
0053                      XKPHYS_TO_PHYS((long long)sp));
0054 #endif
0055     else {
0056         BUG();
0057         usp = sp;
0058     }
0059     if (lfunc >= (long)CKSEG0 && lfunc < (long)CKSEG2)
0060         ufunc = CKSEG1ADDR(lfunc);
0061 #ifdef CONFIG_64BIT
0062     else if ((long long)lfunc >= (long long)PHYS_TO_XKPHYS(0, 0) &&
0063          (long long)lfunc < (long long)PHYS_TO_XKPHYS(8, 0))
0064         ufunc = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
0065                        XKPHYS_TO_PHYS((long long)lfunc));
0066 #endif
0067     else {
0068         BUG();
0069         ufunc = lfunc;
0070     }
0071 
0072     __asm__ __volatile__ (
0073         "   move    $16, $sp\n"
0074         "   move    $sp, %1\n"
0075         "   jalr    %2\n"
0076         "   move    $sp, $16"
0077         : "=r" (ret)
0078         : "r" (usp), "r" (ufunc)
0079         : "$16", "$31");
0080 
0081     return ret;
0082 }