00378f7b32e1bb01dc088db943d6faf06f897e89
[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 os_context_register_t   *
42 os_context_register_addr(os_context_t *context, int offset)
43 {
44     return &((context->uc_mcontext.regs)->gpr[offset]);
45 }
46
47 os_context_register_t *
48 os_context_pc_addr(os_context_t *context)
49 {
50     return &((context->uc_mcontext.regs)->nip);
51 }
52
53 os_context_register_t *
54 os_context_lr_addr(os_context_t *context)
55 {
56     return &((context->uc_mcontext.regs)->link);
57 }
58
59 sigset_t *
60 os_context_sigmask_addr(os_context_t *context)
61 {
62     return &context->uc_sigmask;
63 }
64
65 unsigned long
66 os_context_fp_control(os_context_t *context)
67 {
68     /* So this may look like nice, well behaved code. However, closer
69        inspection reveals that gpr is simply the general purpose
70        registers, and PT_FPSCR is an offset that is larger than 32
71        (the number of ppc registers), but that happens to get the
72        right answer. -- CSR, 2002-07-11 */
73     return context->uc_mcontext.regs->gpr[PT_FPSCR]; 
74 }
75
76 void 
77 os_restore_fp_control(os_context_t *context)
78 {
79     unsigned long control;
80     
81     control = os_context_fp_control(context) & 
82       /* FIXME: Should we preserve the user's requested rounding mode?
83
84          Note that doing 
85
86          ~(FLOAT_STICKY_BITS_MASK | FLOAT_EXCEPTIONS_BYTE_MASK)
87
88          here leads to infinite SIGFPE for invalid operations, as
89          there are bits in the control register that need to be
90          cleared that are let through by that mask. -- CSR, 2002-07-16 */
91       FLOAT_TRAPS_BYTE_MASK;
92     
93     /* FIXME: Shoot me now.
94        
95        Hardcoded nastiness: the "0"s below refer to the first floating
96        point registers -- we should let gcc deal with that. The 8(31)
97        refers to the position on the stack, less one, of control (we
98        need for control to be the high word of the double loaded by
99        lfd; how do I know that r31 contains the stack? I don't, I'm
100        just guessing. The 255, on the other hand, is a valid constant
101        -- it says "move everything in the upper word into the floating
102        point control register. -- CSR, 2002-07-16 */
103     asm ("stw %0, 12(31); lfd 0, 8(31); mtfsf 255, 0" : : "r" (control) : "r31");
104 }
105
106 void 
107 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
108 {
109     /* see ppc-arch.c */
110     ppc_flush_icache(address,length);
111 }
112