| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "support/fake_devices.h" |
| 18 |
#include "support/harness.h" |
| 19 |
#include "support/signature.h" |
| 20 |
|
| 21 |
#include "debug_core.h" |
| 22 |
#include "memory.h" |
| 23 |
|
| 24 |
#include <stdint.h> |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
extern uint8_t *RAM; |
| 29 |
extern uint32_t clockticks6502; |
| 30 |
|
| 31 |
#define SCRATCH 0x0400 |
| 32 |
#define VERA_REG 0x9F23 |
| 33 |
|
| 34 |
|
| 35 |
extern int fake_break_count; |
| 36 |
|
| 37 |
static void |
| 38 |
setup(void) |
| 39 |
{ |
| 40 |
fake_devices_reset(); |
| 41 |
debug_wp_clear_all(); |
| 42 |
fake_break_count = 0; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
static void |
| 48 |
test_watched_store_still_writes(void) |
| 49 |
{ |
| 50 |
setup(); |
| 51 |
RAM[SCRATCH] = 0x00; |
| 52 |
debug_wp_add_for(SCRATCH, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 53 |
|
| 54 |
write6502(SCRATCH, 0, 0x5A); |
| 55 |
|
| 56 |
check_eq(RAM[SCRATCH], 0x5A, "a watched address still receives the store"); |
| 57 |
check(fake_break_count > 0, "and the watchpoint reported a break"); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static void |
| 64 |
test_watched_io_store_still_reaches_device(void) |
| 65 |
{ |
| 66 |
setup(); |
| 67 |
debug_wp_add_for(VERA_REG, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 68 |
|
| 69 |
write6502(VERA_REG, 0, 0x77); |
| 70 |
|
| 71 |
check_eq(fake_dev[FAKE_VERA].writes, 1, "a watched I/O store still reaches VERA"); |
| 72 |
check_eq(fake_dev[FAKE_VERA].last_value, 0x77, "with the value the program wrote"); |
| 73 |
check(fake_break_count > 0, "and the watchpoint reported a break"); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
static void |
| 79 |
test_watch_does_not_alter_the_machine(void) |
| 80 |
{ |
| 81 |
|
| 82 |
|
| 83 |
setup(); |
| 84 |
write6502(SCRATCH, 0, 0x11); |
| 85 |
write6502(VERA_REG, 0, 0x22); |
| 86 |
machine_sig_t unwatched = machine_signature(); |
| 87 |
|
| 88 |
setup(); |
| 89 |
debug_wp_add_for(SCRATCH, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 90 |
write6502(SCRATCH, 0, 0x11); |
| 91 |
write6502(VERA_REG, 0, 0x22); |
| 92 |
machine_sig_t watched = machine_signature(); |
| 93 |
|
| 94 |
check(machine_sig_equal(unwatched, watched), |
| 95 |
"a watchpoint changes nothing about the stores themselves"); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static void |
| 101 |
test_unrelated_watch_is_inert(void) |
| 102 |
{ |
| 103 |
setup(); |
| 104 |
write6502(SCRATCH, 0, 0x33); |
| 105 |
machine_sig_t clean = machine_signature(); |
| 106 |
|
| 107 |
setup(); |
| 108 |
debug_wp_add_for(0x0500, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 109 |
write6502(SCRATCH, 0, 0x33); |
| 110 |
machine_sig_t with_other = machine_signature(); |
| 111 |
|
| 112 |
check(machine_sig_equal(clean, with_other), |
| 113 |
"a watchpoint on another address leaves the machine alone"); |
| 114 |
check_eq(fake_break_count, 0, "and does not report a break"); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
static void |
| 122 |
test_watching_costs_no_cycles(void) |
| 123 |
{ |
| 124 |
setup(); |
| 125 |
write6502(SCRATCH, 0, 0x44); |
| 126 |
uint32_t plain = clockticks6502; |
| 127 |
|
| 128 |
setup(); |
| 129 |
debug_wp_add_for(SCRATCH, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 130 |
write6502(SCRATCH, 0, 0x44); |
| 131 |
check_eq(clockticks6502, plain, "a watched store costs the same as any other"); |
| 132 |
|
| 133 |
|
| 134 |
setup(); |
| 135 |
write6502(0x9FA0, 0, 0x55); |
| 136 |
uint32_t io_plain = clockticks6502; |
| 137 |
|
| 138 |
setup(); |
| 139 |
debug_wp_add_for(0x9FA0, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 140 |
write6502(0x9FA0, 0, 0x55); |
| 141 |
check_eq(clockticks6502, io_plain, "and a watched slow-I/O store costs the same"); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
static void |
| 147 |
test_value_filter_still_writes(void) |
| 148 |
{ |
| 149 |
setup(); |
| 150 |
debug_wp_add_for(SCRATCH, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 151 |
debug_wp_set_value(SCRATCH, DEBUG_BANK_ANY, BPCMP_EQ, 0x99); |
| 152 |
|
| 153 |
write6502(SCRATCH, 0, 0x01); |
| 154 |
check_eq(RAM[SCRATCH], 0x01, "a store that fails the filter still writes"); |
| 155 |
check_eq(fake_break_count, 0, "and reports no break"); |
| 156 |
|
| 157 |
write6502(SCRATCH, 0, 0x99); |
| 158 |
check_eq(RAM[SCRATCH], 0x99, "a store that matches the filter also writes"); |
| 159 |
check(fake_break_count > 0, "and reports a break"); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
static void |
| 165 |
test_inactive_watch_is_inert(void) |
| 166 |
{ |
| 167 |
setup(); |
| 168 |
debug_wp_add_for(SCRATCH, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 169 |
debug_wp_set_active(SCRATCH, DEBUG_BANK_ANY, false); |
| 170 |
|
| 171 |
write6502(SCRATCH, 0, 0x66); |
| 172 |
check_eq(RAM[SCRATCH], 0x66, "a disabled watchpoint still lets the store through"); |
| 173 |
check_eq(fake_break_count, 0, "and reports no break"); |
| 174 |
} |
| 175 |
|
| 176 |
int |
| 177 |
main(void) |
| 178 |
{ |
| 179 |
test_watched_store_still_writes(); |
| 180 |
test_watched_io_store_still_reaches_device(); |
| 181 |
test_watch_does_not_alter_the_machine(); |
| 182 |
test_unrelated_watch_is_inert(); |
| 183 |
test_watching_costs_no_cycles(); |
| 184 |
test_value_filter_still_writes(); |
| 185 |
test_inactive_watch_is_inert(); |
| 186 |
return x16_test_summary("watchpoint_purity"); |
| 187 |
} |