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.

907 lines
17 KiB

  1. ;******************************************************************************
  2. ;
  3. ; Simulator 16
  4. ;
  5. ; Author : Chandan Chauhan
  6. ;
  7. ; Date : 1/28/91
  8. ;
  9. ;******************************************************************************
  10. include incs.inc ; segment definitions
  11. MAXSIZE EQU 1024 ; 1k length
  12. Arg1 EQU [bp+6]
  13. Arg2 EQU [bp+8]
  14. WOW32_Buffer EQU [bp+6] ; buffer address
  15. WOW32_Size EQU [bp+8] ; length of VDM memory
  16. WOW32_Off EQU [bp+10] ; off of VDM memory
  17. WOW32_Sel EQU [bp+12] ; sel of VDM memory
  18. WOWStackNP EQU [bp+6] ; WOWStack
  19. WOWStackOff EQU [bp+6]
  20. WOWStackSel EQU [bp+8]
  21. extrn Initialize:near
  22. MAIN_DATA SEGMENT
  23. PUBLIC TransmitPkt, ReceivePkt, ReceivePktPtr, RespPkt, ToWOW32Pkt
  24. PUBLIC ACKPkt, NAKPkt, GetMemPkt, SetMemPkt, WAKEUPPkt
  25. PUBLIC fReceive, fRxCount, fRxError, RxPktLen
  26. PUBLIC fTxCount, fTransmitting
  27. PUBLIC fInitTime
  28. PUBLIC VDMAddress
  29. PUBLIC WOWStack, WOW32Buffer
  30. Reserved DB 16 DUP (0) ; reserved
  31. TransmitPkt DD -1 ; packet being transmitted
  32. TransmitPktLen DW 0 ; packet being transmitted
  33. TransmitPktPtr DW 0 ; byte to Tx
  34. ReceivePkt DB MAXSIZE DUP (0FFh) ; packet being received
  35. ReceivePktPtr DW 0 ; packet being received
  36. RespPkt DB MAXSIZE DUP (0FFh) ; packet being transmitted
  37. ToWOW32Pkt DB 9 DUP (?) ; ToWOW32 packet
  38. DB 0
  39. WAKEUPPkt DB 9 DUP (0) ; WAKEUP packet
  40. DB 0
  41. ACKPkt DB 5 DUP (?) ; ACK packet
  42. DB 0
  43. NAKPkt DB 5 DUP (?) ; NAK packet
  44. DB 0
  45. GetMemPkt DB MAXSIZE DUP (?) ;***************
  46. SetMemPkt DB MAXSIZE DUP (?) ;***************
  47. VDMAddress DD -1 ; stores VDM sel:off
  48. VDMLength DW -1 ; number of bytes
  49. WOW32Buffer DD -1 ; ptr caller's buffer
  50. WOWStack DD -1 ; ptr to caller's WOWStack
  51. fTxCount DW 0
  52. fTransmitting DW 0
  53. fReceive DW 0
  54. fRxCount DW 0
  55. fRxError DW 0
  56. fInitTime DW 0
  57. fInitDLL DW 0
  58. RxPktLen DW 0
  59. Stack DW 256 DUP (?)
  60. StackTop DW ?
  61. OldSS DW ?
  62. OldSP DW ?
  63. Scratch DW ?
  64. fStackUse DW -1
  65. IntRoutines LABEL WORD
  66. DW COMISR_MSR
  67. DW COMISR_Transmit
  68. DW COMISR_Receive
  69. DW COMISR_LSR
  70. HelloString DB cr, lf, 'WOW Simulator *****', cr, lf, lf
  71. DB 'Hello, this is a test string !!!!!!!!!!', cr, lf
  72. HelloStringLen EQU $ - HelloString
  73. MAIN_DATA ENDS
  74. MAIN_CODE SEGMENT
  75. ASSUME CS:MAIN_CODE, DS:MAIN_DATA, ES:NOTHING
  76. ;*****************************************************************************
  77. ; S I M U L A T O R L A Y E R
  78. ;*****************************************************************************
  79. ;*****************************************************************************
  80. ;
  81. ; Sim32SendSim16
  82. ;
  83. ;*****************************************************************************
  84. ;***************
  85. PROCEDURE Sim32SendSim16 PUBLIC, FAR
  86. push bp ; save stack frame
  87. mov bp, sp
  88. pusha ; temps...
  89. push ds ; temps...
  90. push es ; temps...
  91. mov bx, ds
  92. mov ax, SEG MAIN_DATA
  93. mov ds, ax
  94. mov si, OFFSET WAKEUPPkt ; DS:SI -> WAKEUP packet
  95. mov ax, WOWStackNP
  96. mov WOWStack._off, ax
  97. mov WOWStack._sel, bx
  98. cmp fInitTime, 0
  99. je Sim32SendSim16_Init
  100. les bx, WOWStack ; ES:BX -> SS:SP of WOW VDM task
  101. mov ax, es:[bx]._off ; get SP
  102. mov [si].MEM_OFF, ax
  103. mov ax, es:[bx]._sel ; get SS
  104. mov [si].MEM_SEL, ax
  105. call Xceive
  106. Sim32SendSim16_Ret:
  107. les bx, WOWStack ; ES:BX -> SS:SP of WOW VDM task
  108. mov di, OFFSET ReceivePkt
  109. mov ax, [di].ToWOW32_OFF
  110. mov es:[bx]._off, ax
  111. mov ax, [di].ToWOW32_SEL
  112. mov es:[bx]._sel, ax
  113. pop es ; temps...
  114. pop ds ; temps...
  115. popa ; temps...
  116. mov sp, bp
  117. pop bp
  118. ret 2
  119. Sim32SendSim16_Init:
  120. call Receive
  121. inc fInitTime
  122. call Initialize
  123. jmp SHORT Sim32SendSim16_Ret
  124. Sim32SendSim16 ENDP
  125. ;*****************************************************************************
  126. ;
  127. ; Sim32GetVDMMemory
  128. ;
  129. ;*****************************************************************************
  130. ;***************
  131. PROCEDURE Sim32GetVDMMemory PUBLIC, FAR
  132. push bp ; save stack frame
  133. mov bp, sp
  134. pusha ; temps...
  135. push ds ; temps...
  136. push es ; temps...
  137. mov bx, ds
  138. mov ax, SEG MAIN_DATA
  139. mov ds, ax
  140. mov si, OFFSET GetMemPkt ; DS:SI -> ToWOW32 packet
  141. mov ax, WOW32_Buffer ; get buffer's address
  142. mov WOW32Buffer._off, ax
  143. mov ax, bx
  144. mov WOW32Buffer._sel, ax
  145. mov ax, WOW32_Off
  146. mov [si].MEM_OFF, ax
  147. mov ax, WOW32_Sel
  148. mov [si].MEM_SEL, ax
  149. mov cx, WOW32_Size ; get the length
  150. cmp cx, 3B6h
  151. jg Sim32GetMem_Error
  152. mov [si].MEM_LENGTH, cx
  153. call Xceive ; send GetMem packet and pickup
  154. ; the response
  155. mov cx, WOW32_Size
  156. les di, WOW32Buffer ; ES:DI -> WOW32 buffer
  157. mov si, OFFSET ReceivePkt+4
  158. rep movsb
  159. pop es ; temps...
  160. pop ds ; temps...
  161. popa ; temps...
  162. mov sp, bp
  163. pop bp
  164. ret 8
  165. Sim32GetMem_Error:
  166. int 3
  167. Sim32GetVDMMemory ENDP
  168. ;*****************************************************************************
  169. ;
  170. ; Sim32SetVDMMemory
  171. ;
  172. ;*****************************************************************************
  173. ;***************
  174. PROCEDURE Sim32SetVDMMemory PUBLIC, FAR
  175. push bp ; save stack frame
  176. mov bp, sp
  177. pusha ; temps...
  178. push ds ; temps...
  179. push es ; temps...
  180. mov bx, ds
  181. mov ax, SEG MAIN_DATA
  182. mov ds, ax
  183. mov di, OFFSET SetMemPkt ; DS:DI -> SetMem packet
  184. mov ax, WOW32_Buffer ; get buffer's address
  185. mov WOW32Buffer._off, ax
  186. mov ax, bx
  187. mov WOW32Buffer._sel, ax
  188. mov ax, WOW32_Off
  189. mov [di].MEM_OFF, ax
  190. mov ax, WOW32_Sel
  191. mov [di].MEM_SEL, ax
  192. mov cx, WOW32_Size
  193. cmp cx, 3B6h
  194. jg Sim32SetMem_Error
  195. mov [di].MEM_LENGTH, cx
  196. mov bx, 11
  197. add bx, cx
  198. mov [di].Len, bx
  199. add di, 0Ah
  200. mov bx, ds
  201. mov es, bx
  202. lds si, WOW32Buffer ; DS:SI -> Buffer
  203. rep movsb
  204. mov BYTE PTR es:[di], EOT
  205. mov ds, bx
  206. mov si, OFFSET SetMemPkt ; DS:SI -> SetMem packet
  207. call Xceive
  208. pop es ; temps...
  209. pop ds ; temps...
  210. popa ; temps...
  211. mov sp, bp
  212. pop bp
  213. ret 8
  214. Sim32SetMem_Error:
  215. int 3
  216. Sim32SetVDMMemory ENDP
  217. ;*****************************************************************************
  218. ;
  219. ; Sim16SendSim32
  220. ;
  221. ;*****************************************************************************
  222. PROCEDURE Sim16SendSim32 PUBLIC, FAR
  223. push bp ; save stack frame
  224. mov bp, sp
  225. pusha ; temps...
  226. push ds ; temps...
  227. push es ; temps...
  228. mov bx, ds
  229. mov ax, SEG MAIN_DATA
  230. mov ds, ax
  231. mov si, OFFSET ToWOW32Pkt ; DS:SI -> ToWOW32 packet
  232. cmp fInitDLL, 0
  233. jne @f
  234. pusha
  235. call Initialize
  236. popa
  237. inc fInitDLL
  238. @@:
  239. ; prepare ToWOW32 packet
  240. mov ax, WOWStackOff
  241. mov [si].ToWOW32_OFF, ax ;
  242. mov ax, WOWStackSel
  243. mov [si].ToWOW32_SEL, ax ;
  244. ; send it
  245. call Xceive ; send ToWOW32 packet and pick up
  246. ; the response
  247. Sim16SendSim32_Loop:
  248. mov di, OFFSET Receivepkt
  249. mov ax, [di].MEM_OFF ; get sel:off and length from
  250. mov VDMAddress._off, ax ; packet
  251. mov ax, [di].MEM_SEL
  252. mov VDMAddress._sel, ax
  253. mov ax, [di].MEM_LENGTH
  254. mov VDMLength, ax
  255. Sim16SendSim32_GetMem:
  256. cmp [di].Command, GETMEM
  257. jne Sim16SendSim32_SetMem
  258. call GetVDMMemory ; get vdm memory
  259. call Xceive ; send response and get next packet
  260. jmp SHORT Sim16SendSim32_Loop
  261. Sim16SendSim32_SetMem:
  262. cmp [di].Command, SETMEM
  263. jne Sim16SendSim32_PszLen
  264. call SetVDMMemory ; get vdm memory
  265. call Xceive ; send response and get next packet
  266. jmp SHORT Sim16SendSim32_Loop
  267. Sim16SendSim32_PszLen:
  268. cmp [di].Command, PSZ
  269. jne Sim16SendSim32_WakeUp
  270. call PszLen
  271. call Xceive ; send response and get next packet
  272. jmp SHORT Sim16SendSim32_Loop
  273. Sim16SendSim32_WakeUp:
  274. cmp [di].Command, WAKEUP
  275. jne Sim16SendSim32_Error
  276. Sim16SendSim32_Done:
  277. pop es ; temps...
  278. pop ds ; temps...
  279. popa ; temps...
  280. IFDEF STACKSWITCH
  281. cli
  282. mov sp, VDMAddress._off
  283. mov ss, VDMAddress._sel ; could be a task switch !
  284. sub sp, 8
  285. sti
  286. ENDIF
  287. pop bp
  288. ret 4
  289. Sim16SendSim32_Error:
  290. int 3
  291. mov si, OFFSET NAKPkt
  292. call Xceive
  293. jmp SHORT Sim16SendSim32_Loop
  294. Sim16SendSim32 ENDP
  295. ;*****************************************************************************
  296. ;
  297. ; GetVDMMemory
  298. ;
  299. ;*****************************************************************************
  300. PROCEDURE GetVDMMemory, PUBLIC
  301. ASSUME CS:MAIN_CODE, DS:DGROUP
  302. push di
  303. push es
  304. push ds
  305. mov ax, ds
  306. mov es, ax
  307. mov di, OFFSET RespPkt+4 ; ES:DI -> Response Packet
  308. mov cx, VDMLength
  309. lds si, VDMAddress ; DS:SI -> memory to get
  310. rep movsb
  311. pop ds
  312. pop es
  313. pop di
  314. mov si, OFFSET RespPkt ; DS:SI -> Resp packet
  315. mov ax, si
  316. mov cx, VDMLength
  317. add cx, 5
  318. mov [si].Len, cx
  319. add si, cx
  320. dec si
  321. mov [si], BYTE PTR EOT
  322. mov si, ax ; DS:SI -> Resp packet
  323. ret
  324. GetVDMMemory ENDP
  325. ;*****************************************************************************
  326. ;
  327. ; SetVDMMemory
  328. ;
  329. ;*****************************************************************************
  330. PROCEDURE SetVDMMemory, PUBLIC
  331. ASSUME CS:MAIN_CODE, DS:DGROUP
  332. push di
  333. push es
  334. lea si, ReceivePkt.DataM ; DS:SI -> Data to set
  335. mov cx, VDMLength
  336. les di, VDMAddress ; DS:SI -> memory to set
  337. rep movsb
  338. mov si, OFFSET RespPkt ; DS:DI -> Response Packet
  339. mov [si].Len, 7
  340. mov [si].MEM_OFF, 0AAh
  341. mov BYTE PTR [si].MEM_SEL, EOT
  342. pop es
  343. pop di
  344. ret
  345. SetVDMMemory ENDP
  346. ;*****************************************************************************
  347. ;
  348. ; PszLen
  349. ;
  350. ; This routine returns the length of the null terminated string
  351. ; address specified by VDMAddress.
  352. ;
  353. ;*****************************************************************************
  354. PROCEDURE PszLen, PUBLIC
  355. ASSUME CS:MAIN_CODE, DS:DGROUP
  356. push di
  357. push es
  358. les di, VDMAddress ; ES:DI -> String
  359. mov cx, 0FFFFh
  360. sub ax, ax ; look for null
  361. repne scasb
  362. jnz PszLen_Notfound
  363. xor cx, 0FFFFh ; CX = length of string
  364. mov si, OFFSET RespPkt ; DS:DI -> Response Packet
  365. mov [si].Len, 7
  366. mov [si].MEM_OFF, cx
  367. mov BYTE PTR [si].MEM_SEL, EOT
  368. pop es
  369. pop di
  370. ret
  371. PszLen_Notfound:
  372. int 3
  373. pop es
  374. pop di
  375. ret
  376. PszLen ENDP
  377. ;*****************************************************************************
  378. ; T R A N S P O R T L A Y E R
  379. ;*****************************************************************************
  380. ;*****************************************************************************
  381. ;
  382. ; Xceive - TransCeive
  383. ;
  384. ; DS:SI -> Packet to be transmitted
  385. ;
  386. ;*****************************************************************************
  387. PROCEDURE Xceive, PUBLIC
  388. ASSUME CS:MAIN_CODE, DS:DGROUP
  389. mov RxPktLen, -1
  390. mov ReceivePktPtr, 0
  391. mov fReceive, 0
  392. mov fRxCount, 0
  393. mov fRxError, 0
  394. call StartTransmitter
  395. Xceive_Loop:
  396. cmp fReceive, 0
  397. je Xceive_Loop
  398. mov fReceive, 0
  399. cmp fRxError, 0
  400. jne Xceive_NAK
  401. cmp ReceivePkt, SOH
  402. jne Xceive_NAK
  403. mov bx, ReceivePkt.Len
  404. dec bx
  405. cmp ReceivePkt.[bx], EOT
  406. jne Xceive_NAK
  407. xor ax, ax
  408. ret
  409. Xceive_NAK:
  410. cmp fRxCount, MAXCOUNT
  411. jg Xceive_Error
  412. inc fRxCount
  413. mov si, OFFSET NAKPkt
  414. jmp SHORT Xceive_Loop
  415. Xceive_Error:
  416. int 3
  417. mov ax, 1
  418. ret
  419. Xceive ENDP
  420. ;*****************************************************************************
  421. ;
  422. ; Receive
  423. ;
  424. ;*****************************************************************************
  425. PROCEDURE Receive, PUBLIC
  426. ASSUME CS:MAIN_CODE, DS:DGROUP
  427. mov RxPktLen, -1
  428. mov ReceivePktPtr, 0
  429. mov fReceive, 0
  430. mov fRxCount, 0
  431. Receive_Loop:
  432. cmp fReceive, 0
  433. je Receive_Loop
  434. mov fReceive, 0
  435. cmp fRxError, 0
  436. jne Receive_NAK
  437. xor ax, ax
  438. ret
  439. Receive_NAK:
  440. cmp fRxCount, MAXCOUNT
  441. jg Receive_Error
  442. inc fRxCount
  443. mov si, OFFSET NAKPkt
  444. call StartTransmitter
  445. jmp SHORT Receive
  446. Receive_Error:
  447. int 3
  448. mov ax, 1
  449. ret
  450. Receive ENDP
  451. ;*****************************************************************************
  452. ; S E R I A L D R I V E R
  453. ;*****************************************************************************
  454. ;*****************************************************************************
  455. ;
  456. ; Start Transmitter
  457. ;
  458. ;*****************************************************************************
  459. PROCEDURE StartTransmitter, PUBLIC
  460. ASSUME CS:MAIN_CODE, DS:DGROUP
  461. StartTransmitter_Loop:
  462. cmp fTransmitting, 1
  463. je StartTransmitter_Loop
  464. mov TransmitPkt._sel, ds
  465. mov TransmitPkt._off, si
  466. mov ax, [si].Len ; get packet length
  467. mov TransmitPktLen, ax
  468. mov TransmitPktPtr, 0
  469. mov fTransmitting, 1
  470. cmp TransmitPktLen, 0
  471. je StartTransmitter_Ret
  472. mov dx, SERIALPORT ; COM1 or COM2
  473. mov dl, IER ; turn on interrupts on 8250
  474. in al, dx
  475. DELAY
  476. or al, TxInt
  477. out dx, al
  478. DELAY
  479. StartTransmitter_Ret:
  480. ret
  481. StartTransmitter ENDP
  482. ;*****************************************************************************
  483. ;
  484. ; Interrupt Routine
  485. ;
  486. ;*****************************************************************************
  487. PUBLIC COMISR, COMISR_LSR, COMISR_Receive, COMISR_Transmit, COMISR_MSR
  488. COMISR:
  489. push ax
  490. push ds
  491. mov ax, SEG DGROUP
  492. mov ds, ax
  493. DISABLE
  494. call NewStack
  495. pusha
  496. push es
  497. COMISR_More:
  498. mov dx, SERIALPORT
  499. mov dl, IIR
  500. in al, dx
  501. test al, IntPending ; is int pending ?
  502. jnz COMISR_Ret ; no int is pending
  503. xor ah, ah
  504. mov di, ax
  505. shr di, 1
  506. add di, di
  507. jmp [di].IntRoutines ; service int
  508. COMISR_LSR:
  509. INT3
  510. mov fRxError, 1
  511. mov dx, SERIALPORT
  512. mov dl, LSR
  513. in al, dx
  514. DELAY
  515. jmp SHORT COMISR_More
  516. COMISR_Receive:
  517. mov dx, SERIALPORT
  518. in al, dx
  519. DELAY
  520. mov bx, ReceivePktPtr
  521. mov [bx].ReceivePkt, al
  522. inc ReceivePktPtr
  523. cmp bx, 03
  524. jne COMISR_ReceiveNext
  525. mov ax, WORD PTR ReceivePkt+2
  526. dec ax
  527. mov RxPktLen, ax
  528. COMISR_ReceiveNext:
  529. cmp bx, RxPktLen
  530. jne @f
  531. mov fReceive, 1 ; receive Done !
  532. @@:
  533. jmp SHORT COMISR_More
  534. COMISR_Transmit:
  535. cmp TransmitPktLen, 0
  536. jne COMISR_Send
  537. mov dx, SERIALPORT
  538. mov dl, IER ; turn off interrupts on 8250
  539. in al, dx
  540. DELAY
  541. and al, NOT TxInt
  542. out dx, al
  543. DELAY
  544. mov fTransmitting, 0
  545. jmp SHORT COMISR_More
  546. COMISR_Send:
  547. les bx, DWORD PTR TransmitPkt
  548. mov di, TransmitPktPtr
  549. mov al, BYTE PTR es:[bx][di]
  550. mov dx, SERIALPORT
  551. out dx, al
  552. DELAY
  553. inc TransmitPktPtr
  554. dec TransmitPktLen
  555. jmp COMISR_More
  556. COMISR_MSR:
  557. INT3
  558. mov fRxError, 1
  559. mov dx, SERIALPORT
  560. mov dl, MSR
  561. in al, dx
  562. DELAY
  563. jmp COMISR_More
  564. COMISR_Ret:
  565. DELAY
  566. pop es
  567. popa
  568. call OldStack
  569. DISABLE
  570. mov al, EOI
  571. out PIC, al
  572. pop ds
  573. pop ax
  574. iret
  575. ;*****************************************************************************
  576. ;
  577. ; New Stack
  578. ;
  579. ;*****************************************************************************
  580. PROCEDURE NewStack, PUBLIC
  581. ASSUME CS:MAIN_CODE, DS:DGROUP
  582. inc fStackUse
  583. jnz NewStack_Ret
  584. pop Scratch
  585. mov OldSS, ss
  586. mov OldSP, sp
  587. push ds
  588. pop ss
  589. mov sp, OFFSET StackTop
  590. push Scratch
  591. NewStack_Ret:
  592. ret
  593. NewStack ENDP
  594. ;*****************************************************************************
  595. ;
  596. ; Old Stack
  597. ;
  598. ;*****************************************************************************
  599. PROCEDURE OldStack, PUBLIC
  600. ASSUME CS:MAIN_CODE, DS:DGROUP
  601. DISABLE
  602. cmp fStackUse, 0
  603. jne OldStack_Ret
  604. pop Scratch
  605. mov ss, OldSS
  606. mov sp, OldSP
  607. push Scratch
  608. OldStack_Ret:
  609. dec fStackUse
  610. ENABLE
  611. ret
  612. OldStack ENDP
  613. MAIN_CODE ENDS
  614. END