| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#include "debug_core.h" |
| 13 |
#include "cpu/registers.h" |
| 14 |
|
| 15 |
#include <stdbool.h> |
| 16 |
#include <stdint.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <string.h> |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
struct regs regs; |
| 23 |
bool is_gen2; |
| 24 |
|
| 25 |
static uint8_t g_mem[0x10000]; |
| 26 |
static uint8_t g_ram_bank = 0; |
| 27 |
static uint8_t g_rom_bank = 0; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
typedef enum { CPU_65C02, CPU_816_EMU, CPU_816_NATIVE_8, CPU_816_NATIVE_16 } cpu_mode_t; |
| 32 |
|
| 33 |
static const char * |
| 34 |
cpu_mode_name(cpu_mode_t m) |
| 35 |
{ |
| 36 |
switch (m) { |
| 37 |
case CPU_65C02: return "65C02"; |
| 38 |
case CPU_816_EMU: return "65C816 emulation"; |
| 39 |
case CPU_816_NATIVE_8: return "65C816 native, 8-bit"; |
| 40 |
case CPU_816_NATIVE_16: return "65C816 native, 16-bit"; |
| 41 |
} |
| 42 |
return "?"; |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
set_cpu_mode(cpu_mode_t m) |
| 47 |
{ |
| 48 |
switch (m) { |
| 49 |
case CPU_65C02: |
| 50 |
regs.is65c816 = false; |
| 51 |
regs.e = 1; |
| 52 |
regs.status = FLAG_MEMORY_WIDTH | FLAG_INDEX_WIDTH; |
| 53 |
break; |
| 54 |
case CPU_816_EMU: |
| 55 |
regs.is65c816 = true; |
| 56 |
regs.e = 1; |
| 57 |
|
| 58 |
regs.status = 0; |
| 59 |
break; |
| 60 |
case CPU_816_NATIVE_8: |
| 61 |
regs.is65c816 = true; |
| 62 |
regs.e = 0; |
| 63 |
regs.status = FLAG_MEMORY_WIDTH | FLAG_INDEX_WIDTH; |
| 64 |
break; |
| 65 |
case CPU_816_NATIVE_16: |
| 66 |
regs.is65c816 = true; |
| 67 |
regs.e = 0; |
| 68 |
regs.status = 0; |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
static bool |
| 75 |
mode_is_16bit(cpu_mode_t m) |
| 76 |
{ |
| 77 |
return m == CPU_816_NATIVE_16; |
| 78 |
} |
| 79 |
|
| 80 |
uint8_t |
| 81 |
real_read6502(uint16_t address, uint8_t bank, bool debugOn, int16_t x16Bank) |
| 82 |
{ |
| 83 |
(void)bank; |
| 84 |
(void)debugOn; |
| 85 |
(void)x16Bank; |
| 86 |
return g_mem[address]; |
| 87 |
} |
| 88 |
|
| 89 |
uint8_t |
| 90 |
memory_get_ram_bank(void) |
| 91 |
{ |
| 92 |
return g_ram_bank; |
| 93 |
} |
| 94 |
|
| 95 |
uint8_t |
| 96 |
memory_get_rom_bank(void) |
| 97 |
{ |
| 98 |
return g_rom_bank; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
static int failures = 0; |
| 104 |
|
| 105 |
static void |
| 106 |
check(bool cond, const char *what) |
| 107 |
{ |
| 108 |
if (!cond) { |
| 109 |
failures++; |
| 110 |
printf("FAIL: %s\n", what); |
| 111 |
} else { |
| 112 |
printf("ok : %s\n", what); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
static void |
| 117 |
reset_all(void) |
| 118 |
{ |
| 119 |
debug_core_free(); |
| 120 |
memset(g_mem, 0, sizeof(g_mem)); |
| 121 |
memset(®s, 0, sizeof(regs)); |
| 122 |
g_ram_bank = 0; |
| 123 |
g_rom_bank = 0; |
| 124 |
} |
| 125 |
|
| 126 |
static struct breakpoint |
| 127 |
bp_at(int pc, uint8_t bank, int x16Bank) |
| 128 |
{ |
| 129 |
struct breakpoint bp = { pc, bank, x16Bank, 0, false }; |
| 130 |
return bp; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
static int |
| 142 |
debug_bp_add(struct breakpoint bp) |
| 143 |
{ |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
return debug_bp_add_for(bp, DEBUG_OWNER_CLI) == DEBUG_ADD_CREATED ? numBreakpoints - 1 : -1; |
| 148 |
} |
| 149 |
|
| 150 |
static bool |
| 151 |
debug_bp_remove(int pc, uint8_t bank, int x16Bank) |
| 152 |
{ |
| 153 |
return debug_bp_delete(pc, bank, x16Bank); |
| 154 |
} |
| 155 |
|
| 156 |
static void |
| 157 |
debug_bp_toggle(int pc, uint8_t bank, int x16Bank) |
| 158 |
{ |
| 159 |
debug_bp_toggle_for(pc, bank, x16Bank, DEBUG_OWNER_CLI); |
| 160 |
} |
| 161 |
|
| 162 |
static int |
| 163 |
debug_wp_add(uint16_t addr, uint16_t len, int x16Bank) |
| 164 |
{ |
| 165 |
return debug_wp_add_for(addr, len, x16Bank, DEBUG_OWNER_CLI) == DEBUG_ADD_CREATED |
| 166 |
? debug_wp_count() - 1 |
| 167 |
: -1; |
| 168 |
} |
| 169 |
|
| 170 |
static bool |
| 171 |
debug_wp_remove(uint16_t addr, int x16Bank) |
| 172 |
{ |
| 173 |
return debug_wp_delete(addr, x16Bank); |
| 174 |
} |
| 175 |
|
| 176 |
int |
| 177 |
main(void) |
| 178 |
{ |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
{ |
| 183 |
reset_all(); |
| 184 |
check(numBreakpoints == 0, "starts with no breakpoints"); |
| 185 |
check(!debug_bp_is_set(0x8000, 0), "reports nothing set before anything is added"); |
| 186 |
|
| 187 |
check(debug_bp_add(bp_at(0x8000, 0, -1)) == 0, "adds a breakpoint"); |
| 188 |
check(debug_bp_add(bp_at(0x9000, 0, -1)) == 1, "adds a second without losing the first"); |
| 189 |
check(numBreakpoints == 2, "keeps both"); |
| 190 |
check(debug_bp_is_set(0x8000, 0) && debug_bp_is_set(0x9000, 0), |
| 191 |
"both breakpoints are live at once"); |
| 192 |
|
| 193 |
check(debug_bp_add(bp_at(0x8000, 0, -1)) == -1, "refuses a duplicate address"); |
| 194 |
check(numBreakpoints == 2, "a refused duplicate does not grow the table"); |
| 195 |
|
| 196 |
check(debug_bp_remove(0x8000, 0, -1), "removes a breakpoint"); |
| 197 |
check(!debug_bp_is_set(0x8000, 0), "the removed one stops matching"); |
| 198 |
check(debug_bp_is_set(0x9000, 0), "removing one leaves the other alone"); |
| 199 |
check(!debug_bp_remove(0x8000, 0, -1), "removing a missing breakpoint reports nothing done"); |
| 200 |
|
| 201 |
|
| 202 |
reset_all(); |
| 203 |
for (int i = 0; i < 5; i++) { |
| 204 |
debug_bp_add(bp_at(0x8000 + i * 0x10, 0, -1)); |
| 205 |
} |
| 206 |
debug_bp_remove(0x8010, 0, -1); |
| 207 |
debug_bp_remove(0x8030, 0, -1); |
| 208 |
check(numBreakpoints == 3, "removes from the middle"); |
| 209 |
check(debug_bp_is_set(0x8000, 0) && debug_bp_is_set(0x8020, 0) && debug_bp_is_set(0x8040, 0), |
| 210 |
"the survivors are still the right ones"); |
| 211 |
check(!debug_bp_is_set(0x8010, 0) && !debug_bp_is_set(0x8030, 0), |
| 212 |
"the removed ones are gone"); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
{ |
| 219 |
reset_all(); |
| 220 |
bool all_added = true; |
| 221 |
for (int i = 0; i < 200; i++) { |
| 222 |
if (debug_bp_add(bp_at(0x1000 + i, 0, -1)) != i) { |
| 223 |
all_added = false; |
| 224 |
} |
| 225 |
} |
| 226 |
check(all_added, "adds 200 breakpoints, each at the expected index"); |
| 227 |
check(numBreakpoints == 200, "grows past the initial capacity"); |
| 228 |
check(debug_bp_is_set(0x1000, 0) && debug_bp_is_set(0x1063, 0) && debug_bp_is_set(0x10C7, 0), |
| 229 |
"entries survive the reallocations"); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
{ |
| 234 |
reset_all(); |
| 235 |
debug_bp_toggle(0x8000, 0, -1); |
| 236 |
check(debug_bp_is_set(0x8000, 0), "toggle adds when absent"); |
| 237 |
debug_bp_toggle(0x8000, 0, -1); |
| 238 |
check(!debug_bp_is_set(0x8000, 0), "toggle removes when present"); |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
reset_all(); |
| 245 |
g_ram_bank = 5; |
| 246 |
debug_bp_toggle(0xA100, 0, 5); |
| 247 |
check(debug_bp_is_set(0xA100, 0), "arms a breakpoint in the displayed bank"); |
| 248 |
|
| 249 |
g_ram_bank = 6; |
| 250 |
debug_bp_toggle(0xA100, 0, 6); |
| 251 |
check(debug_bp_is_set(0xA100, 0), "toggling the same address in another bank arms it"); |
| 252 |
g_ram_bank = 5; |
| 253 |
check(debug_bp_is_set(0xA100, 0), "and leaves the first bank's breakpoint alone"); |
| 254 |
check(numBreakpoints == 2, "both banks' breakpoints coexist"); |
| 255 |
|
| 256 |
|
| 257 |
g_ram_bank = 6; |
| 258 |
debug_bp_toggle(0xA100, 0, 6); |
| 259 |
check(!debug_bp_is_set(0xA100, 0), "toggling off removes the right one"); |
| 260 |
g_ram_bank = 5; |
| 261 |
check(debug_bp_is_set(0xA100, 0), "the other bank's breakpoint survives"); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
{ |
| 268 |
reset_all(); |
| 269 |
check(debug_bp_add(bp_at(0xA000, 0, 5)) == 0, "adds a breakpoint in bank 5"); |
| 270 |
check(debug_bp_add(bp_at(0xA000, 0, 6)) == 1, |
| 271 |
"adds one at the same address in bank 6"); |
| 272 |
check(numBreakpoints == 2, "keeps both"); |
| 273 |
|
| 274 |
|
| 275 |
g_ram_bank = 5; |
| 276 |
check(debug_bp_on_arrival(0xA000, 0), "stops in bank 5"); |
| 277 |
check(debug_bp_on_arrival(0xA000, 0), "stops in bank 5 again"); |
| 278 |
g_ram_bank = 6; |
| 279 |
check(debug_bp_on_arrival(0xA000, 0), "stops in bank 6"); |
| 280 |
check(debug_bp_get_hits(0xA000, 0, 5) == 2 && debug_bp_get_hits(0xA000, 0, 6) == 1, |
| 281 |
"each bank's breakpoint counts its own hits"); |
| 282 |
|
| 283 |
|
| 284 |
debug_bp_set_condition(0xA000, 0, 5, BPOPERAND_A, 0, BPCMP_EQ, 0x11); |
| 285 |
regs.c = 0x22; |
| 286 |
g_ram_bank = 5; |
| 287 |
check(!debug_bp_on_arrival(0xA000, 0), "bank 5's condition applies in bank 5"); |
| 288 |
g_ram_bank = 6; |
| 289 |
check(debug_bp_on_arrival(0xA000, 0), "and does not leak into bank 6"); |
| 290 |
|
| 291 |
check(debug_bp_add(bp_at(0xA000, 0, 5)) == -1, |
| 292 |
"still refuses a true duplicate (same address AND bank)"); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
{ |
| 301 |
reset_all(); |
| 302 |
debug_bp_add(bp_at(0xA000, 0, 5)); |
| 303 |
|
| 304 |
g_ram_bank = 5; |
| 305 |
check(debug_bp_is_set(0xA000, 0), "fires in the bank it was set for"); |
| 306 |
g_ram_bank = 6; |
| 307 |
check(!debug_bp_is_set(0xA000, 0), "does not fire in a different RAM bank"); |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
reset_all(); |
| 312 |
debug_bp_add(bp_at(0x0801, 0, -1)); |
| 313 |
g_ram_bank = 3; |
| 314 |
check(debug_bp_is_set(0x0801, 0), "unbanked addresses ignore the RAM bank"); |
| 315 |
|
| 316 |
|
| 317 |
reset_all(); |
| 318 |
debug_bp_add(bp_at(0xC000, 0, 2)); |
| 319 |
g_rom_bank = 2; |
| 320 |
g_ram_bank = 9; |
| 321 |
check(debug_bp_is_set(0xC000, 0), "the ROM window follows the ROM bank"); |
| 322 |
g_rom_bank = 3; |
| 323 |
check(!debug_bp_is_set(0xC000, 0), "does not fire in a different ROM bank"); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
{ |
| 328 |
reset_all(); |
| 329 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 330 |
|
| 331 |
check(!debug_bp_on_arrival(0x7FFF, 0), "does not stop where no breakpoint is"); |
| 332 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, "a breakpoint starts with no hits"); |
| 333 |
|
| 334 |
check(debug_bp_on_arrival(0x8000, 0), "stops on a plain breakpoint"); |
| 335 |
check(debug_bp_get_hits(0x8000, 0, -1) == 1, "counts the hit"); |
| 336 |
check(debug_bp_on_arrival(0x8000, 0), "stops again"); |
| 337 |
check(debug_bp_get_hits(0x8000, 0, -1) == 2, "keeps counting"); |
| 338 |
|
| 339 |
debug_bp_reset_hits(0x8000, 0, -1); |
| 340 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, "the count can be reset"); |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
debug_bp_on_arrival(0x8000, 0); |
| 346 |
debug_bp_remove(0x8000, 0, -1); |
| 347 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 348 |
check(debug_bp_get_hits(0x8000, 0, -1) == 1, "the count survives a disable/enable cycle"); |
| 349 |
|
| 350 |
|
| 351 |
debug_bp_remove(0x8000, 0, -1); |
| 352 |
debug_bp_forget(0x8000, 0, -1); |
| 353 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 354 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, "an explicit delete discards the count"); |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
{ |
| 362 |
reset_all(); |
| 363 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 364 |
debug_bp_set_ignore(0x8000, 0, -1, 3); |
| 365 |
|
| 366 |
check(!debug_bp_on_arrival(0x8000, 0), "does not stop on the 1st of 3 ignored hits"); |
| 367 |
check(!debug_bp_on_arrival(0x8000, 0), "does not stop on the 2nd"); |
| 368 |
check(!debug_bp_on_arrival(0x8000, 0), "does not stop on the 3rd"); |
| 369 |
check(debug_bp_on_arrival(0x8000, 0), "stops on the 4th, once the budget is spent"); |
| 370 |
check(debug_bp_get_hits(0x8000, 0, -1) == 4, "ignored arrivals are still counted"); |
| 371 |
check(debug_bp_on_arrival(0x8000, 0), "keeps stopping thereafter"); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
{ |
| 376 |
reset_all(); |
| 377 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 378 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0x42); |
| 379 |
|
| 380 |
regs.c = 0x41; |
| 381 |
check(!debug_bp_on_arrival(0x8000, 0), "does not stop while the condition is false"); |
| 382 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, |
| 383 |
"an unsatisfied condition does not spend a hit"); |
| 384 |
|
| 385 |
regs.c = 0x42; |
| 386 |
check(debug_bp_on_arrival(0x8000, 0), "stops once the condition holds"); |
| 387 |
|
| 388 |
|
| 389 |
regs.c = 0x10; |
| 390 |
struct { int op; uint32_t val; bool want; const char *what; } cases[] = { |
| 391 |
{ BPCMP_EQ, 0x10, true, "== when equal" }, |
| 392 |
{ BPCMP_EQ, 0x11, false, "== when not equal" }, |
| 393 |
{ BPCMP_NE, 0x11, true, "!= when different" }, |
| 394 |
{ BPCMP_NE, 0x10, false, "!= when same" }, |
| 395 |
{ BPCMP_LT, 0x11, true, "< when below" }, |
| 396 |
{ BPCMP_LT, 0x10, false, "< when equal" }, |
| 397 |
{ BPCMP_LE, 0x10, true, "<= when equal" }, |
| 398 |
{ BPCMP_LE, 0x0F, false, "<= when above" }, |
| 399 |
{ BPCMP_GT, 0x0F, true, "> when above" }, |
| 400 |
{ BPCMP_GT, 0x10, false, "> when equal" }, |
| 401 |
{ BPCMP_GE, 0x10, true, ">= when equal" }, |
| 402 |
{ BPCMP_GE, 0x11, false, ">= when below" }, |
| 403 |
}; |
| 404 |
bool all_ok = true; |
| 405 |
for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { |
| 406 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, cases[i].op, cases[i].val); |
| 407 |
if (debug_bp_on_arrival(0x8000, 0) != cases[i].want) { |
| 408 |
printf(" (comparison wrong: %s)\n", cases[i].what); |
| 409 |
all_ok = false; |
| 410 |
} |
| 411 |
} |
| 412 |
check(all_ok, "every comparison operator behaves as named"); |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0xFF); |
| 417 |
regs.c = 0x00; |
| 418 |
check(!debug_bp_on_arrival(0x8000, 0), "condition still applies before clearing"); |
| 419 |
debug_bp_clear_condition(0x8000, 0, -1); |
| 420 |
check(debug_bp_on_arrival(0x8000, 0), "clearing the condition makes it fire again"); |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
{ |
| 425 |
reset_all(); |
| 426 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 427 |
|
| 428 |
regs.x = 0x33; |
| 429 |
regs.y = 0x44; |
| 430 |
regs.sp = 0x01F0; |
| 431 |
regs.status = 0x24; |
| 432 |
|
| 433 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_X, 0, BPCMP_EQ, 0x33); |
| 434 |
check(debug_bp_on_arrival(0x8000, 0), "tests X"); |
| 435 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_Y, 0, BPCMP_EQ, 0x44); |
| 436 |
check(debug_bp_on_arrival(0x8000, 0), "tests Y"); |
| 437 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_P, 0, BPCMP_EQ, 0x24); |
| 438 |
check(debug_bp_on_arrival(0x8000, 0), "tests the status register"); |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_SP, 0, BPCMP_EQ, 0x01F0); |
| 443 |
check(debug_bp_on_arrival(0x8000, 0), "tests the full 16-bit stack pointer"); |
| 444 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_SP, 0, BPCMP_EQ, 0x00F0); |
| 445 |
check(!debug_bp_on_arrival(0x8000, 0), "does not truncate the stack pointer to 8 bits"); |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
g_mem[0x1234] = 0x99; |
| 450 |
g_mem[0x1235] = 0xAB; |
| 451 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_BYTE, 0x1234, BPCMP_EQ, 0x99); |
| 452 |
check(debug_bp_on_arrival(0x8000, 0), "tests a byte in memory"); |
| 453 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_WORD, 0x1234, BPCMP_EQ, 0xAB99); |
| 454 |
check(debug_bp_on_arrival(0x8000, 0), "tests a little-endian word in memory"); |
| 455 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_WORD, 0x1234, BPCMP_EQ, 0x99AB); |
| 456 |
check(!debug_bp_on_arrival(0x8000, 0), "reads the word in the right byte order"); |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
{ |
| 464 |
reset_all(); |
| 465 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 466 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0x07); |
| 467 |
debug_bp_set_ignore(0x8000, 0, -1, 2); |
| 468 |
|
| 469 |
regs.c = 0x00; |
| 470 |
for (int i = 0; i < 10; i++) { |
| 471 |
debug_bp_on_arrival(0x8000, 0); |
| 472 |
} |
| 473 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, |
| 474 |
"arrivals that fail the condition do not spend the ignore budget"); |
| 475 |
|
| 476 |
regs.c = 0x07; |
| 477 |
check(!debug_bp_on_arrival(0x8000, 0), "1st satisfying arrival is ignored"); |
| 478 |
check(!debug_bp_on_arrival(0x8000, 0), "2nd satisfying arrival is ignored"); |
| 479 |
check(debug_bp_on_arrival(0x8000, 0), "3rd satisfying arrival stops"); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
{ |
| 484 |
reset_all(); |
| 485 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 486 |
|
| 487 |
int has_cond = 9, operand = 9, op = 9; |
| 488 |
uint16_t operand_addr = 9; |
| 489 |
uint32_t value = 9, ignore = 9; |
| 490 |
check(!debug_bp_get_condition(0x8000, 0, -1, &has_cond, &operand, &operand_addr, &op, &value, &ignore), |
| 491 |
"reports nothing for a breakpoint never given a condition"); |
| 492 |
|
| 493 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_BYTE, 0x1234, BPCMP_GE, 0x55); |
| 494 |
debug_bp_set_ignore(0x8000, 0, -1, 7); |
| 495 |
check(debug_bp_get_condition(0x8000, 0, -1, &has_cond, &operand, &operand_addr, &op, &value, &ignore), |
| 496 |
"reads a condition back"); |
| 497 |
check(has_cond == 1 && operand == BPOPERAND_BYTE && operand_addr == 0x1234 |
| 498 |
&& op == BPCMP_GE && value == 0x55 && ignore == 7, |
| 499 |
"reads back exactly what was set"); |
| 500 |
|
| 501 |
|
| 502 |
check(debug_bp_get_condition(0x8000, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL), |
| 503 |
"tolerates NULL out-parameters"); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
{ |
| 511 |
reset_all(); |
| 512 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 513 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0x1234); |
| 514 |
|
| 515 |
|
| 516 |
regs.is65c816 = false; |
| 517 |
regs.c = 0x1234; |
| 518 |
check(!debug_bp_on_arrival(0x8000, 0), "an 8-bit A never matches a 16-bit value"); |
| 519 |
|
| 520 |
|
| 521 |
regs.is65c816 = true; |
| 522 |
regs.e = 0; |
| 523 |
regs.status = FLAG_INDEX_WIDTH; |
| 524 |
check(debug_bp_on_arrival(0x8000, 0), "a 16-bit A matches the full value"); |
| 525 |
|
| 526 |
|
| 527 |
regs.c = 0x9934; |
| 528 |
check(!debug_bp_on_arrival(0x8000, 0), |
| 529 |
"a 16-bit A does not match on the low byte alone"); |
| 530 |
|
| 531 |
|
| 532 |
regs.status = FLAG_MEMORY_WIDTH | FLAG_INDEX_WIDTH; |
| 533 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0x34); |
| 534 |
check(debug_bp_on_arrival(0x8000, 0), "an 8-bit A compares its low byte"); |
| 535 |
|
| 536 |
|
| 537 |
regs.e = 1; |
| 538 |
regs.status = FLAG_INDEX_WIDTH; |
| 539 |
regs.c = 0x9934; |
| 540 |
check(debug_bp_on_arrival(0x8000, 0), "emulation mode forces the 8-bit comparison"); |
| 541 |
|
| 542 |
|
| 543 |
regs.e = 0; |
| 544 |
regs.status = FLAG_MEMORY_WIDTH; |
| 545 |
regs.x = 0x0555; |
| 546 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_X, 0, BPCMP_EQ, 0x0555); |
| 547 |
check(debug_bp_on_arrival(0x8000, 0), "a 16-bit X matches the full value"); |
| 548 |
|
| 549 |
regs.y = 0x0666; |
| 550 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_Y, 0, BPCMP_EQ, 0x0666); |
| 551 |
check(debug_bp_on_arrival(0x8000, 0), "a 16-bit Y matches the full value"); |
| 552 |
|
| 553 |
regs.status = FLAG_MEMORY_WIDTH | FLAG_INDEX_WIDTH; |
| 554 |
check(!debug_bp_on_arrival(0x8000, 0), |
| 555 |
"an 8-bit Y does not match a 16-bit value"); |
| 556 |
|
| 557 |
regs.is65c816 = false; |
| 558 |
regs.e = 0; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
{ |
| 567 |
reset_all(); |
| 568 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 569 |
debug_bp_set_condition(0x8000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 0xAA); |
| 570 |
debug_bp_set_ignore(0x8000, 0, -1, 5); |
| 571 |
regs.c = 0xAA; |
| 572 |
debug_bp_on_arrival(0x8000, 0); |
| 573 |
|
| 574 |
debug_bp_clear_all(); |
| 575 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 576 |
|
| 577 |
check(debug_bp_get_hits(0x8000, 0, -1) == 0, "a full clear discards hit counts"); |
| 578 |
int has_cond = 9; |
| 579 |
check(!debug_bp_get_condition(0x8000, 0, -1, &has_cond, NULL, NULL, NULL, NULL, NULL), |
| 580 |
"a full clear discards conditions"); |
| 581 |
regs.c = 0x00; |
| 582 |
check(debug_bp_on_arrival(0x8000, 0), |
| 583 |
"the recreated breakpoint is unconditional, not the old one"); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
{ |
| 588 |
reset_all(); |
| 589 |
debug_bp_add(bp_at(0x8000, 0, -1)); |
| 590 |
debug_bp_add(bp_at(0x9000, 0, -1)); |
| 591 |
debug_bp_clear_all(); |
| 592 |
check(numBreakpoints == 0, "clears the whole table"); |
| 593 |
check(!debug_bp_is_set(0x8000, 0) && !debug_bp_is_set(0x9000, 0), |
| 594 |
"nothing matches after clearing"); |
| 595 |
check(!debug_bp_on_arrival(0x8000, 0), "and nothing stops"); |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
{ |
| 603 |
reset_all(); |
| 604 |
check(debug_wp_count() == 0, "starts with no watchpoints"); |
| 605 |
check(!debug_wp_check_write(0x1234, 0x00), "nothing fires before anything is watched"); |
| 606 |
|
| 607 |
check(debug_wp_add(0x1234, 1, -1) == 0, "adds a watchpoint"); |
| 608 |
check(debug_wp_count() == 1, "counts it"); |
| 609 |
check(debug_wp_check_write(0x1234, 0x55), "fires on a write to the watched byte"); |
| 610 |
check(!debug_wp_check_write(0x1235, 0x55), "does not fire on the next byte"); |
| 611 |
check(!debug_wp_check_write(0x1233, 0x55), "does not fire on the previous byte"); |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
check(debug_wp_add(0x1234, 8, DEBUG_BANK_ANY) == -1 && debug_wp_count() == 1, |
| 617 |
"refuses a duplicate address in the same bank"); |
| 618 |
|
| 619 |
check(debug_wp_remove(0x1234, DEBUG_BANK_ANY), "removes a watchpoint"); |
| 620 |
check(debug_wp_count() == 0, "the table is empty again"); |
| 621 |
check(!debug_wp_check_write(0x1234, 0x55), "the removed one no longer fires"); |
| 622 |
check(!debug_wp_remove(0x1234, DEBUG_BANK_ANY), "removing a missing one reports nothing done"); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
{ |
| 627 |
reset_all(); |
| 628 |
debug_wp_add(0x2000, 4, -1); |
| 629 |
check(debug_wp_check_write(0x2000, 0) && debug_wp_check_write(0x2003, 0), |
| 630 |
"fires anywhere inside the range"); |
| 631 |
check(!debug_wp_check_write(0x1FFF, 0) && !debug_wp_check_write(0x2004, 0), |
| 632 |
"does not fire either side of it"); |
| 633 |
|
| 634 |
|
| 635 |
reset_all(); |
| 636 |
debug_wp_add(0x3000, 0, -1); |
| 637 |
check(debug_wp_check_write(0x3000, 0), "a zero length watches one byte"); |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
reset_all(); |
| 643 |
debug_wp_add(0xFFFE, 8, DEBUG_BANK_ANY); |
| 644 |
check(debug_wp_check_write(0xFFFF, 0), "watches up to the last byte"); |
| 645 |
check(!debug_wp_check_write(0x0000, 0), "does not wrap past the end of memory"); |
| 646 |
check(!debug_wp_check_write(0x0005, 0), "really does not wrap"); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
{ |
| 653 |
reset_all(); |
| 654 |
debug_wp_add(0x1234, 1, -1); |
| 655 |
check(debug_wp_set_value(0x1234, DEBUG_BANK_ANY, BPCMP_EQ, 0x00), "attaches a value filter"); |
| 656 |
check(debug_wp_check_write(0x1234, 0x00), "fires when the written value matches"); |
| 657 |
check(!debug_wp_check_write(0x1234, 0x01), "stays quiet when it does not"); |
| 658 |
|
| 659 |
check(!debug_wp_set_value(0x9999, DEBUG_BANK_ANY, BPCMP_EQ, 0), |
| 660 |
"declines a filter for an unwatched address"); |
| 661 |
|
| 662 |
|
| 663 |
struct { int op; uint8_t val; uint8_t written; bool want; const char *what; } wcases[] = { |
| 664 |
{ BPCMP_EQ, 0x10, 0x10, true, "== when equal" }, |
| 665 |
{ BPCMP_EQ, 0x10, 0x11, false, "== when not equal" }, |
| 666 |
{ BPCMP_NE, 0x10, 0x11, true, "!= when different" }, |
| 667 |
{ BPCMP_NE, 0x10, 0x10, false, "!= when same" }, |
| 668 |
{ BPCMP_LT, 0x10, 0x0F, true, "< when below" }, |
| 669 |
{ BPCMP_LT, 0x10, 0x10, false, "< when equal" }, |
| 670 |
{ BPCMP_LE, 0x10, 0x10, true, "<= when equal" }, |
| 671 |
{ BPCMP_LE, 0x10, 0x11, false, "<= when above" }, |
| 672 |
{ BPCMP_GT, 0x10, 0x11, true, "> when above" }, |
| 673 |
{ BPCMP_GT, 0x10, 0x10, false, "> when equal" }, |
| 674 |
{ BPCMP_GE, 0x10, 0x10, true, ">= when equal" }, |
| 675 |
{ BPCMP_GE, 0x10, 0x0F, false, ">= when below" }, |
| 676 |
}; |
| 677 |
bool wp_ops_ok = true; |
| 678 |
for (unsigned i = 0; i < sizeof(wcases) / sizeof(wcases[0]); i++) { |
| 679 |
debug_wp_set_value(0x1234, DEBUG_BANK_ANY, wcases[i].op, wcases[i].val); |
| 680 |
if (debug_wp_check_write(0x1234, wcases[i].written) != wcases[i].want) { |
| 681 |
printf(" (watchpoint comparison wrong: %s)\n", wcases[i].what); |
| 682 |
wp_ops_ok = false; |
| 683 |
} |
| 684 |
} |
| 685 |
check(wp_ops_ok, "every watchpoint comparison behaves as named"); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
{ |
| 692 |
reset_all(); |
| 693 |
debug_wp_add(0xA100, 1, 5); |
| 694 |
|
| 695 |
g_ram_bank = 5; |
| 696 |
check(debug_wp_check_write(0xA100, 0x99), "fires in the bank it was set for"); |
| 697 |
g_ram_bank = 6; |
| 698 |
check(!debug_wp_check_write(0xA100, 0x99), "stays quiet in a different bank"); |
| 699 |
|
| 700 |
|
| 701 |
reset_all(); |
| 702 |
debug_wp_add(0x0400, 1, -1); |
| 703 |
g_ram_bank = 7; |
| 704 |
check(debug_wp_check_write(0x0400, 0x01), "unbanked addresses ignore the RAM bank"); |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
reset_all(); |
| 709 |
debug_wp_add(0xA100, 1, -1); |
| 710 |
g_ram_bank = 2; |
| 711 |
bool any_first = debug_wp_check_write(0xA100, 0x01); |
| 712 |
g_ram_bank = 9; |
| 713 |
check(any_first && debug_wp_check_write(0xA100, 0x01), |
| 714 |
"a bankless banked watchpoint fires in every bank"); |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
{ |
| 719 |
reset_all(); |
| 720 |
debug_wp_add(0x1234, 1, -1); |
| 721 |
debug_wp_set_value(0x1234, DEBUG_BANK_ANY, BPCMP_EQ, 0x42); |
| 722 |
|
| 723 |
check(debug_wp_set_active(0x1234, DEBUG_BANK_ANY, false), "disables a watchpoint"); |
| 724 |
check(!debug_wp_check_write(0x1234, 0x42), "a disabled watchpoint does not fire"); |
| 725 |
check(debug_wp_count() == 1, "but it is still in the table"); |
| 726 |
|
| 727 |
check(debug_wp_set_active(0x1234, DEBUG_BANK_ANY, true), "re-enables it"); |
| 728 |
check(debug_wp_check_write(0x1234, 0x42), "and its value filter survived"); |
| 729 |
check(!debug_wp_set_active(0x9999, DEBUG_BANK_ANY, true), "declines to enable one that is not there"); |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
{ |
| 734 |
reset_all(); |
| 735 |
debug_wp_add(0x2000, 4, -1); |
| 736 |
check(debug_wp_covers(0x2002), "reports a watched address as covered"); |
| 737 |
check(!debug_wp_covers(0x2004), "reports an unwatched address as not covered"); |
| 738 |
debug_wp_set_active(0x2000, DEBUG_BANK_ANY, false); |
| 739 |
check(!debug_wp_covers(0x2002), "a disabled watchpoint covers nothing"); |
| 740 |
|
| 741 |
reset_all(); |
| 742 |
int added = 0; |
| 743 |
for (int i = 0; i < MAX_WATCHPOINTS + 10; i++) { |
| 744 |
if (debug_wp_add((uint16_t)(0x4000 + i), 1, -1) >= 0) { |
| 745 |
added++; |
| 746 |
} |
| 747 |
} |
| 748 |
check(added == MAX_WATCHPOINTS, "fills the table and then refuses more"); |
| 749 |
check(debug_wp_count() == MAX_WATCHPOINTS, "does not overflow the table"); |
| 750 |
check(debug_wp_check_write(0x4000, 0) && debug_wp_check_write(0x403F, 0), |
| 751 |
"every entry that fit still works"); |
| 752 |
|
| 753 |
debug_wp_clear_all(); |
| 754 |
check(debug_wp_count() == 0, "clears them all"); |
| 755 |
check(!debug_wp_check_write(0x4000, 0), "and none fire afterwards"); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
{ |
| 760 |
reset_all(); |
| 761 |
for (int i = 0; i < 5; i++) { |
| 762 |
debug_wp_add((uint16_t)(0x5000 + i * 0x10), 1, -1); |
| 763 |
} |
| 764 |
debug_wp_remove(0x5010, DEBUG_BANK_ANY); |
| 765 |
debug_wp_remove(0x5030, DEBUG_BANK_ANY); |
| 766 |
check(debug_wp_count() == 3, "removes from the middle"); |
| 767 |
check(debug_wp_check_write(0x5000, 0) && debug_wp_check_write(0x5020, 0) |
| 768 |
&& debug_wp_check_write(0x5040, 0), |
| 769 |
"the survivors still fire"); |
| 770 |
check(!debug_wp_check_write(0x5010, 0) && !debug_wp_check_write(0x5030, 0), |
| 771 |
"the removed ones do not"); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
{ |
| 781 |
reset_all(); |
| 782 |
|
| 783 |
|
| 784 |
debug_bp_add(bp_at(0xA000, 0, DEBUG_BANK_ANY)); |
| 785 |
g_ram_bank = 0; |
| 786 |
bool any0 = debug_bp_is_set(0xA000, 0); |
| 787 |
g_ram_bank = 5; |
| 788 |
bool any5 = debug_bp_is_set(0xA000, 0); |
| 789 |
g_ram_bank = 200; |
| 790 |
check(any0 && any5 && debug_bp_is_set(0xA000, 0), |
| 791 |
"a bankless breakpoint fires in every RAM bank"); |
| 792 |
|
| 793 |
|
| 794 |
reset_all(); |
| 795 |
debug_bp_add(bp_at(0xC000, 0, DEBUG_BANK_ANY)); |
| 796 |
g_rom_bank = 0; |
| 797 |
bool rany0 = debug_bp_is_set(0xC000, 0); |
| 798 |
g_rom_bank = 31; |
| 799 |
check(rany0 && debug_bp_is_set(0xC000, 0), |
| 800 |
"a bankless breakpoint fires in every ROM bank"); |
| 801 |
|
| 802 |
|
| 803 |
reset_all(); |
| 804 |
debug_bp_add(bp_at(0xA000, 0, 5)); |
| 805 |
g_ram_bank = 5; |
| 806 |
check(debug_bp_is_set(0xA000, 0), "a specific bank fires in that bank"); |
| 807 |
g_ram_bank = 6; |
| 808 |
check(!debug_bp_is_set(0xA000, 0), "and not in another"); |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
reset_all(); |
| 814 |
debug_bp_add(bp_at(0x0801, 0, 7)); |
| 815 |
g_ram_bank = 3; |
| 816 |
check(debug_bp_is_set(0x0801, 0), |
| 817 |
"an unbanked address ignores a bank it was given"); |
| 818 |
check(debug_bp_add(bp_at(0x0801, 0, 9)) == -1, |
| 819 |
"the same unbanked address is one breakpoint whatever bank is named"); |
| 820 |
check(debug_bp_remove(0x0801, 0, DEBUG_BANK_ANY), |
| 821 |
"and it can be removed without naming that bank"); |
| 822 |
|
| 823 |
|
| 824 |
reset_all(); |
| 825 |
debug_wp_add(0xA100, 1, DEBUG_BANK_ANY); |
| 826 |
g_ram_bank = 1; |
| 827 |
bool wany1 = debug_wp_check_write(0xA100, 0); |
| 828 |
g_ram_bank = 99; |
| 829 |
check(wany1 && debug_wp_check_write(0xA100, 0), |
| 830 |
"a bankless watchpoint fires in every bank"); |
| 831 |
|
| 832 |
reset_all(); |
| 833 |
debug_wp_add(0x0400, 1, 7); |
| 834 |
g_ram_bank = 2; |
| 835 |
check(debug_wp_check_write(0x0400, 0), |
| 836 |
"an unbanked watch address ignores a bank it was given"); |
| 837 |
|
| 838 |
|
| 839 |
reset_all(); |
| 840 |
debug_wp_add(0xC100, 1, 3); |
| 841 |
g_rom_bank = 3; |
| 842 |
g_ram_bank = 9; |
| 843 |
check(debug_wp_check_write(0xC100, 0), "the ROM window follows the ROM bank"); |
| 844 |
g_rom_bank = 4; |
| 845 |
check(!debug_wp_check_write(0xC100, 0), "and not a different ROM bank"); |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
reset_all(); |
| 851 |
check(debug_wp_add(0xA100, 1, 5) == 0, "watches an address in bank 5"); |
| 852 |
check(debug_wp_add(0xA100, 1, 6) == 1, "watches the same address in bank 6"); |
| 853 |
check(debug_wp_count() == 2, "keeps both"); |
| 854 |
g_ram_bank = 5; |
| 855 |
bool w5 = debug_wp_check_write(0xA100, 0); |
| 856 |
g_ram_bank = 6; |
| 857 |
check(w5 && debug_wp_check_write(0xA100, 0), "each fires in its own bank"); |
| 858 |
g_ram_bank = 7; |
| 859 |
check(!debug_wp_check_write(0xA100, 0), "and neither fires in a third"); |
| 860 |
|
| 861 |
|
| 862 |
check(debug_wp_remove(0xA100, 5) && debug_wp_count() == 1, |
| 863 |
"removes only the bank it names"); |
| 864 |
g_ram_bank = 6; |
| 865 |
check(debug_wp_check_write(0xA100, 0), "the other bank's watchpoint survives"); |
| 866 |
|
| 867 |
|
| 868 |
reset_all(); |
| 869 |
debug_wp_add(0xA100, 1, 5); |
| 870 |
debug_wp_add(0xA100, 1, 6); |
| 871 |
check(debug_wp_set_value(0xA100, 5, BPCMP_EQ, 0x11), |
| 872 |
"attaches a filter to one bank's watchpoint"); |
| 873 |
g_ram_bank = 5; |
| 874 |
check(!debug_wp_check_write(0xA100, 0x22), "that bank honours its filter"); |
| 875 |
g_ram_bank = 6; |
| 876 |
check(debug_wp_check_write(0xA100, 0x22), "the other bank is unaffected"); |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
{ |
| 885 |
const cpu_mode_t modes[] = { CPU_65C02, CPU_816_EMU, CPU_816_NATIVE_8, |
| 886 |
CPU_816_NATIVE_16 }; |
| 887 |
bool low_ok = true, wide_ok = true, narrow_ok = true; |
| 888 |
|
| 889 |
for (unsigned mi = 0; mi < sizeof(modes) / sizeof(modes[0]); mi++) { |
| 890 |
const cpu_mode_t m = modes[mi]; |
| 891 |
const bool wide = mode_is_16bit(m); |
| 892 |
|
| 893 |
|
| 894 |
const struct { int operand; const char *name; } regs8[] = { |
| 895 |
{ BPOPERAND_A, "A" }, { BPOPERAND_X, "X" }, { BPOPERAND_Y, "Y" }, |
| 896 |
}; |
| 897 |
for (unsigned ri = 0; ri < 3; ri++) { |
| 898 |
reset_all(); |
| 899 |
set_cpu_mode(m); |
| 900 |
debug_bp_add(bp_at(0x8000, 0, DEBUG_BANK_ANY)); |
| 901 |
regs.c = regs.x = regs.y = 0x0042; |
| 902 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, regs8[ri].operand, 0, |
| 903 |
BPCMP_EQ, 0x42); |
| 904 |
if (!debug_bp_on_arrival(0x8000, 0)) { |
| 905 |
printf(" (%s == $42 failed on %s)\n", regs8[ri].name, cpu_mode_name(m)); |
| 906 |
low_ok = false; |
| 907 |
} |
| 908 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, regs8[ri].operand, 0, |
| 909 |
BPCMP_NE, 0x42); |
| 910 |
if (debug_bp_on_arrival(0x8000, 0)) { |
| 911 |
printf(" (%s != $42 wrongly fired on %s)\n", regs8[ri].name, |
| 912 |
cpu_mode_name(m)); |
| 913 |
low_ok = false; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
reset_all(); |
| 919 |
set_cpu_mode(m); |
| 920 |
debug_bp_add(bp_at(0x8000, 0, DEBUG_BANK_ANY)); |
| 921 |
regs.c = regs.x = regs.y = 0x1234; |
| 922 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, regs8[ri].operand, 0, |
| 923 |
BPCMP_EQ, 0x1234); |
| 924 |
bool matched16 = debug_bp_on_arrival(0x8000, 0); |
| 925 |
if (matched16 != wide) { |
| 926 |
printf(" (%s == $1234 %s on %s)\n", regs8[ri].name, |
| 927 |
matched16 ? "wrongly matched" : "did not match", cpu_mode_name(m)); |
| 928 |
wide_ok = false; |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, regs8[ri].operand, 0, |
| 934 |
BPCMP_EQ, 0x34); |
| 935 |
bool matched8 = debug_bp_on_arrival(0x8000, 0); |
| 936 |
if (matched8 == wide) { |
| 937 |
printf(" (%s == $34 with A=$1234 %s on %s)\n", regs8[ri].name, |
| 938 |
matched8 ? "wrongly matched" : "did not match", cpu_mode_name(m)); |
| 939 |
narrow_ok = false; |
| 940 |
} |
| 941 |
} |
| 942 |
} |
| 943 |
check(low_ok, "A, X and Y compare their low byte in every CPU mode"); |
| 944 |
check(wide_ok, "A, X and Y compare 16 bits only where the CPU is 16-bit"); |
| 945 |
check(narrow_ok, "an 8-bit register is not matched by a 16-bit value, and vice versa"); |
| 946 |
|
| 947 |
|
| 948 |
bool fixed_ok = true; |
| 949 |
for (unsigned mi = 0; mi < sizeof(modes) / sizeof(modes[0]); mi++) { |
| 950 |
const cpu_mode_t m = modes[mi]; |
| 951 |
reset_all(); |
| 952 |
set_cpu_mode(m); |
| 953 |
debug_bp_add(bp_at(0x8000, 0, DEBUG_BANK_ANY)); |
| 954 |
|
| 955 |
regs.sp = 0x01F0; |
| 956 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_SP, 0, BPCMP_EQ, 0x01F0); |
| 957 |
if (!debug_bp_on_arrival(0x8000, 0)) { printf(" (SP full on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 958 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_SP, 0, BPCMP_EQ, 0x00F0); |
| 959 |
if (debug_bp_on_arrival(0x8000, 0)) { printf(" (SP truncated on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 960 |
|
| 961 |
|
| 962 |
uint8_t saved = regs.status; |
| 963 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_P, 0, BPCMP_EQ, saved); |
| 964 |
if (!debug_bp_on_arrival(0x8000, 0)) { printf(" (P on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 965 |
|
| 966 |
g_mem[0x1234] = 0x99; |
| 967 |
g_mem[0x1235] = 0xAB; |
| 968 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_BYTE, 0x1234, BPCMP_EQ, 0x99); |
| 969 |
if (!debug_bp_on_arrival(0x8000, 0)) { printf(" (BYTE on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 970 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_WORD, 0x1234, BPCMP_EQ, 0xAB99); |
| 971 |
if (!debug_bp_on_arrival(0x8000, 0)) { printf(" (WORD on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 972 |
debug_bp_set_condition(0x8000, 0, DEBUG_BANK_ANY, BPOPERAND_WORD, 0x1234, BPCMP_EQ, 0x99AB); |
| 973 |
if (debug_bp_on_arrival(0x8000, 0)) { printf(" (WORD byte order on %s)\n", cpu_mode_name(m)); fixed_ok = false; } |
| 974 |
} |
| 975 |
check(fixed_ok, "SP, P, and memory operands keep their width in every CPU mode"); |
| 976 |
|
| 977 |
reset_all(); |
| 978 |
} |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
{ |
| 987 |
|
| 988 |
reset_all(); |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
debug_bp_add(bp_at(0x0801, 0, 7)); |
| 994 |
bool unbanked_ok = true; |
| 995 |
for (int b = 0; b < 3; b++) { |
| 996 |
g_ram_bank = (uint8_t)(b * 7); |
| 997 |
g_rom_bank = (uint8_t)(b * 3); |
| 998 |
if (!debug_bp_is_set(0x0801, 0)) |
| 999 |
unbanked_ok = false; |
| 1000 |
} |
| 1001 |
check(unbanked_ok, "an unbanked address matches whatever banks are mapped"); |
| 1002 |
|
| 1003 |
|
| 1004 |
check(debug_bank_selector_matches(7, 0x0801, 0), |
| 1005 |
"a bank named for low memory does not filter anything out"); |
| 1006 |
|
| 1007 |
|
| 1008 |
reset_all(); |
| 1009 |
debug_bp_add(bp_at(0xA000, 0, 5)); |
| 1010 |
bool ram_exact_ok = true; |
| 1011 |
for (int b = 0; b < 256; b++) { |
| 1012 |
g_ram_bank = (uint8_t)b; |
| 1013 |
if (debug_bp_is_set(0xA000, 0) != (b == 5)) |
| 1014 |
ram_exact_ok = false; |
| 1015 |
} |
| 1016 |
check(ram_exact_ok, "a RAM-bank breakpoint matches exactly one of all 256 banks"); |
| 1017 |
|
| 1018 |
reset_all(); |
| 1019 |
debug_bp_add(bp_at(0xA000, 0, DEBUG_BANK_ANY)); |
| 1020 |
bool ram_any_ok = true; |
| 1021 |
for (int b = 0; b < 256; b++) { |
| 1022 |
g_ram_bank = (uint8_t)b; |
| 1023 |
if (!debug_bp_is_set(0xA000, 0)) |
| 1024 |
ram_any_ok = false; |
| 1025 |
} |
| 1026 |
check(ram_any_ok, "a bankless RAM breakpoint matches all 256 banks"); |
| 1027 |
|
| 1028 |
|
| 1029 |
reset_all(); |
| 1030 |
debug_bp_add(bp_at(0xE000, 0, 7)); |
| 1031 |
bool rom_exact_ok = true; |
| 1032 |
for (int b = 0; b < 32; b++) { |
| 1033 |
g_rom_bank = (uint8_t)b; |
| 1034 |
if (debug_bp_is_set(0xE000, 0) != (b == 7)) |
| 1035 |
rom_exact_ok = false; |
| 1036 |
} |
| 1037 |
check(rom_exact_ok, "a ROM-bank breakpoint matches exactly one of all 32 banks"); |
| 1038 |
|
| 1039 |
reset_all(); |
| 1040 |
debug_bp_add(bp_at(0xE000, 0, DEBUG_BANK_ANY)); |
| 1041 |
bool rom_any_ok = true; |
| 1042 |
for (int b = 0; b < 32; b++) { |
| 1043 |
g_rom_bank = (uint8_t)b; |
| 1044 |
if (!debug_bp_is_set(0xE000, 0)) |
| 1045 |
rom_any_ok = false; |
| 1046 |
} |
| 1047 |
check(rom_any_ok, "a bankless ROM breakpoint matches all 32 banks"); |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
reset_all(); |
| 1052 |
debug_bp_add(bp_at(0xA000, 0, 4)); |
| 1053 |
debug_bp_add(bp_at(0xE000, 0, 4)); |
| 1054 |
g_ram_bank = 4; |
| 1055 |
g_rom_bank = 9; |
| 1056 |
bool ram_hit = debug_bp_is_set(0xA000, 0), rom_miss = debug_bp_is_set(0xE000, 0); |
| 1057 |
g_ram_bank = 9; |
| 1058 |
g_rom_bank = 4; |
| 1059 |
check(ram_hit && !rom_miss && !debug_bp_is_set(0xA000, 0) && debug_bp_is_set(0xE000, 0), |
| 1060 |
"the two windows use their own bank registers"); |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
reset_all(); |
| 1065 |
is_gen2 = false; |
| 1066 |
debug_bp_add(bp_at(0xA000, 1, 5)); |
| 1067 |
g_ram_bank = 5; |
| 1068 |
bool g1_hit = debug_bp_is_set(0xA000, 1); |
| 1069 |
g_ram_bank = 6; |
| 1070 |
check(g1_hit && !debug_bp_is_set(0xA000, 1), |
| 1071 |
"on a gen1 65C816 the RAM window still applies inside a program bank"); |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
reset_all(); |
| 1076 |
is_gen2 = true; |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
debug_bp_add(bp_at(0xA000, 1, 5)); |
| 1082 |
bool gs_ok = true; |
| 1083 |
for (int b = 0; b < 8; b++) { |
| 1084 |
g_ram_bank = (uint8_t)b; |
| 1085 |
if (!debug_bp_is_set(0xA000, 1)) |
| 1086 |
gs_ok = false; |
| 1087 |
} |
| 1088 |
check(gs_ok, "in a Gen2 program bank the RAM bank does not apply"); |
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
check(debug_bank_selector_matches(5, 0xA000, 1), |
| 1093 |
"a named bank does not filter inside a Gen2 program bank"); |
| 1094 |
g_ram_bank = 5; |
| 1095 |
is_gen2 = false; |
| 1096 |
check(debug_bank_selector_matches(5, 0xA000, 1), |
| 1097 |
"but on gen1 the window still applies inside a program bank"); |
| 1098 |
g_ram_bank = 6; |
| 1099 |
check(!debug_bank_selector_matches(5, 0xA000, 1), |
| 1100 |
"and there it filters on the mapped bank"); |
| 1101 |
is_gen2 = true; |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
check(debug_bp_add(bp_at(0xA000, 1, 3)) == -1, |
| 1106 |
"naming a bank inside a Gen2 program bank does not make a new breakpoint"); |
| 1107 |
|
| 1108 |
|
| 1109 |
reset_all(); |
| 1110 |
is_gen2 = true; |
| 1111 |
debug_bp_add(bp_at(0xA000, 0, 5)); |
| 1112 |
g_ram_bank = 5; |
| 1113 |
bool gs0_hit = debug_bp_is_set(0xA000, 0); |
| 1114 |
g_ram_bank = 6; |
| 1115 |
check(gs0_hit && !debug_bp_is_set(0xA000, 0), |
| 1116 |
"program bank 0 on a Gen2 is banked as usual"); |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
reset_all(); |
| 1121 |
is_gen2 = true; |
| 1122 |
check(debug_bp_add(bp_at(0x8000, 0, DEBUG_BANK_ANY)) == 0 |
| 1123 |
&& debug_bp_add(bp_at(0x8000, 1, DEBUG_BANK_ANY)) == 1, |
| 1124 |
"the same address in two program banks is two breakpoints"); |
| 1125 |
check(debug_bp_is_set(0x8000, 0) && debug_bp_is_set(0x8000, 1) |
| 1126 |
&& !debug_bp_is_set(0x8000, 2), |
| 1127 |
"each program bank matches only itself"); |
| 1128 |
|
| 1129 |
reset_all(); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
{ |
| 1135 |
reset_all(); |
| 1136 |
debug_wp_add(0xA100, 1, 5); |
| 1137 |
bool wp_ram_ok = true; |
| 1138 |
for (int b = 0; b < 256; b++) { |
| 1139 |
g_ram_bank = (uint8_t)b; |
| 1140 |
if (debug_wp_check_write(0xA100, 0) != (b == 5)) |
| 1141 |
wp_ram_ok = false; |
| 1142 |
} |
| 1143 |
check(wp_ram_ok, "a RAM-bank watchpoint fires in exactly one of all 256 banks"); |
| 1144 |
|
| 1145 |
reset_all(); |
| 1146 |
debug_wp_add(0xA100, 1, DEBUG_BANK_ANY); |
| 1147 |
bool wp_any_ok = true; |
| 1148 |
for (int b = 0; b < 256; b++) { |
| 1149 |
g_ram_bank = (uint8_t)b; |
| 1150 |
if (!debug_wp_check_write(0xA100, 0)) |
| 1151 |
wp_any_ok = false; |
| 1152 |
} |
| 1153 |
check(wp_any_ok, "a bankless watchpoint fires in all 256 banks"); |
| 1154 |
|
| 1155 |
reset_all(); |
| 1156 |
debug_wp_add(0xE000, 1, 7); |
| 1157 |
bool wp_rom_ok = true; |
| 1158 |
for (int b = 0; b < 32; b++) { |
| 1159 |
g_rom_bank = (uint8_t)b; |
| 1160 |
if (debug_wp_check_write(0xE000, 0) != (b == 7)) |
| 1161 |
wp_rom_ok = false; |
| 1162 |
} |
| 1163 |
check(wp_rom_ok, "a ROM-window watchpoint fires in exactly one of all 32 banks"); |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
reset_all(); |
| 1169 |
debug_wp_add(0x0400, 1, 7); |
| 1170 |
check(debug_wp_remove(0x0400, DEBUG_BANK_ANY), |
| 1171 |
"an unbanked watchpoint can be removed without naming a bank"); |
| 1172 |
reset_all(); |
| 1173 |
debug_wp_add(0x0400, 1, DEBUG_BANK_ANY); |
| 1174 |
check(debug_wp_remove(0x0400, 7), |
| 1175 |
"and can be removed while naming one, since it means nothing there"); |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
reset_all(); |
| 1182 |
debug_wp_add(0xBFFF, 2, 5); |
| 1183 |
g_ram_bank = 5; |
| 1184 |
g_rom_bank = 9; |
| 1185 |
bool lo_hit = debug_wp_check_write(0xBFFF, 0); |
| 1186 |
check(lo_hit && debug_wp_check_write(0xC000, 0), |
| 1187 |
"a range crossing $C000 keeps its bank meaning throughout"); |
| 1188 |
g_ram_bank = 6; |
| 1189 |
check(!debug_wp_check_write(0xBFFF, 0) && !debug_wp_check_write(0xC000, 0), |
| 1190 |
"and the whole range stops matching when that bank is unmapped"); |
| 1191 |
|
| 1192 |
reset_all(); |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
{ |
| 1203 |
|
| 1204 |
|
| 1205 |
reset_all(); |
| 1206 |
check(debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI) == DEBUG_ADD_CREATED, |
| 1207 |
"the first owner creates the entry"); |
| 1208 |
check(debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE) == DEBUG_ADD_EXISTED, |
| 1209 |
"the second owner joins the entry that is already there"); |
| 1210 |
check(numBreakpoints == 1, "two owners at one address are still one place to stop"); |
| 1211 |
|
| 1212 |
check(debug_bp_remove_for(0x2000, 0, -1, DEBUG_OWNER_CLI), |
| 1213 |
"the first owner can let go"); |
| 1214 |
check(numBreakpoints == 1 && debug_bp_is_set(0x2000, 0), |
| 1215 |
"and the breakpoint stays armed for the owner that still wants it"); |
| 1216 |
check(debug_bp_on_arrival(0x2000, 0), "and still actually fires"); |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
check(debug_bp_remove_for(0x2000, 0, -1, DEBUG_OWNER_DAP_SOURCE), |
| 1222 |
"the last owner can let go too"); |
| 1223 |
check(numBreakpoints == 0 && !debug_bp_is_set(0x2000, 0), |
| 1224 |
"and then nothing is left armed"); |
| 1225 |
|
| 1226 |
|
| 1227 |
reset_all(); |
| 1228 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI); |
| 1229 |
check(!debug_bp_remove_for(0x2000, 0, -1, DEBUG_OWNER_DAP_SOURCE), |
| 1230 |
"an owner that never asked cannot remove"); |
| 1231 |
check(numBreakpoints == 1, "and the entry is untouched"); |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
reset_all(); |
| 1238 |
debug_bp_add_for(bp_at(0x3000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1239 |
check(debug_bp_add_for(bp_at(0x3000, 0, -1), DEBUG_OWNER_DAP_SOURCE) == DEBUG_ADD_EXISTED, |
| 1240 |
"one owner asking twice is idempotent"); |
| 1241 |
check(debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE) == 1, |
| 1242 |
"and one clear retires it exactly once"); |
| 1243 |
check(numBreakpoints == 0, "leaving nothing armed"); |
| 1244 |
|
| 1245 |
|
| 1246 |
reset_all(); |
| 1247 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI); |
| 1248 |
check(debug_bp_clear_owner(DEBUG_OWNER_DAP_FUNCTION) == 0, |
| 1249 |
"clearing an owner that holds nothing disarms nothing"); |
| 1250 |
check(numBreakpoints == 1, "and leaves the table alone"); |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
reset_all(); |
| 1256 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI); |
| 1257 |
debug_bp_set_condition(0x2000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 5); |
| 1258 |
regs.c = 5; |
| 1259 |
debug_bp_on_arrival(0x2000, 0); |
| 1260 |
debug_bp_on_arrival(0x2000, 0); |
| 1261 |
check(debug_bp_get_hits(0x2000, 0, -1) == 2, "the -bp breakpoint has been hit twice"); |
| 1262 |
|
| 1263 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1264 |
check(debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE) == 0, |
| 1265 |
"a DAP session ending disarms nothing another owner still wants"); |
| 1266 |
check(debug_bp_is_set(0x2000, 0), "the -bp breakpoint is still armed"); |
| 1267 |
|
| 1268 |
int has_cond = 0, operand = 0, op = 0; |
| 1269 |
uint32_t value = 0, ignore = 0; |
| 1270 |
uint16_t operand_addr = 0; |
| 1271 |
check(debug_bp_get_condition(0x2000, 0, -1, &has_cond, &operand, &operand_addr, &op, |
| 1272 |
&value, &ignore) |
| 1273 |
&& has_cond && operand == BPOPERAND_A && op == BPCMP_EQ && value == 5, |
| 1274 |
"with its condition intact"); |
| 1275 |
check(debug_bp_get_hits(0x2000, 0, -1) == 2, "and its hit count intact"); |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
reset_all(); |
| 1281 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1282 |
debug_bp_on_arrival(0x2000, 0); |
| 1283 |
debug_bp_on_arrival(0x2000, 0); |
| 1284 |
debug_bp_on_arrival(0x2000, 0); |
| 1285 |
debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE); |
| 1286 |
check(numBreakpoints == 0, "the client's breakpoint goes when the client drops it"); |
| 1287 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1288 |
check(debug_bp_get_hits(0x2000, 0, -1) == 3, |
| 1289 |
"but re-sending the same breakpoint keeps its hit count"); |
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
reset_all(); |
| 1297 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1298 |
debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE); |
| 1299 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_UI); |
| 1300 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1301 |
debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE); |
| 1302 |
check(numBreakpoints == 1 && debug_bp_is_set(0x2000, 0), |
| 1303 |
"a client session ending leaves the user's F9 breakpoint armed"); |
| 1304 |
check(debug_bp_has_owner(0x2000, 0, -1, DEBUG_OWNER_UI) |
| 1305 |
&& !debug_bp_has_owner(0x2000, 0, -1, DEBUG_OWNER_DAP_SOURCE), |
| 1306 |
"and owned by the user alone"); |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
reset_all(); |
| 1311 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI); |
| 1312 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1313 |
debug_bp_remove_for(0x2000, 0, -1, DEBUG_OWNER_DAP_SOURCE); |
| 1314 |
debug_bp_remove_for(0x2000, 0, -1, DEBUG_OWNER_CLI); |
| 1315 |
check(numBreakpoints == 0, "both owners letting go clears the address"); |
| 1316 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1317 |
debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE); |
| 1318 |
check(numBreakpoints == 0, |
| 1319 |
"and a later client breakpoint there is not mistaken for the user's"); |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
reset_all(); |
| 1326 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1327 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_FUNCTION); |
| 1328 |
check(debug_bp_delete(0x2000, 0, -1), "the user can delete a client's breakpoint"); |
| 1329 |
check(numBreakpoints == 0 && !debug_bp_is_set(0x2000, 0), |
| 1330 |
"and it is really gone, not merely down one owner"); |
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
reset_all(); |
| 1335 |
debug_bp_toggle_for(0x2000, 0, -1, DEBUG_OWNER_UI); |
| 1336 |
check(debug_bp_is_set(0x2000, 0) && debug_bp_has_owner(0x2000, 0, -1, DEBUG_OWNER_UI), |
| 1337 |
"F9 on a clear address arms one for the user"); |
| 1338 |
debug_bp_toggle_for(0x2000, 0, -1, DEBUG_OWNER_UI); |
| 1339 |
check(!debug_bp_is_set(0x2000, 0), "and F9 again takes it away"); |
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
reset_all(); |
| 1346 |
debug_bp_add_for(bp_at(0x0801, 0, 7), DEBUG_OWNER_DAP_SOURCE); |
| 1347 |
check(debug_bp_has_owner(0x0801, 0, DEBUG_BANK_ANY, DEBUG_OWNER_DAP_SOURCE), |
| 1348 |
"an owner recorded with a meaningless bank is found without one"); |
| 1349 |
check(debug_bp_remove_for(0x0801, 0, DEBUG_BANK_ANY, DEBUG_OWNER_DAP_SOURCE), |
| 1350 |
"and can let go without naming it"); |
| 1351 |
check(numBreakpoints == 0, "leaving nothing behind"); |
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
reset_all(); |
| 1359 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_CLI); |
| 1360 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1361 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1362 |
debug_bp_add_for(bp_at(0x2100, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1363 |
debug_bp_set_condition(0x2000, 0, -1, BPOPERAND_A, 0, BPCMP_EQ, 5); |
| 1364 |
regs.c = 5; |
| 1365 |
debug_bp_on_arrival(0x2000, 0); |
| 1366 |
|
| 1367 |
debug_bp_clear_owner(DEBUG_OWNER_DAP_SOURCE); |
| 1368 |
check(debug_bp_is_set(0x2000, 0), |
| 1369 |
"clearing the owner leaves an address another owner still wants"); |
| 1370 |
check(!debug_bp_is_set(0x2100, 0), "and releases the one only it wanted"); |
| 1371 |
|
| 1372 |
|
| 1373 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1374 |
check(debug_bp_is_set(0x2000, 0) && numBreakpoints == 1, |
| 1375 |
"re-asserting a claim restores it without duplicating the entry"); |
| 1376 |
check(debug_bp_get_hits(0x2000, 0, -1) == 1, |
| 1377 |
"and the hit count survives the round trip"); |
| 1378 |
check(debug_bp_get_condition(0x2000, 0, -1, &has_cond, NULL, NULL, NULL, NULL, NULL) |
| 1379 |
&& has_cond, |
| 1380 |
"as does the condition, which belongs to the address"); |
| 1381 |
|
| 1382 |
reset_all(); |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
{ |
| 1390 |
reset_all(); |
| 1391 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_UI); |
| 1392 |
debug_bp_on_arrival(0x2000, 0); |
| 1393 |
debug_bp_on_arrival(0x2000, 0); |
| 1394 |
|
| 1395 |
check(debug_bp_set_enabled(0x2000, 0, -1, false), "a breakpoint can be disabled"); |
| 1396 |
check(numBreakpoints == 1, "and keeps its place in the table"); |
| 1397 |
check(!debug_bp_is_set(0x2000, 0), "but no longer counts as set"); |
| 1398 |
check(!debug_bp_on_arrival(0x2000, 0), "and does not stop the machine"); |
| 1399 |
check(debug_bp_get_hits(0x2000, 0, -1) == 2, |
| 1400 |
"arriving while disabled does not spend the count"); |
| 1401 |
check(debug_bp_has_owner(0x2000, 0, -1, DEBUG_OWNER_UI), |
| 1402 |
"and it still belongs to whoever asked for it"); |
| 1403 |
|
| 1404 |
check(debug_bp_set_enabled(0x2000, 0, -1, true), "and can be enabled again"); |
| 1405 |
check(debug_bp_on_arrival(0x2000, 0), "whereupon it fires again"); |
| 1406 |
check(debug_bp_get_hits(0x2000, 0, -1) == 3, "carrying its count with it"); |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
debug_bp_set_enabled(0x2000, 0, -1, false); |
| 1411 |
debug_bp_add_for(bp_at(0x2000, 0, -1), DEBUG_OWNER_DAP_SOURCE); |
| 1412 |
check(debug_bp_is_enabled(0x2000, 0, -1), "re-adding a disabled breakpoint re-arms it"); |
| 1413 |
|
| 1414 |
check(!debug_bp_set_enabled(0x9999, 0, -1, false), |
| 1415 |
"enabling something that is not there reports so"); |
| 1416 |
|
| 1417 |
reset_all(); |
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
{ |
| 1424 |
reset_all(); |
| 1425 |
check(debug_wp_add_for(0xA100, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI) == DEBUG_ADD_CREATED, |
| 1426 |
"-wp creates the watchpoint"); |
| 1427 |
check(debug_wp_add_for(0xA100, 1, DEBUG_BANK_ANY, DEBUG_OWNER_DAP_SOURCE) |
| 1428 |
== DEBUG_ADD_EXISTED, |
| 1429 |
"a data breakpoint joins it"); |
| 1430 |
check(debug_wp_count() == 1, "two owners share one watch"); |
| 1431 |
|
| 1432 |
debug_wp_set_value(0xA100, DEBUG_BANK_ANY, BPCMP_EQ, 0x42); |
| 1433 |
check(debug_wp_clear_owner(DEBUG_OWNER_DAP_SOURCE) == 0, |
| 1434 |
"the client's session ending disarms nothing -wp still wants"); |
| 1435 |
check(debug_wp_count() == 1, "the -wp watchpoint survives"); |
| 1436 |
check(debug_wp_check_write(0xA100, 0x42) && !debug_wp_check_write(0xA100, 0x01), |
| 1437 |
"with its value filter intact"); |
| 1438 |
|
| 1439 |
check(debug_wp_remove_for(0xA100, DEBUG_BANK_ANY, DEBUG_OWNER_CLI), |
| 1440 |
"and goes when its last owner does"); |
| 1441 |
check(debug_wp_count() == 0, "leaving nothing watched"); |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
reset_all(); |
| 1446 |
debug_wp_add_for(0xA100, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 1447 |
debug_wp_add_for(0xA100, 1, DEBUG_BANK_ANY, DEBUG_OWNER_DAP_CONSOLE); |
| 1448 |
check(debug_wp_delete(0xA100, DEBUG_BANK_ANY), "a delete takes the whole watch"); |
| 1449 |
check(debug_wp_count() == 0, "whoever asked for it"); |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
reset_all(); |
| 1455 |
bool filled = true; |
| 1456 |
for (int i = 0; i < MAX_WATCHPOINTS; i++) { |
| 1457 |
if (debug_wp_add_for((uint16_t)(0x1000 + i), 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI) |
| 1458 |
!= DEBUG_ADD_CREATED) |
| 1459 |
filled = false; |
| 1460 |
} |
| 1461 |
check(filled, "the watchpoint table takes its full complement"); |
| 1462 |
check(debug_wp_add_for(0x2000, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI) == DEBUG_ADD_FULL, |
| 1463 |
"one more reports a full table"); |
| 1464 |
check(debug_wp_add_for(0x1000, 1, DEBUG_BANK_ANY, DEBUG_OWNER_DAP_SOURCE) |
| 1465 |
== DEBUG_ADD_EXISTED, |
| 1466 |
"which is not the same answer as one that is already there"); |
| 1467 |
|
| 1468 |
reset_all(); |
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
{ |
| 1480 |
reset_all(); |
| 1481 |
is_gen2 = false; |
| 1482 |
struct breakpoint bp; |
| 1483 |
|
| 1484 |
check(debug_bp_from_ref(0xA555, DEBUG_BANK_ANY, 0, &bp) |
| 1485 |
&& bp.pc == 0xA555 && bp.bank == 0 && bp.x16Bank == DEBUG_BANK_ANY, |
| 1486 |
"a bare address names no bank and matches whichever is mapped"); |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
check(debug_bp_from_ref(0x33A555, DEBUG_BANK_ANY, 0, &bp) |
| 1491 |
&& bp.pc == 0xA555 && bp.bank == 0 && bp.x16Bank == 0x33, |
| 1492 |
"a packed bank byte is the window bank on a gen1, not the program bank"); |
| 1493 |
|
| 1494 |
|
| 1495 |
struct breakpoint colon; |
| 1496 |
check(debug_bp_from_ref(0xA555, 0x33, 0, &colon) |
| 1497 |
&& colon.pc == bp.pc && colon.bank == bp.bank |
| 1498 |
&& colon.x16Bank == bp.x16Bank, |
| 1499 |
"the bb:aaaa form and the packed form describe one breakpoint"); |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
check(debug_bp_add(bp) == 0, "the resolved breakpoint goes into the table"); |
| 1504 |
g_ram_bank = 0x33; |
| 1505 |
bool armed = debug_bp_is_set(0xA555, 0); |
| 1506 |
g_ram_bank = 0x34; |
| 1507 |
check(armed && !debug_bp_is_set(0xA555, 0), |
| 1508 |
"and fires in the bank it named, and only there"); |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
reset_all(); |
| 1513 |
is_gen2 = false; |
| 1514 |
debug_bp_add(bp_at(0xA555, 0x33, DEBUG_BANK_ANY)); |
| 1515 |
bool dead = true; |
| 1516 |
for (int b = 0; b < 0x40; b++) { |
| 1517 |
g_ram_bank = (uint8_t)b; |
| 1518 |
if (debug_bp_is_set(0xA555, 0)) |
| 1519 |
dead = false; |
| 1520 |
} |
| 1521 |
check(dead, "a window bank left in the program-bank field can never match"); |
| 1522 |
|
| 1523 |
reset_all(); |
| 1524 |
is_gen2 = false; |
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
check(!debug_bp_from_ref(0x330555, DEBUG_BANK_ANY, 0, &bp), |
| 1529 |
"a bank packed onto an unbanked address is refused"); |
| 1530 |
check(!debug_bp_from_ref(0x0555, 0x33, 0, &bp), |
| 1531 |
"and so is one named alongside it"); |
| 1532 |
|
| 1533 |
check(!debug_bp_from_ref(0x33A555, 0x34, 0, &bp), |
| 1534 |
"a bank given twice, two different ways, is refused"); |
| 1535 |
|
| 1536 |
check(!debug_bp_from_ref(-1, DEBUG_BANK_ANY, 0, &bp) |
| 1537 |
&& !debug_bp_from_ref(0x1000000, DEBUG_BANK_ANY, 0, &bp), |
| 1538 |
"a reference outside 24 bits is refused"); |
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
check(debug_bp_from_ref(0x33A555, DEBUG_BANK_ANY, 0x10, &bp) |
| 1543 |
&& bp.pc == 0xA565 && bp.x16Bank == 0x33, |
| 1544 |
"an offset moves the address and leaves the bank alone"); |
| 1545 |
check(debug_bp_from_ref(0xFFFF, DEBUG_BANK_ANY, 1, &bp) && bp.pc == 0x0000, |
| 1546 |
"and wraps inside 16 bits rather than into the bank byte"); |
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
is_gen2 = true; |
| 1551 |
check(debug_bp_from_ref(0x01A555, DEBUG_BANK_ANY, 0, &bp) |
| 1552 |
&& bp.pc == 0xA555 && bp.bank == 1 && bp.x16Bank == DEBUG_BANK_ANY, |
| 1553 |
"on a Gen2 a packed bank byte is the program bank"); |
| 1554 |
check(debug_bp_from_ref(0xA555, 5, 0, &bp) |
| 1555 |
&& bp.pc == 0xA555 && bp.bank == 0 && bp.x16Bank == 5, |
| 1556 |
"and program bank 0 there is still the windowed map"); |
| 1557 |
|
| 1558 |
reset_all(); |
| 1559 |
is_gen2 = true; |
| 1560 |
} |
| 1561 |
|
| 1562 |
debug_core_free(); |
| 1563 |
|
| 1564 |
if (failures) { |
| 1565 |
printf("\nFAILED (%d failures)\n", failures); |
| 1566 |
return 1; |
| 1567 |
} |
| 1568 |
printf("\nPASSED (0 failures)\n"); |
| 1569 |
return 0; |
| 1570 |
} |