先是注释:
;----------------------------------------------------------------------------
;
; I N T E R R U P T 1 4
;
; coreBiosSerialInterface - The BIOS serial interface supports the
; Intel 8250 Serial chip.
; Functions available are init, send, receive, and status.
;
;
; AH = 00 - Initialize Communications Port
; Entry: DX - COM adapter to initialize (0-3)
; AL - Initialization values
;
; 7 6 5 4 3 2 1 0
; Baud rate Parity stop bits Word length
; ---------------------------------------
; 000-110 00-None 0-1 10-7 Bits
; 001-150 01-Odd 1-2 11-8 Bits
; 010-300 10-None
; 011-600 11-Even
; 100-1200
; 101-2400
; 110-4800
; 111-9600
; Exit: AH - Line status
;
;
; AH = 01 - Send Character
; Entry: DX - Communication adapter number (0-3)
; AL - Character to send
; Exit: AH - Line Status
;
;
; AH = 02 - Receive Character
; Entry: DX - Communcation adapter number (0-3)
; Exit: AL - Character received
; AH - Line Status
;
;
; AH = 03 - Return Communication Status
; Entry: DX - Communication adapter number (0-3)
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
; AH = 04 - Extended Initialize (PS2 compatibility)
; Entry: DX - Communication adapter number (0-3)
; AL - Break
; 00H - No Break
; 01H - Break
; BH - Parity
; 00H - None
; 01H - Odd
; 02H - Even
; 03H - Stick parity odd
; 04H - Stick parity even
; BL - Stop Bit
; 00H - One
; 01H - Two if 6,7, or 8 bit word length
; One and one-half if 5 bit word length
; CH - Word Length
; 00H - 5 bits
; 01H - 6 bits
; 02H - 7 bits
; 03H - 8 bits
; CL - Baud Rates
; 00H - 110 baud
; 01H - 150 baud
; 02H - 300 baud
; 03H - 600 baud
; 04H - 1200 baud
; 05H - 2400 baud
; 06H - 4000 baud
; 07H - 9600 baud
; 08H - 19200 baud
;
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
; AH = 05 - Extended Communications Port Control (PS2 compatibility)
; Entry: AL = 0 Read modem control register
; DX - Communication adapter number (0-3)
; Exit BL = Modem control register
;
; Entry AL = 01 Write modem control register
; DX - Communication adapter number (0-3)
; BL - Modem Control Register
;
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
;============================================================================作者: saliwen302 时间: 2008-5-22 14:52 标题: 贴一段phoenix 的int 14h的code吧 2
这个是int 14h的入口函数,用来dispatch任务
;============================================================================
;
; DECLARE SERIAL COMMAND TABLE
;
PUBLIC coreSerialCmdTable
coreSerialCmdTable LABEL WORD
DW coreSerialInit
DW coreSerialSend
DW coreSerialReceive
DW coreSerialStatus
DW coreExtendedSerialInit
DW coreExtendedPortControl
coreBiosSerialInterface PROC FAR
sti
PUSH_REG_STACK ; Save regs, set BP
cmp ah, 05 ; Command out of range?
ja serialExit ; Yes - Don't do anything
cmp dx, 3 ; Requesting > COM4?
ja serialExit ; Yes - Don't do anything
mov ds, SegAddressBDA ; Access BIOS data area
mov bx, dx ; Get COM channel number
mov cl, bdaRS232TimeOut[bx] ; Get timeout value
shl bx, 1 ; Double for Base address
mov dx, bdaRS232Table[bx] ; Read base address for COM
or dx, dx ; Test for COM not available
jz serialExit ; Yes-Dont do anything
movzx bx, ah ; Save command number in BX
mov ah, cl ; Keep timeut in AH
shl bx, 1 ; Double for table offset
add dx, 04 ; Advance DX to MCR
call cs:coreSerialCmdTable[bx] ; Go perform command
serialExit:
mov BYTE PTR [bp].regStack.axReg + 1, ah ; Save line status in AH
POP_REG_STACK ; Restore callers registers
iret
coreBiosSerialInterface ENDP作者: saliwen302 时间: 2008-5-22 14:54 标题: 贴一段phoenix 的int 14h的code吧 3
两个macro,帮助理解程序:
;;---------------------------------------------------------------------------
;;
;; PUSH_REG_STACK - set up register stack
;;
;; Processing:
;; pushes all regs associated with register stack structure
;; copies SP to BP
;;
;; Usage:
;; PUSH_REG_STACK - to set up register stack
;; [bp].regStack.axReg - to reference AX register on regStack
;;
PUSH_REG_STACK MACRO
pusha
push es
push ds
mov bp, sp
ENDM
;;---------------------------------------------------------------------------
;;
;; POP_REG_STACK - restore regs from register stack
;;
;; Usage:
;; POP_REG_STACK - to restore regs from register stack
;;
POP_REG_STACK MACRO
pop ds
pop es
popa
ENDM作者: saliwen302 时间: 2008-5-22 14:55 标题: 贴一段phoenix 的int 14h的code吧 3
Init COM的代码,分为legacy init和extend mode init
;+---------------------------------------------------------------------------
;
; coreSerialInit - Initialize the specified RS232 channel.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; Initialization consists of programming the line control registers,
; the baud rate divisor, and clearing the interrupt enable register.
;
coreSerialInit PROC NEAR PUBLIC
and al, 01Fh ; Clear Baud bits from init
mov ch, al ; Save to restore w DLAB off
or al, 080h ; Set the DLAB bit on
dec dx ; Decrement to LCR (xFBH)
out dx, al ; Keep Stick and Set Break low
mov al, BYTE PTR [bp].regStack.axReg ; Get init byte again
mov cl, 05 ; Shift baud bits down
shr al, cl ; to bit 0 position
mov cl, al ; Save baud rate number
or al, al ; Are we setting 110 baud ?
mov ax, 417h ; Handle 110 baud special
jz setBaudRate ; Yes-Use value in AX
mov ax, 0600h ; Compute divisor based
shr ax, cl ; on baud rate number
setBaudRate:
xchg al, ah ; Get high divisor into AL
dec dx ; Move back to high divisor
dec dx ; located at xF9H.
out dx, al ; Write MSB of divisor
IODELAY
dec dx ; Move back to LSB of divisor
mov al, ah ; Get LSB divisor byte
out dx, al ; Write at xF8H.
add dx, 03 ; Advance to LCR
mov al, ch ; Get LCR value w/o DLAB set
out dx, al ; Write LCR (xFBH)
sub dx, 02 ; Go back to interrupt
mov al, 00 ; Dont allow any 8250
out dx, al ; interrupts occur
add dx, 03h ; Move to (LSR-1) (xFCH)
jmp coreSerialStatus ; Go return Line & Modem status
coreSerialInit ENDP
;+---------------------------------------------------------------------------
; coreExtendedSerialInit - For PS/2 Compatibility
; Extended communications port initialization.
;
; Entry:
; DX points to MCR
;
; Exit:
;
; Modified:
;
coreExtendedSerialInit PROC NEAR PUBLIC
mov cx, [bp].regStack.cxReg
cmp cl, 8
ja extendedSerialInitEx
xor ch, ch ; Retrieve the baud rate divisor
shl cx, 1 ; and set the baud rate.
mov di, cx
mov bx, baudDivisorTable[di]
dec dx ; Reference the line control register.
push ax
call setBd
pop ax
and al, 00000001b ; Use only the break/no break.
shl al, 6 ; Build the line control word. AL is
mov bx, [bp].regStack.bxReg
shl bl, 2 ; Break/no break, BL is stops,
or al, bl ; Doesn't match the control register's
mov cx, [bp].regStack.cxReg
or al, ch
mov bl, bh
and bx, 00000111b
or al, BYTE PTR BHTranslate[BX]
out dx, al ; Set LCR
IODELAY
sub dx, 02 ; Go back to interrupt
mov al, 00 ; Dont allow any 8250
out dx, al ; interrupts occur
add dx, 03h ; Move to MCR
ExtendedSerialInitEx:
jmp coreSerialStatus ; Go return Line & Modem status
coreExtendedSerialInit ENDP作者: saliwen302 时间: 2008-5-22 14:56 标题: 贴一段phoenix 的int 14h的code吧 4
然后是发送和接受
;+---------------------------------------------------------------------------
;
; coreSerialSend - Send specified character to 8250 Serial Device.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; Before the data is sent, CTS and DTR must be set and the tranmitter
; holding register must be empty.
;
coreSerialSend PROC NEAR PUBLIC
movzx cx, ah ; Set timeout in CX
mov al, 03h ; Set DTR and RTS
out dx, al ; Write to MCR (xFCH)
inc dx ; Advance to Modem status
inc dx ; register (MSR at xFEH)
sendWaitLoop:
push cx ; Save Timeout count
mov bx, 3030h ; Mask for CTS and DSR
mov cx, 8235h ; Wait for 1 sec
call coreIOstatus30us ; Wait for CTS and DSR
jz lsrTranReg
pop cx ; Restore count
loop sendWaitLoop ; Loop again if I/O timeout
jmp coreSerialTimeout
lsrTranReg:
pop cx
dec dx ; Else-Move back to LSR
transmitWait:
push cx ; Save timeout
mov bx, 2020h ; Wait for Transmit Reg empty
mov cx, 8235h
call coreIOstatus30us
pop cx ; Restore timeout
loopne transmitWait ; Go wait if not ready and time left
jnz coreserialTimeout ; Exit if error
serialTransmit:
sub dx, 05 ; Move back to Data reg (xF8H)
mov al, BYTE PTR [bp].regStack.axReg ; Get byte to send
out dx, al ; Send it to 8250
add dx, 05 ; Advance to LSR
jmp coreserialStatus1 ; Go return Line Status
;+---------------------------------------------------------------------------
;
; coreSerialReceive - Receive a character from the 8250.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; In order for a character to be received, DSR must be set in
; the modem status register and em status register and data ready must be set in the
; line status register. If the break key is pressed during the
; timeout period, then a premature timeout will occur.
;
coreSerialReceive PROC NEAR PUBLIC
movzx cx, ah ; Set timeout in CX
mov al, 01 ; Set DTR in MCR
out dx, al ; Write to Modem Control reg
inc dx ; Advance to modem status
inc dx ; register (MSR at xFEH)
dsrWaitLoop:
push cx ; Save timeout count
mov bx, 2020h ; Mask for DSR
mov cx, 8235h ; Wait for 1 sec
call coreIOstatus30us ; Wait for DSR - All registers
; are preserved across call
pop cx ; Restore count
jz checkLsrDataRdy
loop dsrWaitLoop ; Loop again if I/O timeout
jmp coreSerialTimeout ; Exit if error
checkLsrDataRdy:
dec dx ; Else-Decrement to LSR
in al, dx ; Read LSR
mov ah, al ; Save line status
and ah, 1Eh ; Isolate error bits
receiveWait:
push cx ; Save timeout
mov bx, 0101h ; Mask for Data Ready
mov cx, 8235h ; 1 sec wait
call coreIOstatus30us ; Wait for Data Ready - All registers
; are preserved across call
pop cx ; Restore timeout
loopne receiveWait ; Go wait if not ready and time left
jnz coreSerialTimeout ; Exit if error
coreDataReady:
sub dx, 05 ; Move back to data register
in al, dx ; Read character from line
mov BYTE PTR [bp].regStack.axReg, al ; Save character in AL
ret ; Return to caller
coreSerialReceive ENDP作者: saliwen302 时间: 2008-5-22 14:58 标题: 贴一段phoenix 的int 14h的code吧 5
取得当前COM状态的函数
;+---------------------------------------------------------------------------
;
; coreSerialStatus - Return the status of the line status register
; and the modem status register.
;
; Entry:
;
; Exit:
;
coreSerialStatus PROC NEAR PUBLIC
inc dx ; Advance to LSR
call coreSerialStatus1 ; Read status of registers
mov BYTE PTR [bp].regStack.axReg, al ; Save the Modem status in AL
ret
coreSerialStatus ENDP
;+---------------------------------------------------------------------------
;
; coreSerialStatus1 - Return the status of the line status register
; and the modem status register.
;
; Entry:
;
; Exit:
;
coreSerialStatus1 PROC NEAR PUBLIC
in al, dx ; Read Line Status register
mov ah, al ; Save line status in AH
inc dx ; Advance to Modem status reg
in al, dx ; Read modem status register
ret
coreSerialStatus1 ENDP作者: saliwen302 时间: 2008-5-22 14:59 最后一个函数,如果是用 ah=05 int 14h的话,就会到以下这个函数执行。
;+---------------------------------------------------------------------------
;
; coreExtendedPortControl - For PS/2 compatability
;
; Entry:
; DX points to MCR
;
; Exit:
;
coreExtendedPortControl PROC NEAR PUBLIC
cmp al, 1 ; Check function in range
je ecpcWrite ; If AL == 1, then WRITE requested.
jb ecpcRead ; If AL == 0, then READ requested.
ret
; the READ returns the contents of the Modem Control Port, of the Line Status
; Register, and of the Modem Status Register.
ecpcRead:
in al, dx ; Read it and
mov BYTE PTR [bp].regStack.bxReg, al
jmp ecpcExit
; the WRITE sets the contents of the Modem Control Register, and then returns
; the contents of the Modem Status Register and of the Line Status Register.
ecpcWrite:
mov al, BYTE PTR [bp].regStack.bxReg ; Get original bx
and al, 01Fh
out dx, al ; Set modem control
;+---------------------------------------------------------------------------
;
; coreIOStatus30us - Wait a specified time for an IO port status
;
; Entry:
; BH - Mask
; BL - Match
; CX - Time in 30us
; DX - IO Address
;
; Exit:
; ZF = 0 - Timed out waiting for desired status
; = 1 - Data value matched
;
; Modifies:
; Minor flags
;
; Process:
; This routine waits until either the specified port matches
; the desired state or for the specified time to expire.
;
coreIOStatus30us PROC NEAR PUBLIC
push ax
push ecx
mov cx, 1 ; Delay at least 15us
call coreDelayMin15us
pop cx
IOS30CheckEntry:
in al, dx ; AL := Current value of target port
and al, bh ; Eliminate don't care bits
cmp al, bl ; Remaining bits = expected pattern?
je IOS30GotStatus ; Yes-Exit check loop
loopd IOS30Check ; No -Repeat until timer expires