1 # SPDX-License-Identifier: GPL-2.0-or-later
5 # All Memory regions have two components.
6 # (1) A count of regions, in the form N_NAME
7 # (2) An array within info about each region.
11 # <NAME>( RegionNumber , ATTRIBUTE )
13 # Where <NAME> is one of:
15 # N_FLASH & FLASH (internal memory)
16 # N_RAM & RAM (internal memory)
17 # N_MMREGS & MMREGS (for memory mapped registers)
18 # N_XMEM & XMEM (off chip memory, ie: flash on cs0, sdram on cs2)
19 # or N_UNKNOWN & UNKNOWN for things that do not exist.
21 # We have 1 unknown region.
23 # All MEMORY regions must have these attributes
24 # CS - chip select (if internal, use -1)
25 set UNKNOWN
(0,CHIPSELECT
) -1
26 # BASE - base address in memory
28 # LEN - length in bytes
29 set UNKNOWN
(0,LEN
) $CPU_MAX_ADDRESS
30 # HUMAN - human name of the region
31 set UNKNOWN
(0,HUMAN
) "unknown"
33 # flash, ram, mmr, unknown
35 # iflash, dflash, iram, dram
36 set UNKNOWN
(0,TYPE
) "unknown"
38 # unix style chmod bits
43 # hence: 7 - readwrite execute
48 set RWX_RW
[expr {$RWX_R_ONLY + $RWX_W_ONLY}]
49 set RWX_R_X
[expr {$RWX_R_ONLY + $RWX_X_ONLY}]
50 set RWX_RWX
[expr {$RWX_R_ONLY + $RWX_W_ONLY + $RWX_X_ONLY}]
51 set UNKNOWN
(0,RWX
) $RWX_NO_ACCESS
53 # WIDTH - access width
54 # 8,16,32 [0 means ANY]
55 set ACCESS_WIDTH_NONE
0
56 set ACCESS_WIDTH_8
$BIT0
57 set ACCESS_WIDTH_16
$BIT1
58 set ACCESS_WIDTH_32
$BIT2
59 set ACCESS_WIDTH_ANY
[expr {$ACCESS_WIDTH_8 + $ACCESS_WIDTH_16 + $ACCESS_WIDTH_32}]
60 set UNKNOWN
(0,ACCESS_WIDTH
) $ACCESS_WIDTH_NONE
62 proc iswithin
{ ADDRESS BASE LEN
} {
63 return [expr {(($ADDRESS - $BASE) >= 0) && (($BASE + $LEN - $ADDRESS) > 0)}]
66 proc address_info
{ ADDRESS
} {
68 foreach WHERE
{ FLASH RAM MMREGS XMEM UNKNOWN
} {
69 if { info exists
$WHERE } {
70 set lmt
[set N_
[set WHERE
]]
71 for { set region
0 } { $region < $lmt } { incr region
} {
72 if { iswithin
$ADDRESS $WHERE($region,BASE
) $WHERE($region,LEN
) } {
73 return "$WHERE $region";
79 # Return the 'unknown'
83 proc memread32
{ADDR
} {
84 if ![ catch { set foo
[read_memory
$ADDR 32 1] } msg
] {
87 error "memread32: $msg"
91 proc memread16
{ADDR
} {
92 if ![ catch { set foo
[read_memory
$ADDR 16 1] } msg
] {
95 error "memread16: $msg"
99 proc memread8
{ADDR
} {
100 if ![ catch { set foo
[read_memory
$ADDR 8 1] } msg
] {
103 error "memread8: $msg"
107 proc memwrite32
{ADDR DATA
} {
108 if ![ catch { write_memory
$ADDR 32 $DATA } msg
] {
111 error "memwrite32: $msg"
115 proc memwrite16
{ADDR DATA
} {
116 if ![ catch { write_memory
$ADDR 16 $DATA } msg
] {
119 error "memwrite16: $msg"
123 proc memwrite8
{ADDR DATA
} {
124 if ![ catch { write_memory
$ADDR 8 $DATA } msg
] {
127 error "memwrite8: $msg"
131 proc memread32_phys
{ADDR
} {
132 if ![ catch { set foo
[read_memory
$ADDR 32 1 phys
] } msg
] {
135 error "memread32: $msg"
139 proc memread16_phys
{ADDR
} {
140 if ![ catch { set foo
[read_memory
$ADDR 16 1 phys
] } msg
] {
143 error "memread16: $msg"
147 proc memread8_phys
{ADDR
} {
148 if ![ catch { set foo
[read_memory
$ADDR 8 1 phys
] } msg
] {
151 error "memread8: $msg"
155 proc memwrite32_phys
{ADDR DATA
} {
156 if ![ catch { write_memory
$ADDR 32 $DATA phys
} msg
] {
159 error "memwrite32: $msg"
163 proc memwrite16_phys
{ADDR DATA
} {
164 if ![ catch { write_memory
$ADDR 16 $DATA phys
} msg
] {
167 error "memwrite16: $msg"
171 proc memwrite8_phys
{ADDR DATA
} {
172 if ![ catch { write_memory
$ADDR 8 $DATA phys
} msg
] {
175 error "memwrite8: $msg"