-
Notifications
You must be signed in to change notification settings - Fork 337
/
Copy pathdebug_defines.h
3156 lines (3154 loc) · 116 KB
/
debug_defines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is auto-generated by running 'make debug_defines' in
* https://github.com/riscv/riscv-debug-spec/ (40b9a05)
*/
#ifndef DEBUG_DEFINES_H
#define DEBUG_DEFINES_H
#define DTM_IDCODE 0x01
/*
* Identifies the release version of this part.
*/
#define DTM_IDCODE_VERSION_OFFSET 0x1cULL
#define DTM_IDCODE_VERSION_LENGTH 4ULL
#define DTM_IDCODE_VERSION 0xf0000000ULL
/*
* Identifies the designer's part number of this part.
*/
#define DTM_IDCODE_PARTNUMBER_OFFSET 0xcULL
#define DTM_IDCODE_PARTNUMBER_LENGTH 0x10ULL
#define DTM_IDCODE_PARTNUMBER 0xffff000ULL
/*
* Identifies the designer/manufacturer of this part. Bits 6:0 must be
* bits 6:0 of the designer/manufacturer's Identification Code as
* assigned by JEDEC Standard JEP106. Bits 10:7 contain the modulo-16
* count of the number of continuation characters (0x7f) in that same
* Identification Code.
*/
#define DTM_IDCODE_MANUFID_OFFSET 1ULL
#define DTM_IDCODE_MANUFID_LENGTH 0xbULL
#define DTM_IDCODE_MANUFID 0xffeULL
#define DTM_IDCODE_1_OFFSET 0ULL
#define DTM_IDCODE_1_LENGTH 1ULL
#define DTM_IDCODE_1 1ULL
#define DTM_DTMCS 0x10
/*
* This optional field may provide additional detail about an error
* that occurred when communicating with a DM. It is updated whenever
* \FdtmDmiOp is updated by the hardware or when 1 is written to
* \FdtmDtmcsDmireset.
*/
#define DTM_DTMCS_ERRINFO_OFFSET 0x12ULL
#define DTM_DTMCS_ERRINFO_LENGTH 3ULL
#define DTM_DTMCS_ERRINFO 0x1c0000ULL
/*
* not implemented: This field is not implemented.
*/
#define DTM_DTMCS_ERRINFO_NOT_IMPLEMENTED 0
/*
* dmi error: There was an error between the DTM and DMI.
*/
#define DTM_DTMCS_ERRINFO_DMI_ERROR 1
/*
* communication error: There was an error between the DMI and a DMI subordinate.
*/
#define DTM_DTMCS_ERRINFO_COMMUNICATION_ERROR 2
/*
* device error: The DMI subordinate reported an error.
*/
#define DTM_DTMCS_ERRINFO_DEVICE_ERROR 3
/*
* unknown: There is no error to report, or no further information available
* about the error. This is the reset value if the field is implemented.
*/
#define DTM_DTMCS_ERRINFO_UNKNOWN 4
/*
* Other values are reserved for future use by this specification.
*/
/*
* Writing 1 to this bit does a hard reset of the DTM,
* causing the DTM to forget about any outstanding DMI transactions, and
* returning all registers and internal state to their reset value.
* In general this should only be used when the Debugger has
* reason to expect that the outstanding DMI transaction will never
* complete (e.g. a reset condition caused an inflight DMI transaction to
* be cancelled).
*/
#define DTM_DTMCS_DTMHARDRESET_OFFSET 0x11ULL
#define DTM_DTMCS_DTMHARDRESET_LENGTH 1ULL
#define DTM_DTMCS_DTMHARDRESET 0x20000ULL
/*
* Writing 1 to this bit clears the sticky error state and resets
* \FdtmDtmcsErrinfo, but does not affect outstanding DMI transactions.
*/
#define DTM_DTMCS_DMIRESET_OFFSET 0x10ULL
#define DTM_DTMCS_DMIRESET_LENGTH 1ULL
#define DTM_DTMCS_DMIRESET 0x10000ULL
/*
* This is a hint to the debugger of the minimum number of
* cycles a debugger should spend in
* Run-Test/Idle after every DMI scan to avoid a `busy'
* return code (\FdtmDtmcsDmistat of 3). A debugger must still
* check \FdtmDtmcsDmistat when necessary.
*
* 0: It is not necessary to enter Run-Test/Idle at all.
*
* 1: Enter Run-Test/Idle and leave it immediately.
*
* 2: Enter Run-Test/Idle and stay there for 1 cycle before leaving.
*
* And so on.
*/
#define DTM_DTMCS_IDLE_OFFSET 0xcULL
#define DTM_DTMCS_IDLE_LENGTH 3ULL
#define DTM_DTMCS_IDLE 0x7000ULL
/*
* Read-only alias of \FdtmDmiOp.
*/
#define DTM_DTMCS_DMISTAT_OFFSET 0xaULL
#define DTM_DTMCS_DMISTAT_LENGTH 2ULL
#define DTM_DTMCS_DMISTAT 0xc00ULL
/*
* The size of \FdmSbaddressZeroAddress in \RdtmDmi.
*/
#define DTM_DTMCS_ABITS_OFFSET 4ULL
#define DTM_DTMCS_ABITS_LENGTH 6ULL
#define DTM_DTMCS_ABITS 0x3f0ULL
#define DTM_DTMCS_VERSION_OFFSET 0ULL
#define DTM_DTMCS_VERSION_LENGTH 4ULL
#define DTM_DTMCS_VERSION 0xfULL
/*
* 0.11: Version described in spec version 0.11.
*/
#define DTM_DTMCS_VERSION_0_11 0
/*
* 1.0: Version described in spec versions 0.13 and 1.0.
*/
#define DTM_DTMCS_VERSION_1_0 1
/*
* custom: Version not described in any available version of this spec.
*/
#define DTM_DTMCS_VERSION_CUSTOM 15
#define DTM_DMI 0x11
/*
* Address used for DMI access. In Update-DR this value is used
* to access the DM over the DMI.
* \FdtmDmiOp defines what this register contains after every possible
* operation.
*/
#define DTM_DMI_ADDRESS_OFFSET 0x22ULL
#define DTM_DMI_ADDRESS_LENGTH(abits) (abits)
#define DTM_DMI_ADDRESS(abits) ((0x400000000ULL * (1ULL << (abits))) + -0x400000000ULL)
/*
* The data to send to the DM over the DMI during Update-DR, and
* the data returned from the DM as a result of the previous operation.
*/
#define DTM_DMI_DATA_OFFSET 2ULL
#define DTM_DMI_DATA_LENGTH 0x20ULL
#define DTM_DMI_DATA 0x3fffffffcULL
/*
* When the debugger writes this field, it has the following meaning:
*/
#define DTM_DMI_OP_OFFSET 0ULL
#define DTM_DMI_OP_LENGTH 2ULL
#define DTM_DMI_OP 3ULL
/*
* nop: Ignore \FdmSbdataZeroData and \FdmSbaddressZeroAddress.
*
* Don't send anything over the DMI during Update-DR.
* This operation should never result in a busy or error response.
* The address and data reported in the following Capture-DR
* are undefined.
*
* This operation leaves the values in \FdtmDmiAddress and \FdtmDmiData
* \unspecified.
*/
#define DTM_DMI_OP_NOP 0
/*
* read: Read from \FdtmDmiAddress.
*
* When this operation succeeds, \FdtmDmiAddress contains the address
* that was read from, and \FdtmDmiData contains the value that was
* read.
*/
#define DTM_DMI_OP_READ 1
/*
* write: Write \FdtmDmiData to \FdtmDmiAddress.
*
* This operation leaves the values in \FdtmDmiAddress and \FdtmDmiData
* \unspecified.
*/
#define DTM_DMI_OP_WRITE 2
/*
* reserved: Reserved.
*/
/*
* When the debugger reads this field, it means the following:
*/
/*
* success: The previous operation completed successfully.
*/
#define DTM_DMI_OP_SUCCESS 0
/*
* reserved: Reserved.
*/
/*
* failed: A previous operation failed. The data scanned into \RdtmDmi in
* this access will be ignored. This status is sticky and can be
* cleared by writing \FdtmDtmcsDmireset in \RdtmDtmcs.
*
* This indicates that the DM itself or the DMI responded with an error.
* There are no specified cases in which the DM would
* respond with an error, and DMI is not required to support
* returning errors.
*
* If a debugger sees this status, there might be additional
* information in \FdtmDtmcsErrinfo.
*/
#define DTM_DMI_OP_FAILED 2
/*
* busy: An operation was attempted while a DMI request is still in
* progress. The data scanned into \RdtmDmi in this access will be
* ignored. This status is sticky and can be cleared by writing
* \FdtmDtmcsDmireset in \RdtmDtmcs. If a debugger sees this status, it
* needs to give the target more TCK edges between Update-DR and
* Capture-DR. The simplest way to do that is to add extra transitions
* in Run-Test/Idle.
*/
#define DTM_DMI_OP_BUSY 3
#define CSR_DCSR 0x7b0
#define CSR_DCSR_DEBUGVER_OFFSET 0x1cULL
#define CSR_DCSR_DEBUGVER_LENGTH 4ULL
#define CSR_DCSR_DEBUGVER 0xf0000000ULL
/*
* none: There is no debug support.
*/
#define CSR_DCSR_DEBUGVER_NONE 0
/*
* 1.0: Debug support exists as it is described in this document.
*/
#define CSR_DCSR_DEBUGVER_1_0 4
/*
* custom: There is debug support, but it does not conform to any
* available version of this spec.
*/
#define CSR_DCSR_DEBUGVER_CUSTOM 15
#define CSR_DCSR_EBREAKVS_OFFSET 0x11ULL
#define CSR_DCSR_EBREAKVS_LENGTH 1ULL
#define CSR_DCSR_EBREAKVS 0x20000ULL
/*
* exception: {\tt ebreak} instructions in VS-mode behave as described in the
* Privileged Spec.
*/
#define CSR_DCSR_EBREAKVS_EXCEPTION 0
/*
* debug mode: {\tt ebreak} instructions in VS-mode enter Debug Mode.
*/
#define CSR_DCSR_EBREAKVS_DEBUG_MODE 1
/*
* This bit is hardwired to 0 if the hart does not support virtualization mode.
*/
#define CSR_DCSR_EBREAKVU_OFFSET 0x10ULL
#define CSR_DCSR_EBREAKVU_LENGTH 1ULL
#define CSR_DCSR_EBREAKVU 0x10000ULL
/*
* exception: {\tt ebreak} instructions in VU-mode behave as described in the
* Privileged Spec.
*/
#define CSR_DCSR_EBREAKVU_EXCEPTION 0
/*
* debug mode: {\tt ebreak} instructions in VU-mode enter Debug Mode.
*/
#define CSR_DCSR_EBREAKVU_DEBUG_MODE 1
/*
* This bit is hardwired to 0 if the hart does not support virtualization mode.
*/
#define CSR_DCSR_EBREAKM_OFFSET 0xfULL
#define CSR_DCSR_EBREAKM_LENGTH 1ULL
#define CSR_DCSR_EBREAKM 0x8000ULL
/*
* exception: {\tt ebreak} instructions in M-mode behave as described in the
* Privileged Spec.
*/
#define CSR_DCSR_EBREAKM_EXCEPTION 0
/*
* debug mode: {\tt ebreak} instructions in M-mode enter Debug Mode.
*/
#define CSR_DCSR_EBREAKM_DEBUG_MODE 1
#define CSR_DCSR_EBREAKS_OFFSET 0xdULL
#define CSR_DCSR_EBREAKS_LENGTH 1ULL
#define CSR_DCSR_EBREAKS 0x2000ULL
/*
* exception: {\tt ebreak} instructions in S-mode behave as described in the
* Privileged Spec.
*/
#define CSR_DCSR_EBREAKS_EXCEPTION 0
/*
* debug mode: {\tt ebreak} instructions in S-mode enter Debug Mode.
*/
#define CSR_DCSR_EBREAKS_DEBUG_MODE 1
/*
* This bit is hardwired to 0 if the hart does not support S-mode.
*/
#define CSR_DCSR_EBREAKU_OFFSET 0xcULL
#define CSR_DCSR_EBREAKU_LENGTH 1ULL
#define CSR_DCSR_EBREAKU 0x1000ULL
/*
* exception: {\tt ebreak} instructions in U-mode behave as described in the
* Privileged Spec.
*/
#define CSR_DCSR_EBREAKU_EXCEPTION 0
/*
* debug mode: {\tt ebreak} instructions in U-mode enter Debug Mode.
*/
#define CSR_DCSR_EBREAKU_DEBUG_MODE 1
/*
* This bit is hardwired to 0 if the hart does not support U-mode.
*/
#define CSR_DCSR_STEPIE_OFFSET 0xbULL
#define CSR_DCSR_STEPIE_LENGTH 1ULL
#define CSR_DCSR_STEPIE 0x800ULL
/*
* interrupts disabled: Interrupts (including NMI) are disabled during single stepping
* with \FcsrDcsrStep set.
* This value should be supported.
*/
#define CSR_DCSR_STEPIE_INTERRUPTS_DISABLED 0
/*
* interrupts enabled: Interrupts (including NMI) are enabled during single stepping
* with \FcsrDcsrStep set.
*/
#define CSR_DCSR_STEPIE_INTERRUPTS_ENABLED 1
/*
* Implementations may hard wire this bit to 0.
* In that case interrupt behavior can be emulated by the debugger.
*
* The debugger must not change the value of this bit while the hart
* is running.
*/
#define CSR_DCSR_STOPCOUNT_OFFSET 0xaULL
#define CSR_DCSR_STOPCOUNT_LENGTH 1ULL
#define CSR_DCSR_STOPCOUNT 0x400ULL
/*
* normal: Increment counters as usual.
*/
#define CSR_DCSR_STOPCOUNT_NORMAL 0
/*
* freeze: Don't increment any hart-local counters while in Debug Mode or
* on {\tt ebreak} instructions that cause entry into Debug Mode.
* These counters include the {\tt instret} CSR. On single-hart cores
* {\tt cycle} should be stopped, but on multi-hart cores it must keep
* incrementing.
*/
#define CSR_DCSR_STOPCOUNT_FREEZE 1
/*
* An implementation may hardwire this bit to 0 or 1.
*/
#define CSR_DCSR_STOPTIME_OFFSET 9ULL
#define CSR_DCSR_STOPTIME_LENGTH 1ULL
#define CSR_DCSR_STOPTIME 0x200ULL
/*
* normal: \Rtime continues to reflect \Rmtime.
*/
#define CSR_DCSR_STOPTIME_NORMAL 0
/*
* freeze: \Rtime is frozen at the time that Debug Mode was entered. When
* leaving Debug Mode, \Rtime will reflect the latest
* value of \Rmtime again.
*
* While all harts have \FcsrDcsrStoptime=1 and are in Debug Mode,
* \Rmtime is allowed to stop incrementing.
*/
#define CSR_DCSR_STOPTIME_FREEZE 1
/*
* An implementation may hardwire this bit to 0 or 1.
*/
/*
* Explains why Debug Mode was entered.
*
* When there are multiple reasons to enter Debug Mode in a single
* cycle, hardware should set \FcsrDcsrCause to the cause with the highest
* priority. See table~\ref{tab:dcsrcausepriority} for priorities.
*/
#define CSR_DCSR_CAUSE_OFFSET 6ULL
#define CSR_DCSR_CAUSE_LENGTH 3ULL
#define CSR_DCSR_CAUSE 0x1c0ULL
/*
* ebreak: An {\tt ebreak} instruction was executed.
*/
#define CSR_DCSR_CAUSE_EBREAK 1
/*
* trigger: A Trigger Module trigger fired with action=1.
*/
#define CSR_DCSR_CAUSE_TRIGGER 2
/*
* haltreq: The debugger requested entry to Debug Mode using \FdmDmcontrolHaltreq.
*/
#define CSR_DCSR_CAUSE_HALTREQ 3
/*
* step: The hart single stepped because \FcsrDcsrStep was set.
*/
#define CSR_DCSR_CAUSE_STEP 4
/*
* resethaltreq: The hart halted directly out of reset due to \Fresethaltreq. It
* is also acceptable to report 3 when this happens.
*/
#define CSR_DCSR_CAUSE_RESETHALTREQ 5
/*
* group: The hart halted because it's part of a halt group.
* Harts may report 3 for this cause instead.
*/
#define CSR_DCSR_CAUSE_GROUP 6
/*
* Other values are reserved for future use.
*/
/*
* Extends the prv field with the virtualization mode the hart was operating
* in when Debug Mode was entered. The encoding is described in Table
* \ref{tab:privmode}.
* A debugger can change this value to change the hart's virtualization mode
* when exiting Debug Mode.
* This bit is hardwired to 0 on harts that do not support virtualization mode.
*/
#define CSR_DCSR_V_OFFSET 5ULL
#define CSR_DCSR_V_LENGTH 1ULL
#define CSR_DCSR_V 0x20ULL
#define CSR_DCSR_MPRVEN_OFFSET 4ULL
#define CSR_DCSR_MPRVEN_LENGTH 1ULL
#define CSR_DCSR_MPRVEN 0x10ULL
/*
* disabled: \FcsrMstatusMprv in \Rmstatus is ignored in Debug Mode.
*/
#define CSR_DCSR_MPRVEN_DISABLED 0
/*
* enabled: \FcsrMstatusMprv in \Rmstatus takes effect in Debug Mode.
*/
#define CSR_DCSR_MPRVEN_ENABLED 1
/*
* Implementing this bit is optional. It may be tied to either 0 or 1.
*/
/*
* When set, there is a Non-Maskable-Interrupt (NMI) pending for the hart.
*
* Since an NMI can indicate a hardware error condition,
* reliable debugging may no longer be possible once this bit becomes set.
* This is implementation-dependent.
*/
#define CSR_DCSR_NMIP_OFFSET 3ULL
#define CSR_DCSR_NMIP_LENGTH 1ULL
#define CSR_DCSR_NMIP 8ULL
/*
* When set and not in Debug Mode, the hart will only execute a single
* instruction and then enter Debug Mode. See Section~\ref{stepBit}
* for details.
*
* The debugger must not change the value of this bit while the hart
* is running.
*/
#define CSR_DCSR_STEP_OFFSET 2ULL
#define CSR_DCSR_STEP_LENGTH 1ULL
#define CSR_DCSR_STEP 4ULL
/*
* Contains the privilege mode the hart was operating in when Debug
* Mode was entered. The encoding is described in Table
* \ref{tab:privmode}. A debugger can change this value to change
* the hart's privilege mode when exiting Debug Mode.
*
* Not all privilege modes are supported on all harts. If the
* encoding written is not supported or the debugger is not allowed to
* change to it, the hart may change to any supported privilege mode.
*/
#define CSR_DCSR_PRV_OFFSET 0ULL
#define CSR_DCSR_PRV_LENGTH 2ULL
#define CSR_DCSR_PRV 3ULL
#define CSR_DPC 0x7b1
#define CSR_DPC_DPC_OFFSET 0ULL
#define CSR_DPC_DPC_LENGTH(DXLEN) (DXLEN)
#define CSR_DPC_DPC(DXLEN) ((1ULL << (DXLEN)) + -1ULL)
#define CSR_DSCRATCH0 0x7b2
#define CSR_DSCRATCH0_DSCRATCH0_OFFSET 0ULL
#define CSR_DSCRATCH0_DSCRATCH0_LENGTH(DXLEN) (DXLEN)
#define CSR_DSCRATCH0_DSCRATCH0(DXLEN) ((1ULL << (DXLEN)) + -1ULL)
#define CSR_DSCRATCH1 0x7b3
#define CSR_DSCRATCH1_DSCRATCH1_OFFSET 0ULL
#define CSR_DSCRATCH1_DSCRATCH1_LENGTH(DXLEN) (DXLEN)
#define CSR_DSCRATCH1_DSCRATCH1(DXLEN) ((1ULL << (DXLEN)) + -1ULL)
#define CSR_TSELECT 0x7a0
#define CSR_TSELECT_INDEX_OFFSET 0ULL
#define CSR_TSELECT_INDEX_LENGTH(XLEN) (XLEN)
#define CSR_TSELECT_INDEX(XLEN) ((1ULL << (XLEN)) + -1ULL)
#define CSR_TDATA1 0x7a1
#define CSR_TDATA1_TYPE_OFFSET(XLEN) ((XLEN) + -4ULL)
#define CSR_TDATA1_TYPE_LENGTH 4ULL
#define CSR_TDATA1_TYPE(XLEN) (0xfULL * (1ULL << ((XLEN) + -4ULL)))
/*
* none: There is no trigger at this \RcsrTselect.
*/
#define CSR_TDATA1_TYPE_NONE 0
/*
* legacy: The trigger is a legacy SiFive address match trigger. These
* should not be implemented and aren't further documented here.
*/
#define CSR_TDATA1_TYPE_LEGACY 1
/*
* mcontrol: The trigger is an address/data match trigger. The remaining bits
* in this register act as described in \RcsrMcontrol.
*/
#define CSR_TDATA1_TYPE_MCONTROL 2
/*
* icount: The trigger is an instruction count trigger. The remaining bits
* in this register act as described in \RcsrIcount.
*/
#define CSR_TDATA1_TYPE_ICOUNT 3
/*
* itrigger: The trigger is an interrupt trigger. The remaining bits
* in this register act as described in \RcsrItrigger.
*/
#define CSR_TDATA1_TYPE_ITRIGGER 4
/*
* etrigger: The trigger is an exception trigger. The remaining bits
* in this register act as described in \RcsrEtrigger.
*/
#define CSR_TDATA1_TYPE_ETRIGGER 5
/*
* mcontrol6: The trigger is an address/data match trigger. The remaining bits
* in this register act as described in \RcsrMcontrolSix. This is similar
* to a type 2 trigger, but provides additional functionality and
* should be used instead of type 2 in newer implementations.
*/
#define CSR_TDATA1_TYPE_MCONTROL6 6
/*
* tmexttrigger: The trigger is a trigger source external to the TM. The
* remaining bits in this register act as described in \RcsrTmexttrigger.
*/
#define CSR_TDATA1_TYPE_TMEXTTRIGGER 7
/*
* custom: These trigger types are available for non-standard use.
*/
#define CSR_TDATA1_TYPE_CUSTOM_LOW 12
#define CSR_TDATA1_TYPE_CUSTOM_HIGH 14
/*
* disabled: This trigger is disabled. In this state, \RcsrTdataTwo and
* \RcsrTdataThree can be written with any value that is supported for
* any of the types this trigger implements.
* The remaining bits in this register, except for \FcsrTdataOneDmode,
* are ignored.
*/
#define CSR_TDATA1_TYPE_DISABLED 15
/*
* Other values are reserved for future use.
*/
/*
* If \FcsrTdataOneType is 0, then this bit is hard-wired to 0.
*/
#define CSR_TDATA1_DMODE_OFFSET(XLEN) ((XLEN) + -5ULL)
#define CSR_TDATA1_DMODE_LENGTH 1ULL
#define CSR_TDATA1_DMODE(XLEN) (1ULL << ((XLEN) + -5ULL))
/*
* both: Both Debug and M-mode can write the {\tt tdata} registers at the
* selected \RcsrTselect.
*/
#define CSR_TDATA1_DMODE_BOTH 0
/*
* dmode: Only Debug Mode can write the {\tt tdata} registers at the
* selected \RcsrTselect. Writes from other modes are ignored.
*/
#define CSR_TDATA1_DMODE_DMODE 1
/*
* This bit is only writable from Debug Mode.
* In ordinary use, external debuggers will always set this bit when
* configuring a trigger.
* When clearing this bit, debuggers should also set the action field
* (whose location depends on \FcsrTdataOneType) to something other
* than 1.
*/
/*
* If \FcsrTdataOneType is 0, then this field is hard-wired to 0.
*
* Trigger-specific data.
*/
#define CSR_TDATA1_DATA_OFFSET 0ULL
#define CSR_TDATA1_DATA_LENGTH(XLEN) ((XLEN) + -5ULL)
#define CSR_TDATA1_DATA(XLEN) ((1ULL << ((XLEN) + -5ULL)) + -1ULL)
#define CSR_TDATA2 0x7a2
#define CSR_TDATA2_DATA_OFFSET 0ULL
#define CSR_TDATA2_DATA_LENGTH(XLEN) (XLEN)
#define CSR_TDATA2_DATA(XLEN) ((1ULL << (XLEN)) + -1ULL)
#define CSR_TDATA3 0x7a3
#define CSR_TDATA3_DATA_OFFSET 0ULL
#define CSR_TDATA3_DATA_LENGTH(XLEN) (XLEN)
#define CSR_TDATA3_DATA(XLEN) ((1ULL << (XLEN)) + -1ULL)
#define CSR_TINFO 0x7a4
/*
* Contains the version of the Sdtrig extension implemented.
*/
#define CSR_TINFO_VERSION_OFFSET 0x18ULL
#define CSR_TINFO_VERSION_LENGTH 8ULL
#define CSR_TINFO_VERSION 0xff000000ULL
/*
* 0: Supports triggers as described in this spec at commit 5a5c078,
* made on February 2, 2023.
*
* \begin{steps}{In these older versions:}
* \item \RcsrMcontrolSix has a timing bit identical to
* \FcsrMcontrolTiming
* \item \FcsrMcontrolSixHitZero behaves just as \FcsrMcontrolHit.
* \item \FcsrMcontrolSixHitOne is read-only 0.
* \item Encodings for \FcsrMcontrolSixSize for access sizes larger
* than 64 bits are different.
* \end{steps}
*/
#define CSR_TINFO_VERSION_0 0
/*
* 1: Supports triggers as described in the ratified version 1.0 of
* this document.
*/
#define CSR_TINFO_VERSION_1 1
/*
* One bit for each possible \FcsrTdataOneType enumerated in \RcsrTdataOne. Bit N
* corresponds to type N. If the bit is set, then that type is
* supported by the currently selected trigger.
*
* If the currently selected trigger doesn't exist, this field
* contains 1.
*/
#define CSR_TINFO_INFO_OFFSET 0ULL
#define CSR_TINFO_INFO_LENGTH 0x10ULL
#define CSR_TINFO_INFO 0xffffULL
#define CSR_TCONTROL 0x7a5
/*
* M-mode previous trigger enable field.
*
* \FcsrTcontrolMpte and \FcsrTcontrolMte provide one solution to a problem
* regarding triggers with action=0 firing in M-mode trap handlers. See
* Section~\ref{sec:nativetrigger} for more details.
*
* When any trap into M-mode is taken, \FcsrTcontrolMpte is set to the value of
* \FcsrTcontrolMte.
*/
#define CSR_TCONTROL_MPTE_OFFSET 7ULL
#define CSR_TCONTROL_MPTE_LENGTH 1ULL
#define CSR_TCONTROL_MPTE 0x80ULL
/*
* M-mode trigger enable field.
*/
#define CSR_TCONTROL_MTE_OFFSET 3ULL
#define CSR_TCONTROL_MTE_LENGTH 1ULL
#define CSR_TCONTROL_MTE 8ULL
/*
* disabled: Triggers with action=0 do not match/fire while the hart is in M-mode.
*/
#define CSR_TCONTROL_MTE_DISABLED 0
/*
* enabled: Triggers do match/fire while the hart is in M-mode.
*/
#define CSR_TCONTROL_MTE_ENABLED 1
/*
* When any trap into M-mode is taken, \FcsrTcontrolMte is set to 0. When {\tt
* mret} is executed, \FcsrTcontrolMte is set to the value of \FcsrTcontrolMpte.
*/
#define CSR_HCONTEXT 0x6a8
#define CSR_SCONTEXT 0x5a8
/*
* Supervisor mode software can write a context number to this
* register, which can be used to set triggers that only fire in that
* specific context.
*
* An implementation may tie any number of high bits in this field to
* 0. It's recommended to implement no more than 16 bits on RV32, and
* 34 on RV64.
*/
#define CSR_SCONTEXT_DATA_OFFSET 0ULL
#define CSR_SCONTEXT_DATA_LENGTH(XLEN) (XLEN)
#define CSR_SCONTEXT_DATA(XLEN) ((1ULL << (XLEN)) + -1ULL)
#define CSR_MCONTEXT 0x7a8
/*
* M-Mode or HS-Mode (using \RcsrHcontext) software can write a context
* number to this register, which can be used to set triggers that only
* fire in that specific context.
*
* An implementation may tie any number of upper bits in this field to
* 0. If the H extension is not implemented, it's recommended to implement
* no more than 6 bits on RV32 and 13 on RV64 (as visible through the
* \RcsrMcontext register). If the H extension is implemented,
* it's recommended to implement no more than 7 bits on RV32
* and 14 on RV64.
*/
#define CSR_MCONTEXT_HCONTEXT_OFFSET 0ULL
#define CSR_MCONTEXT_HCONTEXT_LENGTH(XLEN) (XLEN)
#define CSR_MCONTEXT_HCONTEXT(XLEN) ((1ULL << (XLEN)) + -1ULL)
#define CSR_MSCONTEXT 0x7aa
#define CSR_MCONTROL 0x7a1
#define CSR_MCONTROL_TYPE_OFFSET(XLEN) ((XLEN) + -4ULL)
#define CSR_MCONTROL_TYPE_LENGTH 4ULL
#define CSR_MCONTROL_TYPE(XLEN) (0xfULL * (1ULL << ((XLEN) + -4ULL)))
#define CSR_MCONTROL_DMODE_OFFSET(XLEN) ((XLEN) + -5ULL)
#define CSR_MCONTROL_DMODE_LENGTH 1ULL
#define CSR_MCONTROL_DMODE(XLEN) (1ULL << ((XLEN) + -5ULL))
/*
* Specifies the largest naturally aligned powers-of-two (NAPOT) range
* supported by the hardware when \FcsrMcontrolMatch is 1. The value is the
* logarithm base 2 of the number of bytes in that range.
* A value of 0 indicates \FcsrMcontrolMatch 1 is not supported.
* A value of 63 corresponds to the maximum NAPOT range, which is
* $2^{63}$ bytes in size.
*/
#define CSR_MCONTROL_MASKMAX_OFFSET(XLEN) ((XLEN) + -0xbULL)
#define CSR_MCONTROL_MASKMAX_LENGTH 6ULL
#define CSR_MCONTROL_MASKMAX(XLEN) (0x3fULL * (1ULL << ((XLEN) + -0xbULL)))
/*
* This field only exists when XLEN is at least 64.
* It contains the 2 high bits of the access size. The low bits
* come from \FcsrMcontrolSizelo. See \FcsrMcontrolSizelo for how this
* is used.
*/
#define CSR_MCONTROL_SIZEHI_OFFSET 0x15ULL
#define CSR_MCONTROL_SIZEHI_LENGTH 2ULL
#define CSR_MCONTROL_SIZEHI 0x600000ULL
/*
* If this bit is implemented then it must become set when this
* trigger fires and may become set when this trigger matches.
* The trigger's user can set or clear it at any
* time. It is used to determine which
* trigger(s) matched. If the bit is not implemented, it is always 0
* and writing it has no effect.
*/
#define CSR_MCONTROL_HIT_OFFSET 0x14ULL
#define CSR_MCONTROL_HIT_LENGTH 1ULL
#define CSR_MCONTROL_HIT 0x100000ULL
/*
* This bit determines the contents of the XLEN-bit compare values.
*/
#define CSR_MCONTROL_SELECT_OFFSET 0x13ULL
#define CSR_MCONTROL_SELECT_LENGTH 1ULL
#define CSR_MCONTROL_SELECT 0x80000ULL
/*
* address: There is at least one compare value and it contains the lowest
* virtual address of the access.
* It is recommended that there are additional compare values for
* the other accessed virtual addresses.
* (E.g. on a 32-bit read from 0x4000, the lowest address is 0x4000
* and the other addresses are 0x4001, 0x4002, and 0x4003.)
*/
#define CSR_MCONTROL_SELECT_ADDRESS 0
/*
* data: There is exactly one compare value and it contains the data
* value loaded or stored, or the instruction executed.
* Any bits beyond the size of the data access will contain 0.
*/
#define CSR_MCONTROL_SELECT_DATA 1
#define CSR_MCONTROL_TIMING_OFFSET 0x12ULL
#define CSR_MCONTROL_TIMING_LENGTH 1ULL
#define CSR_MCONTROL_TIMING 0x40000ULL
/*
* before: The action for this trigger will be taken just before the
* instruction that triggered it is retired, but after all preceding
* instructions are retired. \Rxepc or \RcsrDpc (depending
* on \FcsrMcontrolAction) must be set to the virtual address of the
* instruction that matched.
*
* If this is combined with \FcsrMcontrolLoad and
* \FcsrMcontrolSelect=1 then a memory access will be
* performed (including any side effects of performing such an access) even
* though the load will not update its destination register. Debuggers
* should consider this when setting such breakpoints on, for example,
* memory-mapped I/O addresses.
*
* If an instruction matches this trigger and the instruction performs
* multiple memory accesses, it is \unspecified which memory accesses
* have completed before the trigger fires.
*/
#define CSR_MCONTROL_TIMING_BEFORE 0
/*
* after: The action for this trigger will be taken after the instruction
* that triggered it is retired. It should be taken before the next
* instruction is retired, but it is better to implement triggers imprecisely
* than to not implement them at all. \Rxepc or
* \RcsrDpc (depending on \FcsrMcontrolAction) must be set to
* the virtual address of the next instruction that must be executed to
* preserve the program flow.
*/
#define CSR_MCONTROL_TIMING_AFTER 1
/*
* Most hardware will only implement one timing or the other, possibly
* dependent on \FcsrMcontrolSelect, \FcsrMcontrolExecute,
* \FcsrMcontrolLoad, and \FcsrMcontrolStore. This bit
* primarily exists for the hardware to communicate to the debugger
* what will happen. Hardware may implement the bit fully writable, in
* which case the debugger has a little more control.
*
* Data load triggers with \FcsrMcontrolTiming of 0 will result in the same load
* happening again when the debugger lets the hart run. For data load
* triggers, debuggers must first attempt to set the breakpoint with
* \FcsrMcontrolTiming of 1.
*
* If a trigger with \FcsrMcontrolTiming of 0 matches, it is
* implementation-dependent whether that prevents a trigger with
* \FcsrMcontrolTiming of 1 matching as well.
*/
/*
* This field contains the 2 low bits of the access size. The high bits come
* from \FcsrMcontrolSizehi. The combined value is interpreted as follows:
*/
#define CSR_MCONTROL_SIZELO_OFFSET 0x10ULL
#define CSR_MCONTROL_SIZELO_LENGTH 2ULL
#define CSR_MCONTROL_SIZELO 0x30000ULL
/*
* any: The trigger will attempt to match against an access of any size.
* The behavior is only well-defined if $|select|=0$, or if the access
* size is XLEN.
*/
#define CSR_MCONTROL_SIZELO_ANY 0
/*
* 8bit: The trigger will only match against 8-bit memory accesses.
*/
#define CSR_MCONTROL_SIZELO_8BIT 1
/*
* 16bit: The trigger will only match against 16-bit memory accesses or
* execution of 16-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_16BIT 2
/*
* 32bit: The trigger will only match against 32-bit memory accesses or
* execution of 32-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_32BIT 3
/*
* 48bit: The trigger will only match against execution of 48-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_48BIT 4
/*
* 64bit: The trigger will only match against 64-bit memory accesses or
* execution of 64-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_64BIT 5
/*
* 80bit: The trigger will only match against execution of 80-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_80BIT 6
/*
* 96bit: The trigger will only match against execution of 96-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_96BIT 7
/*
* 112bit: The trigger will only match against execution of 112-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_112BIT 8
/*
* 128bit: The trigger will only match against 128-bit memory accesses or
* execution of 128-bit instructions.
*/
#define CSR_MCONTROL_SIZELO_128BIT 9
/*
* An implementation must support the value of 0, but all other values
* are optional. When an implementation supports address triggers
* (\FcsrMcontrolSelect=0), it is recommended that those triggers
* support every access size that the hart supports, as well as for
* every instruction size that the hart supports.
*
* Implementations such as RV32D or RV64V are able to perform loads
* and stores that are wider than XLEN. Custom extensions may also
* support instructions that are wider than XLEN. Because
* \RcsrTdataTwo is of size XLEN, there is a known limitation that
* data value triggers (\FcsrMcontrolSelect=1) can only be supported
* for access sizes up to XLEN bits. When an implementation supports
* data value triggers (\FcsrMcontrolSelect=1), it is recommended
* that those triggers support every access size up to XLEN that the
* hart supports, as well as for every instruction length up to XLEN
* that the hart supports.
*/
/*
* The action to take when the trigger fires. The values are explained
* in Table~\ref{tab:action}.
*/
#define CSR_MCONTROL_ACTION_OFFSET 0xcULL
#define CSR_MCONTROL_ACTION_LENGTH 4ULL
#define CSR_MCONTROL_ACTION 0xf000ULL
/*
* breakpoint:
*/
#define CSR_MCONTROL_ACTION_BREAKPOINT 0
/*
* debug mode:
*/
#define CSR_MCONTROL_ACTION_DEBUG_MODE 1
/*
* trace on:
*/
#define CSR_MCONTROL_ACTION_TRACE_ON 2
/*
* trace off:
*/
#define CSR_MCONTROL_ACTION_TRACE_OFF 3
/*
* trace notify:
*/
#define CSR_MCONTROL_ACTION_TRACE_NOTIFY 4
/*
* external0:
*/
#define CSR_MCONTROL_ACTION_EXTERNAL0 8
/*
* external1:
*/
#define CSR_MCONTROL_ACTION_EXTERNAL1 9
#define CSR_MCONTROL_CHAIN_OFFSET 0xbULL
#define CSR_MCONTROL_CHAIN_LENGTH 1ULL
#define CSR_MCONTROL_CHAIN 0x800ULL
/*
* disabled: When this trigger matches, the configured action is taken.
*/
#define CSR_MCONTROL_CHAIN_DISABLED 0
/*
* enabled: While this trigger does not match, it prevents the trigger with
* the next index from matching.
*/
#define CSR_MCONTROL_CHAIN_ENABLED 1
/*
* A trigger chain starts on the first trigger with $|chain|=1$ after
* a trigger with $|chain|=0$, or simply on the first trigger if that
* has $|chain|=1$. It ends on the first trigger after that which has
* $|chain|=0$. This final trigger is part of the chain. The action
* on all but the final trigger is ignored. The action on that final
* trigger will be taken if and only if all the triggers in the chain
* match at the same time.
*
* Debuggers should not terminate a chain with a trigger with a
* different type. It is undefined when exactly such a chain fires.
*
* Because \FcsrMcontrolChain affects the next trigger, hardware must zero it in
* writes to \RcsrMcontrol that set \FcsrTdataOneDmode to 0 if the next trigger has
* \FcsrTdataOneDmode of 1.
* In addition hardware should ignore writes to \RcsrMcontrol that set
* \FcsrTdataOneDmode to 1 if the previous trigger has both \FcsrTdataOneDmode of 0 and
* \FcsrMcontrolChain of 1. Debuggers must avoid the latter case by checking
* \FcsrMcontrolChain on the previous trigger if they're writing \RcsrMcontrol.
*
* Implementations that wish to limit the maximum length of a trigger
* chain (eg. to meet timing requirements) may do so by zeroing
* \FcsrMcontrolChain in writes to \RcsrMcontrol that would make the chain too long.
*/
#define CSR_MCONTROL_MATCH_OFFSET 7ULL
#define CSR_MCONTROL_MATCH_LENGTH 4ULL
#define CSR_MCONTROL_MATCH 0x780ULL
/*
* equal: Matches when any compare value equals \RcsrTdataTwo.
*/
#define CSR_MCONTROL_MATCH_EQUAL 0
/*
* napot: Matches when the top $M$ bits of any compare value match the top
* $M$ bits of \RcsrTdataTwo.
* $M$ is $|XLEN|-1$ minus the index of the least-significant
* bit containing 0 in \RcsrTdataTwo. Debuggers should only write values
* to \RcsrTdataTwo such that $M + $\FcsrMcontrolMaskmax$ \geq |XLEN|$
* and $M\gt0$ , otherwise it's undefined on what conditions the
* trigger will match.
*/
#define CSR_MCONTROL_MATCH_NAPOT 1
/*
* ge: Matches when any compare value is greater than (unsigned) or
* equal to \RcsrTdataTwo.
*/
#define CSR_MCONTROL_MATCH_GE 2
/*
* lt: Matches when any compare value is less than (unsigned)
* \RcsrTdataTwo.
*/
#define CSR_MCONTROL_MATCH_LT 3
/*
* mask low: Matches when $\frac{|XLEN|}{2}-1$:$0$ of any compare value
* equals $\frac{|XLEN|}{2}-1$:$0$ of \RcsrTdataTwo after
* $\frac{|XLEN|}{2}-1$:$0$ of the compare value is ANDed with
* $|XLEN|-1$:$\frac{|XLEN|}{2}$ of \RcsrTdataTwo.
*/
#define CSR_MCONTROL_MATCH_MASK_LOW 4
/*
* mask high: Matches when $|XLEN|-1$:$\frac{|XLEN|}{2}$ of any compare
* value equals $\frac{|XLEN|}{2}-1$:$0$ of \RcsrTdataTwo after
* $|XLEN|-1$:$\frac{|XLEN|}{2}$ of the compare value is ANDed with
* $|XLEN|-1$:$\frac{|XLEN|}{2}$ of \RcsrTdataTwo.
*/
#define CSR_MCONTROL_MATCH_MASK_HIGH 5
/*
* not equal: Matches when \FcsrMcontrolMatch$=0$ would not match.
*/
#define CSR_MCONTROL_MATCH_NOT_EQUAL 8
/*
* not napot: Matches when \FcsrMcontrolMatch$=1$ would not match.
*/
#define CSR_MCONTROL_MATCH_NOT_NAPOT 9
/*
* not mask low: Matches when \FcsrMcontrolMatch$=4$ would not match.
*/
#define CSR_MCONTROL_MATCH_NOT_MASK_LOW 12
/*
* not mask high: Matches when \FcsrMcontrolMatch$=5$ would not match.
*/
#define CSR_MCONTROL_MATCH_NOT_MASK_HIGH 13
/*
* Other values are reserved for future use.
*
* All comparisons only look at the lower XLEN (in the current mode)
* bits of the compare values and of \RcsrTdataTwo.
* When \FcsrMcontrolSelect=1 and access size is N, this is further
* reduced, and comparisons only look at the lower N bits of the
* compare values and of \RcsrTdataTwo.
*/
/*
* When set, enable this trigger in M-mode.
*/
#define CSR_MCONTROL_M_OFFSET 6ULL