2 * This is the ARM BSD incarnation of arch-dependent OS-dependent
3 * routines. See also "bsd-os.c".
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
18 #include <sys/param.h>
20 #include "genesis/sbcl.h"
24 #include "interrupt.h"
28 #include <sys/types.h>
37 #ifdef LISP_FEATURE_SB_THREAD
38 #error "Define threading support functions"
40 int arch_os_thread_init(struct thread
*thread
) {
42 /* Signal handlers are normally run on the main stack, but we've
43 * swapped stacks, require that the control stack contain only
44 * boxed data, and expands upwards while the C stack expands
46 sigstack
.ss_sp
= calc_altstack_base(thread
);
47 sigstack
.ss_flags
= 0;
48 sigstack
.ss_size
= calc_altstack_size(thread
);
49 if(sigaltstack(&sigstack
,0)<0)
50 lose("Cannot sigaltstack: %s",strerror(errno
));
52 return 1; /* success */
54 int arch_os_thread_cleanup(struct thread
*thread
) {
55 return 1; /* success */
59 #if defined(LISP_FEATURE_NETBSD)
61 os_context_register_t
*
62 os_context_register_addr(os_context_t
*context
, int offset
)
64 /* KLUDGE: All of the context registers are stored in the
65 * structure consecutively, in order, as separately-named fields.
66 * Rather than do a big switch/case and all that, just take the
67 * address of the first one (R0) and treat it as the start of an
69 return &context
->uc_mcontext
.__gregs
[offset
];
72 #elif defined(LISP_FEATURE_OPENBSD)
74 os_context_register_t
*
75 os_context_register_addr(os_context_t
*context
, int offset
)
78 case 0: return (os_context_register_t
*)(&context
->sc_r0
);
79 case 1: return (os_context_register_t
*)(&context
->sc_r1
);
80 case 2: return (os_context_register_t
*)(&context
->sc_r2
);
81 case 3: return (os_context_register_t
*)(&context
->sc_r3
);
82 case 4: return (os_context_register_t
*)(&context
->sc_r4
);
83 case 5: return (os_context_register_t
*)(&context
->sc_r5
);
84 case 6: return (os_context_register_t
*)(&context
->sc_r6
);
85 case 7: return (os_context_register_t
*)(&context
->sc_r7
);
86 case 8: return (os_context_register_t
*)(&context
->sc_r8
);
87 case 9: return (os_context_register_t
*)(&context
->sc_r9
);
88 case 10: return (os_context_register_t
*)(&context
->sc_r10
);
89 case 11: return (os_context_register_t
*)(&context
->sc_r11
);
90 case 12: return (os_context_register_t
*)(&context
->sc_r12
);
91 case reg_NSP
: return (os_context_register_t
*)(&context
->sc_usr_sp
);
92 case reg_LR
: return (os_context_register_t
*)(&context
->sc_usr_lr
);
93 case reg_PC
: return (os_context_register_t
*)(&context
->sc_pc
);
95 lose("illegal register number: %d", offset
);
100 os_context_register_t
*
101 os_context_lr_addr(os_context_t
*context
)
103 return os_context_register_addr(context
, reg_LR
);
106 #if defined(LISP_FEATURE_OPENBSD)
109 os_restore_fp_control(os_context_t
*context
)
111 asm ("fmxr fpscr,%0" : : "r" (context
->sc_fpscr
));
117 os_restore_fp_control(os_context_t
*context
)
119 /* FIXME: Implement. */
125 os_flush_icache(os_vm_address_t address
, os_vm_size_t length
)
127 arm_sync_icache(address
, length
);
131 sigtrap_handler(int signal
, siginfo_t
*siginfo
, os_context_t
*context
)
133 unsigned int code
= *((unsigned char *)(4+OS_CONTEXT_PC(context
)));
134 uint32_t trap_instruction
= *(uint32_t *)OS_CONTEXT_PC(context
);
136 if (trap_instruction
!= 0xe7ffdefe) {
137 lose("Unrecognized trap instruction %08lx in sigtrap_handler()",
141 if (code
== trap_PendingInterrupt
) {
142 arch_skip_instruction(context
);
145 handle_trap(context
, code
);
148 void arch_install_interrupt_handlers()
150 ll_install_handler(SIGTRAP
, sigtrap_handler
);