0.9.3.69:
[sbcl.git] / src / runtime / mips-linux-os.c
1 /*
2  * This is the MIPS Linux incarnation of arch-dependent OS-dependent
3  * routines. See also "linux-os.c".
4  */
5
6 /*
7  * This software is part of the SBCL system. See the README file for
8  * more information.
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include "sbcl.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 <sys/socket.h>
29 #include <sys/utsname.h>
30
31 #include <sys/types.h>
32 #include <signal.h>
33 #include <sys/time.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36
37 /* for cacheflush() */
38 #include <sys/cachectl.h>
39
40 /* for BD_CAUSE */
41 #include <asm/mipsregs.h>
42
43 #include "validate.h"
44
45 size_t os_vm_page_size;
46
47 int
48 arch_os_thread_init(struct thread *thread)
49 {
50 #ifdef LISP_FEATURE_SB_THREAD
51 #warning "Check threading support functions"
52 #endif
53     return 1;                  /* success */
54 }
55
56 int
57 arch_os_thread_cleanup(struct thread *thread)
58 {
59 #ifdef LISP_FEATURE_SB_THREAD
60 #warning "Check threading support functions"
61 #endif
62     return 1;                  /* success */
63 }
64
65 os_context_register_t *
66 os_context_register_addr(os_context_t *context, int offset)
67 {
68     return &(((struct sigcontext *)&(context->uc_mcontext))->sc_regs[offset]);
69 }
70
71 os_context_register_t *
72 os_context_pc_addr(os_context_t *context)
73 {
74     /* Why do I get all the silly ports? -- CSR, 2002-08-11 */
75     return &(((struct sigcontext *)&(context->uc_mcontext))->sc_pc);
76 }
77
78 sigset_t *
79 os_context_sigmask_addr(os_context_t *context)
80 {
81     return &(context->uc_sigmask);
82 }
83
84 unsigned int
85 os_context_fp_control(os_context_t *context)
86 {
87     /* FIXME: Probably do something. */
88     return 0;
89 }
90
91 void
92 os_restore_fp_control(os_context_t *context)
93 {
94     /* FIXME: Probably do something. */
95 }
96
97 unsigned int
98 os_context_bd_cause(os_context_t *context)
99 {
100     /* We need to see if whatever happened, happened because of a
101        branch delay event */
102     /* FIXME: However, I'm not convinced that the values that Linux
103        puts in this slot are actually right; specifically, attempting
104        to compile sbcl with sbcl-0.7.7.7 lead to an "infinite SIGTRAP
105        loop" where a (BREAK 16) not in a branch delay slot would have
106        CAUSEF_BD filled. So, we comment
107
108         return (((struct sigcontext *) &(context->uc_mcontext))->sc_cause
109                 & CAUSEF_BD);
110
111        out and return 0 always.  -- CSR, 2002-09-02 */
112     /* Unfortunately, returning 0 fails for taken branches because
113        os_context_bd_cause is also used to find out if a branch
114        emulation is needed.  We work around that by checking if the
115        current instruction is a jump or a branch.  */
116     unsigned int inst = *((unsigned int *)(unsigned int)(*os_context_pc_addr(context)));
117
118     switch (inst >> 26) {
119     case 0x0: /* immediate jumps */
120         switch (inst & 0x3f) {
121         case 0x08:
122         case 0x09:
123             return CAUSEF_BD;
124         }
125         break;
126     /* branches and register jumps */
127     case 0x1:
128     case 0x2:
129     case 0x3:
130     case 0x4:
131     case 0x5:
132     case 0x6:
133     case 0x7:
134         return CAUSEF_BD;
135     }
136     return 0;
137 }
138
139 void
140 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
141 {
142     if (cacheflush(address, length, ICACHE) == -1)
143         perror("cacheflush");
144 }