|
22 | 22 | #define DBGWCR_WR (0x2 << 3)
|
23 | 23 | #define DBGWCR_EL1 (0x1 << 1)
|
24 | 24 | #define DBGWCR_E (0x1 << 0)
|
| 25 | +#define DBGWCR_LBN_SHIFT 16 |
| 26 | +#define DBGWCR_WT_SHIFT 20 |
| 27 | +#define DBGWCR_WT_LINK (0x1 << DBGWCR_WT_SHIFT) |
25 | 28 |
|
26 | 29 | #define SPSR_D (1 << 9)
|
27 | 30 | #define SPSR_SS (1 << 21)
|
@@ -171,6 +174,28 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr)
|
171 | 174 | enable_monitor_debug_exceptions();
|
172 | 175 | }
|
173 | 176 |
|
| 177 | +static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, uint64_t addr, |
| 178 | + uint64_t ctx) |
| 179 | +{ |
| 180 | + uint32_t wcr; |
| 181 | + uint64_t ctx_bcr; |
| 182 | + |
| 183 | + /* Setup a context-aware breakpoint for Linked Context ID Match */ |
| 184 | + ctx_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E | |
| 185 | + DBGBCR_BT_CTX_LINK; |
| 186 | + write_dbgbcr(ctx_bp, ctx_bcr); |
| 187 | + write_dbgbvr(ctx_bp, ctx); |
| 188 | + |
| 189 | + /* Setup a linked watchpoint (linked to the context-aware breakpoint) */ |
| 190 | + wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E | |
| 191 | + DBGWCR_WT_LINK | ((uint32_t)ctx_bp << DBGWCR_LBN_SHIFT); |
| 192 | + write_dbgwcr(addr_wp, wcr); |
| 193 | + write_dbgwvr(addr_wp, addr); |
| 194 | + isb(); |
| 195 | + |
| 196 | + enable_monitor_debug_exceptions(); |
| 197 | +} |
| 198 | + |
174 | 199 | void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr,
|
175 | 200 | uint64_t ctx)
|
176 | 201 | {
|
@@ -306,6 +331,16 @@ static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn)
|
306 | 331 | write_sysreg(0, contextidr_el1);
|
307 | 332 | GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp_ctx));
|
308 | 333 |
|
| 334 | + /* Linked watchpoint */ |
| 335 | + reset_debug_state(); |
| 336 | + install_wp_ctx(wpn, ctx_bpn, PC(write_data), ctx); |
| 337 | + /* Set context id */ |
| 338 | + write_sysreg(ctx, contextidr_el1); |
| 339 | + isb(); |
| 340 | + write_data = 'x'; |
| 341 | + GUEST_ASSERT_EQ(write_data, 'x'); |
| 342 | + GUEST_ASSERT_EQ(wp_data_addr, PC(write_data)); |
| 343 | + |
309 | 344 | GUEST_DONE();
|
310 | 345 | }
|
311 | 346 |
|
|
0 commit comments