a2b49bcbcfcb351787c9d2c59018a6f91d2e508e
[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 /* Call the real mode function */
108 mov bx, FNID_PnpBiosGetDeviceNodeCount
109 call CallRealMode
110
111 xor eax, eax
112 mov ax, [BSS_PnpNodeSize]
113 mov [rcx], eax
114 mov ax, [BSS_PnpNodeCount]
115 mov [rdx], eax
116
117 mov eax, dword ptr [BSS_PnpResult]
118
119 ret
120
121
122
123 /*
124 * U32 PnpBiosGetDeviceNode(U8 *NodeId<rcx>, U8 *NodeBuffer<rdx>);
125 *
126 * RETURNS:
127 */
128 PUBLIC PnpBiosGetDeviceNode
129 PnpBiosGetDeviceNode:
130
131 /* get current node number */
132 mov al, [rcx]
133 mov byte ptr [BSS_PnpNodeNumber], al
134
135 /* convert pointer to node buffer to segment/offset */
136 mov rax, rdx
137 shr eax, 4
138 mov word ptr [BSS_PnpBiosBufferSegment], ax
139 mov rax, rdx
140 and eax, HEX(0f)
141 mov word ptr [BSS_PnpBiosBufferOffset], ax
142
143 /* Call the real mode function */
144 mov bx, FNID_PnpBiosGetDeviceNode
145 call CallRealMode
146
147 /* update node number */
148 mov al, byte ptr [BSS_PnpNodeNumber]
149 mov [rcx], al
150
151 mov eax, [BSS_PnpResult]
152
153 ret
154
155 END
156 /* EOF */