Skip to content
os.h 4.27 KiB
Newer Older
wlott's avatar
wlott committed
/*
 * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.28 2011/09/01 05:18:26 rtoy Exp $
wlott's avatar
wlott committed
 *
 * Common interface for os-dependent functions.
 *
 */

wlott's avatar
wlott committed

#include "lisp.h"

#define DPRINTF(t,a) { if (t) fprintf a; }

#ifdef DARWIN
#include "Darwin-os.h"
#else
wlott's avatar
wlott committed
#ifdef MACH
#include "mach-os.h"
#else
#ifdef sun
#include "sunos-os.h"
#else
#ifdef hpux
#include "hpux-os.h"
hallgren's avatar
hallgren committed
#else
#ifdef osf1
#include "osf1-os.h"
hallgren's avatar
hallgren committed
#else
#ifdef irix
#include "irix-os.h"
ram's avatar
ram committed
#else
#ifdef __FreeBSD__
#include "FreeBSD-os.h"
#else
#ifdef __OpenBSD__
#include "OpenBSD-os.h"
#else
#ifdef __NetBSD__
#include "NetBSD-os.h"
#else
ram's avatar
ram committed
#ifdef __linux__
#include "Linux-os.h"
#endif
#endif
hallgren's avatar
hallgren committed
#endif
hallgren's avatar
hallgren committed
#endif
#endif
wlott's avatar
wlott committed
#endif
#endif
wlott's avatar
wlott committed

#ifndef os_context_t
#define os_context_t struct sigcontext
#endif
ram's avatar
ram committed
#ifndef HANDLER_ARGS
#define HANDLER_ARGS int signal, int code, os_context_t *context
ram's avatar
ram committed
#endif
#ifndef CODE
#define CODE(code)  code
#endif
#ifndef SAVE_CONTEXT
#define SAVE_CONTEXT() do {} while(0)
#endif
#ifndef RESTORE_FPU
#define RESTORE_FPU(context) do {} while (0)
#endif
ram's avatar
ram committed

wlott's avatar
wlott committed
#define OS_VM_PROT_ALL (OS_VM_PROT_READ|OS_VM_PROT_WRITE|OS_VM_PROT_EXECUTE)

extern os_vm_size_t os_vm_page_size;

extern void os_init0(const char *argv[], const char *envp[]);
rtoy's avatar
rtoy committed
extern void os_init(const char *argv[], const char *envp[]);
wlott's avatar
wlott committed
extern void os_install_interrupt_handlers(void);

extern os_vm_address_t os_allocate(os_vm_size_t len);
extern os_vm_address_t os_allocate_at(os_vm_address_t addr, os_vm_size_t len);
extern os_vm_address_t os_reallocate(os_vm_address_t addr,
				     os_vm_size_t old_len, os_vm_size_t len);
wlott's avatar
wlott committed
extern void os_deallocate(os_vm_address_t addr, os_vm_size_t len);
extern void os_zero(os_vm_address_t addr, os_vm_size_t length);

extern os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len);
extern void os_invalidate(os_vm_address_t addr, os_vm_size_t len);
extern os_vm_address_t os_map(int fd, int offset, os_vm_address_t addr,
			      os_vm_size_t len);
extern void os_flush_icache(os_vm_address_t addr, os_vm_size_t len);
extern void os_protect(os_vm_address_t addr, os_vm_size_t len,
wlott's avatar
wlott committed
		       os_vm_prot_t protection);
extern boolean valid_addr(os_vm_address_t test);

#define os_trunc_to_page(addr) \
    (os_vm_address_t)(((long)(addr))&~(os_vm_page_size-1))
#define os_round_up_to_page(addr) \
    os_trunc_to_page((addr)+(os_vm_page_size-1))

#define os_trunc_size_to_page(size) \
    (os_vm_size_t)(((long)(size))&~(os_vm_page_size-1))
#define os_round_up_size_to_page(size) \
    os_trunc_size_to_page((size)+(os_vm_page_size-1))

moore's avatar
 
moore committed
extern void os_foreign_linkage_init(void);
extern void *os_dlsym(const char *sym_name, lispobj lib_list);
moore's avatar
 
moore committed

enum stack_zone_t { BOTH_ZONES, YELLOW_ZONE, RED_ZONE };
extern int os_stack_grows_down(void);
extern void os_guard_control_stack(int zone, int guard);
extern int os_control_stack_overflow(void *, os_context_t *);
unsigned long *os_sigcontext_reg(ucontext_t *, int);
unsigned long *os_sigcontext_pc(ucontext_t *);
unsigned char *os_sigcontext_fpu_reg(ucontext_t *, int);
unsigned int os_sigcontext_fpu_modes(ucontext_t *);
#ifdef i386
extern boolean os_support_sse2(void);
#endif

char* convert_lisp_string(char* c_string, void* lisp_string, int len);

Raymond Toy's avatar
Raymond Toy committed
/*
 * Define macro to allocate a local array of the appropriate size
 * where the fpu state can be stored.
 */
#if defined(i386) || defined(__x86_64)
#define FPU_STATE_SIZE 27
    /* 
     * Need 512 byte area, aligned on a 16-byte boundary.  So allocate
     * 512+16 bytes of space and let the routine adjust use the
     * appropriate alignment.
     */
#define SSE_STATE_SIZE ((512+16)/4)

/*
 * Just use the SSE size for both x87 and sse2 since the SSE size is
 * enough for either.
 */
#define FPU_STATE(name)    int name[SSE_STATE_SIZE];

#elif defined(sparc)
/*
 * 32 (single-precision) FP registers, and the FP state register.
 * But Sparc V9 has 32 double-precision registers (equivalent to 64
 * single-precision, but can't be accessed), so we leave enough room
 * for that.
 */
#define FPU_STATE_SIZE (((32 + 32 + 1) + 1)/2)
#define FPU_STATE(name)    long long name[FPU_STATE_SIZE];
#elif defined(DARWIN) && defined(__ppc__)
#define FPU_STATE_SIZE 32
#define FPU_STATE(name)    long long name[FPU_STATE_SIZE];
#endif
extern void save_fpu_state(void*);
extern void restore_fpu_state(void*);