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.

234 lines
5.4 KiB

  1. include incs.inc
  2. extrn LocalInit:FAR
  3. extrn __acrtused:abs ; pull in windows startup code
  4. MAIN_DATA SEGMENT
  5. extrn RespPkt:BYTE
  6. extrn ToWOW32Pkt:BYTE
  7. extrn WAKEUPPkt:BYTE
  8. extrn ACKPkt:BYTE
  9. extrn NAKPkt:BYTE
  10. extrn GetMemPkt:BYTE
  11. extrn SetMemPkt:BYTE
  12. MAIN_DATA ENDS
  13. MAIN_CODE SEGMENT
  14. ASSUME CS:MAIN_CODE, DS:MAIN_DATA
  15. extrn COMISR:NEAR
  16. ;*****************************************************************************
  17. ;
  18. ; LibEntry, called when DLL is loaded
  19. ;
  20. ;*****************************************************************************
  21. PUBLIC LibEntry
  22. LibEntry PROC FAR
  23. int 3
  24. jcxz LibEntry_Initialize
  25. push ds ; heap segment
  26. xor ax, ax ;
  27. push ax
  28. push cx ; heap size
  29. call LocalInit ; initialize heap
  30. or ax, ax
  31. jz LibEntry_Fail
  32. LibEntry_Initialize:
  33. call Initialize ; initialize com port and buffers
  34. LibEntry_Fail:
  35. ret
  36. LibEntry ENDP
  37. ;*****************************************************************************
  38. ;
  39. ; Initialize com port and memory
  40. ;
  41. ;*****************************************************************************
  42. PUBLIC Initialize
  43. Initialize PROC NEAR
  44. call Init_Com ; initialize com port
  45. or ax, ax
  46. jz Initialize_Fail
  47. push ax
  48. call Init_Mem ; initialize memory
  49. pop ax
  50. ret
  51. Initialize_Fail:
  52. int 3
  53. ret
  54. Initialize ENDP
  55. ;*****************************************************************************
  56. ;
  57. ; WEP, called when DLL is unloaded
  58. ;
  59. ;*****************************************************************************
  60. PUBLIC WEP
  61. WEP PROC FAR
  62. nop
  63. ret
  64. WEP ENDP
  65. ;*****************************************************************************
  66. ;
  67. ; Initialization of the Port
  68. ;
  69. ;*****************************************************************************
  70. Init_Com PROC NEAR
  71. mov dx, SERIALPORT
  72. mov dl, LCR
  73. mov al, DLAB ; turn on divisor latch
  74. out dx, al
  75. DELAY
  76. mov dl, RxBuf
  77. mov ax, BaudRate ; set baud rate
  78. out dx, al
  79. DELAY
  80. inc dx
  81. mov al, ah
  82. out dx, al
  83. DELAY
  84. mov dl, LCR ; set LCR
  85. mov al, InitLCR
  86. out dx, al
  87. DELAY
  88. mov dl, IER ; turn on interrupts on 8250
  89. mov al, AllInt
  90. out dx, al
  91. DELAY
  92. mov dl, MCR ; set MCR
  93. mov al, InitMCR
  94. out dx, al
  95. Init_ClearRegisters:
  96. mov dl, LSR
  97. in al, dx
  98. mov dl, RxBuf
  99. in al, dx
  100. mov dl, MSR
  101. in al, dx
  102. mov dl, IIR
  103. in al, dx
  104. in al, dx
  105. test al, 1
  106. jz Init_ClearRegisters
  107. ;
  108. ; install interrupt handler
  109. ;
  110. cli
  111. mov al, 0Ch
  112. push ds
  113. mov dx, SEG MAIN_CODE
  114. mov ds, dx
  115. mov dx, OFFSET COMISR
  116. mov ah, 25h
  117. int 21h
  118. pop ds
  119. in al, PIC_IntEnable
  120. and al, 0E7h
  121. DELAY
  122. out PIC_IntEnable, al
  123. sti
  124. mov al, EOI
  125. out PIC, al
  126. mov ax, 1 ; return sucess !
  127. ret
  128. Init_Com ENDP
  129. ;*****************************************************************************
  130. ;
  131. ; Initialize memory ie, allocate buffers and packets
  132. ;
  133. ;*****************************************************************************
  134. PUBLIC Init_Mem
  135. Init_Mem PROC NEAR
  136. mov bx, OFFSET RespPkt
  137. mov [bx].Start, SOH ; start of header
  138. mov [bx].Command, RESP ; Resp packet
  139. mov bx, OFFSET ToWOW32Pkt ; ToWOW32 packet
  140. mov [bx].Start, SOH ; start of header
  141. mov [bx].Command, ToWOW32 ; ToWOW32 packet
  142. mov [bx].Len, 9 ; length of entire packet
  143. mov BYTE PTR [bx+8], EOT ; end of transmission
  144. mov bx, OFFSET WAKEUPPkt ; WAKEUP packet
  145. mov [bx].Start, SOH ; start of header
  146. mov [bx].Command, WAKEUP ; WAKEUP packet
  147. mov [bx].Len, 9 ; length of entire packet
  148. mov BYTE PTR [bx+8], EOT ; end of transmission
  149. mov bx, OFFSET ACKPkt ; ACK packet
  150. mov [bx].Start, SOH ; start of header
  151. mov [bx].Command, ACK ; ACK packet
  152. mov [bx].Len, 5 ; length of entire packet
  153. mov BYTE PTR [bx+4], EOT ; end of transmission
  154. mov bx, OFFSET NAKPkt ; NAK packet
  155. mov [bx].Start, SOH ; start of header
  156. mov [bx].Command, NAK ; NAK packet
  157. mov [bx].Len, 5 ; length of entire packet
  158. mov BYTE PTR [bx+4], EOT ; end of transmission
  159. mov bx, OFFSET GetMemPkt ; GetMem packet
  160. mov [bx].Start, SOH ; start of header
  161. mov [bx].Command, GETMEM ; GETMEN packet
  162. mov [bx].Len, 11 ; length of entire packet
  163. mov BYTE PTR [bx+10], EOT ; end of transmission
  164. mov bx, OFFSET SetMemPkt ; SetMem packet
  165. mov [bx].Start, SOH ; start of header
  166. mov [bx].Command, SETMEM ; SETMEM packet
  167. mov [bx].Len, 11 ; length of entire packet
  168. mov BYTE PTR [bx+10], EOT ; end of transmission
  169. ret
  170. Init_Mem ENDP
  171. MAIN_CODE ENDS
  172. END LibEntry