-
Notifications
You must be signed in to change notification settings - Fork 9
/
PCI.ASM
534 lines (392 loc) · 8.6 KB
/
PCI.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
_TEXT segment dword public 'CODE'
assume cs:_TEXT
.386p
; general notes:
;
; arguments are pushed from right to left
; when the C calling convention is used
;
; int far cdecl _pci_is_bios_present( void )
;
; returns 1 in AX if PCI BIOS is present
; returns 0 in AX otherwise
;
_pci_is_bios_present proc far
; save the caller's registers
;
push edx
; AH = PCI function ID
; AL = PCI BIOS presence query
;
mov ax, 0B101h
int 1Ah
; should now have "PCI " in EDX register
;
cmp edx, " ICP" ; byte swapped for little-endian
setz al ; AL = 1 IFF zero flag set
cbw ; AX = AL w/ sign extension
; restore the caller's registers
;
pop edx
ret
_pci_is_bios_present endp
; unsigned short far _cdecl pci_get_device_handle(
; unsigned short device_id, // BP + 6
; unsigned short vendor_id, // BP + 8
; unsigned short index // BP + 10
; )
;
; returns the handle of the Nth device with the
; desired device ID and vendor ID
;
; call this function multiple times, incrementing
; the index from zero onward, until it returns
; 0xFFFF indicating no (more) cards matched
;
; note: for Trancell Systems PCI-155 ATM network
; interface card, the device ID is 11D3h and the
; vendor ID is 0002h
;
_pci_get_device_handle proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push cx
push si
; AH = PCI function ID
; AL = find device
;
mov ax, 0B102h
mov cx, [bp + 6]
mov dx, [bp + 8]
mov si, [bp + 10]
int 1Ah
jnc handle_ok
mov ax, 0FFFFh
jmp handle_done
handle_ok:
; move the handle into AX for return to C
;
; the minimal doc I have says that device handle
; is just the upper 5 bits (7:3) of BL, but
; disassembly of TESTCM.EXE provided by Trancell
; uses entire contents of BX to pass to its next
; call to PCI BIOS, so I assume that is where
; the bits should stay
;
movzx ax, bl
handle_done:
; restore the caller's registers
;
pop si
pop cx
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_get_device_handle endp
; Bit32 far _cdecl pci_read_config_32(
; Bit16 device_handle, // BP + 6
; Bit16 offset // BP + 8
; )
;
; returns the 32-bit configuration register
; on the PCI device with the given handle
; at the given offset
;
; errors are ignored
;
_pci_read_config_32 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push bx
push ecx
push di
; AH = PCI function ID
; AL = read configuration DWORD
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
;
mov ax, 0B10Ah
mov bx, [bp + 6]
mov di, [bp + 8]
int 1Ah
; move the value into DX:AX for return to C language
;
mov ax, cx
shr ecx, 16
mov dx, cx
; restore the caller's registers
;
pop di
pop ecx
pop bx
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_read_config_32 endp
; Bit16 far _cdecl pci_read_config_16(
; Bit16 device_handle, // BP + 6
; Bit16 offset // BP + 8
; )
;
; returns the 16-bit configuration register
; on the PCI device with the given handle
; at the given offset
;
; errors are ignored
;
_pci_read_config_16 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push bx
push cx
push di
; AH = PCI function ID
; AL = read configuration WORD
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
;
mov ax, 0B109h
mov bx, [bp + 6]
mov di, [bp + 8]
int 1Ah
; move the value into AX for return to C language
;
mov ax, cx
; restore the caller's registers
;
pop di
pop cx
pop bx
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_read_config_16 endp
; Bit8 far _cdecl pci_read_config_8(
; Bit16 device_handle, // BP + 6
; Bit16 offset // BP + 8
; )
;
; returns the 8-bit configuration register
; on the PCI device with the given handle
; at the given offset
;
; errors are ignored
;
_pci_read_config_8 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push bx
push cx
push di
; AH = PCI function ID
; AL = read configuration BYTE
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
;
mov ax, 0B108h
mov bx, [bp + 6]
mov di, [bp + 8]
int 1Ah
; move the value into AL for return to C language
;
mov al, cl
; restore the caller's registers
;
pop di
pop cx
pop bx
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_read_config_8 endp
; void far _cdecl pci_write_config_32(
; Bit16 device_handle, // BP + 6
; Bit16 offset, // BP + 8
; Bit32 value // BP + 10
; )
;
; sets the 32-bit configuration register
; on the PCI device with the given handle
; at the given offset to the given value
;
; errors are ignored
;
_pci_write_config_32 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push ax
push bx
push ecx
push di
; AH = PCI function ID
; AL = write configuration DWORD
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
; ECX = value to write
;
mov ax, 0B10Dh
mov bx, [bp + 6]
mov di, [bp + 8]
mov ecx, [bp + 10]
int 1Ah
; restore the caller's registers
;
pop di
pop ecx
pop bx
pop ax
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_write_config_32 endp
; void far _cdecl pci_write_config_16(
; Bit16 device_handle, // BP + 6
; Bit16 offset, // BP + 8
; Bit16 value // BP + 10
; )
;
; sets the 16-bit configuration register
; on the PCI device with the given handle
; at the given offset to the given value
;
; errors are ignored
;
_pci_write_config_16 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push ax
push bx
push cx
push di
; AH = PCI function ID
; AL = write configuration WORD
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
; CX = value to write
;
mov ax, 0B10Ch
mov bx, [bp + 6]
mov di, [bp + 8]
mov cx, [bp + 10]
int 1Ah
; restore the caller's registers
;
pop di
pop cx
pop bx
pop ax
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_write_config_16 endp
; void far _cdecl pci_write_config_8(
; Bit16 device_handle, // BP + 6
; Bit16 offset, // BP + 8
; Bit8 value // BP + 10
; )
;
; sets the 8-bit configuration register
; on the PCI device with the given handle
; at the given offset to the given value
;
; errors are ignored
;
_pci_write_config_8 proc far
; set up the stack frame
;
push bp
mov bp, sp
; save the caller's registers
;
push ax
push bx
push cx
push di
; AH = PCI function ID
; AL = write configuration BYTE
; BX 15:8 = bus number
; 7:3 = device ID
; 2:0 = function number (subdevice)
; DI = byte offset into config space
; CL = value to write
;
mov ax, 0B10Bh
mov bx, [bp + 6]
mov di, [bp + 8]
mov cl, [bp + 10]
int 1Ah
; restore the caller's registers
;
pop di
pop cx
pop bx
pop ax
; clean up the stack frame
;
pop bp
; caller cleans up the stack themselves
;
ret
_pci_write_config_8 endp
public _pci_is_bios_present
public _pci_get_device_handle
public _pci_read_config_32
public _pci_read_config_16
public _pci_read_config_8
public _pci_write_config_32
public _pci_write_config_16
public _pci_write_config_8
_TEXT ends
end