Rev 5363 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5363 | Rev 8384 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
8 | format MS COFF |
- | |
9 | - | ||
10 | DEBUG equ 1 |
- | |
11 | 8 | format PE DLL native 0.05 |
|
12 | include 'proc32.inc' |
- | |
13 | include 'imports.inc' |
- | |
Line -... | Line 9... | ||
- | 9 | entry START |
|
- | 10 | ||
Line 14... | Line 11... | ||
14 | 11 | __DEBUG__ equ 1 |
|
15 | 12 | __DEBUG_LEVEL__ equ 1 ; 1 = verbose, 2 = errors only |
|
Line 16... | Line 13... | ||
16 | 13 | ||
Line 24... | Line 21... | ||
24 | SLOT_BASE equ (OS_BASE+0x0080000) |
21 | SLOT_BASE equ (OS_BASE+0x0080000) |
25 | TASK_COUNT equ (OS_BASE+0x0003004) |
22 | TASK_COUNT equ (OS_BASE+0x0003004) |
26 | CURRENT_TASK equ (OS_BASE+0x0003000) |
23 | CURRENT_TASK equ (OS_BASE+0x0003000) |
Line -... | Line 24... | ||
- | 24 | ||
- | 25 | ||
- | 26 | section '.flat' readable writable executable |
|
- | 27 | ||
- | 28 | include 'proc32.inc' |
|
- | 29 | include 'struct.inc' |
|
- | 30 | include 'macros.inc' |
|
- | 31 | include 'fdo.inc' |
|
- | 32 | include 'peimport.inc' |
|
27 | 33 | ||
28 | 34 | ||
29 | struc APPOBJ ;common object header |
35 | struc APPOBJ ;common object header |
30 | { |
36 | { |
31 | .magic dd ? ; |
37 | .magic dd ? ; |
32 | .destroy dd ? ;internal destructor |
38 | .destroy dd ? ;internal destructor |
33 | .fd dd ? ;next object in list |
39 | .fd dd ? ;next object in list |
34 | .bk dd ? ;prev object in list |
- | |
35 | .pid dd ? ;owner id |
- | |
36 | }; |
- | |
37 | - | ||
38 | virtual at 0 |
- | |
39 | APPOBJ APPOBJ |
- | |
40 | end virtual |
- | |
41 | - | ||
42 | struc IOCTL |
- | |
43 | { .handle dd ? |
- | |
44 | .io_code dd ? |
- | |
45 | .input dd ? |
- | |
46 | .inp_size dd ? |
- | |
47 | .output dd ? |
40 | .bk dd ? ;prev object in list |
Line 48... | Line 41... | ||
48 | .out_size dd ? |
41 | .pid dd ? ;owner id |
49 | } |
42 | } |
50 | 43 | ||
Line 51... | Line -... | ||
51 | virtual at 0 |
- | |
52 | IOCTL IOCTL |
- | |
53 | end virtual |
- | |
54 | - | ||
55 | DEBUG equ 1 |
- | |
56 | 44 | virtual at 0 |
|
57 | DRV_ENTRY equ 1 |
45 | APPOBJ APPOBJ |
58 | DRV_EXIT equ -1 |
46 | end virtual |
59 | 47 | ||
60 | THR_REG equ 0; x3f8 ;transtitter/reciever |
48 | THR_REG equ 0; x3f8 ;transtitter/reciever |
Line 104... | Line 92... | ||
104 | 92 | ||
105 | MCR_DTR equ 0x01 ;0-> DTR=1, 1-> DTR=0 |
93 | MCR_DTR equ 0x01 ;0-> DTR=1, 1-> DTR=0 |
106 | MCR_RTS equ 0x02 ;0-> RTS=1, 1-> RTS=0 |
94 | MCR_RTS equ 0x02 ;0-> RTS=1, 1-> RTS=0 |
107 | MCR_OUT_1 equ 0x04 ;0-> OUT1=1, 1-> OUT1=0 |
95 | MCR_OUT_1 equ 0x04 ;0-> OUT1=1, 1-> OUT1=0 |
108 | MCR_OUT_2 equ 0x08 ;0-> OUT2=1, 1-> OUT2=0; enable intr |
96 | MCR_OUT_2 equ 0x08 ;0-> OUT2=1, 1-> OUT2=0; enable intr |
Line 109... | Line 97... | ||
109 | MCR_LOOP equ 0x10 ;lopback mode |
97 | MCR_LOOP equ 0x10 ;loopback mode |
110 | 98 | ||
111 | MSR_DCTS equ 0x01 ;delta clear to send |
99 | MSR_DCTS equ 0x01 ;delta clear to send |
112 | MSR_DDSR equ 0x02 ;delta data set redy |
100 | MSR_DDSR equ 0x02 ;delta data set redy |
Line 171... | Line 159... | ||
171 | .xmit_wp dd ? |
159 | .xmit_wp dd ? |
172 | .xmit_count dd ? |
160 | .xmit_count dd ? |
173 | .xmit_free dd ? |
161 | .xmit_free dd ? |
174 | .xmit_top dd ? |
162 | .xmit_top dd ? |
175 | } |
163 | } |
- | 164 | ||
176 | virtual at 0 |
165 | virtual at 0 |
177 | UART UART |
166 | UART UART |
178 | end virtual |
167 | end virtual |
Line 179... | Line 168... | ||
179 | 168 | ||
Line 195... | Line 184... | ||
195 | CONNECTION CONNECTION |
184 | CONNECTION CONNECTION |
196 | end virtual |
185 | end virtual |
Line 197... | Line 186... | ||
197 | 186 | ||
Line 198... | Line -... | ||
198 | CONNECTION_SIZE equ 7*4 |
- | |
199 | - | ||
200 | public START |
- | |
Line -... | Line 187... | ||
- | 187 | CONNECTION_SIZE equ 7*4 |
|
201 | public service_proc |
188 | |
Line -... | Line 189... | ||
- | 189 | ||
202 | public version |
190 | ;proc START c, state:dword |
- | 191 | ; cmp [state], 1 |
|
Line -... | Line 192... | ||
- | 192 | ||
203 | 193 | align 4 |
|
204 | section '.flat' code readable align 16 |
194 | proc START c, state:dword |
Line -... | Line 195... | ||
- | 195 | DEBUGF 1, "Loading driver UART (entry at %x)...\n", START |
|
- | 196 | ||
- | 197 | push esi ; [bw] ??? |
|
205 | 198 | cmp [state], DRV_ENTRY |
|
206 | proc START stdcall, state:dword |
199 | jne .stop |
- | 200 | ||
- | 201 | mov esi, msg_start |
|
- | 202 | invoke SysMsgBoardStr |
|
207 | 203 | ||
208 | cmp [state], 1 |
204 | mov eax, UART_SIZE |
Line -... | Line 205... | ||
- | 205 | invoke Kmalloc |
|
- | 206 | ; invoke Kmalloc, UART_SIZE (1) -- failure |
|
209 | jne .stop |
207 | ; invoke Kmalloc, UART_SIZE (2) -- success |
210 | 208 | ; DEBUGF 1,"[UART.START] Kmalloc: UART_SIZE=%d eax=%d\n", UART_SIZE, eax |
|
211 | mov eax, UART_SIZE |
209 | test eax, eax |
212 | call Kmalloc |
210 | jz .fail |
213 | test eax, eax |
211 | |
214 | jz .fail |
212 | DEBUGF 1, "Structure %x allocated\n", eax |
Line 215... | Line 213... | ||
215 | 213 | ||
216 | mov [com1], eax |
214 | mov [com1], eax |
Line 217... | Line 215... | ||
217 | mov edi, eax |
215 | mov edi, eax |
Line 218... | Line 216... | ||
218 | mov ecx, UART_SIZE/4 |
216 | mov ecx, UART_SIZE/4 |
219 | xor eax, eax |
217 | xor eax, eax |
Line 220... | Line 218... | ||
220 | cld |
218 | cld |
Line 234... | Line 232... | ||
234 | add eax, 8192 |
232 | add eax, 8192 |
235 | mov [edi+UART.xmit_buff], eax |
233 | mov [edi+UART.xmit_buff], eax |
236 | add eax, 8192 |
234 | add eax, 8192 |
237 | mov [edi+UART.xmit_top], eax |
235 | mov [edi+UART.xmit_top], eax |
Line 238... | Line 236... | ||
238 | 236 | ||
239 | call AllocPage |
237 | invoke AllocPage |
240 | test eax, eax |
238 | test eax, eax |
Line 241... | Line 239... | ||
241 | jz .fail |
239 | jz .fail |
242 | 240 | ||
243 | shr edx, 12 |
241 | shr edx, 12 |
244 | or eax, PG_SW |
242 | or eax, PG_SW |
Line 245... | Line 243... | ||
245 | mov [page_tabs+edx*4], eax |
243 | mov [page_tabs+edx*4], eax |
246 | mov [page_tabs+edx*4+8], eax |
244 | mov [page_tabs+edx*4+8], eax |
247 | 245 | ||
Line 248... | Line 246... | ||
248 | call AllocPage |
246 | invoke AllocPage |
249 | test eax, eax |
247 | test eax, eax |
250 | jz .fail |
248 | jz .fail |
Line 251... | Line 249... | ||
251 | 249 | ||
252 | or eax, PG_SW |
250 | or eax, PG_SW |
253 | mov [page_tabs+edx*4+4], eax |
251 | mov [page_tabs+edx*4+4], eax |
Line 254... | Line 252... | ||
254 | mov [page_tabs+edx*4+12], eax |
252 | mov [page_tabs+edx*4+12], eax |
255 | 253 | ||
256 | call AllocPage |
254 | invoke AllocPage |
Line 257... | Line 255... | ||
257 | test eax, eax |
255 | test eax, eax |
258 | jz .fail |
256 | jz .fail |
259 | 257 | ||
Line 260... | Line 258... | ||
260 | or eax, PG_SW |
258 | or eax, PG_SW |
261 | mov [page_tabs+edx*4+16], eax |
259 | mov [page_tabs+edx*4+16], eax |
Line 280... | Line 278... | ||
280 | invlpg [eax+0x7000] |
278 | invlpg [eax+0x7000] |
Line 281... | Line 279... | ||
281 | 279 | ||
282 | mov eax, edi |
280 | mov eax, edi |
Line 283... | Line 281... | ||
283 | call uart_reset.internal ;eax= uart |
281 | call uart_reset.internal ;eax= uart |
- | 282 | ||
- | 283 | invoke AttachIntHandler, COM_1_IRQ, com_1_isr, dword 0 |
|
- | 284 | test eax, eax |
|
- | 285 | jnz @f |
|
- | 286 | DEBUGF 2, "Could not attach int handler (%x)\n", COM_1_IRQ |
|
- | 287 | jmp .fail |
|
- | 288 | ||
- | 289 | @@: |
|
284 | 290 | DEBUGF 1, "Attached int handler (%x)\n", COM_1_IRQ |
|
285 | stdcall AttachIntHandler, COM_1_IRQ, com_1_isr, dword 0 |
291 | pop esi |
- | 292 | invoke RegService, sz_uart_srv, service_proc |
|
286 | stdcall RegService, sz_uart_srv, service_proc |
293 | ret |
287 | ret |
294 | |
- | 295 | .fail: |
|
- | 296 | .stop: |
|
288 | .fail: |
297 | DEBUGF 2, "Failed\n" |
289 | .stop: |
298 | pop esi |
290 | xor eax, eax |
299 | xor eax, eax |
Line 310... | Line 319... | ||
310 | PORT_READ equ 8 |
319 | PORT_READ equ 8 |
311 | PORT_WRITE equ 9 |
320 | PORT_WRITE equ 9 |
Line 312... | Line 321... | ||
312 | 321 | ||
313 | align 4 |
322 | align 4 |
314 | proc service_proc stdcall, ioctl:dword |
- | |
315 | 323 | proc service_proc stdcall, ioctl:dword |
|
316 | mov ebx, [ioctl] |
324 | mov ebx, [ioctl] |
317 | mov eax, [ebx+io_code] |
325 | mov eax, [ebx+io_code] |
318 | cmp eax, PORT_WRITE |
326 | cmp eax, PORT_WRITE |
Line 347... | Line 355... | ||
347 | call [uart_func+eax*4] |
355 | call [uart_func+eax*4] |
348 | ret |
356 | ret |
349 | .fail: |
357 | .fail: |
350 | or eax, -1 |
358 | or eax, -1 |
351 | ret |
359 | ret |
352 | - | ||
353 | endp |
360 | endp |
Line 354... | Line 361... | ||
354 | 361 | ||
355 | restore handle |
362 | ;restore handle |
356 | restore io_code |
363 | ;restore io_code |
357 | restore input |
364 | ;restore input |
358 | restore inp_size |
365 | ;restore inp_size |
359 | restore output |
366 | ;restore output |
Line 360... | Line 367... | ||
360 | restore out_size |
367 | ;restore out_size |
361 | 368 | ||
362 | 369 | ||
Line 396... | Line 403... | ||
396 | add edx, MCR_REG |
403 | add edx, MCR_REG |
397 | xor eax, eax |
404 | xor eax, eax |
398 | out dx, al ;clear DTR & RTS |
405 | out dx, al ;clear DTR & RTS |
Line 399... | Line 406... | ||
399 | 406 | ||
400 | mov eax, esi |
407 | mov eax, esi |
- | 408 | ; mov ebx, RATE_2400 |
|
401 | mov ebx, RATE_2400 |
409 | mov ebx, RATE_115200 |
402 | mov ecx, LCR_8BIT+LCR_STOP_1 |
410 | mov ecx, LCR_8BIT+LCR_STOP_1 |
Line 403... | Line 411... | ||
403 | call uart_set_mode.internal |
411 | call uart_set_mode.internal |
404 | 412 | ||
Line 611... | Line 619... | ||
611 | 619 | ||
612 | mov ebx, [CURRENT_TASK] |
620 | mov ebx, [CURRENT_TASK] |
613 | shl ebx, 5 |
621 | shl ebx, 5 |
614 | mov ebx, [CURRENT_TASK+ebx+4] |
622 | mov ebx, [CURRENT_TASK+ebx+4] |
615 | mov eax, CONNECTION_SIZE |
623 | mov eax, CONNECTION_SIZE |
616 | call CreateObject |
624 | invoke CreateObject |
617 | pop esi ;uart |
625 | pop esi ;uart |
618 | test eax, eax |
626 | test eax, eax |
Line 619... | Line 627... | ||
619 | jz .fail |
627 | jz .fail |
Line 638... | Line 646... | ||
638 | cmp [eax+APPOBJ.magic], 'CNCT' |
646 | cmp [eax+APPOBJ.magic], 'CNCT' |
639 | jne .fail |
647 | jne .fail |
Line 640... | Line 648... | ||
640 | 648 | ||
641 | cmp [eax+APPOBJ.destroy], uart_close.destroy |
649 | cmp [eax+APPOBJ.destroy], uart_close.destroy |
- | 650 | jne .fail |
|
642 | jne .fail |
651 | |
- | 652 | .destroy: |
|
643 | .destroy: |
653 | ; DEBUGF 1, "[UART.destroy] eax=%x uart=%x\n", eax, [eax+CONNECTION.uart] |
644 | push [eax+CONNECTION.uart] |
654 | push [eax+CONNECTION.uart] |
645 | call DestroyObject ;eax= object |
655 | invoke DestroyObject ;eax= object |
646 | pop eax ;eax= uart |
656 | pop eax ;eax= uart |
647 | test eax, eax |
657 | test eax, eax |
Line 648... | Line 658... | ||
648 | jz .fail |
658 | jz .fail |
Line 880... | Line 890... | ||
880 | 890 | ||
881 | align 4 |
891 | align 4 |
882 | com_2_isr: |
892 | com_2_isr: |
883 | mov ebx, [com2] |
893 | mov ebx, [com2] |
- | 894 | jmp com_1_isr.get_info |
|
884 | jmp com_1_isr.get_info |
895 | |
885 | align 4 |
896 | align 4 |
886 | com_1_isr: |
897 | com_1_isr: |
- | 898 | mov ebx, [com1] |
|
887 | mov ebx, [com1] |
899 | |
888 | .get_info: |
900 | .get_info: |
889 | mov edx, [ebx+UART.base] |
901 | mov edx, [ebx+UART.base] |
890 | add edx, IIR_REG |
902 | add edx, IIR_REG |
Line 908... | Line 920... | ||
908 | in al, dx |
920 | in al, dx |
909 | ret |
921 | ret |
Line 910... | Line 922... | ||
910 | 922 | ||
911 | align 4 |
923 | align 4 |
- | 924 | isr_recieve: |
|
912 | isr_recieve: |
925 | ; DEBUGF 1, "[UART.isr_recieve] ebx=%x\n", ebx |
913 | mov esi, [ebx+UART.base] |
926 | mov esi, [ebx+UART.base] |
914 | add esi, LSR_REG |
927 | add esi, LSR_REG |
915 | mov edi, [ebx+UART.rcvr_wp] |
928 | mov edi, [ebx+UART.rcvr_wp] |
916 | xor ecx, ecx |
929 | xor ecx, ecx |
Line 966... | Line 979... | ||
966 | dd isr_line |
979 | dd isr_line |
Line 967... | Line 980... | ||
967 | 980 | ||
Line 968... | Line 981... | ||
968 | version dd (5 shl 16) or (UART_VERSION and 0xFFFF) |
981 | version dd (5 shl 16) or (UART_VERSION and 0xFFFF) |
- | 982 | ||
Line 969... | Line -... | ||
969 | - | ||
- | 983 | sz_uart_srv db 'UART', 0 |
|
Line -... | Line 984... | ||
- | 984 | msg_start db 'Loading UART driver...',13,10,0 |
|
970 | sz_uart_srv db 'UART',0 |
985 | |
971 | 986 | include_debug_strings ; All data wich FDO uses will be included here |
|
Line -... | Line 987... | ||
- | 987 | ||
- | 988 | align 4 |
|
- | 989 | com1 rd 1 |