2 * This is the IBM/Motorola/Apple/whoever Linux incarnation of
3 * arch-dependent OS-dependent routines. See also "linux-os.c". */
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
16 /* These header files were lifted wholesale from linux-os.c, some may
17 * be redundant. -- Dan Barlow ca. 2001-05-01 */
19 #include <sys/param.h>
26 #include "interrupt.h"
29 #include <sys/socket.h>
30 #include <sys/utsname.h>
32 #include <sys/types.h>
37 #include <sys/prctl.h>
40 #include "ppc-linux-mcontext.h"
42 size_t os_vm_page_size;
44 int arch_os_thread_init(struct thread *thread) {
45 /* For some reason, PPC Linux appears to default to not generating
46 * floating point exceptions. PR_SET_FPEXC is a PPC-specific
47 * option new in kernel 2.4.21 and 2.5.32 that allows us to
48 * configure this. Should we need to run on an older kenel, the
49 * equivalent trick is to get into a signal-handling context and
50 * modify the saved machine state register.
52 * PR_FP_EXC_PRECISE may be more accurate than we need,
53 * particularly if we move to the x86oid trick of inserting
54 * explicit synchronization for floating-point exception
55 * delivery. If we wish to move to such a model, the other two
56 * exception delivery modes that we could use are PR_FP_EXC_ASYNC
57 * and PR_FP_EXC_NONRECOV, and exception delivery can be forced
58 * by any access to the FPSCR. -- AB, 2010-May-23 */
59 prctl(PR_SET_FPEXC, PR_FP_EXC_PRECISE, 0, 0);
61 return 1; /* success */
63 int arch_os_thread_cleanup(struct thread *thread) {
64 return 1; /* success */
67 os_context_register_t *
68 os_context_register_addr(os_context_t *context, int offset)
70 #if defined(GLIBC231_STYLE_UCONTEXT)
71 return &((context->uc_mcontext.regs)->gpr[offset]);
72 #elif defined(GLIBC232_STYLE_UCONTEXT)
73 return &((context->uc_mcontext.uc_regs->gregs)[offset]);
77 os_context_register_t *
78 os_context_pc_addr(os_context_t *context)
80 #if defined(GLIBC231_STYLE_UCONTEXT)
81 return &((context->uc_mcontext.regs)->nip);
82 #elif defined(GLIBC232_STYLE_UCONTEXT)
83 return &((context->uc_mcontext.uc_regs->gregs)[PT_NIP]);
87 os_context_register_t *
88 os_context_lr_addr(os_context_t *context)
90 #if defined(GLIBC231_STYLE_UCONTEXT)
91 return &((context->uc_mcontext.regs)->link);
92 #elif defined(GLIBC232_STYLE_UCONTEXT)
93 return &((context->uc_mcontext.uc_regs->gregs)[PT_LNK]);
97 os_context_register_t *
98 os_context_ctr_addr(os_context_t *context)
100 /* Like os_context_fp_control() and os_context_lr_addr(), this
101 * uses an index beyond the declared end of the array in order to
102 * find the correct register value in the context. */
103 #if defined(GLIBC231_STYLE_UCONTEXT)
104 /* FIXME: This probably should be ->ctr instead of ->gpr[PT_CTR]. */
105 return &((context->uc_mcontext.regs)->gpr[PT_CTR]);
106 #elif defined(GLIBC232_STYLE_UCONTEXT)
107 return &((context->uc_mcontext.uc_regs)->gregs[PT_CTR]);
111 os_context_register_t *
112 os_context_cr_addr(os_context_t *context)
114 /* Like os_context_fp_control() and os_context_lr_addr(), this
115 * uses an index beyond the declared end of the array in order to
116 * find the correct register value in the context. */
117 #if defined(GLIBC231_STYLE_UCONTEXT)
118 /* FIXME: This probably should be ->ccr instead of ->gpr[PT_CCR]. */
119 return &((context->uc_mcontext.regs)->gpr[PT_CCR]);
120 #elif defined(GLIBC232_STYLE_UCONTEXT)
121 return &((context->uc_mcontext.uc_regs)->gregs[PT_CCR]);
126 os_context_sigmask_addr(os_context_t *context)
128 #if defined(GLIBC231_STYLE_UCONTEXT)
129 return &context->uc_sigmask;
130 #elif defined(GLIBC232_STYLE_UCONTEXT)
131 return &context->uc_sigmask;
136 os_context_fp_control(os_context_t *context)
138 /* So this may look like nice, well behaved code. However, closer
139 inspection reveals that gpr is simply the general purpose
140 registers, and PT_FPSCR is an offset that is larger than 32
141 (the number of ppc registers), but that happens to get the
142 right answer. -- CSR, 2002-07-11 */
143 #if defined(GLIBC231_STYLE_UCONTEXT)
144 return context->uc_mcontext.regs->gpr[PT_FPSCR];
145 #elif defined(GLIBC232_STYLE_UCONTEXT)
146 return context->uc_mcontext.uc_regs->gregs[PT_FPSCR];
151 os_restore_fp_control(os_context_t *context)
153 /* KLUDGE: mtfsf has to be run against a float register, so we
154 * construct the float we need to use as an integer, then cast
155 * a pointer to its storage to a double and load that. For
156 * this to work, control must be the same width as a double,
157 * 64 bits. And why aren't we using a union here, anyway? */
158 unsigned long long control;
161 /* FIXME: We are only preserving enabled traps and rounding
162 * mode here. Do we also want to preserve "fast mode"? */
163 control = os_context_fp_control(context) &
164 (FLOAT_TRAPS_BYTE_MASK | FLOAT_ROUNDING_MODE_MASK);
166 d = *((double *) &control);
167 asm volatile ("mtfsf 0xff,%0" : : "f" (d));
171 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
174 ppc_flush_icache(address,length);