]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/bootstruct.c
18c9ccdd161ce91ab433049342a1fd88ed1ffe7a
[apple/boot.git] / i386 / libsaio / bootstruct.c
1 /*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999-2003 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 2.0 (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 #include "bootstruct.h"
31
32 // CMOS access ports in I/O space.
33 //
34 #define CMOSADDR 0x70
35 #define CMOSDATA 0x71
36 #define HDTYPE 0x12
37
38 /*==========================================================================
39 * Returns the number of active ATA drives since these will increment the
40 * bios device numbers of SCSI drives.
41 */
42 static int countIDEDisks()
43 {
44 int count = 0;
45 unsigned short hdtype;
46
47 #if DEBUG
48 struct driveParameters param;
49
50 printf("Reading drive parameters...\n");
51 readDriveParameters(0x80, &param);
52 printf("%d fixed disk drive(s) installed\n", param.totalDrives);
53 for (count = 0; count < 256; count++)
54 {
55 if (readDriveParameters(count + 0x80, &param))
56 break;
57 else
58 {
59 printf("Drive %d: %d cyls, %d heads, %d sectors\n",
60 count, param.cylinders, param.heads, param.sectors);
61 }
62 }
63 outb(CMOSADDR, 0x11);
64 printf("CMOS addr 0x11 = %x\n",inb(CMOSDATA));
65 outb(CMOSADDR, 0x12);
66 printf("CMOS addr 0x12 = %x\n",inb(CMOSDATA));
67 return count;
68 #endif
69
70 outb( CMOSADDR, HDTYPE );
71 hdtype = (unsigned short) inb( CMOSDATA );
72
73 if (hdtype & 0xF0) count++;
74 if (hdtype & 0x0F) count++;
75 return count;
76 }
77
78 /*==========================================================================
79 * Initialize the 'kernBootStruct'. A structure of parameters passed to
80 * the kernel by the booter.
81 */
82
83 KernelBootArgs_t *bootArgs;
84
85 void initKernBootStruct( int biosdev )
86 {
87 static int init_done = 0;
88
89 bootArgs = (KernelBootArgs_t *)KERNSTRUCT_ADDR;
90
91 if ( !init_done )
92 {
93 bzero(bootArgs, sizeof(KernelBootArgs_t));
94
95 // Get system memory map. Also update the size of the
96 // conventional/extended memory for backwards compatibility.
97
98 bootArgs->memoryMapCount =
99 getMemoryMap( bootArgs->memoryMap, kMemoryMapCountMax,
100 (unsigned long *) &bootArgs->convmem,
101 (unsigned long *) &bootArgs->extmem );
102
103 if ( bootArgs->memoryMapCount == 0 )
104 {
105 // BIOS did not provide a memory map, systems with
106 // discontiguous memory or unusual memory hole locations
107 // may have problems.
108
109 bootArgs->convmem = getConventionalMemorySize();
110 bootArgs->extmem = getExtendedMemorySize();
111 }
112
113 bootArgs->magicCookie = KERNBOOTMAGIC;
114 bootArgs->configEnd = bootArgs->config;
115 bootArgs->graphicsMode = TEXT_MODE;
116
117 /* New style */
118 /* XXX initialize bootArgs here */
119
120 init_done = 1;
121 }
122
123 // Get number of ATA devices.
124
125 bootArgs->numDrives = countIDEDisks();
126
127 // Update kernDev from biosdev.
128
129 bootArgs->kernDev = biosdev;
130 }
131
132
133 /* Copy boot args after kernel and record address. */
134
135 void
136 reserveKernBootStruct(void)
137 {
138 void *oldAddr = bootArgs;
139 bootArgs = (KernelBootArgs_t *)AllocateKernelMemory(sizeof(KERNBOOTSTRUCT));
140 bcopy(oldAddr, bootArgs, sizeof(KernelBootArgs_t));
141 }
142