]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/pci/pcibios1.asm
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / pci / pcibios1.asm
1
2 ; NTS: We use NASM to achieve our goals here because WASM sucks donkey balls
3 ;      Maybe when they bother to implement a proper conditional macro system, I'll consider it...
4
5 global try_pci_bios1_
6 global try_pci_bios2_
7 global _pci_bios_read_dword_16
8 global _pci_bios_write_dword_16
9 extern _pci_bios_protmode_entry_point   ; 32-bit
10 extern _pci_bios_hw_characteristics     ; 8-bit
11 extern _pci_bios_last_bus               ; 16-bit
12 extern _pci_bios_interface_level        ; 16-bit
13
14 section .text
15
16 %if TARGET_MSDOS == 32
17 %define point_s esi
18 %define result eax
19 %define pushan pushad
20 %define popan popad
21 %define pushfn pushfd
22 %define popfn popfd
23 use32
24 %else
25 %define point_s si
26 %define result ax
27 %define pushan pusha
28 %define popan popa
29 %define pushfn pushf
30 %define popfn popf
31 use16
32 %endif
33
34 %if TARGET_MSDOS == 16
35  %ifndef MMODE
36   %error You must specify MMODE variable (memory model) for 16-bit real mode code
37  %endif
38 %endif
39
40 %if TARGET_MSDOS == 16
41  ; large & medium memory models have far pointers for code segments
42  %ifidni MMODE,l
43   %define MMODE_FAR_CALL
44  %endif
45  %ifidni MMODE,m
46   %define MMODE_FAR_CALL
47  %endif
48
49  %ifdef MMODE_FAR_CALL
50   %define retnative retf
51   %define cdecl_param_offset 6  ; RETF addr + PUSH BP
52  %else
53   %define retnative ret
54   %define cdecl_param_offset 4  ; RET addr + PUSH BP
55  %endif
56 %else
57  %define retnative ret
58  %define cdecl_param_offset 8   ; RET addr + PUSH EBP
59 %endif
60
61 ; int try_pci_bios2();
62 try_pci_bios2_:
63                 pushan
64                 mov             ax,0xB101
65                 xor             edi,edi                 ; BUGFIX: Some BIOSes don't set EDI so the "entry point" address we get is whatever Watcom left on the stack.
66                                                         ;         This fix resolves the weird erratic values seen when running under Microsoft Virtual PC 2007.
67                 xor             edx,edx
68                 xor             ebx,ebx
69                 xor             ecx,edx
70                 int             0x1A
71                 jnc             @1                      ; CF=0?
72                 jmp             fail
73 @1:             cmp             ah,0                    ; AH=0?
74                 jz              @2
75                 jmp             fail
76 @2:             cmp             edx,0x20494350          ; EDX = 'PCI '?
77                 jz              @3
78                 jmp             fail
79 @3:             mov             dword [_pci_bios_protmode_entry_point],edi
80                 mov             byte [_pci_bios_hw_characteristics],al
81                 mov             byte [_pci_bios_interface_level],bl
82                 mov             byte [_pci_bios_interface_level+1],bh
83                 xor             ch,ch
84                 mov             word [_pci_bios_last_bus],cx
85
86                 popan
87                 mov             result,1
88                 retnative
89 fail:           popan
90                 xor             result,result
91                 retnative
92
93 ; int try_pci_bios1();
94 try_pci_bios1_:
95                 pushan
96                 mov             ax,0xB001
97                 int             0x1A
98                 jc              fail2                   ; CF=0?
99                 cmp             dx,0x4350               ; DX:CX should spell out 'PCI '
100                 jnz             fail2
101                 cmp             cx,0x2049
102                 jnz             fail2
103                 popan
104                 mov             result,1
105                 retnative
106 fail2:          popan
107                 xor             result,result
108                 retnative
109
110 %if TARGET_MSDOS == 16
111 ; uint32_t __cdecl pci_bios_read_dword_16(uint16_t bx,uint16_t di)
112 _pci_bios_read_dword_16:
113                 push            bp
114                 mov             bp,sp
115
116                 push            cx
117                 push            bx
118                 push            di
119                 mov             bx,[bp+cdecl_param_offset]
120                 mov             di,[bp+cdecl_param_offset+2]
121                 mov             ax,0xB10A
122                 int             0x1A
123                 jc              @2r             ; CF=1 means failure
124                 cmp             ah,0x00
125                 jz              @1r             ; AH!=0 means failure
126 @2r:            xor             ecx,ecx
127                 dec             ecx
128 @1r:            pop             di
129                 pop             bx
130                 mov             ax,cx
131                 shr             ecx,16
132                 mov             dx,cx
133                 pop             cx
134
135                 pop             bp
136                 retnative
137
138 ; void __cdecl pci_bios_write_dword_16(uint16_t bx,uint16_t di,uint32_t data);
139 _pci_bios_write_dword_16:
140                 push            bp
141                 mov             bp,sp
142
143                 push            cx
144                 push            bx
145                 push            di
146                 mov             bx,[bp+cdecl_param_offset]
147                 mov             di,[bp+cdecl_param_offset+2]
148                 mov             ecx,[bp+cdecl_param_offset+4]
149                 mov             ax,0xB10D
150                 int             0x1A
151                 pop             di
152                 pop             bx
153                 pop             cx
154
155                 pop             bp
156                 retnative
157 %endif
158