*       LibFunc.p
*
*       Part of the Storm-PowerASM tutorial
*
*       A small PPC program which demonstrates how to create
*       a shared library function
*
*       © 1997 HAAGE&PARTNER Computer GmbH

                include exec/types.i
                include exec/libraries.i

                STRUCTURE       DUMMYLIB,LN_SIZE        ;private library struct
                APTR            DUMMYLIB_LINKERDB


                XREF    _LinkerDB

                XDEF    Function1               ;export function addresses
                XDEF    Function2



Function1
                prolog  4096,,TOC               ;create stackframe and save r2
                lwz     base,DUMMYLIB_LINKERDB(r3) ;evaluate our own r2
                ls      f2,PI                   ;load PI into f2
                fadd    f2,f2,f2                ;2*PI
                ls      f3,_360                 ;load 360 into f3
                fdivs   f1,f1,f3                ;angle / 360
                fmuls   f1,f1,f2                ;result = 2*PI * angle / 360
                epilog  TOC                     ;remove stackframe and restore r2


Function2
                prolog  4096,,TOC               ;create stackframe and save r2
                bl      .label                  ;branch to .label
                dc.l    _LinkerDB               ;Pointer to Smalldata-Base
.label
                mflr    r3                      ;get Address of _LinkerDB
                lwz     base,0(r3)              ;get _LinkerDB and put it into r2
                ls      f2,PI                   ;load PI into f2
                fadd    f2,f2,f2                ;2*PI
                ls      f3,_360                 ;load 360 into f3
                fdivs   f1,f1,f3                ;angle / 360
                fmuls   f1,f1,f2                ;result = 2*PI * angle / 360
                epilog  TOC                     ;remove stackframe and restore r2


                section data
PI              dc.s    3.14159265358979
_360            dc.s    360
