Subversion Repositories Kolibri OS

Rev

Rev 3630 | 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
;-------------------------------------------------------------
145
include	'macros.inc'
146
MEOS_APP_START
147
CODE
148
	call draw_window
149
 
150
still:	mcall	10			; wait here for event
151
	dec	eax			; redraw request ?
152
	jz	red
153
	dec	eax			; key in buffer ?
154
	jz	key
155
	dec	eax			; button in buffer ?
156
	jz	button
157
	jmp	still
158
 
159
red:					; redraw
160
	mcall	9, Proc_Info, -1	; window redraw requested so get new window coordinates and size
7134 dunkaist 161
	mov	eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure
587 Ghost 162
	mov	[Form + 2], ax		; x start position
7134 dunkaist 163
	mov	eax, [Proc_Info.box.top];
587 Ghost 164
	mov	[Form + 6], ax		; ystart position
7134 dunkaist 165
	mov	eax, [Proc_Info.box.width];
587 Ghost 166
	mov	[Form], ax		; window width
7134 dunkaist 167
	mov	eax, [Proc_Info.box.height];
587 Ghost 168
	mov	[Form + 4] ,ax		; window height
169
	call	draw_window		; go redraw window now
170
	jmp	still
171
 
172
key:					; key
173
	mcall	2			; just read it and ignore
174
	jmp	still
175
button:					; button
176
	mcall	17			; get id
177
	cmp	ah, 1			; button id = 1 ?
178
	jne	still
179
	mcall	-1			; close this program
180
 
181
draw_window:
182
	mov	byte [total], 0
183
	mcall	12, 1			; start of draw
184
	; DRAW WINDOW
185
	mcall	0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
186
	; Insert horizontal bars  in list area
187
	mov	eax, 13			; draw bar system function
188
	mov	ebx, 18			; set Xstart position of bar
189
	shl	ebx, 16			;
190
	mov	bx, word [Form]	; get width of window
191
	sub	bx, 32			; bar is 32 pixels shorter then window width
192
	mov	ecx, 119 * 65536 + 10	; set Ystart(109) and Height(10) of bar   109
193
	mov	edx, 0xC0C0C0		; set color of bar
194
again:	;begin draw bar loop
195
	mcall				; draw bar to window area
196
	shr	ecx, 16			; move the Ystart position to working area
197
	add	ecx, 34			; add 34 pixels to Y Start (moves bar down)
198
	cmp	cx, word [Form + 4]	; is the Ystart position outside of window area
199
	jae	nomo			; if so stop drawing bars
200
	sub	ecx, 14			; if not, we only need 20 pixels between bar tops
201
	shl	ecx, 16			; set that values as Ystart
202
	add	ecx, 10			; Bar Height is always 10 pixels
203
	jmp	again			; draw another bar
204
nomo:					;done drawing bars here
205
	; start PCI stuff
206
	call	Get_PCI_Info		; get pci version and last bus, scan for and draw each pci device
207
 
208
	; Window inteface
209
	mov	cx, [PCI_Version]
210
	add	ch, '0'
211
	mov	[PCIWin + 85], ch	; 0xBADCODE but it work !
212
	mov	ch, cl
213
	shr	cl, 4
214
	and	ch, 0x0f
215
	add	cx, '00'
216
	mov	[PCIWin + 87], cx
217
	mov	cl, [PCI_LastBus]
218
	add	cl, '0'
219
	mov	[PCIWin + 105], cl
3630 fedesco 220
 
587 Ghost 221
	mov	edx, PCIWin
222
	mov	ebx, 20 * 65536 + 25	; x start, ystart of text
223
	mov	ecx, 0x224466		; color of text
224
	mov	eax, 4
225
@@:	movzx	esi, byte[edx]
226
	inc	edx
227
	mcall
228
	add	ebx, 10
229
	add	edx, esi
230
	cmp	byte[edx], -1
231
	jne	@b
232
	; Quantity of devices...
233
	movzx	ecx, byte [total]	; number to draw
234
	mcall	47, 0x00020000,,150 * 65536 + 65, 0x224466
235
 
236
	mcall	12, 2			; end of draw
237
	ret
238
 
239
;------------------------------------------------------------------
240
;* Gets the PCI Version and Last Bus
241
Get_PCI_Info:
242
	mov	ebp, 1
243
	mcall	57
244
	mov	word [PCI_Version], bx
245
	mov	byte [PCI_LastBus], cl
246
	;----------------------------------------------------------
247
	;* Get all devices on PCI Bus
248
	cmp	al, 0xff		; 0xFF means no pci bus found
249
	jne	Pci_Exists		;
250
	ret				; if no bus then leave
251
Pci_Exists:
252
	mov	byte [V_Bus], 0		; reset varibles
253
	mov	byte [V_Dev], 0		;
254
	mov	edx,  20 * 65536 + 110	; set start write position
255
Start_Enum:
256
	mov	ebp, 0x0a		; get a dword
257
	xor	edi, edi		; offset to device/vendor id
258
	mov	bh, byte [V_Bus]	; bus of pci device
259
	mov	bl, byte [V_Dev]	; device number/function
260
	mcall	57			; get ID's
261
	cmp	cx, 0			; Vendor ID should not be 0 or 0xFFFF
262
	je	nextDev			; check next device if nothing exists here
263
	cmp	cx, 0xffff		;
264
	je	nextDev			;
265
	mov	word [PCI_Vendor], cx	; There is a device here, save the ID's
266
	shr	ecx, 16			;
267
	mov	word [PCI_Device], cx	;
268
 
3630 fedesco 269
 
270
 
587 Ghost 271
	mov	ebp, 8			; Read config byte
272
	mov	bh, byte [V_Bus]	; Bus #
273
	mov	bl, byte [V_Dev]	; Device # on bus
274
	mov	edi, 0x08		; Register to read (Get Revision)
275
	mcall	57			; Read it
276
	mov	byte [PCI_Rev], cl	; Save it
3630 fedesco 277
 
587 Ghost 278
	mov	edi, 0x0b		; Register to read (Get class)
279
	mcall	57			; Read it
280
	mov	byte [PCI_Class], cl	; Save it
3630 fedesco 281
 
587 Ghost 282
	mov	edi, 0x0a		; Register to read (Get Subclass)
283
	mcall	57			; Read it
284
	mov	byte [PCI_SubClass], cl; Save it
285
; from Mario79 august 2006
286
	mov	edi, 0x09		; Register to read (Get Interface)
287
	mcall	57			; Read it
288
	mov  [PCI_Interface], cl	; Save it
289
;
290
; from Ghost april 2007
291
	mov	edi, 0x3c		; Register to read (Get IRQ)
292
	mcall	57			; Read it
293
	mov	[PCI_IRQ], cl		; Save it
294
;
295
	inc	byte [total]		; one more device found
296
	call	Print_New_Device	; print device info to screen
297
nextDev:
298
	inc	byte [V_Dev]		; next device on this bus
299
	jnz	Start_Enum		; jump until we reach zero
300
	;(used to be JNO which caused bug!!! 30-4-2006, JMD)
301
	mov	byte [V_Dev], 0		; reset device number
302
	inc	byte [V_Bus]		; next bus
303
	mov	al, byte [PCI_LastBus]	; get last bus
304
	cmp	byte [V_Bus], al	; was it last bus
305
	jbe	Start_Enum		; if not jump to keep searching
306
	ret
307
 
308
;------------------------------------------------------------------
309
;* Print device info to screen
310
Print_New_Device:
311
	xor	esi, esi		; Color of text
312
	movzx	ecx,word [PCI_Vendor]	; Pointer to number to be written
313
	mcall	47, 0x00040100		; Write Vendor ID
314
	and	edx, 0xFFFF		;*****************************************
315
	or	edx, 54 * 65536	; X start becomes 54
316
	movzx	ecx, word [PCI_Device]	; get Vendor ID
317
	mcall				; Draw Vendor ID to Window
318
	and	edx, 0xFFFF		;*****************************************
319
	or	edx, 98 * 65536	; X start becomes 98
320
	movzx	ecx, byte [V_Bus]	; get bus number
321
	mcall	,0x00020100		; draw bus number to screen
322
	and	edx, 0xFFFF		;*****************************************
323
	or	edx, 128 * 65536	; X start becomes 128
324
	movzx	ecx, byte [V_Dev]	; get device number
325
	shr	ecx, 3			; device number is bits 3-7
326
	mcall				; Draw device Number To Window
3630 fedesco 327
 
587 Ghost 328
	and	edx, 0xFFFF		;*****************************************
329
	or	edx, 155 * 65536	; X start becomes 155
330
	movzx	ecx, byte [V_Dev]	; get Function number
331
	and	ecx, 7			; function is first 3 bits
332
	mcall				; Draw Function Number To Window
333
	and	edx, 0xFFFF		;*****************************************
334
	or	edx, 179 * 65536	; X start becomes 179
335
	movzx	ecx, byte [PCI_Rev]	; get revision number
336
	mcall				; Draw Revision to screen
337
	and	edx, 0xFFFF		;*****************************************
338
	or	edx, 215*65536		; X start becomes 215
339
	movzx	ecx, byte [PCI_Class]	; get PCI_Class
340
	mcall				; Draw Class to screen
341
	and	edx, 0xFFFF		;*****************************************
342
	or	edx, 250*65536		; X start becomes 250
343
	movzx	ecx, byte [PCI_SubClass]; get sub class
344
	mcall				; Draw Sub Class to screen
345
; from Mario79 august 2006
346
	and	edx, 0xFFFF		;*****************************************
347
	or	edx, 280 * 65536	; X start becomes 280
348
	movzx	ecx, [PCI_Interface]	; get Interface
349
	mcall
350
;
351
; from Ghost april 2007			;*****************************************
352
	movzx	ecx, [PCI_IRQ]		; get Interface
353
	cmp	cl, 0x0f		; IRQ between 0..15
354
	ja	@f
355
	and	edx, 0xFFFF
356
	or	edx, 310 * 65536	; X start becomes 310
357
	mcall
358
@@:
359
;
360
	;Write Names
361
	movzx	ebx, dx		; Set y position
362
	or	ebx, 340*65536		; set Xposition to 340
363
 
364
;------------------------------------------------------------------
365
; Prints the Vendor's Name based on Vendor ID
366
;
367
; Modified on ??-04-2007 by Ghost for size
368
;------------------------------------------------------------------
369
	mov	edx, VendorsTab
370
	mov	cx, word[PCI_Vendor]
3630 fedesco 371
 
587 Ghost 372
.fn:	mov	ax, [edx]
373
	add	edx, 6
374
	test	ax, ax
375
	jz	.find
376
	cmp	ax, cx
377
	jne	.fn
378
.find:	mov	edx, [edx - 4]
379
	mcall	4,, 0x80000000		; lets print the vendor Name
380
 
381
;------------------------------------------------------------------
382
; Get description based on Class/Subclass
383
;
384
; Modified on ??-04-2007 by Ghost for size
385
;------------------------------------------------------------------
386
	mov	eax, dword [PCI_Class]
387
	and	eax, 0xffffff
388
	xor	edx, edx
389
	xor	esi, esi
390
.fnc:	inc	esi
391
	mov	ecx, [Classes + esi * 8 - 8]
392
	cmp	cx, 0xffff
393
	je	.endfc
394
	cmp	cx, ax
395
	jne	.fnc
396
	test	ecx, 0xff000000
397
	jz	@f
398
	mov	edx, [Classes + esi * 8 - 4]
399
	jmp	.fnc
400
@@:	cmp	eax, ecx
401
	jne	.fnc
402
	xor	edx, edx
403
.endfc:	test	edx, edx
404
	jnz	@f
405
	mov	edx, [Classes + esi * 8 - 4]
3630 fedesco 406
@@:
587 Ghost 407
	and	ebx, 0x0000FFFF		; clear X position
408
	or	ebx, 0x24E0000		; set X position to 590 pixels
409
	mcall	4,, 0x80000000,, 32	; draw the text
410
	movzx	edx, bx		; get y coordinate
411
	add	edx, 0x0014000A		; add 10 to y coordinate and set x coordinate to 20
412
	ret
413
 
3630 fedesco 414
include	'vendors.inc'
587 Ghost 415
;------------------------------------------------------------------
416
; DATA AREA
417
DATA
418
 
419
 
420
Form:	dw 800 ; window width (no more, special for 800x600)
421
	dw 100 ; window x start
422
	dw 420 ; window height
423
	dw 100 ; window y start
424
 
3630 fedesco 425
if lang eq it
587 Ghost 426
title	db 'PCI Device Enumeration v 2.1n new PCI API test', 0
427
PCIWin mls \
3630 fedesco 428
	'Ricordarsi di abilitare l accesso alla PCI per le applicazioni dal menu.',\
429
	'',\
430
	'Versione PCI = x.xx',\
431
	'Ultimo Bus PCI = x',\
432
	'Numerod di devices =',\
433
	'',\
434
	'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Compania                     Descrizione',\
435
	'                                      Interface',\
436
	'----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
437
else
438
title	db 'PCI Device Enumeration v 2.1n new PCI API test', 0
439
PCIWin mls \
587 Ghost 440
	'Please remember to enable PCI Access to Applications in Setup Menu.',\
441
	'',\
442
	'PCI Version  = x.xx',\
443
	'Last PCI Bus = x',\
444
	'Quantity of devices =',\
445
	'',\
446
	'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Company                      Description',\
447
	'                                      Interface',\
448
	'----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
3630 fedesco 449
end if
587 Ghost 450
;------------------------------------------------------------------
451
; UNINITIALIZED DATA AREA
452
UDATA
453
 
454
total		db ?
455
V_Bus		db ?
456
V_Dev		db ?
457
PCI_Version	dw ?
458
PCI_LastBus	db ?
459
PCI_Device	dw ?
460
PCI_Vendor	dw ?
461
PCI_Bus		db ?
462
PCI_Dev		db ?
463
PCI_Rev		db ?
464
; don`t change order!!!
465
PCI_Class	db ?
466
PCI_SubClass	db ?
467
PCI_Interface	db ?
468
PCI_IRQ		db ?
469
 
470
Proc_Info	process_information
471
MEOS_APP_END