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