5,12 → 5,15 |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
format PE DLL native 0.05 |
entry START |
format MS COFF |
|
__DEBUG__ equ 1 |
__DEBUG_LEVEL__ equ 1 ; 1 = verbose, 2 = errors only |
DEBUG equ 1 |
|
include 'proc32.inc' |
include 'imports.inc' |
|
|
|
API_VERSION equ 0 |
UART_VERSION equ API_VERSION |
|
23,15 → 26,6 |
CURRENT_TASK equ (OS_BASE+0x0003000) |
|
|
section '.flat' readable writable executable |
|
include 'proc32.inc' |
include 'struct.inc' |
include 'macros.inc' |
include 'fdo.inc' |
include 'peimport.inc' |
|
|
struc APPOBJ ;common object header |
{ |
.magic dd ? ; |
39,12 → 33,30 |
.fd dd ? ;next object in list |
.bk dd ? ;prev object in list |
.pid dd ? ;owner id |
} |
}; |
|
virtual at 0 |
APPOBJ APPOBJ |
end virtual |
|
struc IOCTL |
{ .handle dd ? |
.io_code dd ? |
.input dd ? |
.inp_size dd ? |
.output dd ? |
.out_size dd ? |
} |
|
virtual at 0 |
IOCTL IOCTL |
end virtual |
|
DEBUG equ 1 |
|
DRV_ENTRY 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 |
94,7 → 106,7 |
MCR_RTS equ 0x02 ;0-> RTS=1, 1-> RTS=0 |
MCR_OUT_1 equ 0x04 ;0-> OUT1=1, 1-> OUT1=0 |
MCR_OUT_2 equ 0x08 ;0-> OUT2=1, 1-> OUT2=0; enable intr |
MCR_LOOP equ 0x10 ;loopback mode |
MCR_LOOP equ 0x10 ;lopback mode |
|
MSR_DCTS equ 0x01 ;delta clear to send |
MSR_DDSR equ 0x02 ;delta data set redy |
161,7 → 173,6 |
.xmit_free dd ? |
.xmit_top dd ? |
} |
|
virtual at 0 |
UART UART |
end virtual |
186,31 → 197,22 |
|
CONNECTION_SIZE equ 7*4 |
|
public START |
public service_proc |
public version |
|
;proc START c, state:dword |
; cmp [state], 1 |
section '.flat' code readable align 16 |
|
align 4 |
proc START c, state:dword |
DEBUGF 1, "Loading driver UART (entry at %x)...\n", START |
proc START stdcall, state:dword |
|
push esi ; [bw] ??? |
cmp [state], DRV_ENTRY |
cmp [state], 1 |
jne .stop |
|
mov esi, msg_start |
invoke SysMsgBoardStr |
|
mov eax, UART_SIZE |
invoke Kmalloc |
; invoke Kmalloc, UART_SIZE (1) -- failure |
; invoke Kmalloc, UART_SIZE (2) -- success |
; DEBUGF 1,"[UART.START] Kmalloc: UART_SIZE=%d eax=%d\n", UART_SIZE, eax |
call Kmalloc |
test eax, eax |
jz .fail |
|
DEBUGF 1, "Structure %x allocated\n", eax |
|
mov [com1], eax |
mov edi, eax |
mov ecx, UART_SIZE/4 |
221,7 → 223,7 |
mov eax, [com1] |
mov [eax+UART.base], COM_1_BASE |
|
invoke AllocKernelSpace, 32768 |
stdcall AllocKernelSpace, 32768 |
|
mov edi, [com1] |
mov edx, eax |
234,7 → 236,7 |
add eax, 8192 |
mov [edi+UART.xmit_top], eax |
|
invoke AllocPage |
call AllocPage |
test eax, eax |
jz .fail |
|
243,7 → 245,7 |
mov [page_tabs+edx*4], eax |
mov [page_tabs+edx*4+8], eax |
|
invoke AllocPage |
call AllocPage |
test eax, eax |
jz .fail |
|
251,7 → 253,7 |
mov [page_tabs+edx*4+4], eax |
mov [page_tabs+edx*4+12], eax |
|
invoke AllocPage |
call AllocPage |
test eax, eax |
jz .fail |
|
259,7 → 261,7 |
mov [page_tabs+edx*4+16], eax |
mov [page_tabs+edx*4+24], eax |
|
invoke AllocPage |
call AllocPage |
test eax, eax |
jz .fail |
|
280,22 → 282,11 |
mov eax, edi |
call uart_reset.internal ;eax= uart |
|
invoke AttachIntHandler, COM_1_IRQ, com_1_isr, dword 0 |
test eax, eax |
jnz @f |
DEBUGF 2, "Could not attach int handler (%x)\n", COM_1_IRQ |
jmp .fail |
|
@@: |
DEBUGF 1, "Attached int handler (%x)\n", COM_1_IRQ |
pop esi |
invoke RegService, sz_uart_srv, service_proc |
stdcall AttachIntHandler, COM_1_IRQ, com_1_isr, dword 0 |
stdcall RegService, sz_uart_srv, service_proc |
ret |
|
.fail: |
.stop: |
DEBUGF 2, "Failed\n" |
pop esi |
xor eax, eax |
ret |
endp |
321,6 → 312,7 |
|
align 4 |
proc service_proc stdcall, ioctl:dword |
|
mov ebx, [ioctl] |
mov eax, [ebx+io_code] |
cmp eax, PORT_WRITE |
357,14 → 349,15 |
.fail: |
or eax, -1 |
ret |
|
endp |
|
;restore handle |
;restore io_code |
;restore input |
;restore inp_size |
;restore output |
;restore out_size |
restore handle |
restore io_code |
restore input |
restore inp_size |
restore output |
restore out_size |
|
|
; param |
405,8 → 398,7 |
out dx, al ;clear DTR & RTS |
|
mov eax, esi |
; mov ebx, RATE_2400 |
mov ebx, RATE_115200 |
mov ebx, RATE_2400 |
mov ecx, LCR_8BIT+LCR_STOP_1 |
call uart_set_mode.internal |
|
621,7 → 613,7 |
shl ebx, 5 |
mov ebx, [CURRENT_TASK+ebx+4] |
mov eax, CONNECTION_SIZE |
invoke CreateObject |
call CreateObject |
pop esi ;uart |
test eax, eax |
jz .fail |
648,11 → 640,9 |
|
cmp [eax+APPOBJ.destroy], uart_close.destroy |
jne .fail |
|
.destroy: |
; DEBUGF 1, "[UART.destroy] eax=%x uart=%x\n", eax, [eax+CONNECTION.uart] |
push [eax+CONNECTION.uart] |
invoke DestroyObject ;eax= object |
call DestroyObject ;eax= object |
pop eax ;eax= uart |
test eax, eax |
jz .fail |
892,11 → 882,9 |
com_2_isr: |
mov ebx, [com2] |
jmp com_1_isr.get_info |
|
align 4 |
com_1_isr: |
mov ebx, [com1] |
|
.get_info: |
mov edx, [ebx+UART.base] |
add edx, IIR_REG |
922,7 → 910,6 |
|
align 4 |
isr_recieve: |
; DEBUGF 1, "[UART.isr_recieve] ebx=%x\n", ebx |
mov esi, [ebx+UART.base] |
add esi, LSR_REG |
mov edi, [ebx+UART.rcvr_wp] |
981,14 → 968,9 |
version dd (5 shl 16) or (UART_VERSION and 0xFFFF) |
|
sz_uart_srv db 'UART', 0 |
msg_start db 'Loading UART driver...',13,10,0 |
|
include_debug_strings ; All data wich FDO uses will be included here |
align 4 |
|
align 4 |
com1 rd 1 |
com2 rd 1 |
|
align 4 |
data fixups |
end data |