;*************************************************************************
;** mmu.library                                                         **
;**                                                                     **
;** a system library for arbitration and control of the MC68K MMUs      **
;**                                                                     **
;** © 1998 THOR-Software, Thomas Richter                                **
;** No commercial use, reassembly, modification without prior, written  **
;** permission of the authors.                                          **
;** Including this library in any commercial software REQUIRES a        **
;** written permission and the payment of a small fee.                  **
;**                                                                     **
;** This is an internal header file, do not depend on anything here.    **
;** Use the official include files.                                     **
;** Distributed only for the mmu.library development group for private  **
;** use.                                                                **
;**                                                                     **
;**---------------------------------------------------------------------**
;** Block: The library base                                             **
;** Definition of the library base                                      **
;*************************************************************************

;FOLD MMUConfig
;*************************************************
;** MMUConfig                                   **
;** this keeps all MMU registers                **
;*************************************************
        rsreset
mcf_userrootpointer:    rs.l 2          ;depends on MMU whether 32 or 64 bit
mcf_superrootpointer:   rs.l 2          ;ditto
mcf_translationctrl:    rs.l 1          ;translation control register
mcf_dtt0:               rs.l 1          ;transparent data translation 0
mcf_dtt1:               rs.l 1          ;transparent data translation 1
mcf_itt0:               rs.l 1          ;transparent instruction translation 0
mcf_itt1:               rs.l 1          ;transparent instruction translation 1
mcf_len:                rs.b 0
;ENDFOLD
;FOLD Library base
;*************************************************
;** Library base                                **
;** this is the MMU library base                **
;*************************************************
        rsreset
                                ;first the node structure
mulib_succ:             rs.l 1          ;pointer to next library
mulib_pred:             rs.l 1          ;to previous
mulib_type:             rs.b 1          ;NT_LIBRARY
mulib_pri:              rs.b 1          ;priority, left blank
mulib_name:             rs.l 1          ;name of the game
                                ;the exec library header
mulib_flags:            rs.b 1          ;exec library flags
mulib_pad:              rs.b 1
mulib_negsize:          rs.w 1          ;jump vectors
mulib_possize:          rs.w 1          ;positive size, i.e. size of this structure
mulib_version:          rs.w 1
mulib_revision:         rs.w 1
mulib_idstring:         rs.l 1          ;ASCII vendor identification
mulib_sum:              rs.l 1          ;checksum
mulib_opencnt:          rs.w 1          ;open count
                                ;private mmu library header follows here
mulib_MMUType:          rs.b 1          ;type of mmu detected, see below
mulib_AttnFlags:        rs.b 1          ;copy of ExecBase->AttnFlags
mulib_Flags1:           rs.l 1          ;private flags, see below

mulib_Segment:          rs.l 1          ;Library segment for unloading

                                ;Processor specific data follows here

                                ;Masks containing the valid bits of
                                ;the MMU table pointers
                                ;the root mask applies to the root level, i.e.
                                ;to the bits in the hardware MMU register

mulib_LevelAMask:       rs.l 1          ;alignment of the LevelA pointer table pointed to by the MMU URP
mulib_LevelBMask:       rs.l 1
mulib_LevelCMask:       rs.l 1
mulib_LevelDMask:       rs.l 1
mulib_IndirectMask:     rs.l 1          ;Alignment for indirect
mulib_PageMask:         rs.l 1          ;Alignment at page level

                                        ;the mask +1 is called alignment
                                        ;it is therefore the alignment of
                                        ;the object ONE LEVEL BELOW
                                        ;since at the level above only the
                                        ;bits mentioned in the mask are
                                        ;used.

mulib_LevelAAlign:      rs.l 1          ;alignment of the LevelA pointer table pointed to by the MMU URP
mulib_LevelBAlign:      rs.l 1
mulib_LevelCAlign:      rs.l 1
mulib_LevelDAlign:      rs.l 1
mulib_IndirectAlign:    rs.l 1          ;Alignment for indirect: Unused (must be four anyways)
mulib_PageSize:         rs.l 0          ;Page size choosen. Should be 4K
mulib_PageAlign:        rs.l 1          ;Alignment at page level: This is identical to the page size

mulib_InitialShift:     rs.b 1          ;Initial shift bits, only used for MC68851/MC68030
mulib_LevelABits:       rs.b 1          ;Bits for the Root Index level of the tree
mulib_LevelBBits:       rs.b 1          ;Bits for the Pointer Index level of the tree
mulib_LevelCBits:       rs.b 1          ;Bits for the Page Index level of the tree
mulib_LevelDBits:       rs.b 1          ;Bits for the Level D pointer, used only in MC68851/68030
mulib_PageBits:         rs.b 1          ;Bits for the Page Offset level of the tree

mulib_reserved1:        rs.b 2

mulib_UpperEnd:         rs.l 1          ;Total upper end of the address space (0 for 2^32)

mulib_MMUConfig:        rs.b mcf_len    ;the initial MMU configuration

                                ;vectors to other libraries
mulib_SysBase:          rs.l 1          ;ExecBase. Important!
mulib_UtilityBase:      rs.l 1          ;utility.library
mulib_ExpansionBase:    rs.l 1          ;expansion.library
mulib_040Base:          rs.l 1          ;68040.library
mulib_060Base:          rs.l 1          ;68060.library
                                ;system lists
mulib_ContextList:      rs.l 3          ;minlist of known contexts.
mulib_ContextPool:      rs.l 1          ;memory pool
                                        ;no, this is NOT exec compatible.
mulib_ContextSemaphore: rs.b $2e        ;access for the List
mulib_PoolSemaphore:    rs.b $2e        ;access for the Pool

                                ;other important pointers
mulib_CurrentContext:   rs.l 1          ;currently active context
mulib_DefaultContext:   rs.l 1          ;context for standard applications, NULL context

                                ;at this point, we start with
                                ;the internal jump vectors for
                                ;processor specific routines.
                                ;These are filled in at startup
                                ;This is CODE, and the CPU jumps
                                ;directly in here.

mulib_InternalVecs      =       7       ;four vectors have to be initialized

mulib_Internals:        rs.w 0
mulib_ReadConfig:       rs.w 3          ;Read MMU Configuration data
mulib_WriteConfig:      rs.w 3          ;Write back MMU configuration
mulib_SetLibrary:       rs.w 3          ;set the variables of the library base from the config
mulib_ParseMMU:         rs.w 3          ;build a context from the MMU table
mulib_ParseTT:          rs.w 3          ;add the transparent translation registers
mulib_EnterContext:     rs.w 3          ;Set the MMU root pointer
mulib_GetMMUData:       rs.w 3          ;Fill in processor specific data

mulib_len:              rs.b 0
;ENDFOLD
;FOLD Standard library flags definitions we care about
lib_changed     =       1
lib_sumused     =       2
lib_delexp      =       3       ;marked for expunge
lib_exp0cnt     =       4       ;special system expunge flag
;ENDFOLD
;FOLD Standard node types we care about
NT_UNKNOWN      EQU 0
NT_TASK         EQU 1   ; Exec task
NT_INTERRUPT    EQU 2
NT_DEVICE       EQU 3
NT_MSGPORT      EQU 4
NT_MESSAGE      EQU 5   ; Indicates message currently pending
NT_FREEMSG      EQU 6
NT_REPLYMSG     EQU 7   ; Message has been replied
NT_RESOURCE     EQU 8
NT_LIBRARY      EQU 9
NT_MEMORY       EQU 10
NT_SOFTINT      EQU 11  ; Internal flag used by SoftInts
NT_PROCESS      EQU 13  ; AmigaDOS Process
NT_SIGNALSEM    EQU 15  ; signal semaphores

NT_CONTEXT      EQU 32  ;A context node, private.
;ENDFOLD
;FOLD MMU types known
mutype_none     =       0       ;no mmu detected
mutype_68851    =       '2'     ;68020 mmu
mutype_68030    =       '3'     ;68030 mmu
mutype_68040    =       '4'     ;68040 mmu
mutype_68060    =       '6'     ;68060 mmu
;ENDFOLD
;FOLD Private flags in the library base
mmuf1_contextopen       =       0       ;a context is in use
;ENDFOLD
;FOLD CPU types
;I'm again too lazy to include the complete exec/execbase.i.
;Here just what I need:
AF_68010        =       0
AF_68020        =       1
AF_68030        =       2
AF_68040        =       3
AF_68060        =       7
;ENDFOLD

