Newer
Older
/*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/sparc-arch.c,v 1.5 1994/10/27 17:13:54 ram Exp $
This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain.
*/
#include "lisp.h"
#include "internals.h"
#include "globals.h"
#include "validate.h"
#include "os.h"
#include "lispregs.h"
#include "signal.h"
#include "interrupt.h"
char *arch_init()
{
{
unsigned long badinst;
int rs1;
/* On the sparc, we have to decode the instruction. */
/* Make sure it's not the pc thats bogus, and that it was lisp code */
/* that caused the fault. */
if ((SC_PC(context) & 3) != 0 ||
((SC_PC(context) < READ_ONLY_SPACE_START ||
SC_PC(context) >= READ_ONLY_SPACE_START+READ_ONLY_SPACE_SIZE) &&
((lispobj *)SC_PC(context) < current_dynamic_space &&
(lispobj *)SC_PC(context) >=
if ((badinst >> 30) != 3)
/* All load/store instructions have op = 11 (binary) */
rs1 = (badinst>>14)&0x1f;
if (badinst & (1<<13)) {
/* r[rs1] + simm(13) */
int simm13 = badinst & 0x1fff;
if (simm13 & (1<<12))
simm13 |= -1<<13;
return (os_vm_address_t)(SC_REG(context, rs1) + simm13);
}
else {
/* r[rs1] + r[rs2] */
int rs2 = badinst & 0x1f;
return (os_vm_address_t)(SC_REG(context, rs1) + SC_REG(context, rs2));
}
}
void arch_skip_instruction(context)
struct sigcontext *context;
{
/* Skip the offending instruction */
}
unsigned char *arch_internal_error_arguments(struct sigcontext *scp)
{
}
boolean arch_pseudo_atomic_atomic(struct sigcontext *scp)
{
return (SC_REG(scp, reg_ALLOC) & 4);
}
void arch_set_pseudo_atomic_interrupted(struct sigcontext *scp)
{
SC_REG(scp, reg_ALLOC) |= 1;
}
unsigned long arch_install_breakpoint(void *pc)
{
unsigned long *ptr = (unsigned long *)pc;
unsigned long result = *ptr;
*ptr = trap_Breakpoint;
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 *)SC_PC(scp);
unsigned long *npc = (unsigned long *)SC_NPC(scp);
#ifdef POSIX_SIGS
orig_sigmask = scp->uc_sigmask;
sigemptyset(&scp->uc_sigmask);
FILLBLOCKSET(&scp->uc_sigmask);
#else
*pc = orig_inst;
skipped_break_addr = pc;
displaced_after_inst = *npc;
*npc = trap_AfterBreakpoint;
#ifdef SOLARIS
/* XXX never tested */
setcontext(scp);
#else
SAVE_CONTEXT();
#ifdef POSIX_SIGS
sigprocmask(SIG_SETMASK, &context->uc_sigmask, 0);
#else
sigsetmask(context->sc_mask);
#endif
#ifdef SOLARIS
if (CODE(code) == ILL_ILLOPC)
#else
if (CODE(code) == T_UNIMP_INSTR)
#endif
{
arch_skip_instruction(context);
interrupt_handle_pending(context);
lose("%%primitive halt called; the party is over.\n");
case trap_Error:
case trap_Cerror:
interrupt_internal_error(signal, code, context, trap == trap_Cerror);
SC_PC(context)=(int)handle_function_end_breakpoint(signal, code, context);
SC_NPC(context)=SC_PC(context) + 4;
break;
case trap_AfterBreakpoint:
*skipped_break_addr = trap_Breakpoint;
skipped_break_addr = NULL;
*(unsigned long *)SC_PC(context) = displaced_after_inst;
#ifdef POSIX_SIGS
context->uc_sigmask = orig_sigmask;
#else
context->sc_mask = orig_sigmask;
#endif
#ifdef SOLARIS
else if (CODE(code) == ILL_ILLTRP)
#else
else if (CODE(code) >= T_SOFTWARE_TRAP + 16 & CODE(code) < T_SOFTWARE_TRAP + 32)
#endif
interrupt_internal_error(signal, code, context, FALSE);
{
unsigned long badinst;
boolean subtract, immed;
int rd, rs1, op1, rs2, op2, result;
if ((badinst >> 30) != 2 || ((badinst >> 20) & 0x1f) != 0x11) {
/* It wasn't a tagged add. Pass the signal into lisp. */
return;
}
/* Extract the parts of the inst. */
subtract = badinst & (1<<19);
rs1 = (badinst>>14) & 0x1f;
/* If the first arg is $ALLOC then it is really a signal-pending note */
/* for the pseudo-atomic noise. */
if (rs1 == reg_ALLOC) {
/* Perform the op anyway. */
op2 = badinst & 0x1fff;
if (op2 & (1<<12))
op2 |= -1<<13;
if (subtract)
result = op1 - op2;
else
result = op1 + op2;
SC_REG(context, reg_ALLOC) = result & ~7;
arch_skip_instruction(context);
interrupt_handle_pending(context);
return;
}
if ((op1 & 3) != 0) {
/* The first arg wan't a fixnum. */
return;
}
if (immed = badinst & (1<<13)) {
op2 = badinst & 0x1fff;
if (op2 & (1<<12))
op2 |= -1<<13;
}
else {
rs2 = badinst & 0x1f;
}
if ((op2 & 3) != 0) {
/* The second arg wan't a fixnum. */
return;
}
rd = (badinst>>25) & 0x1f;
if (rd != 0) {
/* Don't bother computing the result unless we are going to use it. */
if (subtract)
result = (op1>>2) - (op2>>2);
else
result = (op1>>2) + (op2>>2);
current_dynamic_space_free_pointer =
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
}
void arch_install_interrupt_handlers()
{
interrupt_install_low_level_handler(SIGILL,sigill_handler);
interrupt_install_low_level_handler(SIGEMT,sigemt_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);
}