]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/bootstruct.c
boot-83.2.tar.gz
[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 "io_inline.h"
30 #include "libsaio.h"
31 #include "kernBootStruct.h"
32
33 // CMOS access ports in I/O space.
34 //
35 #define CMOSADDR 0x70
36 #define CMOSDATA 0x71
37 #define HDTYPE 0x12
38
39 /*==========================================================================
40 * Returns the number of active ATA drives since these will increment the
41 * bios device numbers of SCSI drives.
42 */
43 static int
44 countIDEDisks()
45 {
46 int count = 0;
47 unsigned short hdtype;
48
49 #if DEBUG
50 struct driveParameters param;
51
52 printf("Reading drive parameters...\n");
53 readDriveParameters(0x80, &param);
54 printf("%d fixed disk drive(s) installed\n", param.totalDrives);
55 for (count = 0; count < 256; count++)
56 {
57 if (readDriveParameters(count + 0x80, &param))
58 break;
59 else
60 {
61 printf("Drive %d: %d cyls, %d heads, %d sectors\n",
62 count, param.cylinders, param.heads, param.sectors);
63 }
64 }
65 outb(CMOSADDR, 0x11);
66 printf("CMOS addr 0x11 = %x\n",inb(CMOSDATA));
67 outb(CMOSADDR, 0x12);
68 printf("CMOS addr 0x12 = %x\n",inb(CMOSDATA));
69 return count;
70 #endif
71
72 outb( CMOSADDR, HDTYPE );
73 hdtype = (unsigned short) inb( CMOSDATA );
74
75 if (hdtype & 0xF0) count++;
76 if (hdtype & 0x0F) count++;
77 return count;
78 }
79
80 /*==========================================================================
81 * Initialize the 'kernBootStruct'. A structure of parameters passed to
82 * the kernel by the booter.
83 */
84
85 KERNBOOTSTRUCT * kernBootStruct = (KERNBOOTSTRUCT *) KERNSTRUCT_ADDR;
86
87 void
88 initKernBootStruct()
89 {
90 unsigned char i;
91
92 bzero( (char *) kernBootStruct, sizeof(*kernBootStruct) );
93
94 // Get size of conventional memory.
95
96 kernBootStruct->convmem = memsize(0);
97
98 // Get size of extended memory.
99
100 kernBootStruct->extmem = memsize(1);
101
102 // Get number of ATA devices.
103
104 kernBootStruct->numIDEs = countIDEDisks();
105
106 // Get disk info from BIOS.
107
108 for ( i = 0; i < 4; i++ )
109 {
110 kernBootStruct->diskInfo[i] = get_diskinfo(0x80 + i);
111 }
112
113 kernBootStruct->magicCookie = KERNBOOTMAGIC;
114 kernBootStruct->configEnd = kernBootStruct->config;
115 kernBootStruct->graphicsMode = GRAPHICS_MODE;
116 }