home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / M2V11-1.LHA / modula / amiga / Expansion.def < prev    next >
Encoding:
Text File  |  1993-11-10  |  16.2 KB  |  424 lines

  1. DEFINITION FOR LIBRARY MODULE Expansion ;
  2.  
  3. FROM SYSTEM IMPORT STRING, ADDRESS, SHORTSET, BYTE, LONGSET ;
  4. FROM Exec   IMPORT Node, Library, List ;
  5. FROM Dos    IMPORT DeviceNodePtr ;
  6.  
  7. (* AutoConfig (tm) hardware register and bit definitions *)
  8.  
  9. (* AutoConfig (tm) boards each contain a 32 byte "ExpansionRom" area that is  *)
  10. (* read by the system software at configuration time.  Configuration of each  *)
  11. (* board starts when the ConfigIn* signal is passed from the previous board   *)
  12. (* (or from the system for the first board).  Each board will present it's    *)
  13. (* ExpansionRom structure at location $00E80000 to be read by the system.     *)
  14. (* This file defines the appearance of the ExpansionRom area.              *)
  15. (*                                          *)
  16. (* Expansion boards are actually organized such that only one nybble per      *)
  17. (* 16 bit word contains valid information.  The low nybbles of each          *)
  18. (* word are combined to fill the structure below. (This table is structured   *)
  19. (* as LOGICAL information.  This means that it never corresponds exactly      *)
  20. (* with a physical implementation.)                          *)
  21. (*                                          *)
  22. (* The ExpansionRom space is further split into two regions:  The first 16    *)
  23. (* bytes are read-only.  Except for the er_type field, this area is inverted  *)
  24. (* by the system software when read in.  The second 16 bytes contain the      *)
  25. (* control portion, where all read/write registers are located.              *)
  26. (*                                          *)
  27. (* The system builds one "ConfigDev" structure for each board found.  The     *)
  28. (* list of boards can be examined using the expansion.library/FindConfigDev   *)
  29. (* function.                                      *)
  30. (*                                          *)
  31. (* A special "hacker" Manufacturer ID number is reserved for test use:          *)
  32. (* 2011 ($7DB).  When inverted this will look like $F824.              *)
  33.  
  34. TYPE
  35.   ExpansionRomPtr = POINTER TO ExpansionRom ;
  36.   ExpansionRom = RECORD          (* -First 16 bytes of the expansion ROM     *)
  37.     er_Type        : SHORTSET  ; (* Board type, size and flags              *)
  38.     er_Product        : SHORTCARD ; (* Product number, assigned by manufacturer *)
  39.     er_Flags        : SHORTSET  ; (* Flags                      *)
  40.     er_Reserved03   : SHORTCARD ; (* Must be zero ($ff inverted)          *)
  41.     er_Manufacturer : CARDINAL  ; (* Unique ID,ASSIGNED BY COMMODORE-AMIGA!   *)
  42.     er_SerialNumber : LONGINT   ; (* Available for use by manufacturer          *)
  43.     er_InitDiagVec  : CARDINAL  ; (* Offset to optional "DiagArea" structure  *)
  44.     er_Reserved0c   : SHORTCARD ;
  45.     er_Reserved0d   : SHORTCARD ;
  46.     er_Reserved0e   : SHORTCARD ;
  47.     er_Reserved0f   : SHORTCARD ;
  48.   END ;
  49.  
  50. (* Note that use of the ec_BaseAddress register is tricky.  The system       *)
  51. (* will actually write twice.  First the low order nybble is written       *)
  52. (* to the ec_BaseAddress register+2 (D15-D12).    Then the entire byte is    *)
  53. (* written to ec_BaseAddress (D15-D8).    This allows writing of a byte-wide *)
  54. (* address to nybble size registers.                       *)
  55.  
  56. TYPE
  57.   ExpansionControlPtr = POINTER TO ExpansionControl ;
  58.   ExpansionControl = RECORD    (* -Second 16 bytes of the expansion ROM     *)
  59.     ec_Interrupt  : SHORTSET  ;    (* Optional interrupt control register         *)
  60.     ec_Z3_HighBase: SHORTCARD ; (* Zorro III   : Config address bits 24-31   *)
  61.     ec_BaseAddress: SHORTCARD ; (* Zorro II/III: Config address bits 16-23   *)
  62.     ec_Shutup     : SHORTCARD ;    (* The system writes here to shut up a board *)
  63.     ec_Reserved14 : SHORTCARD ;
  64.     ec_Reserved15 : SHORTCARD ;
  65.     ec_Reserved16 : SHORTCARD ;
  66.     ec_Reserved17 : SHORTCARD ;
  67.     ec_Reserved18 : SHORTCARD ;
  68.     ec_Reserved19 : SHORTCARD ;
  69.     ec_Reserved1a : SHORTCARD ;
  70.     ec_Reserved1b : SHORTCARD ;
  71.     ec_Reserved1c : SHORTCARD ;
  72.     ec_Reserved1d : SHORTCARD ;
  73.     ec_Reserved1e : SHORTCARD ;
  74.     ec_Reserved1f : SHORTCARD ;
  75.  END ;
  76.  
  77. (* many of the constants below consist of a triplet of equivalent       *)
  78. (* definitions: xxMASK is a bit mask of those bits that matter.           *)
  79. (* xxBIT is the starting bit number of the field.  xxSIZE is the       *)
  80. (* number of bits that make up the definition.    This method is           *)
  81. (* used when the field is larger than one bit.                   *)
  82. (*                                       *)
  83. (* If the field is only one bit wide then the xxB_xx and xxF_xx convention *)
  84. (* is used (xxB_xx is the bit number, and xxF_xx is mask of the bit).       *)
  85.  
  86. (* manifest constants *)
  87.  
  88. CONST
  89.   E_SLOTSIZE    = 010000H ;
  90.   E_SLOTMASK    = 0FFFFH ;
  91.   E_SLOTSHIFT    = 16 ;
  92.  
  93. (* these define the free regions of Zorro memory space.        *)
  94. (* THESE MAY WELL CHANGE FOR FUTURE PRODUCTS!            *)
  95.  
  96. CONST
  97.   E_EXPANSIONBASE    = 000E80000H ;    (* Zorro II  config address    *)
  98.   EZ3_EXPANSIONBASE    = 0FF000000H ;    (* Zorro III config address    *)
  99.  
  100.   E_EXPANSIONSIZE    = 000080000H ;    (* Zorro II  I/O type cards    *)
  101.   E_EXPANSIONSLOTS    = 8 ;
  102.  
  103.   E_MEMORYBASE        = 000200000H ;    (* Zorro II  8MB space        *)
  104.   E_MEMORYSIZE        = 000800000H ;
  105.   E_MEMORYSLOTS        = 128 ;
  106.  
  107.   EZ3_CONFIGAREA    = 040000000H ;    (* Zorro III space        *)
  108.   EZ3_CONFIGAREAEND    = 07FFFFFFFH ;    (* Zorro III space        *)
  109.   EZ3_SIZEGRANULARITY    = 000080000H ;    (* 512K increments        *)
  110.  
  111.  
  112.  
  113. (**** er_Type definitions (ttldcmmm) ***************************************)
  114.  
  115. (* er_Type board type bits -- the OS ignores "old style" boards *)
  116. CONST
  117.   ERT_TYPEMASK        = {6,7} ;    (* Bits 7-6 *)
  118.   ERT_TYPEBIT        = 6 ;
  119.   ERT_TYPESIZE        = 2 ;
  120.   ERT_NEWBOARD        = SHORTSET( 0C0H ) ;
  121.   ERT_ZORROII        = ERT_NEWBOARD ;
  122.   ERT_ZORROIII        = SHORTSET( 080H ) ;
  123.  
  124. (* other bits defined in er_Type *)
  125.   ERTB_MEMLIST        = 5 ;   (* Link RAM into free memory list *)
  126.   ERTB_DIAGVALID    = 4 ;   (* ROM vector is valid *)
  127.   ERTB_CHAINEDCONFIG    = 3 ;   (* Next config is part of the same card *)
  128.  
  129.   ERTF_MEMLIST        = {5} ;
  130.   ERTF_DIAGVALID    = {4} ;
  131.   ERTF_CHAINEDCONFIG    = {3} ;
  132.  
  133. (* er_Type field memory size bits *)
  134.   ERT_MEMMASK        = {0..2} ;    (* Bits 2-0 *)
  135.   ERT_MEMBIT        = 0 ;
  136.   ERT_MEMSIZE        = 3 ;
  137.  
  138.  
  139. (**** er_Flags byte -- for those things that didn't fit into the type byte ****)
  140. (**** the hardware stores this byte in inverted form               ****)
  141.  
  142.   ERFF_MEMSPACE        = {7} ;    (* Wants to be in 8 meg space.        *)
  143.   ERFB_MEMSPACE        =  7  ;    (* (NOT IMPLEMENTED)            *)
  144.  
  145.   ERFF_NOSHUTUP        = {6} ;    (* Board can't be shut up        *)
  146.   ERFB_NOSHUTUP        =  6  ;
  147.  
  148.   ERFF_EXTENDED        = {5} ;    (* Zorro III: Use extended size table    *)
  149.   ERFB_EXTENDED        =  5  ;    (*          for bits 0-2 of er_Type    *)
  150.                 (* Zorro II : Must be 0            *)
  151.  
  152.   ERFF_ZORRO_III    = {4} ;    (* Zorro III: must be 1            *)
  153.   ERFB_ZORRO_III    =  4  ;    (* Zorro II : must be 0            *)
  154.  
  155.   ERT_Z3_SSMASK        = {0..3};(* Bits 3-0.  Zorro III Sub-Size.  How  *)
  156.   ERT_Z3_SSBIT        =  0 ;     (* much space the card actually uses    *)
  157.   ERT_Z3_SSSIZE        =  4 ;     (* (regardless of config granularity)   *)
  158.                  (* Zorro II : must be 0         *)
  159.  
  160.  
  161. (* ec_Interrupt register (unused) ********************************************)
  162.  
  163.   ECIB_INTENA        = 1 ;
  164.   ECIB_RESET        = 3 ;
  165.   ECIB_INT2PEND        = 4 ;
  166.   ECIB_INT6PEND        = 5 ;
  167.   ECIB_INT7PEND        = 6 ;
  168.   ECIB_INTERRUPTING    = 7 ;
  169.  
  170.   ECIF_INTENA        = {1} ;
  171.   ECIF_RESET        = {3} ;
  172.   ECIF_INT2PEND        = {4} ;
  173.   ECIF_INT6PEND        = {5} ;
  174.   ECIF_INT7PEND        = {6} ;
  175.   ECIF_INTERRUPTING    = {7} ;
  176.  
  177. (*==========================================================================*)
  178. (*                                        *)
  179. (* these are the specifications for the diagnostic area.  If the Diagnostic *)
  180. (* Address Valid bit is set in the Board Type byte (the first byte in       *)
  181. (* expansion space) then the Diag Init vector contains a valid offset.        *)
  182. (*                                        *)
  183. (* The Diag Init vector is actually a word offset from the base of the        *)
  184. (* board.  The resulting address points to the base of the DiagArea        *)
  185. (* structure.  The structure may be physically implemented either four,     *)
  186. (* eight, or sixteen bits wide.  The code will be copied out into        *)
  187. (* ram first before being called.                        *)
  188. (*                                        *)
  189. (* The da_Size field, and both code offsets (da_DiagPoint and da_BootPoint) *)
  190. (* are offsets from the diag area AFTER it has been copied into ram, and    *)
  191. (* "de-nibbleized" (if needed).  (In other words, the size is the size of   *)
  192. (* the actual information, not how much address space is required to        *)
  193. (* store it.)                                    *)
  194. (*                                        *)
  195. (* All bits are encoded with uninverted logic (e.g. 5 volts on the bus        *)
  196. (* is a logic one).                                *)
  197. (*                                        *)
  198. (* If your board is to make use of the boot facility then it must leave        *)
  199. (* its config area available even after it has been configured.  Your        *)
  200. (* boot vector will be called AFTER your board's final address has been        *)
  201. (* set.                                        *)
  202. (*                                        *)
  203. (*==========================================================================*)
  204.  
  205. TYPE
  206.   DiagAreaPtr = POINTER TO DiagArea ;
  207.   DiagArea = RECORD
  208.     da_Config      : SHORTSET ;    (* see below for definitions              *)
  209.     da_Flags      : SHORTSET ;    (* see below for definitions              *)
  210.     da_Size       : CARDINAL ;    (* the size (in bytes) of the total diag area *)
  211.     da_DiagPoint  : CARDINAL ;    (* where to start for diagnostics, or zero    *)
  212.     da_BootPoint  : CARDINAL ;    (* where to start for booting              *)
  213.     da_Name      : CARDINAL ;    (* offset in diag area where a string          *)
  214.                 (*   identifier can be found (or zero if no   *)
  215.                 (*   identifier is present).              *)
  216.  
  217.     da_Reserved01 : CARDINAL ;    (* two words of reserved data.    must be zero. *)
  218.     da_Reserved02 : CARDINAL ;
  219.   END ;
  220.  
  221. (* da_Config definitions *)
  222. (* DAC_BYTEWIDE can be simulated using DAC_NIBBLEWIDE. *)
  223.  
  224. CONST
  225.   DAC_BUSWIDTH     = SHORTSET( 0C0H ) ; (* two bits for bus width              *)
  226.   DAC_NIBBLEWIDE = SHORTSET( 000H ) ;
  227.   DAC_BYTEWIDE     = SHORTSET( 040H ) ; (*BUG:Will not work under V34 Kickstart!*)
  228.   DAC_WORDWIDE     = SHORTSET( 080H ) ;
  229.  
  230.   DAC_BOOTTIME     = SHORTSET( 030H ) ; (* two bits for when to boot          *)
  231.   DAC_NEVER     = SHORTSET( 000H ) ; (* obvious                  *)
  232.   DAC_CONFIGTIME = SHORTSET( 010H ) ; (* call da_BootPoint when first          *)
  233.                         (*  configing the device              *)
  234.   DAC_BINDTIME     = SHORTSET( 020H ) ; (* run when binding drivers to boards   *)
  235.  
  236. (* These are the calling conventions for the diagnostic callback    *)
  237. (* (from da_DiagPoint):                            *)
  238. (*                                    *)
  239. (* A7 -- points to at least 2K of stack                    *)
  240. (* A6 -- ExecBase                            *)
  241. (* A5 -- ExpansionBase                            *)
  242. (* A3 -- your board's ConfigDev structure                *)
  243. (* A2 -- Base of diag/init area that was copied                *)
  244. (* A0 -- Base of your board                        *)
  245. (*                                    *)
  246. (* Your board must return a value in D0.  If this value is NULL, then    *)
  247. (* the diag/init area that was copied in will be returned to the free    *)
  248. (* memory pool.                                *)
  249.  
  250. (* At early system startup time, one ConfigDev structure is created for      *)
  251. (* each board found in the system.  Software may seach for ConfigDev         *)
  252. (* structures by vendor & product ID number.  For debugging and diagnostic   *)
  253. (* use, the entire list can be accessed.  See the expansion.library document *)
  254. (* for more information.                             *)
  255.  
  256. TYPE
  257.   ConfigDevPtr = POINTER TO ConfigDev ;
  258.   ConfigDev = RECORD
  259.     cd_Node     : Node ;
  260.     cd_Flags     : SHORTSET ;    (* (read/write)                *)
  261.     cd_Pad     : SHORTCARD ;    (* reserved                *)
  262.     cd_Rom     : ExpansionRom;(* copy of board's expansion ROM    *)
  263.     cd_BoardAddr : ADDRESS ;    (* where in memory the board was placed *)
  264.     cd_BoardSize : LONGINT ;    (* size of board in bytes        *)
  265.     cd_SlotAddr  : CARDINAL ;    (* which slot number (PRIVATE)        *)
  266.     cd_SlotSize  : CARDINAL ;    (* number of slots (PRIVATE)        *)
  267.     cd_Driver    : ADDRESS ;    (* pointer to node of driver        *)
  268.     cd_NextCD     : ConfigDevPtr;(* linked list of drivers to config    *)
  269.     cd_Unused     : ARRAY [0..3] OF LONGINT ;
  270.                     (* for whatever the driver wants    *)
  271.   END ;
  272.  
  273. (* cd_Flags *)
  274. CONST
  275.   CDB_SHUTUP    = 0 ;    (* this board has been shut up            *)
  276.   CDB_CONFIGME    = 1 ;    (* this board needs a driver to claim it    *)
  277.   CDB_BADMEMORY    = 2 ;    (* this board contains bad memory        *)
  278.   CDB_PROCESSED    = 3 ;    (* private flag                    *)
  279.  
  280.   CDF_SHUTUP    = {0} ;
  281.   CDF_CONFIGME    = {1} ;
  282.   CDF_BADMEMORY    = {2} ;
  283.   CDF_PROCESSED    = {3} ;
  284.  
  285. (* Boards are usually "bound" to software drivers.            *)
  286. (* This structure is used by GetCurrentBinding() and SetCurrentBinding()*)
  287.  
  288. TYPE
  289.   CurrentBindingPtr = POINTER TO CurrentBinding ;
  290.   CurrentBinding = RECORD
  291.     cb_ConfigDev    : ConfigDevPtr ; (* first configdev in chain    *)
  292.     cb_FileName        : STRING ;     (* file name of driver        *)
  293.     cb_ProductString    : STRING ;     (* product # string        *)
  294.     cb_ToolTypes    : POINTER TO ARRAY OF STRING ;
  295.                          (* tooltypes from disk object  *)
  296.   END ;
  297.  
  298. CONST
  299.   EXPANSIONNAME    = "expansion.library" ;
  300.  
  301. (* flags for the AddDosNode() call *)
  302.   ADNB_STARTPROC =  0  ;
  303.   ADNF_STARTPROC = {0} ;
  304.  
  305.  
  306. (* BootNodes are scanned by dos.library at startup.  Items found on the
  307.    list are started by dos. BootNodes are added with the AddDosNode() or
  308.    the V36 AddBootNode() calls. *)
  309.  
  310. TYPE
  311.   BootNodePtr = POINTER TO BootNode ;
  312.   BootNode = RECORD
  313.     bn_Node      : Node ;
  314.     bn_Flags      : BITSET ;
  315.     bn_DeviceNode : ADDRESS ;
  316.   END ;
  317.  
  318.  
  319. (* expansion.library has functions to manipulate most of the information in
  320.    ExpansionBase.  Direct access is not permitted.  Use FindConfigDev()
  321.    to scan the board list. *)
  322.  
  323.   ExpansionBasePtr = POINTER TO ExpansionBaseRec ;
  324.   ExpansionBaseRec = RECORD
  325.     LibNode     : Library ;
  326.     Flags     : SHORTSET ;        (* read only (see below)        *)
  327.     eb_Private01 : SHORTCARD ;        (* private                *)
  328.     eb_Private02 : LONGINT ;        (* private                *)
  329.     eb_Private03 : LONGINT ;        (* private                *)
  330.     eb_Private04 : CurrentBinding ;    (* private                *)
  331.     eb_Private05 : List ;        (* private                *)
  332.     MountList     : List ;        (* contains struct BootNode entries *)
  333.     (* private *)
  334.   END ;
  335.  
  336. VAR
  337.   ExpansionBase : ExpansionBasePtr ;
  338.  
  339. (* error codes *)
  340. CONST
  341.   EE_OK         =  0 ;
  342.   EE_LASTBOARD     = 40 ; (* could not shut him up           *)
  343.   EE_NOEXPANSION = 41 ; (* not enough expansion mem; board shut up *)
  344.   EE_NOMEMORY     = 42 ; (* not enough normal memory           *)
  345.   EE_NOBOARD     = 43 ; (* no board at that address           *)
  346.   EE_BADMEM     = 44 ; (* tried to add bad memory card           *)
  347.  
  348. (* Flags *)
  349.  
  350.   EBB_CLOGGED     =  0  ; (* someone could not be shutup  *)
  351.   EBF_CLOGGED     = {0} ;
  352.   EBB_SHORTMEM     =  1  ; (* ran out of expansion mem     *)
  353.   EBF_SHORTMEM     = {1} ;
  354.   EBB_BADMEM     =  2  ; (* tried to add bad memory card *)
  355.   EBF_BADMEM     = {2} ;
  356.   EBB_DOSFLAG     =  3  ; (* reserved for use by AmigaDOS *)
  357.   EBF_DOSFLAG     = {3} ;
  358.   EBB_KICKBACK33 =  4  ; (* reserved for use by AmigaDOS *)
  359.   EBF_KICKBACK33 = {4} ;
  360.   EBB_KICKBACK36 =  5  ; (* reserved for use by AmigaDOS *)
  361.   EBF_KICKBACK36 = {5} ;
  362.  
  363. (* If the following flag is set by a floppy's bootblock code, the initial
  364.    open of the initial shell window will be delayed until the first output
  365.    to that shell.  Otherwise the 1.3 compatible behavior applies. *)
  366.  
  367.   EBB_SILENTSTART =  6  ;
  368.   EBF_SILENTSTART = {6} ;
  369.  
  370. (* Magic kludge for CC0 use *)
  371.  
  372.   EBB_START_CC0      =  7  ;
  373.   EBF_START_CC0      = {7} ;
  374.  
  375. (*--- functions in V33 or higher (Release 1.2) ---*)
  376.  
  377. PROCEDURE AddConfigDev( configDev : ConfigDevPtr ) ;
  378.  
  379. (*--- functions in V33 or higher (Release 1.2) ---*)
  380.  
  381. PROCEDURE AllocBoardMem( slotSpec : LONGINT ) ;
  382. PROCEDURE AllocConfigDev( ) : ConfigDevPtr ;
  383. PROCEDURE AllocExpansionMem( numSlots,slotAlign : LONGINT ) : ADDRESS ;
  384. PROCEDURE ConfigBoard( board : ADDRESS ; configDev : ConfigDevPtr ) ;
  385. PROCEDURE ConfigChain( baseAddr : ADDRESS ) ;
  386.  
  387. PROCEDURE FindConfigDev( oldConfigDev : ConfigDevPtr ;
  388.              manufacturer, product : LONGINT ) : ConfigDevPtr ;
  389.  
  390. PROCEDURE FreeBoardMem( startSlot , slotSpec : LONGINT );
  391. PROCEDURE FreeConfigDev( configDev : ConfigDevPtr ) ;
  392. PROCEDURE FreeExpansionMem( startSlot, numSlots : LONGINT ) ;
  393. PROCEDURE ReadExpansionByte( board : ADDRESS ; offset : LONGINT ) : BYTE ;
  394. PROCEDURE ReadExpansionRom( board : ADDRESS ; configDev : ConfigDevPtr ) ;
  395. PROCEDURE RemConfigDev( configDev : ConfigDevPtr ) ;
  396.  
  397. PROCEDURE WriteExpansionByte( board  : ADDRESS ;
  398.                   offset : LONGINT ;
  399.                   byte   : BYTE ) ;
  400.  
  401. PROCEDURE ObtainConfigBinding( ) ;
  402. PROCEDURE ReleaseConfigBinding( ) ;
  403.  
  404. PROCEDURE SetCurrentBinding( cb : CurrentBindingPtr ;
  405.                  bindingSize : LONGINT ) ;
  406.  
  407. PROCEDURE GetCurrentBinding( cb : CurrentBindingPtr ;
  408.                  bindingSize : LONGINT ) : LONGINT ;
  409.  
  410. PROCEDURE MakeDosNode( parmPacket : ADDRESS ) : DeviceNodePtr ;
  411.  
  412. PROCEDURE AddDosNode( bootPri    : LONGINT ;
  413.               flags      : LONGSET ;
  414.               deviceNode : DeviceNodePtr ) : BOOLEAN ;
  415.  
  416. (*--- functions in V36 or higher (Release 2.0) ---*)
  417.  
  418. PROCEDURE AddBootNode( bootPri      : LONGINT ;
  419.                flags      : LONGSET ;
  420.                deviceNode : DeviceNodePtr ;
  421.                configDev  : ConfigDevPtr ) : BOOLEAN ;
  422.  
  423. END Expansion.
  424.