Source code of Windows XP (NT5)
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.

634 lines
16 KiB

  1. ;++
  2. ;
  3. ; WOW v1.0
  4. ;
  5. ; Copyright (c) 1991, Microsoft Corporation
  6. ;
  7. ; WINSTACK.ASM
  8. ; Win16 stack munging routines
  9. ;
  10. ; History:
  11. ;
  12. ; Created 18-Jun-1991 by Jeff Parsons (jeffpar)
  13. ; Copied from WIN31 and edited (as little as possible) for WOW16
  14. ;--
  15. ;****************************************************************************
  16. ;* *
  17. ;* WINSTACK.ASM - *
  18. ;* *
  19. ;* Stack Frame setup routines *
  20. ;* *
  21. ;****************************************************************************
  22. ifdef WOW
  23. NOEXTERNS equ 1
  24. endif
  25. .xlist
  26. include user.inc
  27. .list
  28. ;
  29. ; Short jump macro
  30. ;
  31. jmps macro adr
  32. jmp short (adr)
  33. endm
  34. ;
  35. ; XMOV macro
  36. ;
  37. ; Use instead of MOV ax,reg. Saves a byte.
  38. ;
  39. xmov macro a,b
  40. xchg a,b
  41. endm
  42. ifdef WOWDEBUG
  43. sBegin DATA
  44. externW <pStackTop>
  45. externW <pStackMin>
  46. externW <pStackBot>
  47. sEnd
  48. ifdef DEBUG
  49. sBegin TEXT
  50. ExternFP <DivideByZero>
  51. sEnd
  52. endif
  53. endif ;WOWDEBUG
  54. createSeg _TEXT, TEXT, WORD, PUBLIC, CODE
  55. assumes CS,TEXT
  56. assumes SS,DATA
  57. sBegin TEXT
  58. org 0 ; MUST be at the start of each segment
  59. ; so that WinFarFrame can jump back
  60. ; to the proper location.
  61. ;*--------------------------------------------------------------------------*
  62. ;* *
  63. ;* _TEXT_NEARFRAME() - *
  64. ;* *
  65. ;*--------------------------------------------------------------------------*
  66. ; Call to _segname_NEARFRAME should be in following format:
  67. ;
  68. ; call _segname_NEARFRAME
  69. ; db cbLocals (count of local words to be allocated)
  70. ; db cbParams (count of argument words)
  71. LabelNP <PUBLIC, _TEXT_NEARFRAME>
  72. push cs ; Save the current segment
  73. jmps WinNearFrame ; Jump to the (only) NEARFRAME routine
  74. nop
  75. nop
  76. nop
  77. nf2: push cs ; Save the CS (it may have changed!)
  78. jmps WinNearFrame2 ; Jump to the second half of NEARFRAME
  79. nop
  80. nop
  81. nop
  82. ;*--------------------------------------------------------------------------*
  83. ;* *
  84. ;* _TEXT_FARFRAME() - *
  85. ;* *
  86. ;*--------------------------------------------------------------------------*
  87. ; Call to _segname_FARFRAME should be in following format:
  88. ;
  89. ; call _segname_FARFRAME
  90. ; db cbLocals (count of local words to be allocated)
  91. ; db cbParams (count of argument words)
  92. LabelNP <PUBLIC, _TEXT_FARFRAME>
  93. push cs ; Save the current segment
  94. jmps WinFarFrame ; Jump to the (only) FARFRAME routine
  95. nop
  96. nop
  97. nop
  98. ifdef WOWDEBUG
  99. ff2: jmp near ptr WinFarFrame2 ; Jump to the second half of FARFRAME
  100. else
  101. ff2: jmp short near ptr WinFarFrame2
  102. endif
  103. ifdef WOWDEBUG
  104. ;*--------------------------------------------------------------------------*
  105. ;* *
  106. ;* __astkovr1() - *
  107. ;* *
  108. ;*--------------------------------------------------------------------------*
  109. ; Stack Overflow checking routine
  110. ;externFP <__astkovr>
  111. ;__astkovr1: jmp __astkovr
  112. endif
  113. ;*--------------------------------------------------------------------------*
  114. ;* *
  115. ;* WinNearFrame() - *
  116. ;* *
  117. ;*--------------------------------------------------------------------------*
  118. ; Sets up and dismantles the frame for a NEAR routine. This routine
  119. ; is FAR JMPed to by _segname_NEARFRAME. It munges the stack so that a
  120. ; NEAR RET returns to a JMP to WinNearFrame2 which dismantles the frame.
  121. ;
  122. ; CX must be is preserved in the first portion.
  123. LabelFP <PUBLIC, WinNearFrame>
  124. pop es ; Get the caller's Code Segment
  125. pop bx ; Get pointer to sizes of args and locals
  126. push bp ; Update the BP chain
  127. mov bp,sp
  128. mov dx,word ptr es:[bx] ; Move the 2 parms in DX
  129. xor ax,ax
  130. mov al,dl ; Move the # of local words into AL
  131. shl ax,1 ; Convert # of words into # of bytes
  132. ifdef WOWDEBUG
  133. sub ax,sp
  134. ; jae __astkovr1 ; Check for stack overflow in
  135. neg ax ; debugging versions
  136. cmp ss:[pStackTop],ax
  137. ; ja __astkovr1
  138. cmp ss:[pStackMin],ax
  139. jbe nf100
  140. mov ss:[pStackMin],ax
  141. nf100: xmov sp,ax
  142. else
  143. sub sp,ax ; Reserve room for locals on stack
  144. endif
  145. push si ; Save SI and DI
  146. push di
  147. xor ax,ax
  148. mov al,dh ; Move the # of func args into AL
  149. shl ax,1 ; Convert words to bytes
  150. push ax ; Save on the stack
  151. mov ax,offset nf2 ; Push the offset of the JMP to
  152. push ax ; WinNearFrame2 for function's RET
  153. inc bx ; Move pointer past the parms to the
  154. inc bx ; actual function code
  155. push es ; Jump back to the function via RETF
  156. push bx
  157. xor bx,bx ; insure ES is 0
  158. mov es,bx
  159. retf
  160. LabelFP <PUBLIC,WinNearFrame2>
  161. ; NOTE: AX and DX must be preserved now since they contain the C
  162. ; return value.
  163. pop es ; Get the caller's CS
  164. pop cx ; Get # of func args in CX
  165. pop di ; Restore SI and DI
  166. pop si
  167. mov sp,bp ; Free the local variables
  168. pop bp ; Restore BP
  169. pop bx ; Get the caller's return address
  170. add sp,cx ; Remove paramters from stack
  171. push es ; Return to caller via RETF
  172. push bx
  173. xor bx,bx ; insure ES is 0
  174. mov es,bx
  175. retf
  176. ;*--------------------------------------------------------------------------*
  177. ;* *
  178. ;* WinFarFrame() - *
  179. ;* *
  180. ;*--------------------------------------------------------------------------*
  181. ; Sets up and dismantles the frame for a FAR routine. This routine
  182. ; is FAR JMPed to by _segname_NEARFRAME. It munges the stack so that a
  183. ; NEAR RET returns to a JMP to WinFarFrame2 which dismantles the frame.
  184. ;
  185. ; CX must be is preserved in the first portion.
  186. LabelFP <PUBLIC, WinFarFrame>
  187. mov ax,ds ; This is patched by the loader to become
  188. nop ; mov ax,DSVAL
  189. pop es ; Get the caller's CS
  190. pop bx ; Get pointer to sizes of args and locals
  191. inc bp ; Make BP odd to mark far frame
  192. push bp ; Update the BP chain
  193. mov bp,sp
  194. push ds ; Save DS
  195. mov dx,word ptr es:[bx] ; Move the 2 parms into DX
  196. mov ds,ax ; Get the new DS from the loader patch
  197. xor ax,ax
  198. mov al,dl ; Move the # of local words into AL
  199. shl ax,1 ; Convert # of words into # of bytes
  200. ifdef WOWDEBUG
  201. sub ax,sp
  202. ; jae __astkovr1 ; Check for stack overflow in
  203. neg ax ; debugging versions
  204. cmp ss:[pStackTop],ax
  205. ; ja __astkovr1
  206. cmp ss:[pStackMin],ax
  207. jbe ff100
  208. mov ss:[pStackMin],ax
  209. ff100: xmov sp,ax
  210. else
  211. sub sp,ax ; Reserve room for locals on stack
  212. endif
  213. push si ; Save SI and DI
  214. push di
  215. xor ax,ax
  216. mov al,dh ; Move the # of func args into AL
  217. shl ax,1 ; Convert words to bytes
  218. push ax ; Save on the stack
  219. mov ax,offset ff2 ; Push the offset of the JMP to
  220. push ax ; WinFarFrame2 for function's RET
  221. inc bx ; Move pointer past the parms to the
  222. inc bx ; actual function code
  223. push es ; Jump back to the function via RETF
  224. push bx
  225. xor bx,bx ; Ensure es is 0
  226. mov es,bx
  227. retf
  228. LabelFP <PUBLIC,WinFarFrame2>
  229. ; NOTE: AX and DX must be preserved now since they contain the C
  230. ; return value.
  231. pop cx ; Get # of func args in CX
  232. pop di ; Restore SI and DI
  233. pop si
  234. if 0
  235. sub bp,2 ; Point BP at the DS value
  236. mov sp,bp ; Free the local variables
  237. pop ds ; Restore DS
  238. pop bp ; Restore BP
  239. dec bp ; Make BP even again
  240. pop bx ; Get the caller's return address
  241. pop es
  242. add sp,cx ; Remove paramters from stack
  243. push es ; Return to caller via RETF
  244. push bx
  245. xor bx,bx ; Ensure es is 0
  246. mov es,bx
  247. endif
  248. mov ds,[bp-2] ; Restore DS
  249. lea bx,[bp+2] ; get caller's return address
  250. add bx,cx ; Where we want to put the old CS:IP
  251. mov cx,[bp+4] ; get old CS
  252. mov ss:[bx+2],cx ; move it up
  253. mov cx,[bp+2] ; Get old IP
  254. mov ss:[bx],cx ; move it up
  255. mov bp,[bp] ; restore the old BP
  256. dec bp ; make it even again
  257. mov sp,bx ; point to the moved CS:IP
  258. retf ; later dude
  259. ifdef WOWDEBUG
  260. ORG 0cch
  261. jmp far ptr DivideByZero
  262. endif
  263. sEnd TEXT
  264. ifndef WOW
  265. ;==============================================================================
  266. ; FFFE SEGMENT
  267. ;==============================================================================
  268. createSeg _FFFE, FFFE, BYTE, PUBLIC, CODE
  269. assumes CS,_FFFE
  270. assumes SS,DATA
  271. sBegin FFFE
  272. ORG 0 ; This segment must have a magic header
  273. ; so that we know to move it up into
  274. ; segment FFFE:0000 if possible
  275. ; db 16 DUP ("AC")
  276. ; db 16 DUP (0) ; Tony's sleazy zeros
  277. ifdef WOWDEBUG
  278. ;*--------------------------------------------------------------------------*
  279. ;* *
  280. ;* __ffastkovr1() - *
  281. ;* *
  282. ;*--------------------------------------------------------------------------*
  283. ; Stack Overflow checking routine
  284. ;__ffastkovr1: jmp __astkovr
  285. endif
  286. ;*--------------------------------------------------------------------------*
  287. ;* *
  288. ;* _FFFE_NEARFRAME() - *
  289. ;* *
  290. ;*--------------------------------------------------------------------------*
  291. LabelNP <PUBLIC, _FFFE_NEARFRAME>
  292. pop bx ; Get pointer to sizes of args and locals
  293. push bp ; Update the BP chain
  294. mov bp,sp
  295. mov dx,word ptr cs:[bx] ; Move the 2 parms in DX
  296. xor ax,ax
  297. mov al,dl ; Move the # of local words into AL
  298. shl ax,1 ; Convert # of words into # of bytes
  299. ifdef WOWDEBUG
  300. sub ax,sp
  301. ; jae __ffastkovr1 ; Check for stack overflow in
  302. neg ax ; debugging versions
  303. cmp ss:[pStackTop],ax
  304. ; ja __ffastkovr1
  305. cmp ss:[pStackMin],ax
  306. jbe ffnf100
  307. mov ss:[pStackMin],ax
  308. ffnf100: xmov sp,ax
  309. else
  310. sub sp,ax ; Reserve room for locals on stack
  311. endif
  312. push si ; Save SI and DI
  313. push di
  314. xor ax,ax
  315. mov al,dh ; Move the # of func args into AL
  316. shl ax,1 ; Convert words to bytes
  317. push ax ; Save on the stack
  318. ifndef userhimem
  319. mov ax,offset FFFE_nf2 ; Munge the stack so the function
  320. else
  321. push ds
  322. mov ax, _INTDS
  323. mov ds,ax
  324. assumes ds,INTDS
  325. mov ax,fffedelta
  326. pop ds
  327. assumes ds,DATA
  328. add ax, OFFSET FFFE_nf2
  329. endif
  330. push ax ; "returns" to FFFE_nf2
  331. inc bx ; Move pointer past the parms to the
  332. inc bx ; actual function code
  333. push bx ; Jump back to the function
  334. ret
  335. LabelFP <PUBLIC,FFFE_nf2>
  336. ; NOTE: AX and DX must be preserved now since they contain the C
  337. ; return value
  338. pop cx ; Get # of func args in CX
  339. pop di ; Restore SI and DI
  340. pop si
  341. mov sp,bp ; Free the local variables
  342. pop bp ; Restore BP
  343. pop bx ; Get the caller's return address
  344. add sp,cx ; Remove paramters from stack
  345. push bx ; Return to caller
  346. ret
  347. ;*--------------------------------------------------------------------------*
  348. ;* *
  349. ;* _FFFE_FARFRAME() - *
  350. ;* *
  351. ;*--------------------------------------------------------------------------*
  352. LabelNP <PUBLIC, _FFFE_FARFRAME>
  353. mov ax,ds ; This is patched by the loader to become
  354. nop ; mov ax,DSVAL
  355. pop bx ; Get pointer to sizes of args and locals
  356. inc bp ; Make BP odd to mark far frame
  357. push bp ; Update the BP chain
  358. mov bp,sp
  359. push ds ; Save DS
  360. mov ds,ax ; Get the new DS from the loader patch
  361. mov dx,word ptr cs:[bx] ; Move the 2 parms into DX
  362. xor ax,ax
  363. mov al,dl ; Move the # of local words into AL
  364. shl ax,1 ; Convert # of words into # of bytes
  365. ifdef WOWDEBUG
  366. sub ax,sp
  367. ; jae __ffastkovr1 ; Check for stack overflow in
  368. neg ax ; debugging versions
  369. cmp ss:[pStackTop],ax
  370. ; ja __ffastkovr1
  371. cmp ss:[pStackMin],ax
  372. jbe ffff100
  373. mov ss:[pStackMin],ax
  374. ffff100: xmov sp,ax
  375. else
  376. sub sp,ax ; Reserve room for locals on stack
  377. endif
  378. push si ; Save SI and DI
  379. push di
  380. xor ax,ax
  381. mov al,dh ; Move the # of func args into AL
  382. shl ax,1 ; Convert words to bytes
  383. push ax ; Save on the stack
  384. ifndef userhimem
  385. mov ax,offset FFFE_ff2 ; Munge the stack so the function
  386. else
  387. push ds
  388. mov ax, _INTDS
  389. mov ds,ax
  390. assumes ds,INTDS
  391. mov ax,fffedelta
  392. pop ds
  393. assumes ds,DATA
  394. add ax,offset FFFE_ff2 ; Munge the stack so the function
  395. endif
  396. push ax ; "returns" to FFFE_nf2
  397. inc bx ; Move pointer past the parms to the
  398. inc bx ; actual function code
  399. push bx ; Jump back to the function
  400. ret
  401. ; NOTE: AX and DX must be preserved now since they contain the C
  402. ; return value
  403. LabelFP <PUBLIC,FFFE_ff2>
  404. pop cx ; Get # of func args in CX
  405. pop di ; Restore SI and DI
  406. pop si
  407. sub bp,2 ; Point BP at the DS value
  408. mov sp,bp ; Free the local variables
  409. pop ds ; Restore DS
  410. pop bp ; Restore BP
  411. dec bp ; Make BP even again
  412. pop bx ; Get the caller's return address
  413. pop es
  414. add sp,cx ; Remove paramters from stack
  415. push es ; Return to caller via RETF
  416. push bx
  417. xor bx,bx ; Ensure es is 0
  418. mov es,bx
  419. retf
  420. sEnd FFFE
  421. ;*--------------------------------------------------------------------------*
  422. ;* *
  423. ;* CreateFrame Macro - *
  424. ;* *
  425. ;*--------------------------------------------------------------------------*
  426. CreateFrame macro SegName
  427. createSeg _&SegName, SegName, BYTE, PUBLIC, CODE
  428. assumes CS,_&SegName
  429. assumes SS,DATA
  430. sBegin SegName
  431. org 0 ; MUST be at the start of each segment
  432. ; so that WinFarFrame can jump back
  433. ; to the proper location.
  434. LabelNP <PUBLIC, _&SegName&_NEARFRAME>
  435. push cs ; Save the current segment
  436. jmp WinNearFrame ; Jump to the (only) NEARFRAME routine
  437. push cs ; Save the CS (it may have changed!)
  438. jmp WinNearFrame2 ; Jump to the second half of NEARFRAME
  439. LabelNP <PUBLIC, _&SegName&_FARFRAME>
  440. push cs ; Save the current segment
  441. jmp WinFarFrame ; Jump to the (only) FARFRAME routine
  442. jmp WinFarFrame2 ; Jump to the second half of FARFRAME
  443. sEnd SegName
  444. endm
  445. ;==============================================================================
  446. ; SEGMENT FRAMES
  447. ;==============================================================================
  448. ;CreateFrame INIT
  449. ;CreateFrame MDKEY
  450. ;CreateFrame MENUCORE
  451. ;CreateFrame MENUAPI
  452. ;CreateFrame MENUSTART
  453. ;CreateFrame RUNAPP
  454. ;CreateFrame DLGBEGIN
  455. ;CreateFrame DLGCORE
  456. ;CreateFrame SCRLBAR
  457. CreateFrame WMGR
  458. CreateFrame WMGR2
  459. ;CreateFrame RARE
  460. ;CreateFrame LBOX
  461. ;CreateFrame LBOXAPI
  462. ;CreateFrame LBOXDIR
  463. ;CreateFrame LBOXMULTI
  464. ;CreateFrame LBOXRARE
  465. ;CreateFrame CLPBRD
  466. ;CreateFrame COMDEV
  467. ;CreateFrame ICON
  468. ;CreateFrame SWITCH
  469. ;CreateFrame MSGBOX
  470. ;CreateFrame MDIWIN
  471. ;CreateFrame MDIMENU
  472. ;CreateFrame EDECRARE
  473. ;CreateFrame EDSLRARE
  474. ;CreateFrame EDMLONCE
  475. ;CreateFrame EDMLRARE
  476. ;CreateFrame WINCRTDST
  477. ;CreateFrame WINUTIL
  478. ;CreateFrame RESOURCE
  479. ;CreateFrame WALLPAPER
  480. ;CreateFrame WINSWP
  481. CreateFrame LANG
  482. endif ;WOW
  483. end