@@ -95,18 +95,30 @@ GEN_DEBUG_WRITE_REG(dbgwvr)
95
95
96
96
static void reset_debug_state (void )
97
97
{
98
+ uint8_t brps , wrps , i ;
99
+ uint64_t dfr0 ;
100
+
98
101
asm volatile ("msr daifset, #8" );
99
102
100
103
write_sysreg (0 , osdlr_el1 );
101
104
write_sysreg (0 , oslar_el1 );
102
105
isb ();
103
106
104
107
write_sysreg (0 , mdscr_el1 );
105
- /* This test only uses the first bp and wp slot. */
106
- write_sysreg (0 , dbgbvr0_el1 );
107
- write_sysreg (0 , dbgbcr0_el1 );
108
- write_sysreg (0 , dbgwcr0_el1 );
109
- write_sysreg (0 , dbgwvr0_el1 );
108
+
109
+ /* Reset all bcr/bvr/wcr/wvr registers */
110
+ dfr0 = read_sysreg (id_aa64dfr0_el1 );
111
+ brps = FIELD_GET (ARM64_FEATURE_MASK (ID_AA64DFR0_BRPS ), dfr0 );
112
+ for (i = 0 ; i <= brps ; i ++ ) {
113
+ write_dbgbcr (i , 0 );
114
+ write_dbgbvr (i , 0 );
115
+ }
116
+ wrps = FIELD_GET (ARM64_FEATURE_MASK (ID_AA64DFR0_WRPS ), dfr0 );
117
+ for (i = 0 ; i <= wrps ; i ++ ) {
118
+ write_dbgwcr (i , 0 );
119
+ write_dbgwvr (i , 0 );
120
+ }
121
+
110
122
isb ();
111
123
}
112
124
@@ -118,14 +130,14 @@ static void enable_os_lock(void)
118
130
GUEST_ASSERT (read_sysreg (oslsr_el1 ) & 2 );
119
131
}
120
132
121
- static void install_wp (uint64_t addr )
133
+ static void install_wp (uint8_t wpn , uint64_t addr )
122
134
{
123
135
uint32_t wcr ;
124
136
uint32_t mdscr ;
125
137
126
138
wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E ;
127
- write_dbgwcr (0 , wcr );
128
- write_dbgwvr (0 , addr );
139
+ write_dbgwcr (wpn , wcr );
140
+ write_dbgwvr (wpn , addr );
129
141
130
142
isb ();
131
143
@@ -136,14 +148,14 @@ static void install_wp(uint64_t addr)
136
148
isb ();
137
149
}
138
150
139
- static void install_hw_bp (uint64_t addr )
151
+ static void install_hw_bp (uint8_t bpn , uint64_t addr )
140
152
{
141
153
uint32_t bcr ;
142
154
uint32_t mdscr ;
143
155
144
156
bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E ;
145
- write_dbgbcr (0 , bcr );
146
- write_dbgbvr (0 , addr );
157
+ write_dbgbcr (bpn , bcr );
158
+ write_dbgbvr (bpn , addr );
147
159
isb ();
148
160
149
161
asm volatile ("msr daifclr, #8" );
@@ -166,7 +178,7 @@ static void install_ss(void)
166
178
167
179
static volatile char write_data ;
168
180
169
- static void guest_code (void )
181
+ static void guest_code (uint8_t bpn , uint8_t wpn )
170
182
{
171
183
GUEST_SYNC (0 );
172
184
@@ -179,15 +191,15 @@ static void guest_code(void)
179
191
180
192
/* Hardware-breakpoint */
181
193
reset_debug_state ();
182
- install_hw_bp (PC (hw_bp ));
194
+ install_hw_bp (bpn , PC (hw_bp ));
183
195
asm volatile ("hw_bp: nop" );
184
196
GUEST_ASSERT_EQ (hw_bp_addr , PC (hw_bp ));
185
197
186
198
GUEST_SYNC (2 );
187
199
188
200
/* Hardware-breakpoint + svc */
189
201
reset_debug_state ();
190
- install_hw_bp (PC (bp_svc ));
202
+ install_hw_bp (bpn , PC (bp_svc ));
191
203
asm volatile ("bp_svc: svc #0" );
192
204
GUEST_ASSERT_EQ (hw_bp_addr , PC (bp_svc ));
193
205
GUEST_ASSERT_EQ (svc_addr , PC (bp_svc ) + 4 );
@@ -196,7 +208,7 @@ static void guest_code(void)
196
208
197
209
/* Hardware-breakpoint + software-breakpoint */
198
210
reset_debug_state ();
199
- install_hw_bp (PC (bp_brk ));
211
+ install_hw_bp (bpn , PC (bp_brk ));
200
212
asm volatile ("bp_brk: brk #0" );
201
213
GUEST_ASSERT_EQ (sw_bp_addr , PC (bp_brk ));
202
214
GUEST_ASSERT_EQ (hw_bp_addr , PC (bp_brk ));
@@ -205,7 +217,7 @@ static void guest_code(void)
205
217
206
218
/* Watchpoint */
207
219
reset_debug_state ();
208
- install_wp (PC (write_data ));
220
+ install_wp (wpn , PC (write_data ));
209
221
write_data = 'x' ;
210
222
GUEST_ASSERT_EQ (write_data , 'x' );
211
223
GUEST_ASSERT_EQ (wp_data_addr , PC (write_data ));
@@ -239,7 +251,7 @@ static void guest_code(void)
239
251
/* OS Lock blocking hardware-breakpoint */
240
252
reset_debug_state ();
241
253
enable_os_lock ();
242
- install_hw_bp (PC (hw_bp2 ));
254
+ install_hw_bp (bpn , PC (hw_bp2 ));
243
255
hw_bp_addr = 0 ;
244
256
asm volatile ("hw_bp2: nop" );
245
257
GUEST_ASSERT_EQ (hw_bp_addr , 0 );
@@ -251,7 +263,7 @@ static void guest_code(void)
251
263
enable_os_lock ();
252
264
write_data = '\0' ;
253
265
wp_data_addr = 0 ;
254
- install_wp (PC (write_data ));
266
+ install_wp (wpn , PC (write_data ));
255
267
write_data = 'x' ;
256
268
GUEST_ASSERT_EQ (write_data , 'x' );
257
269
GUEST_ASSERT_EQ (wp_data_addr , 0 );
@@ -376,6 +388,8 @@ static void test_guest_debug_exceptions(void)
376
388
vm_install_sync_handler (vm , VECTOR_SYNC_CURRENT ,
377
389
ESR_EC_SVC64 , guest_svc_handler );
378
390
391
+ /* Run tests with breakpoint#0 and watchpoint#0. */
392
+ vcpu_args_set (vcpu , 2 , 0 , 0 );
379
393
for (stage = 0 ; stage < 11 ; stage ++ ) {
380
394
vcpu_run (vcpu );
381
395
0 commit comments