forked from fysnet/i440fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpci.asm
2235 lines (1979 loc) · 64.9 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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
comment |*******************************************************************
* Copyright (c) 1984-2025 Forever Young Software Benjamin David Lunt *
* *
* i440FX BIOS ROM v1.0 *
* FILE: pci.asm *
* *
* This code is freeware, not public domain. Please use respectfully. *
* *
* You may: *
* - use this code for learning purposes only. *
* - use this code in your own Operating System development. *
* - distribute any code that you produce pertaining to this code *
* as long as it is for learning purposes only, not for profit, *
* and you give credit where credit is due. *
* *
* You may NOT: *
* - distribute this code for any purpose other than listed above. *
* - distribute this code for profit. *
* *
* You MUST: *
* - include this whole comment block at the top of this file. *
* - include contact information to where the original source is located. *
* https://github.com/fysnet/i440fx *
* *
* DESCRIPTION: *
* pci include file *
* *
* BUILT WITH: NewBasic Assembler *
* http://www.fysnet/newbasic.htm *
* NBASM ver 00.27.15 *
* Command line: nbasm i440fx /z<enter> *
* *
* Last Updated: 21 Jan 2025 *
* *
****************************************************************************
* Notes: *
* *
***************************************************************************|
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; pci protected mode entry point and tables
PCI_FIXED_HOST_BRIDGE equ 0x12378086 ; i440FX PCI bridge
PCI_FIXED_HOST_BRIDGE2 equ 0x01228086 ; i430FX PCI bridge
PCI_FIXED_HOST_BRIDGE3 equ 0x71908086 ; i440BX PCI bridge
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; this code is pmode code
; (https://wiki.osdev.org/BIOS32)
.pmode
.para
bios32_entry_point:
pushf
cmp eax,0x49435024 ; "$PCI"
jne short pci_unknown_service
mov eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
cmp eax,PCI_FIXED_HOST_BRIDGE
je short @f
cmp eax,PCI_FIXED_HOST_BRIDGE2
je short @f
cmp eax,PCI_FIXED_HOST_BRIDGE3
je short @f
cmp eax,0xFFFFFFFF
je short pci_unknown_service
@@: mov ebx,0x000E0000
mov edx,offset pcibios_protected
mov ecx,0x10000
xor al,al
jmp short @f
pci_unknown_service:
mov al,0x80
@@:
.ifdef BX_QEMU
and dword [esp+8],0xFFFFFFFC ; reset cs.RPL for kqemu ?????
.endif
popf
retf
.para
pcibios_protected:
pushf
cli
push esi
push edi
; installation check
cmp al,0x01
jne short @f
mov bx,0x0210
call pci_pro_get_max_bus
mov edx,0x20494350 ; 'PCI '
mov al,0x01
jmp pci_pro_ok
@@: ; find pci device
cmp al,0x02
jne short @f
shl ecx,16
mov cx,dx
xor bx,bx
mov di,0x00
pci_pro_devloop:
call pci_pro_select_reg
mov dx,0x0CFC
in eax,dx
cmp eax,ecx
jne short pci_pro_nextdev
or si,si
je pci_pro_ok
dec si
pci_pro_nextdev:
inc bx
cmp bx,0x0200
jne short pci_pro_devloop
mov ah,0x86
jmp pci_pro_fail
@@: ; find class code
cmp al,0x03
jne short @f
xor bx,bx
mov di,0x08
pci_pro_devloop2:
call pci_pro_select_reg
mov dx,0x0CFC
in eax,dx
shr eax,8
cmp eax,ecx
jne short pci_pro_nextdev2
or si,si
je pci_pro_ok
dec si
pci_pro_nextdev2:
inc bx
cmp bx,0x0200
jne short pci_pro_devloop2
mov ah,0x86
jmp pci_pro_fail
@@: ; read configuration byte
cmp al,0x08
jne short @f
call pci_pro_select_reg
push edx
mov dx,di
and dx,0x03
add dx,0x0CFC
in al,dx
pop edx
mov cl,al
jmp pci_pro_ok
@@: ; read configuration word
cmp al,0x09
jne short @f
call pci_pro_select_reg
push edx
mov dx,di
and dx,0x02
add dx,0x0CFC
in ax,dx
pop edx
mov cx,ax
jmp short pci_pro_ok
@@: ; read configuration dword
cmp al,0x0A
jne short @f
call pci_pro_select_reg
push edx
mov dx,0x0CFC
in eax,dx
pop edx
mov ecx,eax
jmp short pci_pro_ok
@@: ; write configuration byte
cmp al,0x0B
jne short @f
call pci_pro_select_reg
push edx
mov dx,di
and dx,0x03
add dx,0x0CFC
mov al,cl
out dx,al
pop edx
jmp short pci_pro_ok
@@: ; write configuration word
cmp al,0x0C
jne short @f
call pci_pro_select_reg
push edx
mov dx,di
and dx,0x02
add dx,0x0CFC
mov ax,cx
out dx,ax
pop edx
jmp short pci_pro_ok
@@: ; write configuration dword
cmp al,0x0D
jne short @f
call pci_pro_select_reg
push edx
mov dx,0x0CFC
mov eax,ecx
out dx,eax
pop edx
jmp short pci_pro_ok
@@: mov ah,0x81
pci_pro_fail:
pop edi
pop esi
.ifdef BX_QEMU
and dword [esp+8],0xFFFFFFFC ; reset cs.RPL for kqemu ?????
.endif
popfd
stc
retf
pci_pro_ok:
xor ah,ah
pop edi
pop esi
.ifdef BX_QEMU
and dword [esp+8],0xFFFFFFFC ; reset cs.RPL for kqemu ?????
.endif
popfd
clc
retf
pci_pro_get_max_bus:
push eax
mov eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
mov cx,0
cmp eax,PCI_FIXED_HOST_BRIDGE3
jne short @f
mov cx,0x0001
@@: pop eax
ret
pci_pro_select_reg:
push edx
mov eax,0x800000
mov ax,bx
shl eax,8
and di,0xFF
or ax,di
and al,0xFC
mov dx,0x0CF8
out dx,eax
pop edx
ret
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; back to real mode stuff
.rmode
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; PCI Services
; on entry:
; ds = 0x0040
; stack currently has (after we set bp):
; flags cs ip es ds
; [bp+44] [bp+42] [bp+40] [bp+38] [bp+36]
; edi esi ebp esp ebx edx ecx eax
; [bp+04] [bp+08] [bp+12] [bp+16] [bp+20] [bp+24] [bp+28] [bp+32]
; on return
; nothing
; destroys nothing
pcibios_function proc near ; don't put anything here
push bp
mov bp,sp
; sub sp,4
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; first make sure we have a PCI present
mov eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
cmp eax,PCI_FIXED_HOST_BRIDGE
je short @f
cmp eax,PCI_FIXED_HOST_BRIDGE2
je short @f
cmp eax,PCI_FIXED_HOST_BRIDGE3
je short @f
cmp eax,0xFFFFFFFF
jne short @f
mov ah,0xFF
jmp pci_int1A_fail
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; make sure our registers are up to date
@@: mov eax,REG_EAX
mov ecx,REG_ECX
mov edx,REG_EDX
mov esi,REG_ESI
mov edi,REG_EDI
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; installation check
cmp al,0x01
jne short @f
mov word REG_AX,0x0001
mov word REG_BX,0x0210
call pci_real_get_max_bus
mov dword REG_EDX,0x20494350 ; 'PCI '
mov dword REG_EDI,(0xE0000 + pcibios_protected)
jmp pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; find pci device
@@: cmp al,0x02
jne short @f
shl ecx,16
mov cx,dx
xor bx,bx
xor di,di
pci_real_devloop:
call pci_real_select_reg
mov dx,0x0CFC
in eax,dx
cmp eax,ecx
jne short pci_real_nextdev
or si,si
mov REG_BX,bx
je pci_int1A_success
dec si
pci_real_nextdev:
inc bx
cmp bx,0x0200 ;;; bus 2, devfunc 0 ???????????? (what if we have more than 2 buses?)
jne short pci_real_devloop
;mov dx,cx
;shr ecx,16
mov ax,0x8602
jmp pci_int1A_fail
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; find class code
@@: cmp al,0x03
jne short @f
xor bx,bx
mov di,0x08
pci_real_devloop2:
call pci_real_select_reg
mov dx,0x0CFC
in eax,dx
shr eax,8
cmp eax,ecx
jne short pci_real_nextdev2
or si,si
mov REG_BX,bx
je pci_int1A_success
dec si
pci_real_nextdev2:
inc bx
cmp bx,0x0200 ;;; bus 2, devfunc 0 ???????????? (what if we have more than 2 buses?)
jne short pci_real_devloop2
;mov dx,cx
;shr ecx,16
mov ax,0x8603
jmp pci_int1A_fail
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; bus specific operations
@@: cmp al,0x06
jne short @f
mov ax,0x8106
jmp pci_int1A_fail
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read configuration byte
@@: cmp al,0x08
jne short @f
call pci_real_select_reg
mov dx,di
and dx,0x03
add dx,0x0CFC
in al,dx
mov REG_CL,al
jmp pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read configuration word
@@: cmp al,0x09
jne short @f
call pci_real_select_reg
mov dx,di
and dx,0x02
add dx,0x0CFC
in ax,dx
mov REG_CX,ax
jmp pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read configuration dword
@@: cmp al,0x0A
jne short @f
call pci_real_select_reg
mov dx,0x0CFC
in eax,dx
mov REG_ECX,eax
jmp short pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; write configuration byte
@@: cmp al,0x0B
jne short @f
call pci_real_select_reg
mov dx,di
and dx,0x03
add dx,0x0CFC
mov al,cl
out dx,al
jmp short pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; write configuration word
@@: cmp al,0x0C
jne short @f
call pci_real_select_reg
mov dx,di
and dx,0x02
add dx,0x0CFC
mov ax,cx
out dx,ax
jmp short pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; write configuration dword
@@: cmp al,0x0D
jne short @f
call pci_real_select_reg
mov dx,0x0CFC
mov eax,ecx
out dx,eax
jmp short pci_int1A_success
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; get irq routing options
; (this call assumes the Guest sets DS to 0xF000)
@@: cmp al,0x0E
jne short @f
mov ax,(pci_routing_table_structure_end - pci_routing_table_structure_start)
cmp es:[di],ax
jb short pci_real_too_small
stosw ; size of our return data
mov si,offset pci_routing_table_structure_start
les di,es:[di+2]
mov cx,ax
cld
rep
movsb
mov word REG_BX,((1 << 9) | (1 << 11)) ; irq 9 and 11 are used
jmp short pci_int1A_success
pci_real_too_small:
stosw ; size of our return data
mov ah,0x89
jmp short pci_int1A_fail
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; unknown/unsupported function call
@@:
mov bx,$
mov ax,REG_AX
call unsupported
mov ah,0x81
pci_int1A_fail:
mov REG_AX,ax
or word REG_FLAGS,0x0001
mov sp,bp
pop bp
ret
pci_int1A_success:
mov byte REG_AH,0x00 ; success
and word REG_FLAGS,(~0x0001)
mov sp,bp
pop bp
ret
pcibios_function endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; get the last bus number
; on entry:
; nothing
; on return
; cx = last bus number
; destroys none
pci_real_get_max_bus proc near uses eax
mov eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
xor cx,cx
cmp eax,PCI_FIXED_HOST_BRIDGE3
jne short @f
inc cx
@@: ret
pci_real_get_max_bus endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; on entry:
; bx = ??
; di = ??
; on return
; nothing
; destroys eax ??
pci_real_select_reg proc near uses dx
mov eax,0x800000
mov ax,bx
shl eax,8
and di,0xFF
or ax,di
and al,0xFC
mov dx,0x0CF8
out dx,eax
ret
pci_real_select_reg endp
.if (DO_INIT_BIOS32 == 0)
pci_irq_list:
db 11, 10, 9, 5
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; set the bus/dev/func/address
; on entry:
; bx =
; dx =
; on return
; nothing
pcibios_init_sel_reg proc near uses eax
mov eax,0x00800000
mov ax,bx
shl eax,8
and dl,0xFC
or al,dl
mov dx,0x0CF8
out dx,eax
ret
pcibios_init_sel_reg endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the PCI
; on entry:
; nothing
; on return
; nothing
; destroys all general
init_pci_bases proc near uses ds
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
push bp
mov bp,sp ; so we can use the stack for some locals
mov eax,0xC0000000 ; base for memory init
push eax
mov ax,0xC000 ; base for i/o init
push ax
mov ax,0x0010 ; start at BAR 0
push ax
mov bx,0x0008
pci_init_io_loop1:
mov dl,0x00
call pcibios_init_sel_reg
mov dx,0x0CFC
in ax,dx
cmp ax,0xFFFF
jz next_pci_dev
mov dl,0x04 ; disable i/o and memory space access
call pcibios_init_sel_reg
mov dx,0x0CFC
in al,dx
and al,0xFC
out dx,al
pci_init_io_loop2:
mov dl,[bp-8]
call pcibios_init_sel_reg
mov dx,0x0CFC
in eax,dx
test al,0x01
jnz init_io_base
mov ecx,eax
mov eax,0xFFFFFFFF
out dx,eax
in eax,dx
cmp eax,ecx
je short next_pci_base
not eax
mov ecx,eax
mov eax,[bp-4]
out dx,eax
add eax,ecx ; calculate next free mem base
add eax,0x01000000
and eax,0xFF000000
mov [bp-4],eax
jmp short next_pci_base
init_io_base:
mov cx,ax
mov ax,0xFFFF
out dx,ax
in ax,dx
cmp ax,cx
je short next_pci_base
xor ax,0xFFFE
mov cx,ax
mov ax,[bp-6]
out dx,ax
add ax,cx ; calculate next free i/o base
add ax,0x0100
and ax,0xFF00
mov [bp-6],ax
next_pci_base:
mov al,[bp-8]
add al,0x04
cmp al,0x28
je short enable_iomem_space
mov [bp-8],al
jmp short pci_init_io_loop2
enable_iomem_space:
mov dl,0x04 ; enable i/o and memory space access if available
call pcibios_init_sel_reg
mov dx,0x0CFC
in al,dx
or al,0x03
out dx,al
next_pci_dev:
mov byte [bp-8],0x10
inc bx
cmp bx,0x0100
jne pci_init_io_loop1
leave
ret
init_pci_bases endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the (basic) PCI
; on entry:
; nothing
; on return
; nothing
; destroys all general
init_pci_irqs proc near uses ds
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
push bp
mov dx,0x04D0 ; reset ELCR1 + ELCR2
mov al,0x00
out dx,al
inc dx
out dx,al
mov ax,BIOS_BASE2
mov ds,ax
mov si,offset pci_routing_table_structure
mov bh,[si+8]
mov bl,[si+9]
mov dl,0x00
call pcibios_init_sel_reg
mov dx,0x0CFC
in ax,dx
cmp ax,[si+12] ; check irq router
jne pci_init_end
mov dl,[si+34]
call pcibios_init_sel_reg
push bx ; save irq router bus + devfunc
mov dx,0x0CFC
mov ax,0x8080
out dx,ax ; reset PIRQ route control
add dx,2
out dx,ax
mov ax,[si+6]
sub ax,0x20
shr ax,4
mov cx,ax
add si,0x20 ; set pointer to 1st entry
mov bp,sp
push offset pci_irq_list
push 0x0000
pci_init_irq_loop1:
mov bh,[si]
mov bl,[si+1]
pci_init_irq_loop2:
mov dl,0x00
call pcibios_init_sel_reg
mov dx,0x0CFC
in ax,dx
cmp ax,0xFFFF
jnz short pci_test_int_pin
test bl,0x07
jz short next_pir_entry
jmp short next_pci_func
pci_test_int_pin:
mov dl,0x3C
call pcibios_init_sel_reg
mov dx,0x0CFD
in al,dx
and al,0x07
jz short next_pci_func
dec al ; determine pirq reg
mov dl,0x03
mul dl
add al,0x02
xor ah,ah
mov bx,ax
mov al,[si+bx]
mov dl,al
mov bx,[bp]
call pcibios_init_sel_reg
mov dx,0x0CFC
and al,0x03
add dl,al
in al,dx
cmp al,0x80
jb short pirq_found
mov bx,[bp-2] ; pci irq list pointer
mov al,[bx]
out dx,al
inc bx
mov [bp-2],bx
call pcibios_init_set_elcr
pirq_found:
mov bh,[si]
mov bl,[si+1]
add bl,[bp-3] ; pci function number
mov dl,0x3C
call pcibios_init_sel_reg
mov dx,0x0CFC
out dx,al
next_pci_func:
inc byte [bp-3]
inc bl
test bl,0x07
jnz short pci_init_irq_loop2
next_pir_entry:
add si,0x10
mov byte [bp-3],0x00
loop pci_init_irq_loop1
mov sp,bp
pop bx
pci_init_end:
pop bp
ret
init_pci_irqs endp
pcibios_init_set_elcr proc near uses ax cx
mov dx,0x04D0
test al,0x08
jz short is_master_pic
inc dx
and al,0x07
is_master_pic:
mov cl,al
mov bl,0x01
shl bl,cl
in al,dx
or al,bl
out dx,al
ret
pcibios_init_set_elcr endp
.else ; DO_INIT_BIOS32
;PCI_ADDRESS_SPACE_MEM 0x00
PCI_ADDRESS_SPACE_IO equ 0x01
;PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
PCI_ROM_SLOT equ 6
PCI_NUM_REGIONS equ 7
;PCI_DEVICES_MAX 64
PCI_CLASS_STORAGE_IDE equ 0x0101
PCI_CLASS_DISPLAY_VGA equ 0x0300
PCI_CLASS_SYSTEM_PIC equ 0x0800
PCI_VENDOR_ID equ 0x00
PCI_DEVICE_ID equ 0x02
PCI_COMMAND equ 0x04
PCI_COMMAND_IO equ 0x01 ; Enable response in I/O space
PCI_COMMAND_MEMORY equ 0x02 ; Enable response in Memory space
PCI_COMMAND_BUSMASTER equ 0x04 ; Enable response as Bus Master
PCI_CLASS_DEVICE equ 0x0A
PCI_HEADER_TYPE equ 0x0E
PCI_INTERRUPT_LINE equ 0x3C
PCI_INTERRUPT_PIN equ 0x3D
;PCI_MIN_GNT 0x3e /* 8 bits */
;PCI_MAX_LAT 0x3f /* 8 bits */
PCI_BASE_ADDRESS_0 equ 0x10
PCI_ROM_ADDRESS equ 0x30
PCI_ROM_ADDRESS_ENABLE equ 0x01
PCI_VENDOR_ID_INTEL equ 0x8086
PCI_DEVICE_ID_INTEL_82437 equ 0x0122
PCI_DEVICE_ID_INTEL_82441 equ 0x1237
PCI_DEVICE_ID_INTEL_82443 equ 0x7190
PCI_DEVICE_ID_INTEL_82443_1 equ 0x7191
PCI_DEVICE_ID_INTEL_82443_NOAGP equ 0x7192
PCI_DEVICE_ID_INTEL_82371FB_0 equ 0x122E
PCI_DEVICE_ID_INTEL_82371FB_1 equ 0x1230
PCI_DEVICE_ID_INTEL_82371SB_0 equ 0x7000
PCI_DEVICE_ID_INTEL_82371SB_1 equ 0x7010
PCI_DEVICE_ID_INTEL_82371AB_0 equ 0x7110
PCI_DEVICE_ID_INTEL_82371AB equ 0x7111
PCI_DEVICE_ID_INTEL_82371AB_3 equ 0x7113
PCI_VENDOR_ID_IBM equ 0x1014
PCI_VENDOR_ID_APPLE equ 0x106B
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read a byte from the PCI configuration space
; on entry:
; dh = bus
; dl = devfunc
; bx = byte offset
; on return
; al = byte read
; destroys nothing
pci_config_read_byte proc near uses cx dx
; shift count
mov cl,bl
and cl,0x03
shl cl,3
push eax ; save the high word/high byte of eax
xor eax,eax
mov al,dh
shl eax,16
mov ah,dl
mov al,bl
and al,0xFC
or eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
shr eax,cl
mov cl,al
pop eax ; restore the high word/high byte of eax
mov al,cl
ret
pci_config_read_byte endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read a word from the PCI configuration space
; on entry:
; dh = bus
; dl = devfunc
; bx = byte offset (can cross a dword boundary)
; on return
; ax = word read
; destroys nothing
pci_config_read_word proc near uses cx dx
; do we cross a dword boundary?
mov cl,bl
and cl,0x03
cmp cl,0x02
jbe short @f
; we cross a boundary, so read two bytes instead
inc bx
call pci_config_read_byte
mov ah,al
dec bx
call pci_config_read_byte
ret
; we don't cross a boundary, so read the word
@@: shl cl,3 ; shift count
push eax ; save the high word of eax
xor eax,eax
mov al,dh
shl eax,16
mov ah,dl
mov al,bl
and al,0xFC
or eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
shr eax,cl
mov cx,ax
pop eax ; restore the high word of eax
mov ax,cx
ret
pci_config_read_word endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read a dword from the PCI configuration space
; on entry:
; dh = bus
; dl = devfunc
; bx = byte offset (can cross a dword boundary)
; on return
; eax = dword read
; destroys nothing
pci_config_read_dword proc near uses cx edx
; do we cross a dword boundary?
mov cl,bl
and cl,0x03
jz short @f
; we cross a boundary, so read two words instead
add bx,2
call pci_config_read_word
shl eax,16
sub bx,2
call pci_config_read_word
ret
; we don't cross a boundary, so read the word
@@: xor eax,eax
mov al,dh
shl eax,16
mov ah,dl
mov al,bl
;and al,0xFC
or eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
ret
pci_config_read_dword endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; write a byte to the PCI configuration space
; on entry:
; dh = bus
; dl = devfunc
; bx = byte offset
; al = byte to write
; on return
; nothing
; destroys nothing
pci_config_write_byte proc near uses eax bx cx dx
; shift count
mov cl,bl
and cl,0x03
shl cl,3
push ax ; save byte to write
xor eax,eax
mov al,dh
shl eax,16
mov ah,dl
mov al,bl
and al,0xFC
or eax,0x80000000
mov dx,0x0CF8
out dx,eax
mov dx,0x0CFC
in eax,dx
mov ebx,0xFFFFFF00