0.8.3.87
[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 "./signal.h"
21 #include "os.h"
22 #include "arch.h"
23 #include "globals.h"
24 #include "interrupt.h"
25 #include "interr.h"
26 #include "lispregs.h"
27 #include "sbcl.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 #include "validate.h"
38 /* for cacheflush() */
39 #include <asm/cachectl.h>
40
41 /* FIXME: For CAUSEF_BD */
42 #include <asm/mipsregs.h>
43 size_t os_vm_page_size;
44
45 #ifdef LISP_FEATURE_SB_THREAD
46 #error "Define threading support functions"
47 #else
48 struct thread *arch_os_get_current_thread() {
49     return all_threads;
50 }
51 int arch_os_thread_init(struct thread *thread) {
52     return 1;                  /* success */
53 }
54 int arch_os_thread_cleanup(struct thread *thread) {
55     return 1;                  /* success */
56 }
57 #endif
58
59 os_context_register_t *
60 os_context_register_addr(os_context_t *context, int offset)
61 {
62     if (offset == 0) {
63         /* KLUDGE: I'm not sure, but it's possible that Linux puts the
64            contents of the Processor Status Word in the (wired-zero)
65            slot in the mcontext. In any case, the following is
66            unlikely to do any harm: */
67         static unsigned long long zero;
68         zero = 0;
69         return &zero;
70     } else {
71         return &(((struct sigcontext *) &(context->uc_mcontext))->sc_regs[offset]);
72     }
73 }
74
75 os_context_register_t *
76 os_context_pc_addr(os_context_t *context)
77 {
78     /* Why do I get all the silly ports? -- CSR, 2002-08-11 */
79     return &(((struct sigcontext *) &(context->uc_mcontext))->sc_pc);
80 }
81
82 sigset_t *
83 os_context_sigmask_addr(os_context_t *context)
84 {
85     return &(context->uc_sigmask);
86 }
87
88 void 
89 os_restore_fp_control(os_context_t *context)
90 {
91     /* FIXME: Probably do something. */
92 }
93
94 unsigned int
95 os_context_bd_cause(os_context_t *context)
96 {
97     /* We need to see if whatever happened, happened because of a
98        branch delay event */
99     /* FIXME: However, I'm not convinced that the values that Linux
100        puts in this slot are actually right; specifically, attempting
101        to compile sbcl with sbcl-0.7.7.7 lead to an "infinite SIGTRAP
102        loop" where a (BREAK 16) not in a branch delay slot would have
103        CAUSEF_BD filled. So, we comment
104
105         return (((struct sigcontext *) &(context->uc_mcontext))->sc_cause 
106                 & CAUSEF_BD);
107
108        out and return 0 always.  -- CSR, 2002-09-02 */
109     return 0;
110 }
111
112 void 
113 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
114 {
115     if (cacheflush(address, length, ICACHE) == -1)
116         perror("cacheflush");
117 }