This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / hal / halx86 / bios32.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            ntoskrnl/hal/pci
5  * PURPOSE:         Interfaces to BIOS32 interface
6  * PROGRAMMER:      David Welch (welch@mcmail.com)
7  * UPDATE HISTORY:
8  *               05/06/98: Created
9  */
10
11 /*
12  * NOTES: Sections copied from the Linux pci support
13  */
14
15 /* INCLUDES ***************************************************************/
16
17 #include <ddk/ntddk.h>
18 #include <internal/mm.h>
19 #include <internal/i386/segment.h>
20
21
22 /* TYPES ******************************************************************/
23
24 typedef struct
25 {
26    /*
27     * "_32_" if present
28     */
29    unsigned int signature;
30    
31    /*
32     * Entry point (physical address)
33     */
34    unsigned long int entry;
35    
36    /*
37     * Revision level
38     */
39    unsigned char revision;
40    
41    /*
42     * Length in paragraphs
43     */
44    unsigned char length;
45    
46    /*
47     * Checksum (so all bytes add up to zero)
48     */
49    unsigned char checksum;
50    
51    unsigned char reserved[5];
52 } bios32;
53
54 BOOLEAN bios32_detected = FALSE;
55
56 static struct
57 {
58    unsigned long address;
59    unsigned short segment;
60 } bios32_indirect = {0,KERNEL_CS};
61
62 /* FUNCTIONS **************************************************************/
63
64 #define BIOS32_SIGNATURE (('_' << 0)+('3'<<8)+('2'<<16)+('_'<<24))
65
66 #if 0
67 BOOL static checksum(bios32* service_entry)
68 /*
69  * FUNCTION: Checks the checksum of a bios32 service entry
70  * ARGUMENTS:
71  *         service_entry = Pointer to the service entry
72  * RETURNS: True if the sum of the bytes in the entry was zero
73  *          False otherwise
74  */
75 {
76    unsigned char* p = (unsigned char *)service_entry;
77    int i;
78    unsigned char sum=0;
79    
80    for (i=0; i<(service_entry->length*16); i++)
81      {
82         sum=sum+p[i];
83      }
84 //   DbgPrint("sum = %d\n",sum);
85    if (sum==0)
86      {
87         return(TRUE);
88      }
89    return(FALSE);
90 }
91 #endif
92
93 BOOLEAN Hal_bios32_is_service_present(ULONG service)
94 {
95    unsigned char return_code;
96    unsigned int address;
97    unsigned int length;
98    unsigned int entry;
99    
100    __asm__("lcall *(%%edi)"
101            : "=a" (return_code),
102              "=b" (address),
103              "=c" (length),
104              "=d" (entry)
105            : "0" (service),
106              "1" (0),
107              "D" (&bios32_indirect));
108    if (return_code==0)
109      {
110         return(address+entry);
111      }
112    return(0);
113 }
114
115 VOID Hal_bios32_probe()
116 /*
117  * FUNCTION: Probes for an BIOS32 extension
118  * RETURNS: True if detected
119  */
120 {
121    DbgPrint ("Hal_bios32_probe()\n");
122
123    return;
124 #if 0
125    int i;
126    
127    for (i=0xe0000;i<=0xffff0;i++)
128      {
129         bios32* service_entry = (bios32 *)physical_to_linear(i);
130         if ( service_entry->signature != BIOS32_SIGNATURE )
131           {
132              continue;
133           }
134         DbgPrint("Signature detected at %x\n",i);
135         if (!checksum(service_entry))
136           {
137              continue;
138           }
139         DbgPrint("ReactOS: BIOS32 detected at %x\n",i);
140         bios32_indirect.address = service_entry->entry;
141         bios32_detected=TRUE;
142      }
143 #endif
144 }