2 #include <exec/types.h>
3 #include <exec/libraries.h>
4 #include <exec/resident.h>
6 #include <proto/exec.h>
9 # define SAVEDS //__saveds confuses data=faronly
11 # define REG(r,a) register __ ## r a
12 #elif defined(__GNUC__)
13 # define SAVEDS /*__geta4*/
15 # define REG(r,a) a __asm(#r)
24 #define LIB_REVISION 0
26 int LibReserved(void) {
30 static const APTR LibInitTable
[];
31 extern const char LibName
[];
32 extern const char LibId
[];
34 #ifndef __HAVE_68881__
35 struct Library
*__MathIeeeDoubBasBase
;
36 struct Library
*__MathIeeeDoubTransBase
;
39 struct MyLibrary
* ASM
LibInit(REG(a0
,BPTR seglist
),
40 REG(d0
,struct MyLibrary
*base
),
41 REG(a6
,struct ExecBase
*sysbase
));
42 struct MyLibrary
* ASM
LibOpen(REG(a6
,struct MyLibrary
*base
));
43 BPTR ASM
LibClose(REG(a6
,struct MyLibrary
*base
));
44 BPTR ASM
LibExpunge(REG(a6
,struct MyLibrary
*base
));
46 void (** SAVEDS ASM
LibgetBase(void))();
48 static const struct Resident romtag
={
50 (struct Resident
*)&romtag
,
61 static const APTR LibFuncTable
[]={
70 #define INITBYTE_ENTRY(x) UWORD a##x;UWORD b##x;UBYTE c##x;UBYTE d##x
71 #define INITWORD_ENTRY(x) UWORD a##x;UWORD b##x;UWORD c##x
72 #define INITAPTR_ENTRY(x) UWORD a##x;UWORD b##x;APTR c##x
73 #define INITBYTE(S,E,x) 0xe000,offsetof(struct S,E),(x),0
74 #define INITWORD(S,E,x) 0xd000,offsetof(struct S,E),(x)
75 #define INITAPTR(S,E,x) 0xc000,offsetof(struct S,E),(x)
86 INITBYTE(Node
,ln_Type
,NT_LIBRARY
),
87 INITAPTR(Node
,ln_Name
,(APTR
)LibName
),
88 INITBYTE(Library
,lib_Flags
,LIBF_SUMUSED
|LIBF_CHANGED
),
89 INITWORD(Library
,lib_Version
,LIB_VERSION
),
90 INITWORD(Library
,lib_Revision
,LIB_REVISION
),
91 INITAPTR(Library
,lib_IdString
,(APTR
)LibId
),
95 static const APTR LibInitTable
[]={
96 (APTR
)((sizeof(struct MyLibrary
)+3)&~3),
102 struct ExecBase
*SysBase
;
104 extern void (*funcTable
[])();
107 struct MyLibrary
* SAVEDS ASM
LibInit(REG(a0
,BPTR seglist
),
108 REG(d0
,struct MyLibrary
*base
),
109 REG(a6
,struct ExecBase
*sysbase
)) {
110 base
->seglist
=seglist
;
115 struct MyLibrary
* SAVEDS ASM
LibOpen(REG(a6
,struct MyLibrary
*base
)) {
116 base
->lib
.lib_Flags
&=~LIBF_DELEXP
;
117 #ifndef __HAVE_68881__
118 __MathIeeeDoubBasBase
= OpenLibrary("mathieeedoubbas.library",0);
119 if (__MathIeeeDoubBasBase
)
120 __MathIeeeDoubTransBase
= OpenLibrary("mathieeedoubtrans.library",0);
121 if (!__MathIeeeDoubBasBase
|| !__MathIeeeDoubTransBase
)
124 ++base
->lib
.lib_OpenCnt
;
128 BPTR SAVEDS ASM
LibClose(REG(a6
,struct MyLibrary
*base
)) {
130 #ifndef __HAVE_68881__
131 CloseLibrary(__MathIeeeDoubTransBase
);
132 CloseLibrary(__MathIeeeDoubBasBase
);
134 if(base
->lib
.lib_OpenCnt
>0)
135 --base
->lib
.lib_OpenCnt
;
136 if(base
->lib
.lib_OpenCnt
==0 && base
->lib
.lib_Flags
&LIBF_DELEXP
)
137 retval
=LibExpunge(base
);
141 BPTR SAVEDS ASM
LibExpunge(REG(a6
,struct MyLibrary
*base
)) {
143 base
->lib
.lib_Flags
|=LIBF_DELEXP
;
144 if(base
->lib
.lib_OpenCnt
==0) {
145 struct Library
*SysBase
=*(struct Library
**)4;
147 Remove(&base
->lib
.lib_Node
);
148 FreeMem((UBYTE
*)base
-base
->lib
.lib_NegSize
,
149 base
->lib
.lib_NegSize
+base
->lib
.lib_PosSize
);
155 void (** SAVEDS ASM
LibgetBase(void))() {