Fix make-array transforms.
[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 <signal.h>
19
20 /* for cacheflush() */
21 #include <sys/cachectl.h>
22
23 #include "sbcl.h"
24 #include "os.h"
25 #include "arch.h"
26
27 #define CAUSEF_BD (1 << 31)
28
29 size_t os_vm_page_size;
30
31 int
32 arch_os_thread_init(struct thread *thread)
33 {
34 #ifdef LISP_FEATURE_SB_THREAD
35 #warning "Check threading support functions"
36 #endif
37     return 1;                  /* success */
38 }
39
40 int
41 arch_os_thread_cleanup(struct thread *thread)
42 {
43 #ifdef LISP_FEATURE_SB_THREAD
44 #warning "Check threading support functions"
45 #endif
46     return 1;                  /* success */
47 }
48
49 os_context_register_t *
50 os_context_register_addr(os_context_t *context, int offset)
51 {
52     mcontext_t *mctx = &context->uc_mcontext;
53     struct sigcontext *ctx = (struct sigcontext *)mctx;
54     return &ctx->sc_regs[offset];
55 }
56
57 os_context_register_t *
58 os_context_fpregister_addr(os_context_t *context, int offset)
59 {
60     mcontext_t *mctx = &context->uc_mcontext;
61     struct sigcontext *ctx = (struct sigcontext *)mctx;
62     return &ctx->sc_fpregs[offset];
63 }
64
65 os_context_register_t *
66 os_context_pc_addr(os_context_t *context)
67 {
68     /* Why do I get all the silly ports? -- CSR, 2002-08-11 */
69     mcontext_t *mctx = &context->uc_mcontext;
70     struct sigcontext *ctx = (struct sigcontext *)mctx;
71     return &ctx->sc_pc;
72 }
73
74 sigset_t *
75 os_context_sigmask_addr(os_context_t *context)
76 {
77     return &(context->uc_sigmask);
78 }
79
80 unsigned int
81 os_context_fp_control(os_context_t *context)
82 {
83     mcontext_t *mctx = &context->uc_mcontext;
84     struct sigcontext *ctx = (struct sigcontext *)mctx;
85     return ctx->sc_fpc_csr;
86 }
87
88 void
89 os_restore_fp_control(os_context_t *context)
90 {
91     unsigned int ctl = os_context_fp_control(context);
92     ctl &= ~(FLOAT_STICKY_BITS_MASK | FLOAT_EXCEPTIONS_BYTE_MASK);
93     arch_set_fp_control(ctl);
94 }
95
96 unsigned int
97 os_context_bd_cause(os_context_t *context)
98 {
99     /* We need to see if whatever happened, happened because of a
100        branch delay event */
101     /* FIXME: However, I'm not convinced that the values that Linux
102        puts in this slot are actually right; specifically, attempting
103        to compile sbcl with sbcl-0.7.7.7 lead to an "infinite SIGTRAP
104        loop" where a (BREAK 16) not in a branch delay slot would have
105        CAUSEF_BD filled. So, we comment
106
107         return (((struct sigcontext *) &(context->uc_mcontext))->sc_cause
108                 & CAUSEF_BD);
109
110        out and return 0 always.  -- CSR, 2002-09-02 */
111     /* Unfortunately, returning 0 fails for taken branches because
112        os_context_bd_cause is also used to find out if a branch
113        emulation is needed.  We work around that by checking if the
114        current instruction is a jump or a branch.  */
115     extern boolean arch_insn_with_bdelay_p(unsigned int insn);
116
117     os_vm_address_t addr
118         = (os_vm_address_t)(unsigned int)*os_context_pc_addr(context);
119     unsigned int insn = *(unsigned int *)addr;
120
121     if (arch_insn_with_bdelay_p(insn))
122         return CAUSEF_BD;
123
124     return 0;
125 }
126
127 void
128 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
129 {
130     if (cacheflush(address, length, ICACHE) == -1)
131         perror("cacheflush");
132 }