com driver

git-svn-id: svn://kolibrios.org@413 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-03-11 13:37:42 +00:00
parent 391818d48f
commit 8670b710f7
8 changed files with 740 additions and 805 deletions

View File

@ -216,11 +216,18 @@ sayerr:
push 0 push 0
pop es pop es
and word [es:0x9031], 0 and word [es:0x9031], 0
; \begin{Mario79}
; find HDD IDE DMA PCI device
; check for PCI BIOS
mov ax, 0xB101 mov ax, 0xB101
int 0x1A int 0x1A
jc .nopci jc .nopci
cmp edx, 'PCI ' cmp edx, 'PCI '
jnz .nopci jnz .nopci
; find PCI class code
; class 1 = mass storage
; subclass 1 = IDE controller
; a) class 1, subclass 1, programming interface 0x80
mov ax, 0xB103 mov ax, 0xB103
mov ecx, 1*10000h + 1*100h + 0x80 mov ecx, 1*10000h + 1*100h + 0x80
mov si, 0 ; device index = 0 mov si, 0 ; device index = 0

View File

@ -972,7 +972,9 @@ malloc_large:
align 4 align 4
init_malloc: init_malloc:
stdcall kernel_alloc, 0x20000 stdcall kernel_alloc, 0x20000
mov [mst.top], eax mov [mst.top], eax
mov [mst.topsize], 128*1024 mov [mst.topsize], 128*1024
mov dword [eax+4], (128*1024) or 1 mov dword [eax+4], (128*1024) or 1

View File

@ -452,13 +452,13 @@ align 4
proc page_fault_handler proc page_fault_handler
pushad pushad
push eax ; push eax
push edx ; push edx
mov edx, 0x400 ;bocsh ; mov edx, 0x400 ;bocsh
mov al,0xff ;bocsh ; mov al,0xff ;bocsh
out dx, al ;bocsh ; out dx, al ;bocsh
pop edx ; pop edx
pop eax ; pop eax
mov ebp, esp mov ebp, esp
mov eax, cr2 mov eax, cr2

View File

@ -22,6 +22,13 @@ DEBUG equ 1
DRV_ENTRY equ 1 DRV_ENTRY equ 1
DRV_EXIT equ -1 DRV_EXIT equ -1
THR_REG equ 0; x3f8 ;transtitter/reciever
IER_REG equ 1; x3f9 ;interrupt enable
IIR_REG equ 2; x3fA ;interrupt info
LCR_REG equ 3; x3FB ;line control
MCR_REG equ 4; x3FC ;modem control
LSR_REG equ 5; x3FD ;line status
MSR_REG equ 6; x3FE ;modem status
LCR_5BIT equ 0x00 LCR_5BIT equ 0x00
LCR_6BIT equ 0x01 LCR_6BIT equ 0x01
@ -63,7 +70,7 @@ IER_MSI equ 0x08 ;modem status interrupt
MCR_DTR equ 0x01 ;0-> DTR=1, 1-> DTR=0 MCR_DTR equ 0x01 ;0-> DTR=1, 1-> DTR=0
MCR_RTS equ 0x02 ;0-> RTS=1, 1-> RTS=0 MCR_RTS equ 0x02 ;0-> RTS=1, 1-> RTS=0
MCR_OUT_1 equ 0x04 ;0-> OUT1=1, 1-> OUT1=0 MCR_OUT_1 equ 0x04 ;0-> OUT1=1, 1-> OUT1=0
MCR_OUT_2 equ 0x08 ;0-> OUT2=1, 1-> OUT2=0 MCR_OUT_2 equ 0x08 ;0-> OUT2=1, 1-> OUT2=0 enable intr
MCR_LOOP equ 0x10 ;lopback mode MCR_LOOP equ 0x10 ;lopback mode
MSR_DCTS equ 0x01 ;delta clear to send MSR_DCTS equ 0x01 ;delta clear to send
@ -71,13 +78,6 @@ MSR_DDSR equ 0x02 ;delta data set redy
MSR_TERI equ 0x04 ;trailinh edge of ring MSR_TERI equ 0x04 ;trailinh edge of ring
MSR_DDCD equ 0x08 ;delta carrier detect MSR_DDCD equ 0x08 ;delta carrier detect
COM_THR equ 0x3f8 ;transtitter/reciever
COM_IER equ 0x3f9 ;interrupt enable
COM_IIR equ 0x3fA ;interrupt info
COM_LCR equ 0x3FB ;line control
COM_MCR equ 0x3FC ;modem control
COM_LSR equ 0x3FD ;line status
COM_MSR equ 0x3FE ;modem status
RATE_50 equ 0 RATE_50 equ 0
RATE_75 equ 1 RATE_75 equ 1
@ -99,62 +99,89 @@ RATE_38400 equ 16
RATE_57600 equ 17 RATE_57600 equ 17
RATE_115200 equ 18 RATE_115200 equ 18
COM_1 equ 0 COM_1 equ 1
COM_2 equ 1 COM_2 equ 2
COM_3 equ 2 COM_3 equ 3
COM_4 equ 3 COM_4 equ 4
COM_MAX equ 2 ;only two port supported
COM_1_BASE equ 0x3F8
COM_2_BASE equ 0x2F8
COM_1_IRQ equ 4 COM_1_IRQ equ 4
COM_2_IRQ equ 3 COM_2_IRQ equ 3
TRANSMIT equ 1
UART_CLOSED equ 0
UART_TRANSMIT equ 1
struc COMPORT struc UART
{ {
; .owner dd ? unused
.lock dd ?
.base dd ? .base dd ?
.lcr_reg dd ? .lcr_reg dd ?
.mcr_reg dd ? .mcr_reg dd ?
.rate dd ? .rate dd ?
.mode dd ? .mode dd ?
.state dd ? .state dd ?
.connection dd ?
.rcvr_rp dd ? .rcvr_rp dd ?
.rcvr_wp dd ? .rcvr_wp dd ?
.rcvr_free dd ? .rcvr_free dd ?
.rcvr_count dd ?
.xmit_rp dd ? .xmit_rp dd ?
.xmit_wp dd ? .xmit_wp dd ?
.xmit_free dd ? .xmit_free dd ?
.xmit_count dd ?
.xmit_buffer rb 128
.rcvr_buffer rb 128 .rcvr_buffer rb 128
.xmit_buffer rb 128
} }
virtual at 0 virtual at 0
COMPORT COMPORT UART UART
end virtual end virtual
COMPORT_SIZE equ 256+15*4 RCVR_OFFSET equ 14*4
XMIT_OFFSET equ (13*4*128)
UART_SIZE equ (256+13*4)
UART_VERSION equ 0x00000000 struc CONNECTION
{
.magic dd ? ;'CNCT'
.destroy dd ? ;internal destructor
.fd dd ? ;next object in list
.bk dd ? ;prev object in list
.pid dd ? ;owner id
init_com: .id dd ? ;reserved
mov eax, COMPORT_SIZE .uart dd ? ;uart pointer
}
virtual at 0
CONNECTION CONNECTION
end virtual
CONNECTION_SIZE equ 7*4
UART_VERSION equ 0x12345678 ;debug
init_uart_service:
mov eax, UART_SIZE
call malloc call malloc
test eax, eax test eax, eax
jz .fail jz .fail
mov [com1], eax mov [com1], eax
mov edi, eax mov edi, eax
mov ecx, COMPORT_SIZE/4 mov ecx, UART_SIZE/4
xor eax, eax xor eax, eax
cld cld
rep stosd rep stosd
call reset mov eax, [com1]
mov [eax+UART.base], COM_1_BASE
stdcall attach_int_handler, COM_1_IRQ, com_isr call uart_reset ;eax= uart
stdcall attach_int_handler, COM_1_IRQ, com_1_isr
stdcall reg_service, sz_uart_srv, uart_proc stdcall reg_service, sz_uart_srv, uart_proc
ret ret
.fail: .fail:
@ -191,30 +218,24 @@ proc uart_proc stdcall, ioctl:dword
jne @F jne @F
mov eax, [ebx+output] mov eax, [ebx+output]
mov eax, [eax]
mov [eax], dword UART_VERSION mov [eax], dword UART_VERSION
xor eax, eax xor eax, eax
ret ret
@@: @@:
cmp eax, PORT_OPEN cmp eax, PORT_OPEN
jne @F jne @F
call open_port
mov ebx, [ebx+input]
mov eax, [ebx]
call uart_open
mov ebx, [ioctl]
mov ebx, [ebx+output]
mov [ebx], ecx
ret ret
@@:
mov esi, [ebx+input] ;input buffer
mov esi, [ebx+input] call [uart_func+eax*4]
mov ecx, [esi]
mov edx, [com1]
cmp [edx+COMPORT.connection], ecx
je @F
mov edx, [com2]
cmp [edx+COMPORT.connection], ecx
jne .fail
mov edi, [ebx+output]
call [uart_func+eax*4] ;edx, esi, edi
ret ret
.fail: .fail:
or eax, -1 or eax, -1
ret ret
@ -229,57 +250,50 @@ restore output
restore out_size restore out_size
open_port:
ret
; param
; edx= port
; esi= input data
; edi= output data
;
; retval
; eax=0 success
; eax <>0 error
align 4
close_port:
call reset
mov [edx+COMPORT.connection], 0
xor eax, eax
ret
; set mode 2400 bod 8-bit ; set mode 2400 bod 8-bit
; disable DTR & RTS
; clear FIFO ; clear FIFO
; clear pending interrupts ; clear pending interrupts
;
; param
; eax= uart
align 4 align 4
reset: uart_reset:
mov eax, RATE_2400 mov esi, eax
mov ebx, LCR_8BIT+LCR_STOP_1 mov [eax+UART.state], UART_CLOSED
call set_mode mov edx, [eax+UART.base]
add edx, MCR_REG
xor eax, eax
out dx, al ;clear DTR & RTS
mov eax, esi
mov ebx, RATE_2400
mov ecx, LCR_8BIT+LCR_STOP_1
call uart_set_mode.internal
mov edx, [esi+UART.base]
add edx, IIR_REG
mov eax,FCR_EFIFO+FCR_CRB+FCR_CXMIT+FCR_FIFO_14 mov eax,FCR_EFIFO+FCR_CRB+FCR_CXMIT+FCR_FIFO_14
mov edx, COM_IIR
out dx, al out dx, al
.clear_RB: .clear_RB:
mov edx, COM_LSR mov edx, [esi+UART.base]
add edx, LSR_REG
in al, dx in al, dx
test eax, LSR_DR test eax, LSR_DR
jz @F jz @F
mov edx, COM_THR mov edx, [esi+UART.base]
in al, dx in al, dx
jmp .clear_RB jmp .clear_RB
@@: @@:
mov edx, [esi+UART.base]
add edx, IER_REG
mov eax,IER_RDAI+IER_THRI+IER_LSI mov eax,IER_RDAI+IER_THRI+IER_LSI
mov edx, COM_IER
out dx, al out dx, al
.clear_IIR: .clear_IIR:
mov edx, COM_IIR mov edx, [esi+UART.base]
add edx, IIR_REG
in al, dx in al, dx
test al, IIR_INTR test al, IIR_INTR
jnz .done jnz .done
@ -288,7 +302,8 @@ reset:
and eax, 3 and eax, 3
jnz @F jnz @F
mov edx, COM_MSR mov edx, [esi+UART.base]
add edx, MSR_REG
in al, dx in al, dx
jmp .clear_IIR jmp .clear_IIR
@@: @@:
@ -298,86 +313,83 @@ reset:
cmp eax, 2 cmp eax, 2
jne @F jne @F
mov edx, COM_THR mov edx, [esi+UART.base]
in al, dx in al, dx
jmp .clear_IIR jmp .clear_IIR
@@: @@:
mov edx, COM_LSR mov edx, [esi+UART.base]
add edx, LSR_REG
in al, dx in al, dx
jmp .clear_IIR jmp .clear_IIR
.done: .done:
mov edi, rcvr_buff lea edi, [esi+UART.rcvr_buffer]
xor eax, eax
mov ecx, 256/4 mov ecx, 256/4
xor eax, eax
mov [rcvr_rp], edi mov [esi+UART.rcvr_rp], eax
mov [rcvr_wp], edi mov [esi+UART.rcvr_wp], eax
mov [rcvr_free], 128 mov [esi+UART.rcvr_free], 128
;; mov [rcvr_count], 16 mov [esi+UART.xmit_rp], eax
mov [esi+UART.xmit_wp], eax
mov [xmit_rp], xmit_buff mov [esi+UART.xmit_free], 128
mov [xmit_wp], xmit_buff
mov [xmit_free], 128
mov [xmit_count], 16 ;FIFO free
cld cld
rep stosd rep stosd
ret ret
; param ; param
; eax= rate constant ; esi= input buffer
; ebx= mode bits ; +0 connection
; +4 rate
; +8 mode
;
; retval
; eax= error code
align 4 align 4
set_mode: uart_set_mode:
cmp eax, RATE_115200 mov eax, [esi]
cmp [eax+APPOBJ.magic], 'CNCT'
jne .fail
cmp [eax+APPOBJ.destroy], uart_close.destroy
jne .fail
mov eax, [eax+CONNECTION.uart]
test eax, eax
jz .fail
mov ebx, [esi+4]
mov ecx, [esi+8]
; param
; eax= uart
; ebx= baud rate
; ecx= mode
align 4
.internal:
cmp ebx, RATE_115200
ja .fail ja .fail
cmp ebx, LCR_BREAK cmp ecx, LCR_BREAK
jae .fail jae .fail
mov [rate], eax mov [eax+UART.rate], ebx
mov [mode], ebx mov [eax+UART.mode], ecx
mov cx, [divisor+eax*2] mov esi, eax
mov bx, [divisor+ebx*2]
mov dx, COM_LCR mov edx, [esi+UART.base]
push edx
add edx, LCR_REG
in al, dx in al, dx
or al, 0x80 or al, 0x80
out dx, al out dx, al
mov dx, COM_THR pop edx
mov al, cl
out dx, al
inc dx
mov al, ch
out dx, al
mov dx, COM_LCR
mov eax, ebx
out dx, al
.fail:
ret
; param
; eax= rate constant
align 4
set_rate:
cmp eax, RATE_115200
ja .fail
mov [rate], eax
mov bx, [divisor+eax*2]
mov dx, COM_LCR
in al, dx
or al, 0x80
out dx, al
mov dx, COM_THR
mov al, bl mov al, bl
out dx, al out dx, al
@ -385,104 +397,251 @@ set_rate:
mov al, bh mov al, bh
out dx, al out dx, al
mov dx, COM_LCR add edx, LCR_REG-1
mov eax, [lcr_reg] mov eax, ecx
out dx, al
xor eax, eax
ret
.fail:
or eax, -1
ret
align 4
uart_set_modem:
mov [eax+UART.mcr_reg], ebx
mov edx, [eax+UART.base]
add edx, MCR_REG
mov al, bl
out dx, al
ret
; param
; eax= port
;
; retval
; ecx= connection
; eax= error code
align 4
uart_open:
dec eax
cmp eax, COM_MAX
jae .fail
mov esi, [com1+eax*4] ;uart
push esi
.do_wait:
cmp dword [esi+UART.lock],0
je .get_lock
call change_task
jmp .do_wait
.get_lock:
mov eax, 1
xchg eax, [esi+UART.lock]
test eax, eax
jnz .do_wait
mov eax, esi ;uart
call uart_reset
mov ebx, [CURRENT_TASK]
shl ebx, 5
mov ebx, [CURRENT_TASK+ebx+4]
mov eax, CONNECTION_SIZE
call create_kernel_object
pop esi ;uart
test eax, eax
jz .fail
mov [eax+APPOBJ.magic], 'CNCT'
mov [eax+APPOBJ.destroy], uart_close.destroy
mov [eax+CONNECTION.uart], esi
mov ecx, eax
xor eax, eax
ret
.fail:
or eax, -1
ret
restore .uart
; param
; esi= input buffer
align 4
uart_close:
mov eax, [esi]
cmp [eax+APPOBJ.magic], 'CNCT'
jne .fail
cmp [eax+APPOBJ.destroy], uart_close.destroy
jne .fail
.destroy:
push [eax+CONNECTION.uart]
call destroy_kernel_object ;eax= object
pop eax ;eax= uart
test eax, eax
jz .fail
mov [eax+UART.state], UART_CLOSED
mov [eax+UART.lock], 0 ;release port
xor eax, eax
ret
.fail:
or eax, -1
ret
; param
; eax= uart
; ebx= baud rate
align 4
set_rate:
cmp ebx, RATE_115200
ja .fail
mov [eax+UART.rate], ebx
mov bx, [divisor+ebx*2]
mov edx, [eax+UART.base]
add edx, LCR_REG
in al, dx
push eax
or al, 0x80
out dx, al
sub edx, LCR_REG
mov al, bl
out dx, al
inc edx
mov al, bh
out dx, al
pop eax
add edx, LCR_REG-1
out dx, al out dx, al
.fail: .fail:
ret ret
; param
; ebx= uart
align 4 align 4
transmit: transmit:
push esi push esi
mov edx, COM_THR push edi
push ebp
mov [xmit_count], 16 mov edx, [ebx+UART.base]
pushfd pushfd
cli cli
mov esi, [xmit_rp] mov ebp, 16
mov ecx, [xmit_free] mov esi, [ebx+UART.xmit_rp]
lea edi, [ebx+UART.xmit_buffer]
mov ecx, [ebx+UART.xmit_free]
cmp ecx, 128 cmp ecx, 128
je .exit je .exit
@@: @@:
and esi, 127 and esi, 127
mov al, [xmit_buff+esi] mov al, [esi+edi]
inc esi inc esi
out dx, al out dx, al
inc ecx inc ecx
dec [xmit_count] dec ebp
jz .done jz .done
cmp ecx, 128 cmp ecx, 128
jne @B jne @B
.done: .done:
add esi, xmit_buff mov [ebx+UART.xmit_rp], esi
mov [xmit_rp], esi mov [ebx+UART.xmit_free], ecx
mov [xmit_free], ecx mov [ebx+UART.state], UART_TRANSMIT
mov [com_state], TRANSMIT
.exit: .exit:
popfd popfd
pop ebp
pop edi
pop esi pop esi
ret ret
; param
; eax= src ; eax= uart
; ebx= count ; ebx= src
; edx= count
align 4 align 4
comm_send: uart_write:
mov edi, [xmit_wp] mov esi, ebx
mov esi, eax mov edi, [eax+UART.xmit_wp]
lea ebx, [eax+UART.xmit_buffer]
.write: .write:
test ebx, ebx test edx, edx
jz .done jz .done
.wait: .wait:
cmp [xmit_free], 0 cmp [eax+UART.xmit_free], 0
jne .fill jne .fill
cmp [com_state], TRANSMIT cmp [eax+UART.state], UART_TRANSMIT
je .wait je .wait
mov ebx, eax
push edx
call transmit call transmit
pop edx
mov eax, ebx
lea ebx, [ebx+UART.xmit_buffer]
jmp .write jmp .write
.fill: .fill:
mov ecx, xmit_buff+128 mov ecx, 128
sub ecx, edi sub ecx, edi
cmp ecx, [xmit_free] jz .clip
jb @F cmp ecx, [eax+UART.xmit_free]
jbe @F
mov ecx, [xmit_free] mov ecx, [eax+UART.xmit_free]
@@: @@:
cmp ecx, ebx cmp ecx, edx
jb @F jbe @F
mov ecx, ebx mov ecx, edx
@@: @@:
sub [xmit_free], ecx sub [eax+UART.xmit_free], ecx
sub ebx, ecx sub edx, ecx
add edi, ebx
cld cld
rep movsb rep movsb
cmp edi, xmit_buff+128 sub edi, ebx
jb .write .clip:
sub edi, 128 and edi, 127
jmp .write jmp .write
.done: .done:
cmp [com_state], TRANSMIT mov [eax+UART.xmit_wp], edi
cmp [eax+UART.state], UART_TRANSMIT
je @F je @F
mov ebx, eax
call transmit call transmit
@@: @@:
ret ret
align 4 align 4
com_isr: com_2_isr:
mov ebx, [com2]
jmp com_1_isr.get_info
align 4
com_1_isr:
mov ebx, [com1]
.get_info: .get_info:
mov dx, COM_IIR mov edx, [ebx+UART.base]
add edx, IIR_REG
in al, dx in al, dx
test al, IIR_INTR test al, IIR_INTR
@ -498,28 +657,42 @@ com_isr:
align 4 align 4
isr_line: isr_line:
mov edx, COM_LSR mov edx, [ebx+UART.base]
add edx, LSR_REG
in al, dx in al, dx
ret ret
align 4 align 4
isr_recieve: isr_recieve:
mov edx, COM_THR mov edx, [ebx+UART.base]
in al, dx in al, dx
ret ret
align 4 align 4
isr_modem: isr_modem:
mov edx, COM_MSR mov edx, [ebx+UART.base]
in al, dx add edx, MSR_REG
ret in al, dx
ret
align 4 align 4
uart_func dd 0 ;get version com1 dd 0
dd 0 ;open port com2 dd 0
dd close_port
align 4
uart_func dd 0 ;SRV_GETVERSION
dd 0 ;PORT_OPEN
dd uart_close ;PORT_CLOSE
dd 0 ;PORT_RESET
dd uart_set_mode ;PORT_SETMODE
; dd uart.get_mode ;PORT_GETMODE
; dd uart.set_mcr ;PORT_SETMCR
;PORT_GETMCR equ 7
;PORT_READ equ 8
;PORT_WRITE equ 9
isr_action dd isr_modem isr_action dd isr_modem
@ -527,6 +700,7 @@ isr_action dd isr_modem
dd isr_recieve dd isr_recieve
dd isr_line dd isr_line
;version dd 0x00040000
divisor dw 2304, 1536, 1047, 857, 768, 384 divisor dw 2304, 1536, 1047, 857, 768, 384
dw 192, 96, 64, 58, 48, 32 dw 192, 96, 64, 58, 48, 32
@ -536,33 +710,5 @@ divisor dw 2304, 1536, 1047, 857, 768, 384
sz_uart_srv db 'UART',0 sz_uart_srv db 'UART',0
;version dd 0x00040000
align 4
com1 dd ?
com2 dd ?
rcvr_rp dd ?
rcvr_wp dd ?
rcvr_free dd ?
rcvr_count dd ?
xmit_rp dd ?
xmit_wp dd ?
xmit_free dd ?
xmit_count dd ?
lcr_reg dd ?
mcr_reg dd ?
rate dd ?
mode dd ?
com_state dd ?
connection dd ?
align 128
rcvr_buff rb 128
xmit_buff rb 128

File diff suppressed because it is too large Load Diff

View File

@ -1893,7 +1893,6 @@ fs_FloppyRewrite:
dec edi dec edi
dec edi dec edi
; lea eax, [edi-FLOPPY_FAT]
mov eax, edi mov eax, edi
sub eax, FLOPPY_FAT sub eax, FLOPPY_FAT

View File

@ -721,23 +721,13 @@ first_app_found:
cmp [IDEContrRegsBaseAddr], 0 cmp [IDEContrRegsBaseAddr], 0
setnz [dma_hdd] setnz [dma_hdd]
;if 0 call init_uart_service
call init_com
mov eax, msg_com
mov ebx, 46
call comm_send
;end if
sti sti
jmp $ ; wait here for timer to take control jmp $ ; wait here for timer to take control
; Fly :) ; Fly :)
;if 0
msg_com db 'com1 port message ',0x0D, 0x0A
db 'test comm_send() function',0
;end if
include 'unpacker.inc' include 'unpacker.inc'
include 'fdo.inc' include 'fdo.inc'

View File

@ -263,9 +263,9 @@ include "video/cursors.inc" ; cursors functions
; Network Interface & TCPIP Stack ; Network Interface & TCPIP Stack
include "network/stack.inc" include "network/stack.inc"
;if 0
include "drivers/comport.asm" include "drivers/comport.asm"
;end if
; Mouse pointer ; Mouse pointer