home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 299.lha / MMU_Mon_v1.0 / MMU.asm < prev   
Encoding:
Assembly Source File  |  1980-12-04  |  6.9 KB  |  323 lines

  1. ;    MMU.asm  written by Michael R. Mossman and released to 
  2. ;    Public Domain in Oct 89.
  3.  
  4.  
  5.                CSECT text,0,,0,4
  6.                INCLUDE "exec/types.i"
  7.            INCLUDE "exec/tasks.i"
  8.        
  9.        STRUCTURE MMUM,0
  10.            ULONG MMUM_LOGICAL_ADDRESS    
  11.            ULONG MMUM_PHYSICAL_ADDRESS
  12.            LABEL MMUM_SIZE
  13.  
  14.            STRUCTURE MMU,MMUM_SIZE
  15.                ULONG MMU_UCRP
  16.                ULONG MMU_LCRP
  17.                ULONG MMU_USRP
  18.                ULONG MMU_LSRP
  19.                ULONG MMU_UDRP
  20.                ULONG MMU_LDRP
  21.                ULONG MMU_TC
  22.                UWORD MMU_AC
  23.                UWORD MMU_PSR
  24.                UWORD MMU_PCSR
  25.                UBYTE MMU_CAL
  26.                UBYTE MMU_VAL
  27.                UBYTE MMU_SCC
  28.            UBYTE MMU_BLANK
  29.                LABEL MMU_SIZE
  30.  
  31. CRP_OUT        EQU   %11110000000100000100111000000000           
  32. SRP_OUT        EQU   %11110000000100000100101000000000
  33. DRP_OUT        EQU   %11110000000100000100011000000000
  34. TC_OUT         EQU   %11110000000100000100001000000000
  35. AC_OUT         EQU   %11110000000100000101111000000000
  36. PSR_OUT        EQU   %11110000000100000110001000000000
  37. PCSR_OUT       EQU   %11110000000100000110011000000000
  38. CAL_OUT        EQU   %11110000000100000101001000000000
  39. VAL_OUT        EQU   %11110000000100000101011000000000
  40. SCC_OUT        EQU   %11110000000100000101101000000000
  41.  
  42.  
  43. CRP_IN         EQU   %11110000000100000100110000000000           
  44. SRP_IN         EQU   %11110000000100000100100000000000
  45. DRP_IN         EQU   %11110000000100000100010000000000
  46. TC_IN          EQU   %11110000000100000100000000000000
  47. AC_IN          EQU   %11110000000100000101110000000000
  48. PSR_IN         EQU   %11110000000100000110000000000000
  49. PCSR_IN        EQU   %11110000000100000110010000000000
  50. CAL_IN         EQU   %11110000000100000101000000000000
  51. VAL_IN         EQU   %11110000000100000101010000000000
  52. SCC_IN         EQU   %11110000000100000101100000000000
  53.  
  54. READ_TAB       EQU   %11110000000100001001111100110110
  55.  
  56. CALLSYS        macro  *
  57.                jsr    LVO\1(A6)
  58.            endm
  59.     
  60. P_MOVE         macro  *
  61.                CNOP  0,2
  62.                DC.l   \1
  63.            CNOP  0,2
  64.            endm
  65.  
  66. P_TEST         macro  *
  67.                CNOP  0,2
  68.                DC.l   \1
  69.            CNOP  0,2
  70.            endm
  71.  
  72.            XREF _myMMU
  73.            XDEF _Read_MMU
  74.            XDEF _Write_MMU
  75.            XDEF _Read_Table
  76.            XDEF _End
  77.            XDEF _MMU_PRESENT
  78.            XDEF _EXCEPTION
  79.  
  80.  
  81. LVOSupervisor  EQU  -30
  82. LVOFindTask    EQU  -294           
  83.            
  84. SuperVisor:
  85.                movem.l D2-D7/A2-A6,-(SP)
  86.                move.l 4,A6
  87.            jsr Test_For_MMU
  88.                move.l ADDRESS,A5
  89.            CALLSYS Supervisor
  90.            movem.l (SP)+,D2-D7/A2-A6
  91.            rts
  92.  
  93.  
  94.            
  95. _Read_MMU:
  96.            lea Read,A0
  97.            move.l A0,ADDRESS
  98.            jmp SuperVisor
  99.            
  100.            
  101. Read:           
  102.                lea _myMMU,A1
  103.                lea MMU_UCRP(A1),A0
  104.            P_MOVE CRP_OUT
  105.            lea MMU_USRP(A1),A0
  106.            P_MOVE SRP_OUT
  107.            lea MMU_UDRP(A1),A0
  108.            P_MOVE DRP_OUT
  109.            lea MMU_TC(A1),A0
  110.            P_MOVE TC_OUT
  111.            lea MMU_AC(A1),A0
  112.            P_MOVE AC_OUT
  113.            lea MMU_PSR(A1),A0
  114.            P_MOVE PSR_OUT
  115.            lea MMU_PCSR(A1),A0
  116.            P_MOVE PCSR_OUT
  117.            lea MMU_CAL(A1),A0
  118.            P_MOVE CAL_OUT
  119.            lea MMU_VAL(A1),A0
  120.            P_MOVE VAL_OUT
  121.            lea MMU_SCC(A1),A0
  122.            P_MOVE SCC_OUT
  123.            move.l #1,D0
  124.            rte
  125.            
  126.            
  127. _Write_MMU:
  128.               move.l 4(SP),OFFSET_ADD
  129.               lea Write,A0
  130.           move.l A0,ADDRESS
  131.           jmp SuperVisor
  132.           
  133. Write:
  134.               lea _myMMU,A0
  135.           exg A0,D0
  136.           move.l OFFSET_ADD,D1
  137.           move.l D1,A0
  138.           sub.l D0,D1
  139.           cmpi #MMU_UCRP,D1
  140.           bne 1$
  141.           P_MOVE CRP_IN
  142.           jmp 11$
  143.           
  144. 1$:
  145.               cmpi #MMU_USRP,D1
  146.               bne 2$
  147.           P_MOVE SRP_IN
  148.           jmp 11$                    
  149.                  
  150. 2$:    
  151.               cmpi #MMU_UDRP,D1
  152.               bne 3$
  153.           P_MOVE DRP_IN
  154.           jmp 11$
  155.           
  156.           
  157. 3$:            
  158.               cmpi #MMU_TC,D1
  159.           bne 4$
  160.           P_MOVE TC_IN
  161.           jmp 11$
  162.  
  163.  
  164. 4$:           
  165.               cmpi #MMU_AC,D1
  166.               bne 5$
  167.           P_MOVE AC_IN
  168.           jmp 11$          
  169.  
  170. 5$: 
  171.               cmpi #MMU_PSR,D1
  172.               bne 6$
  173.           P_MOVE PSR_IN
  174.           jmp 11$
  175.  
  176. 6$:
  177.               cmpi #MMU_PCSR,D1
  178.           bne 7$
  179.           P_MOVE PCSR_IN
  180.           jmp 11$    
  181.  
  182. 7$:
  183.               cmpi #MMU_CAL,D1
  184.           bne 8$
  185.           P_MOVE CAL_IN
  186.           jmp 11$          
  187.  
  188. 8$:
  189.               cmpi #MMU_VAL,D1
  190.           bne 9$
  191.           P_MOVE VAL_IN
  192.           jmp 11$
  193.  
  194.  
  195. 9$:
  196.               cmpi #MMU_SCC,D1
  197.           bne 10$
  198.           P_MOVE SCC_IN
  199.           jmp 11$
  200.  
  201. 10$:
  202.               move.l #0,D0
  203.               rte
  204.           
  205. 11$:          
  206.               move.l #1,D0
  207.           rte                    
  208.                     
  209.  
  210. _Read_Table:
  211.               jsr _Read_MMU
  212.           lea _myMMU,A0
  213.           cmpi.l #$80000000,MMU_TC(A0)
  214.           bcc 1$
  215.           move.l #0,MMUM_PHYSICAL_ADDRESS(A0)
  216.           move.l #0,D0
  217.           rts
  218. 1$          
  219.           lea Read_Table,A0
  220.           move.l A0,ADDRESS
  221.           jmp SuperVisor
  222.  
  223. Read_Table:
  224.               lea _myMMU,A1
  225.           move.l MMUM_LOGICAL_ADDRESS(A1),A0
  226.           P_TEST READ_TAB
  227.           lea _myMMU,A0
  228.           move.l A1,MMUM_PHYSICAL_ADDRESS(A0)
  229.           move.l #1,D0
  230.           rte
  231.  
  232.  
  233. Test_For_MMU:
  234.               move.l _MMU_PRESENT,D0     ;test for MMU and turn on trapping
  235.           beq  1$
  236.           rts
  237.           
  238. 1$:           
  239.               move.l 4,A6
  240.               move.l #0,A1
  241.           CALLSYS FindTask
  242.           move.l D0,A5
  243.           move.l TC_TRAPCODE(A5),A4
  244.           move.l #3$,TC_TRAPCODE(A5)
  245.           lea _myMMU,A1
  246.               lea MMU_UCRP(A1),A0
  247.           P_MOVE CRP_OUT
  248.           move.l A4,TC_TRAPCODE(A5)
  249.           move.l _MMU_PRESENT,D0
  250.           beq  2$
  251.           move.l $E0,CONFIG
  252.           move.l $E4,ILLEGAL
  253.           move.l $E8,ACCESS
  254.           lea 5$,A0
  255.           move.l A0,$E0
  256.           lea 5$,A0
  257.           move.l A0,$E4
  258.           lea 5$,A0
  259.           move.l A0,$E8
  260.           rts       
  261.  
  262. 2$:          
  263.               addq.l #4,SP
  264.           movem.l (SP)+,D2-D7/A2-A6
  265.           move.l #0,D0
  266.           rts
  267.           
  268. 3$:           
  269.               move.l (SP)+,D0
  270.           cmpi #11,D0
  271.           beq 4$
  272.           move.l #1,_MMU_PRESENT
  273.           addq.l #4,2(SP)
  274.           rte
  275.           
  276. 4$:           
  277.               addq.l #4,2(SP)
  278.           rte                    
  279.  
  280.  
  281. 5$:           
  282.               move.l D0,-(SP)    ;trap exceptions 56-58
  283.           move.l #0,D0
  284.           move.w 10(SP),D0
  285.           andi.w #$0FFF,D0
  286.           divu.w #4,D0
  287.           move.w D0,_EXCEPTION
  288.           move.l (SP)+,D0
  289.           rte
  290.  
  291.  
  292. _End:
  293.               move.l CONFIG,$E0
  294.           move.l ILLEGAL,$E4
  295.           move.l ACCESS,$E8
  296.           rts
  297.  
  298.  
  299.           
  300. OFFSET_ADD     DS.l  1    ;The offset into the MMU register structure
  301. ADDRESS        DS.l  1    ;What code is to be executed in Supervisor mode
  302. CONFIG         DS.l  1    ;Store exception vector #56
  303. ILLEGAL        DS.l  1    ;Store exception vector #57
  304. ACCESS         DS.l  1    ;Store exception vector #58
  305. _MMU_PRESENT   DC.l  0    ;Assume no MMU
  306. _EXCEPTION     DC.w  0    ;Where we keep the execption number
  307.            END           
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.