14411f60ff253b60a7ebe04bcecbe85fcaab0e6a
[sbcl.git] / src / runtime / ppc-linux-os.c
1 /*
2  * This is the IBM/Motorola/Apple/whoever Linux incarnation of
3  * arch-dependent OS-dependent routines. See also "linux-os.c".  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
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.
14  */
15
16 /* These header files were lifted wholesale from linux-os.c, some may
17  * be redundant. -- Dan Barlow ca. 2001-05-01 */
18 #include <stdio.h>
19 #include <sys/param.h>
20 #include <sys/file.h>
21 #include "./signal.h"
22 #include "os.h"
23 #include "arch.h"
24 #include "globals.h"
25 #include "interrupt.h"
26 #include "interr.h"
27 #include "lispregs.h"
28 #include "sbcl.h"
29 #include <sys/socket.h>
30 #include <sys/utsname.h>
31
32 #include <sys/types.h>
33 #include <signal.h>
34 #include <sys/time.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37
38 #include "validate.h"
39 size_t os_vm_page_size;
40
41 #if defined GENCGC              /* unlikely ... */
42 #error SBCL PPC does not work with the GENCGC
43 #include "gencgc.h"
44 #endif
45
46 os_context_register_t   *
47 os_context_register_addr(os_context_t *context, int offset)
48 {
49     return &((context->uc_mcontext.regs)->gpr[offset]);
50 }
51
52 os_context_register_t *
53 os_context_pc_addr(os_context_t *context)
54 {
55     return &((context->uc_mcontext.regs)->nip);
56 }
57
58 os_context_register_t *
59 os_context_lr_addr(os_context_t *context)
60 {
61     return &((context->uc_mcontext.regs)->link);
62 }
63
64 sigset_t *
65 os_context_sigmask_addr(os_context_t *context)
66 {
67     return &context->uc_sigmask;
68 }
69
70 unsigned long
71 os_context_fp_control(os_context_t *context)
72 {
73     /* So this may look like nice, well behaved code. However, closer
74        inspection reveals that gpr is simply the general purpose
75        registers, and PT_FPSCR is an offset that is larger than 32
76        (the number of ppc registers), but that happens to get the
77        right answer. -- CSR, 2002-07-11 */
78     return context->uc_mcontext.regs->gpr[PT_FPSCR]; 
79 }
80
81 void 
82 os_restore_fp_control(os_context_t *context)
83 {
84     unsigned long control;
85     
86     control = os_context_fp_control(context) & 
87       /* FIXME: Should we preserve the user's requested rounding mode?
88
89          Note that doing 
90
91          ~(FLOAT_STICKY_BITS_MASK | FLOAT_EXCEPTIONS_BYTE_MASK)
92
93          here leads to infinite SIGFPE for invalid operations, as
94          there are bits in the control register that need to be
95          cleared that are let through by that mask. -- CSR, 2002-07-16 */
96       FLOAT_TRAPS_BYTE_MASK;
97     
98     /* FIXME: Shoot me now.
99        
100        Hardcoded nastiness: the "0"s below refer to the first floating
101        point registers -- we should let gcc deal with that. The 8(31)
102        refers to the position on the stack, less one, of control (we
103        need for control to be the high word of the double loaded by
104        lfd; how do I know that r31 contains the stack? I don't, I'm
105        just guessing. The 255, on the other hand, is a valid constant
106        -- it says "move everything in the upper word into the floating
107        point control register. -- CSR, 2002-07-16 */
108     asm ("stw %0, 12(31); lfd 0, 8(31); mtfsf 255, 0" : : "r" (control) : "r31");
109 }
110
111 void 
112 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
113 {
114     /* see ppc-arch.c */
115     ppc_flush_icache(address,length);
116 }
117