0.9.18.14:
[sbcl/tcr.git] / src / runtime / mips-linux-os.c
blob1028b837d2b579a8efcc10c66c17c3a49d062410
1 /*
2 * This is the MIPS Linux incarnation of arch-dependent OS-dependent
3 * routines. See also "linux-os.c".
4 */
6 /*
7 * This software is part of the SBCL system. See the README file for
8 * more information.
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.
17 #include <stdio.h>
18 #include <signal.h>
20 /* for cacheflush() */
21 #include <sys/cachectl.h>
23 #include "sbcl.h"
24 #include "os.h"
25 #include "arch.h"
27 #define CAUSEF_BD (1 << 31)
29 size_t os_vm_page_size;
31 int
32 arch_os_thread_init(struct thread *thread)
34 #ifdef LISP_FEATURE_SB_THREAD
35 #warning "Check threading support functions"
36 #endif
37 return 1; /* success */
40 int
41 arch_os_thread_cleanup(struct thread *thread)
43 #ifdef LISP_FEATURE_SB_THREAD
44 #warning "Check threading support functions"
45 #endif
46 return 1; /* success */
49 os_context_register_t *
50 os_context_register_addr(os_context_t *context, int offset)
52 return &(((struct sigcontext *)&(context->uc_mcontext))->sc_regs[offset]);
55 os_context_register_t *
56 os_context_fpregister_addr(os_context_t *context, int offset)
58 return &(((struct sigcontext *)&(context->uc_mcontext))->sc_fpregs[offset]);
61 os_context_register_t *
62 os_context_pc_addr(os_context_t *context)
64 /* Why do I get all the silly ports? -- CSR, 2002-08-11 */
65 return &(((struct sigcontext *)&(context->uc_mcontext))->sc_pc);
68 sigset_t *
69 os_context_sigmask_addr(os_context_t *context)
71 return &(context->uc_sigmask);
74 unsigned int
75 os_context_fp_control(os_context_t *context)
77 /* FIXME: Probably do something. */
78 return 0;
81 void
82 os_restore_fp_control(os_context_t *context)
84 /* FIXME: Probably do something. */
87 unsigned int
88 os_context_bd_cause(os_context_t *context)
90 /* We need to see if whatever happened, happened because of a
91 branch delay event */
92 /* FIXME: However, I'm not convinced that the values that Linux
93 puts in this slot are actually right; specifically, attempting
94 to compile sbcl with sbcl-0.7.7.7 lead to an "infinite SIGTRAP
95 loop" where a (BREAK 16) not in a branch delay slot would have
96 CAUSEF_BD filled. So, we comment
98 return (((struct sigcontext *) &(context->uc_mcontext))->sc_cause
99 & CAUSEF_BD);
101 out and return 0 always. -- CSR, 2002-09-02 */
102 /* Unfortunately, returning 0 fails for taken branches because
103 os_context_bd_cause is also used to find out if a branch
104 emulation is needed. We work around that by checking if the
105 current instruction is a jump or a branch. */
106 extern boolean arch_insn_with_bdelay_p(unsigned int insn);
108 os_vm_address_t addr
109 = (os_vm_address_t)(unsigned int)*os_context_pc_addr(context);
110 unsigned int insn = *(unsigned int *)addr;
112 if (arch_insn_with_bdelay_p(insn))
113 return CAUSEF_BD;
115 return 0;
118 void
119 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
121 if (cacheflush(address, length, ICACHE) == -1)
122 perror("cacheflush");