home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cl5sr386.zip / GO32 / GRPROT.ASM < prev    next >
Assembly Source File  |  1992-04-13  |  6KB  |  280 lines

  1. ; This is file GRPROT.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14.  
  15. ;    History:270,22
  16.     title    grprot
  17.     .386p
  18.  
  19.     include    build.inc
  20.     include    segdefs.inc
  21.     include tss.inc
  22.     include gdt.inc
  23.     include idt.inc
  24.  
  25. ;
  26. ;  Memory Map (relative to 0xe0000000) :
  27. ;    00000000 - 000fffff == read/write area
  28. ;    00100000 - 001fffff == read only area
  29. ;    00200000 - 002fffff == write only area
  30. ;
  31. ;  If your board can support separate read & write mappings,
  32. ;  like the TSENG chips, then either one of two cases applies:
  33. ;  1. The read and write mappings are the same, and the rw, r,
  34. ;     and w areas all have one present bank.
  35. ;  2. The read and write mappings are different, and only the
  36. ;     r and w areas have a mapped bank.  Accesses to the rw area
  37. ;     cause a page fault and the board goes back into case #1.
  38. ;
  39. ;  If your board can't support separate read & write mappings,
  40. ;  always map the rw, r, and w areas to the same page (case #1 above)
  41. ;
  42. ;  It is up to the programmer to ensure that the program doesn't
  43. ;  read from the write only area, or write to the read only area.
  44. ;
  45. ;  This method is used because you can't use the string move instructions
  46. ;  across pages.  The "movsx" instruction causes *two* memory references,
  47. ;  potentially to different banks.  The first causes one bank to be
  48. ;  enabled, and the instruction is restarted.  The second access causes
  49. ;  the second bank to be enabled, and the instruction is *RESTARTED*.
  50. ;  This means it will attempt the *first* access again, causing it to be
  51. ;  enabled, ad infinitum.
  52. ;
  53. ;  Thus, bcopy() and memcpy() shouldn't *ever* access the rw area!
  54.  
  55. ;------------------------------------------------------------------------
  56.  
  57.     start_data16
  58.  
  59.     extrn    _gr_paging_func:dword
  60.     extrn    _graphics_pt:dword
  61.     public    _graphics_pt_lin
  62. _graphics_pt_lin    dd    ?    ; filled in by paging.c
  63.  
  64. ; pointer into _graphics_pt_lin
  65. ; 0, 64, 128, . . .
  66. ; 00h, 40h, 80h, . . .
  67. ; addresses 00000h, 10000h, 20000h, . . .
  68. cur_rw        dd    0
  69. cur_r        dd    0
  70. cur_w        dd    0
  71. r_bank        db    0
  72. w_bank        db    0
  73.  
  74. mode        db    0
  75.  mode_none    equ    0
  76.  mode_rw    equ    1
  77.  mode_r_w    equ    2
  78.  
  79.     end_data16
  80.  
  81. ;------------------------------------------------------------------------
  82.  
  83.     start_code16
  84.  
  85. handlers    label    word
  86.     dw    offset handler_rw
  87.     dw    offset handler_r
  88.     dw    offset handler_w
  89.  
  90.     extrn    _page_fault:near
  91.     public    graphics_fault
  92. graphics_fault:
  93.     cli
  94.     mov    ax,g_core
  95.     mov    gs,ax
  96.  
  97.     mov    ebx,cr2
  98.     and    ebx,00f00000h
  99.     shr    ebx,19
  100.     jmp    cs:handlers[bx]
  101.  
  102. ;------------------------------------------------------------------------
  103.  
  104. handler_rw:
  105.     cmp    mode,mode_none
  106.     je    h_none_rw
  107.     cmp    mode,mode_r_w
  108.     je    h_r_w_rw
  109.  
  110.     mov    esi,_graphics_pt_lin
  111.     add    esi,cur_rw
  112.     mov    ecx,16
  113. L0:
  114.     and    byte ptr gs:[esi],0feh    ; "not present"
  115.     add    esi,4
  116.     loop    L0
  117.     jmp    h_none_rw
  118.  
  119. h_r_w_rw:
  120.     mov    esi,_graphics_pt_lin
  121.     add    esi,cur_r
  122.     mov    ecx,16
  123. L1:
  124.     and    byte ptr gs:[esi],0feh    ; "not present"
  125.     add    esi,4
  126.     loop    L1
  127.     mov    esi,_graphics_pt_lin
  128.     add    esi,cur_w
  129.     mov    ecx,16
  130. L2:
  131.     and    byte ptr gs:[esi],0feh    ; "not present"
  132.     add    esi,4
  133.     loop    L2
  134.  
  135. h_none_rw:
  136.     mov    mode,mode_rw
  137.  
  138.     mov    eax,cr2
  139.     shr    eax,10
  140.     and    eax,000003c0h
  141.     mov    cur_rw,eax
  142.  
  143.     shr    ax,6            ; al is now page number
  144.     mov    ah,al
  145.     call    [_gr_paging_func]
  146.  
  147.     mov    esi,_graphics_pt_lin
  148.     add    esi,cur_rw
  149.     mov    ecx,16
  150. L3:
  151.     or    byte ptr gs:[esi],01h    ; "present"
  152.     add    esi,4
  153.     loop    L3
  154.  
  155.     mov    eax,cr3
  156.     mov    cr3,eax
  157.  
  158.     pop    eax
  159.     iretd                ; back to running program
  160.     jmp    _page_fault
  161.  
  162. ;------------------------------------------------------------------------
  163.  
  164. handler_r:
  165.     cmp    mode,mode_none
  166.     je    h_none_r
  167.     cmp    mode,mode_rw
  168.     je    h_rw_r
  169.  
  170.     mov    esi,_graphics_pt_lin
  171.     add    esi,cur_r
  172.     mov    ecx,16
  173. L10:
  174.     and    byte ptr gs:[esi],0feh    ; "not present"
  175.     add    esi,4
  176.     loop    L10
  177.     jmp    h_none_r
  178.  
  179. h_rw_r:
  180.     mov    esi,_graphics_pt_lin
  181.     add    esi,cur_rw
  182.     mov    ecx,16
  183. L11:
  184.     and    byte ptr gs:[esi],0feh    ; "not present"
  185.     add    esi,4
  186.     loop    L11
  187.  
  188. h_none_r:
  189.     mov    mode,mode_r_w
  190.  
  191.     mov    eax,cr2
  192.     shr    eax,10
  193.     and    eax,000003c0h
  194.     mov    cur_r,eax
  195.     add    cur_r,1024        ; 1M
  196.  
  197.     shr    ax,6            ; al is now page number
  198.     mov    r_bank,al
  199.     mov    ah,al
  200.     mov    al,w_bank
  201.     call    [_gr_paging_func]
  202.  
  203.     mov    esi,_graphics_pt_lin
  204.     add    esi,cur_r
  205.     mov    ecx,16
  206. L12:
  207.     or    byte ptr gs:[esi],01h    ; "present"
  208.     add    esi,4
  209.     loop    L12
  210.  
  211.     mov    eax,cr3
  212.     mov    cr3,eax
  213.  
  214.     pop    eax
  215.     iretd                ; back to running program
  216.     jmp    _page_fault
  217.  
  218. ;------------------------------------------------------------------------
  219.  
  220. handler_w:
  221.     cmp    mode,mode_none
  222.     je    h_none_w
  223.     cmp    mode,mode_rw
  224.     je    h_rw_w
  225.  
  226.     mov    esi,_graphics_pt_lin
  227.     add    esi,cur_w
  228.     mov    ecx,16
  229. L20:
  230.     and    byte ptr gs:[esi],0feh    ; "not present"
  231.     add    esi,4
  232.     loop    L20
  233.     jmp    h_none_w
  234.  
  235. h_rw_w:
  236.     mov    esi,_graphics_pt_lin
  237.     add    esi,cur_rw
  238.     mov    ecx,16
  239. L21:
  240.     and    byte ptr gs:[esi],0feh    ; "not present"
  241.     add    esi,4
  242.     loop    L21
  243.  
  244. h_none_w:
  245.     mov    mode,mode_r_w
  246.  
  247.     mov    eax,cr2
  248.     shr    eax,10
  249.     and    eax,000003c0h
  250.     mov    cur_w,eax
  251.     add    cur_w,2048        ; 1M
  252.  
  253.     shr    ax,6            ; al is now page number
  254.     mov    w_bank,al
  255.     mov    ah,r_bank
  256.     call    [_gr_paging_func]
  257.  
  258.     mov    esi,_graphics_pt_lin
  259.     add    esi,cur_w
  260.     mov    ecx,16
  261. L23:
  262.     or    byte ptr gs:[esi],01h    ; "present"
  263.     add    esi,4
  264.     loop    L23
  265.  
  266.     mov    eax,cr3
  267.     mov    cr3,eax
  268.  
  269.     pop    eax
  270.     iretd                ; back to running program
  271.     jmp    _page_fault
  272.  
  273. ;------------------------------------------------------------------------
  274.  
  275.     end_code16
  276.  
  277. ;------------------------------------------------------------------------
  278.  
  279.     end
  280.