| Commit | Line | Data |
|---|---|---|
| 62957726 | 1 | /* |
| dafb9e03 | 2 | * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.28 2011/09/01 05:18:26 rtoy Exp $ |
| 62957726 | 3 | * |
| 4 | * Common interface for os-dependent functions. | |
| 5 | * | |
| 6 | */ | |
| 7 | ||
| e67c0397 | 8 | #ifndef _OS_H_ |
| 9 | #define _OS_H_ | |
| 62957726 | 10 | |
| 11 | #include "lisp.h" | |
| 12 | ||
| 0a3b5441 | 13 | #define DPRINTF(t,a) { if (t) fprintf a; } |
| 14 | ||
| eb44537a | 15 | #ifdef DARWIN |
| 16 | #include "Darwin-os.h" | |
| 17 | #else | |
| 62957726 | 18 | #ifdef MACH |
| 19 | #include "mach-os.h" | |
| 20 | #else | |
| 21 | #ifdef sun | |
| 22 | #include "sunos-os.h" | |
| 28d03d3d | 23 | #else |
| 24 | #ifdef hpux | |
| 25 | #include "hpux-os.h" | |
| 6f4a04e5 | 26 | #else |
| 27 | #ifdef osf1 | |
| 28 | #include "osf1-os.h" | |
| cdac17ab | 29 | #else |
| 30 | #ifdef irix | |
| 31 | #include "irix-os.h" | |
| 5ced0fdf | 32 | #else |
| 33 | #ifdef __FreeBSD__ | |
| 34 | #include "FreeBSD-os.h" | |
| 35 | #else | |
| 195461c1 | 36 | #ifdef __OpenBSD__ |
| 37 | #include "OpenBSD-os.h" | |
| 38 | #else | |
| 4ea11535 | 39 | #ifdef __NetBSD__ |
| 40 | #include "NetBSD-os.h" | |
| 41 | #else | |
| 5ced0fdf | 42 | #ifdef __linux__ |
| 43 | #include "Linux-os.h" | |
| 44 | #endif | |
| 45 | #endif | |
| cdac17ab | 46 | #endif |
| 6f4a04e5 | 47 | #endif |
| 28d03d3d | 48 | #endif |
| 62957726 | 49 | #endif |
| 50 | #endif | |
| 195461c1 | 51 | #endif |
| 4ea11535 | 52 | #endif |
| eb44537a | 53 | #endif |
| 62957726 | 54 | |
| 9a8c1c2f | 55 | #ifndef os_context_t |
| 5d2cd5df | 56 | #define os_context_t struct sigcontext |
| 57 | #endif | |
| 571df509 | 58 | #ifndef HANDLER_ARGS |
| 5d2cd5df | 59 | #define HANDLER_ARGS int signal, int code, os_context_t *context |
| 571df509 | 60 | #endif |
| 61 | #ifndef CODE | |
| 62 | #define CODE(code) code | |
| 63 | #endif | |
| 571df509 | 64 | #ifndef SAVE_CONTEXT |
| 65 | #define SAVE_CONTEXT() do {} while(0) | |
| 66 | #endif | |
| 44eba57f | 67 | #ifndef RESTORE_FPU |
| 68 | #define RESTORE_FPU(context) do {} while (0) | |
| 69 | #endif | |
| 571df509 | 70 | |
| 62957726 | 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 | ||
| dafb9e03 | 75 | extern void os_init0(const char *argv[], const char *envp[]); |
| 0f0aed07 | 76 | extern void os_init(const char *argv[], const char *envp[]); |
| 62957726 | 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, | |
| 9a8c1c2f | 82 | os_vm_size_t old_len, os_vm_size_t len); |
| 62957726 | 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, | |
| 9a8c1c2f | 92 | |
| 62957726 | 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 | ||
| bf84be07 | 106 | extern void os_foreign_linkage_init(void); |
| 9a8c1c2f | 107 | extern void *os_dlsym(const char *sym_name, lispobj lib_list); |
| bf84be07 | 108 | |
| 9a8c1c2f | 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 *); | |
| 670d643f | 113 | |
| 9495c516 | 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); | |
| b17a70c7 | 117 | unsigned int os_sigcontext_fpu_modes(ucontext_t *); |
| 9495c516 | 118 | |
| aa9c2237 | 119 | #ifdef i386 |
| 120 | extern boolean os_support_sse2(void); | |
| 121 | #endif | |
| 122 | ||
| 68e8e5d1 | 123 | char* convert_lisp_string(char* c_string, void* lisp_string, int len); |
| 124 | ||
| c07cc020 RT |
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 | ||
| e67c0397 | 160 | #endif /* _OS_H_ */ |