testutils.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # MIPS simulator testsuite utility functions.
  2. # Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. # Contributed by Chris Demetriou of Broadcom Corporation.
  4. #
  5. # This file is part of the GNU simulators.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>. */
  19. # $1, $4, $5, %6, are used as temps by the macros defined here.
  20. .macro writemsg msg
  21. la $5, 901f
  22. li $6, 902f - 901f
  23. .data
  24. 901: .ascii "\msg\n"
  25. 902:
  26. .previous
  27. .set push
  28. .set noreorder
  29. jal _dowrite
  30. li $4, 0
  31. .set pop
  32. .endm
  33. # The MIPS simulator uses "break 0x3ff" as the code to exit,
  34. # with the return value in $4 (a0).
  35. .macro exit rc
  36. li $4, \rc
  37. break 0x3ff
  38. .endm
  39. .macro setup
  40. .global _start
  41. .global __start
  42. .ent _start
  43. _start:
  44. __start:
  45. .set push
  46. .set noreorder
  47. j DIAG
  48. nop
  49. .set pop
  50. .end _start
  51. .global _fail
  52. .ent _fail
  53. _fail:
  54. writemsg "fail"
  55. exit 1
  56. .end _fail
  57. .global _pass
  58. .ent _pass
  59. _pass:
  60. writemsg "pass"
  61. exit 0
  62. .end _pass
  63. # The MIPS simulator can use multiple different monitor types,
  64. # so we hard-code the simulator "write" reserved instruction opcode,
  65. # rather than jumping to a vector that invokes it. The operation
  66. # expects RA to point to the location at which to continue
  67. # after writing.
  68. .global _dowrite
  69. .ent _dowrite
  70. _dowrite:
  71. # Write opcode (reserved instruction). See sim_monitor and its
  72. # callers in sim/mips/interp.c.
  73. .word 0x00000039 | ((8 << 1) << 6)
  74. .end _dowrite
  75. .endm # setup
  76. .macro pass
  77. .set push
  78. .set noreorder
  79. j _pass
  80. nop
  81. .set pop
  82. .endm
  83. .macro fail
  84. .set push
  85. .set noreorder
  86. j _fail
  87. nop
  88. .set pop
  89. .endm
  90. .macro load32 reg, val
  91. li \reg, \val
  92. .endm
  93. .macro load64 reg, val
  94. dli \reg, \val
  95. .endm
  96. .macro loadaddr reg, addr
  97. la \reg, \addr
  98. .endm
  99. .macro checkreg reg, expreg
  100. .set push
  101. .set noat
  102. .set noreorder
  103. beq \expreg, \reg, 901f
  104. nop
  105. fail
  106. 901:
  107. .set pop
  108. .endm
  109. .macro check32 reg, val
  110. .set push
  111. .set noat
  112. load32 $1, \val
  113. checkreg \reg, $1
  114. .set pop
  115. .endm
  116. .macro check64 reg, val
  117. .set push
  118. .set noat
  119. load64 $1, \val
  120. checkreg \reg, $1
  121. .set pop
  122. .endm
  123. # Check hi-lo register pair against data stored at base+o1 and base+o2
  124. # Clobbers $1 - $5
  125. .macro checkpair lo, hi, base, w, o1, o2
  126. move $2, \lo
  127. move $3, \hi
  128. .set noat
  129. la $1, \base
  130. l\w $4, \o1($1)
  131. l\w $5, \o2($1)
  132. .set at
  133. checkreg $2, $4
  134. checkreg $3, $5
  135. .endm
  136. .macro checkpair_le_d lo, hi, base
  137. checkpair \lo, \hi, \base, w, 0, 4
  138. .endm
  139. .macro checkpair_be_d lo, hi, base
  140. checkpair \lo, \hi, \base, w, 4, 0
  141. .endm
  142. .macro checkpair_le_q lo, hi, base
  143. checkpair \lo, \hi, \base, d, 0, 8
  144. .endm
  145. .macro checkpair_be_q lo, hi, base
  146. checkpair \lo, \hi, \base, d, 8, 0
  147. .endm
  148. # Endian-ness for comparison is determined by reading a word at ec
  149. .macro checkpair_xendian lo, hi, base, ec, w
  150. .set noat
  151. lw $1, \ec
  152. andi $1, $1, 0x1
  153. # check endianess
  154. beqz $1, 2f
  155. .set at
  156. 1: # big endian
  157. checkpair_be_\w \lo, \hi, \base
  158. b 3f
  159. 2: # little endian
  160. checkpair_le_\w \lo, \hi, \base
  161. 3:
  162. .endm
  163. .macro checkpair_qword lo, hi, base, oe
  164. checkpair_xendian \lo, \hi, \base, \oe, q
  165. .endm
  166. .macro checkpair_dword lo, hi, base, oe
  167. checkpair_xendian \lo, \hi, \base, \oe, d
  168. .endm