v2.tcl 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. # Copyright (C) 2015, 2020 Synopsys, Inc.
  2. # Anton Kolesov <anton.kolesov@synopsys.com>
  3. # Didin Evgeniy <didin@synopsys.com>
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-or-later
  6. source [find cpu/arc/common.tcl]
  7. # Currently 'examine_target' can only read JTAG registers and set properties -
  8. # but it shouldn't write any of registers - writes will be cached, but cache
  9. # will be invalidated before flushing after examine_target, and changes will be
  10. # lost. Perhaps that would be fixed later - perhaps writes shouldn't be cached
  11. # after all. But if write to register is really needed from TCL - then it
  12. # should be done via "arc jtag" for now.
  13. proc arc_v2_examine_target { {target ""} } {
  14. # Set current target, because OpenOCD event handlers don't do this for us.
  15. if { $target != "" } {
  16. targets $target
  17. }
  18. # Those registers always exist. DEBUG and DEBUGI are formally optional,
  19. # however they come with JTAG interface, and so far there is no way
  20. # OpenOCD can communicate with target without JTAG interface.
  21. arc set-reg-exists identity pc status32 bta debug lp_start lp_end \
  22. eret erbta erstatus ecr efa
  23. # 32 core registers
  24. arc set-reg-exists \
  25. r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 \
  26. r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 \
  27. gp fp sp ilink r30 blink lp_count pcl
  28. # Actionpoints
  29. if { [arc get-reg-field ap_build version] == 5 } {
  30. set ap_build_type [arc get-reg-field ap_build type]
  31. # AP_BUILD.TYPE > 0b0110 is reserved in current ISA.
  32. # Current ISA supports up to 8 actionpoints.
  33. if { $ap_build_type < 8 } {
  34. # Two LSB bits of AP_BUILD.TYPE define amount of actionpoints:
  35. # 0b00 - 2 actionpoints
  36. # 0b01 - 4 actionpoints
  37. # 0b10 - 8 actionpoints
  38. # 0b11 - reserved.
  39. set ap_num [expr {0x2 << ($ap_build_type & 3)}]
  40. # Expression on top may produce 16 action points - which is a
  41. # reserved value for now.
  42. if { $ap_num < 16 } {
  43. # Enable actionpoint registers
  44. for {set i 0} {$i < $ap_num} {incr i} {
  45. arc set-reg-exists ap_amv$i ap_amm$i ap_ac$i
  46. }
  47. # Set amount of actionpoints
  48. arc num-actionpoints $ap_num
  49. }
  50. }
  51. }
  52. # DCCM
  53. set dccm_version [arc get-reg-field dccm_build version]
  54. if { $dccm_version == 3 || $dccm_version == 4 } {
  55. arc set-reg-exists aux_dccm
  56. }
  57. # ICCM
  58. if { [arc get-reg-field iccm_build version] == 4 } {
  59. arc set-reg-exists aux_iccm
  60. }
  61. # MPU
  62. if { [arc get-reg-field mpu_build version] >= 2 &&
  63. [arc get-reg-field mpu_build version] <= 4 } {
  64. arc set-reg-exists mpu_en mpu_ecr
  65. set mpu_regions [arc get-reg-field mpu_build regions]
  66. for {set i 0} {$i < $mpu_regions} {incr i} {
  67. arc set-reg-exists mpu_rdp$i mpu_rdb$i
  68. }
  69. # Secure MPU
  70. if { [arc get-reg-field mpu_build version] == 4 } {
  71. arc set-reg-exists mpu_index mpu_rstart mpu_rend mpu_rper
  72. }
  73. }
  74. }
  75. proc arc_v2_init_regs { } {
  76. # XML features
  77. set core_feature "org.gnu.gdb.arc.core.v2"
  78. set aux_min_feature "org.gnu.gdb.arc.aux-minimal"
  79. set aux_other_feature "org.gnu.gdb.arc.aux-other"
  80. # Describe types
  81. # Types are sorted alphabetically according to their name.
  82. arc add-reg-type-struct -name ap_build_t -bitfield version 0 7 \
  83. -bitfield type 8 11
  84. arc add-reg-type-struct -name ap_control_t -bitfield at 0 3 -bitfield tt 4 5 \
  85. -bitfield m 6 6 -bitfield p 7 7 -bitfield aa 8 8 -bitfield q 9 9
  86. # Cycles field added in version 4.
  87. arc add-reg-type-struct -name dccm_build_t -bitfield version 0 7 \
  88. -bitfield size0 8 11 -bitfield size1 12 15 -bitfield cycles 17 19
  89. arc add-reg-type-struct -name debug_t \
  90. -bitfield fh 1 1 -bitfield ah 2 2 -bitfield asr 3 10 \
  91. -bitfield is 11 11 -bitfield ep 19 19 -bitfield ed 20 20 \
  92. -bitfield eh 21 21 -bitfield ra 22 22 -bitfield zz 23 23 \
  93. -bitfield sm 24 26 -bitfield ub 28 28 -bitfield bh 29 29 \
  94. -bitfield sh 30 30 -bitfield ld 31 31
  95. arc add-reg-type-struct -name ecr_t \
  96. -bitfield parameter 0 7 \
  97. -bitfield cause 8 15 \
  98. -bitfield vector 16 23 \
  99. -bitfield U 30 30 \
  100. -bitfield P 31 31
  101. arc add-reg-type-struct -name iccm_build_t -bitfield version 0 7 \
  102. -bitfield iccm0_size0 8 11 -bitfield iccm1_size0 12 15 \
  103. -bitfield iccm0_size1 16 19 -bitfield iccm1_size1 20 23
  104. arc add-reg-type-struct -name identity_t \
  105. -bitfield arcver 0 7 -bitfield arcnum 8 15 -bitfield chipid 16 31
  106. arc add-reg-type-struct -name isa_config_t -bitfield version 0 7 \
  107. -bitfield pc_size 8 11 -bitfield lpc_size 12 15 -bitfield addr_size 16 19 \
  108. -bitfield b 20 20 -bitfield a 21 21 -bitfield n 22 22 -bitfield l 23 23 \
  109. -bitfield c 24 27 -bitfield d 28 31
  110. arc add-reg-type-struct -name mpu_build_t -bitfield version 0 7 \
  111. -bitfield regions 8 15 \
  112. -bitfield s 16 16 \
  113. -bitfield i 17 17
  114. arc add-reg-type-struct -name mpu_ecr_t \
  115. -bitfield MR 0 7 \
  116. -bitfield VT 8 9 \
  117. -bitfield EC_CODE 16 31
  118. arc add-reg-type-struct -name mpu_en_t \
  119. -bitfield UE 3 3 -bitfield UW 4 4 -bitfield UR 5 5 \
  120. -bitfield KE 6 6 -bitfield KW 7 7 -bitfield KR 8 8 \
  121. -bitfield S 15 15 -bitfield SID 16 23 \
  122. -bitfield EN 30 30
  123. arc add-reg-type-struct -name mpu_index_t \
  124. -bitfield I 0 3 -bitfield M 30 30 -bitfield D 31 31
  125. arc add-reg-type-struct -name mpu_rper_t \
  126. -bitfield V 0 0 \
  127. -bitfield UE 3 3 -bitfield UW 4 4 -bitfield UR 5 5 \
  128. -bitfield KE 6 6 -bitfield KW 7 7 -bitfield KR 8 8 \
  129. -bitfield S 15 15 -bitfield SID 16 23
  130. arc add-reg-type-flags -name status32_t \
  131. -flag H 0 -flag E0 1 -flag E1 2 -flag E2 3 \
  132. -flag E3 4 -flag AE 5 -flag DE 6 -flag U 7 \
  133. -flag V 8 -flag C 9 -flag N 10 -flag Z 11 \
  134. -flag L 12 -flag DZ 13 -flag SC 14 -flag ES 15 \
  135. -flag RB0 16 -flag RB1 17 -flag RB2 18 \
  136. -flag AD 19 -flag US 20 -flag IE 31
  137. # Core registers
  138. set core_regs {
  139. r0 0 uint32
  140. r1 1 uint32
  141. r2 2 uint32
  142. r3 3 uint32
  143. r4 4 uint32
  144. r5 5 uint32
  145. r6 6 uint32
  146. r7 7 uint32
  147. r8 8 uint32
  148. r9 9 uint32
  149. r10 10 uint32
  150. r11 11 uint32
  151. r12 12 uint32
  152. r13 13 uint32
  153. r14 14 uint32
  154. r15 15 uint32
  155. r16 16 uint32
  156. r17 17 uint32
  157. r18 18 uint32
  158. r19 19 uint32
  159. r20 20 uint32
  160. r21 21 uint32
  161. r22 23 uint32
  162. r23 24 uint32
  163. r24 24 uint32
  164. r25 25 uint32
  165. gp 26 data_ptr
  166. fp 27 data_ptr
  167. sp 28 data_ptr
  168. ilink 29 code_ptr
  169. r30 30 uint32
  170. blink 31 code_ptr
  171. r32 32 uint32
  172. r33 33 uint32
  173. r34 34 uint32
  174. r35 35 uint32
  175. r36 36 uint32
  176. r37 37 uint32
  177. r38 38 uint32
  178. r39 39 uint32
  179. r40 40 uint32
  180. r41 41 uint32
  181. r42 42 uint32
  182. r43 43 uint32
  183. r44 44 uint32
  184. r45 45 uint32
  185. r46 46 uint32
  186. r47 47 uint32
  187. r48 48 uint32
  188. r49 49 uint32
  189. r50 50 uint32
  190. r51 51 uint32
  191. r52 52 uint32
  192. r53 53 uint32
  193. r54 54 uint32
  194. r55 55 uint32
  195. r56 56 uint32
  196. r57 57 uint32
  197. accl 58 uint32
  198. acch 59 uint32
  199. lp_count 60 uint32
  200. limm 61 uint32
  201. reserved 62 uint32
  202. pcl 63 code_ptr
  203. }
  204. foreach {reg count type} $core_regs {
  205. arc add-reg -name $reg -num $count -core -type $type -g \
  206. -feature $core_feature
  207. }
  208. # AUX min
  209. set aux_min {
  210. 0x6 pc code_ptr
  211. 0x2 lp_start code_ptr
  212. 0x3 lp_end code_ptr
  213. 0xA status32 status32_t
  214. }
  215. foreach {num name type} $aux_min {
  216. arc add-reg -name $name -num $num -type $type -feature $aux_min_feature -g
  217. }
  218. # AUX other
  219. set aux_other {
  220. 0x004 identity identity_t
  221. 0x005 debug debug_t
  222. 0x018 aux_dccm int
  223. 0x208 aux_iccm int
  224. 0x220 ap_amv0 uint32
  225. 0x221 ap_amm0 uint32
  226. 0x222 ap_ac0 ap_control_t
  227. 0x223 ap_amv1 uint32
  228. 0x224 ap_amm1 uint32
  229. 0x225 ap_ac1 ap_control_t
  230. 0x226 ap_amv2 uint32
  231. 0x227 ap_amm2 uint32
  232. 0x228 ap_ac2 ap_control_t
  233. 0x229 ap_amv3 uint32
  234. 0x22A ap_amm3 uint32
  235. 0x22B ap_ac3 ap_control_t
  236. 0x22C ap_amv4 uint32
  237. 0x22D ap_amm4 uint32
  238. 0x22E ap_ac4 ap_control_t
  239. 0x22F ap_amv5 uint32
  240. 0x230 ap_amm5 uint32
  241. 0x231 ap_ac5 ap_control_t
  242. 0x232 ap_amv6 uint32
  243. 0x233 ap_amm6 uint32
  244. 0x234 ap_ac6 ap_control_t
  245. 0x235 ap_amv7 uint32
  246. 0x236 ap_amm7 uint32
  247. 0x237 ap_ac7 ap_control_t
  248. 0x400 eret code_ptr
  249. 0x401 erbta code_ptr
  250. 0x402 erstatus status32_t
  251. 0x403 ecr ecr_t
  252. 0x404 efa data_ptr
  253. 0x409 mpu_en mpu_en_t
  254. 0x412 bta code_ptr
  255. 0x420 mpu_ecr mpu_ecr_t
  256. 0x422 mpu_rdb0 int
  257. 0x423 mpu_rdp0 int
  258. 0x424 mpu_rdb1 int
  259. 0x425 mpu_rdp1 int
  260. 0x426 mpu_rdb2 int
  261. 0x427 mpu_rdp2 int
  262. 0x428 mpu_rdb3 int
  263. 0x429 mpu_rdp3 int
  264. 0x42A mpu_rdb4 int
  265. 0x42B mpu_rdp4 int
  266. 0x42C mpu_rdb5 int
  267. 0x42D mpu_rdp5 int
  268. 0x42E mpu_rdb6 int
  269. 0x42F mpu_rdp6 int
  270. 0x430 mpu_rdb7 int
  271. 0x431 mpu_rdp7 int
  272. 0x432 mpu_rdb8 int
  273. 0x433 mpu_rdp8 int
  274. 0x434 mpu_rdb9 int
  275. 0x435 mpu_rdp9 int
  276. 0x436 mpu_rdb10 int
  277. 0x437 mpu_rdp10 int
  278. 0x438 mpu_rdb11 int
  279. 0x439 mpu_rdp11 int
  280. 0x43A mpu_rdb12 int
  281. 0x43B mpu_rdp12 int
  282. 0x43C mpu_rdb13 int
  283. 0x43D mpu_rdp13 int
  284. 0x43E mpu_rdb14 int
  285. 0x43F mpu_rdp14 int
  286. 0x440 mpu_rdb15 int
  287. 0x441 mpu_rdp15 int
  288. 0x448 mpu_index mpu_index_t
  289. 0x449 mpu_rstart uint32
  290. 0x44A mpu_rend uint32
  291. 0x44B mpu_rper mpu_rper_t
  292. 0x44C mpu_probe uint32
  293. }
  294. foreach {num name type} $aux_other {
  295. arc add-reg -name $name -num $num -type $type -feature $aux_other_feature
  296. }
  297. # AUX BCR
  298. set bcr {
  299. 0x6D mpu_build
  300. 0x74 dccm_build
  301. 0x76 ap_build
  302. 0x78 iccm_build
  303. 0xC1 isa_config
  304. }
  305. foreach {num reg} $bcr {
  306. arc add-reg -name $reg -num $num -type ${reg}_t -bcr -feature $aux_other_feature
  307. }
  308. [target current] configure \
  309. -event examine-end "arc_v2_examine_target [target current]"
  310. }
  311. proc arc_v2_reset { {target ""} } {
  312. arc_common_reset $target
  313. # Disable all actionpoints. Cannot write via regcache yet, because it will
  314. # not be flushed and all changes to registers will get lost. Therefore has
  315. # to write directly via JTAG layer...
  316. set num_ap [arc num-actionpoints]
  317. for {set i 0} {$i < $num_ap} {incr i} {
  318. arc jtag set-aux-reg [expr {0x222 + $i * 3}] 0
  319. }
  320. }