forked from stsquad/risu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrisu_reginfo_m68k.c
More file actions
158 lines (129 loc) · 4.3 KB
/
risu_reginfo_m68k.c
File metadata and controls
158 lines (129 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*****************************************************************************
* Copyright (c) 2016 Laurent Vivier
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*****************************************************************************/
#include <stdio.h>
#include <ucontext.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "risu.h"
#include "risu_reginfo_m68k.h"
const struct option * const arch_long_opts;
const char * const arch_extra_help;
void process_arch_opt(int opt, const char *arg)
{
abort();
}
void arch_init(void)
{
}
int reginfo_size(struct reginfo *ri)
{
return sizeof(*ri);
}
/* reginfo_init: initialize with a ucontext */
void reginfo_init(struct reginfo *ri, ucontext_t *uc, void *siaddr)
{
int i;
memset(ri, 0, sizeof(*ri));
ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.gregs[R_PC]);
ri->pc = uc->uc_mcontext.gregs[R_PC] - image_start_address;
for (i = 0; i < NGREG; i++) {
ri->gregs[i] = uc->uc_mcontext.gregs[i];
}
ri->fpregs.f_pcr = uc->uc_mcontext.fpregs.f_pcr;
ri->fpregs.f_psr = uc->uc_mcontext.fpregs.f_psr;
ri->fpregs.f_fpiaddr = uc->uc_mcontext.fpregs.f_fpiaddr;
for (i = 0; i < 8; i++) {
memcpy(ri->fpregs.f_fpregs[i],
uc->uc_mcontext.fpregs.f_fpregs[i],
sizeof(ri->fpregs.f_fpregs[0]));
}
}
/* reginfo_is_eq: compare the reginfo structs, returns true if equal */
bool reginfo_is_eq(struct reginfo *m, struct reginfo *a)
{
int i;
if (m->gregs[R_PS] != a->gregs[R_PS]) {
return false;
}
for (i = 0; i < 16; i++) {
if (i == R_SP || i == R_A6) {
continue;
}
if (m->gregs[i] != a->gregs[i]) {
return false;
}
}
if (m->fpregs.f_pcr != a->fpregs.f_pcr) {
return false;
}
if (m->fpregs.f_psr != a->fpregs.f_psr) {
return false;
}
for (i = 0; i < 8; i++) {
if (m->fpregs.f_fpregs[i][0] != a->fpregs.f_fpregs[i][0] ||
m->fpregs.f_fpregs[i][1] != a->fpregs.f_fpregs[i][1] ||
m->fpregs.f_fpregs[i][2] != a->fpregs.f_fpregs[i][2]) {
return false;
}
}
return true;
}
/* reginfo_dump: print state to a stream */
void reginfo_dump(struct reginfo *ri, FILE *f)
{
int i;
fprintf(f, " pc \e[1;101;37m0x%08x\e[0m\n", ri->pc);
fprintf(f, "\tPC: %08x\n", ri->gregs[R_PC]);
fprintf(f, "\tPS: %04x\n", ri->gregs[R_PS]);
for (i = 0; i < 8; i++) {
fprintf(f, "\tD%d: %8x\tA%d: %8x\n", i, ri->gregs[i],
i, ri->gregs[i + 8]);
}
for (i = 0; i < 8; i++) {
fprintf(f, "\tFP%d: %08x %08x %08x\n", i,
ri->fpregs.f_fpregs[i][0], ri->fpregs.f_fpregs[i][1],
ri->fpregs.f_fpregs[i][2]);
}
fprintf(f, "\n");
}
void reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
{
int i;
if (m->gregs[R_PS] != a->gregs[R_PS]) {
fprintf(f, " PS: %08x vs %08x\n",
m->gregs[R_PS], a->gregs[R_PS]);
}
for (i = 0; i < 16; i++) {
if (i == R_SP || i == R_A6) {
continue;
}
if (m->gregs[i] != a->gregs[i]) {
fprintf(f, " %c%d: %08x vs %08x\n",
i < 8 ? 'D' : 'A', i % 8, m->gregs[i], a->gregs[i]);
}
}
if (m->fpregs.f_pcr != a->fpregs.f_pcr) {
fprintf(f, " FPCR: %04x vs %04x\n",
m->fpregs.f_pcr, a->fpregs.f_pcr);
}
if (m->fpregs.f_psr != a->fpregs.f_psr) {
fprintf(f, " FPSR: %04x vs %04x\n",
m->fpregs.f_psr, a->fpregs.f_psr);
}
for (i = 0; i < 8; i++) {
if (m->fpregs.f_fpregs[i][0] != a->fpregs.f_fpregs[i][0] ||
m->fpregs.f_fpregs[i][1] != a->fpregs.f_fpregs[i][1] ||
m->fpregs.f_fpregs[i][2] != a->fpregs.f_fpregs[i][2]) {
fprintf(f, " FP%d: %08x%08x%08x vs %08x%08x%08x\n", i,
m->fpregs.f_fpregs[i][0], m->fpregs.f_fpregs[i][1],
m->fpregs.f_fpregs[i][2], a->fpregs.f_fpregs[i][0],
a->fpregs.f_fpregs[i][1], a->fpregs.f_fpregs[i][2]);
}
}
}