@@ -24,10 +24,19 @@ static int packet_mismatch;
int send_register_info(write_fn write_fn, void *uc)
{
struct reginfo ri;
+ trace_header_t header;
int op;
+
reginfo_init(&ri, uc);
op = get_risuop(&ri);
+ /* Write a header with PC/op to keep in sync */
+ header.pc = get_pc(&ri);
+ header.risu_op = op;
+ if (write_fn(&header, sizeof(header)) != 0) {
+ return -1;
+ }
+
switch (op) {
case OP_TESTEND:
return write_fn(&ri, sizeof(ri));
@@ -62,46 +71,63 @@ int send_register_info(write_fn write_fn, void *uc)
int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
{
int resp = 0, op;
+ trace_header_t header;
reginfo_init(&master_ri, uc);
op = get_risuop(&master_ri);
- switch (op) {
- case OP_COMPARE:
- case OP_TESTEND:
- default:
- /* Do a simple register compare on (a) explicit request
- * (b) end of test (c) a non-risuop UNDEF
- */
- if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
- packet_mismatch = 1;
- resp = 2;
- } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
- /* register mismatch */
- resp = 2;
- } else if (op == OP_TESTEND) {
- resp = 1;
- }
- resp_fn(resp);
- break;
- case OP_SETMEMBLOCK:
- memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
- break;
- case OP_GETMEMBLOCK:
- set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
- (uintptr_t)memblock);
- break;
- case OP_COMPAREMEM:
- mem_used = 1;
- if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
- packet_mismatch = 1;
- resp = 2;
- } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
- /* memory mismatch */
- resp = 2;
+ if (read_fn(&header, sizeof(header)) != 0) {
+ return -1;
+ }
+
+ if (header.risu_op == op ) {
+
+ /* send OK for the header */
+ resp_fn(0);
+
+ switch (op) {
+ case OP_COMPARE:
+ case OP_TESTEND:
+ default:
+ /* Do a simple register compare on (a) explicit request
+ * (b) end of test (c) a non-risuop UNDEF
+ */
+ if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
+ packet_mismatch = 1;
+ resp = 2;
+
+ } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
+ /* register mismatch */
+ resp = 2;
+
+ } else if (op == OP_TESTEND) {
+ resp = 1;
+ }
+ resp_fn(resp);
+ break;
+ case OP_SETMEMBLOCK:
+ memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
+ break;
+ case OP_GETMEMBLOCK:
+ set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
+ (uintptr_t)memblock);
+ break;
+ case OP_COMPAREMEM:
+ mem_used = 1;
+ if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
+ packet_mismatch = 1;
+ resp = 2;
+ } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
+ /* memory mismatch */
+ resp = 2;
+ }
+ resp_fn(resp);
+ break;
}
+ } else {
+ /* We are out of sync */
+ resp = 2;
resp_fn(resp);
- break;
}
return resp;
@@ -50,6 +50,12 @@ extern int test_fp_exc;
struct reginfo;
+typedef struct
+{
+ uintptr_t pc;
+ uint32_t risu_op;
+} trace_header_t;
+
/* Functions operating on reginfo */
/* Function prototypes for read/write helper functions.
@@ -102,6 +108,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri);
*/
int get_risuop(struct reginfo *ri);
+/* Return the PC from a reginfo */
+uintptr_t get_pc(struct reginfo *ri);
+
/* initialize structure from a ucontext */
void reginfo_init(struct reginfo *ri, ucontext_t *uc);
@@ -40,3 +40,8 @@ int get_risuop(struct reginfo *ri)
uint32_t risukey = 0x00005af0;
return (key != risukey) ? -1 : op;
}
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+ return ri->pc;
+}
@@ -68,3 +68,8 @@ int get_risuop(struct reginfo *ri)
uint32_t risukey = (isz == 2) ? 0xdee0 : 0xe7fe5af0;
return (key != risukey) ? -1 : op;
}
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+ return ri->gpreg[15];
+}
@@ -33,3 +33,8 @@ int get_risuop(struct reginfo *ri)
uint32_t risukey = 0x4afc7000;
return (key != risukey) ? -1 : op;
}
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+ return ri->gregs[R_PC];
+}
@@ -38,3 +38,8 @@ int get_risuop(struct reginfo *ri)
uint32_t risukey = 0x00005af0;
return (key != risukey) ? -1 : op;
}
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+ return ri->nip;
+}