1
2
3
4
5
6
7
8#include "qemu/osdep.h"
9#include "qemu/log.h"
10#include "cpu.h"
11#include "internals.h"
12#include "cpregs.h"
13#include "exec/exec-all.h"
14#include "exec/helper-proto.h"
15#include "sysemu/tcg.h"
16
17#ifdef CONFIG_TCG
18
19static int arm_debug_target_el(CPUARMState *env)
20{
21 bool secure = arm_is_secure(env);
22 bool route_to_el2 = false;
23
24 if (arm_feature(env, ARM_FEATURE_M)) {
25 return 1;
26 }
27
28 if (arm_is_el2_enabled(env)) {
29 route_to_el2 = env->cp15.hcr_el2 & HCR_TGE ||
30 env->cp15.mdcr_el2 & MDCR_TDE;
31 }
32
33 if (route_to_el2) {
34 return 2;
35 } else if (arm_feature(env, ARM_FEATURE_EL3) &&
36 !arm_el_is_aa64(env, 3) && secure) {
37 return 3;
38 } else {
39 return 1;
40 }
41}
42
43
44
45
46
47G_NORETURN static void
48raise_exception_debug(CPUARMState *env, uint32_t excp, uint32_t syndrome)
49{
50 int debug_el = arm_debug_target_el(env);
51 int cur_el = arm_current_el(env);
52
53
54
55
56
57
58 assert(debug_el >= cur_el);
59 syndrome |= (debug_el == cur_el) << ARM_EL_EC_SHIFT;
60 raise_exception(env, excp, syndrome, debug_el);
61}
62
63
64static bool aa64_generate_debug_exceptions(CPUARMState *env)
65{
66 int cur_el = arm_current_el(env);
67 int debug_el;
68
69 if (cur_el == 3) {
70 return false;
71 }
72
73
74 if (arm_is_secure_below_el3(env)
75 && extract32(env->cp15.mdcr_el3, 16, 1)) {
76 return false;
77 }
78
79
80
81
82
83 debug_el = arm_debug_target_el(env);
84
85 if (cur_el == debug_el) {
86 return extract32(env->cp15.mdscr_el1, 13, 1)
87 && !(env->daif & PSTATE_D);
88 }
89
90
91 return debug_el > cur_el;
92}
93
94static bool aa32_generate_debug_exceptions(CPUARMState *env)
95{
96 int el = arm_current_el(env);
97
98 if (el == 0 && arm_el_is_aa64(env, 1)) {
99 return aa64_generate_debug_exceptions(env);
100 }
101
102 if (arm_is_secure(env)) {
103 int spd;
104
105 if (el == 0 && (env->cp15.sder & 1)) {
106
107
108
109
110
111 return true;
112 }
113
114 spd = extract32(env->cp15.mdcr_el3, 14, 2);
115 switch (spd) {
116 case 1:
117
118 case 0:
119
120
121
122
123
124
125 return true;
126 case 2:
127 return false;
128 case 3:
129 return true;
130 }
131 }
132
133 return el != 2;
134}
135
136
137
138
139
140
141
142
143
144
145
146
147
148bool arm_generate_debug_exceptions(CPUARMState *env)
149{
150 if ((env->cp15.oslsr_el1 & 1) || (env->cp15.osdlr_el1 & 1)) {
151 return false;
152 }
153 if (is_a64(env)) {
154 return aa64_generate_debug_exceptions(env);
155 } else {
156 return aa32_generate_debug_exceptions(env);
157 }
158}
159
160
161
162
163
164bool arm_singlestep_active(CPUARMState *env)
165{
166 return extract32(env->cp15.mdscr_el1, 0, 1)
167 && arm_el_is_aa64(env, arm_debug_target_el(env))
168 && arm_generate_debug_exceptions(env);
169}
170
171
172static bool linked_bp_matches(ARMCPU *cpu, int lbn)
173{
174 CPUARMState *env = &cpu->env;
175 uint64_t bcr = env->cp15.dbgbcr[lbn];
176 int brps = arm_num_brps(cpu);
177 int ctx_cmps = arm_num_ctx_cmps(cpu);
178 int bt;
179 uint32_t contextidr;
180 uint64_t hcr_el2;
181
182
183
184
185
186
187
188
189 if (lbn >= brps || lbn < (brps - ctx_cmps)) {
190 return false;
191 }
192
193 bcr = env->cp15.dbgbcr[lbn];
194
195 if (extract64(bcr, 0, 1) == 0) {
196
197 return false;
198 }
199
200 bt = extract64(bcr, 20, 4);
201 hcr_el2 = arm_hcr_el2_eff(env);
202
203 switch (bt) {
204 case 3:
205 switch (arm_current_el(env)) {
206 default:
207
208 return false;
209 case 2:
210 if (!(hcr_el2 & HCR_E2H)) {
211
212 return false;
213 }
214 contextidr = env->cp15.contextidr_el[2];
215 break;
216 case 1:
217 contextidr = env->cp15.contextidr_el[1];
218 break;
219 case 0:
220 if ((hcr_el2 & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) {
221 contextidr = env->cp15.contextidr_el[2];
222 } else {
223 contextidr = env->cp15.contextidr_el[1];
224 }
225 break;
226 }
227 break;
228
229 case 7:
230 contextidr = env->cp15.contextidr_el[1];
231 break;
232 case 13:
233 contextidr = env->cp15.contextidr_el[2];
234 break;
235
236 case 9:
237 case 11:
238 case 15:
239 default:
240
241
242
243
244 return false;
245 }
246
247
248
249
250
251
252 return contextidr == (uint32_t)env->cp15.dbgbvr[lbn];
253}
254
255static bool bp_wp_matches(ARMCPU *cpu, int n, bool is_wp)
256{
257 CPUARMState *env = &cpu->env;
258 uint64_t cr;
259 int pac, hmc, ssc, wt, lbn;
260
261
262
263
264 bool is_secure = arm_is_secure(env);
265 int access_el = arm_current_el(env);
266
267 if (is_wp) {
268 CPUWatchpoint *wp = env->cpu_watchpoint[n];
269
270 if (!wp || !(wp->flags & BP_WATCHPOINT_HIT)) {
271 return false;
272 }
273 cr = env->cp15.dbgwcr[n];
274 if (wp->hitattrs.user) {
275
276
277
278
279
280 access_el = 0;
281 }
282 } else {
283 uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
284
285 if (!env->cpu_breakpoint[n] || env->cpu_breakpoint[n]->pc != pc) {
286 return false;
287 }
288 cr = env->cp15.dbgbcr[n];
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303 pac = FIELD_EX64(cr, DBGWCR, PAC);
304 hmc = FIELD_EX64(cr, DBGWCR, HMC);
305 ssc = FIELD_EX64(cr, DBGWCR, SSC);
306
307 switch (ssc) {
308 case 0:
309 break;
310 case 1:
311 case 3:
312 if (is_secure) {
313 return false;
314 }
315 break;
316 case 2:
317 if (!is_secure) {
318 return false;
319 }
320 break;
321 }
322
323 switch (access_el) {
324 case 3:
325 case 2:
326 if (!hmc) {
327 return false;
328 }
329 break;
330 case 1:
331 if (extract32(pac, 0, 1) == 0) {
332 return false;
333 }
334 break;
335 case 0:
336 if (extract32(pac, 1, 1) == 0) {
337 return false;
338 }
339 break;
340 default:
341 g_assert_not_reached();
342 }
343
344 wt = FIELD_EX64(cr, DBGWCR, WT);
345 lbn = FIELD_EX64(cr, DBGWCR, LBN);
346
347 if (wt && !linked_bp_matches(cpu, lbn)) {
348 return false;
349 }
350
351 return true;
352}
353
354static bool check_watchpoints(ARMCPU *cpu)
355{
356 CPUARMState *env = &cpu->env;
357 int n;
358
359
360
361
362
363 if (extract32(env->cp15.mdscr_el1, 15, 1) == 0
364 || !arm_generate_debug_exceptions(env)) {
365 return false;
366 }
367
368 for (n = 0; n < ARRAY_SIZE(env->cpu_watchpoint); n++) {
369 if (bp_wp_matches(cpu, n, true)) {
370 return true;
371 }
372 }
373 return false;
374}
375
376bool arm_debug_check_breakpoint(CPUState *cs)
377{
378 ARMCPU *cpu = ARM_CPU(cs);
379 CPUARMState *env = &cpu->env;
380 target_ulong pc;
381 int n;
382
383
384
385
386
387 if (extract32(env->cp15.mdscr_el1, 15, 1) == 0
388 || !arm_generate_debug_exceptions(env)) {
389 return false;
390 }
391
392
393
394
395
396 if (arm_singlestep_active(env) && !(env->pstate & PSTATE_SS)) {
397 return false;
398 }
399
400
401
402
403 pc = is_a64(env) ? env->pc : env->regs[15];
404 if ((is_a64(env) || !env->thumb) && (pc & 3) != 0) {
405 return false;
406 }
407
408
409
410
411
412
413
414 for (n = 0; n < ARRAY_SIZE(env->cpu_breakpoint); n++) {
415 if (bp_wp_matches(cpu, n, false)) {
416 return true;
417 }
418 }
419 return false;
420}
421
422bool arm_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)
423{
424
425
426
427
428 ARMCPU *cpu = ARM_CPU(cs);
429
430 return check_watchpoints(cpu);
431}
432
433
434
435
436
437static uint32_t arm_debug_exception_fsr(CPUARMState *env)
438{
439 ARMMMUFaultInfo fi = { .type = ARMFault_Debug };
440 int target_el = arm_debug_target_el(env);
441 bool using_lpae;
442
443 if (arm_feature(env, ARM_FEATURE_M)) {
444 using_lpae = false;
445 } else if (target_el == 2 || arm_el_is_aa64(env, target_el)) {
446 using_lpae = true;
447 } else if (arm_feature(env, ARM_FEATURE_PMSA) &&
448 arm_feature(env, ARM_FEATURE_V8)) {
449 using_lpae = true;
450 } else if (arm_feature(env, ARM_FEATURE_LPAE) &&
451 (env->cp15.tcr_el[target_el] & TTBCR_EAE)) {
452 using_lpae = true;
453 } else {
454 using_lpae = false;
455 }
456
457 if (using_lpae) {
458 return arm_fi_to_lfsc(&fi);
459 } else {
460 return arm_fi_to_sfsc(&fi);
461 }
462}
463
464void arm_debug_excp_handler(CPUState *cs)
465{
466
467
468
469
470 ARMCPU *cpu = ARM_CPU(cs);
471 CPUARMState *env = &cpu->env;
472 CPUWatchpoint *wp_hit = cs->watchpoint_hit;
473
474 if (wp_hit) {
475 if (wp_hit->flags & BP_CPU) {
476 bool wnr = (wp_hit->flags & BP_WATCHPOINT_HIT_WRITE) != 0;
477
478 cs->watchpoint_hit = NULL;
479
480 env->exception.fsr = arm_debug_exception_fsr(env);
481 env->exception.vaddress = wp_hit->hitaddr;
482 raise_exception_debug(env, EXCP_DATA_ABORT,
483 syn_watchpoint(0, 0, wnr));
484 }
485 } else {
486 uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
487
488
489
490
491
492
493
494 if (cpu_breakpoint_test(cs, pc, BP_GDB)
495 || !cpu_breakpoint_test(cs, pc, BP_CPU)) {
496 return;
497 }
498
499 env->exception.fsr = arm_debug_exception_fsr(env);
500
501
502
503
504
505 env->exception.vaddress = 0;
506 raise_exception_debug(env, EXCP_PREFETCH_ABORT, syn_breakpoint(0));
507 }
508}
509
510
511
512
513
514void HELPER(exception_bkpt_insn)(CPUARMState *env, uint32_t syndrome)
515{
516 int debug_el = arm_debug_target_el(env);
517 int cur_el = arm_current_el(env);
518
519
520 env->exception.fsr = arm_debug_exception_fsr(env);
521
522
523
524
525
526 env->exception.vaddress = 0;
527
528
529
530
531
532
533
534
535 if (debug_el < cur_el) {
536 debug_el = cur_el;
537 }
538 raise_exception(env, EXCP_BKPT, syndrome, debug_el);
539}
540
541void HELPER(exception_swstep)(CPUARMState *env, uint32_t syndrome)
542{
543 raise_exception_debug(env, EXCP_UDEF, syndrome);
544}
545
546void hw_watchpoint_update(ARMCPU *cpu, int n)
547{
548 CPUARMState *env = &cpu->env;
549 vaddr len = 0;
550 vaddr wvr = env->cp15.dbgwvr[n];
551 uint64_t wcr = env->cp15.dbgwcr[n];
552 int mask;
553 int flags = BP_CPU | BP_STOP_BEFORE_ACCESS;
554
555 if (env->cpu_watchpoint[n]) {
556 cpu_watchpoint_remove_by_ref(CPU(cpu), env->cpu_watchpoint[n]);
557 env->cpu_watchpoint[n] = NULL;
558 }
559
560 if (!FIELD_EX64(wcr, DBGWCR, E)) {
561
562 return;
563 }
564
565 switch (FIELD_EX64(wcr, DBGWCR, LSC)) {
566 case 0:
567
568 return;
569 case 1:
570 flags |= BP_MEM_READ;
571 break;
572 case 2:
573 flags |= BP_MEM_WRITE;
574 break;
575 case 3:
576 flags |= BP_MEM_ACCESS;
577 break;
578 }
579
580
581
582
583
584
585 mask = FIELD_EX64(wcr, DBGWCR, MASK);
586 if (mask == 1 || mask == 2) {
587
588
589
590
591
592 return;
593 } else if (mask) {
594
595 len = 1ULL << mask;
596
597
598
599
600
601 wvr &= ~(len - 1);
602 } else {
603
604 int bas = FIELD_EX64(wcr, DBGWCR, BAS);
605 int basstart;
606
607 if (extract64(wvr, 2, 1)) {
608
609
610
611
612 bas &= 0xf;
613 }
614
615 if (bas == 0) {
616
617 return;
618 }
619
620
621
622
623
624
625
626 basstart = ctz32(bas);
627 len = cto32(bas >> basstart);
628 wvr += basstart;
629 }
630
631 cpu_watchpoint_insert(CPU(cpu), wvr, len, flags,
632 &env->cpu_watchpoint[n]);
633}
634
635void hw_watchpoint_update_all(ARMCPU *cpu)
636{
637 int i;
638 CPUARMState *env = &cpu->env;
639
640
641
642
643
644 cpu_watchpoint_remove_all(CPU(cpu), BP_CPU);
645 memset(env->cpu_watchpoint, 0, sizeof(env->cpu_watchpoint));
646
647 for (i = 0; i < ARRAY_SIZE(cpu->env.cpu_watchpoint); i++) {
648 hw_watchpoint_update(cpu, i);
649 }
650}
651
652void hw_breakpoint_update(ARMCPU *cpu, int n)
653{
654 CPUARMState *env = &cpu->env;
655 uint64_t bvr = env->cp15.dbgbvr[n];
656 uint64_t bcr = env->cp15.dbgbcr[n];
657 vaddr addr;
658 int bt;
659 int flags = BP_CPU;
660
661 if (env->cpu_breakpoint[n]) {
662 cpu_breakpoint_remove_by_ref(CPU(cpu), env->cpu_breakpoint[n]);
663 env->cpu_breakpoint[n] = NULL;
664 }
665
666 if (!extract64(bcr, 0, 1)) {
667
668 return;
669 }
670
671 bt = extract64(bcr, 20, 4);
672
673 switch (bt) {
674 case 4:
675 case 5:
676 qemu_log_mask(LOG_UNIMP,
677 "arm: address mismatch breakpoint types not implemented\n");
678 return;
679 case 0:
680 case 1:
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 int bas = extract64(bcr, 5, 4);
707 addr = bvr & ~3ULL;
708 if (bas == 0) {
709 return;
710 }
711 if (bas == 0xc) {
712 addr += 2;
713 }
714 break;
715 }
716 case 2:
717 case 8:
718 case 10:
719 qemu_log_mask(LOG_UNIMP,
720 "arm: unlinked context breakpoint types not implemented\n");
721 return;
722 case 9:
723 case 11:
724 case 3:
725 default:
726
727
728
729
730
731
732 return;
733 }
734
735 cpu_breakpoint_insert(CPU(cpu), addr, flags, &env->cpu_breakpoint[n]);
736}
737
738void hw_breakpoint_update_all(ARMCPU *cpu)
739{
740 int i;
741 CPUARMState *env = &cpu->env;
742
743
744
745
746
747 cpu_breakpoint_remove_all(CPU(cpu), BP_CPU);
748 memset(env->cpu_breakpoint, 0, sizeof(env->cpu_breakpoint));
749
750 for (i = 0; i < ARRAY_SIZE(cpu->env.cpu_breakpoint); i++) {
751 hw_breakpoint_update(cpu, i);
752 }
753}
754
755#if !defined(CONFIG_USER_ONLY)
756
757vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len)
758{
759 ARMCPU *cpu = ARM_CPU(cs);
760 CPUARMState *env = &cpu->env;
761
762
763
764
765
766
767
768
769 if (arm_sctlr_b(env)) {
770 if (len == 1) {
771 addr ^= 3;
772 } else if (len == 2) {
773 addr ^= 2;
774 }
775 }
776
777 return addr;
778}
779
780#endif
781#endif
782
783
784
785
786
787static CPAccessResult access_tdosa(CPUARMState *env, const ARMCPRegInfo *ri,
788 bool isread)
789{
790 int el = arm_current_el(env);
791 uint64_t mdcr_el2 = arm_mdcr_el2_eff(env);
792 bool mdcr_el2_tdosa = (mdcr_el2 & MDCR_TDOSA) || (mdcr_el2 & MDCR_TDE) ||
793 (arm_hcr_el2_eff(env) & HCR_TGE);
794
795 if (el < 2 && mdcr_el2_tdosa) {
796 return CP_ACCESS_TRAP_EL2;
797 }
798 if (el < 3 && (env->cp15.mdcr_el3 & MDCR_TDOSA)) {
799 return CP_ACCESS_TRAP_EL3;
800 }
801 return CP_ACCESS_OK;
802}
803
804
805
806
807
808static CPAccessResult access_tdra(CPUARMState *env, const ARMCPRegInfo *ri,
809 bool isread)
810{
811 int el = arm_current_el(env);
812 uint64_t mdcr_el2 = arm_mdcr_el2_eff(env);
813 bool mdcr_el2_tdra = (mdcr_el2 & MDCR_TDRA) || (mdcr_el2 & MDCR_TDE) ||
814 (arm_hcr_el2_eff(env) & HCR_TGE);
815
816 if (el < 2 && mdcr_el2_tdra) {
817 return CP_ACCESS_TRAP_EL2;
818 }
819 if (el < 3 && (env->cp15.mdcr_el3 & MDCR_TDA)) {
820 return CP_ACCESS_TRAP_EL3;
821 }
822 return CP_ACCESS_OK;
823}
824
825
826
827
828
829static CPAccessResult access_tda(CPUARMState *env, const ARMCPRegInfo *ri,
830 bool isread)
831{
832 int el = arm_current_el(env);
833 uint64_t mdcr_el2 = arm_mdcr_el2_eff(env);
834 bool mdcr_el2_tda = (mdcr_el2 & MDCR_TDA) || (mdcr_el2 & MDCR_TDE) ||
835 (arm_hcr_el2_eff(env) & HCR_TGE);
836
837 if (el < 2 && mdcr_el2_tda) {
838 return CP_ACCESS_TRAP_EL2;
839 }
840 if (el < 3 && (env->cp15.mdcr_el3 & MDCR_TDA)) {
841 return CP_ACCESS_TRAP_EL3;
842 }
843 return CP_ACCESS_OK;
844}
845
846
847
848
849
850
851
852
853static CPAccessResult access_tdcc(CPUARMState *env, const ARMCPRegInfo *ri,
854 bool isread)
855{
856 int el = arm_current_el(env);
857 uint64_t mdcr_el2 = arm_mdcr_el2_eff(env);
858 bool mdscr_el1_tdcc = extract32(env->cp15.mdscr_el1, 12, 1);
859 bool mdcr_el2_tda = (mdcr_el2 & MDCR_TDA) || (mdcr_el2 & MDCR_TDE) ||
860 (arm_hcr_el2_eff(env) & HCR_TGE);
861 bool mdcr_el2_tdcc = cpu_isar_feature(aa64_fgt, env_archcpu(env)) &&
862 (mdcr_el2 & MDCR_TDCC);
863 bool mdcr_el3_tdcc = cpu_isar_feature(aa64_fgt, env_archcpu(env)) &&
864 (env->cp15.mdcr_el3 & MDCR_TDCC);
865
866 if (el < 1 && mdscr_el1_tdcc) {
867 return CP_ACCESS_TRAP;
868 }
869 if (el < 2 && (mdcr_el2_tda || mdcr_el2_tdcc)) {
870 return CP_ACCESS_TRAP_EL2;
871 }
872 if (el < 3 && ((env->cp15.mdcr_el3 & MDCR_TDA) || mdcr_el3_tdcc)) {
873 return CP_ACCESS_TRAP_EL3;
874 }
875 return CP_ACCESS_OK;
876}
877
878static void oslar_write(CPUARMState *env, const ARMCPRegInfo *ri,
879 uint64_t value)
880{
881
882
883
884
885 int oslock;
886
887 if (ri->state == ARM_CP_STATE_AA32) {
888 oslock = (value == 0xC5ACCE55);
889 } else {
890 oslock = value & 1;
891 }
892
893 env->cp15.oslsr_el1 = deposit32(env->cp15.oslsr_el1, 1, 1, oslock);
894}
895
896static void osdlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
897 uint64_t value)
898{
899 ARMCPU *cpu = env_archcpu(env);
900
901
902
903
904 if(arm_feature(env, ARM_FEATURE_AARCH64)
905 ? cpu_isar_feature(aa64_doublelock, cpu)
906 : cpu_isar_feature(aa32_doublelock, cpu)) {
907 env->cp15.osdlr_el1 = value & 1;
908 }
909}
910
911static void dbgclaimset_write(CPUARMState *env, const ARMCPRegInfo *ri,
912 uint64_t value)
913{
914 env->cp15.dbgclaim |= (value & 0xFF);
915}
916
917static uint64_t dbgclaimset_read(CPUARMState *env, const ARMCPRegInfo *ri)
918{
919
920 return 0xFF;
921}
922
923static void dbgclaimclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
924 uint64_t value)
925{
926 env->cp15.dbgclaim &= ~(value & 0xFF);
927}
928
929static const ARMCPRegInfo debug_cp_reginfo[] = {
930
931
932
933
934
935
936
937 { .name = "DBGDRAR", .cp = 14, .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 0,
938 .access = PL0_R, .accessfn = access_tdra,
939 .type = ARM_CP_CONST, .resetvalue = 0 },
940 { .name = "MDRAR_EL1", .state = ARM_CP_STATE_AA64,
941 .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 0,
942 .access = PL1_R, .accessfn = access_tdra,
943 .type = ARM_CP_CONST, .resetvalue = 0 },
944 { .name = "DBGDSAR", .cp = 14, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 0,
945 .access = PL0_R, .accessfn = access_tdra,
946 .type = ARM_CP_CONST, .resetvalue = 0 },
947
948 { .name = "MDSCR_EL1", .state = ARM_CP_STATE_BOTH,
949 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 2,
950 .access = PL1_RW, .accessfn = access_tda,
951 .fgt = FGT_MDSCR_EL1,
952 .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1),
953 .resetvalue = 0 },
954
955
956
957
958 { .name = "MDCCSR_EL0", .state = ARM_CP_STATE_AA64,
959 .opc0 = 2, .opc1 = 3, .crn = 0, .crm = 1, .opc2 = 0,
960 .access = PL0_R, .accessfn = access_tdcc,
961 .type = ARM_CP_CONST, .resetvalue = 0 },
962
963
964
965
966
967
968 { .name = "OSDTRRX_EL1", .state = ARM_CP_STATE_BOTH, .cp = 14,
969 .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 2,
970 .access = PL1_RW, .accessfn = access_tdcc,
971 .type = ARM_CP_CONST, .resetvalue = 0 },
972 { .name = "OSDTRTX_EL1", .state = ARM_CP_STATE_BOTH, .cp = 14,
973 .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 2,
974 .access = PL1_RW, .accessfn = access_tdcc,
975 .type = ARM_CP_CONST, .resetvalue = 0 },
976
977 { .name = "DBGDTR_EL0", .state = ARM_CP_STATE_BOTH, .cp = 14,
978 .opc0 = 2, .opc1 = 3, .crn = 0, .crm = 5, .opc2 = 0,
979 .access = PL0_RW, .accessfn = access_tdcc,
980 .type = ARM_CP_CONST, .resetvalue = 0 },
981
982
983
984
985
986 { .name = "OSECCR_EL1", .state = ARM_CP_STATE_BOTH, .cp = 14,
987 .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2,
988 .access = PL1_RW, .accessfn = access_tda,
989 .fgt = FGT_OSECCR_EL1,
990 .type = ARM_CP_CONST, .resetvalue = 0 },
991
992
993
994
995
996 { .name = "DBGDSCRint", .state = ARM_CP_STATE_AA32,
997 .cp = 14, .opc1 = 0, .crn = 0, .crm = 1, .opc2 = 0,
998 .type = ARM_CP_ALIAS,
999 .access = PL1_R, .accessfn = access_tda,
1000 .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1), },
1001 { .name = "OSLAR_EL1", .state = ARM_CP_STATE_BOTH,
1002 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 4,
1003 .access = PL1_W, .type = ARM_CP_NO_RAW,
1004 .accessfn = access_tdosa,
1005 .fgt = FGT_OSLAR_EL1,
1006 .writefn = oslar_write },
1007 { .name = "OSLSR_EL1", .state = ARM_CP_STATE_BOTH,
1008 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 4,
1009 .access = PL1_R, .resetvalue = 10,
1010 .accessfn = access_tdosa,
1011 .fgt = FGT_OSLSR_EL1,
1012 .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1) },
1013
1014 { .name = "OSDLR_EL1", .state = ARM_CP_STATE_BOTH,
1015 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 3, .opc2 = 4,
1016 .access = PL1_RW, .accessfn = access_tdosa,
1017 .fgt = FGT_OSDLR_EL1,
1018 .writefn = osdlr_write,
1019 .fieldoffset = offsetof(CPUARMState, cp15.osdlr_el1) },
1020
1021
1022
1023
1024 { .name = "DBGVCR",
1025 .cp = 14, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0,
1026 .access = PL1_RW, .accessfn = access_tda,
1027 .type = ARM_CP_NOP },
1028
1029
1030
1031
1032 { .name = "DBGVCR32_EL2", .state = ARM_CP_STATE_AA64,
1033 .opc0 = 2, .opc1 = 4, .crn = 0, .crm = 7, .opc2 = 0,
1034 .access = PL2_RW, .accessfn = access_tda,
1035 .type = ARM_CP_NOP | ARM_CP_EL3_NO_EL2_KEEP },
1036
1037
1038
1039
1040
1041 { .name = "MDCCINT_EL1", .state = ARM_CP_STATE_BOTH,
1042 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 0,
1043 .access = PL1_RW, .accessfn = access_tdcc,
1044 .type = ARM_CP_NOP },
1045
1046
1047
1048
1049
1050 { .name = "DBGCLAIMSET_EL1", .state = ARM_CP_STATE_BOTH,
1051 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 7, .crm = 8, .opc2 = 6,
1052 .type = ARM_CP_ALIAS,
1053 .access = PL1_RW, .accessfn = access_tda,
1054 .fgt = FGT_DBGCLAIM,
1055 .writefn = dbgclaimset_write, .readfn = dbgclaimset_read },
1056 { .name = "DBGCLAIMCLR_EL1", .state = ARM_CP_STATE_BOTH,
1057 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 7, .crm = 9, .opc2 = 6,
1058 .access = PL1_RW, .accessfn = access_tda,
1059 .fgt = FGT_DBGCLAIM,
1060 .writefn = dbgclaimclr_write, .raw_writefn = raw_write,
1061 .fieldoffset = offsetof(CPUARMState, cp15.dbgclaim) },
1062};
1063
1064static const ARMCPRegInfo debug_lpae_cp_reginfo[] = {
1065
1066 { .name = "DBGDRAR", .cp = 14, .crm = 1, .opc1 = 0,
1067 .access = PL0_R, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
1068 { .name = "DBGDSAR", .cp = 14, .crm = 2, .opc1 = 0,
1069 .access = PL0_R, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
1070};
1071
1072static void dbgwvr_write(CPUARMState *env, const ARMCPRegInfo *ri,
1073 uint64_t value)
1074{
1075 ARMCPU *cpu = env_archcpu(env);
1076 int i = ri->crm;
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089 value &= ~3ULL;
1090
1091 raw_write(env, ri, value);
1092 if (tcg_enabled()) {
1093 hw_watchpoint_update(cpu, i);
1094 }
1095}
1096
1097static void dbgwcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
1098 uint64_t value)
1099{
1100 ARMCPU *cpu = env_archcpu(env);
1101 int i = ri->crm;
1102
1103 raw_write(env, ri, value);
1104 if (tcg_enabled()) {
1105 hw_watchpoint_update(cpu, i);
1106 }
1107}
1108
1109static void dbgbvr_write(CPUARMState *env, const ARMCPRegInfo *ri,
1110 uint64_t value)
1111{
1112 ARMCPU *cpu = env_archcpu(env);
1113 int i = ri->crm;
1114
1115 raw_write(env, ri, value);
1116 if (tcg_enabled()) {
1117 hw_breakpoint_update(cpu, i);
1118 }
1119}
1120
1121static void dbgbcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
1122 uint64_t value)
1123{
1124 ARMCPU *cpu = env_archcpu(env);
1125 int i = ri->crm;
1126
1127
1128
1129
1130
1131 value = deposit64(value, 6, 1, extract64(value, 5, 1));
1132 value = deposit64(value, 8, 1, extract64(value, 7, 1));
1133
1134 raw_write(env, ri, value);
1135 if (tcg_enabled()) {
1136 hw_breakpoint_update(cpu, i);
1137 }
1138}
1139
1140void define_debug_regs(ARMCPU *cpu)
1141{
1142
1143
1144
1145
1146 int i;
1147 int wrps, brps, ctx_cmps;
1148
1149
1150
1151
1152
1153
1154 if (cpu->isar.dbgdidr != 0) {
1155 ARMCPRegInfo dbgdidr = {
1156 .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0,
1157 .opc1 = 0, .opc2 = 0,
1158 .access = PL0_R, .accessfn = access_tda,
1159 .type = ARM_CP_CONST, .resetvalue = cpu->isar.dbgdidr,
1160 };
1161 define_one_arm_cp_reg(cpu, &dbgdidr);
1162 }
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174 if (extract32(cpu->isar.dbgdidr, 15, 1)) {
1175 ARMCPRegInfo dbgdevid = {
1176 .name = "DBGDEVID",
1177 .cp = 14, .opc1 = 0, .crn = 7, .opc2 = 2, .crn = 7,
1178 .access = PL1_R, .accessfn = access_tda,
1179 .type = ARM_CP_CONST, .resetvalue = cpu->isar.dbgdevid,
1180 };
1181 define_one_arm_cp_reg(cpu, &dbgdevid);
1182 }
1183 if (cpu_isar_feature(aa32_debugv7p1, cpu)) {
1184 ARMCPRegInfo dbgdevid12[] = {
1185 {
1186 .name = "DBGDEVID1",
1187 .cp = 14, .opc1 = 0, .crn = 7, .opc2 = 1, .crn = 7,
1188 .access = PL1_R, .accessfn = access_tda,
1189 .type = ARM_CP_CONST, .resetvalue = cpu->isar.dbgdevid1,
1190 }, {
1191 .name = "DBGDEVID2",
1192 .cp = 14, .opc1 = 0, .crn = 7, .opc2 = 0, .crn = 7,
1193 .access = PL1_R, .accessfn = access_tda,
1194 .type = ARM_CP_CONST, .resetvalue = 0,
1195 },
1196 };
1197 define_arm_cp_regs(cpu, dbgdevid12);
1198 }
1199
1200 brps = arm_num_brps(cpu);
1201 wrps = arm_num_wrps(cpu);
1202 ctx_cmps = arm_num_ctx_cmps(cpu);
1203
1204 assert(ctx_cmps <= brps);
1205
1206 define_arm_cp_regs(cpu, debug_cp_reginfo);
1207
1208 if (arm_feature(&cpu->env, ARM_FEATURE_LPAE)) {
1209 define_arm_cp_regs(cpu, debug_lpae_cp_reginfo);
1210 }
1211
1212 for (i = 0; i < brps; i++) {
1213 char *dbgbvr_el1_name = g_strdup_printf("DBGBVR%d_EL1", i);
1214 char *dbgbcr_el1_name = g_strdup_printf("DBGBCR%d_EL1", i);
1215 ARMCPRegInfo dbgregs[] = {
1216 { .name = dbgbvr_el1_name, .state = ARM_CP_STATE_BOTH,
1217 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = i, .opc2 = 4,
1218 .access = PL1_RW, .accessfn = access_tda,
1219 .fgt = FGT_DBGBVRN_EL1,
1220 .fieldoffset = offsetof(CPUARMState, cp15.dbgbvr[i]),
1221 .writefn = dbgbvr_write, .raw_writefn = raw_write
1222 },
1223 { .name = dbgbcr_el1_name, .state = ARM_CP_STATE_BOTH,
1224 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = i, .opc2 = 5,
1225 .access = PL1_RW, .accessfn = access_tda,
1226 .fgt = FGT_DBGBCRN_EL1,
1227 .fieldoffset = offsetof(CPUARMState, cp15.dbgbcr[i]),
1228 .writefn = dbgbcr_write, .raw_writefn = raw_write
1229 },
1230 };
1231 define_arm_cp_regs(cpu, dbgregs);
1232 g_free(dbgbvr_el1_name);
1233 g_free(dbgbcr_el1_name);
1234 }
1235
1236 for (i = 0; i < wrps; i++) {
1237 char *dbgwvr_el1_name = g_strdup_printf("DBGWVR%d_EL1", i);
1238 char *dbgwcr_el1_name = g_strdup_printf("DBGWCR%d_EL1", i);
1239 ARMCPRegInfo dbgregs[] = {
1240 { .name = dbgwvr_el1_name, .state = ARM_CP_STATE_BOTH,
1241 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = i, .opc2 = 6,
1242 .access = PL1_RW, .accessfn = access_tda,
1243 .fgt = FGT_DBGWVRN_EL1,
1244 .fieldoffset = offsetof(CPUARMState, cp15.dbgwvr[i]),
1245 .writefn = dbgwvr_write, .raw_writefn = raw_write
1246 },
1247 { .name = dbgwcr_el1_name, .state = ARM_CP_STATE_BOTH,
1248 .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = i, .opc2 = 7,
1249 .access = PL1_RW, .accessfn = access_tda,
1250 .fgt = FGT_DBGWCRN_EL1,
1251 .fieldoffset = offsetof(CPUARMState, cp15.dbgwcr[i]),
1252 .writefn = dbgwcr_write, .raw_writefn = raw_write
1253 },
1254 };
1255 define_arm_cp_regs(cpu, dbgregs);
1256 g_free(dbgwvr_el1_name);
1257 g_free(dbgwcr_el1_name);
1258 }
1259}
1260