Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / popupmenu / libinit.c
blob6b7bec94941f55fd5e74ef8b34f31526e23c5905
1 #define _USEOLDEXEC_ 1
3 #include <exec/types.h>
4 #include <exec/exec.h>
5 #include <exec/execbase.h>
6 #include <intuition/intuition.h>
7 #include <libraries/dos.h>
8 #include <proto/exec.h>
9 #include <proto/dos.h>
10 #include <string.h>
12 #include <libraries/pm.h>
14 /* Prototypes */
15 ULONG __asm _LibExpunge( register __a6 struct PopupMenuBase *libbase );
16 ULONG __asm _LibInit ( register __a0 APTR seglist,
17 register __d0 struct PopupMenuBase *libbase );
19 int __saveds __asm __UserLibInit (register __a6 struct PopupMenuBase *libbase);
20 void __saveds __asm __UserLibCleanup(register __a6 struct PopupMenuBase *libbase);
22 int __saveds __asm __UserDevInit (register __d0 long unit,
23 register __a0 struct IORequest *ior,
24 register __a6 struct PopupMenuBase *libbase);
25 void __saveds __asm __UserDevCleanup(register __a0 struct IORequest *ior,
26 register __a6 struct PopupMenuBase *libbase);
28 int __saveds __asm __libfpinit (register __a6 struct PopupMenuBase *libbase);
29 void __saveds __asm __libfpterm (register __a6 struct PopupMenuBase *libbase);
32 typedef LONG (*myPFL)(); /* pointer to function returning 32-bit int */
34 /* library initialization table, used for AUTOINIT libraries */
35 struct InitTable {
36 ULONG *it_DataSize; /* library data space size */
37 myPFL *it_FuncTable; /* table of entry points */
38 APTR it_DataInit; /* table of data initializers */
39 myPFL it_InitFunc; /* initialization function to run */
42 /* symbols generated by blink */
43 extern char __far _LibID[]; /* ID string */
44 extern char __far _LibName[]; /* Name string */
45 extern char __far RESLEN; /* size of init data */
46 extern long __far NEWDATAL; /* size of global data */
47 extern long __far NUMJMPS; /* number of jmp vectors to copy */
48 extern myPFL _LibFuncTab[]; /* my function table */
49 extern long __far _LibVersion; /* Version of library */
50 extern long __far _LibRevision; /* Revision of library */
51 #define MYVERSION ((long)&_LibVersion)
52 #define MYREVISION ((long)&_LibRevision)
53 #define DATAWORDS ((long)&NEWDATAL) /* magic to get right tpye of reloc */
54 #define SIZEJMPTAB ((long)libbase->pmb_origbase->pmb_numjmps)
55 /* size in bytes of jmp table */
57 /* From libent.o, needed to determine where data is loaded by loadseg */
58 extern long far _Libmergeddata;
60 #define MYLIBRARYSIZE ((sizeof(struct PopupMenuBase) +3) & ~3)
64 struct InitTable __far _LibInitTab = {
65 (long *)(&RESLEN+MYLIBRARYSIZE),
66 _LibFuncTab,
67 NULL, /* will initialize my own data */
68 _LibInit,
71 __asm ULONG _LibInit( register __a0 APTR seglist,
72 register __d0 struct PopupMenuBase *libbase )
74 long *reloc;
75 long *sdata;
76 char *ddata;
77 long nrelocs;
80 libbase->pmb_SegList = (ULONG) seglist;
82 /* init. library structure (since I don't do automatic data init.) */
83 libbase->pmb_Library.lib_Node.ln_Type = NT_LIBRARY;
84 libbase->pmb_Library.lib_Node.ln_Name = _LibName;
85 libbase->pmb_Library.lib_Node.ln_Succ = NULL;
86 libbase->pmb_Library.lib_Node.ln_Pred = NULL;
87 libbase->pmb_Library.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
88 libbase->pmb_Library.lib_Version = MYVERSION;
89 libbase->pmb_Library.lib_Revision = MYREVISION;
90 libbase->pmb_Library.lib_IdString = (APTR) _LibID;
92 /* Start of copy of global data after structure */
93 ddata = (char *)libbase + MYLIBRARYSIZE;
95 sdata = (long *)&_Libmergeddata; /* where loadseg loaded the data */
96 memcpy(ddata, (void *)sdata, DATAWORDS*4);
98 /* perform relocs if we want one global section for all programs */
99 /* that have this lib open. If we want a global section for each */
100 /* open, copy the relocs, and do them on each open call. */
101 sdata = sdata + DATAWORDS;
102 nrelocs = *sdata;
103 sdata++;
104 while (nrelocs > 0)
106 reloc = (long *)((long)ddata + *sdata++);
107 *reloc += (long)ddata;
108 nrelocs--;
111 if (__UserLibInit(libbase) != 0)
112 return NULL; /* abort if user init failed */
114 return ( (ULONG) libbase );
117 LONG __asm _LibOpen(
118 register __a6 struct PopupMenuBase *libbase )
120 /* mark us as having another customer */
121 libbase->pmb_Library.lib_OpenCnt++;
123 /* clear delayed expunges (standard procedure) */
124 libbase->pmb_Library.lib_Flags &= ~LIBF_DELEXP;
126 return ( (LONG) libbase );
129 ULONG __asm _LibClose(
130 register __a6 struct PopupMenuBase *libbase )
132 ULONG retval = 0;
134 if (( --libbase->pmb_Library.lib_OpenCnt == 0 ) &&
135 ( libbase->pmb_Library.lib_Flags & LIBF_DELEXP ))
137 /* no more people have me open,
138 * and I have a delayed expunge pending
140 retval = _LibExpunge( libbase ); /* return segment list */
143 return (retval);
146 ULONG __asm _LibExpunge( register __a6 struct PopupMenuBase *libbase )
148 ULONG seglist = 0;
149 LONG libsize;
151 libbase->pmb_Library.lib_Flags |= LIBF_DELEXP;
152 if ( libbase->pmb_Library.lib_OpenCnt == 0 )
154 /* really expunge: remove libbase and freemem */
155 __UserLibCleanup(libbase);
156 //KPutStr("libcleanup done\n");
158 seglist = libbase->pmb_SegList;
160 //kprintf("Removing: %08lx (%s)\n", libbase, libbase->lib_Node.ln_Name);
161 //kprintf("SysBase: %08lx\n", SysBase);
162 SysBase=*((struct ExecBase **)4);
163 //kprintf("SysBase: %08lx\n", SysBase);
164 Remove( (struct Node *) libbase);
165 //KPutStr("Removed library\n");
167 libsize = libbase->pmb_Library.lib_NegSize + libbase->pmb_Library.lib_PosSize;
168 FreeMem( (char *) libbase - libbase->pmb_Library.lib_NegSize,(LONG) libsize );
171 /* return NULL or real seglist */
172 return ( (ULONG) seglist );