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