/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2005 Thiemo Seufer6* Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.7* Author: Maciej W. Rozycki <[email protected]>8*/91011#include <asm/addrspace.h>12#include <asm/bug.h>13#include <asm/cacheflush.h>1415#ifndef CKSEG216#define CKSEG2 CKSSEG17#endif18#ifndef TO_PHYS_MASK19#define TO_PHYS_MASK -120#endif2122/*23* FUNC is executed in one of the uncached segments, depending on its24* original address as follows:25*26* 1. If the original address is in CKSEG0 or CKSEG1, then the uncached27* segment used is CKSEG1.28* 2. If the original address is in XKPHYS, then the uncached segment29* used is XKPHYS(2).30* 3. Otherwise it's a bug.31*32* The same remapping is done with the stack pointer. Stack handling33* works because we don't handle stack arguments or more complex return34* values, so we can avoid sharing the same stack area between a cached35* and the uncached mode.36*/37unsigned long run_uncached(void *func)38{39register long ret __asm__("$2");40long lfunc = (long)func, ufunc;41long usp;42long sp;4344__asm__("move %0, $sp" : "=r" (sp));4546if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)47usp = CKSEG1ADDR(sp);48#ifdef CONFIG_64BIT49else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0) &&50(long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))51usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,52XKPHYS_TO_PHYS((long long)sp));53#endif54else {55BUG();56usp = sp;57}58if (lfunc >= (long)CKSEG0 && lfunc < (long)CKSEG2)59ufunc = CKSEG1ADDR(lfunc);60#ifdef CONFIG_64BIT61else if ((long long)lfunc >= (long long)PHYS_TO_XKPHYS(0, 0) &&62(long long)lfunc < (long long)PHYS_TO_XKPHYS(8, 0))63ufunc = PHYS_TO_XKPHYS(K_CALG_UNCACHED,64XKPHYS_TO_PHYS((long long)lfunc));65#endif66else {67BUG();68ufunc = lfunc;69}7071__asm__ __volatile__ (72" move $16, $sp\n"73" move $sp, %1\n"74" jalr %2\n"75" move $sp, $16"76: "=r" (ret)77: "r" (usp), "r" (ufunc)78: "$16", "$31");7980return ret;81}828384