

				  TECH.DOC

			   AutoInitalize Sections

    The startup code (dlib:c.o) creates two code sections named 'autoinit'
    and 'autoexit'.  The end-tag file (dlib:x.o) generates an RTS for each
    of these sections.	Note that normally DCC automatically puts c.o and x.o
    in the dlink line, as well as dlib:c.lib and dlib:amiga.lib

    The linker guarentees that ordering is maintained within a section.  Thus,
    any autoinit or autoexit sections you specify inbetween are automatically
    coagulated together.  The result is that you can include code, usually
    something of the order:

	xdef	_My_Dummy_Label

	section autoinit,code

_My_Dummy_Label
	jsr _MySpecialInitCode
	nop

	section autoexit,code

	jsr _MySpecialExitCode
	nop

	END

    DAS automatically pads code sections with NOPs.  If you are not using DAS
    (and I do NOT suggest you use DAS for any assembly projects, it is not a
    real assembler), then be sure your autoinit and autoexit sections are
    long word aligned because you WANT the code to fall through to the
    next module's autoinit/autoexit section... propogating through until
    DLIB:X.O's rts is hit.

    The autoinit section is called *before* __main (_main() in C), thus
    stdio and level 1 IO have NOT been setup yet.

    The autoexit section is called *after* _exit but before __exit (that is,
    it is the first thing DLIB.C.O/__exit calls).  At this point all files
    and file descriptors have been closed, but memory allocation will still
    work.

    The idea behind autoinit is simple:  Some routine of yours references some
    other routine in a library of yours and you want this reference to
    automatically cause a third, independant module to be included in the
    autoinit/autoexit by virtual of your library routine referencing a dummy
    label in said section, like this:

    extern long &My_Dummy_Label     ; not really a long
    static long Dummy = &My_Dummy_Label


			       REAL-LIFE EXAMPLE

    So, for example, you can have autoinit code automatically open and
    close libraries if you wish, like this (in A68K, DAS can't handle strings):

			; autoinit code to deal with intuition.library

			section bss,bss

    _IntuitionBase	ds.l	1

			section autoinit,code

			moveq.l #0,D0		    ; 2
			move.l	D0,-(sp)            ; 2
			pea	lname		    ; 6 CAN'T USE (pc) here!
			jsr	_OpenLibrary(pc)    ; 4
			addq.l	#8,sp		    ; 2
						    ; 16, no nop required

			section autoexit,code

			move.l	_IntuitionBase,-(sp)    ; 6
			beq.b	l10			; 2
			jsr	_CloseLibrary(pc)       ; 4
    l10 		addq.l	#4,sp			; 2
			nop				; 2 NOP, lw align.

			section const,code

    lname		dc.b	'intuition.library',0

			END


    Note that you cannot use pc-relative to reference a string in the code
    section (we could have put it in the data section, by the way, but it
    is never modified so no reason to).  If the IntuitionBase variable is
    ever referenced anywhere else then this autoinit/exit code will be
    included to automatically open/close the library.



