Newer
Older
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
#include <stdio.h>
#include <mips/cpu.h>
#include "lisp.h"
#include "globals.h"
#include "validate.h"
#include "os.h"
#include "internals.h"
#include "arch.h"
#include "lispregs.h"
#include "signal.h"
#include "alloc.h"
#include "interrupt.h"
#include "interr.h"
#include "breakpoint.h"
char *arch_init(void)
{
return NULL;
}
os_vm_address_t arch_get_bad_addr(struct sigcontext *scp)
{
/* Finding the bad address on the mips is easy. */
return (os_vm_address_t)scp->sc_badvaddr;
}
void arch_skip_instruction(scp)
struct sigcontext *scp;
{
/* Skip the offending instruction */
if (scp->sc_cause & CAUSE_BD)
emulate_branch(scp, *(unsigned long *)scp->sc_pc);
else
scp->sc_pc += 4;
}
unsigned char *arch_internal_error_arguments(struct sigcontext *scp)
{
if (scp->sc_cause & CAUSE_BD)
return (unsigned char *)(scp->sc_pc+8);
else
return (unsigned char *)(scp->sc_pc+4);
}
boolean arch_pseudo_atomic_atomic(struct sigcontext *scp)
{
return (scp->sc_regs[reg_ALLOC] & 1);
}
#define PSEUDO_ATOMIC_INTERRUPTED_BIAS 0x7f000000
void arch_set_pseudo_atomic_interrupted(struct sigcontext *scp)
scp->sc_regs[reg_NL4] += PSEUDO_ATOMIC_INTERRUPTED_BIAS;
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
}
unsigned long arch_install_breakpoint(void *pc)
{
unsigned long *ptr = (unsigned long *)pc;
unsigned long result = *ptr;
*ptr = (trap_Breakpoint << 16) | 0xd;
return result;
}
void arch_remove_breakpoint(void *pc, unsigned long orig_inst)
{
*(unsigned long *)pc = orig_inst;
}
static unsigned long *skipped_break_addr, displaced_after_inst;
void arch_do_displaced_inst(struct sigcontext *scp,
unsigned long orig_inst)
{
unsigned long *pc = (unsigned long *)scp->sc_pc;
unsigned long *break_pc, *next_pc;
unsigned long next_inst;
int opcode;
struct sigcontext tmp;
/* Figure out where the breakpoint is, and what happens next. */
if (scp->sc_cause & CAUSE_BD) {
break_pc = pc+1;
next_inst = *pc;
}
else {
break_pc = pc;
next_inst = orig_inst;
}
/* Put the original instruction back. */
*break_pc = orig_inst;
skipped_break_addr = break_pc;
/* Figure out where it goes. */
opcode = next_inst >> 26;
if (opcode == 1 || ((opcode & 0x3c) == 0x4) || ((next_inst & 0xf00e0000) == 0x80000000)) {
tmp = *scp;
emulate_branch(&tmp, next_inst);
next_pc = (unsigned long *)scp->sc_pc;
}
else
next_pc = pc+1;
displaced_after_inst = *next_pc;
*next_pc = (trap_AfterBreakpoint << 16) | 0xd;
sigreturn(scp);
}
static void sigtrap_handler(int signal, int code, struct sigcontext *scp)
{
switch (code) {
case trap_PendingInterrupt:
interrupt_handle_pending(scp);
break;
case trap_Halt:
fake_foreign_function_call(scp);
lose("%%primitive halt called; the party is over.\n");
case trap_Error:
case trap_Cerror:
interrupt_internal_error(signal, code, scp, code==trap_Cerror);
break;
case trap_Breakpoint:
sigsetmask(scp->sc_mask);
fake_foreign_function_call(scp);
handle_breakpoint(signal, code, scp);
undo_fake_foreign_function_call(scp);
break;
case trap_FunctionEndBreakpoint:
sigsetmask(scp->sc_mask);
fake_foreign_function_call(scp);
handle_function_end_breakpoint(signal, code, scp);
undo_fake_foreign_function_call(scp);
break;
case trap_AfterBreakpoint:
*skipped_break_addr = (trap_Breakpoint << 16) | 0xd;
skipped_break_addr = NULL;
*(unsigned long *)scp->sc_pc = displaced_after_inst;
break;
default:
interrupt_handle_now(signal, code, scp);
break;
}
}
#define FIXNUM_VALUE(lispobj) (((int)lispobj)>>2)
static void sigfpe_handler(int signal, int code, struct sigcontext *scp)
{
unsigned long bad_inst;
unsigned int op, rs, rt, rd, funct, dest;
int immed;
long result;
if (scp->sc_cause & CAUSE_BD)
bad_inst = *(unsigned long *)(scp->sc_pc + 4);
else
bad_inst = *(unsigned long *)(scp->sc_pc);
op = (bad_inst >> 26) & 0x3f;
rs = (bad_inst >> 21) & 0x1f;
rt = (bad_inst >> 16) & 0x1f;
rd = (bad_inst >> 11) & 0x1f;
funct = bad_inst & 0x3f;
immed = (((int)(bad_inst & 0xffff)) << 16) >> 16;
switch (op) {
case 0x0: /* SPECIAL */
switch (funct) {
case 0x20: /* ADD */
/* Check to see if this is really a pa_interrupted hit */
if (rs == reg_ALLOC && rt == reg_NL4) {
scp->sc_regs[reg_ALLOC] +=
(scp->sc_regs[reg_NL4] -
PSEUDO_ATOMIC_INTERRUPTED_BIAS);
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
arch_skip_instruction(scp);
interrupt_handle_pending(scp);
return;
}
result = FIXNUM_VALUE(scp->sc_regs[rs]) + FIXNUM_VALUE(scp->sc_regs[rt]);
dest = rd;
break;
case 0x22: /* SUB */
result = FIXNUM_VALUE(scp->sc_regs[rs]) - FIXNUM_VALUE(scp->sc_regs[rt]);
dest = rd;
break;
default:
dest = 32;
break;
}
break;
case 0x8: /* ADDI */
result = FIXNUM_VALUE(scp->sc_regs[rs]) + (immed>>2);
dest = rt;
break;
default:
dest = 32;
break;
}
if (dest < 32) {
current_dynamic_space_free_pointer =
(lispobj *) scp->sc_regs[reg_ALLOC];
scp->sc_regs[dest] = alloc_number(result);
scp->sc_regs[reg_ALLOC] =
(unsigned long) current_dynamic_space_free_pointer;
arch_skip_instruction(scp);
}
else
interrupt_handle_now(signal, code, scp);
}
void arch_install_interrupt_handlers()
{
interrupt_install_low_level_handler(SIGTRAP,sigtrap_handler);
interrupt_install_low_level_handler(SIGFPE,sigfpe_handler);
}
extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs);
lispobj funcall0(lispobj function)
{
lispobj *args = current_control_stack_pointer;
return call_into_lisp(function, args, 0);
}
lispobj funcall1(lispobj function, lispobj arg0)
{
lispobj *args = current_control_stack_pointer;
current_control_stack_pointer += 1;
args[0] = arg0;
return call_into_lisp(function, args, 1);
}
lispobj funcall2(lispobj function, lispobj arg0, lispobj arg1)
{
lispobj *args = current_control_stack_pointer;
current_control_stack_pointer += 2;
args[0] = arg0;
args[1] = arg1;
return call_into_lisp(function, args, 2);
}
lispobj funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
{
lispobj *args = current_control_stack_pointer;
current_control_stack_pointer += 3;
args[0] = arg0;
args[1] = arg1;
args[2] = arg2;
return call_into_lisp(function, args, 3);
}
/* This is apparently called by emulate_branch, but isn't defined. So */
/* just do nothing and hope it works... */
void cacheflush(void)
{
}