2 * PDB, the PicoDrive debugger
5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
11 #include <sys/types.h>
12 #include <sys/socket.h>
16 #include "debug_net.h"
18 static const char * const regnames[] = {
20 "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",
21 "R8", "R9", "R10", "R11", "R12", "R13", "R14", "SP",
22 "PC2", "PC3", "PR", "SR", "GBR", "VBR", "MACH", "MACL",
23 "MEM0", "MEM1", // mem i/o csums
26 int main(int argc, char *argv[])
28 unsigned int pc_trace[5][4], pc_trace_p[5] = { 0, };
29 struct addrinfo *ai, *ais, hints;
30 int sock = -1, sock1, sock2;
31 struct sockaddr_in6 sa;
32 packet_t packet1, packet2;
33 int i, ret, cnt, cpuid;
34 int check_len_override = 0;
38 check_len_override = atoi(argv[1]);
40 memset(&hints, 0, sizeof(hints));
41 hints.ai_flags = AI_CANONNAME;
42 hints.ai_family = PF_UNSPEC;
43 hints.ai_socktype = SOCK_STREAM;
45 ret = getaddrinfo("::", "1234", &hints, &ais);
49 for (ai = ais; ai != NULL; ai = ai->ai_next) {
50 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
54 ret = bind(sock, ai->ai_addr, ai->ai_addrlen);
65 perror("failed to bind");
69 ret = listen(sock, SOMAXCONN);
71 perror("failed to listen");
76 sock1 = accept(sock, (struct sockaddr *)&sa, &sal);
78 perror("failed to accept");
81 printf("client1 connected\n");
84 sock2 = accept(sock, (struct sockaddr *)&sa, &sal);
86 perror("failed to accept");
89 printf("client2 connected\n");
91 for (cnt = 0; ; cnt++)
94 #define tmp_size (4+4 + 24*4 + 2*4)
95 ret = recv(sock1, &packet1, tmp_size, MSG_WAITALL);
96 if (ret != tmp_size) {
100 printf("recv1 %d\n", ret);
103 ret = recv(sock2, &packet2, tmp_size, MSG_WAITALL);
104 if (ret != tmp_size) {
108 printf("recv2 %d\n", ret);
112 cpuid = packet1.header.cpuid;
113 len = sizeof(packet1.header) + packet1.header.len;
114 if (check_len_override > 0)
115 len = check_len_override;
117 if (memcmp(&packet1, &packet2, len) == 0) {
118 pc_trace[cpuid][pc_trace_p[cpuid]++ & 3] = packet1.regs[0];
122 if (packet1.header.cpuid != packet2.header.cpuid)
123 printf("%d: CPU %d %d\n", cnt, packet1.header.cpuid & 0xff, packet2.header.cpuid & 0xff);
124 else if (*(int *)&packet1.header != *(int *)&packet2.header)
125 printf("%d: header\n", cnt);
127 // check regs (and stuff)
128 for (i = 0; i < 1+24+2; i++)
129 if (packet1.regs[i] != packet2.regs[i])
130 printf("%d: %3s: %08x %08x\n", cnt, regnames[i], packet1.regs[i], packet2.regs[i]);
135 printf("--\nCPU %d\n", cpuid);
136 for (cpuid = 0; cpuid < 2; cpuid++) {
137 printf("trace%d: ", cpuid);
138 for (i = 0; i < 4; i++)
139 printf(" %08x", pc_trace[cpuid][pc_trace_p[cpuid]++ & 3]);
141 if (packet1.header.cpuid == cpuid)
142 printf(" %08x", packet1.regs[0]);
143 else if (packet2.header.cpuid == cpuid)
144 printf(" %08x", packet2.regs[0]);
148 for (i = 0; i < 24+1; i++)
149 printf("%3s: %08x %08x\n", regnames[i], packet1.regs[i], packet2.regs[i]);