ofwcall32.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*-
  2. * Copyright (C) 2009-2011 Nathan Whitehorn
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  22. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  23. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * $FreeBSD$
  26. */
  27. #include <sys/syscall.h>
  28. #include <machine/trap.h>
  29. #include <machine/param.h>
  30. #include <machine/spr.h>
  31. #include <machine/asm.h>
  32. #define OFWSTKSZ 4096 /* 4K Open Firmware stack */
  33. /*
  34. * Globals
  35. */
  36. .data
  37. GLOBAL(ofmsr)
  38. .long 0, 0, 0, 0, 0 /* msr/sprg0-3 used in Open Firmware */
  39. GLOBAL(rtasmsr)
  40. .long 0
  41. GLOBAL(openfirmware_entry)
  42. .long 0 /* Open Firmware entry point */
  43. GLOBAL(rtas_entry)
  44. .long 0 /* RTAS entry point */
  45. .align 4
  46. ofwstk:
  47. .space OFWSTKSZ
  48. rtas_regsave:
  49. .space 4
  50. /*
  51. * Open Firmware Entry Point. May need to enter real mode.
  52. *
  53. * C prototype: int ofwcall(void *callbuffer);
  54. */
  55. ASENTRY(ofwcall)
  56. mflr %r0
  57. stw %r0,4(%r1)
  58. /* Record the old MSR */
  59. mfmsr %r6
  60. /* GOT pointer in r7 */
  61. bl 1f
  62. 1:
  63. mflr %r7
  64. addis %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@ha
  65. addi %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@l
  66. /* read client interface handler */
  67. lwz %r4,openfirmware_entry@got(%r7)
  68. lwz %r4,0(%r4)
  69. /*
  70. * Set the MSR to the OF value. This has the side effect of disabling
  71. * exceptions, which prevents preemption later.
  72. */
  73. lwz %r5,ofmsr@got(%r7)
  74. lwz %r5,0(%r5)
  75. mtmsr %r5
  76. isync
  77. /*
  78. * Set up OF stack. This needs to be potentially accessible in real mode
  79. * The pointer to the current kernel stack is placed at the very
  80. * top of the stack along with the old MSR so we can get them back
  81. * later.
  82. */
  83. mr %r5,%r1
  84. lwz %r1,ofwstk@got(%r7)
  85. addi %r1,%r1,(OFWSTKSZ-32)
  86. stw %r5,20(%r1) /* Save real stack pointer */
  87. stw %r2,24(%r1) /* Save curthread */
  88. stw %r6,28(%r1) /* Save old MSR */
  89. li %r5,0
  90. stw %r5,4(%r1)
  91. stw %r5,0(%r1)
  92. /* Finally, branch to OF */
  93. mtctr %r4
  94. bctrl
  95. /* Reload stack pointer and MSR from the OFW stack */
  96. lwz %r6,28(%r1)
  97. lwz %r2,24(%r1)
  98. lwz %r1,20(%r1)
  99. /* Now set the real MSR */
  100. mtmsr %r6
  101. isync
  102. /* Return */
  103. lwz %r0,4(%r1)
  104. mtlr %r0
  105. blr
  106. ASEND(ofwcall)
  107. /*
  108. * RTAS Entry Point. Similar to the OF one, but simpler (no separate stack)
  109. *
  110. * C prototype: int rtascall(void *callbuffer, void *rtas_privdat);
  111. */
  112. ASENTRY(rtascall)
  113. mflr %r0
  114. stw %r0,4(%r1)
  115. /* GOT pointer in r7 */
  116. bl 1f
  117. 1:
  118. mflr %r7
  119. addis %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@ha
  120. addi %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@l
  121. /* Record the old MSR to real-mode-accessible area */
  122. mfmsr %r0
  123. lwz %r5,rtas_regsave@got(%r7)
  124. stw %r0,0(%r5)
  125. /* read client interface handler */
  126. lwz %r5,rtas_entry@got(%r7)
  127. lwz %r5,0(%r5)
  128. /* Set the MSR to the RTAS value */
  129. lwz %r6,rtasmsr@got(%r7)
  130. lwz %r6,0(%r6)
  131. mtmsr %r6
  132. isync
  133. /* Branch to RTAS */
  134. mtctr %r5
  135. bctrl
  136. /* GOT pointer in r7 */
  137. bl 1f
  138. 1:
  139. mflr %r7
  140. addis %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@ha
  141. addi %r7,%r7,(_GLOBAL_OFFSET_TABLE_-1b)@l
  142. /* Now set the MSR back */
  143. lwz %r6,rtas_regsave@got(%r7)
  144. lwz %r6,0(%r6)
  145. mtmsr %r6
  146. isync
  147. /* And return */
  148. lwz %r0,4(%r1)
  149. mtlr %r0
  150. blr
  151. ASEND(rtascall)