home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d04xx / d0400.lha / SetCPU / other.a < prev    next >
Text File  |  1990-11-03  |  5KB  |  178 lines

  1. ;======================================================================
  2. ;
  3. ;    SetCPU V1.60
  4. ;    by Dave Haynie, April 13, 1990
  5. ;    Released to the Public Domain
  6. ;
  7. ;    OTHER.A MODULE
  8. ;
  9. ;    This module contains miscellaneous assembly functions that just
  10. ;    didn't seem to fit in elsewhere.
  11. ;
  12. ;======================================================================
  13.  
  14.     include "setcpu.i"
  15.  
  16.     cseg
  17.  
  18. ;**********************************************************************
  19. ;
  20. ;    Some useful MMU functions.
  21. ;
  22. **********************************************************************
  23.  
  24.     xdef    _SetMMUTag    ; Sets up MMU from systag
  25.     xdef    _FlushATC    ; Flush MMU address translation cache
  26.  
  27. ;======================================================================
  28. ;
  29. ;    This function cleanly sets up a new MMU context.  It accepts a
  30. ;    valid systag, and will first go to Supervisor more, turn off
  31. ;    the current MMU setup, then set CRP and finally TC.  The reason
  32. ;    this call is needed is that we need the OS alive to get to
  33. ;    Supervisor mode.  Setting up a new MMU context would normally
  34. ;    take three calls to Supervisor(), one to turn off the MMU
  35. ;    (ROM dies...), two to set first the new CRP and then the new
  36. ;    TC.
  37. ;
  38. ;    void SetMMUTag(struct systag *tag)
  39. ;
  40. ;======================================================================
  41.  
  42. _SetMMUTag:
  43.     move.l    4(sp),a0        ; Get the systag where we can use it
  44.     move.l    4,a6            ; Get ExecBase
  45.     movem.l    a2/a5,-(sp)
  46.     move.l    a0,a2
  47.     lea.l    1$,a5            ; Get the start of the supervisor code
  48.      CALLSYS    Supervisor
  49.     movem.l    (sp)+,a2/a5        ; Give back registers
  50.     rts
  51. 1$
  52.     lea.l    TAG_TC(a2),a0        ; Get TC register
  53.     lea.l    TAG_CRP_0(a2),a1    ; Get CRP register
  54.  
  55.     and.l    #$7fffffff,(a0)        ; Turn off MMU
  56.     PMOVE_    (a0),tc    
  57.     or.l    #$80000000,(a0)
  58.     PMOVE_    (a1),crp        ; Load up the CRP value
  59.     PMOVE_    (a0),tc            ; MMU goes back on
  60.     rte
  61.  
  62. ;======================================================================
  63. ;
  64. ;    This function flushes the MMU Address Translation Cache.
  65. ;
  66. ;    void FlushATC(void)
  67. ;
  68. ;======================================================================
  69.  
  70. _FlushATC:
  71.     move.l    4,a6            ; Get ExecBase
  72.     move.l    a5,-(sp)
  73.     lea.l    1$,a5            ; Get the start of the supervisor code
  74.     CALLSYS    Supervisor
  75.     movem.l    (sp)+,a5        ; Give back registers
  76.     rts
  77. 1$
  78.     PFLUSHA_            ; Flush the ATC
  79.     rte
  80.  
  81. ;**********************************************************************
  82. ;
  83. ;    This section contains the keyboad patch routine.
  84. ;
  85. ;**********************************************************************
  86.  
  87.     xdef    _KeyCode    ; Start of the keyboard patch
  88.     xdef    _KeyCodeSize    ; Size of the keyboard patch
  89.     xdef    _SetKeyDelay    ; Set keyboard count parameter
  90.  
  91. ;======================================================================
  92. ;
  93. ;    This is the keyboard delay patch routine. 
  94. ;
  95. ;======================================================================
  96.  
  97. KeyCode:
  98.     movem.l    d0/d1,-(sp)
  99. KeyOpt:
  100.     move.l    #12345678,d0
  101. 1$    move.w    ANYCREG,d1
  102.     subq.l    #1,d0
  103.     bne    1$
  104.     movem.l    (sp)+,d0/d1
  105.     rts
  106. KeyCodeEnd:
  107.  
  108. ;======================================================================
  109. ;
  110. ;    This function programs the patch delay value.
  111. ;
  112. ;    void SetKeyDelay(ULONG)
  113. ;
  114. ;======================================================================
  115.  
  116. _SetKeyDelay:
  117.     move.l    4(sp),d0        ; Get the delay value
  118.     lea    KeyOpt,a0        ; Get the location
  119.     move.l    d0,2(a0)        ; Set the value
  120.     rts
  121.  
  122. _KeyCode:
  123.     dc.l    KeyCode
  124. _KeyCodeSize:
  125.     dc.l    KeyCodeEnd-KeyCode+1
  126.  
  127. ;**********************************************************************
  128. ;
  129. ;    This section contains the items used for the exception handler.
  130. ;
  131. ;**********************************************************************
  132.  
  133.     xdef    _BerrCode    ; Start of the trap routine
  134.     xdef    _BerrCodeSize    ; Size of the trap routine
  135.  
  136. ;======================================================================
  137. ;
  138. ;    This is the exception handler for Bus Errors (level 2).  User
  139. ;    code that misbehaves when the MMU is on can result in such an
  140. ;    exception.  While the code needs to be fixed if this happens, 
  141. ;    it's very possible that the code is not depending on it's random
  142. ;    action; especially in the case of an accidental write to ROM
  143. ;    space, which is harmless on a normally configured machine.
  144. ;    This routine is never directly called by SetCPU.  Instead, it's
  145. ;    copied into memory that's allocated as permanent by SetCPU.
  146. ;
  147. ;======================================================================
  148.  
  149. STATUS    EQU    $0a+4
  150.  
  151. SR_DF    EQU    8
  152.  
  153. BerrTrapCode:
  154.     move.l    d0,-(sp)        ; Save d0...
  155.     move.w    STATUS(sp),d0        ; Fetch exception status register
  156.  
  157.     bclr.l    #SR_DF,d0        ; Clear the data fault bit
  158. repair:
  159.     move.w    d0,STATUS(sp)        ; Fix the status word
  160. done:
  161.     move.l    (sp)+,d0
  162.     rte
  163.  
  164. BerrTrapEnd:
  165.  
  166. ;======================================================================
  167. ;
  168. ;    These give us the size and location of the Bus Error Code.
  169. ;
  170. ;======================================================================
  171.  
  172. _BerrCode:
  173.     dc.l    BerrTrapCode
  174. _BerrCodeSize:
  175.     dc.l    BerrTrapEnd-BerrTrapCode+1
  176.  
  177.     end
  178.