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.

488 lines
18 KiB

  1. TITLE Hangeul/Hanja Console Device Driver Header
  2. page ,132
  3. ;****************************************************************************;
  4. ; (C)Copyright Qnix Co., Ltd., 1985-1991. ;
  5. ; This program contains proprietary and confidential information. ;
  6. ; All rights reserved. ;
  7. ;****************************************************************************;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;; File name: HECON.ASM
  10. ;; Description:
  11. ;; These routine are the header of HECON.SYS which is Installable
  12. ;; Device Driver that is the console device driver to handle
  13. ;; Hangeul/Hanja console IO services
  14. ;;
  15. ;; Called routine:
  16. ;; HAN_INIT - procedure in INIT.ASM file
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. .sall ; supress macro listings
  19. BreakInt equ 1bH * 4
  20. ;
  21. ;------------------------------------------------------------------------
  22. ; MACRO DEFINITION ;
  23. ;------------------------------------------------------------------------
  24. ; Given a label <lbl> generate either 2 byte jump to another label <lbl>_J
  25. ; if it is near enough or 3 byte jump to <lbl>
  26. ;
  27. Jump macro lbl
  28. local a
  29. .xcref
  30. ifndef lbl&_J ; is this the first invocation
  31. a: jmp lbl
  32. else
  33. if (lbl&_J GE $) or ($-lbl&_J GT 126)
  34. a: jmp lbl ; is the jump too far away?
  35. else
  36. a: jmp lbl&_J ; do the short one...
  37. endif
  38. endif
  39. lbl&_j = a
  40. .cref
  41. endm
  42. .xcref Jump
  43. ;------------------------------------------------------------------------
  44. code segment public byte 'code'
  45. assume cs:code, ds:code
  46. INCLUDE EQU.INC
  47. if ComFile
  48. org 100h
  49. extrn HanInit:near
  50. HeconStart:
  51. jmp HanInit
  52. else
  53. HeconStart: ; dummy
  54. ; start of HECON.SYS routine
  55. public ConHeader
  56. ConHeader label word
  57. dw -1,-1 ; pointer to next device
  58. dw 1000000001010011B ; con-in and con-out + special
  59. dw Strategy ; strategy entry point
  60. dw ConIO ; interrupt entry point
  61. db 'CON ' ; device name
  62. ConTbl:
  63. db 13h
  64. dw ConInit ;0
  65. dw Exit ;1
  66. dw Exit ;2
  67. dw CmdErr ;3
  68. dw ConRead ;4
  69. dw ConCheck ;5
  70. dw Exit ;6
  71. dw ConFlush ;7
  72. dw ConWrite ;8
  73. dw ConWrite ;9
  74. dw Exit ;A
  75. dw Exit ;B
  76. if hdos60
  77. dw Exit ;C
  78. dw Exit ;D
  79. dw Exit ;E
  80. dw Exit ;F
  81. dw Exit ;10H
  82. dw Exit ;11H
  83. dw Exit ;12H
  84. dw GenIoctl ;13H
  85. dw Exit ;14H
  86. endif ; hdos60
  87. page
  88. ;
  89. ; The next nine equ's describe the offset into the request header for
  90. ; different information. For example STATUS is in byte 3 of the request
  91. ; header (starting count at zero).
  92. ;
  93. CmdLen = 0 ; length of this command
  94. Unit = 1 ; sub unit specifier
  95. Cmd = 2 ; command code
  96. Status = 3 ; status
  97. Media = 13 ; media descriptor
  98. Trans = 14 ; transfer address
  99. Count = 18 ; count of blocks or characters
  100. Start = 20 ; first block to transfer
  101. Extra = 22 ; Usually pointer to Vol Id for err 15
  102. if hdos60
  103. ; Bilingual implementation
  104. WansungCode = 949
  105. ChohabCode = 1361
  106. EnglishCode = 437
  107. SetCode = 04ah
  108. IoctlReq struc
  109. db 13 dup(?)
  110. MajorCode db ?
  111. MinorCode db ?
  112. SiReg dw ?
  113. DiReg dw ?
  114. DataBuf dd ?
  115. IoctlReq ends
  116. endif ; hdos60
  117. ;
  118. ; PtrSav - pointer save
  119. ;
  120. ; This variable holds the pointer to the Request Header passed by a program
  121. ; wishing to use a device driver. When the strategy routine is called
  122. ; it puts the address of the Request header in this variable and returns.
  123. ;
  124. public PtrSav
  125. PtrSav dd 0
  126. Foo proc far
  127. Strategy:
  128. mov word ptr cs:[PtrSav],bx
  129. mov word ptr cs:[PtrSav+2],es
  130. ret
  131. Foo endp
  132. ;
  133. ; This section is the prolog to all default device drivers. All registers
  134. ; are saved, the registers are filled with information fromthe request header,
  135. ; and the routine from the jump table is called. Error checking is done
  136. ; to assure command code is valid. Before calling the routine in the
  137. ; jump table the register are:
  138. ;
  139. ; AH = Media Descriptor
  140. ; BX = offset to PtrSav (request header is therefore at DS:BX)
  141. ; CX = count from request header
  142. ; DS:SI = tranfer address
  143. ;
  144. ; Once the routine finishes its job it jumps back to one of the eight
  145. ; pieces of code below labeled Exit Points.
  146. ;
  147. ;------------------------------------------------------------------------
  148. ;
  149. ; Device entry point
  150. ;
  151. ; The following ten pieces of code are the interrupt entry points for the
  152. ; default device drivers. These small pieces of code have two jobs.
  153. ;
  154. ; 1) Make SI point to the beginning of the proper command jump table.
  155. ; SI must first be pushed to preserve original contents.
  156. ;
  157. ; Con device:
  158. ;
  159. ConIO:
  160. Entry:
  161. sti ; enable interrupts
  162. push ax ; save all registers
  163. push bx
  164. push cx
  165. push si
  166. push ds
  167. mov si,offset ConTbl ; get pointer to console IO table
  168. lds bx,cs:[PtrSav] ; get pointer to I/O packet
  169. mov cx,ds:[bx].Count ; cx = count
  170. mov al,ds:[bx].Cmd
  171. cmp al,cs:[si] ; is command code a valid number?
  172. ja CmdErr ; no, jump to handle error
  173. cbw ; note that al <= 15 means OK
  174. shl ax,1
  175. inc si
  176. add si,ax ; get di to point to address of routine
  177. mov ah,ds:[bx].Media ; ah = media descriptor
  178. shr ah,1
  179. shr ah,1
  180. jmp word ptr cs:[si] ; go to the command
  181. page
  182. ;------------------------------------------------------------------------
  183. ;
  184. ; Exit Points
  185. ;
  186. ; All device driver call return through one of these eight
  187. ; pieces of code. The code set error and status conditions
  188. ; and then restores the registers.
  189. ;
  190. CmdErr:
  191. ; sub [bx].Count,cx ; # of successful I/O's
  192. mov ax,1000000100000011B ; mark error(unknown command) & return
  193. jmp short Exit1
  194. BusyExit: ; device busy exit
  195. mov ah,00000011B ; set error code
  196. jmp short Exit1
  197. Exit:
  198. mov ah,00000001B
  199. Exit1: lds bx,cs:[PtrSav]
  200. Exit2: and ah,11111011b
  201. mov [bx].Status,ax ; mark operation complete
  202. pop ds ; restore register and return
  203. pop si
  204. pop cx
  205. pop bx
  206. pop ax
  207. FarRet1 proc far
  208. ret
  209. FarRet1 endp
  210. ;------------------------------------------------------------------------
  211. ; ;
  212. ; C O N - Console Device Driver ;
  213. ; ;
  214. ;------------------------------------------------------------------------
  215. ;
  216. ; Device Header for the CON Device Driver
  217. ;
  218. ; ALTAH is a single character buffer used to handle special keys.
  219. ;
  220. AltAH db 0 ; Special key handling
  221. ;------------------------------------------------------------------------
  222. ; ;
  223. ; Console Read routine ;
  224. ; ;
  225. ;------------------------------------------------------------------------
  226. ConRead:
  227. jcxz ConReadExit ; to be read -- just exit
  228. lds si,ds:[bx].Trans ; get ds:si to point to trans addr
  229. test ah,00000001B
  230. jnz ConReadNonDisp
  231. mov bx,0 ; get complete char code
  232. ConReadLoop:
  233. call CharIn ; get char in al
  234. mov ds:[si],al ; store char at ds:si, specified buffer
  235. inc si ; point to next buffer position
  236. loop ConReadLoop ; if cx is non-zero more char to read
  237. ConReadExit:
  238. Jump Exit ; all done, successful return
  239. ConReadNonDisp:
  240. mov bx,(240 shl 8) ; get interim char code
  241. cmp cx,1
  242. jne ConReadNonDispLoop
  243. call CharIn ; get char in al
  244. mov ds:[si],al ; store char at ds:si, specified buffer
  245. inc si ; point to next buffer position
  246. cmp ah,0f0H ; interim char?
  247. jne ConReadExit ; jump no
  248. mov ah,00000101B ; indicate interim char
  249. Jump Exit1
  250. ConReadNonDispLoop:
  251. call CharIn ; get char in al
  252. cmp ah,0f0H ; interim char?
  253. je ConReadNonDispLoop ; jump so
  254. mov ds:[si],al ; store char at ds:si, specified buffer
  255. inc si ; point to next buffer position
  256. loop ConReadNonDispLoop ; if cx is non-zero more char to read
  257. Jump Exit
  258. ;------------------------------------------------------------------------
  259. ; ;
  260. ; Input single character into AL ;
  261. ; ;
  262. ;------------------------------------------------------------------------
  263. CharIn:
  264. xor ax,ax ; set cmd and clear al
  265. xchg al,cs:[AltAH] ; get character & zero AltAH
  266. or al,al ; see if buffer has a character
  267. jnz CharInRet ; if so - return this character
  268. mov ax,bx
  269. int 16H ; call ROM-Bios keyboard routine
  270. or ax,ax ; Check for non-key after BREAK
  271. jz CharIn
  272. cmp ax,7200H ; Check for Ctrl-PrtSc
  273. jnz CharInOk
  274. mov al,16 ; indicate prtsc
  275. CharInOk:
  276. or al,al ; special case?
  277. jnz CharInRet ; no, return with character
  278. mov cs:[AltAH],ah ; yes, store special key
  279. CharInRet:
  280. ret
  281. ;----------------------------------------------------------------
  282. ; :
  283. ; Keyboard non destructive read, no wait :
  284. ; :
  285. ; If bit 10 is set by the DOS in the status word of the request :
  286. ; packet, and there is no character in the input buffer, the :
  287. ; driver issues a system WAIT request to the ROM. On return :
  288. ; from the ROM, it returns a 'char-not-found' to the DOS. :
  289. ; :
  290. ;----------------------------------------------------------------
  291. ConCheck:
  292. mov al,cs:[AltAH] ; first see if there is a
  293. or al,al ; character in the buffer?
  294. jnz ConCheckExit ; yes, return that character
  295. ; no, continue
  296. mov bx,(1 shl 8)
  297. test ah,00000001B
  298. jz ReConCheck ; jump if wanted complete char code
  299. mov bx,(241 shl 8)
  300. ReConCheck:
  301. mov ax,bx
  302. int 16H ; call ROM-BIOS keyboard routine
  303. jz ConBusy ; not available char, jump to busy
  304. or ax,ax ; check for null after break
  305. jnz ConCheckOk ; no, skip down
  306. ; note: AH is already zero, no need to set command
  307. int 16H ; yes, read the null
  308. jmp short ReConCheck
  309. ConCheckOk:
  310. cmp ah,0f0H ; incomplete scan code?
  311. jnz ConCheckFinal
  312. lds bx,cs:[PtrSav] ; get pointer to request header
  313. mov [bx].Media,al ; move character into req. header
  314. mov ah,00000101B ; indicate interim char
  315. Jump Exit2
  316. ConCheckFinal:
  317. cmp ax,7200H ; check for Ctrl-PrtSc
  318. jnz ConCheckExit ; no
  319. mov al,16 ; yes, indicate Ctrl-PrtSc
  320. ConCheckExit:
  321. lds bx,cs:[PtrSav] ; get pointer to request header
  322. mov [bx].Media,al ; move character into req. header
  323. Jump Exit ; all done -- successful return
  324. ConBusy:
  325. Jump BusyExit ; done -- con device is busy
  326. ;----------------------------------------------------------------
  327. ; :
  328. ; Keyboard flush routine :
  329. ; :
  330. ;----------------------------------------------------------------
  331. ConFlush:
  332. mov cs:[AltAH],0 ; clear out holding buffer
  333. mov ah,243 ; Keyboard flush entry
  334. int 16H
  335. Jump Exit
  336. ;----------------------------------------------------------------
  337. ; :
  338. ; Console Write Routine :
  339. ; :
  340. ;----------------------------------------------------------------
  341. ConWrite:
  342. cld ; clear the direction flag
  343. jcxz ConWriteExit ; if cx is zero, get out
  344. lds si,ds:[bx].Trans ; get ds:si to point to trans addr
  345. mov bx,7 ; set page #(bh), foreground color(bl)
  346. test ah,00000001B
  347. jnz ConWriteLoopNac ; output character & no cursor advance
  348. ConWriteLoop:
  349. lodsb ; get character
  350. mov ah,0eH ; write char with cursor advancing
  351. int 10H ; call bios
  352. loop ConWriteLoop ; repeat until all through
  353. ConWriteExit:
  354. mov ah,00000001B
  355. lds bx,cs:[PtrSav]
  356. mov [bx].Status,ax ; mark operation complete
  357. pop ds ; restore register and return
  358. pop si
  359. pop cx
  360. pop bx
  361. pop ax
  362. FarRet2 proc far
  363. ret
  364. FarRet2 endp
  365. ConWriteLoopNac:
  366. lodsb ; get character
  367. mov ah,0feH ; write char w/o cursor advancing
  368. int 10H ; call bios
  369. loop ConWriteLoopNac ; repeat until all through
  370. Jump Exit
  371. ;------------------------------------------------
  372. ;
  373. ; CONSOLE INIT ROUTINE
  374. ;
  375. ;------------------------------------------------
  376. ConInit:
  377. push dx ; save registers
  378. ; patch the BREAK key handling interrupt routine
  379. sub ax,ax
  380. mov ds,ax
  381. mov bx,BreakInt
  382. mov ax,offset cBreak
  383. mov dx,cs
  384. cli
  385. mov ds:[bx],ax
  386. mov ds:[bx+2],dx
  387. sti
  388. extrn HanInit:near
  389. call HanInit
  390. ;
  391. ; Now, CX:DX points to the end of HECON.SYS resident part
  392. ;
  393. lds bx,cs:[PtrSav]
  394. mov [bx].Trans,dx
  395. mov [bx].Trans+2,cx
  396. pop dx ; restore registers
  397. Jump Exit
  398. ;-----------------------------------------------------------------------
  399. ;
  400. ; BREAK KEY HANDLING
  401. ;
  402. ;-----------------------------------------------------------------------
  403. cBreak:
  404. mov cs:[AltAH],3 ; indicate break key set
  405. push ax ; save register
  406. mov ah,243 ; keyboard flush
  407. int 16H
  408. pop ax ; recover register
  409. iret
  410. if hdos60
  411. ;
  412. ; Bilingual implementation
  413. ;
  414. extrn ChangeCodeR:near
  415. GenIoctl:
  416. mov al,ds:[bx.MinorCode]
  417. cmp al,SetCode
  418. je @f
  419. jmp CmdErr
  420. @@:
  421. push bx
  422. push es
  423. push dx
  424. les bx,ds:[bx.DataBuf]
  425. mov ax,es:[bx+2]
  426. mov dl,0
  427. cmp ax,WansungCode
  428. je CallChange
  429. mov dl,1
  430. cmp ax,ChohabCode
  431. je CallChange
  432. mov dl,2
  433. cmp ax,EnglishCode
  434. je CallChange
  435. pop dx
  436. pop es
  437. pop bx
  438. jmp CmdErr
  439. CallChange:
  440. mov al,dl
  441. call ChangeCodeR
  442. pop dx
  443. pop es
  444. pop bx
  445. jmp Exit
  446. endif ; hdos60
  447. endif ; if ComFile
  448. code ends
  449. end HeconStart