* Sync to trunk HEAD (r53318).
[reactos.git] / boot / freeldr / freeldr / arch / i386 / i386pnp.cmake.S
1 /*
2 * FreeLoader
3 * Copyright (C) 2003 Eric Kohl
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <asm.inc>
21 #include <arch/pc/x86common.h>
22
23 EXTERN i386CallRealMode:PROC
24
25 .code32
26
27 /*
28 * U32 PnpBiosSupported(VOID);
29 *
30 * RETURNS:
31 */
32 PUBLIC _PnpBiosSupported
33 _PnpBiosSupported:
34
35 push edi
36 push esi
37 push ecx
38 push edx
39
40 xor edi, edi
41
42 /* init esi */
43 mov esi, HEX(0F0000)
44
45 pnp_again:
46 mov eax, [esi]
47 cmp eax, HEX(506E5024) /* "$PnP" */
48 je pnp_found
49
50 cmp esi, HEX(0FFFF0)
51 je pnp_not_found
52
53 pnp_add:
54 add esi, 16
55 jmp pnp_again
56
57 pnp_found:
58 /* first calculate the checksum */
59 push esi
60
61 push HEX(21)
62 pop ecx
63 xor edx, edx
64
65 pnp_loop:
66 lodsb
67 add dl, al
68 loop pnp_loop
69
70 test dl, dl
71 pop esi
72 jnz pnp_add
73
74 mov edi, esi
75
76 /* Calculate the bios entry point (far pointer) */
77 xor eax, eax
78 mov ax, [esi + HEX(0F)]
79 shl eax, 16
80 mov ax, [esi + HEX(0D)]
81 mov dword ptr ds:[BSS_PnpBiosEntryPoint], eax
82
83 /* Store bios data segment */
84 mov ax, [esi + HEX(1B)]
85 mov word ptr ds:[BSS_PnpBiosDataSegment], ax
86
87 pnp_not_found:
88 mov eax, edi
89
90 pop edx
91 pop ecx
92 pop esi
93 pop edi
94
95 ret
96
97
98 /*
99 * U32 PnpBiosGetDeviceNodeCount(U32 *NodeSize, U32 *NodeCount);
100 *
101 * RETURNS:
102 */
103 PUBLIC _PnpBiosGetDeviceNodeCount
104 _PnpBiosGetDeviceNodeCount:
105
106 push ebp
107 mov ebp, esp
108
109 pusha
110 push es
111
112 mov bx, FNID_PnpBiosGetDeviceNodeCount
113 call i386CallRealMode
114
115 mov esi, [ebp + 8]
116 mov ax, [BSS_PnpNodeSize]
117 movzx ecx, ax
118 mov [esi], ecx
119
120 mov esi, [ebp + 12]
121 mov ax, [BSS_PnpNodeCount]
122 movzx ecx, ax
123 mov [esi], eax
124
125 pop es
126 popa
127
128 mov esp, ebp
129 pop ebp
130
131 mov eax, dword ptr [BSS_PnpResult]
132
133 ret
134
135
136 /*
137 * U32 PnpBiosGetDeviceNode(U8 *NodeId, U8 *NodeBuffer);
138 *
139 * RETURNS:
140 */
141 PUBLIC _PnpBiosGetDeviceNode
142 _PnpBiosGetDeviceNode:
143 .code32
144
145 push ebp
146 mov ebp, esp
147
148 pusha
149 push es
150
151 /* get current node number */
152 mov esi, [ebp + 8]
153 mov al, [esi]
154 mov byte ptr ds:[BSS_PnpNodeNumber], al
155
156 /* convert pointer to node buffer to segment/offset */
157 mov eax, [ebp + 12]
158 shr eax, 4
159 and eax, HEX(0f000)
160 mov word ptr ds:[BSS_PnpBiosBufferSegment], ax
161 mov eax, [ebp + 12]
162 and eax, HEX(0ffff)
163 mov word ptr ds:[BSS_PnpBiosBufferOffset], ax
164
165 mov bx, FNID_PnpBiosGetDeviceNode
166 call i386CallRealMode
167
168 /* update node number */
169 mov esi, [ebp + 8]
170 mov al, byte ptr ds:[BSS_PnpNodeNumber]
171 mov [esi], al
172
173 pop es
174 popa
175
176 mov esp, ebp
177 pop ebp
178
179 mov eax, [BSS_PnpResult]
180
181 ret
182
183 END
184 /* EOF */