Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 diamond 1
;***************************************************************
2
; project name:    PCI Device Enumeration
3
; target platform: KolibriOS and MenuetOS
4
; compiler:        flat assmebler 1.63.2
5
; version:         1.31
6
; last update:     13(th) May 2006
7
; maintained by:   Jason Delozier (cordata51)
8
; e-mail:          cordata51@hotmail.com
9
; project site:    http://www.asmfreaks.com/menuetos
10
;***************************************************************
11
;Summary: This program will attempt to scan the PCI Bus
12
;        and display basic information about each device
13
;        connected to the PCI Bus.
14
;***************************************************************
15
;HISTORY:
16
;keep dates in european format (dd/mm/yyyy), please
17
; '!' means big changes
18
; to-do:
19
;PCI version should be normalized (0210->02.10)
20
;----------------------------------------------------------------
21
;1.31: PCIDEV   13/05/2006
22
;Author:    Jason Delozier 
23
;Features:
24
;           fixed
25
;                 * ! bug in Company Name look up code that would cause Unknown Name errors.
26
;                 * ! possible bugs, many instructions missing byte, word, dword prefixes
27
;                 * ! possible bug which could have occured after removing  "PREVIOUSVERSIONLIST"
28
;                     entry in loop up code and not fixing jump parameters.
29
;           added
30
;                 *  comments to various parts of the code
31
;           optimized
32
;                 * various parts of the source, too many to remember and mention.
33
;                 * changed entries for Subclasses in vendors.inc to Byte format, saves a little space.
34
;----------------------------------------------------------------
35
;1.30: PCIDEV   11/05/2006
36
;Author:    Sergey Kuzmin aka Wildwest 
37
;Features:
38
;           added
39
;                * 3 new vendor id's (ESS from Madis Kalme and 2 id's
40
;                  forgotten from 1.15 release: Broadcom -SiByte and Chaintech Comp.)
41
;                       changed
42
;                            * I don't know why other devs (Jason or Victor) changed window style
43
;                  to old ugly one, so I changed it back to skinned type 3.
44
;                * the same goes to the use of macroc.inc - it is enabled again.
45
;           deleted
46
;                * there is no more label "PREVIOUSVERSIONLIST" - id's moved to the
47
;                  appropriate parts of global list.
48
;----------------------------------------------------------------
49
;1.29: PCIDEV   30/04/2006
50
;Author:    Jason Delozier 
51
;Features:
52
;           fixed
53
;                 * ! bug that would not allow devices with device
54
;                   numbers > 16 to be displayed.
55
;           added
56
;                 * ! another heading called "FNC" (function) which allows
57
;                   the multipurpose Device/Function varible to be split and
58
;                   displayed to the user properly.
59
;                 * horizontal bars to display for easier reading.
60
;           optimized
61
;                 * vendor/description search routines for speed and space.
62
;----------------------------------------------------------------
63
;1.25: PCIDEV   02/10/2005
64
;Author:    Sergey Kuzmin aka Wildwest 
65
;Features:
66
;            changed
67
;                                       * ! Description is based on Class and SubClass
68
;                     now (PCI 3.0). The Names of Classes and SubClasses
69
;                     are in the end of Vendors.inc
70
;            deleted
71
;                  * label "Descriptions" (names of Classes)
72
;
73
;----------------------------------------------------------------
74
;1.20: PCIDEV   16/08/2005
75
;Author:    Victor Alberto Gil Hanla a.k.a. vhanla 
76
;Features:
77
;           added
78
;                  * ! many vendor lists (865)
79
;           deleted
80
;                  * previous version's list
81
;           changed
82
;                  * previous Company Name searching and printing
83
;----------------------------------------------------------------
84
;1.15: PCIDEV   03/06/2005
85
;Author:    Sergey Kuzmin aka Wildwest 
86
;Features:
87
;           added
88
;                                  * quantity of devices,
89
;                                  * ! detection of Company Name based on Vendor ID,
90
;                                  * database of VenID (35 ID's),
91
;                                  * macros.inc for smaller size,
92
;           changed
93
;                                  * interface+(skinned window),
94
;                                  * VenID before DevID in 'table'(was DevID before VenID)
95
;----------------------------------------------------------------
96
;1.0: PCIDEV    30/01/2005
97
;Author:    Jason Delozier
98
;Features:
99
;          able to
100
;                 * detect PCI version,
101
;                 * quantity of PCI buses,
102
;                 * Vendor&Device ID for appropriate Device on Bus;
103
;                 * detect Revision, Class and Subclass of Device,
104
;                 * and make Description based on Class
105
;-------------------------------------------------------------
106
use32
107
 
108
	org    0x0
109
 
110
	db     'MENUET01'; 8 byte id
111
	dd     0x01	 ; header version
112
	dd     START	 ; start of code
113
	dd     I_END	 ; size of image
114
	dd     0xFFFF	 ; memory for app = 64 KB
115
	dd     I_END	 ; esp
116
	dd     0x0 , 0x0 ; I_Param , I_Icon
117
 
118
 
119
include 'macros.inc'
120
include 'VENDORS.INC'
121
 
122
START:	  ; start of execution
123
     call draw_window
124
 
125
still:
126
    mov  eax,10   ; wait here for event
127
    int  0x40
128
 
129
    cmp  eax,1	 ; redraw request ?
130
    je	red
131
    cmp  eax,2	 ; key in buffer ?
132
    je	key
133
    cmp  eax,3	 ; button in buffer ?
134
    je	button
135
 
136
    jmp  still
137
 
138
  red:	  ; redraw
139
    mov eax, 9		    ;window redraw requested so get new window coordinates and size
140
    mov ebx, Proc_Info	    ;area to store process information
141
    mov ecx, -1 	    ;
142
    int 0x40		    ;get the process information
143
    mov eax,[Proc_Info+34]  ;store the window coordinates into the Form Structure
144
    mov [Form+2], ax	    ;x start position
145
    mov eax,[Proc_Info+38]  ;
146
    mov [Form+6],ax	    ;ystart position
147
    mov eax,[Proc_Info+42]  ;
148
    mov [Form],ax	    ;window width
149
    mov eax,[Proc_Info+46]  ;
150
    mov [Form+4] ,ax	    ;window height
151
    call draw_window	    ;go redraw window now
152
    jmp  still
153
 
154
  key:	  ; key
155
    mov  eax,2	 ; just read it and ignore
156
    int  0x40
157
    jmp  still
158
  button:   ; button
159
    mov  eax,17   ; get id
160
    int  0x40
161
 
162
    cmp  ah,1	; button id=1 ?
163
    jne  noclose
164
 
165
    mov  eax,-1   ; close this program
166
    int  0x40
167
  noclose:
168
    jmp  still
169
 
170
 
171
 
172
 
173
;   *********************************************
174
;   *******  WINDOW DEFINITIONS AND DRAW ********
175
;   *********************************************
176
Form:
177
   dw 780 ;window width
178
   dw 100 ;window x start
179
   dw 420 ;window height
180
   dw 100 ;window y start
181
 
182
 
183
 
184
draw_window:
185
 
186
    mov byte [total],0
187
 
188
    mov  eax,12      ; function 12:tell os about windowdraw
189
    mov  ebx,1	     ; 1, start of draw
190
    int  0x40
191
    ; DRAW WINDOW
192
    mov  eax,0			   ; function 0 : define and draw window
193
    mov  ebx, dword [Form]	   ; x/width of window
194
    mov  ecx, dword [Form+4]	   ; y/height of window
195
    mov  edx,0x03ffffff 	   ; color of work area RRGGBB,8->color gl
196
    mov  esi,0x805080d0 	   ; color of grab bar  RRGGBB,8->color gl
197
    mov  edi,0x005080d0 	   ; color of frames    RRGGBB
198
    int  0x40			   ; draw the window
199
    ; WINDOW LABEL
200
    mov  eax,4			   ; function 4 : write text to window
201
    mov  ebx,8*65536+8		   ; [x start] *65536 + [y start]
202
    mov  ecx,0x10ddeeff 	   ; font 1 & color ( 0xF0RRGGBB )
203
    mov  edx,labelt		   ; pointer to text beginning
204
    mov  esi,labellen-labelt	   ; text length
205
    int  0x40
206
 
207
    ;draw captions to window
208
    mov ebx, 20*65536+25	   ;x start, ystart of text
209
    mov ecx, 0x224466		   ;color of text
210
    mov edx, dword PCIWin	   ;start of text buffer
211
    mov esi, 106		   ;lenght of line
212
newline:			   ;
213
    mov eax, 4			   ;draw text system function
214
    int 0x40			   ;draw the text
215
    add ebx, 10 		   ;one line down
216
    add edx, esi		   ;add lenght of line to offset of text buffer
217
    cmp byte[edx], byte 'x'	   ;is it the end of buffer?
218
    jne newline 		   ;if not draw another line of text
219
 
220
    ;Insert horizontal bars  in list area
221
    mov eax, 13 		   ;draw bar system function
222
    mov ebx, 18 		   ;set Xstart position of bar
223
    shl ebx, 16 		   ;
224
    mov bx,word [Form]		   ;get width of window
225
    sub bx, 32			   ;bar is 32 pixels shorter then window width
226
    mov ecx, 109*65536+10	   ;set Ystart(109) and Height(10) of bar
227
    mov edx, 0xb6b6b6		   ;set color of bar
228
   again:			   ;begin draw bar loop
229
    int 0x40			   ;draw bar to window area
230
    shr ecx, 16 		   ;move the Ystart position to working area
231
    add ecx, 34 		   ;add 34 pixels to Y Start (moves bar down)
232
    cmp cx,word [Form+4]	   ;is the Ystart position outside of window area
233
    jae nomo			   ;if so stop drawing bars
234
    sub ecx, 14 		   ;if not, we only need 20 pixels between bar tops
235
    shl ecx, 16 		   ;set that values as Ystart
236
    add ecx, 10 		   ;Bar Height is always 10 pixels
237
    jmp again			   ;draw another bar
238
   nomo:			   ;done drawing bars here
239
 
240
    ;start PCI stuff
241
    call Get_PCI_Info		   ;get pci version and last bus
242
    mov cx,word [PCI_Version]	   ;number to draw
243
    mov eax, 47 		   ;draw number system function
244
    xor esi, esi		   ;color of text
245
    mov ebx, 0x00040100 	   ;4 digits to draw in hex format
246
    mov edx, 110*65536+45	   ;x/y start position of number
247
    int 0x40			   ;draw pci version to window
248
    mov cl,byte [PCI_LastBus]	   ;number to draw
249
    mov ebx, 0x00020100 	   ;2 digits hex format
250
    add edx, 10 		   ;one line below pci version
251
    int 0x40			   ;draw the last bus to window
252
 
253
    call scan_Pci		   ;scan for and draw each pci device
254
 
255
    movzx ecx, byte [total]	   ;number to draw
256
    mov eax, 47 		   ;draw number system function
257
    mov ebx, 0x00020000 	   ;2 digits to draw in decimal format
258
    xor esi, esi		   ;color of text
259
    mov edx, 150*65536+65	   ;x/y position to draw to
260
    int 0x40			   ;draw total number of devices to window
261
 
262
    mov  eax,12 		   ; function 12:tell os about windowdraw
263
    mov  ebx,2			   ; 2, end of draw
264
    int  0x40
265
 
266
    ret
267
;   ***********************************************
268
;   *******  END WINDOW DEFINITIONS & DRAW  *******
269
;   ***********************************************
270
 
271
 
272
;******************************************************
273
;* Gets the PCI Versioin and Last Bus
274
Get_PCI_Info:
275
    mov eax, 62
276
    xor ebx, ebx
277
    int 0x40
278
    mov word [PCI_Version], ax
279
    mov eax, 62
280
    mov ebx, 1
281
    int 0x40
282
    mov byte [PCI_LastBus], al
283
ret
284
;******************************************************
285
 
286
 
287
;******************************************************
288
;* Get all devices on PCI Bus
289
scan_Pci:
290
   cmp	byte [PCI_LastBus],0xff ;0xFF means no pci bus found
291
   jne	Pci_Exists		;
292
   ret				;if no bus then leave
293
Pci_Exists:
294
   mov	byte [V_Bus], 0 	;reset varibles
295
   mov	byte [V_Dev], 0 	;
296
   mov	edx,  20*65536+110	;set start write position
297
Start_Enum:
298
   mov	bl, 6			;get a dword
299
   mov	bh, byte [V_Bus]	;bus of pci device
300
   mov	ch, byte [V_Dev]	;device number/function
301
   mov	cl, 0			;offset to device/vendor id
302
   mov	eax, 62 		;pci system function
303
   int	0x40			;get ID's
304
 
305
   cmp	ax, 0			;Vendor ID should not be 0 or 0xFFFF
306
   je	nextDev 		;check next device if nothing exists here
307
   cmp	ax, 0xffff		;
308
   je	nextDev 		;
309
 
310
   mov	word [PCI_Vendor], ax	;There is a device here, save the ID's
311
   shr	eax, 16 		;
312
   mov	word [PCI_Device], ax	;
313
   mov	eax, 62 		;PCI Sys Function
314
   mov	bl, 4			;Read config byte
315
   mov	bh, byte [V_Bus]	;Bus #
316
   mov	ch, byte [V_Dev]	;Device # on bus
317
   mov	cl, 0x08		;Register to read (Get Revision)
318
   int	0x40			;Read it
319
   mov	byte [PCI_Rev], al	;Save it
320
   mov	eax, 62 		;PCI Sys Function
321
   mov	cl, 0x0b		;Register to read (Get class)
322
   int	0x40			;Read it
323
   mov	byte [PCI_Class], al	;Save it
324
   mov	eax, 62 		;PCI Sys Function
325
   mov	cl, 0x0a		;Register to read (Get Subclass)
326
   int	0x40			;Read it
327
   mov	byte [PCI_SubClass], al ;Save it
328
   inc	byte [total]		;one more device found
329
   call Print_New_Device	;print device info to screen
330
nextDev:
331
   inc	byte [V_Dev]		;next device on this bus
332
   jnz	Start_Enum		;jump until we reach zero
333
				;(used to be JNO which caused bug!!! 30-4-2006, JMD)
334
   mov	byte [V_Dev], 0 	;reset device number
335
   inc	byte [V_Bus]		;next bus
336
   mov	al, byte [PCI_LastBus]	;get last bus
337
   cmp	byte [V_Bus], al	;was it last bus
338
   jbe	Start_Enum		;if not jump to keep searching
339
ret
340
;******************************************************
341
 
342
 
343
 
344
;******************************************************
345
;* Print device info to screen
346
Print_New_Device:
347
   mov	 eax, 47		;Write number to screen system function
348
   mov	 ebx, 0x00040100	;4 byte number, print in hexidecimal
349
   xor	 esi, esi              	;Color of text
350
   movzx ecx,word [PCI_Vendor]	;Pointer to number to be written
351
   int	 0x40			;Write Vendor ID
352
   and	 edx, 0xFFFF		;*****************************************
353
   or	 edx, 54*65536		;X start becomes 54
354
   movzx ecx,word [PCI_Device]	;get Vendor ID
355
   int	 0x40			;Draw Vendor ID to Window
356
   mov	 ebx, 0x00020100	;2 digit number, in hexidecimal format
357
   and	 edx, 0xFFFF		;*****************************************
358
   or	 edx, 98*65536		;X start becomes 98
359
   movzx ecx,byte [V_Bus]	;get bus number
360
   int	 0x40			;draw bus number to screen
361
   and	 edx, 0xFFFF		;*****************************************
362
   or	 edx, 128*65536 	;X start becomes 128
363
   movzx ecx,byte [V_Dev]	;get device number
364
   shr	 ecx, 3 		;device number is bits 3-7
365
   int	 0x40			;Draw device Number To Window
366
   and	 edx, 0xFFFF		;*****************************************
367
   or	 edx, 155*65536 	;X start becomes 155
368
   movzx ecx, byte [V_Dev]	;get Function number
369
   and	 ecx, 7 		;function is first 3 bits
370
   int	 0x40			;Draw Function Number To Window
371
   and	 edx, 0xFFFF		;*****************************************
372
   or	 edx, 179*65536 	;X start becomes 179
373
   movzx ecx,byte [PCI_Rev]	;get revision number
374
   int	 0x40			;Draw Revision to screen
375
   and	 edx, 0xFFFF		;*****************************************
376
   or	 edx, 215*65536 	;X start becomes 215
377
   movzx ecx,byte [PCI_Class]	;get PCI_Class
378
   int	 0x40			;Draw Class to screen
379
   and	 edx, 0xFFFF		;*****************************************
380
   or	 edx, 266*65536 	;X start becomes 266
381
   movzx ecx,byte [PCI_SubClass];get sub class
382
   int	 0x40			;Draw Sub Class to screen
383
   ;Write Names
384
   movzx ebx, dx		;Set y position
385
   or	 ebx, 310*65536 	;set Xposition to 310
386
 
387
;**********************************************************
388
;Prints the Vendor's Name based on Vendor ID
389
;
390
; modified part by vhanla (I know it is not a fastest way to search)
391
; it needs optimization... HELP this project!
392
;
393
; Modified on 30-04-2006 by JMD for size
394
;-----------------------------------------------------------------------------
395
    ;first determine which list to find the vendor in
396
    mov ax, word [PCI_Vendor]
397
    mov ecx, 255	   ;# vendors in most lists
398
    cmp ax,4800 	   ;Check if Vendor's value is less than this number
399
    jae next1		   ;if it is less, let's continue, or jump to next1
400
      mov edx, _FIRSTPART  ;select this list
401
      jmp rep1		   ;start searching list
402
  next1:		   ;
403
    cmp ax,5314 	   ;same thing happening here as above^
404
    jae next2		   ;
405
      mov edx, _SECONDPART ;
406
      jmp rep1		   ;
407
  next2:		   ;
408
    cmp ax,5574 	   ;
409
    jae next3		   ;
410
      mov edx, _THIRDPART  ;
411
      jmp rep1		   ;
412
  next3:		   ;
413
      mov ecx, 110	   ;only 110 vendors in this list
414
      mov edx, _FOURTHPART ;
415
 
416
  rep1:
417
   cmp ax,word[edx+50]	   ;are Vendor ID's the same?
418
   je  ex		   ;if so jump to print the description to screen
419
   add edx, 52		   ;if not put us at start of next description
420
   dec ecx		   ;one less description in list
421
   jnz rep1		   ;was it our last?
422
   mov edx, _UNKNOWN	   ;if so we dont know this Vendor
423
 
424
 ex:
425
  ;lets print the vendor Name
426
   xor ecx, ecx 	   ;font color
427
   mov eax,4		   ;OS CMD
428
   mov esi,50		   ;Length of text
429
   int 0x40		   ;Print the text
430
;------------------------------------------------------------------
431
 
432
;------------------------------------------------------------------
433
;Get description based on Class/Subclass
434
   cmp	 byte [PCI_Class], 11h	  ;we only know of 17 classes
435
   ja	 endd			  ;if its more then, its unknown to us, so jump
436
   movzx eax, byte [PCI_Class]	  ;load our class
437
   shl	 eax, 3 		  ;multiply for jump table
438
   mov	 ecx, [ClassList+eax+4]   ;number of descriptions for this class
439
   mov	 edx, [ClassList+eax]	  ;start of description list for class
440
   movzx eax, byte [PCI_SubClass] ;get subclass
441
 repu1:
442
   cmp	 al,byte[edx+32]	  ;are subclasses the same?
443
   je	 endd			  ;if so jump to print the description to screen
444
   add	 edx, 33		  ;if not put us at start of next description
445
   dec	 ecx			  ;one less description in list
446
   jnz	 repu1			  ;was it our last?
447
   mov	 edx,_UNKNOWND		  ;if so its unknown device
448
 endd:
449
   and	 ebx, 0x0000FFFF	  ;clear X position
450
   or	 ebx, 0x02300000	  ;set X position to 560 pixels
451
   xor	 ecx, ecx		  ;color of text
452
   mov	 eax,4			  ;draw text system function
453
   mov	 esi,32 		  ;length of text to draw
454
   int	 0x40			  ;draw the text
455
 
456
   movzx edx, bx		  ;get y coordinate
457
   add	 edx, 0x0014000A	  ;add 10 to y coordinate and set x coordinate to 20
458
ret
459
 
460
ClassList:
461
 dd Class0 ,  2, Class1 , 8, Class2,  8, Class3, 4
462
 dd Class4 ,  4, Class5 , 3, Class6, 12, Class7, 7
463
 dd Class8 ,  8, Class9 , 6, ClassA,  2, ClassB, 7
464
 dd ClassC , 10, ClassD , 8, ClassE,  1, ClassF, 4
465
 dd Class10,  3, Class11, 5
466
;------------------------------------------------------------------
467
 
468
 
469
 
470
; DATA AREA
471
 
472
labelt:
473
db 'PCI Device Enumeration v 1.31 by J. Delozier, S. Kuzmin and V. Hanla'
474
 labellen:
475
 
476
PCIWin:
477
db 'Please remember to enable PCI Access to Applications in Setup Menu.'
478
db '                                       '
479
db '                                                                   '
480
db '                                       '
481
db 'PCI Version  =                                                     '
482
db '                                       '
483
db 'Last PCI Bus =                                                     '
484
db '                                       '
485
db 'Quantity of devices =                                              '
486
db '                                       '
487
db '                                                                   '
488
db '                                       '
489
db 'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass                 Comp'
490
db 'any                      Description   '
491
db '----- ----- ---- ---- --- ---  -----  -------- --------------------'
492
db '---------------------- ----------------'
493
db 'x'
494
 
495
total	     db 0
496
V_Bus	     db 0
497
V_Dev	     db 0
498
PCI_Version  dw 0
499
PCI_LastBus  db 0
500
PCI_Device   dw 0
501
PCI_Vendor   dw 0
502
PCI_Bus      db 0
503
PCI_Dev      db 0
504
PCI_Rev      db 0
505
PCI_Class    db 0
506
PCI_SubClass db 0
507
 
508
 
509
Proc_Info:
510
 times 1024 db 0
511
 
512
I_END: