Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.4 KiB

  1. page ,132
  2. ;----------------------------Module-Header------------------------------;
  3. ; Module Name: FLAT.ASM
  4. ;
  5. ; init/term routines for using flat pointers
  6. ;
  7. ; LocalAlloc should go through here!
  8. ;
  9. ;-----------------------------------------------------------------------;
  10. .286
  11. ?PLM=1
  12. ?WIN=0
  13. .xlist
  14. include cmacros.inc
  15. .list
  16. ;--------------------------------------------------------------------------;
  17. ;--------------------------------------------------------------------------;
  18. sBegin Data
  19. public flatBase
  20. public flatSel
  21. flatSel dw 0
  22. flatBase dd 0
  23. KernelLocalAlloc dd 0
  24. sEnd
  25. ifndef SEGNAME
  26. SEGNAME equ <_TEXT>
  27. endif
  28. createSeg %SEGNAME, CodeSeg, word, public, CODE
  29. sBegin CodeSeg
  30. assumes cs,CodeSeg
  31. assumes ds,Data
  32. assumes es,nothing
  33. externFP GetSelectorBase ; in KERNEL
  34. externFP SetSelectorBase ; in KERNEL
  35. externFP GetSelectorLimit ; in KERNEL
  36. externFP SetSelectorLimit ; in KERNEL
  37. externFP GlobalWire ; in KERNEL
  38. externFP GlobalUnwire ; in KERNEL
  39. externFP GlobalFix ; in KERNEL
  40. externFP GlobalUnfix ; in KERNEL
  41. ; externFP KernelLocalAlloc ; in KERNEL
  42. externFP GetProcAddress ; in KERNEL
  43. externFP GetModuleHandle ; in KERNEL
  44. externFP AllocSelector ; in KERNEL
  45. externFP FreeSelector ; in KERNEL
  46. ;--------------------------------------------------------------------------;
  47. ;
  48. ; FlatInit
  49. ;
  50. ;--------------------------------------------------------------------------;
  51. cProc FlatInit, <FAR, PUBLIC, PASCAL>
  52. cBegin
  53. ; cCall GlobalWire, <ds>
  54. cCall GlobalFix, <ds>
  55. cCall AllocSelector,<ds>
  56. mov [flatSel],ax
  57. mov bx,ax
  58. mov ax,0008h ; DPMI Set Limit
  59. mov cx,-1
  60. mov dx,-1
  61. int 31h
  62. ; cCall SetSelectorLimit,<ax,-1,-1>
  63. cCall GetSelectorBase, <ds>
  64. mov word ptr flatBase[0],ax
  65. mov word ptr flatBase[2],dx
  66. cEnd
  67. ;--------------------------------------------------------------------------;
  68. ;
  69. ; FlatTerm
  70. ;
  71. ;--------------------------------------------------------------------------;
  72. cProc FlatTerm, <FAR, PUBLIC, PASCAL>
  73. cBegin
  74. cCall SetSelectorLimit,<[flatSel],0,0>
  75. cCall FreeSelector,<[flatSel]>
  76. ; cCall GlobalUnwire, <ds>
  77. cCall GlobalUnfix, <ds>
  78. mov word ptr [flatBase][0],0
  79. mov word ptr [flatBase][2],0
  80. mov [flatSel],0
  81. cEnd
  82. ;--------------------------------------------------------------------------;
  83. ;
  84. ; LocalAlloc
  85. ;
  86. ;--------------------------------------------------------------------------;
  87. szKernel: db "KERNEL",0
  88. cProc LocalAlloc, <FAR, PUBLIC, PASCAL>
  89. ParmW flags
  90. ParmW bytes
  91. cBegin
  92. mov ax,word ptr [KernelLocalAlloc][0]
  93. or ax,word ptr [KernelLocalAlloc][2]
  94. jnz @f
  95. lea ax,szKernel
  96. cCall GetModuleHandle,<cs,ax>
  97. cCall GetProcAddress,<ax, 0, 5>
  98. mov word ptr [KernelLocalAlloc][0],ax
  99. mov word ptr [KernelLocalAlloc][2],dx
  100. @@: mov ax,word ptr [flatBase][0]
  101. or ax,word ptr [flatBase][2]
  102. pushf
  103. jz @f
  104. cCall FlatTerm
  105. @@: cCall KernelLocalAlloc, <flags, bytes>
  106. popf
  107. jz @f
  108. push ax
  109. cCall FlatInit
  110. pop ax
  111. @@:
  112. cEnd
  113. ;--------------------------------------------------------------------------;
  114. ;
  115. ; MapFlat - convert a 16:16 pointer into a 0:32 pointer
  116. ;
  117. ; note this function assumes the memory will *not* move
  118. ; while being accessed. If this is not true call GlobalFix
  119. ; on the memory
  120. ;
  121. ; INPUT:
  122. ; ptr16 16:16 pointer to map flat.
  123. ;
  124. ; OUTPUT:
  125. ; dx:ax flat pointer
  126. ;
  127. ;--------------------------------------------------------------------------;
  128. assumes ds,Data
  129. assumes es,nothing
  130. cProc MapFlat, <NEAR>
  131. ParmD ptr16
  132. cBegin
  133. mov ds,[flatSel]
  134. push word ptr ptr16[2]
  135. cCall GetSelectorBase
  136. add ax,word ptr ptr16[0]
  137. adc dx,0
  138. sub ax,word ptr flatBase[0]
  139. sbb dx,word ptr flatBase[2]
  140. cEnd
  141. sEnd
  142. end