ssmisc.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:9k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. page ,132
  2. TITLE ssmisc - Scan Miscellaneous opcodes
  3. ;***
  4. ;ssmisc - Scan Miscellaneous opcodes
  5. ;
  6. ; Copyright <C> 1986, Microsoft Corporation
  7. ;
  8. ;Purpose:
  9. ;
  10. ;   This module contains miscellaneous scan utilities.
  11. ;
  12. ;
  13. ;****************************************************************************
  14. .xlist
  15. include version.inc
  16. SSMISC_ASM = ON
  17. IncludeOnce conint
  18. IncludeOnce context
  19. IncludeOnce qbimsgs 
  20. IncludeOnce ssint
  21. IncludeOnce txtmgr
  22. IncludeOnce variable
  23. .list
  24. ; .sall
  25. assumes DS, DATA
  26. assumes es, NOTHING
  27. assumes ss, DATA
  28. subttl Static data area definitons.
  29. sBegin SCAN
  30. assumes cs, SCAN
  31. subttl Scan Table Access Routines
  32. page
  33. ;***
  34. ;GetRuleInfo
  35. ;Purpose:
  36. ; Fetch the rule byte and word for this opcode.
  37. ;Input:
  38. ; bx = opcode
  39. ;Output:
  40. ; ax = rule byte
  41. ; bx = rule word
  42. ; PSW.C set iff high bit in mpOpRule set
  43. ;Preserves:
  44. ; all
  45. ;****************************************************************
  46. public GetRuleInfo
  47. GetRuleInfo:
  48. mov bl,mpOpRule[bx] ;Load rule table offset
  49. xor bh,bh ;To byte offset
  50. mov al,tRuleByte[bx] ;Load rule byte
  51. cbw
  52. shl bl,1 ;To word offset
  53. mov bx,tRuleWord[bx] ;Load rule word
  54. ret
  55. subttl Scan Stack Access Routines
  56. page
  57. ;***
  58. ;FindFrame
  59. ;Purpose:
  60. ; Return the address of the the requested frame type, if one exists.
  61. ;
  62. ;Input:
  63. ; ax = Frame identifier for structure entry.
  64. ;
  65. ;Output:
  66. ; bx = address of frame (if PSW.NZ)
  67. ; PSW.Z set if no such structure found.
  68. ;
  69. ;Modifies:
  70. ; none
  71. ;Preserves:
  72. ; ax
  73. ;**********************************************************************
  74. public FindFrame
  75. FindFrame:
  76. push ax
  77. mov bx,sp
  78. add bx,4 ;Back over push and ret address
  79. EnsureFrameLoop:
  80. mov cx,[bx] ;Load frame identifier
  81. cmp cx,STYP_StackEnd ;Test for end of stack
  82. jz EnsureFrameX ;End of stack - exit
  83. test cx,ax ;Test for block of requested type
  84. jnz EnsureFrameX ;Frame found - exit
  85. call CbFrameSTYPCx ;Map STYP in cx to cbFrame in cx
  86. add bx,cx ;Move to next frame
  87. jmp short EnsureFrameLoop ;Loop to check next frame
  88. EnsureFrameX:
  89. pop ax
  90. ret
  91. ;***
  92. ;CbFrameSTYPCx
  93. ;Purpose:
  94. ; Map a frame id to the number of bytes in that frame type.
  95. ;
  96. ; Frame sizes are based on the high byte of the id word.
  97. ; The type bit is converted to an index into an array of
  98. ; frame sizes.  The conversion is performed by shifting the
  99. ; frame id high byte until the single bit indicating the frame
  100. ; type is found.
  101. ;
  102. ;Input:
  103. ; cx = frame id
  104. ;
  105. ;Output:
  106. ; cx = count of bytes in the input frame type
  107. ;
  108. ;Preserves:
  109. ; all
  110. ;*******************************************************************
  111. mcbSTYP LABEL WORD
  112. dw SIZE FIF ;IF
  113. dw SIZE FIF ;ELSE
  114. dw SIZE FFOR  ;FOR
  115. dw SIZE FIF ;DefFn frame same as IF
  116. dw SIZE FDO ;DO
  117. dw SIZE FDO ;WHILE frame is identical to DO frame
  118. dw SIZE FCASE ;CASE
  119. public CbFrameSTYPCx
  120. CbFrameSTYPCx:
  121. push bx
  122. mov bx,-2
  123. CbCountSTYPLoop:
  124. inc bx
  125. inc bx
  126. shr ch,1
  127. jnb CbCountSTYPLoop
  128. mov cx,[bx].mcbSTYP
  129. pop bx
  130. ret
  131. subttl Execution Procedure Frame Allocation
  132. page
  133. ;***
  134. ;SsAllocOFrame - allocate an oFrame for a frame resident variable
  135. ;Purpose:
  136. ; Allocate an oFrame for a frame resident variable.
  137. ; If the oFrame is already allocated then that allocation is honored.
  138. ;
  139. ; Note that this means the allocation is always successful.
  140. ;
  141. ; prsCur contains information about the current frame
  142. ; allocation.  
  143. ;    PRS_cbFrameVars is the start of the last allocated frame variable.
  144. ;
  145. ;Input:
  146. ; ds:bx = pVar of a frame variable that may or may not have an oFrame
  147. ;Output:
  148. ; none
  149. ;Preserves:
  150. ; all
  151. ;**********************************************************************
  152. .errnz 4 - SIZE DM ;Power of two multiply used below
  153. public SsAllocOFrame
  154. SsAllocOFrame:
  155. DbChk PVar,bx ;Verify that this is a variable
  156. push ax
  157. push bx
  158. push cx
  159. push dx
  160. mov dx,[bx].VAR_Flags ;[3] Load flags word from variable
  161. mov cx,dx
  162. and cx,FV_TYP_MASK ;Get oTyp from flags word
  163. jnz @F
  164. mov cx,[bx].VAR_oTyp ;Load data type from variable
  165. @@:
  166. add bx,VAR_value ;Move to value entry
  167. test dx,FVARRAY ; Is this an array?
  168. jz AllocOFrameNotArray ;Not an array
  169. add bx,AFRAME_oFrame ;Move to oFrame for arrays
  170. mov al,[bx-AFRAME_oFrame].AFRAME_cDims ;Dimension count
  171. xor ah,ah
  172. shl ax,1
  173. shl ax,1 ;4 bytes per dimension
  174. add ax,(SIZE AD) - 1 ;AD has a one byte field that
  175. ;overlaps the first dimension info
  176. cmp word ptr [bx],0 ;Already allocated?
  177. jz SsAllocAryOrSimple
  178. AllocOFrameNotArray:
  179. cmp word ptr [bx],0 ;Already allocated?
  180. jnz SsAllocOFrameX ;Already allocated
  181. mov ax,cx ;Map data type..
  182. call CbTypOTypSCAN ; to data byte count.
  183. PadLength:
  184. inc ax
  185. and ax,not 1 ;Round up to even
  186. js StackOverflow ; Variable size is > 32767 bytes
  187. jz AllocFS  ; Brif fixed string or text
  188. TestX dx,FVFUN ;Function return value?
  189. jnz     SetRetVal_OBP         ; add var offset and set oBP
  190. ;Bump cbFrameVars by the size of the current variable.
  191. SsAllocAryOrSimple:
  192. add ax,PrsCur.PRS_cbFrameVars ;Increment cb frame variables
  193.   ; and temporaries
  194. jo StackOverflow
  195. mov prsCur.PRS_cbFrameVars,ax ;Save updated size
  196. SetOBP:
  197. neg ax ;To be subtracted from bp
  198. SetHandle:
  199. mov [bx],ax ;Set oFrame for current var
  200. SsAllocOFrameX:
  201. pop dx
  202. pop cx
  203. pop bx
  204. pop ax
  205. ret
  206. AllocFS:
  207. mov ax,[bx].VAR_cbFixed ; Length of fixed variable
  208. DbAssertRel ax,ne,0,SCAN,<SsAllocOFrame: VAR_cbFixed is 0>
  209. jmp short PadLength  ; Go back and pad
  210. SetRetVal_OBP:
  211. add ax,-FR_FirstVar ; account for offset to first var
  212. jmp short SetOBP
  213. StackOverflow:
  214. mov ax,MSG_OutOfStack
  215. call SsError 
  216. jmp short SsAllocOFrameX
  217. subttl control structure binding helpers
  218. page
  219. ;BindExitCur,BindExit - bind chain of EXIT entries
  220. ;Purpose:
  221. ; Walk a linked list of EXIT addresses and bind them to
  222. ; the passed oTx. This is used by ENDIF, NEXT, LOOP, and
  223. ; WEND scan routines.
  224. ;
  225. ;Input:
  226. ; bx = oTx of start of EXIT chain (terminated by UNDEFINED)
  227. ; cx = oTx to bind EXIT chain to.
  228. ;
  229. ;Output:
  230. ; none.
  231. ;
  232. ;Preserves:
  233. ; dx
  234. public BindExit, BindExitCur
  235. BindExitCur:
  236. mov cx,di ;bind to current emit address
  237. BindExit:
  238. cmp bx,UNDEFINED ;Test for end of list
  239. jz BindX ; and exit - end of EXIT list
  240. mov ax,PTRTX[bx] ;Get the next link
  241. mov PTRTX[bx],cx ;Bind this ref
  242. xchg ax,bx ;Next link to bx
  243. jmp short BindExit ;Go check for another link in the chain.
  244. BindX:
  245. ret
  246. ;***
  247. ;CbTypOTypSCAN, CbTypOTypOMrsSCAN
  248. ;Purpose:
  249. ; This routine returns the number of bytes of data required for
  250. ; the input type.
  251. ;
  252. ; Copied directly from varmgr as part of revision [7].
  253. ;
  254. ; CbTypOTyp assumes that if the oTyp is a user-defined type, it is
  255. ; in the type table for the current mrs
  256. ; CbTypOTypOMrs uses the MRS_bdlVar table in the mrs whose oMrs is
  257. ; given in bx.
  258. ;Input:
  259. ; ax = oTyp
  260. ; for CbTypOTypOMrs, bx = oMrs of type table
  261. ;Output:
  262. ; ax = cbTyp, or 0 if oTyp == ET_FS or ET_FT
  263. ; PSW flags set based on an OR AX,AX
  264. ;Prserves:
  265. ; all (even bx)
  266. ; ES is preserved.  NOTE: for FV_SBSWAP, it is assumed that the ES to be
  267. ; preserved is the text table.
  268. ;***************************************************************************
  269. assumes DS, NOTHING ;can be called with DS != SS
  270. mpCbTyp label byte
  271. .erre ET_IMP EQ ($-mpCbTyp)
  272. DB 0 ;ET_IMP hole
  273. .erre ET_I2 EQ ($-mpCbTyp)
  274. DB 2 ;ET_I2
  275. .erre ET_I4 EQ ($-mpCbTyp)
  276. DB 4 ;ET_I4
  277. .erre ET_R4 EQ ($-mpCbTyp)
  278. DB 4 ;ET_R4
  279. .erre ET_R8 EQ ($-mpCbTyp)
  280. DB 8 ;ET_R8
  281. .erre ET_SD EQ ($-mpCbTyp)
  282. DB SIZE SD  ;ET_SD
  283. .erre ET_FS EQ ($-mpCbTyp)
  284. DB 0 ;ET_FS - - - can't tell size from ET_ type
  285. .erre ET_MAX EQ ($-mpCbTyp-1)
  286. public CbTypOTypOMrsSCAN
  287. public CbTypOTypSCAN
  288. CbTypOTypOMrsSCAN   PROC    NEAR
  289. push bx
  290. jmp short CbTypOTyp_Cont
  291. CbTypOTypSCAN:
  292. push bx
  293. mov bx,[grs.GRS_oMrsCur]
  294. DbChk oTyp,ax  ;sanity check on input oTyp
  295. CbTypOTyp_Cont:
  296. cmp ax,ET_MAX ;Is it a fundamental type?
  297. ja NotPredefinedType ;  brif not - user defined
  298. mov bx,offset mpCbTyp ;base of lookup table in CS
  299. xlat byte ptr cs:[bx] ;al == desired size
  300. pop bx
  301. or ax,ax ;set PSW flags
  302. ret
  303. NotPredefinedType:
  304. PUSH_ES  ;preserve for caller
  305. test [conFlags],F_CON_StaticStructs
  306. jz Mrs_In_Table ;brif mrsCur not set up
  307. cmp bx,[grs.GRS_oMrsCur]
  308. jz Want_MrsCur ;brif passed oMrs is for mrsCur
  309. Mrs_In_Table:
  310. push si
  311. RS_BASE add,bx ;bx points into Rs table
  312. GETRS_SEG es,si,<SPEED,LOAD> ; get seg of Rs table, trashing si
  313. pop si
  314. jmp short Got_pMrs
  315. Want_MrsCur: ;ax is an offset into type table
  316. lea bx,mrsCur ;  found in the current mrs
  317. SETSEG_EQ_SS es
  318. Got_pMrs:
  319. add ax,PTRRS[bx.MRS_bdVar.BD_pb] ;ax = pTyp
  320. xchg bx,ax ;bx = oTyp, ax = garbage
  321. mov ax,[bx].TYP_cbData ;ax = cbData from type table entry
  322. POP_ES
  323. pop bx
  324. or ax,ax ;set PSW flags
  325. ret
  326. CbTypOTypOMrsSCAN   ENDP
  327. ;Added with [11]
  328. ;End of [11]
  329. sEnd SCAN
  330. end