]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/bootstruct.c
667f7c07f05161d80b00277660053dc260f594bd
[apple/boot.git] / i386 / libsaio / bootstruct.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
27 */
28
29 #include "libsaio.h"
30
31 // CMOS access ports in I/O space.
32 //
33 #define CMOSADDR 0x70
34 #define CMOSDATA 0x71
35 #define HDTYPE 0x12
36
37 /*==========================================================================
38 * Returns the number of active ATA drives since these will increment the
39 * bios device numbers of SCSI drives.
40 */
41 static int countIDEDisks()
42 {
43 int count = 0;
44 unsigned short hdtype;
45
46 #if DEBUG
47 struct driveParameters param;
48
49 printf("Reading drive parameters...\n");
50 readDriveParameters(0x80, &param);
51 printf("%d fixed disk drive(s) installed\n", param.totalDrives);
52 for (count = 0; count < 256; count++)
53 {
54 if (readDriveParameters(count + 0x80, &param))
55 break;
56 else
57 {
58 printf("Drive %d: %d cyls, %d heads, %d sectors\n",
59 count, param.cylinders, param.heads, param.sectors);
60 }
61 }
62 outb(CMOSADDR, 0x11);
63 printf("CMOS addr 0x11 = %x\n",inb(CMOSDATA));
64 outb(CMOSADDR, 0x12);
65 printf("CMOS addr 0x12 = %x\n",inb(CMOSDATA));
66 return count;
67 #endif
68
69 outb( CMOSADDR, HDTYPE );
70 hdtype = (unsigned short) inb( CMOSDATA );
71
72 if (hdtype & 0xF0) count++;
73 if (hdtype & 0x0F) count++;
74 return count;
75 }
76
77 /*==========================================================================
78 * Initialize the 'kernBootStruct'. A structure of parameters passed to
79 * the kernel by the booter.
80 */
81
82 KERNBOOTSTRUCT * kernBootStruct = (KERNBOOTSTRUCT *) KERNSTRUCT_ADDR;
83
84 void initKernBootStruct( int biosdev )
85 {
86 static int init_done = 0;
87 unsigned char i;
88
89 if ( !init_done )
90 {
91 bzero( (char *) kernBootStruct, sizeof(*kernBootStruct) );
92
93 // Get size of conventional memory.
94
95 kernBootStruct->convmem = memsize(0);
96
97 // Get size of extended memory.
98
99 kernBootStruct->extmem = memsize(1);
100
101 kernBootStruct->magicCookie = KERNBOOTMAGIC;
102 kernBootStruct->configEnd = kernBootStruct->config;
103 kernBootStruct->graphicsMode = TEXT_MODE;
104
105 init_done = 1;
106 }
107
108 // Get number of ATA devices.
109
110 kernBootStruct->numIDEs = countIDEDisks();
111
112 // Get disk info from BIOS.
113
114 for ( i = 0; i < 4; i++ )
115 {
116 kernBootStruct->diskInfo[i] = get_diskinfo(0x80 + i);
117 }
118
119 // Update kernDev from biosdev.
120
121 switch ( BIOS_DEV_TYPE( biosdev ) )
122 {
123 case kBIOSDevTypeNetwork:
124 kernBootStruct->kernDev = B_TYPE(DEV_EN); break;
125 case kBIOSDevTypeHardDrive:
126 kernBootStruct->kernDev = B_TYPE(DEV_HD); break;
127 case kBIOSDevTypeFloppy:
128 kernBootStruct->kernDev = B_TYPE(DEV_FD); break;
129 }
130 }