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.

225 lines
7.0 KiB

  1. ;***************************************************************************
  2. ;* DIAG.ASM
  3. ;*
  4. ;* Diagnostic-mode routines used to log interesting output to a log
  5. ;* file. Diagnostic mode is enabled/disabled through a command line
  6. ;* switch.
  7. ;*
  8. ;* Created by JonT starting 19 July 1991
  9. ;*
  10. ;***************************************************************************
  11. TITLE LOG - Diagnostic mode logging routines
  12. .xlist
  13. include kernel.inc
  14. .list
  15. .386p
  16. DataBegin
  17. externD lpWindowsDir
  18. externW cBytesWinDir
  19. externB szDiagStart
  20. externB szCRLF
  21. globalW fDiagMode,0 ;Set in LDBOOT.ASM
  22. szLogFileName DB 'BOOTLOG.TXT', 0
  23. szPath DB 128 DUP(0) ;Entire pathname to file
  24. IF KDEBUG
  25. externB szInitSpew
  26. ENDIF
  27. DataEnd
  28. externFP Int21Handler
  29. externFP OutputDebugString
  30. ;** Note that this goes in the fixed code segment
  31. sBegin CODE
  32. assumes CS,CODE
  33. ; DiagQuery
  34. ;
  35. ; Exported entry point that can be called to determine if in
  36. ; diagnostic mode. Returns TRUE iff in diagnostic mode.
  37. cProc DiagQuery, <FAR,PUBLIC>, <si,di,ds>
  38. cBegin
  39. SetKernelDS
  40. mov ax,fDiagMode ;Return the flag
  41. cEnd
  42. ; DiagOutput
  43. ;
  44. ; Exported entry point to allow a string to be written to the
  45. ; log file. The file is flushed after writing the string
  46. ; guaranteeing that it always gets in there in case we abort
  47. ; immediately after the call.
  48. cProc DiagOutput, <FAR,PUBLIC>, <si,di,ds>
  49. parmD lpstr
  50. localW wHandle
  51. cBegin
  52. SetKernelDS
  53. ;** Check for diag mode
  54. cmp fDiagMode,1 ;Diag mode?
  55. jne SHORT DO_End ;Nope, get out
  56. ;** Reopen the log file
  57. mov ah,3dh ;Create file call
  58. mov al,22h ;R/W, Deny W to others
  59. mov dx,dataOFFSET szPath ;File name pointer
  60. DOSCALL
  61. jc SHORT DO_Error ;Error, get out
  62. mov wHandle,ax ;Save the handle
  63. ;** Seek to the end
  64. mov ax,4202h ;Seek to end of file call
  65. mov bx,wHandle ;Get the file handle
  66. xor cx,cx ;0 bytes before end of file
  67. xor dx,dx
  68. DOSCALL
  69. jc SHORT DO_Error ;Error, get out
  70. ;** Get the length of the string
  71. xor cx,cx ;Get max length
  72. dec cx ; (0xffff)
  73. les di,lpstr ;Point to the string
  74. xor al,al ;Zero byte
  75. repnz scasb ;Find the zero byte
  76. neg cx ;Get the length
  77. dec cx
  78. dec cx
  79. IF KDEBUG
  80. ;** Spit to debug terminal in debug KERNEL
  81. push cx
  82. push WORD PTR lpstr[2]
  83. push WORD PTR lpstr[0]
  84. call OutputDebugString
  85. pop cx
  86. ENDIF
  87. ;** Write the string
  88. push ds ;Save our DS
  89. mov ah,40h ;Write file call
  90. mov bx,wHandle ;Get the handle
  91. lds dx,lpstr ;Get the buffer pointer
  92. UnsetKernelDS
  93. DOSCALL
  94. pop ds
  95. ResetKernelDS
  96. jnc SHORT DO_Close ;No problem
  97. DO_Error:
  98. mov fDiagMode,0 ;Clear diagnostic mode and close file
  99. ;** Close the file
  100. DO_Close:
  101. mov bx,wHandle ;Handle in BX
  102. or bx,bx ;File open?
  103. jz SHORT DO_End ;Nope, just get out
  104. mov ah,3eh ;Close file call
  105. DOSCALL
  106. DO_End:
  107. cEnd
  108. ; DiagInit
  109. ;
  110. ; Called from Bootstap (LDBOOT.ASM) and is used to create the log file
  111. ; and write the startup message to it.
  112. cProc DiagInit, <FAR,PUBLIC>, <ds,si,di>
  113. localW wHandle
  114. cBegin
  115. SetKernelDS
  116. smov es,ds ;Point to kernel DS with ES
  117. ;** Get the full path name
  118. mov di,dataOFFSET szPath ;Point to destination path
  119. mov cx,cBytesWinDir ;Get the length of the directory
  120. lds si,lpWindowsDir ;Point to the Windows directory
  121. UnsetKernelDS
  122. rep movsb ;Copy it
  123. smov ds,es ;Get DS back to kernel DS
  124. ResetKernelDS
  125. mov si,dataOFFSET szLogFileName ;Point to log file name
  126. cmp BYTE PTR [di - 1],'/' ;Check for trailing separator
  127. je SHORT DI_NoSeparator ;No separator needed
  128. mov al,'\' ;Get the other separator
  129. cmp [di - 1],al ;Check for other separator
  130. je SHORT DI_NoSeparator ;None needed
  131. stosb ;Put a '\' in
  132. DI_NoSeparator:
  133. lodsb ;Get the char
  134. stosb ;Write it
  135. or al,al ;Zero byte?
  136. jnz DI_NoSeparator ;No, loop for next char
  137. IF KDEBUG
  138. ;** Spit to debug terminal in debug KERNEL
  139. push ds
  140. push dataOFFSET szInitSpew
  141. call OutputDebugString ;Spit out the message
  142. push ds
  143. push dataOFFSET szPath ;Spit out log filename
  144. call OutputDebugString
  145. push ds
  146. push dataOFFSET szCRLF ;Write a CR/LF
  147. call OutputDebugString
  148. ENDIF
  149. ;** Try to open the file. If it exists, we use it as it
  150. mov ah,3dh ;Open file call
  151. xor cx,cx ;Normal file
  152. mov al,22h ;R/W, Deny W to others
  153. mov dx,dataOFFSET szPath ;File name pointer
  154. DOSCALL
  155. jc SHORT DI_Create ;Error, need to create file
  156. mov wHandle,ax ;Save the handle
  157. ;** Seek to the end
  158. mov ax,4202h ;Seek to end of file call
  159. mov bx,wHandle ;Get the file handle
  160. xor cx,cx ;0 bytes before end of file
  161. xor dx,dx
  162. DOSCALL
  163. jmps DI_CloseIt ;Close file now
  164. ;** Create the log file
  165. DI_Create:
  166. mov ah,3ch ;Create file call
  167. xor cx,cx ;Normal file
  168. mov dx,dataOFFSET szPath ;File name pointer
  169. DOSCALL
  170. mov wHandle,ax ;Save the handle
  171. ;** On error, disable logging
  172. jc SHORT DI_End ;Error, get out without enabling
  173. DI_CloseIt:
  174. mov fDiagMode,1 ;We're in diag mode now
  175. ;** Close the file (we reopen it on each call to DiagOutput)
  176. mov bx,wHandle ;Handle in BX
  177. mov ah,3eh ;Close file call
  178. DOSCALL
  179. ;** Now start the log file
  180. mov ax,dataOFFSET szDiagStart ;Point to the string
  181. cCall DiagOutput, <ds,ax> ;Start the file
  182. DI_End:
  183. cEnd
  184. sEnd
  185. END