/************************************************************************
 *
 * This file contains the platform-dependent definitions for the Mac OS X
 * x86 platform.
 *
 *	Copyright (C) 1999-2008 Cincom Systems, Inc.
 *
 ************************************************************************/

#define RIGHT_BIT_FIELD_ORDER 1 /* Compiler ordering of bit fields in structs */

#define PLATFORM_SUPPORTS_64_BITS 1
#define HAS_64_BIT_ARITHMETIC 1
#ifndef assembly
typedef long long longlong;
typedef unsigned long long ulonglong;
#endif

#define HaveCleanSignals TRUE	/* FALSE for polling */
#define CanSmashRegisters FALSE
#define HaveLimitRegister TRUE

/* Ideally this would be defined in the processor include file, but differences
 * in platform assembler syntax makes this a better place.
 */
#define GlueProc "glueUnx86.h"
#define GLUE_ALIGN_IS_POWER_OF_TWO 1
#define UNDERSCORE_EXTERNALS 1

/* This is potentially OS-specific and so does belong here.
 */
#define platcallc_h "macx86CallC.h"

#define PLAT_OSNAME "unix bsd apple I386 MacOSX"
#define StructLayoutAlgorithm "twoFourLayout"

/* The following instruction resets the floating-point unit to the desired
 * initial state which is necessary for correct detection of exceptions in
 * floating-point primitives.  The 80x87 or Pentium FPU will not generate
 * a NaN for an illegal operation such as a divide-by-zero if the exception
 * bit corresponding to that exception is already set in the FPU status word.
 * So to ensure NaNs are produced it is necessary to clear the exception bits
 * before any floating-point operation.  This is because e.g. external code
 * might leave exception bits set in the status word.
 * Implementing it as a single instruction is the fastest approach.
 */
#define NoWaitFInit 1
#if NoWaitFInit
#	define setSaneFPUState() asm("fnclex")
#else
#	define setSaneFPUState() asm("fclex")
#endif
#define assertFPUOk() assert(fpuOk())
#if !defined(assembly)
extern int fpuOk(void);
#endif

#define pdFPUType() 1
#define sc_pc eip
#define SC_PC uc_mcontext->ss.eip

/* Use sbrk for initial alloc to ensure permSpace is below any new old segs. */
#define MORE_MEMORY_USES_SBRK 1

#define MAXWAITMILLISECONDS 500

/* To interoperate with Linux Threads the stack zone needs to be allocated
 * on the stack.
 */
#define ALLOCATE_STACKZONE_ON_C_STACK TRUE

/* This is to ensure $edi & $esi are saved/restored on callback. */
#define USE_JMPBUF 1

/* The OSX x86 ABI requires 16-byte alignment.
 */
#define C_STACK_POINTER_BYTE_ALIGNMENT 16
#if defined(__GNUC__)
# define getsp() ({ register void *sp;				\
	asm volatile ("movl %%esp,%0" : "=r"(sp) : );	\
	sp; })
# define setsp(sp) asm volatile ("movl %0,%%esp" : : "memory"(sp) )
#elif !defined(assembly)
extern void *getsp(void);
extern void setsp(void*);
#endif
