home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / device / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  6.1 KB  |  261 lines

  1. /* $Id: misc.c,v 4.10 1999/09/11 08:22:23 lcs Exp $ */
  2.  
  3. /*
  4.      AHI - Hardware independent audio subsystem
  5.      Copyright (C) 1996-1999 Martin Blom <martin@blom.org>
  6.      
  7.      This library is free software; you can redistribute it and/or
  8.      modify it under the terms of the GNU Library General Public
  9.      License as published by the Free Software Foundation; either
  10.      version 2 of the License, or (at your option) any later version.
  11.      
  12.      This library is distributed in the hope that it will be useful,
  13.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.      Library General Public License for more details.
  16.      
  17.      You should have received a copy of the GNU Library General Public
  18.      License along with this library; if not, write to the
  19.      Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
  20.      MA 02139, USA.
  21. */
  22.  
  23. #include <config.h>
  24. #include <CompilerSpecific.h>
  25.  
  26. #include <exec/lists.h>
  27. #include <exec/nodes.h>
  28. #include <powerup/ppclib/memory.h>
  29. #include <powerup/ppclib/interface.h>
  30. #include <powerup/ppclib/object.h>
  31. #include <powerpc/powerpc.h>
  32. #include <powerpc/memoryPPC.h>
  33. #include <intuition/intuition.h>
  34. #include <proto/exec.h>
  35. #include <proto/intuition.h>
  36. #include <proto/ppc.h>
  37. #include <proto/powerpc.h>
  38.  
  39. #include "ahi_def.h"
  40. #include "header.h"
  41. #include "elfloader.h"
  42.  
  43.  
  44. /******************************************************************************
  45. ** Findnode *******************************************************************
  46. ******************************************************************************/
  47.  
  48. // Find a node in a list
  49.  
  50. struct Node *
  51. FindNode ( struct List *list,
  52.            struct Node *node )
  53. {
  54.   struct Node *currentnode;
  55.  
  56.   for(currentnode = list->lh_Head;
  57.       currentnode->ln_Succ;
  58.       currentnode = currentnode->ln_Succ)
  59.   {
  60.     if(currentnode == node)
  61.     {
  62.       return currentnode;
  63.     }
  64.   }
  65.   return NULL;
  66. }
  67.  
  68.  
  69. /******************************************************************************
  70. ** Fixed2Shift ****************************************************************
  71. ******************************************************************************/
  72.  
  73. // Returns host many steps to right-shift a value to approximate
  74. // scaling with the Fixed argument.
  75.  
  76. int
  77. Fixed2Shift( Fixed f )
  78. {
  79.   int   i   = 0;
  80.   Fixed ref = 0x10000;
  81.  
  82.   while( f < ref )
  83.   {
  84.     i++;
  85.     ref >>= 1;
  86.   }
  87.  
  88.   return i;
  89. }
  90.  
  91. /******************************************************************************
  92. ** Req ************************************************************************
  93. ******************************************************************************/
  94.  
  95. void
  96. Req( const char* text )
  97. {
  98.   struct EasyStruct es = 
  99.   {
  100.     sizeof (struct EasyStruct),
  101.     0,
  102.     (STRPTR) DevName,
  103.     (STRPTR) text,
  104.     "OK"
  105.   };
  106.  
  107.   EasyRequest( NULL, &es, NULL );
  108. }
  109.  
  110. /******************************************************************************
  111. ** AHIAllocVec ****************************************************************
  112. ******************************************************************************/
  113.  
  114. APTR
  115. AHIAllocVec( ULONG byteSize, ULONG requirements )
  116. {
  117. #ifndef VERSION68K
  118.   if( PPCLibBase != NULL )
  119.   {
  120.     return PPCAllocVec( byteSize, requirements );
  121.   }
  122.   else if( PowerPCBase != NULL )
  123.   {
  124.     ULONG new_requirements;
  125.  
  126.     new_requirements = requirements & ~MEMF_PPCMASK;
  127.  
  128.     if( requirements & MEMF_WRITETHROUGHPPC )
  129.       new_requirements |= MEMF_WRITETHROUGH;
  130.  
  131.     if( requirements & MEMF_NOCACHEPPC )
  132.       new_requirements |= MEMF_CACHEOFF;
  133.       
  134.     if( requirements & MEMF_NOCACHESYNCPPC )
  135.       new_requirements |= ( MEMF_CACHEOFF | MEMF_GUARDED );
  136.  
  137.     if( requirements & MEMF_NOCACHESYNCM68K )
  138.       new_requirements |= MEMF_CHIP;            // Sucks!
  139.  
  140.     return AllocVec32( byteSize, new_requirements );
  141.   }
  142.   else
  143. #endif
  144.   {
  145.     return AllocVec( byteSize, requirements & ~MEMF_PPCMASK );
  146.   }
  147. }
  148.  
  149. /******************************************************************************
  150. ** AHIFreeVec *****************************************************************
  151. ******************************************************************************/
  152.  
  153. void
  154. AHIFreeVec( APTR memoryBlock )
  155. {
  156. #ifndef VERSION68K
  157.   if( PPCLibBase != NULL )
  158.   {
  159.     PPCFreeVec( memoryBlock );
  160.   }
  161.   else if( PowerPCBase != NULL )
  162.   {
  163.     FreeVec32( memoryBlock );
  164.   }
  165.   else
  166. #endif
  167.   {
  168.     FreeVec( memoryBlock );
  169.   }
  170. }
  171.  
  172.  
  173. /******************************************************************************
  174. ** AHILoadObject **************************************************************
  175. ******************************************************************************/
  176.  
  177. #ifndef VERSION68K
  178.  
  179. void*
  180. AHILoadObject( const char* objname )
  181. {
  182.   if( PPCLibBase != NULL )
  183.   {
  184.     return PPCLoadObject( (char*) objname );
  185.   }
  186.   else
  187.   {
  188. //kprintf( "loading elf object\n" );
  189.     return ELFLoadObject( objname );
  190.   }
  191. }
  192.  
  193. #endif
  194.  
  195. /******************************************************************************
  196. ** AHIUnLoadObject ************************************************************
  197. ******************************************************************************/
  198.  
  199. #ifndef VERSION68K
  200.  
  201. void
  202. AHIUnLoadObject( void* obj )
  203. {
  204.   if( PPCLibBase != NULL )
  205.   {
  206.     PPCUnLoadObject( obj );
  207.   }
  208.   else
  209.   {
  210. //kprintf( "unloading elf object\n" );
  211.     ELFUnLoadObject( obj );
  212.   }
  213. }
  214.  
  215. #endif
  216.  
  217. /******************************************************************************
  218. ** AHIGetELFSymbol ************************************************************
  219. ******************************************************************************/
  220.  
  221. #ifndef VERSION68K
  222.  
  223. BOOL
  224. AHIGetELFSymbol( const char* name,
  225.                  void** ptr )
  226. {
  227.   BOOL rc = FALSE;
  228.  
  229. //kprintf( "getting symbol %s: ", name );
  230.   if( PPCLibBase != NULL )
  231.   {
  232.     struct PPCObjectInfo oi =
  233.     {
  234.       0,
  235.       NULL,
  236.       PPCELFINFOTYPE_SYMBOL,
  237.       STT_SECTION,
  238.       STB_GLOBAL,
  239.       0
  240.     };
  241.  
  242.     struct TagItem tag_done =
  243.     {
  244.       TAG_DONE, 0
  245.     };
  246.  
  247.     oi.Name = (char*) name;
  248.     rc = PPCGetObjectAttrs( PPCObject, &oi, &tag_done );
  249.     *ptr = (void*) oi.Address;
  250.   }
  251.   else
  252.   {
  253.     rc = ELFGetSymbol( PPCObject, name, ptr );
  254.   }
  255.  
  256. //kprintf( "%08lx (%ld)\n", *ptr, rc );
  257.   return rc;
  258. }
  259.  
  260. #endif
  261.