[comp.sys.amiga] Making Shared Libraries

840445m@aucs.uucp (Alan McKay) (12/15/89)

In article <596@cameron.cs.duke.edu> amr@dukee.egr.duke.edu (Anthony M. Richardson) writes:
>I've always thought the Amiga shared libraries were a nifty idea and
>so I've decided to try and create my own library. Blink (with thei
>
>Tony Richardson        amr@dukee.egr.duke.edu

Try 'oml' which comes with Lattice 5.0x.  It is used specifically for 
making shared libraries.  I have never used it myself but if you look in
the 'commands' section of the manual it should tell you all you need to 
know.  I recall reading this section about six months ago and all seemed
pretty easy, but like I said I never got around to actually trying it.
-- 
+ Alan W. McKay       +  VOICE: (902) 542-1565                        +
+ Acadia University   +  "Courage my friend, it is not yet too late   +
+ WOLFVILLE, N.S.     +   to make the world a better place."          +
+ 840445m@AcadiaU.CA  +                    - Tommy Douglas            +

peter@cbmvax.commodore.com (Peter Cherna) (12/16/89)

In article <1989Dec15.042112.9582@aucs.uucp> 840445m@aucs.UUCP (Alan McKay) writes:
>In article <596@cameron.cs.duke.edu> amr@dukee.egr.duke.edu (Anthony M. Richardson) writes:
>>I've always thought the Amiga shared libraries were a nifty idea and
>>so I've decided to try and create my own library. Blink (with thei
>>
>>Tony Richardson        amr@dukee.egr.duke.edu
>
>Try 'oml' which comes with Lattice 5.0x.  It is used specifically for 
>making shared libraries.
>-- 
>+ Alan W. McKay       +  VOICE: (902) 542-1565                        +
>+ Acadia University   +  "Courage my friend, it is not yet too late   +
>+ WOLFVILLE, N.S.     +   to make the world a better place."          +
>+ 840445m@AcadiaU.CA  +                    - Tommy Douglas            +


Actually, oml is for making linked libraries, which may indeed by
shared _at_compile_time_.  Things like lc.lib, amiga.lib, and others
are like this.

However, I believe Anthony is talking about making Amiga shared libraries
that live in libs:.  There are new support features as of the 5.04 release
of Lattice that help make this easy.

Your C source modules must be compiled with the -ml switch.

If you have a function foo that takes an int and a long *, and returns
a char *, you would declare it like

char * __saveds __asm LIB_foo(register __d0 int i, register __a0 long *lptr)

The __saveds instructs Lattice to set up your data area (off A4) when
anybody calls your function.  The __asm keyword states that you intend
to specify which registers receive which parameters, as shown above.

The 'LIB_' is any prefix you care to associate with the actual names
of the functions.  You must also provide this prefix to blink.

If you wish from within your library to call one of your public functions
through the function table, you just do so, as in:

	cptr = foo(i, lptr)

In highly exceptional circumstances, you may wish to call yourself directly
(not through the table).  Then use

	cptr = LIB_foo(i, lptr)

Note that if someone SetFunctions() your library, only the former type
of call are affected.

You will also have to create an "fd" file, which typically looks like

##base MyLibBase
##bias 30
foo(i,lptr)(D0/A0)
...

##end

The ##base directive names the library base that clients of your
library will need.
The ##bias directive gives the offset to the first of your functions
(for a library, it is 30).
Your functions follow, with the parameters named in brackets, and the
registers after.  Registers are separated by "/" or by ",".  Use
"/" when in correct order for multiple moves (An/Am or Dn/Dm are ok
if n < m, An/Dm is always ok, Dm with An must use a comma, i.e. Dm,An).

Lattice's fd2pragma utility will build a pragma file you can include
so that clients may call your routines.  They'll have to declare
struct Library *MyLibBase and call OpenLibrary() to get it.
The declaration must precede the #include of your pragma file.

In order to call yourself through the library jump table, you must
also include this file.  Your own library base will be in A6, so
you should

	#define MyLibBase (struct Library *)getreg(REG_A6)

When you link, you must link with Lattice's libent.o first,
libinit.c second, and your .o files after.  As well, you provide
LIBPREFIX _LIB_ (or whatever you chose, but you'll need a leading
underscore here), and LIBFD mylib.fd (your fd file).

Also, you may use what look like global variables, and Lattice
arranges to stuff them off your library base.  In the source to
libinit.c, they imply you can initialize stuff at the appropriate
moment.  Well, a warning: DO NOT INITIALIZE ANY OF YOUR GLOBALS
IN LIBINIT.C.  If you need to do stuff upon open, add a call to
some MyOpenFunc() inside LibOpen(), and put that function in a module
other than libinit.c.

If you need stuff in your library base to be public, you'll have
to extend the MyLibrary structure in libinit.c, and figure out
how to access it.  Any globals that Lattice cares for you automatically
are placed whereever Lattice feels, and could change as you change
your source.

You should end up with a shared library.

Hope this helps.

--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.

"A friend of mine is into Voodoo Acupuncture.  You don't have to go.  You'll
just be walking down the street and ..... oooohhh, that's much better..."
     - Steven Wright

walker@sas.UUCP (Doug Walker) (12/19/89)

In article <1989Dec15.042112.9582@aucs.uucp> 840445m@aucs.UUCP (Alan McKay) writes:
>Try 'oml' which comes with Lattice 5.0x.  It is used specifically for 
>making shared libraries.  I have never used it myself but if you look in

No, oml is used for making LINK libraries.  Shared libraries (ala dos.library,
exec.library, intuition.library) are made with BLink.


  *****
=*|_o_o|\\=====Doug Walker, Software Distiller=======================
 *|. o.| ||
  | o  |//     "READY!   FIRE!   AIM!   (Software under development!)
  ======
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 

butch@fergvax.unl.edu (FERGVAX Daily Operator) (09/16/90)

	I posted a message about a month or so ago asking for any help
making a shared library for the Amiga.  I got a few responses from
people pointing to other sources, but none of those ever helped (I never
got a response about the Amiga Developer's Newsletter which supposedly
had an article on the subject).

	Anyway, if anyone who has made a library for the Amiga and would
not mind sharing the how-to's of it all, I would very much appreciate
it, since I've tried and failed on several occasions to make one.

	Also, if anyone has a copy of the Developer's Newsletter which
has the article on making libraries, I would be interested in getting a
copy (if it doesn't violate any copyright laws).  I'm not a develop so
I don't suppose I can subscribe to the newsletter (if non-developers can
subscribe, please let me know how).

Thanks in advance for any info,

Butch Rosecrans
butch@fergvax.unl.edu

lhotka@incstar.uucp (Glamdring) (09/17/90)

In article <butch.653500529@fergvax>, butch@fergvax.unl.edu (FERGVAX Daily Operator) writes:
> 	Anyway, if anyone who has made a library for the Amiga and would
> not mind sharing the how-to's of it all, I would very much appreciate
> it, since I've tried and failed on several occasions to make one.

I would second this motion - if anyone would like to post an example or
some pointers on this topic it would be very nice.  I have read through
several books and such, but it is still somewhat confusing and no one ever
seems to publish an example...

> Butch Rosecrans
> butch@fergvax.unl.edu
 ______________________________________________________________________
/ Rockford Lhotka				INCSTAR Corp	       \
| Systems Administrator				PO Box 285	       |
| incstar!lhotka@rosevax.rosemount.com		1990 Industrial Blvd   |
\ 612/779-1701					Stillwater, MN 55082   /
 ----------------------------------------------------------------------

dlarson@blake.u.washington.edu (Dale Larson) (09/18/90)

>In article <butch.653500529@fergvax>, butch@fergvax.unl.edu (FERGVAX Daily Operator) writes:
>> 	Anyway, if anyone who has made a library for the Amiga and would
>> not mind sharing the how-to's of it all, I would very much appreciate
>> it, since I've tried and failed on several occasions to make one.

Manx comes with example code and detailed instructions for the creation
and use of shared libraries.  Under 5.0 it is really easy.



--
-Dale Larson  (dlarson@blake.u.washington.edu)

valentin@cbmvax.commodore.com (Valentin Pepelea) (09/21/90)

In article <259@incstar.uucp> lhotka@incstar.uucp (Glamdring) writes:
>
>> 	Anyway, if anyone who has made a library for the Amiga and would
>> not mind sharing the how-to's of it all, I would very much appreciate
>> it, since I've tried and failed on several occasions to make one.
>
> I would second this motion - if anyone would like to post an example or
> some pointers on this topic it would be very nice.  I have read through
> several books and such, but it is still somewhat confusing and no one ever
> seems to publish an example...

You both have pointed out a weakness in the available documentation. While the
useage of shared libraries and devices is well explained, the process of
creating such beasts is covered with clarity and simplicity exemplified by
the KGB documentation bureau.

All I can do to help you out for now, it to tell you that there is nothing to
it. Shared libraries consist simply of a skeleton, along with a set of
functions that accompany them. For an assembler example, look in the ROM Kernel
Manual, Includes & Autodocs. For a C example, look in AmigaMail, page III-11.
AmigaMail is a tachnical newsletter sent by CATS (Commodore-Amiga Technical
Support) to registered devellopers.

No, I don't work for CATS.

Valentin
-- 
The Goddess of democracy? "The tyrants     Name:    Valentin Pepelea
may distroy a statue,  but they cannot     Phone:   (215) 431-9327
kill a god."                               UseNet:  cbmvax!valentin@uunet.uu.net
             - Ancient Chinese Proverb     Claimer: I not Commodore spokesman be

bcphyagi@Twg-S5.uucp (Stephen Walton) (09/22/90)

In article <14576@cbmvax.commodore.com> valentin@cbmvax.commodore.com
(Valentin Pepelea) writes:
>
>For a C example [of a shared library], look in AmigaMail, page III-11.
>AmigaMail is a tachnical newsletter sent by CATS (Commodore-Amiga Technical
>Support) to registered devellopers.

The AmigaMail article is Lattice-specific.  For a C example for Manx
5.0, look in the directory reslib on the fourth (or maybe third)
distribution floppy.  Write your subroutines, put their names in a
table in the supplied main, run Make with the example makefile, and
you're done.  The next rev of XPR Kermit (currently under development)
uses it with great success.
--
Stephen R. Walton, Dept. of Physics and Astronomy, Cal State Northridge
I am srw@csun.edu no matter WHAT the stupid From: line says!