Subversion Repositories Kolibri OS

Rev

Rev 587 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
587 Ghost 1
;***************************************************************
2
; project name:    PCI Device Enumeration
3
; target platform: KolibriOS
4
; compiler:        flat assmebler 1.66
5
; version:         2.1
6
; last update:     April 2007
7
; maintained by:   Jason Delozier (cordata51@hotmail.com)
8
;                  Sergey Kuzmin (kuzmin_serg@list.ru)
9
;                  Mihailov Ilia (ghost.nsk@gmail.com)
10
; project site:    http://www.coolthemes.narod.ru/pcidev.html
11
;***************************************************************
12
;Summary: This program will attempt to scan the PCI Bus
13
;        and display basic information about each device
14
;        connected to the PCI Bus.
15
;***************************************************************
16
;HISTORY:
17
;keep dates in european format (dd/mm/yyyy), please
18
; '!' means big changes
19
;
20
;to-do:
21
; more vendors
22
; vendor's website
23
; Subsystem id and Subsystem vendor id detection
24
 
25
; Full device detection (like "ATI Radeon 9200") will increase app
26
; size a lot and probably it is function of particular drivers
27
;----------------------------------------------------------------
28
;2.1n: PCIDEV   ??/04/2007
29
;Author:    Mihailov Ilia aka Ghost 
30
;Features:
31
;           added
32
;                 * new PCI API
33
;----------------------------------------------------------------
34
;2.1: PCIDEV   ??/04/2007
35
;Author:    Mihailov Ilia aka Ghost 
36
;Features:
37
;           fixed
38
;                 * Same little bugs
39
;                 * Source code formating
40
;                 * PCI version normalized 0210 -> 2.10
41
;           added
42
;                 * + 13 vendor (total now 1000!)
43
;                 * + 3 class type
44
;                 * Fast call source ready
45
;                 * Device IRQ detection
46
;           optimized
47
;                 * ! size optimized (61025 -> 32501 see added)
48
;                 * easy to add new vendor & class names
49
;----------------------------------------------------------------
50
;2.0: PCIDEV   30/08/2006
51
;(it differs a lot from the version 1.0, which was introduced 19 months ago)
52
;Author:    Marat Zakiyanov aka Mario79 
53
;           Sergey Kuzmin aka Wildwest 
54
;Features:
55
;           added
56
;                 * Detection of Interface by Mario79
57
;                 * 122 vendor id's by Wildwest
58
;                 * Description is based on Class, SubClass and Interface now (PCI 3.0) by Wildwest
59
;----------------------------------------------------------------
60
;1.31: PCIDEV   13/05/2006
61
;Author:    Jason Delozier 
62
;Features:
63
;           fixed
64
;                 * ! bug in Company Name look up code that would cause Unknown Name errors.
65
;                 * ! possible bugs, many instructions missing byte, word, dword prefixes
66
;                 * ! possible bug which could have occured after removing  "PREVIOUSVERSIONLIST"
67
;                     entry in loop up code and not fixing jump parameters.
68
;           added
69
;                 *  comments to various parts of the code
70
;           optimized
71
;                 * various parts of the source, too many to remember and mention.
72
;                 * changed entries for Subclasses in vendors.inc to Byte format, saves a little space.
73
;----------------------------------------------------------------
74
;1.30: PCIDEV   11/05/2006
75
;Author:    Sergey Kuzmin aka Wildwest 
76
;Features:
77
;           added
78
;                * 3 new vendor id's (ESS from Madis Kalme and 2 id's
79
;                  forgotten from 1.15 release: Broadcom -SiByte and Chaintech Comp.)
80
;           changed
81
;                * I don't know why other devs (Jason or Victor) changed window style
82
;                  to old ugly one, so I changed it back to skinned type 3.
83
;                * the same goes to the use of macroc.inc - it is enabled again.
84
;           deleted
85
;                * there is no more label "PREVIOUSVERSIONLIST" - id's moved to the
86
;                  appropriate parts of global list.
87
;----------------------------------------------------------------
88
;1.29: PCIDEV   30/04/2006
89
;Author:    Jason Delozier 
90
;Features:
91
;           fixed
92
;                 * ! bug that would not allow devices with device
93
;                   numbers > 16 to be displayed.
94
;           added
95
;                 * ! another heading called "FNC" (function) which allows
96
;                   the multipurpose Device/Function varible to be split and
97
;                   displayed to the user properly.
98
;                 * horizontal bars to display for easier reading.
99
;           optimized
100
;                 * vendor/description search routines for speed and space.
101
;----------------------------------------------------------------
102
;1.25: PCIDEV   02/10/2005
103
;Author:    Sergey Kuzmin aka Wildwest 
104
;Features:
105
;            changed
106
;                  * ! Description is based on Class and SubClass
107
;                     now (PCI 3.0). The Names of Classes and SubClasses
108
;                     are in the end of Vendors.inc
109
;            deleted
110
;                  * label "Descriptions" (names of Classes)
111
;
112
;----------------------------------------------------------------
113
;1.20: PCIDEV   16/08/2005
114
;Author:    Victor Alberto Gil Hanla a.k.a. vhanla 
115
;Features:
116
;           added
117
;                  * ! many vendor lists (865)
118
;           deleted
119
;                  * previous version's list
120
;           changed
121
;                  * previous Company Name searching and printing
122
;----------------------------------------------------------------
123
;1.15: PCIDEV   03/06/2005
124
;Author:    Sergey Kuzmin aka Wildwest 
125
;Features:
126
;           added
127
;                 * quantity of devices,
128
;                 * ! detection of Company Name based on Vendor ID,
129
;                 * database of VenID (35 ID's),
130
;                 * macros.inc for smaller size,
131
;           changed
132
;                 * interface+(skinned window),
133
;                 * VenID before DevID in 'table'(was DevID before VenID)
134
;----------------------------------------------------------------
135
;1.0: PCIDEV    30/01/2005
136
;Author:    Jason Delozier
137
;Features:
138
;          able to
139
;                 * detect PCI version,
140
;                 * quantity of PCI buses,
141
;                 * Vendor&Device ID for appropriate Device on Bus;
142
;                 * detect Revision, Class and Subclass of Device,
143
;                 * and make Description based on Class
144
;-------------------------------------------------------------
3630 fedesco 145
include 'lang.inc'
587 Ghost 146
include	'macros.inc'
147
MEOS_APP_START
148
CODE
149
	call draw_window
150
 
151
still:	mcall	10			; wait here for event
152
	dec	eax			; redraw request ?
153
	jz	red
154
	dec	eax			; key in buffer ?
155
	jz	key
156
	dec	eax			; button in buffer ?
157
	jz	button
158
	jmp	still
159
 
160
red:					; redraw
161
	mcall	9, Proc_Info, -1	; window redraw requested so get new window coordinates and size
162
	mov	eax, [Proc_Info.x_start]; store the window coordinates into the Form Structure
163
	mov	[Form + 2], ax		; x start position
164
	mov	eax, [Proc_Info.y_start];
165
	mov	[Form + 6], ax		; ystart position
166
	mov	eax, [Proc_Info.x_size]	;
167
	mov	[Form], ax		; window width
168
	mov	eax, [Proc_Info.y_size]	;
169
	mov	[Form + 4] ,ax		; window height
170
	call	draw_window		; go redraw window now
171
	jmp	still
172
 
173
key:					; key
174
	mcall	2			; just read it and ignore
175
	jmp	still
176
button:					; button
177
	mcall	17			; get id
178
	cmp	ah, 1			; button id = 1 ?
179
	jne	still
180
	mcall	-1			; close this program
181
 
182
draw_window:
183
	mov	byte [total], 0
184
	mcall	12, 1			; start of draw
185
	; DRAW WINDOW
186
	mcall	0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
187
	; Insert horizontal bars  in list area
188
	mov	eax, 13			; draw bar system function
189
	mov	ebx, 18			; set Xstart position of bar
190
	shl	ebx, 16			;
191
	mov	bx, word [Form]	; get width of window
192
	sub	bx, 32			; bar is 32 pixels shorter then window width
193
	mov	ecx, 119 * 65536 + 10	; set Ystart(109) and Height(10) of bar   109
194
	mov	edx, 0xC0C0C0		; set color of bar
195
again:	;begin draw bar loop
196
	mcall				; draw bar to window area
197
	shr	ecx, 16			; move the Ystart position to working area
198
	add	ecx, 34			; add 34 pixels to Y Start (moves bar down)
199
	cmp	cx, word [Form + 4]	; is the Ystart position outside of window area
200
	jae	nomo			; if so stop drawing bars
201
	sub	ecx, 14			; if not, we only need 20 pixels between bar tops
202
	shl	ecx, 16			; set that values as Ystart
203
	add	ecx, 10			; Bar Height is always 10 pixels
204
	jmp	again			; draw another bar
205
nomo:					;done drawing bars here
206
	; start PCI stuff
207
	call	Get_PCI_Info		; get pci version and last bus, scan for and draw each pci device
208
 
209
	; Window inteface
210
	mov	cx, [PCI_Version]
211
	add	ch, '0'
212
	mov	[PCIWin + 85], ch	; 0xBADCODE but it work !
213
	mov	ch, cl
214
	shr	cl, 4
215
	and	ch, 0x0f
216
	add	cx, '00'
217
	mov	[PCIWin + 87], cx
218
	mov	cl, [PCI_LastBus]
219
	add	cl, '0'
220
	mov	[PCIWin + 105], cl
3630 fedesco 221
 
587 Ghost 222
	mov	edx, PCIWin
223
	mov	ebx, 20 * 65536 + 25	; x start, ystart of text
224
	mov	ecx, 0x224466		; color of text
225
	mov	eax, 4
226
@@:	movzx	esi, byte[edx]
227
	inc	edx
228
	mcall
229
	add	ebx, 10
230
	add	edx, esi
231
	cmp	byte[edx], -1
232
	jne	@b
233
	; Quantity of devices...
234
	movzx	ecx, byte [total]	; number to draw
235
	mcall	47, 0x00020000,,150 * 65536 + 65, 0x224466
236
 
237
	mcall	12, 2			; end of draw
238
	ret
239
 
240
;------------------------------------------------------------------
241
;* Gets the PCI Version and Last Bus
242
Get_PCI_Info:
243
	mov	ebp, 1
244
	mcall	57
245
	mov	word [PCI_Version], bx
246
	mov	byte [PCI_LastBus], cl
247
	;----------------------------------------------------------
248
	;* Get all devices on PCI Bus
249
	cmp	al, 0xff		; 0xFF means no pci bus found
250
	jne	Pci_Exists		;
251
	ret				; if no bus then leave
252
Pci_Exists:
253
	mov	byte [V_Bus], 0		; reset varibles
254
	mov	byte [V_Dev], 0		;
255
	mov	edx,  20 * 65536 + 110	; set start write position
256
Start_Enum:
257
	mov	ebp, 0x0a		; get a dword
258
	xor	edi, edi		; offset to device/vendor id
259
	mov	bh, byte [V_Bus]	; bus of pci device
260
	mov	bl, byte [V_Dev]	; device number/function
261
	mcall	57			; get ID's
262
	cmp	cx, 0			; Vendor ID should not be 0 or 0xFFFF
263
	je	nextDev			; check next device if nothing exists here
264
	cmp	cx, 0xffff		;
265
	je	nextDev			;
266
	mov	word [PCI_Vendor], cx	; There is a device here, save the ID's
267
	shr	ecx, 16			;
268
	mov	word [PCI_Device], cx	;
269
 
3630 fedesco 270
 
271
 
587 Ghost 272
	mov	ebp, 8			; Read config byte
273
	mov	bh, byte [V_Bus]	; Bus #
274
	mov	bl, byte [V_Dev]	; Device # on bus
275
	mov	edi, 0x08		; Register to read (Get Revision)
276
	mcall	57			; Read it
277
	mov	byte [PCI_Rev], cl	; Save it
3630 fedesco 278
 
587 Ghost 279
	mov	edi, 0x0b		; Register to read (Get class)
280
	mcall	57			; Read it
281
	mov	byte [PCI_Class], cl	; Save it
3630 fedesco 282
 
587 Ghost 283
	mov	edi, 0x0a		; Register to read (Get Subclass)
284
	mcall	57			; Read it
285
	mov	byte [PCI_SubClass], cl; Save it
286
; from Mario79 august 2006
287
	mov	edi, 0x09		; Register to read (Get Interface)
288
	mcall	57			; Read it
289
	mov  [PCI_Interface], cl	; Save it
290
;
291
; from Ghost april 2007
292
	mov	edi, 0x3c		; Register to read (Get IRQ)
293
	mcall	57			; Read it
294
	mov	[PCI_IRQ], cl		; Save it
295
;
296
	inc	byte [total]		; one more device found
297
	call	Print_New_Device	; print device info to screen
298
nextDev:
299
	inc	byte [V_Dev]		; next device on this bus
300
	jnz	Start_Enum		; jump until we reach zero
301
	;(used to be JNO which caused bug!!! 30-4-2006, JMD)
302
	mov	byte [V_Dev], 0		; reset device number
303
	inc	byte [V_Bus]		; next bus
304
	mov	al, byte [PCI_LastBus]	; get last bus
305
	cmp	byte [V_Bus], al	; was it last bus
306
	jbe	Start_Enum		; if not jump to keep searching
307
	ret
308
 
309
;------------------------------------------------------------------
310
;* Print device info to screen
311
Print_New_Device:
312
	xor	esi, esi		; Color of text
313
	movzx	ecx,word [PCI_Vendor]	; Pointer to number to be written
314
	mcall	47, 0x00040100		; Write Vendor ID
315
	and	edx, 0xFFFF		;*****************************************
316
	or	edx, 54 * 65536	; X start becomes 54
317
	movzx	ecx, word [PCI_Device]	; get Vendor ID
318
	mcall				; Draw Vendor ID to Window
319
	and	edx, 0xFFFF		;*****************************************
320
	or	edx, 98 * 65536	; X start becomes 98
321
	movzx	ecx, byte [V_Bus]	; get bus number
322
	mcall	,0x00020100		; draw bus number to screen
323
	and	edx, 0xFFFF		;*****************************************
324
	or	edx, 128 * 65536	; X start becomes 128
325
	movzx	ecx, byte [V_Dev]	; get device number
326
	shr	ecx, 3			; device number is bits 3-7
327
	mcall				; Draw device Number To Window
3630 fedesco 328
 
587 Ghost 329
	and	edx, 0xFFFF		;*****************************************
330
	or	edx, 155 * 65536	; X start becomes 155
331
	movzx	ecx, byte [V_Dev]	; get Function number
332
	and	ecx, 7			; function is first 3 bits
333
	mcall				; Draw Function Number To Window
334
	and	edx, 0xFFFF		;*****************************************
335
	or	edx, 179 * 65536	; X start becomes 179
336
	movzx	ecx, byte [PCI_Rev]	; get revision number
337
	mcall				; Draw Revision to screen
338
	and	edx, 0xFFFF		;*****************************************
339
	or	edx, 215*65536		; X start becomes 215
340
	movzx	ecx, byte [PCI_Class]	; get PCI_Class
341
	mcall				; Draw Class to screen
342
	and	edx, 0xFFFF		;*****************************************
343
	or	edx, 250*65536		; X start becomes 250
344
	movzx	ecx, byte [PCI_SubClass]; get sub class
345
	mcall				; Draw Sub Class to screen
346
; from Mario79 august 2006
347
	and	edx, 0xFFFF		;*****************************************
348
	or	edx, 280 * 65536	; X start becomes 280
349
	movzx	ecx, [PCI_Interface]	; get Interface
350
	mcall
351
;
352
; from Ghost april 2007			;*****************************************
353
	movzx	ecx, [PCI_IRQ]		; get Interface
354
	cmp	cl, 0x0f		; IRQ between 0..15
355
	ja	@f
356
	and	edx, 0xFFFF
357
	or	edx, 310 * 65536	; X start becomes 310
358
	mcall
359
@@:
360
;
361
	;Write Names
362
	movzx	ebx, dx		; Set y position
363
	or	ebx, 340*65536		; set Xposition to 340
364
 
365
;------------------------------------------------------------------
366
; Prints the Vendor's Name based on Vendor ID
367
;
368
; Modified on ??-04-2007 by Ghost for size
369
;------------------------------------------------------------------
370
	mov	edx, VendorsTab
371
	mov	cx, word[PCI_Vendor]
3630 fedesco 372
 
587 Ghost 373
.fn:	mov	ax, [edx]
374
	add	edx, 6
375
	test	ax, ax
376
	jz	.find
377
	cmp	ax, cx
378
	jne	.fn
379
.find:	mov	edx, [edx - 4]
380
	mcall	4,, 0x80000000		; lets print the vendor Name
381
 
382
;------------------------------------------------------------------
383
; Get description based on Class/Subclass
384
;
385
; Modified on ??-04-2007 by Ghost for size
386
;------------------------------------------------------------------
387
	mov	eax, dword [PCI_Class]
388
	and	eax, 0xffffff
389
	xor	edx, edx
390
	xor	esi, esi
391
.fnc:	inc	esi
392
	mov	ecx, [Classes + esi * 8 - 8]
393
	cmp	cx, 0xffff
394
	je	.endfc
395
	cmp	cx, ax
396
	jne	.fnc
397
	test	ecx, 0xff000000
398
	jz	@f
399
	mov	edx, [Classes + esi * 8 - 4]
400
	jmp	.fnc
401
@@:	cmp	eax, ecx
402
	jne	.fnc
403
	xor	edx, edx
404
.endfc:	test	edx, edx
405
	jnz	@f
406
	mov	edx, [Classes + esi * 8 - 4]
3630 fedesco 407
@@:
587 Ghost 408
	and	ebx, 0x0000FFFF		; clear X position
409
	or	ebx, 0x24E0000		; set X position to 590 pixels
410
	mcall	4,, 0x80000000,, 32	; draw the text
411
	movzx	edx, bx		; get y coordinate
412
	add	edx, 0x0014000A		; add 10 to y coordinate and set x coordinate to 20
413
	ret
414
 
3630 fedesco 415
include	'vendors.inc'
587 Ghost 416
;------------------------------------------------------------------
417
; DATA AREA
418
DATA
419
 
420
 
421
Form:	dw 800 ; window width (no more, special for 800x600)
422
	dw 100 ; window x start
423
	dw 420 ; window height
424
	dw 100 ; window y start
425
 
3630 fedesco 426
if lang eq it
587 Ghost 427
title	db 'PCI Device Enumeration v 2.1n new PCI API test', 0
428
PCIWin mls \
3630 fedesco 429
	'Ricordarsi di abilitare l accesso alla PCI per le applicazioni dal menu.',\
430
	'',\
431
	'Versione PCI = x.xx',\
432
	'Ultimo Bus PCI = x',\
433
	'Numerod di devices =',\
434
	'',\
435
	'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Compania                     Descrizione',\
436
	'                                      Interface',\
437
	'----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
438
else
439
title	db 'PCI Device Enumeration v 2.1n new PCI API test', 0
440
PCIWin mls \
587 Ghost 441
	'Please remember to enable PCI Access to Applications in Setup Menu.',\
442
	'',\
443
	'PCI Version  = x.xx',\
444
	'Last PCI Bus = x',\
445
	'Quantity of devices =',\
446
	'',\
447
	'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Company                      Description',\
448
	'                                      Interface',\
449
	'----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
3630 fedesco 450
end if
587 Ghost 451
;------------------------------------------------------------------
452
; UNINITIALIZED DATA AREA
453
UDATA
454
 
455
total		db ?
456
V_Bus		db ?
457
V_Dev		db ?
458
PCI_Version	dw ?
459
PCI_LastBus	db ?
460
PCI_Device	dw ?
461
PCI_Vendor	dw ?
462
PCI_Bus		db ?
463
PCI_Dev		db ?
464
PCI_Rev		db ?
465
; don`t change order!!!
466
PCI_Class	db ?
467
PCI_SubClass	db ?
468
PCI_Interface	db ?
469
PCI_IRQ		db ?
470
 
471
Proc_Info	process_information
472
MEOS_APP_END