Home | History | Annotate | Line # | Download | only in gdb.arch
riscv-info-fcsr.exp revision 1.1
      1  1.1  christos # Copyright 2022-2023 Free Software Foundation, Inc.
      2  1.1  christos #
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # Check the formatting of the fcsr, fflags, and frm registers in the
     17  1.1  christos # output of the 'info registers' command.
     18  1.1  christos 
     19  1.1  christos if {![istarget "riscv*-*-*"]} {
     20  1.1  christos     verbose "Skipping ${gdb_test_file_name}."
     21  1.1  christos     return
     22  1.1  christos }
     23  1.1  christos 
     24  1.1  christos if { [gdb_skip_float_test] } {
     25  1.1  christos     untested "no floating point support"
     26  1.1  christos     return
     27  1.1  christos }
     28  1.1  christos 
     29  1.1  christos standard_testfile
     30  1.1  christos 
     31  1.1  christos if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
     32  1.1  christos     return -1
     33  1.1  christos }
     34  1.1  christos 
     35  1.1  christos if {![runto_main]} {
     36  1.1  christos    return 0
     37  1.1  christos }
     38  1.1  christos 
     39  1.1  christos # Merge FFLAGS_VALUE and FRM_VALUE into a single hexadecimal value
     40  1.1  christos # that can be written to the fcsr register.  The two arguments should
     41  1.1  christos # be the value of each of the two fields within the fcsr register.
     42  1.1  christos proc merge_fflags_and_frm { fflags_value frm_value } {
     43  1.1  christos     set fcsr_value 0x[format %x [expr $fflags_value | ($frm_value << 5)]]
     44  1.1  christos     return $fcsr_value
     45  1.1  christos }
     46  1.1  christos 
     47  1.1  christos # Use 'info registers' to check the current values of the fflags, frm,
     48  1.1  christos # and fcsr registers.  The value in fcsr should consist of the
     49  1.1  christos # FFLAGS_VALUE and FRM_VALUE, and the frm field of the fcsr register
     50  1.1  christos # should have the text FRM_STRING associated with it.
     51  1.1  christos proc check_fcsr { fflags_value frm_value frm_string } {
     52  1.1  christos     # Merge fflags and frm values into a single fcsr value.
     53  1.1  christos     set fcsr_value [merge_fflags_and_frm $fflags_value $frm_value]
     54  1.1  christos 
     55  1.1  christos     # Build up all the patterns we will need for this test.
     56  1.1  christos     set frm_str_re [string_to_regexp "$frm_string"]
     57  1.1  christos     set frm_val_re [format %d ${frm_value}]
     58  1.1  christos 
     59  1.1  christos     set nv [format %d [expr ($fflags_value >> 4) & 0x1]]
     60  1.1  christos     set dz [format %d [expr ($fflags_value >> 3) & 0x1]]
     61  1.1  christos     set of [format %d [expr ($fflags_value >> 2) & 0x1]]
     62  1.1  christos     set uf [format %d [expr ($fflags_value >> 1) & 0x1]]
     63  1.1  christos     set nx [format %d [expr ($fflags_value >> 0) & 0x1]]
     64  1.1  christos 
     65  1.1  christos     set fflags_pattern "NV:${nv} DZ:${dz} OF:${of} UF:${uf} NX:${nx}"
     66  1.1  christos     set frm_pattern "FRM:${frm_val_re} \\\[${frm_str_re}\\\]"
     67  1.1  christos     set fcsr_pattern "${fflags_pattern} ${frm_pattern}"
     68  1.1  christos 
     69  1.1  christos     # Now use 'info registers' to check the register values.
     70  1.1  christos     array set reg_counts {}
     71  1.1  christos     gdb_test_multiple "info registers \$fflags \$frm \$fcsr" "" {
     72  1.1  christos 	-re "^info registers\[^\r\n\]+\r\n" {
     73  1.1  christos 	    exp_continue
     74  1.1  christos 	}
     75  1.1  christos 
     76  1.1  christos 	-re "^(frm)\\s+${frm_value}\\s+${frm_pattern}\r\n" {
     77  1.1  christos 	    set reg_name $expect_out(1,string)
     78  1.1  christos 	    incr reg_counts($reg_name)
     79  1.1  christos 	    exp_continue
     80  1.1  christos 	}
     81  1.1  christos 
     82  1.1  christos 	-re "^(fflags)\\s+${fflags_value}\\s+${fflags_pattern}\r\n" {
     83  1.1  christos 	    set reg_name $expect_out(1,string)
     84  1.1  christos 	    incr reg_counts($reg_name)
     85  1.1  christos 	    exp_continue
     86  1.1  christos 	}
     87  1.1  christos 
     88  1.1  christos 	-re "^(fcsr)\\s+${fcsr_value}\\s+${fcsr_pattern}\r\n" {
     89  1.1  christos 	    set reg_name $expect_out(1,string)
     90  1.1  christos 	    incr reg_counts($reg_name)
     91  1.1  christos 	    exp_continue
     92  1.1  christos 	}
     93  1.1  christos 
     94  1.1  christos 	-re "^$::gdb_prompt $" {
     95  1.1  christos 	    pass $gdb_test_name
     96  1.1  christos 	}
     97  1.1  christos     }
     98  1.1  christos 
     99  1.1  christos     # Check that each register is seen only once.
    100  1.1  christos     foreach reg {fflags frm fcsr} {
    101  1.1  christos 	gdb_assert { $reg_counts($reg) == 1 } \
    102  1.1  christos 	    "check we saw $reg just once"
    103  1.1  christos     }
    104  1.1  christos }
    105  1.1  christos 
    106  1.1  christos # Set the fcsr register based on FFLAGS_VALUE and FRM_VALUE, then
    107  1.1  christos # check that the value is displayed correctly in the 'info registers'
    108  1.1  christos # output.  FRM_STRING should appear in the 'info registers' output
    109  1.1  christos # next to the frm field.
    110  1.1  christos proc test_fcsr { fflags_value frm_value frm_string } {
    111  1.1  christos     # Merge fflags and frm values into a single fcsr value.
    112  1.1  christos     set fcsr_value [merge_fflags_and_frm $fflags_value $frm_value]
    113  1.1  christos 
    114  1.1  christos     with_test_prefix "fcsr=${fcsr_value}" {
    115  1.1  christos 	# Set the fcsr value directly.
    116  1.1  christos 	gdb_test_no_output "set \$fcsr = ${fcsr_value}"
    117  1.1  christos 
    118  1.1  christos 	with_test_prefix "set through fcsr" {
    119  1.1  christos 	    check_fcsr $fflags_value $frm_value $frm_string
    120  1.1  christos 	}
    121  1.1  christos 
    122  1.1  christos 	# Reset fcsr register back to zero.
    123  1.1  christos 	gdb_test_no_output "set \$fcsr = 0x0" \
    124  1.1  christos 	    "reset fcsr back to 0x0"
    125  1.1  christos 	gdb_test "p/x \$fcsr" " = 0x0"
    126  1.1  christos 
    127  1.1  christos 	# Now set fcsr value through fflags and frm.
    128  1.1  christos 	gdb_test_no_output "set \$fflags = ${fflags_value}"
    129  1.1  christos 	gdb_test_no_output "set \$frm = ${frm_value}"
    130  1.1  christos 
    131  1.1  christos 	with_test_prefix "set through fflags and frm" {
    132  1.1  christos 	    check_fcsr $fflags_value $frm_value $frm_string
    133  1.1  christos 	}
    134  1.1  christos     }
    135  1.1  christos }
    136  1.1  christos 
    137  1.1  christos # Check each valid value of the fflags register.
    138  1.1  christos for { set i 0 } { $i < 32 } { incr i } {
    139  1.1  christos     test_fcsr 0x[format %x $i] 0x0 "RNE (round to nearest; ties to even)"
    140  1.1  christos }
    141  1.1  christos 
    142  1.1  christos # Check each valid value of the frm register.
    143  1.1  christos test_fcsr 0x0 0x1 "RTZ (Round towards zero)"
    144  1.1  christos test_fcsr 0x0 0x2 "RDN (Round down towards -INF)"
    145  1.1  christos test_fcsr 0x0 0x3 "RUP (Round up towards +INF)"
    146  1.1  christos test_fcsr 0x0 0x4 "RMM (Round to nearest; ties to max magnitude)"
    147  1.1  christos test_fcsr 0x0 0x5 "INVALID\[5\]"
    148  1.1  christos test_fcsr 0x0 0x6 "INVALID\[6\]"
    149  1.1  christos test_fcsr 0x0 0x7 "INVALID\[7\] (Dynamic rounding mode)"
    150