fpu_asm.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2015, Cyril Bur, IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include "basic_asm.h"
  10. #include "fpu_asm.h"
  11. FUNC_START(check_fpu)
  12. mr r4,r3
  13. li r3,1 # assume a bad result
  14. lfd f0,0(r4)
  15. fcmpu cr1,f0,f14
  16. bne cr1,1f
  17. lfd f0,8(r4)
  18. fcmpu cr1,f0,f15
  19. bne cr1,1f
  20. lfd f0,16(r4)
  21. fcmpu cr1,f0,f16
  22. bne cr1,1f
  23. lfd f0,24(r4)
  24. fcmpu cr1,f0,f17
  25. bne cr1,1f
  26. lfd f0,32(r4)
  27. fcmpu cr1,f0,f18
  28. bne cr1,1f
  29. lfd f0,40(r4)
  30. fcmpu cr1,f0,f19
  31. bne cr1,1f
  32. lfd f0,48(r4)
  33. fcmpu cr1,f0,f20
  34. bne cr1,1f
  35. lfd f0,56(r4)
  36. fcmpu cr1,f0,f21
  37. bne cr1,1f
  38. lfd f0,64(r4)
  39. fcmpu cr1,f0,f22
  40. bne cr1,1f
  41. lfd f0,72(r4)
  42. fcmpu cr1,f0,f23
  43. bne cr1,1f
  44. lfd f0,80(r4)
  45. fcmpu cr1,f0,f24
  46. bne cr1,1f
  47. lfd f0,88(r4)
  48. fcmpu cr1,f0,f25
  49. bne cr1,1f
  50. lfd f0,96(r4)
  51. fcmpu cr1,f0,f26
  52. bne cr1,1f
  53. lfd f0,104(r4)
  54. fcmpu cr1,f0,f27
  55. bne cr1,1f
  56. lfd f0,112(r4)
  57. fcmpu cr1,f0,f28
  58. bne cr1,1f
  59. lfd f0,120(r4)
  60. fcmpu cr1,f0,f29
  61. bne cr1,1f
  62. lfd f0,128(r4)
  63. fcmpu cr1,f0,f30
  64. bne cr1,1f
  65. lfd f0,136(r4)
  66. fcmpu cr1,f0,f31
  67. bne cr1,1f
  68. li r3,0 # Success!!!
  69. 1: blr
  70. FUNC_START(test_fpu)
  71. # r3 holds pointer to where to put the result of fork
  72. # r4 holds pointer to the pid
  73. # f14-f31 are non volatiles
  74. PUSH_BASIC_STACK(256)
  75. PUSH_FPU(256)
  76. std r3,STACK_FRAME_PARAM(0)(sp) # Address of darray
  77. std r4,STACK_FRAME_PARAM(1)(sp) # Address of pid
  78. bl load_fpu
  79. nop
  80. li r0,__NR_fork
  81. sc
  82. # pass the result of the fork to the caller
  83. ld r9,STACK_FRAME_PARAM(1)(sp)
  84. std r3,0(r9)
  85. ld r3,STACK_FRAME_PARAM(0)(sp)
  86. bl check_fpu
  87. nop
  88. POP_FPU(256)
  89. POP_BASIC_STACK(256)
  90. blr
  91. FUNC_END(test_fpu)
  92. # int preempt_fpu(double *darray, int *threads_running, int *running)
  93. # On starting will (atomically) decrement not_ready as a signal that the FPU
  94. # has been loaded with darray. Will proceed to check the validity of the FPU
  95. # registers while running is not zero.
  96. FUNC_START(preempt_fpu)
  97. PUSH_BASIC_STACK(256)
  98. PUSH_FPU(256)
  99. std r3,STACK_FRAME_PARAM(0)(sp) # double *darray
  100. std r4,STACK_FRAME_PARAM(1)(sp) # int *threads_starting
  101. std r5,STACK_FRAME_PARAM(2)(sp) # int *running
  102. bl load_fpu
  103. nop
  104. sync
  105. # Atomic DEC
  106. ld r3,STACK_FRAME_PARAM(1)(sp)
  107. 1: lwarx r4,0,r3
  108. addi r4,r4,-1
  109. stwcx. r4,0,r3
  110. bne- 1b
  111. 2: ld r3,STACK_FRAME_PARAM(0)(sp)
  112. bl check_fpu
  113. nop
  114. cmpdi r3,0
  115. bne 3f
  116. ld r4,STACK_FRAME_PARAM(2)(sp)
  117. ld r5,0(r4)
  118. cmpwi r5,0
  119. bne 2b
  120. 3: POP_FPU(256)
  121. POP_BASIC_STACK(256)
  122. blr
  123. FUNC_END(preempt_fpu)