1 # SPDX-License-Identifier: GPL-2.0-or-later
3 proc proc_exists
{ NAME
} {
4 set n
[info commands
$NAME]
5 set l
[string length
$n]
6 return [expr {$l != 0}]
9 # Give: REGISTER name - must be a global variable.
10 proc show_mmr32_reg
{ NAME
} {
14 set a
[set [set NAME
]]
16 if ![catch { set v
[memread32
$a] } msg
] {
17 echo
[format "%15s: (0x%08x): 0x%08x" $NAME $a $v]
19 # Was a helper defined?
20 set fn show_
${NAME
}_helper
21 if [ proc_exists
$fn ] {
27 error [format "%s (%s)" $msg $NAME ]
32 # Give: NAMES - an array of names accessible
33 # in the callers symbol-scope.
34 # VAL - the bits to display.
36 proc show_mmr32_bits
{ NAMES VAL
} {
41 foreach {IDX N
} $MYNAMES {
42 set l
[string length
$N]
43 if { $l > $w } { set w
$l }
46 for { set x
24 } { $x >= 0 } { incr x
-8 } {
48 for { set y
7 } { $y >= 0 } { incr y
-1 } {
49 set s
$MYNAMES([expr {$x + $y}])
50 echo
-n [format "%2d: %-*s | " [expr {$x + $y}] $w $s ]
55 for { set y
7 } { $y >= 0 } { incr y
-1 } {
56 echo
-n [format " %d%*s | " [expr {!!($VAL & (1 << ($x + $y)))}] [expr {$w -1}] ""]
63 proc show_mmr_bitfield
{ MSB LSB VAL FIELDNAME FIELDVALUES
} {
64 set width
[expr {(($MSB - $LSB + 1) + 7) / 4}]
65 set nval
[show_normalize_bitfield
$VAL $MSB $LSB ]
66 set name0
[lindex $FIELDVALUES 0 ]
67 if [ string compare
$name0 _NUMBER_
] {
68 set sval
[lindex $FIELDVALUES $nval]
72 echo
[format "%-15s: %d (0x%0*x) %s" $FIELDNAME $nval $width $nval $sval ]
75 # Give: ADDR - address of the register.
78 proc get_mmr_bit
{ ADDR BIT
} {
79 set val
[memread32
$ADDR]
80 set bit_val
[expr {$val & [expr {1 << $BIT}]}]
85 # Give: ADDR - address of the register.
86 # MSB - MSB bit's number.
87 # LSB - LSB bit's number.
89 proc get_mmr_bitfield
{ ADDR MSB LSB
} {
90 set rval
[memread32
$ADDR]
91 return normalize_bitfield
$rval $MSB $LSB