2 # Some generic MIPS tests
5 # When adding a new test to this file, try to do the following things:
7 # * If testing assembly and disassembly of code, don't forget to test
8 # the actual bit encodings of the instructions (using the
9 # --show-raw-insn flag to objdump).
11 # * Try to run the test for as many architectures as appropriate,
12 # using the "run_dump_test_arches" or "run_list_test_arches" functions,
13 # along with the output from a call to "mips_arch_list_matching."
15 # * Be sure to compare the test output before and after your testsuite
16 # changes, to verify that existing and new tests were run as expected.
17 # Look for expect ERROR messages in the testsuite .log file to make sure
18 # the new expect code did not contain errors.
20 # To add support for a new CPU to this file, add an appropriate entry
21 # to the sequence of "mips_arch_create" function calls below, and test
22 # the result. The new CPU should automatically be used when running
23 # various tests. If the new CPU is the default CPU for any tool
24 # targets, make sure the call to "mips_arch_create" reflects that fact.
27 # "LOSE" marks information about tests which fail at a particular point
28 # in time, but which are not XFAILed. Either they used to pass
29 # and indicate either regressions or the need to tweak the tests to keep
30 # up the with code, or they are new tests and it is unknown whether or not
31 # they should pass as-is for the given object formats.
34 # The functions below create and manipulate an "architecture data
35 # array" which contains entries for each MIPS architecture (or CPU)
36 # known to these tests. The array contains the following information
37 # for each architecture, indexed by the name of the architecture
38 # described by the entry:
40 # displayname: The name of the entry to be used for pretty-printing.
42 # gprsize: The size in bits of General Purpose Registers provided by
43 # the architecture (must be 32 or 64).
45 # props: A list of text strings which are associated with the
46 # architecture. These include the architecture name as well as
47 # information about what instructions the CPU supports. When matching
48 # based on properties, an additional property is added to the normal
49 # property list, "gpr<gprsize>" so that tests can match CPUs which
50 # have GPRs of a specific size. The following properties are most
51 # useful when matching properties for generic (i.e., not CPU-specific)
54 # mips1, mips2, mips3, mips4, mips5, mips32, mips64
55 # The architecture includes the instructions defined
58 # mips3d The architecture includes the MIPS-3D ASE.
60 # ror The architecture includes hardware rotate instructions.
63 # The architecture provides 32- or 64-bit General Purpose
66 # as_flags: The assembler flags used when assembling tests for this
69 # objdump_flags: The objdump flags used when disassembling tests for
72 # Most entries in the architecture array will have values in all of
73 # the fields above. One entry, "default" represents the default CPU
74 # based on the target of the assembler being built. If always has
75 # empty "as_flags" and "objdump_flags."
77 # mips_arch_create ARCH GPRSIZE EXTENDS PROPS AS_FLAGS OBJDUMP_FLAGS \
78 # (optional:) DEFAULT_FOR_TARGETS
80 # This function creates a new entry in the architecture data array,
81 # for the architecture or CPU named ARCH, and fills in the entry
82 # according to the rest of the arguments.
84 # The new entry's property list is initialized to contain ARCH, any
85 # properties specified by PROPS, and the properties associated with
86 # the entry specified by EXTENDS. (The new architecture is considered
87 # to extend the capabilities provided by that architecture.)
89 # If DEFAULT_FOR_TARGETS is specified, it is a list of targets for which
90 # this architecture is the default architecture. If "istarget" returns
91 # true for any of the targets in the list, a "default" entry will be
92 # added to the architecture array which indicates that ARCH is the default
94 proc mips_arch_create {arch gprsize extends props as_flags objdump_flags
95 {default_for_targets {}}} {
98 if { [info exists mips_arches($arch)] } {
99 error "mips_arch_create: arch \"$arch\" already exists"
101 if { $gprsize != 32 && $gprsize != 64 } {
102 error "mips_arch_create: invalid GPR size $gprsize"
105 set archdata(displayname) $arch
106 set archdata(gprsize) $gprsize
107 set archdata(as_flags) $as_flags
108 set archdata(objdump_flags) $objdump_flags
109 set archdata(props) $arch
110 eval lappend archdata(props) $props
111 if { [string length $extends] != 0 } {
112 eval lappend archdata(props) [mips_arch_properties $extends 0]
115 set mips_arches($arch) [array get archdata]
117 # Set as default if appropriate.
118 foreach target $default_for_targets {
119 if { [istarget $target] } {
120 if { [info exists mips_arches(default)] } {
121 error "mips_arch_create: default arch already exists"
124 set archdata(displayname) "default = $arch"
125 set archdata(as_flags) ""
126 set archdata(objdump_flags) ""
128 set mips_arches(default) [array get archdata]
136 # This function returns the list of all names of entries in the
137 # architecture data array (including the default entry, if a default
139 proc mips_arch_list_all {} {
141 return [lsort -dictionary [array names mips_arches]]
144 # mips_arch_data ARCH
146 # This function returns the information associated with ARCH
147 # in the architecture data array, in "array get" form.
148 proc mips_arch_data {arch} {
151 if { ! [info exists mips_arches($arch)] } {
152 error "mips_arch_data: unknown arch \"$arch\""
154 return $mips_arches($arch)
157 # mips_arch_displayname ARCH
159 # This function returns the printable name associated with ARCH in
160 # the architecture data array.
161 proc mips_arch_displayname {arch} {
162 array set archdata [mips_arch_data $arch]
163 return $archdata(displayname)
166 # mips_arch_properties ARCH (optional:) INCLUDE_GPRSIZE
168 # This function returns the property list associated with ARCH in the
169 # architecture data array. If INCLUDE_GPRSIZE is non-zero, an additional
170 # "gpr32" or "gpr64" property will be returned as part of the list based
171 # on the architecture's GPR size.
172 proc mips_arch_properties {arch {include_gprsize 1}} {
173 array set archdata [mips_arch_data $arch]
174 set props $archdata(props)
175 if { $include_gprsize } {
176 lappend props gpr$archdata(gprsize)
181 # mips_arch_as_flags ARCH
183 # This function returns the assembler flags associated with ARCH in
184 # the architecture data array.
185 proc mips_arch_as_flags {arch} {
186 array set archdata [mips_arch_data $arch]
187 return $archdata(as_flags)
190 # mips_arch_objdump_flags ARCH
192 # This function returns the objdump disassembly flags associated with
193 # ARCH in the architecture data array.
194 proc mips_arch_objdump_flags {arch} {
195 array set archdata [mips_arch_data $arch]
196 return $archdata(objdump_flags)
199 # mips_arch_matches ARCH PROPMATCHLIST
201 # This function returns non-zero if ARCH matches the set of properties
202 # described by PROPMATCHLIST. Each entry in PROPMATCHLIST can either
203 # be the name of a property which must be matched, or "!" followed by
204 # the name of a property which must not be matched. ARCH matches
205 # PROPMATCHLIST if and only if all of the conditions specified by
206 # PROPMATCHLIST are satisfied.
207 proc mips_arch_matches {arch propmatchlist} {
208 foreach pm $propmatchlist {
209 if { [string match {!*} $pm] } {
212 set p [string range $pm 1 end]
214 # fail if not present.
219 set loc [lsearch -exact [mips_arch_properties $arch] $p]
221 # required-absent and found, or required-present and not found: fail.
222 if { ($inverted && $loc != -1) || (! $inverted && $loc == -1) } {
229 # mips_arch_list_matching ARGS
231 # This function returns a list of all architectures which match
232 # the conditions described by its arguments. Its arguments are
233 # taken as a list and used as the PROPMATCHLIST in a call to
234 # "mips_arch_matches" for each known architecture.
235 proc mips_arch_list_matching {args} {
237 foreach arch [mips_arch_list_all] {
238 # For now, don't match default arch until we know what its
239 # properties actually are.
240 if { [string compare $arch default] == 0
241 && [string length [mips_arch_properties default]] == 0} {
244 if { [mips_arch_matches $arch $args] } {
252 # The functions below facilitate running various types of tests.
254 # run_dump_test_arch NAME ARCH
256 # Invoke "run_dump_test" for test NAME, with extra assembler and
257 # disassembler flags to test architecture ARCH.
258 proc run_dump_test_arch { name arch } {
261 if [catch {run_dump_test $name \
262 "{name {([mips_arch_displayname $arch])}}
263 {objdump {[mips_arch_objdump_flags $arch]}}
264 {as {[mips_arch_as_flags $arch]}}"} rv] {
266 untested "$subdir/$name ($arch)"
270 # run_dump_test_arches NAME ARCH_LIST
272 # Invoke "run_dump_test_arch" for test NAME, for each architecture
273 # listed in ARCH_LIST.
274 proc run_dump_test_arches { name arch_list } {
275 foreach arch $arch_list {
276 run_dump_test_arch "$name" "$arch"
280 # run_list_test NAME OPTS (optional): TESTNAME
282 # Assemble the file "NAME.d" and compare the assembler standard error
283 # output against the regular expressions given in the file "NAME.l".
284 # The assembler is passed the flags given in OPTS. If TESTNAME is
285 # provided, it will be used as the name of the test.
286 proc run_list_test { name opts {testname {}} } {
288 if { [string length $testname] == 0 } then {
289 set testname "MIPS $name"
291 set file $srcdir/$subdir/$name
292 gas_run ${name}.s $opts ">&dump.out"
293 if { [regexp_diff "dump.out" "${file}.l"] } then {
295 verbose "output is [file_contents "dump.out"]" 2
301 # run_list_test_arch NAME OPTS ARCH
303 # Invoke "run_list_test" for test NAME with options OPTS, with extra
304 # assembler flags to test architecture ARCH.
305 proc run_list_test_arch { name opts arch } {
308 set testname "MIPS $name ([mips_arch_displayname $arch])"
309 if [catch {run_list_test "$name" "$opts [mips_arch_as_flags $arch]" \
316 # run_list_test_arches NAME OPTS ARCH_LIST
318 # Invoke "run_list_test_arch" for test NAME with options OPTS, for each
319 # architecture listed in ARCH_LIST.
320 proc run_list_test_arches { name opts arch_list } {
321 foreach arch $arch_list {
322 run_list_test_arch "$name" "$opts" "$arch"
327 # Create the architecture data array by providing data for all
328 # known architectures.
330 # Note that several targets pick default CPU based on ABI. We
331 # can't easily handle that; do NOT list those targets as defaulting
332 # to any architecture.
333 mips_arch_create mips1 32 {} {} \
334 { -march=mips1 -mtune=mips1 } { -mmips:3000 }
335 mips_arch_create mips2 32 mips1 {} \
336 { -march=mips2 -mtune=mips2 } { -mmips:6000 }
337 mips_arch_create mips3 64 mips2 {} \
338 { -march=mips3 -mtune=mips3 } { -mmips:4000 }
339 mips_arch_create mips4 64 mips3 {} \
340 { -march=mips4 -mtune=mips4 } { -mmips:8000 }
341 mips_arch_create mips5 64 mips4 {} \
342 { -march=mips5 -mtune=mips5 } { -mmips:mips5 }
343 mips_arch_create mips32 32 mips2 {} \
344 { -march=mips32 -mtune=mips32 } { -mmips:isa32 } \
345 { mipsisa32-*-* mipsisa32el-*-* }
346 mips_arch_create mips32r2 32 mips32 { ror } \
347 { -march=mips32r2 -mtune=mips32r2 } \
349 { mipsisa32r2-*-* mipsisa32r2el-*-* }
350 mips_arch_create mips64 64 mips5 { mips32 } \
351 { -march=mips64 -mtune=mips64 } { -mmips:isa64 } \
352 { mipsisa64-*-* mipsisa64el-*-* }
353 mips_arch_create r3000 32 mips1 {} \
354 { -march=r3000 -mtune=r3000 } { -mmips:3000 }
355 mips_arch_create r3900 32 mips1 {} \
356 { -march=r3900 -mtune=r3900 } { -mmips:3900 } \
357 { mipstx39-*-* mipstx39el-*-* }
358 mips_arch_create r4000 64 mips3 {} \
359 { -march=r4000 -mtune=r4000 } { -mmips:4000 }
360 mips_arch_create vr5400 64 mips4 { ror } \
361 { -march=vr5400 -mtune=vr5400 } { -mmips:5400 }
362 mips_arch_create sb1 64 mips64 { mips3d } \
363 { -march=sb1 -mtune=sb1 } { -mmips:sb1 } \
364 { mipsisa64sb1-*-* mipsisa64sb1el-*-* }
368 # And now begin the actual tests!
371 if { [istarget mips*-*-*] } then {
373 set elf [expr [istarget *-*-elf*] || [istarget *-*-irix5*] || [istarget *-*-irix6* ] || [istarget *-*-linux*] || [istarget *-*-netbsd*] ]
374 set ecoff [expr [istarget *-*-ecoff*] || [istarget *-*-ultrix*] || [istarget *-*-irix\[1-4\]*] ]
375 set aout [expr [istarget *-*-bsd*] || [istarget *-*-openbsd*] ]
376 set ilocks [istarget mipstx39*-*-*]
377 set gpr_ilocks [expr [istarget mipstx39*-*-*]]
378 set addr32 [expr [istarget mipstx39*-*-*]]
379 set has_newabi [expr [istarget *-*-irix6*] || [istarget mips64*-*-linux*]]
381 if { [istarget "mips*-*-*linux*"] } then {
386 if [istarget mips*el-*-*] {
392 run_dump_test_arches "abs" [mips_arch_list_matching mips1]
393 run_dump_test_arches "add" [mips_arch_list_matching mips1]
394 run_dump_test_arches "and" [mips_arch_list_matching mips1]
395 run_dump_test "break20"
396 run_dump_test "trap20"
398 # LOSE: As of 2002-02-08, "beq" through "bltu" fail for target mips-ecoff.
399 # See http://sources.redhat.com/ml/binutils/2001-10/msg00418.html for
400 # more information. Not sure if the fixes there are correct; should
401 # branches to external labels be allowed for ECOFF?
402 # XXX FIXME: the following tests require -mips2 disasm for
403 # branch-likely instructions. They should be split.
404 run_dump_test_arches "beq" [mips_arch_list_matching mips2]
405 run_dump_test_arches "bge" [mips_arch_list_matching mips2]
406 run_dump_test_arches "bgeu" [mips_arch_list_matching mips2]
407 run_dump_test_arches "blt" [mips_arch_list_matching mips2]
408 run_dump_test_arches "bltu" [mips_arch_list_matching mips2]
409 run_dump_test_arches "branch-misc-1" [mips_arch_list_matching mips1]
410 run_list_test_arches "branch-misc-2" "" [mips_arch_list_matching mips1]
413 run_dump_test "div-ilocks"
417 run_dump_test_arches "dli" [mips_arch_list_matching mips3]
419 run_dump_test_arches "elf-jal" [mips_arch_list_matching mips1]
423 if $elf { run_dump_test "jal-svr4pic" }
424 if $elf { run_dump_test "jal-xgot" }
425 # LOSE: As of 2002-02-08, the jal-empic test fails for target mips-ecoff.
426 # It appears that it broke between 2000-03-11 00:00UTC and
427 # 2000-03-12 00:00 UTC.
428 if $ecoff { run_dump_test "jal-empic" }
430 run_dump_test_arches "jal-empic-elf" [mips_arch_list_matching mips1]
431 run_dump_test_arches "jal-empic-elf-2" [mips_arch_list_matching mips1]
432 run_dump_test_arches "jal-empic-elf-3" [mips_arch_list_matching mips1]
434 run_list_test_arches "jal-range" "" [mips_arch_list_matching mips1]
435 if !$aout { run_dump_test "la" }
436 if $elf { run_dump_test "la-svr4pic" }
437 if $elf { run_dump_test "la-xgot" }
438 # LOSE: As of 2002-02-08, the la-empic test fails for target mips-ecoff.
439 # Not sure when it first cropped up, but may be related to addition of
440 # "la" -> "addiu" pattern in MIPS opcode table long ago.
441 if $ecoff { run_dump_test "la-empic" }
443 # XXX FIXME: Has mips2 and later insns with mips1 disassemblies.
444 # (Should split and then use appropriate arch lists.)
445 run_dump_test_arches "lb" [mips_arch_list_matching !mips2]
448 run_dump_test_arches "lb-svr4pic" [mips_arch_list_matching mips1]
451 # Both versions specify the cpu, so we can run both regardless of
452 # the interlocking in the configured default cpu.
453 run_dump_test "lb-xgot"
454 run_dump_test "lb-xgot-ilocks"
456 if $ecoff { run_dump_test "lb-empic" }
462 run_dump_test "ld-ilocks"
464 run_dump_test "ld-ilocks-addr32"
468 if $elf { run_dump_test "ld-svr4pic" }
469 if $elf { run_dump_test "ld-xgot" }
470 if $ecoff { run_dump_test "ld-empic" }
471 run_dump_test_arches "li" [mips_arch_list_matching mips1]
472 if !$aout { run_dump_test "lifloat" }
473 if $elf { run_dump_test "lif-svr4pic" }
474 if $elf { run_dump_test "lif-xgot" }
475 # LOSE: As of 2002-02-08, the lif-empic test fails for target mips-ecoff.
476 # It appears that it broke between 2000-03-11 00:00UTC and
477 # 2000-03-12 00:00 UTC.
478 if $ecoff { run_dump_test "lif-empic" }
479 run_dump_test_arches "mips4" [mips_arch_list_matching mips4]
481 run_dump_test "mul-ilocks"
486 run_dump_test_arches "rol" [mips_arch_list_matching !ror]
487 run_dump_test_arches "rol-hw" [mips_arch_list_matching ror]
489 run_dump_test_arches "rol64" [mips_arch_list_matching gpr64 !ror]
490 run_dump_test_arches "rol64-hw" [mips_arch_list_matching gpr64 ror]
492 if !$aout { run_dump_test "sb" }
493 run_dump_test "trunc"
494 if !$aout { run_dump_test "ulh" }
495 if $elf { run_dump_test "ulh-svr4pic" }
496 if $elf { run_dump_test "ulh-xgot" }
497 if $ecoff { run_dump_test "ulh-empic" }
505 # The mips16 test can only be run on ELF, because only ELF
506 # supports the necessary mips16 reloc.
507 if { $elf && !$no_mips16 } {
508 run_dump_test "mips16"
509 # Check jalx handling
510 run_dump_test "mips16-jalx"
511 run_dump_test "mips-jalx"
513 run_list_test "mips-no-jalx" ""
514 run_dump_test "delay"
515 run_dump_test "nodelay"
516 run_dump_test "mips4010"
517 run_dump_test "mips4650"
518 run_dump_test "mips4100"
519 run_dump_test "vr4111"
520 run_dump_test "vr4120"
521 run_dump_test "vr4122"
522 run_dump_test "vr5400"
523 run_dump_test "vr5500"
524 run_dump_test "perfcount"
525 run_dump_test "lineno"
528 run_dump_test_arches "mips32" [mips_arch_list_matching mips32]
530 run_dump_test_arches "mips32r2" [mips_arch_list_matching mips32r2]
531 run_list_test_arches "mips32r2-ill" "" [mips_arch_list_matching mips32r2]
533 run_dump_test_arches "mips64" [mips_arch_list_matching mips64]
535 run_dump_test "mips64-mips3d"
536 run_dump_test_arches "mips64-mips3d-incl" [mips_arch_list_matching mips3d]
538 run_dump_test "mips64-mdmx"
539 run_dump_test "sb1-ext-mdmx"
540 run_dump_test "sb1-ext-ps"
542 run_dump_test "relax"
544 run_list_test "illegal" ""
545 run_list_test "baddata1" ""
547 # LOSE: As of 2002-02-08, the next 4 tests fail for target mips-ecoff.
548 # It's unknown whether they _should_ pass as-is, or whether different
549 # variants are needed for ELF and ECOFF.
550 run_dump_test "mips-gp32-fp32"
551 run_dump_test "mips-gp32-fp64"
552 run_dump_test "mips-gp64-fp32"
553 run_dump_test "mips-gp64-fp64"
556 # Make sure that -mcpu=FOO and -mFOO are equivalent. Assemble a file
557 # containing 4650-specific instructions with -m4650 and -mcpu=4650,
558 # and verify that they're the same. Specifically, we're checking
559 # that the EF_MIPS_MACH field is set, and that the 4650 'mul'
560 # instruction does get used. In previous versions of GAS,
561 # only -mcpu=4650 would set the EF_MIPS_MACH field; -m4650 wouldn't.
562 run_dump_test "elf_e_flags1"
563 run_dump_test "elf_e_flags2"
564 run_dump_test "elf_e_flags3"
565 run_dump_test "elf_e_flags4"
567 # Check EF_MIPS_ARCH markings for each supported architecture.
568 run_dump_test "elf_arch_mips1"
569 run_dump_test "elf_arch_mips2"
570 run_dump_test "elf_arch_mips3"
571 run_dump_test "elf_arch_mips4"
572 run_dump_test "elf_arch_mips5"
573 run_dump_test "elf_arch_mips32"
574 run_dump_test "elf_arch_mips32r2"
575 run_dump_test "elf_arch_mips64"
577 # Verify that ASE markings are handled properly.
578 if { !$no_mips16 } { run_dump_test "elf_ase_mips16" }
580 run_dump_test "mips-gp32-fp32-pic"
581 run_dump_test "mips-gp32-fp64-pic"
582 run_dump_test "mips-gp64-fp32-pic"
583 run_dump_test "mips-gp64-fp64-pic"
585 run_dump_test "mips-abi32"
586 run_dump_test "mips-abi32-pic"
587 run_dump_test "mips-abi32-pic2"
589 run_dump_test "elf${el}-rel"
590 if {[istarget mips64*-*-*] || [istarget mipsisa32*-*-*]
591 || [istarget mipsisa64*-*-*]} {
592 run_dump_test "elf${el}-rel2"
594 run_dump_test "e32${el}-rel2"
596 run_dump_test "elf${el}-rel3"
597 if {[istarget mips64*-*-*]} {
598 run_dump_test "elf-rel4"
600 run_dump_test "e32-rel4"
602 run_dump_test "elf-rel5"
603 run_dump_test "elf-rel6"
604 run_dump_test "elf-rel7"
605 run_dump_test "elf-rel8"
606 run_dump_test "elf-rel9"
608 run_dump_test "elf-rel10"
609 run_dump_test "elf-rel11"
611 run_dump_test "elf-rel12"
612 run_dump_test "elf-rel13"
613 run_dump_test "elf-rel14"
614 run_dump_test "${tmips}${el}empic"
615 run_dump_test "empic2"
616 run_dump_test "empic3_e"
617 run_dump_test "empic3_g1"
618 run_dump_test "empic3_g2"
620 run_dump_test "${tmips}mips${el}16-e"
621 run_dump_test "${tmips}mips${el}16-f"
623 run_dump_test "elf-consthilo"
624 run_dump_test "expr1"
628 run_dump_test "n32-consec"
631 # tests of objdump's ability to disassemble using different
633 run_dump_test "gpr-names-numeric"
634 run_dump_test "gpr-names-32"
635 run_dump_test "gpr-names-n32"
636 run_dump_test "gpr-names-64"
638 run_dump_test "fpr-names-numeric"
639 run_dump_test "fpr-names-32"
640 run_dump_test "fpr-names-n32"
641 run_dump_test "fpr-names-64"
643 run_dump_test "cp0-names-numeric"
644 run_dump_test "cp0-names-mips32"
645 run_dump_test "cp0-names-mips32r2"
646 run_dump_test "cp0-names-mips64"
647 run_dump_test "cp0-names-sb1"
649 run_dump_test "cp0sel-names-numeric"
650 run_dump_test "cp0sel-names-mips32"
651 run_dump_test "cp0sel-names-mips32r2"
652 run_dump_test "cp0sel-names-mips64"
653 run_dump_test "cp0sel-names-sb1"
655 run_dump_test "hwr-names-numeric"
656 run_dump_test "hwr-names-mips32r2"