c99647481fd43f5594b8e7f967bb4b652e855957
[projects/cmucl/cmucl.git] / src / lisp / os.h
1 /*
2  * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.28 2011/09/01 05:18:26 rtoy Exp $
3  *
4  * Common interface for os-dependent functions.
5  *
6  */
7
8 #ifndef _OS_H_
9 #define _OS_H_
10
11 #include "lisp.h"
12
13 #define DPRINTF(t,a) { if (t) fprintf a; }
14
15 #ifdef DARWIN
16 #include "Darwin-os.h"
17 #else
18 #ifdef MACH
19 #include "mach-os.h"
20 #else
21 #ifdef sun
22 #include "sunos-os.h"
23 #else
24 #ifdef hpux
25 #include "hpux-os.h"
26 #else
27 #ifdef osf1
28 #include "osf1-os.h"
29 #else
30 #ifdef irix
31 #include "irix-os.h"
32 #else
33 #ifdef __FreeBSD__
34 #include "FreeBSD-os.h"
35 #else
36 #ifdef __OpenBSD__
37 #include "OpenBSD-os.h"
38 #else
39 #ifdef __NetBSD__
40 #include "NetBSD-os.h"
41 #else
42 #ifdef __linux__
43 #include "Linux-os.h"
44 #endif
45 #endif
46 #endif
47 #endif
48 #endif
49 #endif
50 #endif
51 #endif
52 #endif
53 #endif
54
55 #ifndef os_context_t
56 #define os_context_t struct sigcontext
57 #endif
58 #ifndef HANDLER_ARGS
59 #define HANDLER_ARGS int signal, int code, os_context_t *context
60 #endif
61 #ifndef CODE
62 #define CODE(code)  code
63 #endif
64 #ifndef SAVE_CONTEXT
65 #define SAVE_CONTEXT() do {} while(0)
66 #endif
67 #ifndef RESTORE_FPU
68 #define RESTORE_FPU(context) do {} while (0)
69 #endif
70
71 #define OS_VM_PROT_ALL (OS_VM_PROT_READ|OS_VM_PROT_WRITE|OS_VM_PROT_EXECUTE)
72
73 extern os_vm_size_t os_vm_page_size;
74
75 extern void os_init0(const char *argv[], const char *envp[]);
76 extern void os_init(const char *argv[], const char *envp[]);
77 extern void os_install_interrupt_handlers(void);
78
79 extern os_vm_address_t os_allocate(os_vm_size_t len);
80 extern os_vm_address_t os_allocate_at(os_vm_address_t addr, os_vm_size_t len);
81 extern os_vm_address_t os_reallocate(os_vm_address_t addr,
82                                      os_vm_size_t old_len, os_vm_size_t len);
83 extern void os_deallocate(os_vm_address_t addr, os_vm_size_t len);
84 extern void os_zero(os_vm_address_t addr, os_vm_size_t length);
85
86 extern os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len);
87 extern void os_invalidate(os_vm_address_t addr, os_vm_size_t len);
88 extern os_vm_address_t os_map(int fd, int offset, os_vm_address_t addr,
89                               os_vm_size_t len);
90 extern void os_flush_icache(os_vm_address_t addr, os_vm_size_t len);
91 extern void os_protect(os_vm_address_t addr, os_vm_size_t len,
92
93                        os_vm_prot_t protection);
94 extern boolean valid_addr(os_vm_address_t test);
95
96 #define os_trunc_to_page(addr) \
97     (os_vm_address_t)(((long)(addr))&~(os_vm_page_size-1))
98 #define os_round_up_to_page(addr) \
99     os_trunc_to_page((addr)+(os_vm_page_size-1))
100
101 #define os_trunc_size_to_page(size) \
102     (os_vm_size_t)(((long)(size))&~(os_vm_page_size-1))
103 #define os_round_up_size_to_page(size) \
104     os_trunc_size_to_page((size)+(os_vm_page_size-1))
105
106 extern void os_foreign_linkage_init(void);
107 extern void *os_dlsym(const char *sym_name, lispobj lib_list);
108
109 enum stack_zone_t { BOTH_ZONES, YELLOW_ZONE, RED_ZONE };
110 extern int os_stack_grows_down(void);
111 extern void os_guard_control_stack(int zone, int guard);
112 extern int os_control_stack_overflow(void *, os_context_t *);
113
114 unsigned long *os_sigcontext_reg(ucontext_t *, int);
115 unsigned long *os_sigcontext_pc(ucontext_t *);
116 unsigned char *os_sigcontext_fpu_reg(ucontext_t *, int);
117 unsigned int os_sigcontext_fpu_modes(ucontext_t *);
118
119 #ifdef i386
120 extern boolean os_support_sse2(void);
121 #endif
122
123 char* convert_lisp_string(char* c_string, void* lisp_string, int len);
124
125 /*
126  * Define macro to allocate a local array of the appropriate size
127  * where the fpu state can be stored.
128  */
129 #if defined(i386) || defined(__x86_64)
130 #define FPU_STATE_SIZE 27
131     /* 
132      * Need 512 byte area, aligned on a 16-byte boundary.  So allocate
133      * 512+16 bytes of space and let the routine adjust use the
134      * appropriate alignment.
135      */
136 #define SSE_STATE_SIZE ((512+16)/4)
137
138 /*
139  * Just use the SSE size for both x87 and sse2 since the SSE size is
140  * enough for either.
141  */
142 #define FPU_STATE(name)    int name[SSE_STATE_SIZE];
143
144 #elif defined(sparc)
145 /*
146  * 32 (single-precision) FP registers, and the FP state register.
147  * But Sparc V9 has 32 double-precision registers (equivalent to 64
148  * single-precision, but can't be accessed), so we leave enough room
149  * for that.
150  */
151 #define FPU_STATE_SIZE (((32 + 32 + 1) + 1)/2)
152 #define FPU_STATE(name)    long long name[FPU_STATE_SIZE];
153 #elif defined(DARWIN) && defined(__ppc__)
154 #define FPU_STATE_SIZE 32
155 #define FPU_STATE(name)    long long name[FPU_STATE_SIZE];
156 #endif
157 extern void save_fpu_state(void*);
158 extern void restore_fpu_state(void*);
159
160 #endif /* _OS_H_ */