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