Rev 8356 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10062 | ace_dent | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2010-2024. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; netcfg.asm - Network driver control center for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
14 | |||
15 | format binary as "" |
||
16 | |||
17 | __DEBUG__ = 1 |
||
18 | __DEBUG_LEVEL__ = 1 |
||
19 | |||
20 | use32 |
||
21 | org 0x0 |
||
22 | |||
23 | db 'MENUET01' ; 8 byte id |
||
24 | dd 0x01 ; header version |
||
25 | dd START ; start of code |
||
26 | dd IM_END ; size of image |
||
27 | dd (I_END+0x100) ; memory for app |
||
28 | dd (I_END+0x100) ; esp |
||
29 | dd param, 0x0 ; I_Param , I_Icon |
||
30 | |||
31 | include '../../macros.inc' |
||
32 | include '../../debug-fdo.inc' |
||
33 | |||
34 | START: |
||
35 | ; first, check boot parameters |
||
36 | |||
37 | cmp byte[param], 0 |
||
38 | je .noparams |
||
39 | |||
40 | mcall 40, 0 |
||
41 | |||
42 | push .exit |
||
43 | cmp byte[param], 'A' ; A for All |
||
44 | je Get_PCI_Info |
||
45 | |||
46 | cmp byte[param], 'F' ; F for First |
||
47 | je Get_PCI_Info |
||
48 | |||
49 | ret |
||
50 | |||
51 | .exit: |
||
52 | mcall -1 |
||
53 | |||
54 | .noparams: |
||
55 | call draw_window |
||
56 | |||
57 | still: |
||
58 | mcall 10 ; wait here for event |
||
59 | dec eax ; redraw request ? |
||
60 | jz red |
||
61 | dec eax ; key in buffer ? |
||
62 | jz key |
||
63 | dec eax ; button in buffer ? |
||
64 | jz button |
||
65 | jmp still |
||
66 | |||
67 | red: ; redraw |
||
68 | mcall 9, Proc_Info, -1 ; window redraw requested so get new window coordinates and size |
||
69 | mov eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure |
||
70 | mov [Form + 2], ax ; x start position |
||
71 | mov eax, [Proc_Info.box.top]; |
||
72 | mov [Form + 6], ax ; ystart position |
||
73 | mov eax, [Proc_Info.box.width] ; |
||
74 | mov [Form], ax ; window width |
||
75 | mov eax, [Proc_Info.box.height] ; |
||
76 | mov [Form + 4] ,ax ; window height |
||
77 | call draw_window ; go redraw window now |
||
78 | jmp still |
||
79 | |||
80 | key: ; key |
||
81 | mcall 2 ; just read it and ignore |
||
82 | jmp still |
||
83 | button: ; button |
||
84 | mcall 17 ; get id |
||
85 | |||
86 | cmp ah, 1 ; button id = 1 ? |
||
87 | jne @f |
||
88 | exit: |
||
89 | mcall -1 ; close this program |
||
90 | @@: |
||
91 | cmp eax, 0x0000ff00 |
||
92 | jg load_drv |
||
93 | |||
94 | cmp ah, 4 |
||
95 | je hook |
||
96 | |||
97 | cmp ah, 5 |
||
98 | je reset |
||
99 | |||
100 | cmp ah, 6 |
||
101 | je unload |
||
102 | |||
103 | jmp still |
||
104 | |||
105 | |||
106 | load_drv: |
||
107 | shr eax, 16 |
||
108 | mov [selected], ax |
||
109 | |||
110 | mov bl, 6 ; get a dword |
||
111 | mov bh, ah ; bus |
||
112 | mov ch, al ; dev |
||
113 | mov cl, 0 ; offset to device/vendor id |
||
114 | mcall 62 ; get ID's |
||
115 | |||
116 | mov [PCI_Vendor], ax |
||
117 | shr eax, 16 |
||
118 | mov [PCI_Device], ax |
||
119 | call get_drv_ptr |
||
120 | |||
121 | mov ecx, eax |
||
122 | mcall 68, 16 |
||
123 | |||
124 | mov [IOCTL.handle], eax |
||
125 | |||
126 | call draw_window |
||
127 | |||
128 | cmp [IOCTL.handle], 0 |
||
129 | jne still |
||
130 | |||
131 | mcall 4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , load_error |
||
132 | |||
133 | jmp still |
||
134 | |||
135 | |||
136 | hook: |
||
137 | mov ax, [selected] |
||
138 | test ax, ax |
||
139 | jz still |
||
140 | |||
141 | mov [hardwareinfo.pci_dev], al |
||
142 | mov [hardwareinfo.pci_bus], ah |
||
143 | |||
144 | mov [IOCTL.io_code], 1 ; SRV_HOOK |
||
145 | mov [IOCTL.inp_size], 3 |
||
146 | mov [IOCTL.input], hardwareinfo |
||
147 | mov [IOCTL.out_size], 0 |
||
148 | mov [IOCTL.output], 0 |
||
149 | |||
150 | mcall 68, 17, IOCTL |
||
151 | mov [drivernumber], al |
||
152 | |||
153 | jmp still |
||
154 | |||
155 | reset: |
||
156 | movzx ebx, [drivernumber] |
||
157 | mcall 74,,2 |
||
158 | |||
159 | jmp still |
||
160 | |||
161 | unload: |
||
162 | movzx ebx, [drivernumber] |
||
163 | mcall 74,,3 |
||
164 | |||
165 | jmp still |
||
166 | |||
167 | draw_window: |
||
168 | mcall 12, 1 ; start of draw |
||
169 | mcall 0, dword[Form], dword[Form + 4], 0x13ffffff, 0x805080d0, title |
||
170 | |||
171 | call Get_PCI_Info ; get pci version and last bus, scan for and draw each pci device |
||
172 | |||
173 | cmp edx, 20 shl 16 + 110 |
||
174 | je .nonefound |
||
175 | |||
176 | mcall 4, 20 shl 16 + 100, 1 shl 31 + 0x00000000, caption |
||
177 | |||
178 | cmp [selected], 0 |
||
179 | jz .done |
||
180 | cmp [IOCTL.handle] ,0 |
||
181 | jz .done |
||
182 | |||
183 | mcall 8, 18 shl 16 + 100, 35 shl 16 + 18, 4, 0x00007f00 |
||
184 | mcall ,, 55 shl 16 + 18, 5, 0x0000007f |
||
185 | mcall ,, 75 shl 16 + 18, 6, 0x007f0000 |
||
186 | |||
187 | mcall 4, 33 shl 16 + 42, 1 shl 31 + 0x00ffffff, btn_start |
||
188 | mcall , 33 shl 16 + 62, , btn_reset |
||
189 | mcall , 36 shl 16 + 82, , btn_stop |
||
190 | |||
191 | jmp .done |
||
192 | |||
193 | .nonefound: |
||
194 | mcall 4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000, nonefound |
||
195 | .done: |
||
196 | mcall 12, 2 ; end of draw |
||
197 | ret |
||
198 | |||
199 | |||
200 | |||
201 | |||
202 | |||
203 | ;------------------------------------------------------------------ |
||
204 | ;* Gets the PCI Version and Last Bus |
||
205 | Get_PCI_Info: |
||
206 | mcall 62, 0 |
||
207 | mov [PCI_Version], ax |
||
208 | mcall 62, 1 |
||
209 | mov [PCI_LastBus], al |
||
210 | ;---------------------------------------------------------- |
||
211 | ;* Get all devices on PCI Bus |
||
212 | cmp al, 0xff ; 0xFF means no pci bus found |
||
213 | jne Pci_Exists ; |
||
214 | ret ; if no bus then leave |
||
215 | |||
216 | Pci_Exists: |
||
217 | mov [V_Bus], 0 |
||
218 | mov [V_Dev], 0 |
||
219 | mov edx, 20 shl 16 + 110 ; set start write position |
||
220 | |||
221 | Start_Enum: |
||
222 | mov bl, 6 ; read dword |
||
223 | mov bh, [V_Bus] |
||
224 | mov ch, [V_Dev] |
||
225 | mov cl, 0 ; offset to device/vendor id |
||
226 | mcall 62 ; get ID's |
||
227 | |||
228 | cmp ax, 0 ; Vendor ID should not be 0 or 0xFFFF |
||
229 | je .nextDev ; check next device if nothing exists here |
||
230 | cmp ax, 0xffff ; |
||
231 | je .nextDev ; |
||
232 | |||
233 | mov [PCI_Vendor], ax ; There is a device here, save the ID's |
||
234 | shr eax, 16 ; |
||
235 | mov [PCI_Device], ax ; |
||
236 | mov bl, 4 ; Read config byte |
||
237 | mov bh, [V_Bus] ; Bus # |
||
238 | mov ch, [V_Dev] ; Device # on bus |
||
239 | mov cl, 0x08 ; Register to read (Get Revision) |
||
240 | mcall 62 ; Read it |
||
241 | mov [PCI_Rev], al ; Save it |
||
242 | |||
243 | mov cl, 0x0b ; Register to read (Get class) |
||
244 | mcall 62 ; Read it |
||
245 | mov [PCI_Class], al ; Save it |
||
246 | |||
247 | mov cl, 0x0a ; Register to read (Get Subclass) |
||
248 | mcall 62 ; Read it |
||
249 | mov [PCI_SubClass], al ; Save it |
||
250 | |||
251 | mov cl, 0x09 ; Register to read (Get Interface) |
||
252 | mcall 62 ; Read it |
||
253 | mov [PCI_Interface], al ; Save it |
||
254 | |||
255 | mov cl, 0x3c ; Register to read (Get IRQ) |
||
256 | mcall 62 ; Read it |
||
257 | mov [PCI_IRQ], al ; Save it |
||
258 | |||
259 | ; Could it be a network card? |
||
260 | cmp [PCI_Class], 2 ; network controller |
||
261 | je .found |
||
262 | |||
263 | cmp [PCI_Class], 6 ; bridge type device |
||
264 | jne .nextDev |
||
265 | cmp [PCI_SubClass], 0x80 ; PCI-other bridge (for nvidia chipset) |
||
266 | jne .nextDev |
||
267 | cmp [PCI_Vendor], 0x10DE ; nvidia |
||
268 | jne .nextDev |
||
269 | |||
270 | .found: |
||
271 | cmp byte[param], 0 ; Load network driver immediately? |
||
272 | jne load_and_start |
||
273 | |||
274 | call Print_New_Device ; print device info to screen |
||
275 | |||
276 | .nextDev: |
||
277 | test [V_Dev], 7 |
||
278 | jnz .nextFn |
||
279 | |||
280 | ; Is this a multifunction device? |
||
281 | mov bl, 4 ; Read config byte |
||
282 | mov bh, [V_Bus] ; Bus # |
||
283 | mov ch, [V_Dev] ; Device # on bus |
||
284 | mov cl, 0x0e |
||
285 | mcall 62 |
||
286 | test al, al |
||
287 | js .nextFn |
||
288 | |||
289 | ; Not a multifunction device, go to the next device |
||
290 | or [V_Dev], 7 |
||
291 | |||
292 | .nextFn: |
||
293 | inc [V_Dev] ; lower 3 bits are the function number |
||
294 | jnz Start_Enum ; jump until we reach zero |
||
295 | |||
296 | mov [V_Dev], 0 ; reset device number |
||
297 | inc [V_Bus] ; next bus |
||
298 | mov al, [PCI_LastBus] ; get last bus |
||
299 | cmp [V_Bus], al ; was it last bus |
||
300 | jbe Start_Enum ; if not jump to keep searching |
||
301 | ret |
||
302 | |||
303 | |||
304 | |||
305 | load_and_start: |
||
306 | |||
307 | call get_drv_ptr |
||
308 | cmp eax, lbl_none |
||
309 | je .notsupp |
||
310 | |||
311 | mov ecx, eax |
||
312 | mcall 68, 16 |
||
313 | test eax, eax |
||
314 | jz .fail |
||
315 | mov [IOCTL.handle], eax |
||
316 | |||
317 | mov al, [V_Dev] |
||
318 | mov [hardwareinfo.pci_dev], al |
||
319 | mov al, [V_Bus] |
||
320 | mov [hardwareinfo.pci_bus], al |
||
321 | |||
322 | mov [IOCTL.io_code], 1 ; SRV_HOOK |
||
323 | mov [IOCTL.inp_size], 3 |
||
324 | mov [IOCTL.input], hardwareinfo |
||
325 | mov [IOCTL.out_size], 0 |
||
326 | mov [IOCTL.output], 0 |
||
327 | |||
328 | mcall 68, 17, IOCTL |
||
329 | |||
330 | .next: |
||
331 | cmp byte[param], 'A' |
||
332 | je Start_Enum.nextDev |
||
333 | jmp exit |
||
334 | |||
335 | .fail: |
||
336 | DEBUGF 1,"Could not load network driver %s\n", ecx |
||
337 | jmp .next |
||
338 | |||
339 | .notsupp: |
||
340 | DEBUGF 1,"Unsupported PCI network card detected: 0x%x:0x%x\n", [PCI_Vendor]:4, [PCI_Device]:4 |
||
341 | jmp .next |
||
342 | |||
343 | |||
344 | ITEM_H = 15 |
||
345 | ;------------------------------------------------------------------ |
||
346 | ;* Print device info to screen |
||
347 | Print_New_Device: |
||
348 | |||
349 | push edx ; Magic ! (to print a button...) |
||
350 | |||
351 | mov ebx, 18 shl 16 |
||
352 | mov bx, [Form] |
||
353 | sub bx, 36 |
||
354 | |||
355 | mov cx, dx |
||
356 | dec cx |
||
357 | shl ecx, 16 |
||
358 | add ecx, ITEM_H |
||
359 | |||
360 | xor edx, edx |
||
361 | mov dh, [V_Bus] |
||
362 | mov dl, [V_Dev] |
||
363 | |||
364 | mov esi, 0x0059DFFF ; color: yellow if selected, blue otherwise |
||
365 | cmp [selected], dx |
||
366 | jne @f |
||
367 | mov esi, 0x00FFCD0B |
||
368 | @@: |
||
369 | |||
370 | shl edx, 8 |
||
371 | or dl, 0xff |
||
372 | |||
373 | mcall 8 |
||
374 | pop edx |
||
375 | |||
376 | xor esi, esi ; Color of text |
||
377 | movzx ecx, [PCI_Vendor] ; number to be written |
||
378 | add edx, 3 |
||
379 | mcall 47, 0x00040100 ; Write Vendor ID |
||
380 | |||
381 | add edx, (4*6+18) shl 16 |
||
382 | movzx ecx, [PCI_Device] ; get Vendor ID |
||
383 | mcall ; Draw Vendor ID to Window |
||
384 | |||
385 | add edx, (4*6+18) shl 16 |
||
386 | movzx ecx, [V_Bus] |
||
387 | mcall ,0x00020100 ; draw bus number to screen |
||
388 | |||
389 | add edx, (2*6+18) shl 16 |
||
390 | movzx ecx, [V_Dev] |
||
391 | shr ecx, 3 ; device number is bits 3-7 |
||
392 | mcall ; Draw device Number To Window |
||
393 | |||
394 | add edx, (2*6+18) shl 16 |
||
395 | movzx ecx, [PCI_Rev] |
||
396 | mcall ; Draw Revision to screen |
||
397 | |||
398 | add edx, (2*6+18) shl 16 |
||
399 | movzx ecx, [PCI_IRQ] |
||
400 | cmp cl, 0x0f ; IRQ must be between 0 and 15 |
||
401 | ja @f |
||
402 | mcall |
||
403 | @@: |
||
404 | ; |
||
405 | ;Write Names |
||
406 | movzx ebx, dx ; Set y position |
||
407 | or ebx, 230 shl 16 ; set Xposition |
||
408 | |||
409 | ;------------------------------------------------------------------ |
||
410 | ; Prints the Vendor's Name based on Vendor ID |
||
411 | ;------------------------------------------------------------------ |
||
412 | mov edx, VendorsTab |
||
413 | mov cx, [PCI_Vendor] |
||
414 | |||
415 | .fn: mov ax, [edx] |
||
416 | add edx, 6 |
||
417 | test ax, ax |
||
418 | jz .find |
||
419 | cmp ax, cx |
||
420 | jne .fn |
||
421 | .find: mov edx, [edx - 4] |
||
422 | mcall 4,, 0x80000000 ; let's print the vendor Name |
||
423 | |||
424 | ;------------------------------------------------------------------ |
||
425 | ; Get description based on Class/Subclass |
||
426 | ;------------------------------------------------------------------ |
||
427 | mov eax, dword[PCI_Class] |
||
428 | and eax, 0xffffff |
||
429 | xor edx, edx |
||
430 | xor esi, esi |
||
431 | .fnc: inc esi |
||
432 | mov ecx, [Classes + esi * 8 - 8] |
||
433 | cmp cx , 0xffff |
||
434 | je .endfc |
||
435 | cmp cx , ax |
||
436 | jne .fnc |
||
437 | test ecx, 0xff000000 |
||
438 | jz @f |
||
439 | mov edx, [Classes + esi * 8 - 4] |
||
440 | jmp .fnc |
||
441 | @@: cmp eax, ecx |
||
442 | jne .fnc |
||
443 | xor edx, edx |
||
444 | .endfc: test edx, edx |
||
445 | jnz @f |
||
446 | mov edx, [Classes + esi * 8 - 4] |
||
447 | @@: |
||
448 | add ebx, 288 shl 16 |
||
449 | mcall 4,, 0x80000000,, 32 ; draw the text |
||
450 | movzx edx, bx ; get y coordinate |
||
451 | add edx, 0x0014000A ; add 10 to y coordinate and set x coordinate to 20 |
||
452 | |||
453 | ;------------------------------------------------------------------ |
||
454 | ; Print Driver Name |
||
455 | ;------------------------------------------------------------------ |
||
456 | push edx |
||
457 | add ebx, 120 shl 16 |
||
458 | push ebx |
||
459 | |||
460 | call get_drv_ptr |
||
461 | mov edx, eax |
||
462 | pop ebx |
||
463 | mcall 4,,0x80000000 ; let's print the vendor Name |
||
464 | pop edx |
||
465 | ret |
||
466 | |||
467 | get_drv_ptr: |
||
468 | mov eax, driverlist ; eax will be the pointer to latest driver title |
||
469 | mov ebx, driverlist ; ebx is the current pointer |
||
470 | mov ecx, dword[PCI_Vendor] ; the device/vendor id of we want to find |
||
471 | |||
472 | .driverloop: |
||
473 | inc ebx |
||
474 | cmp byte[ebx], 0 |
||
475 | jne .driverloop |
||
476 | inc ebx ; the device/vendor id list for the driver eax is pointing to starts here. |
||
477 | |||
478 | .deviceloop: |
||
479 | cmp dword[ebx], 0 |
||
480 | je .nextdriver |
||
481 | cmp dword[ebx], ecx |
||
482 | je .driverfound |
||
483 | add ebx, 4 |
||
484 | jmp .deviceloop |
||
485 | |||
486 | .nextdriver: |
||
487 | add ebx, 4 |
||
488 | cmp dword[ebx], 0 |
||
489 | je .nodriver |
||
490 | mov eax, ebx |
||
491 | jmp .driverloop |
||
492 | |||
493 | .nodriver: |
||
494 | mov eax, lbl_none ; let's print the vendor Name |
||
495 | ret |
||
496 | |||
497 | .driverfound: |
||
498 | ret |
||
499 | |||
500 | include 'vendors.inc' |
||
501 | include 'drivers.inc' |
||
502 | |||
503 | |||
504 | ;------------------------------------------------------------------ |
||
505 | ; DATA AREA |
||
506 | |||
507 | |||
508 | DATA |
||
509 | |||
510 | |||
511 | Form: dw 740 ; window width (no more, special for 800x600) |
||
512 | dw 100 ; window x start |
||
513 | dw 220 ; window height |
||
514 | dw 100 ; window y start |
||
515 | |||
516 | title db 'Network Driver Control Center', 0 |
||
517 | |||
518 | caption db 'Vendor Device Bus Dev Rev IRQ Company Description DRIVER',0 |
||
519 | nonefound db 'No compatible devices were found!',0 |
||
520 | btn_start db 'Start device',0 |
||
521 | btn_reset db 'Reset device',0 |
||
522 | btn_stop db 'Stop device',0 |
||
523 | lbl_none db 'none',0 |
||
524 | load_error db 'Could not load network driver!',0 |
||
525 | |||
526 | include_debug_strings |
||
527 | |||
528 | hardwareinfo: |
||
529 | .type db 1 ; pci |
||
530 | .pci_bus db ? |
||
531 | .pci_dev db ? |
||
532 | |||
533 | |||
534 | IM_END: |
||
535 | |||
536 | ;------------------------------------------------------------------ |
||
537 | ; UNINITIALIZED DATA AREA |
||
538 | |||
539 | |||
540 | IOCTL: |
||
541 | .handle dd ? |
||
542 | .io_code dd ? |
||
543 | .input dd ? |
||
544 | .inp_size dd ? |
||
545 | .output dd ? |
||
546 | .out_size dd ? |
||
547 | |||
548 | drivernumber db ? |
||
549 | MAC dp ? |
||
550 | |||
551 | |||
552 | type db ? |
||
553 | selected dw ? |
||
554 | V_Bus db ? |
||
555 | V_Dev db ? |
||
556 | PCI_Version dw ? |
||
557 | PCI_LastBus db ? |
||
558 | ; Don't change order |
||
559 | PCI_Vendor dw ? |
||
560 | PCI_Device dw ? |
||
561 | |||
562 | PCI_Bus db ? |
||
563 | PCI_Dev db ? |
||
564 | PCI_Rev db ? |
||
565 | ; Don't change order |
||
566 | PCI_Class db ? |
||
567 | PCI_SubClass db ? |
||
568 | PCI_Interface db ? |
||
569 | PCI_IRQ db ? |
||
570 | |||
571 | Proc_Info process_information |
||
572 | |||
573 | param rb 1024 |
||
574 | |||
575 | |||
576 | I_END: |