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