home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02057b < prev    next >
Text File  |  1991-01-02  |  6KB  |  240 lines

  1.  
  2. COMMENT #
  3. ------------------------------------------------------
  4.         FILE   -  RELOCATE.ASM
  5.  
  6.   Relocate the Process File Handle Table to the area
  7.   defined within this module (new_table).  This will allow
  8.   the number of handles for this process to be expanded up
  9.   to 255.  The equate NEW_TABLE_SIZE defined below should
  10.   be adjusted to reflect the application specific handle
  11.   requirements.
  12.  
  13.   Written for Microsoft MASM 5.x to interface with
  14.   Microsoft C 5.x.
  15.  
  16.   Module Contents:
  17.         void relocate_pfht(void);       -  public
  18.         void find_pfht(void);           -  local
  19.         void init_new_pfht(void);       -  local
  20.         void copy_old_to_new(void);     -  local
  21.         void update_pfht_count(void);   -  local
  22.         void update_pfht_addr(void);    -  local
  23.  
  24.   NOTE:
  25.     The function find_pfht() makes use of two PSP fields
  26.     (PFHT_ADDR and PFHT_COUNT) which are present only in
  27.     DOS versions 3.0 and higher.
  28. ------------------------------------------------------
  29. END OF COMMENT #
  30.  
  31. .model small            ;memory model directive
  32.  
  33. ;                  --- MACROS ---
  34.  
  35. ;push selected registers
  36. apush   macro   a,b,c,d,e,f,g,h
  37.         irp x,<a,b,c,d,e,f,g,h>
  38.         ifnb <x>
  39.         push    x
  40.         endif
  41.         endm
  42.         endm
  43.  
  44. ;pop selected registers
  45. apop    macro   a,b,c,d,e,f,g,h
  46.         irp x,<h,g,f,e,d,c,b,a>
  47.         ifnb <x>
  48.         pop     x
  49.         endif
  50.         endm
  51.         endm
  52.  
  53.  
  54. ;                  --- EQUATES ---
  55.  
  56. ; --- this equate should be adjusted to the number of
  57. ;     file/device handles required by your application.
  58. NEW_TABLE_SIZE          equ     30
  59.  
  60. ; --- offset within the PSP of the dword pointer to the
  61. ;     PFHT
  62. PFHT_ADDR               equ     34h
  63.  
  64. ; --- offset within the PSP of the word containing the
  65. ;     number of elements in the PFHT
  66. PFHT_COUNT              equ     32h
  67.  
  68. ; --- an unused PFHT entry will contain 0ffh
  69. FOXES                   equ     0ffh
  70.  
  71.  
  72. ;                  --- DATA ---
  73. .data
  74.  
  75. ; --- this is the data area for the expanded PFHT
  76. public _new_table
  77. _new_table       db      NEW_TABLE_SIZE dup(0);
  78.  
  79. ; --- declare MSC global variable containing the PSP
  80. ;     segment address
  81. extrn           __psp:word
  82.  
  83.  
  84.  
  85. ;                  --- CODE ---
  86. .code
  87.  
  88. ;----------------------------------------------
  89. ; void relocate_pfht(void);
  90. ;       Move the current PFHT to the area allocated in the
  91. ;       data segment above.
  92. ; TRASHES:
  93. ;       AX
  94. ;----------------------------------------------
  95. public _relocate_pfht
  96. _relocate_pfht proc
  97.         apush   ds,si,es,di,cx
  98.         call    find_pfht
  99.         call    init_new_pfht
  100.         call    copy_old_to_new
  101.         call    update_pfht_count
  102.         call    update_pfht_addr
  103.         apop    ds,si,es,di,cx
  104.         ret
  105. _relocate_pfht endp
  106.  
  107.  
  108. ;----------------------------------------------
  109. ; local void find_pfht(void)
  110. ;       setup registers with the current PFHT, the
  111. ;       new PFHT and the size of the current PFHT.
  112. ; NOTE:
  113. ;       Uses the global variable __psp defined and
  114. ;       initialized by MSC startup code.
  115. ; RETURNS:
  116. ;       DS:SI pointing to the current PFHT
  117. ;       ES:DI pointing to the new, expanded PFHT
  118. ;       CX    size of the current PFHT
  119. ; TRASHES:
  120. ;       AX
  121. ;----------------------------------------------
  122. find_pfht proc
  123. ; --- address the MSC data segment
  124.         mov     ax,DGROUP
  125.         mov     ds,ax
  126. assume ds:DGROUP
  127.  
  128. ; --- get the offset of the new table
  129.         lea     di,_new_table
  130.  
  131. ; --- get the segment of the new table into es
  132.         mov     ax,seg _new_table
  133.         mov     es,ax
  134.  
  135. ; --- get the segment of the PSP in ds
  136.         mov     ds,[__psp]
  137. assume ds:nothing
  138.  
  139. ; --- load cx with the current PFHT count
  140.         mov     cx,word ptr ds:[PFHT_COUNT]
  141.  
  142. ; --- address of current PFHT into ds:si
  143.         lds     si,ds:[PFHT_ADDR]
  144.         ret
  145. find_pfht endp
  146.  
  147.  
  148.  
  149. ;----------------------------------------------
  150. ; local void init_new_pfht(void)
  151. ;       initialize the new PFHT to 0FFh.
  152. ; PRESERVES:
  153. ;       DI and CX
  154. ; TRASHES:
  155. ;       AX
  156. ;----------------------------------------------
  157. init_new_pfht proc
  158.         apush   di,cx
  159.  
  160. ; --- get the new table size
  161.         mov     cx,NEW_TABLE_SIZE
  162.  
  163. ; --- load al with 0FFh
  164.         mov     al,FOXES
  165.  
  166. ; --- move 0FFh into every byte of the table
  167.         repnz   stosb
  168.  
  169.         apop    di,cx
  170.         ret
  171. init_new_pfht endp
  172.  
  173.  
  174.  
  175. ;----------------------------------------------
  176. ; local void copy_old_to_new(void)
  177. ;       Copies the contents of the current PFHT to the new
  178. ;       PFHT.
  179. ; ON ENTRY:  DS:SI points to current PFHT
  180. ;            ES:DI points to new, expanded PFHT
  181. ;            CX    contains the number of entries (bytes)
  182. ;                  in the current PFHT
  183. ; PRESERVES: DI
  184. ; TRASHES:   CX
  185. ;----------------------------------------------
  186. copy_old_to_new proc
  187. ; --- save the offset of the new table
  188.         push    di
  189.         repnz   movsb
  190.         pop     di
  191.         ret
  192. copy_old_to_new endp
  193.  
  194.  
  195.  
  196. ;----------------------------------------------
  197. ; local void update_pfht_count(void)
  198. ;       Update the PFHT Count contained in the PSP to
  199. ;       reflect the size of the new table.
  200. ; ON ENTRY:  DS    segment of PSP
  201. ; TRASHES:
  202. ;            AX, SI
  203. ;----------------------------------------------
  204. update_pfht_count proc
  205. ; --- load the size of the new table
  206.         mov     ax,NEW_TABLE_SIZE
  207.  
  208. ; --- point to the count word and store the new count
  209.         mov     si,PFHT_COUNT
  210.         mov     word ptr [si], ax
  211.         ret
  212. update_pfht_count endp
  213.  
  214.  
  215.  
  216. ;----------------------------------------------
  217. ; local void update_pfht_addr(void)
  218. ;       Update the pointer to the PFHT contained in the PSP
  219. ;       to point to the new PFHT.
  220. ; ON ENTRY:  ES:DI points to the new, expanded PFHT
  221. ;            DS    segment of PSP
  222. ; TRASHES:
  223. ;            SI
  224. ;----------------------------------------------
  225. update_pfht_addr proc
  226. ; --- point to the lo word of the address
  227.         mov     si,PFHT_ADDR
  228.  
  229. ; --- store the offset of the new table
  230.         mov     [si],di
  231.  
  232. ; --- store the segment of the table
  233.         mov     [si+2],es
  234.         ret
  235. update_pfht_addr endp
  236.  
  237.  
  238. end
  239.  
  240.