uncached.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2005 Thiemo Seufer
  7. * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
  8. * Author: Maciej W. Rozycki <macro@mips.com>
  9. */
  10. #include <asm/addrspace.h>
  11. #include <asm/bug.h>
  12. #include <asm/cacheflush.h>
  13. #ifndef CKSEG2
  14. #define CKSEG2 CKSSEG
  15. #endif
  16. #ifndef TO_PHYS_MASK
  17. #define TO_PHYS_MASK -1
  18. #endif
  19. /*
  20. * FUNC is executed in one of the uncached segments, depending on its
  21. * original address as follows:
  22. *
  23. * 1. If the original address is in CKSEG0 or CKSEG1, then the uncached
  24. * segment used is CKSEG1.
  25. * 2. If the original address is in XKPHYS, then the uncached segment
  26. * used is XKPHYS(2).
  27. * 3. Otherwise it's a bug.
  28. *
  29. * The same remapping is done with the stack pointer. Stack handling
  30. * works because we don't handle stack arguments or more complex return
  31. * values, so we can avoid sharing the same stack area between a cached
  32. * and the uncached mode.
  33. */
  34. unsigned long run_uncached(void *func)
  35. {
  36. register long sp __asm__("$sp");
  37. register long ret __asm__("$2");
  38. long lfunc = (long)func, ufunc;
  39. long usp;
  40. if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
  41. usp = CKSEG1ADDR(sp);
  42. #ifdef CONFIG_64BIT
  43. else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0) &&
  44. (long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))
  45. usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
  46. XKPHYS_TO_PHYS((long long)sp));
  47. #endif
  48. else {
  49. BUG();
  50. usp = sp;
  51. }
  52. if (lfunc >= (long)CKSEG0 && lfunc < (long)CKSEG2)
  53. ufunc = CKSEG1ADDR(lfunc);
  54. #ifdef CONFIG_64BIT
  55. else if ((long long)lfunc >= (long long)PHYS_TO_XKPHYS(0, 0) &&
  56. (long long)lfunc < (long long)PHYS_TO_XKPHYS(8, 0))
  57. ufunc = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
  58. XKPHYS_TO_PHYS((long long)lfunc));
  59. #endif
  60. else {
  61. BUG();
  62. ufunc = lfunc;
  63. }
  64. __asm__ __volatile__ (
  65. " move $16, $sp\n"
  66. " move $sp, %1\n"
  67. " jalr %2\n"
  68. " move $sp, $16"
  69. : "=r" (ret)
  70. : "r" (usp), "r" (ufunc)
  71. : "$16", "$31");
  72. return ret;
  73. }