1 ;; -----------------------------------------------------------------------
3 ;; Copyright 2009 Intel Corporation; author: H. Peter Anvin
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;; (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
16 ;; Serial port IRQ code
18 ;; We don't know what IRQ, if any, we have, so map all of them...
32 push dword [cs:oldirq %+ n]
45 mov dx,[cs:SerialPort]
48 test al,1 ; Received data
54 retf ; Chain to next handler
58 mov ax,aux_seg + (aux.serial >> 4)
60 mov di,[cs:SerialHead]
62 mov dx,[cs:SerialPort] ; DX -> RDR
65 mov ah,[cs:FlowIgnore]
72 and di,serial_buf_size-1 ; Wrap around if necessary
73 cmp di,[cs:SerialTail] ; Would this cause overflow?
74 je .drop ; If so, just drop the data
75 mov [cs:SerialHead],di
78 test al,1 ; More data?
87 ; SerialIRQPort will generally track SerialPort, but will be 0 when an
88 ; IRQ service is not installed.
90 SerialIRQPort resw 1 ; Serial port w IRQ service
91 SerialHead resw 1 ; Head of serial port rx buffer
92 SerialTail resw 1 ; Tail of serial port rx buffer
95 IRQMask resw 1 ; PIC IRQ mask status
104 ; Save the old interrupt vectors
113 ; Install new interrupt vectors
119 add ax,serstub_irq1 - serstub_irq0
125 add ax,serstub_irq1 - serstub_irq0
129 mov [SerialIRQPort],bx
131 lea dx,[bx+5] ; DX -> LCR
132 mov al,03h ; Clear DLAB (should already be...)
135 lea dx,[bx+1] ; DX -> IER
136 mov al,1 ; Enable receive interrupt
140 ; Enable all ther interupt lines at the PIC. Some BIOSes
141 ; only enable the timer interrupts and other interrupts
142 ; actively in use by the BIOS.
144 in al,0xA1 ; Secondary PIC mask register
146 in al,0x21 ; Primary PIC mask register
151 xor ax,ax ; Remove all interrupt masks
166 mov bx,[SerialIRQPort]
170 lea dx,[bx+5] ; DX -> LCR
171 mov al,03h ; Clear DLAB (should already be...)
174 lea dx,[bx+1] ; DX -> IER
176 slow_out dx,al ; Clear IER
184 ; Restore the original interrupt vectors
194 mov [SerialIRQPort],ax ; No active interrupt system
203 call sirq_cleanup_nowipe
206 ; Just in case it might contain a password, erase the
207 ; serial port receive buffer...
208 mov ax,aux_seg + (aux.serial >> 4)
211 mov [cs:SerialHead],eax
212 mov cx,serial_buf_size >> 2