home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Devices / TradDriverLoaderLib1.0b5 / MissingLibraryRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.5 KB  |  92 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MissingLibraryRoutines.c
  3.  
  4.     Contains:    Implementation of routines missing from InterfaceLib.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. #include <Types.h>
  22.  
  23. // This file contains implementations of various Mac OS API routines
  24. // that were never rolled in to InterfaceLib.  As a result, these
  25. // routines can be called from classic 68K clients, but not from
  26. // CFM-68K or CFM-PPC clients.
  27.  
  28. extern pascal SInt16 LMGetUnitTableEntryCount(void)
  29.     // Get the value from low memory directly.
  30. {
  31.     return *((SInt16 *) 0x01d2);
  32. }
  33.  
  34. extern pascal void LMSetUnitTableEntryCount(SInt16 value)
  35.     // Put the value into low memory directly.
  36. {
  37.     *((SInt16 *) 0x01d2) = value;
  38. }
  39.  
  40. // DriverInstallReserveMem is a bit trickier to implement that the
  41. // previous two routines.  Basically we have get the address of the
  42. // _DriverInstall ($A03D) trap and then call it using
  43. // CallOSTrapUniversalProc.  There are a number of important things
  44. // to note here:
  45. //   a) We can just get the trap address and treat it as a UPP.
  46. //      The trap tables are defined to contain UPPs, either pointers
  47. //      to real 68K code, or pointers to a routine descriptor (if
  48. //      the trap is native or fat).
  49. //   b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
  50. //      CallOSTrapUniversalProc automatically does a number of things 
  51. //      that are very critical for call OS traps.  See "IM:PowerPC
  52. //      System Software", p2-42 for a full description.
  53. //   c) When calling OS traps from PPC, it's important to get the
  54. //      ProcInfo right.  Specifically, all OS traps assume an
  55. //      implicit parameter of D1 as the first parameter.  After
  56. //      that, the parameters should be defined in the order that
  57. //      they are declared in the prototype.  If you fail to get
  58. //      the order right, or to put D1 first, your code will work,
  59. //      up until it encounters someone who has patched the OS trap
  60. //      with a native or fat patch.  Then strange things will happen,
  61. //      and you'll spend hours in MacsBug trying to figure it out.
  62.  
  63. // The trap number and ProcInfo description for DriverInstallReserveMem.
  64.  
  65. enum {
  66.     _DriverInstallReserveMem = 0x0A43D
  67. };
  68.  
  69. enum {
  70.     uppDriverInstallProcInfo = kRegisterBased
  71.         | REGISTER_RESULT_LOCATION(kRegisterD0)
  72.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  73.         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
  74.         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
  75.         | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
  76. };
  77.  
  78. extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
  79. {
  80.     UniversalProcPtr trapAddress;
  81.     
  82.     // Check that I've got the ProcInfo correct.
  83.     if (false) {
  84.         if ( uppDriverInstallProcInfo != 0x00533022) {
  85.             DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
  86.         }
  87.     }
  88.     
  89.     trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
  90.     return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
  91. }
  92.