home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKEMS.ASM < prev    next >
Assembly Source File  |  1990-10-12  |  5KB  |  264 lines

  1. ;
  2. ;    --- Version 2.2 90-10-12 10:38 ---
  3. ;
  4. ;    CTask - EMS support
  5. ;
  6. ;    Public Domain Software written by
  7. ;        Thomas Wagner
  8. ;        Ferrari electronic Gmbh
  9. ;        Beusselstrasse 27
  10. ;        D-1000 Berlin 21
  11. ;        Germany
  12. ;
  13. ;    This module contains the EMS interface. CTask version 2.1
  14. ;    will save and restore the EMS page map (the LIM 3.2 compatible
  15. ;    64k standard frame only) on a task switch if EMS support is 
  16. ;    installed.
  17. ;
  18. ;    If the EMS driver supports it, the LIM 4.0 save/restore
  19. ;    partial page map function is used. If this function is not
  20. ;    available, the LIM 3.2 full page map save/restore call is used,
  21. ;    provided that the space in the TCB (EMS_SAVE_SIZE) can hold
  22. ;    the page map information.
  23. ;
  24.     name    tskems
  25. ;
  26.     include    tsk.mac
  27. ;
  28.     IF    DOS AND EMS
  29. ;
  30.     .tsk_model
  31. ;
  32.     Pubfunc    tsk_install_ems
  33. ;
  34.     extrn    tsk_glob_rec: byte
  35. ;
  36. ;
  37.     .tsk_data
  38. ;
  39. emm_name    db    "EMMXXXX0"
  40. ;
  41. ems_map        dw    4
  42.         dw    4 dup(?)
  43. ;
  44. getfunc        dw    ?
  45. setfunc        dw    ?
  46. ;
  47.     .tsk_edata
  48.     .tsk_code
  49. ;
  50. ;    tsk_install_ems    installs EMS support if an EMS driver is
  51. ;    present, and saving the page map is possible.
  52. ;
  53. ;    Returns 1 is EMS installed, 0 if no driver, -1 if saving
  54. ;    is impossible.
  55. ;
  56. Localfunc tsk_install_ems,<uses si di>
  57. ;
  58.     IFDEF    LOAD_DS
  59.     push    ds
  60.     mov    ax,@CTASK_DATA
  61.     mov    ds,ax
  62.     ENDIF
  63.     xor    ax,ax
  64.     mov    es,ax
  65.     mov    es,word ptr es:[67h*4+2]
  66.     mov    di,0ah
  67.     mov    si,offset emm_name
  68.     mov    cx,8
  69.     repe cmpsb
  70.     je    ems_there
  71.     jmp    no_ems
  72. ;
  73. ;    EMS is installed, but the partial map functions failed.
  74. ;    Try the full page map save/restore, which is present in
  75. ;    LIM 3.2.
  76. ;
  77. try_32:
  78.     mov    ax,4e03h    ; get size of full page map save array
  79.     int    67h
  80.     or    ah,ah
  81.     jnz    bad_ems        ; we can't save if this fails
  82.     cmp    al,EMS_SAVE_SIZE
  83.     ja    bad_ems        ; we can't save if array too large
  84.     mov    getfunc,4e00h    ; get full map
  85.     mov    setfunc,4e01h    ; set full map
  86.     jmp    enter_ok
  87. ;
  88. bad_ems:
  89.     mov    ax,-1
  90.     jmp    inst_ems_end
  91. ;
  92. ;    EMS is installed, check if we can save a partial page
  93. ;    map in the reserved space, and if the save partial page map
  94. ;    call is implemented at all.
  95. ;
  96. ems_there:
  97.     mov    ax,4f02h    ; get size of partial page map save array
  98.     mov    bx,4        ; for the four standard pages
  99.     int    67h
  100.     or    ah,ah
  101.     jnz    try_32        ; if this call fails, we might have LIM 3.2
  102.     cmp    al,EMS_SAVE_SIZE
  103.     ja    bad_ems        ; we can't save if array too large
  104. ;
  105. ;    The partial page map call is available, and the space allocated
  106. ;    in the TCB is sufficient. Now we have to build the page table
  107. ;    for the get partial map function.
  108. ;
  109. ;    Get physical pages
  110. ;
  111.     mov    ax,5801h    ; get number of entries
  112.     int    67h
  113.     or    ah,ah
  114.     jnz    try_32        ; if this call fails, we might have LIM 3.2
  115.     mov    al,4
  116.     mul    cl        ; space required
  117.     sub    sp,ax        ; make room on stack
  118.     mov    di,sp
  119.     push    ax        ; save size
  120.     mov    ax,ss
  121.     mov    es,ax
  122.     mov    ax,5800h    ; get physical page array
  123.     int    67h
  124.     or    ah,ah
  125.     jz    phys_ok        ; if this call fails, we might have LIM 3.2
  126.     pop    ax
  127.     add    sp,ax
  128.     jmp    try_32
  129. ;
  130. ;    Find the physical page address for the first four pages
  131. ;    (the LIM 3.2 64k frame)
  132. ;
  133. phys_ok:
  134.     mov    ax,-1
  135. ;
  136. first_loop:
  137.     cmp    word ptr es:[di+2],ax    ; compare logical page number
  138.     ja    first_next        ; skip if above what we already found
  139.     mov    ax,word ptr es:[di+2]    ; the new minimum page
  140.     mov    bx,di            ; save the index
  141.     mov    dx,cx            ; and the remaining entries
  142.     or    ax,ax
  143.     jz    first_found
  144. ;
  145. first_next:
  146.     add    di,4
  147.     loop    first_loop
  148. ;
  149. ;    We found the first logical page. Now copy the physical
  150. ;    page numbers for the first four pages to the array.
  151. ;
  152. first_found:
  153.     mov    di,offset ems_map
  154.     mov    word ptr [di],4        ; four entries
  155.     add    di,2
  156.     mov    cx,4
  157. ;
  158. enter_map:
  159.     mov    ax,es:[bx]        ; physical page
  160.     mov    [di],ax            ; store in map array
  161.     add    bx,4
  162.     add    di,2
  163.     dec    cx
  164.     jz    enter_rdy
  165.     dec    dx
  166.     jnz    enter_map
  167.     mov    bx,sp            ; recycle to start of list
  168.     add    bx,2            ; SP+2 since we pushed AX
  169.     jmp    enter_map
  170. ;
  171. enter_rdy:
  172.     pop    ax
  173.     add    sp,ax
  174.     mov    getfunc,4f00h        ; get partial map
  175.     mov    setfunc,4f01h        ; set partial map
  176. ;
  177. ;    Enter the functions into the global variable block
  178. ;
  179. enter_ok:
  180.     mov    word ptr tsk_glob_rec.ems_save,offset @ems_savefn
  181.     mov    word ptr tsk_glob_rec.ems_save+2,cs
  182.     mov    word ptr tsk_glob_rec.ems_rest,offset @ems_restfn
  183.     mov    word ptr tsk_glob_rec.ems_rest+2,cs
  184.     mov    word ptr tsk_glob_rec.ems_savetsk,offset @save_ems_tsk
  185.     mov    word ptr tsk_glob_rec.ems_savetsk+2,cs
  186. ;
  187.     mov    ax,1
  188.     jmp    short inst_ems_end
  189. ;
  190. no_ems:
  191.     xor    ax,ax
  192. ;
  193. inst_ems_end:
  194.     IFDEF    LOAD_DS
  195.     pop    ds
  196.     ENDIF
  197.     ret
  198. ;
  199. tsk_install_ems    endp
  200. ;
  201. ;
  202. ;    The save and restore routines are called by the scheduler,
  203. ;    and are entered with
  204. ;        DS    = CTask data segment
  205. ;        ES:DI = TCB
  206. ;
  207. ;    ems_savefn - Save EMS context function
  208. ;
  209. @ems_savefn    proc    far
  210. ;
  211.     push    si
  212.     push    di
  213.     lea    di,t_ems_map[di]    ; destination
  214.     mov    si,offset ems_map    ; not used for full map
  215.     mov    ax,getfunc        ; get (partial) page map
  216.     int    67h
  217.     pop    di
  218.     pop    si
  219.     ret
  220. ;
  221. @ems_savefn    endp
  222. ;
  223. ;    ems_restfn - Restore EMS context function
  224. ;
  225. @ems_restfn    proc    far
  226. ;
  227.     mov    ax,setfunc        ; set (partial) page map
  228.     push    ds
  229.     push    si
  230.     mov    si,es
  231.     mov    ds,si
  232.     lea    si,t_ems_map[di]    ; source
  233.     int    67h
  234.     pop    si
  235.     pop    ds
  236.     ret
  237. ;
  238. @ems_restfn    endp
  239. ;
  240. ;    save_ems_tsk    Save current EMS context in the specified task's TCB
  241. ;
  242. @save_ems_tsk    proc    far uses di, task: far ptr
  243. ;
  244.     IFDEF    LOAD_DS
  245.     push    ds
  246.     mov    ax,@CTASK_DATA
  247.     mov    ds,ax
  248.     ENDIF
  249.     les    di,task
  250.     call    @ems_savefn
  251.     IFDEF    LOAD_DS
  252.     pop    ds
  253.     ENDIF
  254.     ret
  255. ;
  256. @save_ems_tsk    endp
  257. ;
  258.     .tsk_ecode
  259. ;
  260.     ENDIF
  261. ;
  262.     end
  263.  
  264.