]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/bootstruct.c
dc3bdb4aa75ca690f83947cddfcb8f8f0e35948a
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright 1993 NeXT, Inc.
27 * All rights reserved.
28 */
29
30 #include "libsaio.h"
31 #include "bootstruct.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 countIDEDisks()
44 {
45 int count = 0;
46 unsigned short hdtype;
47
48 #if DEBUG
49 struct driveParameters param;
50
51 printf("Reading drive parameters...\n");
52 readDriveParameters(0x80, &param);
53 printf("%d fixed disk drive(s) installed\n", param.totalDrives);
54 for (count = 0; count < 256; count++)
55 {
56 if (readDriveParameters(count + 0x80, &param))
57 break;
58 else
59 {
60 printf("Drive %d: %d cyls, %d heads, %d sectors\n",
61 count, param.cylinders, param.heads, param.sectors);
62 }
63 }
64 outb(CMOSADDR, 0x11);
65 printf("CMOS addr 0x11 = %x\n",inb(CMOSDATA));
66 outb(CMOSADDR, 0x12);
67 printf("CMOS addr 0x12 = %x\n",inb(CMOSDATA));
68 return count;
69 #endif
70
71 outb( CMOSADDR, HDTYPE );
72 hdtype = (unsigned short) inb( CMOSDATA );
73
74 if (hdtype & 0xF0) count++;
75 if (hdtype & 0x0F) count++;
76 return count;
77 }
78
79 /*==========================================================================
80 * Initialize the 'kernBootStruct'. A structure of parameters passed to
81 * the kernel by the booter.
82 */
83
84 KernelBootArgs_t *bootArgs;
85
86 void initKernBootStruct( int biosdev )
87 {
88 static int init_done = 0;
89
90 bootArgs = (KernelBootArgs_t *)KERNSTRUCT_ADDR;
91
92 if ( !init_done )
93 {
94 bzero(bootArgs, sizeof(KernelBootArgs_t));
95
96 // Get system memory map. Also update the size of the
97 // conventional/extended memory for backwards compatibility.
98
99 bootArgs->memoryMapCount =
100 getMemoryMap( bootArgs->memoryMap, kMemoryMapCountMax,
101 (unsigned long *) &bootArgs->convmem,
102 (unsigned long *) &bootArgs->extmem );
103
104 if ( bootArgs->memoryMapCount == 0 )
105 {
106 // BIOS did not provide a memory map, systems with
107 // discontiguous memory or unusual memory hole locations
108 // may have problems.
109
110 bootArgs->convmem = getConventionalMemorySize();
111 bootArgs->extmem = getExtendedMemorySize();
112 }
113
114 bootArgs->magicCookie = KERNBOOTMAGIC;
115 bootArgs->configEnd = bootArgs->config;
116 bootArgs->graphicsMode = TEXT_MODE;
117
118 /* New style */
119 /* XXX initialize bootArgs here */
120
121 init_done = 1;
122 }
123
124 // Get number of ATA devices.
125
126 bootArgs->numDrives = countIDEDisks();
127
128 // Update kernDev from biosdev.
129
130 bootArgs->kernDev = biosdev;
131 }
132
133
134 /* Copy boot args after kernel and record address. */
135
136 void
137 reserveKernBootStruct(void)
138 {
139 void *oldAddr = bootArgs;
140 bootArgs = (KernelBootArgs_t *)AllocateKernelMemory(sizeof(KERNBOOTSTRUCT));
141 bcopy(oldAddr, bootArgs, sizeof(KernelBootArgs_t));
142 }
143