mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
Both the 68k and PowerPC platform now invoke them in the same order and the 68k code uses the designated invocation priorities. The PowerPC destructor function now sets up the exit() jmp_buf before the destructor functions are called. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14874 87f5fb63-7c3d-0410-a384-fd976d0f7a62
242 lines
6.6 KiB
C
242 lines
6.6 KiB
C
/*
|
|
* $Id: macros.h,v 1.13 2005-03-10 09:55:03 obarthel Exp $
|
|
*
|
|
* :ts=4
|
|
*
|
|
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
|
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* - Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
*
|
|
* - Neither the name of Olaf Barthel nor the names of contributors
|
|
* may be used to endorse or promote products derived from this
|
|
* software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef _MACROS_H
|
|
#define _MACROS_H
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef DOS_DOS_H
|
|
#include <dos/dos.h>
|
|
#endif /* DOS_DOS_H */
|
|
|
|
/****************************************************************************/
|
|
|
|
#define CANNOT !
|
|
#define DO_NOTHING ((void)0)
|
|
#define NO !
|
|
#define NOT !
|
|
#define DO_NOT !
|
|
#define OK (0)
|
|
#define SAME (0)
|
|
#define SEEK_ERROR (-1)
|
|
#define ERROR (-1)
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef ZERO
|
|
#define ZERO ((BPTR)NULL)
|
|
#endif /* ZERO */
|
|
|
|
/****************************************************************************/
|
|
|
|
#define NUM_ENTRIES(t) (sizeof(t) / sizeof(t[0]))
|
|
|
|
/****************************************************************************/
|
|
|
|
#define FLAG_IS_SET(v,f) (((v) & (f)) == (f))
|
|
#define FLAG_IS_CLEAR(v,f) (((v) & (f)) == 0 )
|
|
|
|
/****************************************************************************/
|
|
|
|
#define SET_FLAG(v,f) ((void)((v) |= (f)))
|
|
#define CLEAR_FLAG(v,f) ((void)((v) &= ~(f)))
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Macro to get longword-aligned stack space for a structure
|
|
* Uses ANSI token catenation to form a name for the char array
|
|
* based on the variable name, then creates an appropriately
|
|
* typed pointer to point to the first longword boundary in the
|
|
* char array allocated.
|
|
*/
|
|
#define D_S(type, name) \
|
|
char a_##name[sizeof(type)+3]; \
|
|
type *name = (type *)((LONG)(a_##name+3) & ~3)
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef AMIGA_COMPILER_H
|
|
|
|
#ifdef __SASC
|
|
|
|
#ifndef ASM
|
|
#define ASM __asm
|
|
#endif /* ASM */
|
|
|
|
#ifndef REG
|
|
#define REG(r,p) register __##r p
|
|
#endif /* REG */
|
|
|
|
#ifndef INTERRUPT
|
|
#define INTERRUPT __interrupt
|
|
#endif /* INTERRUPT */
|
|
|
|
#ifndef INLINE
|
|
#define INLINE __inline
|
|
#endif /* INLINE */
|
|
#endif /* __SASC */
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifndef ASM
|
|
#define ASM
|
|
#endif /* ASM */
|
|
|
|
#ifndef REG
|
|
#define REG(r,p) p __asm(#r)
|
|
#endif /* REG */
|
|
|
|
#ifndef INTERRUPT
|
|
#define INTERRUPT __attribute__((__interrupt__))
|
|
#endif /* INTERRUPT */
|
|
|
|
#ifndef INLINE
|
|
#define INLINE __inline__
|
|
#endif /* INLINE */
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* AMIGA_COMPILER_H */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef WEAK
|
|
#ifdef __GNUC__
|
|
#define WEAK __attribute__((weak))
|
|
#else
|
|
#define WEAK /* WEAK */
|
|
#endif /* __GNUC__ */
|
|
#endif /* WEAK */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef UNUSED
|
|
#ifdef __GNUC__
|
|
#define UNUSED __attribute__((unused))
|
|
#define NOCOMMON __attribute__((nocommon))
|
|
#else
|
|
#define UNUSED /* UNUSED */
|
|
#define NOCOMMON /* NOCOMMON */
|
|
#endif /* __GNUC__ */
|
|
#endif /* UNUSED */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifdef __SASC
|
|
|
|
#define CONSTRUCTOR(name,pri) \
|
|
int __stdargs _STI_##pri##_##name(void); \
|
|
int __stdargs _STI_##pri##_##name(void)
|
|
|
|
#define DESTRUCTOR(name,pri) \
|
|
int __stdargs _STD_##pri##_##name(void); \
|
|
int __stdargs _STD_##pri##_##name(void)
|
|
|
|
#define CONSTRUCTOR_SUCCEED() \
|
|
return(0)
|
|
|
|
#define CONSTRUCTOR_FAIL() \
|
|
return(1)
|
|
|
|
#endif /* __SASC */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
#define CONSTRUCTOR(name,pri) \
|
|
STATIC VOID __attribute__((used)) name##_ctor(VOID); \
|
|
STATIC VOID (*__##name##_ctor)(VOID) __attribute__((used,section(".ctors._" #pri))) = name##_ctor; \
|
|
STATIC VOID name##_ctor(VOID)
|
|
|
|
#define DESTRUCTOR(name,pri) \
|
|
STATIC VOID __attribute__((used)) name##_dtor(VOID); \
|
|
STATIC VOID (*__##name##_dtor)(VOID) __attribute__((used,section(".dtors._" #pri))) = name##_dtor; \
|
|
STATIC VOID name##_dtor(VOID)
|
|
|
|
#else
|
|
|
|
#define CONSTRUCTOR(name,pri) \
|
|
STATIC VOID __attribute__((constructor)) __ctor##pri##_##name##(VOID); \
|
|
STATIC void __ctor##pri##_##name##(VOID)
|
|
|
|
#define DESTRUCTOR(name,pri) \
|
|
STATIC VOID __attribute__((destructor)) __dtor##pri##_##name##(VOID); \
|
|
STATIC VOID __dtor##pri##_##name##(VOID)
|
|
|
|
#endif /* __amigaos4__ */
|
|
|
|
#define CONSTRUCTOR_SUCCEED() \
|
|
return
|
|
|
|
#define CONSTRUCTOR_FAIL() \
|
|
exit(RETURN_FAIL) /* ZZZ not a nice thing to do; fix the constructor invocation code! */
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
/****************************************************************************/
|
|
|
|
#define CLIB_CONSTRUCTOR(name) CONSTRUCTOR(name, 500)
|
|
#define CLIB_DESTRUCTOR(name) DESTRUCTOR(name, 500)
|
|
#define PROFILE_CONSTRUCTOR(name) CONSTRUCTOR(name, 150)
|
|
#define PROFILE_DESTRUCTOR(name) DESTRUCTOR(name, 150)
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifdef __SASC
|
|
extern void ASM _PROLOG(REG(a0,char *));
|
|
extern void ASM _EPILOG(REG(a0,char *));
|
|
|
|
#if _PROFILE
|
|
#define PROFILE_OFF() _PROLOG(0L)
|
|
#define PROFILE_ON() _EPILOG(0L)
|
|
#else
|
|
#define PROFILE_OFF() ((void)0)
|
|
#define PROFILE_ON() ((void)0)
|
|
#endif /* _PROFILE */
|
|
#endif /* __SASC */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifdef __GNUC__
|
|
#define PROFILE_OFF() ((void)0)
|
|
#define PROFILE_ON() ((void)0)
|
|
#endif /* __GNUC__ */
|
|
|
|
/****************************************************************************/
|
|
|
|
#endif /* _MACROS_H */
|