pa1.3: watchpoint support

This commit is contained in:
xinyangli 2024-02-08 20:07:03 +08:00
parent 2675a647b0
commit 504d270947
14 changed files with 363 additions and 36 deletions

View file

@ -1,5 +1,6 @@
#include "macro.h"
#include "sys/types.h"
#include "unistd.h"
#include <unistd.h>
#include <assert.h>
#include <check.h>
#include <math.h>
@ -9,6 +10,8 @@
#include <time.h>
#include <addrexp.h>
#include <addrexp_lex.h>
#include <isa.h>
#include <reg.h>
char buf[65536] = {}, ref_buf[65536] = {};
static char code_buf[65536 + 128] = {}; // a little larger than `buf`
@ -147,6 +150,12 @@ struct {
{"-0x1", 0xFFFFFFFFU},
{"0--1", 0x1},
{"0--0x1", 0x1},
}, reg_exprs[] = {
{"$ra", 0x1},
{"0x2 + 4*-$a7", 0xFFFFFFBEU},
{"0x1831/$gp + 13", 2077U},
{"$$0 == 123", 0},
{"$$0 == 0", 1},
};
START_TEST(test_expr_negative_operand) {
yy_scan_string(exprs[_i].expr);
@ -160,6 +169,47 @@ START_TEST(test_expr_negative_operand) {
}
END_TEST
extern const char *regs[];
START_TEST(test_expr_plain_register) {
int i, j, result;
char buf[30] = {};
uint32_t value;
// NOTE: need to fix this if want to support more arch
buf[0] = '$';
for (i = 0; i < 32; i++) {
ck_assert(strncpy(buf + 1, regs[i], 10) != NULL);
gpr(i) = i;
yy_scan_string(buf);
result = yyparse(&value);
yylex_destroy();
ck_assert_msg(result == 0, "expr = %s\n", buf);
ck_assert(value == i);
for (j = 1; j < 10; j++) {
buf[j] = '\0';
}
}
}
END_TEST
START_TEST(test_expr_register) {
int i;
uint32_t value;
for (i = 0; i < 32; i++) {
gpr(i) = i;
}
yy_scan_string(reg_exprs[_i].expr);
ck_assert(!yyparse(&value));
yylex_destroy();
ck_assert_msg(value == reg_exprs[_i].reference,
"\n\texpr = %s\n\t(addr = %u) != (reference = %u)\n", reg_exprs[_i].expr,
value, reg_exprs[_i].reference);
}
END_TEST
Suite *expr_suite(void) {
Suite *s;
TCase *tc_core;
@ -170,6 +220,9 @@ Suite *expr_suite(void) {
tcase_add_loop_test(tc_core, test_expr_random_100, 0, 20);
tcase_add_loop_test(tc_core, test_expr_negative_operand, 0,
sizeof(exprs) / sizeof(exprs[0]));
tcase_add_loop_test(tc_core, test_expr_register, 0,
sizeof(reg_exprs) / sizeof(reg_exprs[0]));
tcase_add_test(tc_core, test_expr_plain_register);
suite_add_tcase(s, tc_core);
return s;