1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Updated for dual PowerPC/68k build.

git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15002 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-07-04 10:25:33 +00:00
parent 38818e6502
commit 525bdde6d5
11 changed files with 450 additions and 64 deletions

View File

@ -0,0 +1,69 @@
#
# $Id: GNUmakefile.68k,v 1.1 2005-07-04 10:25:33 obarthel Exp $
#
# :ts=4
#
# Amiga shared library skeleton example
# 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.
#
WARNINGS = \
-Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
-Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion
CC = gcc
CPU = -m68000
OPTIONS = -DNDEBUG
OPTIMIZE = -O
DEBUG = -g
###############################################################################
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. -I/V/include
###############################################################################
OBJS = \
lib_base.o lib_user.o
###############################################################################
LIBS = -lc -lamiga
###############################################################################
all: skeleton.library
skeleton.library: $(OBJS)
$(CC) -o $@.debug $(OBJS) $(CFLAGS) -Wl,--cref,-M,-Map=$@.map \
-nostartfiles -nostdlib $(LIBS)
strip --strip-all -o $@ $@.debug
###############################################################################
clean:
-rm -f *.o *.debug *.map skeleton.library

View File

@ -0,0 +1,69 @@
#
# $Id: GNUmakefile.os4,v 1.1 2005-07-04 10:25:33 obarthel Exp $
#
# :ts=4
#
# Amiga shared library skeleton example
# 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.
#
WARNINGS = \
-Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
-Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion
CC = ppc-amigaos-gcc
CPU =
OPTIONS = -DNDEBUG
OPTIMIZE = -O
DEBUG = -ggdb
###############################################################################
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. -I/V/include
###############################################################################
OBJS = \
lib_base.o lib_user.o usergroup_68k.o
###############################################################################
LIBS = -lc -lamiga
###############################################################################
all: skeleton.library
skeleton.library: $(OBJS)
$(CC) -o $@.debug $(OBJS) $(CFLAGS) -Wl,--cref,-M,-Map=$@.map \
-nostartfiles -nostdlib $(LIBS)
ppc-amigaos-strip -R.comment -o $@ $@.debug
###############################################################################
clean:
-rm -f *.o *.debug *.map skeleton.library

View File

@ -1,5 +1,5 @@
/*
* $Id: lib_base.c,v 1.1 2005-07-04 09:39:00 obarthel Exp $
* $Id: lib_base.c,v 1.2 2005-07-04 10:25:33 obarthel Exp $
*
* :ts=4
*
@ -31,6 +31,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <exec/execbase.h>
#include <exec/resident.h>
#include <exec/libraries.h>
#include <exec/memory.h>
@ -39,7 +40,8 @@
/****************************************************************************/
#ifndef __NOLIBBASE__
#define __NOLIBBASE__
#define __USE_INLINE__
#include <proto/exec.h>
/****************************************************************************/
@ -57,11 +59,23 @@ LONG _start(VOID);
/****************************************************************************/
STATIC struct SkeletonBase *ASM LibInit(REG (d0, struct SkeletonBase *sb ), REG (a0, BPTR segment_list ), REG (a6, struct Library *sys_base ));
STATIC struct SkeletonBase *ASM LibOpen(REG (a6, struct SkeletonBase *sb ));
STATIC BPTR ASM LibExpunge(REG (a6, struct SkeletonBase *sb ));
STATIC BPTR ASM LibClose(REG (a6, struct SkeletonBase *sb ));
STATIC LONG LibReserved(VOID);
STATIC struct SkeletonBase *ASM lib_init(REG (d0, struct SkeletonBase *sb ), REG (a0, BPTR segment_list ), REG (a6, APTR whatever ));
STATIC struct SkeletonBase *ASM lib_open(REG (a6, APTR base ));
STATIC BPTR ASM lib_expunge(REG (a6, APTR base ));
STATIC BPTR ASM lib_close(REG (a6, APTR base ));
/****************************************************************************/
#if defined(__amigaos4__)
STATIC ULONG lib_default_obtain(struct Interface *self);
STATIC ULONG lib_default_release(struct Interface *self);
#else
STATIC LONG lib_reserved(VOID);
#endif /* __amigaos4__ */
/****************************************************************************/
@ -83,9 +97,7 @@ _start(VOID)
the exception of the lib_Revision field, i.e. everything that
could be gained from the Resident structure is now in the
Library structure. Earlier operating system releases would leave
the entire Library structure uninitialized. For this example
we assume that Kickstart 2.0 is around as it must be possible
to open dos.library V37.
the entire Library structure uninitialized.
The library initialization is single threaded, i.e. the operating
system processes library initialization in a queue. The longer it
@ -101,15 +113,28 @@ _start(VOID)
This routine must return the Library base pointer if it succeeds.
Failure is indicated by returning NULL instead. */
STATIC struct SkeletonBase * ASM
LibInit(
lib_init(
REG(d0,struct SkeletonBase * sb),
REG(a0,BPTR segment_list),
REG(a6,struct Library * sys_base))
REG(a6,APTR whatever))
{
struct SkeletonBase * result = NULL;
struct Library * SysBase;
#if defined(__amigaos4__)
struct ExecIFace * IExec;
#endif /* __amigaos4__ */
SysBase = sys_base;
#if defined(__amigaos4__)
{
IExec = (struct ExecIFace *)whatever;
SysBase = (struct Library *)IExec->Data.LibBase;
}
#else
{
SysBase = (struct Library *)whatever;
}
#endif /* __amigaos4__ */
/* This library implementation requires Kickstart 2.04 or
better to work. */
@ -121,6 +146,12 @@ LibInit(
sb->sb_SysBase = SysBase;
#if defined(__amigaos4__)
{
sb->sb_IExec = IExec;
}
#endif /* __amigaos4__ */
InitSemaphore(&sb->sb_Semaphore);
/* The segment pointer must be stored for later, when this library is
@ -153,8 +184,16 @@ LibInit(
of type RTF_AUTOINIT (see the "struct Resident" rt_Flags
initialization value for the LibTag declaration at the end of
this file). */
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
#if defined(__amigaos4__)
{
DeleteLibrary((struct Library *)sb);
}
#else
{
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
}
#endif /* __amigaos4__ */
}
return(result);
@ -178,8 +217,9 @@ LibInit(
This routine must return the Library base pointer if it succeeds.
Failure is indicated by returning NULL instead. */
STATIC struct SkeletonBase * ASM
LibOpen(REG(a6,struct SkeletonBase * sb))
lib_open(REG(a6,APTR base))
{
USE_LIBBASE(base);
USE_EXEC(sb);
struct SkeletonBase * result = NULL;
@ -232,8 +272,9 @@ LibOpen(REG(a6,struct SkeletonBase * sb))
the life cycle of the library. It is called while Task
switching is disabled. */
STATIC BPTR ASM
LibExpunge(REG(a6,struct SkeletonBase * sb))
lib_expunge(REG(a6,APTR base))
{
USE_LIBBASE(base);
USE_EXEC(sb);
BPTR result = ZERO;
@ -264,8 +305,16 @@ LibExpunge(REG(a6,struct SkeletonBase * sb))
/* Finally, free the data allocated for the
base data structure. */
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
#if defined(__amigaos4__)
{
DeleteLibrary((struct Library *)sb);
}
#else
{
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
}
#endif /* __amigaos4__ */
}
return(result);
@ -278,8 +327,9 @@ LibExpunge(REG(a6,struct SkeletonBase * sb))
Task switching is disabled and has to return the result
code of the library expunge routine when the time is right. */
STATIC BPTR ASM
LibClose(REG(a6,struct SkeletonBase * sb))
lib_close(REG(a6,APTR base))
{
USE_LIBBASE(base);
USE_EXEC(sb);
BPTR result = ZERO;
@ -298,17 +348,138 @@ LibClose(REG(a6,struct SkeletonBase * sb))
/* Trigger the library expunge function, if desired. */
if(sb->sb_Library.lib_OpenCnt == 0 && (sb->sb_Library.lib_Flags & LIBF_DELEXP) != 0)
result = LibExpunge(sb);
result = lib_expunge(base);
return(result);
}
/****************************************************************************/
#if defined(__amigaos4__)
/****************************************************************************/
STATIC ULONG
lib_default_obtain(struct Interface * self)
{
return(self->Data.RefCount++);
}
STATIC ULONG
lib_default_release(struct Interface * self)
{
return(self->Data.RefCount--);
}
/****************************************************************************/
STATIC CONST APTR manager_vectors[] =
{
lib_default_obtain,
lib_default_release,
NULL,
NULL,
lib_open,
lib_close,
lib_expunge,
NULL,
(APTR)-1,
};
STATIC CONST struct TagItem manager_tags[] =
{
{ MIT_Name, (ULONG)"__library" },
{ MIT_VectorTable, (ULONG)manager_vectors },
{ MIT_Version, 1 },
{ TAG_DONE, 0 }
};
/****************************************************************************/
STATIC CONST APTR main_vectors[]=
{
lib_default_obtain,
lib_default_release,
NULL,
NULL,
(APTR)-1
};
STATIC CONST struct TagItem main_tags[] =
{
{ MIT_Name, (ULONG)"main" },
{ MIT_VectorTable, (ULONG)main_vectors },
{ MIT_Version, 1 },
{ TAG_DONE, 0 }
};
/****************************************************************************/
STATIC CONST APTR lib_interfaces[] =
{
(CONST APTR)manager_tags,
(CONST APTR)main_tags,
NULL
};
/****************************************************************************/
extern ULONG VecTable68K[];
/****************************************************************************/
CONST struct TagItem lib_create_tags[] =
{
{ CLT_DataSize, sizeof(struct SkeletonBase) },
{ CLT_Vector68K, (ULONG)VecTable68K },
{ CLT_Interfaces, (ULONG)lib_interfaces },
{ CLT_InitFunc, (ULONG)lib_init },
{ TAG_DONE, 0 }
};
/****************************************************************************/
CONST struct TagItem local_lib_create_tags[] =
{
{ CLT_DataSize, sizeof(struct SkeletonBase) },
{ CLT_Vector68K, (ULONG)VecTable68K },
{ CLT_Interfaces, (ULONG)lib_interfaces },
{ TAG_DONE, 0 }
};
/****************************************************************************/
STATIC CONST UBYTE version_string[] = "$VER: " VSTRING;
/****************************************************************************/
CONST struct Resident LibTag[] =
{
RTC_MATCHWORD,
(struct Resident *)&LibTag[0],
(struct Resident *)&LibTag[1],
RTF_AUTOINIT|RTF_NATIVE,
VERSION,
NT_LIBRARY,
0,
"skeleton.library",
(STRPTR)&version_string[6],
(struct TagItem *)lib_create_tags
};
/****************************************************************************/
#else
/****************************************************************************/
/* This is the reserved library entry point. It always
has to return 0. */
STATIC LONG
LibReserved(VOID)
lib_reserved(VOID)
{
return(0);
}
@ -331,12 +502,12 @@ struct LibraryInitTable
/* This is the table of functions that make up the library. The first
four are mandatory, everything following it are user callable
routines. The table is terminated by the value -1. */
STATIC CONST APTR LibVectors[] =
STATIC CONST APTR lib_vectors[] =
{
LibOpen,
LibClose,
LibExpunge,
LibReserved,
lib_open,
lib_close,
lib_expunge,
lib_reserved,
(APTR) -1
};
@ -345,12 +516,12 @@ STATIC CONST APTR LibVectors[] =
/* This finally sets up the library base data structure and the
function vector. */
STATIC CONST struct LibraryInitTable LibInitTable =
STATIC CONST struct LibraryInitTable lib_init_table =
{
sizeof(struct SkeletonBase),
LibVectors,
(APTR *)lib_vectors,
NULL,
LibInit
lib_init
};
/****************************************************************************/
@ -360,14 +531,18 @@ STATIC CONST struct LibraryInitTable LibInitTable =
setting up the Library base data structure. */
struct Resident LibTag[] =
{
RTC_MATCHWORD, /* Marker value. */
&LibTag[0], /* This points back to itself. */
&LibTag[1], /* This points behind this marker. */
RTF_AUTOINIT, /* The Library should be set up according to the given table. */
VERSION, /* The version of this Library. */
NT_LIBRARY, /* This defines this module as a Library. */
0, /* Initialization priority of this Library; unused. */
"skeleton.library", /* Points to the name of the Library. */
VSTRING, /* The identification string of this Library. */
&LibInitTable /* This table is for initializing the Library. */
RTC_MATCHWORD, /* Marker value. */
(struct Resident *)&LibTag[0], /* This points back to itself. */
(struct Resident *)&LibTag[1], /* This points behind this marker. */
RTF_AUTOINIT, /* The Library should be set up according to the given table. */
VERSION, /* The version of this Library. */
NT_LIBRARY, /* This defines this module as a Library. */
0, /* Initialization priority of this Library; unused. */
"skeleton.library", /* Points to the name of the Library. */
VSTRING, /* The identification string of this Library. */
(APTR)&lib_init_table /* This table is for initializing the Library. */
};
/****************************************************************************/
#endif /* __amigaos4__ */

View File

@ -1,5 +1,5 @@
/*
* $Id: lib_base.h,v 1.1 2005-07-04 09:39:00 obarthel Exp $
* $Id: lib_base.h,v 1.2 2005-07-04 10:25:33 obarthel Exp $
*
* :ts=4
*
@ -36,6 +36,10 @@
/****************************************************************************/
#ifndef EXEC_EXECBASE_H
#include <exec/execbase.h>
#endif /* EXEC_EXECBASE_H */
#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif /* EXEC_LIBRARIES_H */
@ -56,20 +60,55 @@
/****************************************************************************/
struct SkeletonBase
{
struct Library sb_Library;
struct SignalSemaphore sb_Semaphore;
BPTR sb_SegmentList;
struct Library * sb_SysBase;
struct UserData * sb_UserData;
};
#if defined(USE_EXEC)
#undef USE_EXEC
#endif /* USE_EXEC */
/****************************************************************************/
#if defined(__amigaos4__)
/****************************************************************************/
#define USE_EXEC(sb) \
struct ExecIFace * IExec = (sb)->sb_IExec
#define USE_LIBBASE(base) \
struct SkeletonIFace * ISkeleton = (struct SkeletonIFace *)(base); \
struct SkeletonBase * sb = (struct SkeletonBase *)ISkeleton->Data.LibBase
/****************************************************************************/
#else
/****************************************************************************/
#define USE_EXEC(sb) \
struct Library * SysBase = (sb)->sb_SysBase
#define USE_LIBBASE(base) \
struct SkeletonBase * sb = (struct SkeletonBase *)(base)
/****************************************************************************/
#endif /* __amigaos4__ */
/****************************************************************************/
struct SkeletonBase
{
struct Library sb_Library;
struct SignalSemaphore sb_Semaphore;
BPTR sb_SegmentList;
struct Library * sb_SysBase;
#if defined(__amigaos4__)
struct ExecIFace * sb_IExec;
#endif /* __amigaos4__ */
struct UserData * sb_UserData;
};
/****************************************************************************/
#endif /* _LIB_BASE_H */

View File

@ -1,5 +1,5 @@
/*
* $Id: lib_user.c,v 1.1 2005-07-04 09:39:00 obarthel Exp $
* $Id: lib_user.c,v 1.2 2005-07-04 10:25:33 obarthel Exp $
*
* :ts=4
*
@ -31,7 +31,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "lib_base.h"
#include "lib_user.h"
/****************************************************************************/
@ -60,6 +59,12 @@ UserLibInit(struct Library * SysBase,struct UserData * ud)
/* Also remember the SysBase pointer. */
ud->ud_SysBase = SysBase;
#if defined(__amigaos4__)
{
ud->ud_IExec = (struct ExecIFace *)((struct ExecBase *)SysBase)->MainInterface;
}
#endif /* __amigaos4__ */
result = TRUE;
return(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: lib_user.h,v 1.1 2005-07-04 09:39:00 obarthel Exp $
* $Id: lib_user.h,v 1.2 2005-07-04 10:25:33 obarthel Exp $
*
* :ts=4
*
@ -36,6 +36,10 @@
/****************************************************************************/
#ifndef EXEC_EXECBASE_H
#include <exec/execbase.h>
#endif /* EXEC_EXECBASE_H */
#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif /* EXEC_LIBRARIES_H */
@ -45,6 +49,11 @@
struct UserData
{
struct Library * ud_SysBase;
#if defined(__amigaos4__)
struct ExecIFace * ud_IExec;
#endif /* __amigaos4__ */
ULONG ud_UseCount;
};

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 1
#define REVISION 2
#define DATE "4.7.2005"
#define VERS "skeleton.library 1.1"
#define VSTRING "skeleton.library 1.1 (4.7.2005)\r\n"
#define VERSTAG "\0$VER: skeleton.library 1.1 (4.7.2005)"
#define VERS "skeleton.library 1.2"
#define VSTRING "skeleton.library 1.2 (4.7.2005)\r\n"
#define VERSTAG "\0$VER: skeleton.library 1.2 (4.7.2005)"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE library SYSTEM "library.dtd">
<library name="skeleton" basename="SkeletonBase" openname="skeleton.library">
<include>exec/types.h</include>
<interface name="main" version="1.0" struct="SkeletonIFace" prefix="_Skeleton_" asmprefix="ISkeleton" global="ISkeleton">
<method name="Obtain" result="ULONG"/>
<method name="Release" result="ULONG"/>
<method name="Expunge" result="void" status="unimplemented"/>
<method name="Clone" result="struct Interface *" status="unimplemented"/>
</interface>
</library>

View File

@ -0,0 +1,8 @@
==id $Id: skeleton_lib.sfd,v 1.1 2005-07-04 10:25:33 obarthel Exp $
* "skeleton.library"
==base _SkeletonBase
==bias 30
==public
==include <exec/types.h>
*
==end

View File

@ -1,7 +1,7 @@
#
# $Id: smakefile,v 1.1 2005-07-04 09:39:00 obarthel Exp $
# $Id: smakefile,v 1.2 2005-07-04 10:25:33 obarthel Exp $
#
# :ts=4
# :ts=8
#
# Amiga shared library skeleton example
# Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
@ -41,10 +41,11 @@ VERSION = 1
###############################################################################
#OPTIMIZE = optimize optsize optinline optinlocal
CPU = 060
#DEBUG = line
DEBUG = symbolflush noopt
OPTIMIZE = optimize optsize optinline optinlocal
CPU = any
#CPU = 060
DEBUG = line
#DEBUG = symbolflush noopt
###############################################################################
@ -97,7 +98,7 @@ version:
###############################################################################
cvs-tag:
cvs -q tag V$(VERSION)_`type skeleton.library_rev.rev`
cvs -q tag LIB_V$(VERSION)_`type skeleton.library_rev.rev`
###############################################################################