Chameleon

Chameleon Commit Details

Date:2010-01-21 07:41:42 (14 years 2 months ago)
Author:Rekursor
Commit:23
Parents: 22
Message:Merged modifications from my branch to trunk as requested by Zef. This includes asere patch with few modifications /bug fixes. Included JrCs coding standard name convention change. See CHANGES file for details.
Changes:
D/trunk/i386/libsaio/memory.c
D/trunk/i386/libsaio/freq_detect.c
D/trunk/i386/libsaio/freq_detect.h
C/branches/rekursor/coding_standards.txt → /trunk/coding_standards.txt
C/branches/rekursor/CHANGES → /trunk/CHANGES
C/branches/rekursor/i386/libsaio/mem.c → /trunk/i386/libsaio/mem.c
C/branches/rekursor/i386/libsaio/mem.h → /trunk/i386/libsaio/mem.h
C/branches/rekursor/i386/libsaio/allocate.c → /trunk/i386/libsaio/allocate.c
C/branches/rekursor/i386/libsaio/pci_root.c → /trunk/i386/libsaio/pci_root.c
C/branches/rekursor/i386/libsaio/pci_root.h → /trunk/i386/libsaio/pci_root.h
C/branches/rekursor/i386/libsaio/cpu.c → /trunk/i386/libsaio/cpu.c
C/branches/rekursor/i386/libsaio/cpu.h → /trunk/i386/libsaio/cpu.h
M/trunk/i386/libsaio/dsdt_patcher.c
M/trunk
M/trunk/i386/boot0/boot0.s
M/trunk/i386/libsa/efi_tables.c
M/trunk/i386/libsa/efi_tables.h
M/trunk/i386/libsaio/ntfs.c
M/trunk/i386/libsaio/ext2fs.c
M/trunk/i386/libsaio/pci.c
M/trunk/i386/libsaio/bootstruct.h
M/trunk/i386/libsaio/stringTable.c
M/trunk/i386/libsaio/load.c
M/trunk/i386/libsaio/ntfs.h
M/trunk/i386/libsaio/ext2fs.h
M/trunk/i386/libsaio/pci.h
M/trunk/i386/libsaio/acpi.h
M/trunk/i386/libsaio/platform.c
M/trunk/i386/boot2/gui.c
M/trunk/i386/libsaio/platform.h
M/trunk/i386/libsaio/disk.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/libsaio/Makefile
M/trunk/i386/boot2/gui.h
M/trunk/i386/boot2/ramdisk.c
M/trunk/i386/libsaio/device_inject.h
M/trunk/i386/libsaio/SMBIOS.h
M/trunk/i386/libsaio/smbios_patcher.c
M/trunk/i386/boot2/picopng.c
M/trunk/i386/boot2/ramdisk.h
M/trunk/i386/libsaio/console.c
M/trunk/i386/boot2/graphics.c
M/trunk/doc/BootHelp.txt
M/trunk/i386/libsaio/smbios_patcher.h
M/trunk/i386/boot2/picopng.h
M/trunk/i386/boot2/graphics.h
M/trunk/i386/util/machOconv.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/hfs.c
M/trunk/i386/libsaio/device_tree.h
M/trunk/i386/libsaio/hfs.h
M/trunk/i386/libsaio/spd.c
M/trunk/i386/libsaio/fake_efi.c
M/trunk/i386/libsaio/spd.h
M/trunk/i386/libsaio/pci_setup.c
M/trunk/i386/libsaio/misc.c
M/trunk/i386/libsa/zalloc.c
M/trunk/i386/boot2/resume.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/boot2/boot.h
M/trunk/i386/libsaio/msdos.c
M/trunk/i386/libsaio/usb.c
M/trunk/i386/libsaio/saio_internal.h
M/trunk/i386/boot2/options.c
M/trunk/i386/libsaio/ati.c
M/trunk/i386/libsaio/sys.c
M/trunk/i386/libsaio/biosfn.c
M/trunk/i386/boot2/drivers.c
M/trunk/i386/libsaio/ati.h
M/trunk/i386/boot2/mboot.c
M/trunk/i386/libsaio/saio_types.h
M/trunk/i386/libsa/strtol.c
M/trunk/i386/boot2/Makefile

File differences

trunk/coding_standards.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Coding Standard rev. 0 (First Draft)
1. Indentation
having seen most indentation styles going from 2 to 8 spaces, I would suggest a indentation of 4 spaces.
2. Comments
I see here two main differents cases:
function description comments and one-line code quite comments
For functions documentation, I suggest to use this syntax
/**
*
*/
Note the use of /** that will make future html auto-documentation easier (i.e: Doxygen at least recognize this marker)
for punctual, short code comment, let's use:
//
3) #define at top of document
4) Global vars right below #include / #define (notation: gLobal)
Note that global vars and static vars should be avoided as much as possible in favor of local variables use, get/set functions (properties).
5) No curly brackets for single lines
6) else
{
....
}
instead of:
else {
....
}
7) if
{
....
}
instead of:
if {
....
}
8) fall through code (using indention) or bail out early (using returns)?
Using early bail out for preconditions early in the function code,
use common sense to avoid as an example more than 4 imbricated if() constructions.
In the later case, consider decomposing your function in more manageable primitives.
9) Spaces/readability i.e. not: if (fd<0)
but: if (fd < 0)
10. types, variables, functions, naming
non const variables should follow the (currently mostly used) CamelCase convention:
int myVariableIsFine;
instead of :
int my_variable_is_ok;
Functions should follow the same conventions except for standard c lib related functions.
Types should share the same convention but start with a Captial letter instead of lower case.
11. Please make sure you extensively initialize variables:
avoid as much as possible:
int myVar
...
myVar = 10;
but use instead:
int myVar = 10;
12. const values:
const int MY_CONST_VARIABLE=42; is also ok for me, depending on the context of use.
or
const int MyConstVariable = 42; (with a Capital first letter)
13. macro definitions should follow this convention:
#define MY_HANDY_MACROS_PSEUDO_FUNC() ...
14. Macros use should be limited to really special cases where they bring real value (like special optimization cases)
Most of the time inlining a function is much better than the use of macros
15. Don't optimize your code blindly, always favor readability when in doubt.
Very often, optimization is not necessary where you think it is, think about the bubble sort algorithm, where people would code it in assembly, where a heap or quick sort algorithm would be much more efficient (n log(n) instead of quadratic complexity), as an example when values count to be sorted get high.
trunk/doc/BootHelp.txt
5151
5252
5353
54
55
56
5457
5558
5659
"Hide Partition" Remove unwanted partition(s) from the boot menu.
=hd(x,y) [hd(m,n)]
"Rename Partition" Rename partition(s) for the boot menu.
=hd(x,y) <alias>[;hd(m,n) <alias2> ...]
GUI=No Disable the GUI (enabled by default).
"Boot Banner"=Yes|No Show boot banner in GUI mode (enabled by default).
"Legacy Logo"=Yes|No Use the legacy grey apple logo (disabled by default).
trunk/CHANGES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- Added JrCs modified convention name change to coding_standards
- Now malloc (ex. MALLOC in Asere patch) is renamed malloc(size) and is an alias
to safe_malloc(size, file, line) with _FILE_ and _LINE_ prerocessor definitions
- Added a new 'Rename Partition Feature', now permitting to rename partition
like 'System reserved' to a more meaningful name
- Added SystemID option permitting to change the System UUID to a fixed value.
- Added the PciRoot autodetection feature imported from pcefi10.5
- Added automatic "system-id" injection from dmi bios, also compatible
with SystemID boot option and former SMUUID from smbios,plist
- Added "system-type' automatic injection (1=Desktop) plus override possibility
with the new system-type option in bootConfig
- Added SMserial and SMproductname new options for smbios.plist
- Merged with asere patch, while keeping my fake_efi.c changes, and adding a new
stringForKey() API, also changed the DT__XXXX() set of functions
to handle const char * values instead of char*.
trunk/i386/libsaio/memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include "sl.h"
#include "saio_internal.h"
#include "bootstruct.h"
#include "device_tree.h"
static long gImageLastKernelAddr;
#define kPageSize 4096
#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1))
long
AllocateMemoryRange(char * rangeName, long start, long length, long type)
{
char *nameBuf;
uint32_t *buffer;
nameBuf = malloc(strlen(rangeName) + 1);
if (nameBuf == 0) return -1;
strcpy(nameBuf, rangeName);
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0) return -1;
buffer[0] = start;
buffer[1] = length;
DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
return 0;
}
#if 0
long
AllocateMemoryRange(char * rangeName, long start, long length, long type)
{
if ( bootArgs->numBootDrivers < NDRIVERS )
{
int num = bootArgs->numBootDrivers;
bootArgs->driverConfig[num].address = start;
bootArgs->driverConfig[num].size = length;
bootArgs->driverConfig[num].type = type;
bootArgs->numBootDrivers++;
}
else
{
stop( "AllocateMemoryRange error" );
}
return 0;
}
#endif
long
AllocateKernelMemory( long inSize )
{
long addr;
if (gImageLastKernelAddr == 0) {
gImageLastKernelAddr = RoundPage( bootArgs->kaddr +
bootArgs->ksize );
}
addr = gImageLastKernelAddr;
gImageLastKernelAddr += RoundPage(inSize);
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) {
stop ("AllocateKernelMemory error");
}
bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;
return addr;
}
trunk/i386/libsaio/freq_detect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* Copyright 2008 Islam Ahmed Zaid. All rights reserved. <azismed@gmail.com>
*/
#include "libsaio.h"
#include "freq_detect.h"
// DFE: enable_PIT2 and disable_PIT2 come from older xnu
/*
* Enable or disable timer 2.
* Port 0x61 controls timer 2:
* bit 0 gates the clock,
* bit 1 gates output to speaker.
*/
inline static void
enable_PIT2(void)
{
/* Enable gate, disable speaker */
__asm__ volatile(
" inb $0x61,%%al \n\t"
" and $0xFC,%%al \n\t" /* & ~0x03 */
" or $1,%%al \n\t"
" outb %%al,$0x61 \n\t"
: : : "%al" );
}
inline static void
disable_PIT2(void)
{
/* Disable gate and output to speaker */
__asm__ volatile(
" inb $0x61,%%al \n\t"
" and $0xFC,%%al \n\t"/* & ~0x03 */
" outb %%al,$0x61 \n\t"
: : : "%al" );
}
// DFE: set_PIT2_mode0, poll_PIT2_gate, and measure_tsc_frequency are
// roughly based on Linux code
/* Set the 8254 channel 2 to mode 0 with the specified value.
In mode 0, the counter will initially set its gate low when the
timer expires. For this to be useful, you ought to set it high
before calling this function. The enable_PIT2 function does this.
*/
static inline void set_PIT2_mode0(uint16_t value)
{
__asm__ volatile(
" movb $0xB0,%%al \n\t"
" outb%%al,$0x43\n\t"
" movb%%dl,%%al\n\t"
" outb%%al,$0x42\n\t"
" movb%%dh,%%al\n\t"
" outb%%al,$0x42"
: : "d"(value) /*: no clobber */ );
}
/* Returns the number of times the loop ran before the PIT2 signaled */
static inline unsigned long poll_PIT2_gate(void)
{
unsigned long count = 0;
unsigned char nmi_sc_val;
do {
++count;
__asm__ volatile(
"inb$0x61,%0"
: "=q"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */);
} while( (nmi_sc_val & 0x20) == 0);
return count;
}
/*
* DFE: Measures the TSC frequency in Hz (64-bit) using the ACPI PM timer
*/
uint64_t measure_tsc_frequency(void)
{
uint64_t tscStart;
uint64_t tscEnd;
uint64_t tscDelta = 0xffffffffffffffffULL;
unsigned long pollCount;
uint64_t retval = 0;
int i;
/* Time how many TSC ticks elapse in 30 msec using the 8254 PIT
* counter 2. We run this loop 3 times to make sure the cache
* is hot and we take the minimum delta from all of the runs.
* That is to say that we're biased towards measuring the minimum
* number of TSC ticks that occur while waiting for the timer to
* expire. That theoretically helps avoid inconsistencies when
* running under a VM if the TSC is not virtualized and the host
* steals time. The TSC is normally virtualized for VMware.
*/
for(i = 0; i < 3; ++i)
{
enable_PIT2();
set_PIT2_mode0(CALIBRATE_LATCH);
tscStart = rdtsc64();
pollCount = poll_PIT2_gate();
tscEnd = rdtsc64();
/* The poll loop must have run at least a few times for accuracy */
if(pollCount <= 1)
continue;
/* The TSC must increment at LEAST once every millisecond. We
* should have waited exactly 30 msec so the TSC delta should
* be >= 30. Anything less and the processor is way too slow.
*/
if((tscEnd - tscStart) <= CALIBRATE_TIME_MSEC)
continue;
// tscDelta = min(tscDelta, (tscEnd - tscStart))
if( (tscEnd - tscStart) < tscDelta )
tscDelta = tscEnd - tscStart;
}
/* tscDelta is now the least number of TSC ticks the processor made in
* a timespan of 0.03 s (e.g. 30 milliseconds)
* Linux thus divides by 30 which gives the answer in kiloHertz because
* 1 / ms = kHz. But we're xnu and most of the rest of the code uses
* Hz so we need to convert our milliseconds to seconds. Since we're
* dividing by the milliseconds, we simply multiply by 1000.
*/
/* Unlike linux, we're not limited to 32-bit, but we do need to take care
* that we're going to multiply by 1000 first so we do need at least some
* arithmetic headroom. For now, 32-bit should be enough.
* Also unlike Linux, our compiler can do 64-bit integer arithmetic.
*/
if(tscDelta > (1ULL<<32))
retval = 0;
else
{
retval = tscDelta * 1000 / 30;
}
disable_PIT2();
return retval;
}
uint64_t tscFrequency = 0;
uint64_t fsbFrequency = 0;
uint64_t cpuFrequency = 0;
/*
* Calculates the FSB and CPU frequencies using specific MSRs for each CPU
* - multi. is read from a specific MSR. In the case of Intel, there is:
* a max multi. (used to calculate the FSB freq.),
* and a current multi. (used to calculate the CPU freq.)
* - fsbFrequency = tscFrequency / multi
* - cpuFrequency = fsbFrequency * multi
*/
void calculate_freq(void)
{
uint32_tcpuid_reg[4], cpu_vendor;
uint8_tcpu_family, cpu_model, cpu_extfamily, cpu_extmodel;
uint64_tmsr, flex_ratio;
uint8_tmaxcoef, maxdiv, currcoef, currdiv;
do_cpuid(0, cpuid_reg);
cpu_vendor = cpuid_reg[1];
do_cpuid(1, cpuid_reg);
cpu_model = bitfield(cpuid_reg[0], 7, 4);
cpu_family = bitfield(cpuid_reg[0], 11, 8);
cpu_extmodel = bitfield(cpuid_reg[0], 19, 16);
cpu_extfamily = bitfield(cpuid_reg[0], 27, 20);
cpu_model += (cpu_extmodel << 4);
DBG("\nCPU Model: %d - CPU Family: %d - CPU Ext. Family: %d\n", cpu_model, cpu_family, cpu_extfamily);
DBG("The booter will now attempt to read the CPU Multiplier (using RDMSR).\n");
DBG("Press any key to continue..\n\n");
#if DEBUG_FREQ
getc();
#endif
tscFrequency = measure_tsc_frequency();
DBG("CPU Multiplier: ");
if((cpu_vendor == 0x756E6547 /* Intel */) && ((cpu_family == 0x06) || (cpu_family == 0x0f)))
{
if ((cpu_family == 0x06 && cpu_model >= 0x0c) ||
(cpu_family == 0x0f && cpu_model >= 0x03))
{
/* Nehalem CPU model */
if (cpu_family == 0x06 && (cpu_model == 0x1a || cpu_model == 0x1e))
{
msr = rdmsr64(MSR_PLATFORM_INFO);
currcoef = (msr >> 8) & 0xff;
msr = rdmsr64(MSR_FLEX_RATIO);
if ((msr >> 16) & 0x01)
{
flex_ratio = (msr >> 8) & 0xff;
if (currcoef > flex_ratio)
currcoef = flex_ratio;
}
if (currcoef)
{
DBG("%d\n", currcoef);
fsbFrequency = (tscFrequency / currcoef);
}
cpuFrequency = tscFrequency;
}
else
{
msr = rdmsr64(IA32_PERF_STATUS);
currcoef = (msr >> 8) & 0x1f;
/* Non-integer bus ratio for the max-multi*/
maxdiv = (msr >> 46) & 0x01;
/* Non-integer bus ratio for the current-multi (undocumented)*/
currdiv = (msr >> 14) & 0x01;
if ((cpu_family == 0x06 && cpu_model >= 0x0e) ||
(cpu_family == 0x0f)) // This will always be model >= 3
{
/* On these models, maxcoef defines TSC freq */
maxcoef = (msr >> 40) & 0x1f;
}
else
{
/* On lower models, currcoef defines TSC freq */
/* XXX */
maxcoef = currcoef;
}
if (maxcoef)
{
if (maxdiv)
fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1));
else
fsbFrequency = (tscFrequency / maxcoef);
if (currdiv)
cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2);
else
cpuFrequency = (fsbFrequency * currcoef);
DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : "");
}
}
}
}
else if((cpu_vendor == 0x68747541 /* AMD */) && (cpu_family == 0x0f))
{
if(cpu_extfamily == 0x00 /* K8 */)
{
msr = rdmsr64(K8_FIDVID_STATUS);
currcoef = (msr & 0x3f) / 2 + 4;
currdiv = (msr & 0x01) * 2;
}
else if(cpu_extfamily >= 0x01 /* K10+ */)
{
msr = rdmsr64(K10_COFVID_STATUS);
if(cpu_extfamily == 0x01 /* K10 */)
currcoef = (msr & 0x3f) + 0x10;
else /* K11+ */
currcoef = (msr & 0x3f) + 0x08;
currdiv = (2 << ((msr >> 6) & 0x07));
}
if (currcoef)
{
if (currdiv)
{
fsbFrequency = ((tscFrequency * currdiv) / currcoef);
DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv);
}
else
{
fsbFrequency = (tscFrequency / currcoef);
DBG("%d\n", currcoef);
}
fsbFrequency = (tscFrequency / currcoef);
cpuFrequency = tscFrequency;
}
}
if (!fsbFrequency)
{
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
}
DBG("TSC Frequency: %dMHz\n", tscFrequency / 1000000);
DBG("CPU Frequency: %dMHz\n", cpuFrequency / 1000000);
DBG("FSB Frequency: %dMHz\n", fsbFrequency / 1000000);
DBG("Press [Enter] to continue..\n");
#if DEBUG_FREQ
while (getc() != 0x0d) ;
#endif
}
trunk/i386/libsaio/freq_detect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright 2008 Islam Ahmed Zaid. All rights reserved. <azismed@gmail.com>
*/
#ifndef __LIBSAIO_FREQ_DETECT_H
#define __LIBSAIO_FREQ_DETECT_H
#include "libsaio.h"
#ifndef DEBUG_FREQ
#define DEBUG_FREQ 0
#endif
#if DEBUG_FREQ
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
/* Decimal powers: */
#define kilo (1000ULL)
#define Mega (kilo * kilo)
#define Giga (kilo * Mega)
#define Tera (kilo * Giga)
#define Peta (kilo * Tera)
#define bit(n)(1ULL << (n))
#define bitmask(h,l)((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
#define bitfield(x,h,l)(((x) & bitmask(h,l)) >> l)
#defineIA32_PERF_STATUS0x198
#define MSR_FLEX_RATIO0x194
#defineMSR_PLATFORM_INFO0xCE
#define K8_FIDVID_STATUS0xC0010042
#define K10_COFVID_STATUS0xC0010071
#define DEFAULT_FSB100000 /* for now, hardcoding 100MHz for old CPUs */
// DFE: This constant comes from older xnu:
#define CLKNUM1193182/* formerly 1193167 */
// DFE: These two constants come from Linux except CLOCK_TICK_RATE replaced with CLKNUM
#define CALIBRATE_TIME_MSEC 30 /* 30 msecs */
#define CALIBRATE_LATCH\
((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000)
extern uint64_t tscFrequency;
extern uint64_t fsbFrequency;
extern uint64_t cpuFrequency;
void calculate_freq(void);
static inline uint64_t rdtsc64(void)
{
uint64_t ret;
__asm__ volatile("rdtsc" : "=A" (ret));
return ret;
}
static inline uint64_t rdmsr64(uint32_t msr)
{
uint64_t ret;
__asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
return ret;
}
static inline void do_cpuid(uint32_t selector, uint32_t *data)
{
asm volatile ("cpuid"
: "=a" (data[0]),
"=b" (data[1]),
"=c" (data[2]),
"=d" (data[3])
: "a" (selector)
);
}
#endif /* !__LIBSAIO_FREQ_DETECT_H */
trunk/i386/libsaio/console.c
4949
5050
5151
52
53
52
53
5454
5555
5656
......
126126
127127
128128
129
129
130130
131131
132132
......
138138
139139
140140
141
142
143
144
145
141
142
143
144
145
146146
147
147
148148
149
149150
150
151
151
152
153
152154
extern intvprf(const char * fmt, va_list ap);
BOOL gVerboseMode;
BOOL gErrors;
bool gVerboseMode;
bool gErrors;
/*
* write one character to console
int error(const char * fmt, ...)
{
va_list ap;
gErrors = YES;
gErrors = true;
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
prf(fmt, ap, putchar, 0);
void stop(const char * fmt, ...)
{
va_list ap;
printf("\n");
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
va_list ap;
printf("\n");
va_start(ap, fmt);
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
prf(fmt, ap, putchar, 0);
else
} else {
vprf(fmt, ap);
}
va_end(ap);
printf("\n");
halt();
printf("\nThis is a non recoverable error! System HALTED!!!");
halt();
while (1);
}
trunk/i386/libsaio/ext2fs.c
1313
1414
1515
16
16
1717
1818
1919
20
2021
2122
2223
......
3839
3940
4041
41
42
#define EX2ProbeSize2048
BOOL EX2Probe (const void *buf)
bool EX2Probe (const void *buf)
{
return (OSReadLittleInt16(buf+0x438,0)==0xEF53);
}
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[strMaxLen]=0;
strncpy (str, buf+0x478, min (strMaxLen, 16));
free (buf);
}
}
trunk/i386/libsaio/bootstruct.h
126126
127127
128128
129
130129
131130
132131
config_file_t bootConfig; // boot.plist
config_file_t overrideConfig; // additional boot.plist which can override bootConfig keys
config_file_t themeDefault; // default theme.plist
config_file_t themeConfig; // theme.plist
config_file_t smbiosConfig; // smbios.plist
config_file_t helperConfig; // boot helper partition's boot.plist
trunk/i386/libsaio/device_tree.c
6262
6363
6464
65
65
6666
6767
6868
......
112112
113113
114114
115
115
116116
117117
118118
......
150150
151151
152152
153
153
154154
155155
156156
......
308308
309309
310310
311
311
312312
313313
314314
static Property *freeProperties, *allocedProperties;
Property *
DT__AddProperty(Node *node, char *name, uint32_t length, void *value)
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
{
Property *prop;
}
Node *
DT__AddChild(Node *parent, char *name)
DT__AddChild(Node *parent, const char *name)
{
Node *node;
parent->children = node;
}
DTInfo.numNodes++;
DT__AddProperty(node, "name", strlen(name) + 1, name);
DT__AddProperty(node, "name", strlen(name) + 1, (void *) name);
return node;
}
}
Node *
DT__FindNode(char *path, bool createIfMissing)
DT__FindNode(const char *path, bool createIfMissing)
{
Node *node, *child;
DTPropertyNameBuf nameBuf;
trunk/i386/libsaio/hfs.c
109109
110110
111111
112
113
112
114113
115114
116115
......
125124
126125
127126
128
129
127
130128
131129
132130
......
134132
135133
136134
137
135
138136
139137
140
141
138
139
142140
143141
144142
u_int16_t *uniStr2, u_int32_t len2);
static void
SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src)
static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src)
{
dst->fdType = SWAP_BE32(src->fdType);
dst->fdCreator = SWAP_BE32(src->fdCreator);
free(ih);
}
BOOL
HFSProbe (const void *buf)
bool HFSProbe (const void *buf)
{
const HFSMasterDirectoryBlock *mdb;
const HFSPlusVolumeHeader *header;
header=(const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);
if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord )
return TRUE;
return true;
if (SWAP_BE16(header->signature) != kHFSPlusSigWord &&
SWAP_BE16(header->signature) != kHFSXSigWord)
return FALSE;
return TRUE;
return false;
return true;
}
long HFSInitPartition(CICell ih)
trunk/i386/libsaio/ext2fs.h
77
88
99
10
10
1111
*
*/
extern BOOL EX2Probe (const void *buf);
extern bool EX2Probe (const void *buf);
extern void EX2GetDescription(CICell ih, char *str, long strMaxLen);
trunk/i386/libsaio/device_tree.h
99
1010
1111
12
12
1313
1414
1515
......
2727
2828
2929
30
30
3131
3232
33
33
3434
3535
36
36
3737
3838
3939
#include <stdint.h>
typedef struct _Property {
char * name;
const char * name;
uint32_t length;
void * value;
extern Property *
DT__AddProperty(Node *node, char *name, uint32_t length, void *value);
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);
extern Node *
DT__AddChild(Node *parent, char *name);
DT__AddChild(Node *parent, const char *name);
Node *
DT__FindNode(char *path, bool createIfMissing);
DT__FindNode(const char *path, bool createIfMissing);
extern void
DT__FreeProperty(Property *prop);
trunk/i386/libsaio/allocate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include "sl.h"
#include "saio_internal.h"
#include "bootstruct.h"
#include "device_tree.h"
static long gImageLastKernelAddr;
#define kPageSize 4096
#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1))
long
AllocateMemoryRange(char * rangeName, long start, long length, long type)
{
char *nameBuf;
uint32_t *buffer;
nameBuf = malloc(strlen(rangeName) + 1);
if (nameBuf == 0) return -1;
strcpy(nameBuf, rangeName);
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0) return -1;
buffer[0] = start;
buffer[1] = length;
DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
return 0;
}
long
AllocateKernelMemory( long inSize )
{
long addr;
if (gImageLastKernelAddr == 0) {
gImageLastKernelAddr = RoundPage( bootArgs->kaddr +
bootArgs->ksize );
}
addr = gImageLastKernelAddr;
gImageLastKernelAddr += RoundPage(inSize);
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) {
stop ("AllocateKernelMemory error");
}
bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;
return addr;
}
trunk/i386/libsaio/hfs.h
3030
3131
3232
33
33
extern long HFSGetFileBlock(CICell ih, char *str, unsigned long long *firstBlock);
extern long HFSGetUUID(CICell ih, char *uuidStr);
extern void HFSFree(CICell ih);
extern BOOL HFSProbe (const void *buf);
extern bool HFSProbe (const void *buf);
trunk/i386/libsaio/spd.c
11
2
23
3
4
45
56
67
......
1819
1920
2021
21
22
2223
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
24
7025
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Copyright 2010 AsereBLN. All rights reserved. <aserebln@googlemail.com>
*
*
* spd.c - obtain serial presene detect memory information
*/
#include "libsaio.h"
#define DBG(x...)
#endif
static const char *spd_memory_types[] =
void scan_spd(PlatformInfo_t *p)
{
"RAM", /* 00h Undefined */
"FPM", /* 01h FPM */
"EDO", /* 02h EDO */
"",/* 03h PIPELINE NIBBLE */
"SDRAM", /* 04h SDRAM */
"",/* 05h MULTIPLEXED ROM */
"DDR SGRAM",/* 06h SGRAM DDR */
"DDR SDRAM",/* 07h SDRAM DDR */
"DDR2 SDRAM", /* 08h SDRAM DDR 2 */
"",/* 09h Undefined */
"",/* 0Ah Undefined */
"DDR3 SDRAM", /* 0Bh SDRAM DDR 3 */
};
#define rdtsc(low,high) \
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
#define SMBHSTSTS 0
#define SMBHSTCNT 2
#define SMBHSTCMD 3
#define SMBHSTADD 4
#define SMBHSTDAT 5
unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd)
{
int l1, h1, l2, h2;
unsigned long long t;
outb(base + SMBHSTSTS, 0x1f);// reset SMBus Controller
outb(base + SMBHSTDAT, 0xff);
while( inb(base + SMBHSTSTS) & 0x01);// wait until ready
outb(base + SMBHSTCMD, cmd);
outb(base + SMBHSTADD, (adr << 1) | 0x01 );
outb(base + SMBHSTCNT, 0x48 );
rdtsc(l1, h1);
while (!( inb(base + SMBHSTSTS) & 0x02))// wait til command finished
{
rdtsc(l2, h2);
t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform.CPU.TSCFrequency / 40);
if (t > 10)
break;// break after 10ms
}
return inb(base + SMBHSTDAT);
/* NYI */
}
static void read_smb_intel(pci_dt_t *smbus_dev)
{
int i, x;
uint8_tspd_size;
uint32_tbase;
RamSlotInfo_t*slot;
base = pci_config_read16(smbus_dev->dev.addr, 0x20) & 0xFFFE;
// Search MAX_RAM_SLOTS slots
for (i = 0; i < 6; i++)
{
slot = &Platform.RAM.DIMM[i];
spd_size = smb_read_byte_intel(base, 0x50 + i, 0);
// Check spd is present
if (spd_size != 0xff)
{
slot->InUse = YES;
slot->spd = malloc(spd_size);
if (slot->spd)
{
bzero(slot->spd, spd_size);
// Copy spd data into buffer
for (x = 0; x < spd_size; x++)
slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x);
switch (slot->spd[SPD_MEMORY_TYPE])
{
case SPD_MEMORY_TYPE_SDRAM_DDR2:
slot->ModuleSize = ((1 << (slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);
break;
case SPD_MEMORY_TYPE_SDRAM_DDR3:
slot->ModuleSize = ((slot->spd[4] & 0x0f) + 28 ) + ((slot->spd[8] & 0x7) + 3 );
slot->ModuleSize -= (slot->spd[7] & 0x7) + 25;
slot->ModuleSize = ((1 << slot->ModuleSize) * (((slot->spd[7] >> 3) & 0x1f) + 1));
break;
}
}
verbose(" slot %d - %dMB %s SPD %d bytes at %x\n", i, slot->ModuleSize,
spd_memory_types[(uint8_t)slot->spd[SPD_MEMORY_TYPE]],
spd_size, slot->spd);
}
}
}
static struct smbus_controllers_t smbus_controllers[] = {
{0x8086, 0x5032, "EP80579", read_smb_intel },
{0x8086, 0x269B, "ESB2", read_smb_intel },
{0x8086, 0x25A4, "6300ESB", read_smb_intel },
{0x8086, 0x24C3, "ICH4", read_smb_intel },
{0x8086, 0x24D3, "ICH5", read_smb_intel },
{0x8086, 0x266A, "ICH6", read_smb_intel },
{0x8086, 0x27DA, "ICH7", read_smb_intel },
{0x8086, 0x283E, "ICH8", read_smb_intel },
{0x8086, 0x2930, "ICH9", read_smb_intel },
{0x8086, 0x3A30, "ICH10R", read_smb_intel },
{0x8086, 0x3A60, "ICH10B", read_smb_intel },
{0x8086, 0x3B30, "P55", read_smb_intel },
};
void scan_smbus_controller(pci_dt_t *smbus_dev)
{
inti;
for( i = 1; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
if (( smbus_controllers[i].vendor == smbus_dev->vendor_id)
&& ( smbus_controllers[i].device == smbus_dev->device_id))
{
verbose("%s%s SMBus Controller [%4x:%4x] at %02x:%02x.%x\n",
(smbus_dev->vendor_id == 0x8086) ? "Intel(R) " : "",
smbus_controllers[i].name,
smbus_dev->vendor_id, smbus_dev->device_id,
smbus_dev->dev.bits.bus, smbus_dev->dev.bits.dev, smbus_dev->dev.bits.func);
smbus_controllers[i].read_smb(smbus_dev);
}
}
trunk/i386/libsaio/spd.h
11
2
23
3
4
45
56
67
78
89
9
10
1011
11
12
1213
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
15614
/*
* Copyright 2010 AsereBLN. All rights reserved. <aserebln@googlemail.com>
*
*
* spd.h
*/
#ifndef __LIBSAIO_SPD_H
#define __LIBSAIO_SPD_H
#include "libsaio.h"
#include "platform.h"
void scan_smbus_controller(pci_dt_t *smbus_dev);
extern void scan_spd(PlatformInfo_t *p);
struct smbus_controllers_t {
uint32_tvendor;
uint32_tdevice;
char*name;
void (*read_smb)(pci_dt_t *smbus_dev);
};
/*
* Serial Presence Detect (SPD) data stored on SDRAM modules.
*
* Datasheet:
* - Name: PC SDRAM Serial Presence Detect (SPD) Specification
* Revision 1.2A, December, 1997
* - PDF: http://www.intel.com/design/chipsets/memory/spdsd12a.pdf
*
* Datasheet (alternative):
* - Name: SERIAL PRESENCE DETECT STANDARD, General Standard
* JEDEC Standard No. 21-C
* - PDF: http://www.jedec.org/download/search/4_01_02_00R9.PDF
*/
/* Byte numbers. */
#define SPD_NUM_MANUFACTURER_BYTES 0 /* Number of bytes used by module manufacturer */
#define SPD_TOTAL_SPD_MEMORY_SIZE 1 /* Total SPD memory size */
#define SPD_MEMORY_TYPE 2 /* (Fundamental) memory type */
#define SPD_NUM_ROWS 3 /* Number of row address bits */
#define SPD_NUM_COLUMNS 4 /* Number of column address bits */
#define SPD_NUM_DIMM_BANKS 5 /* Number of module rows (banks) */
#define SPD_MODULE_DATA_WIDTH_LSB 6 /* Module data width (LSB) */
#define SPD_MODULE_DATA_WIDTH_MSB 7 /* Module data width (MSB) */
#define SPD_MODULE_VOLTAGE 8 /* Module interface signal levels */
#define SPD_MIN_CYCLE_TIME_AT_CAS_MAX 9 /* SDRAM cycle time (highest CAS latency), RAS access time (tRAC) */
#define SPD_ACCESS_TIME_FROM_CLOCK 10 /* SDRAM access time from clock (highest CAS latency), CAS access time (Tac, tCAC) */
#define SPD_DIMM_CONFIG_TYPE 11 /* Module configuration type */
#define SPD_REFRESH 12 /* Refresh rate/type */
#define SPD_PRIMARY_SDRAM_WIDTH 13 /* SDRAM width (primary SDRAM) */
#define SPD_ERROR_CHECKING_SDRAM_WIDTH 14 /* Error checking SDRAM (data) width */
#define SPD_MIN_CLOCK_DELAY_B2B_RAND_COLUMN 15 /* SDRAM device attributes, minimum clock delay for back to back random column */
#define SPD_SUPPORTED_BURST_LENGTHS 16 /* SDRAM device attributes, burst lengths supported */
#define SPD_NUM_BANKS_PER_SDRAM 17 /* SDRAM device attributes, number of banks on SDRAM device */
#define SPD_ACCEPTABLE_CAS_LATENCIES 18 /* SDRAM device attributes, CAS latency */
#define SPD_CS_LATENCY 19 /* SDRAM device attributes, CS latency */
#define SPD_WE_LATENCY 20 /* SDRAM device attributes, WE latency */
#define SPD_MODULE_ATTRIBUTES 21 /* SDRAM module attributes */
#define SPD_DEVICE_ATTRIBUTES_GENERAL 22 /* SDRAM device attributes, general */
#define SPD_SDRAM_CYCLE_TIME_2ND 23 /* SDRAM cycle time (2nd highest CAS latency) */
#define SPD_ACCESS_TIME_FROM_CLOCK_2ND 24 /* SDRAM access from clock (2nd highest CAS latency) */
#define SPD_SDRAM_CYCLE_TIME_3RD 25 /* SDRAM cycle time (3rd highest CAS latency) */
#define SPD_ACCESS_TIME_FROM_CLOCK_3RD 26 /* SDRAM access from clock (3rd highest CAS latency) */
#define SPD_MIN_ROW_PRECHARGE_TIME 27 /* Minimum row precharge time (Trp) */
#define SPD_MIN_ROWACTIVE_TO_ROWACTIVE 28 /* Minimum row active to row active (Trrd) */
#define SPD_MIN_RAS_TO_CAS_DELAY 29 /* Minimum RAS to CAS delay (Trcd) */
#define SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY 30 /* Minimum RAS pulse width (Tras) */
#define SPD_DENSITY_OF_EACH_ROW_ON_MODULE 31 /* Density of each row on module */
#define SPD_CMD_SIGNAL_INPUT_SETUP_TIME 32 /* Command and address signal input setup time */
#define SPD_CMD_SIGNAL_INPUT_HOLD_TIME 33 /* Command and address signal input hold time */
#define SPD_DATA_SIGNAL_INPUT_SETUP_TIME 34 /* Data signal input setup time */
#define SPD_DATA_SIGNAL_INPUT_HOLD_TIME 35 /* Data signal input hold time */
#define SPD_WRITE_RECOVERY_TIME 36 /* Write recovery time (tWR) */
#define SPD_INT_WRITE_TO_READ_DELAY 37 /* Internal write to read command delay (tWTR) */
#define SPD_INT_READ_TO_PRECHARGE_DELAY 38 /* Internal read to precharge command delay (tRTP) */
#define SPD_MEM_ANALYSIS_PROBE_PARAMS 39 /* Memory analysis probe characteristics */
#define SPD_BYTE_41_42_EXTENSION 40 /* Extension of byte 41 (tRC) and byte 42 (tRFC) */
#define SPD_MIN_ACT_TO_ACT_AUTO_REFRESH 41 /* Minimum active to active auto refresh (tRCmin) */
#define SPD_MIN_AUTO_REFRESH_TO_ACT 42 /* Minimum auto refresh to active/auto refresh (tRFC) */
#define SPD_MAX_DEVICE_CYCLE_TIME 43 /* Maximum device cycle time (tCKmax) */
#define SPD_MAX_DQS_DQ_SKEW 44 /* Maximum skew between DQS and DQ (tDQSQ) */
#define SPD_MAX_READ_DATAHOLD_SKEW 45 /* Maximum read data-hold skew factor (tQHS) */
#define SPD_PLL_RELOCK_TIME 46 /* PLL relock time */
#define SPD_SPD_DATA_REVISION_CODE 62 /* SPD data revision code */
#define SPD_CHECKSUM_FOR_BYTES_0_TO_62 63 /* Checksum for bytes 0-62 */
#define SPD_MANUFACTURER_JEDEC_ID_CODE 64 /* Manufacturer's JEDEC ID code, per EIA/JEP106 (bytes 64-71) */
#define SPD_MANUFACTURING_LOCATION 72 /* Manufacturing location */
#define SPD_MANUFACTURER_PART_NUMBER 73 /* Manufacturer's part number, in 6-bit ASCII (bytes 73-90) */
#define SPD_REVISION_CODE 91 /* Revision code (bytes 91-92) */
#define SPD_MANUFACTURING_DATE 93 /* Manufacturing date (byte 93: year, byte 94: week) */
#define SPD_ASSEMBLY_SERIAL_NUMBER 95 /* Assembly serial number (bytes 95-98) */
#define SPD_MANUFACTURER_SPECIFIC_DATA 99 /* Manufacturer specific data (bytes 99-125) */
#define SPD_INTEL_SPEC_FOR_FREQUENCY 126 /* Intel specification for frequency */
#define SPD_INTEL_SPEC_100_MHZ 127 /* Intel specification details for 100MHz support */
/* DRAM specifications use the following naming conventions for SPD locations */
#define SPD_tRP SPD_MIN_ROW_PRECHARGE_TIME
#define SPD_tRRD SPD_MIN_ROWACTIVE_TO_ROWACTIVE
#define SPD_tRCD SPD_MIN_RAS_TO_CAS_DELAY
#define SPD_tRAS SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY
#define SPD_BANK_DENSITY SPD_DENSITY_OF_EACH_ROW_ON_MODULE
#define SPD_ADDRESS_CMD_HOLD SPD_CMD_SIGNAL_INPUT_HOLD_TIME
#define SPD_tRC41/* SDRAM Device Minimum Active to Active/Auto Refresh Time (tRC) */
#define SPD_tRFC42/* SDRAM Device Minimum Auto Refresh to Active/Auto Refresh (tRFC) */
/* SPD_MEMORY_TYPE values. */
#define SPD_MEMORY_TYPE_FPM_DRAM1
#define SPD_MEMORY_TYPE_EDO2
#define SPD_MEMORY_TYPE_PIPELINED_NIBBLE3
#define SPD_MEMORY_TYPE_SDRAM4
#define SPD_MEMORY_TYPE_MULTIPLEXED_ROM5
#define SPD_MEMORY_TYPE_SGRAM_DDR6
#define SPD_MEMORY_TYPE_SDRAM_DDR7
#define SPD_MEMORY_TYPE_SDRAM_DDR28
#define SPD_MEMORY_TYPE_SDRAM_DDR30xb
/* SPD_MODULE_VOLTAGE values. */
#define SPD_VOLTAGE_TTL0 /* 5.0 Volt/TTL */
#define SPD_VOLTAGE_LVTTL1 /* LVTTL */
#define SPD_VOLTAGE_HSTL2 /* HSTL 1.5 */
#define SPD_VOLTAGE_SSTL33 /* SSTL 3.3 */
#define SPD_VOLTAGE_SSTL24 /* SSTL 2.5 */
/* SPD_DIMM_CONFIG_TYPE values. */
#define ERROR_SCHEME_NONE0
#define ERROR_SCHEME_PARITY1
#define ERROR_SCHEME_ECC2
/* SPD_ACCEPTABLE_CAS_LATENCIES values. */
// TODO: Check values.
#define SPD_CAS_LATENCY_1_00x01
#define SPD_CAS_LATENCY_1_50x02
#define SPD_CAS_LATENCY_2_00x04
#define SPD_CAS_LATENCY_2_50x08
#define SPD_CAS_LATENCY_3_00x10
#define SPD_CAS_LATENCY_3_50x20
#define SPD_CAS_LATENCY_4_00x40
#define SPD_CAS_LATENCY_DDR2_3(1 << 3)
#define SPD_CAS_LATENCY_DDR2_4(1 << 4)
#define SPD_CAS_LATENCY_DDR2_5(1 << 5)
#define SPD_CAS_LATENCY_DDR2_6(1 << 6)
/* SPD_SUPPORTED_BURST_LENGTHS values. */
#define SPD_BURST_LENGTH_11
#define SPD_BURST_LENGTH_22
#define SPD_BURST_LENGTH_44
#define SPD_BURST_LENGTH_88
#define SPD_BURST_LENGTH_PAGE(1 << 7)
/* SPD_MODULE_ATTRIBUTES values. */
#define MODULE_BUFFERED1
#define MODULE_REGISTERED2
#endif /* !__LIBSAIO_SPD_H */
trunk/i386/libsaio/Makefile
44
55
66
7
78
89
910
1011
11
12
13
1214
1315
14
16
1517
1618
1719
1820
1921
2022
21
23
2224
2325
2426
......
3335
3436
3537
36
38
3739
3840
3941
40
42
4143
4244
43
45
4446
4547
4648
UTILDIR = ../util
LIBSADIR = ../libsa
BOOT2DIR = ../boot2
INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone
#SYMROOT=
OPTIM = -Os -Oz
DEBUG = NOTHING
DEBUG = -DNOTHING
#DEBUG = -DDEBUG_CPU=1 -DDEBUG_MEM=1 -DDEBUG_SPD=1 -DDEBUG_PCI=1 -DDEBUG_SMBIOS=1
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost \
-D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \
-DRCZ_COMPRESSED_FILE_SUPPORT -D$(DEBUG) \
-DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \
-mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float
DEFINES=
CONFIG = hd
INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR)
INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(BOOT2DIR)
ifneq "" "$(wildcard /bin/mkdirs)"
MKDIRS = /bin/mkdirs
else
SAIO_OBJS = table.o asm.o bios.o biosfn.o \
disk.o sys.o cache.o bootstruct.o \
stringTable.o load.o pci.o memory.o misc.o \
stringTable.o load.o pci.o allocate.o misc.o \
ufs.o ufs_byteorder.o \
vbe.o nbp.o hfs.o hfs_compare.o \
xml.o ntfs.o msdos.o md5c.o device_tree.o \
freq_detect.o platform.o dsdt_patcher.o \
cpu.o platform.o dsdt_patcher.o \
smbios_patcher.o fake_efi.o ext2fs.o \
hpet.o spd.o usb.o pci_setup.o \
device_inject.o nvidia.o ati.o
device_inject.o nvidia.o ati.o pci_root.o mem.o
SAIO_EXTERN_OBJS = console.o
trunk/i386/libsaio/SMBIOS.h
3939
4040
4141
42
43
44
45
46
47
4248
4349
4450
typedef UInt32 SMBDWord;
typedef UInt64 SMBQWord;
struct DMIHeader{
SMBByte type;
SMBByte length;
SMBWord handle;
} __attribute__((packed));
struct DMIEntryPoint {
SMBByte anchor[5];
SMBByte checksum;
trunk/i386/libsaio/smbios_patcher.c
33
44
55
6
6
77
8
89
910
1011
......
2425
2526
2627
27
28
2829
29
30
31
32
33
34
35
36
30
31
32
33
34
35
36
37
3738
3839
3940
4041
4142
42
43
4344
44
45
46
47
48
49
50
51
45
46
47
48
49
50
51
52
5253
5354
5455
5556
5657
57
58
5859
59
60
61
62
63
64
65
66
60
61
62
63
64
65
66
67
6768
6869
6970
7071
7172
72
73
7374
74
75
76
77
78
79
80
81
75
76
77
78
79
80
81
82
8283
8384
8485
8586
8687
87
88
8889
89
90
91
92
93
94
95
96
90
91
92
93
94
95
96
97
9798
9899
99100
100101
101102
102
103
103
104
104105
105
106
107
106
107
108108
109109
110110
111111
112
113
114
115
116
117
112
113
114
115
116
118117
118
119119
120
121
120
121
122122
123
124
123125
124126
125127
......
127129
128130
129131
130
132
131133
132134
133135
134136
135137
136138
137
138
139
140139
141140
142141
143142
144143
145
146
147
144
148145
149
146
150147
151
148
152149
153
150
154151
152
155153
156154
157155
158156
159
160
161
162
157
158
159
160
161
162
163
163164
164165
165166
166167
167
168
169
170
168
169
170
171
171172
172173
173174
174
175
176
177
178
179
180
181
182
175183
176184
177185
178186
179187
188
189
190
191
192
193
194
180195
181196
182197
183198
184199
200
201
202
203
204
205
206
185207
186208
187209
......
198220
199221
200222
201
202
203
223
224
225
204226
205227
206
207
208
209
210
211
228
229
230
231
232
233
212234
213235
214
215
216
236
237
238
217239
218240
219241
......
227249
228250
229251
230
252
231253
232254
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
263282
264283
265284
266
267
285
268286
269
270
271
272
273
274
275
287
288
289
290
291
292
293
276294
277
295
278296
279
280
281
282
283
284
285
286
297
298
299
300
301
302
303
304
305
306
307
287308
288
289
290
291
292
293
294
295
296
297
298
309
310
311
312
313
314
315
316
317
318
319
320
299321
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
341345
342
343
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
344368
345
369
346370
347
371
372
348373
349374
350375
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
386408
387
388
409
410
411
389412
390
391
392
413
414
415
416
393417
394418
395419
......
397421
398422
399423
400
401
402
424
403425
404
426
405427
406
428
407429
408430
409431
410432
411433
412
434
413435
414
436
437
438
439
415440
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
446466
447
467
468
469
448470
449
450
471
472
473
451474
452
453
475
476
454477
455
456
457
458
459
460
461
462
463
464
465
466
467
478
479
480
481
482
483
484
485
486
487
468488
469
470
489
490
471491
472
473
474
475
492
493
494
495
496
497
498
499
500
501
502
476503
477
478
479
480
481
482
483
484
485
486
487504
488
505
489506
490
491
507
508
492509
493
494
495
496
510
511
512
513
497514
498
499
500
501
502
515
516
517
518
519
520
503521
504
522
523
505524
506
525
526
507527
508
509
510
528
529
530
511531
512
513
532
533
514534
515535
516536
517537
518
538
519539
520
521
522
523
524
525
540
541
542
543
544
545
546
526547
527
548
528549
529
530
531
532
533
534
550
551
552
553
554
555
556
535557
558
536559
537560
538
539
540
561
562
541563
542564
543
565
544566
545567
546568
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
565587
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
584603
585
586
604
605
587606
588
589
590
591
607
608
609
610
611
612
613
614
615
616
617
592618
593
594
595
596
597
598
599
600
601
602619
603
620
604621
605
606
622
623
607624
608
609
610
611
625
626
627
628
629
612630
613
614
615
616
617
631
632
633
634
635
636
618637
619
638
639
620640
621
641
642
622643
623
624
625
644
645
646
626647
627
628
648
649
629650
630651
631652
632653
633654
634655
635
636
637
638
639
640
656
657
658
659
660
661
662
641663
642664
643665
644
645
646
647
648
649
666
667
668
669
670
671
672
650673
674
651675
652676
653
654
655
677
678
656679
657680
658
681
659682
660683
661684
662685
663
664
665
666
667
686
687
688
689
690
668691
669692
670
671
693
672694
673
674
675
676695
677696
678
679697
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
698
700699
701700
702701
*/
#include "libsaio.h"
#include "acpi.h"
#include "boot.h"
#include "bootstruct.h"
#include "acpi.h"
#include "efi_tables.h"
#include "fake_efi.h"
#include "platform.h"
// defaults for a MacBook
static char sm_macbook_defaults[][2][40]={
{"SMbiosvendor","Apple Inc."},
{"SMbiosvendor","Apple Inc."},
{"SMbiosversion","MB41.88Z.0073.B00.0809221748"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","MacBook4,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacBook"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F42D89C8"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","MacBook4,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacBook"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F42D89C8"},
{ "",""}
};
// defaults for a MacBook Pro
static char sm_macbookpro_defaults[][2][40]={
{"SMbiosvendor","Apple Inc."},
{"SMbiosvendor","Apple Inc."},
{"SMbiosversion","MBP41.88Z.0073.B00.0809221748"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","MacBookPro4,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacBookPro"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F42D89C8"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","MacBookPro4,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacBookPro"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F42D89C8"},
{ "",""}
};
// defaults for a Mac mini
static char sm_macmini_defaults[][2][40]={
{"SMbiosvendor","Apple Inc."},
{"SMbiosvendor","Apple Inc."},
{"SMbiosversion","MM21.88Z.009A.B00.0706281359"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","Macmini2,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","Napa Mac"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F4208EAA"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","Macmini2,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","Napa Mac"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F4208EAA"},
{ "",""}
};
// defaults for an iMac
static char sm_imac_defaults[][2][40]={
{"SMbiosvendor","Apple Inc."},
{"SMbiosvendor","Apple Inc."},
{"SMbiosversion","IM81.88Z.00C1.B00.0802091538"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","iMac8,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","Mac"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F227BEC8"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Inc."},
{"SMproductname","iMac8,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","Mac"},
{"SMboardmanufacter","Apple Inc."},
{"SMboardproduct","Mac-F227BEC8"},
{ "",""}
};
// defaults for a Mac Pro
static char sm_macpro_defaults[][2][40]={
{"SMbiosvendor","Apple Computer, Inc."},
{"SMbiosvendor","Apple Computer, Inc."},
{"SMbiosversion","MP31.88Z.006C.B05.0802291410"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Computer, Inc."},
{"SMproductname","MacPro3,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacPro"},
{"SMboardmanufacter","Apple Computer, Inc."},
{"SMboardproduct","Mac-F4208DC8"},
{"SMbiosdate","04/01/2008"},
{"SMmanufacter","Apple Computer, Inc."},
{"SMproductname","MacPro3,1"},
{"SMsystemversion","1.0"},
{"SMserial","SOMESRLNMBR"},
{"SMfamily","MacPro"},
{"SMboardmanufacter","Apple Computer, Inc."},
{"SMboardproduct","Mac-F4208DC8"},
{ "",""}
};
static char *sm_get_defstr(char *name, int table_num)
{
int i;
char (*sm_defaults)[2][40];
inti;
char(*sm_defaults)[2][40];
if (Platform.CPU.Mobile)
if (Platform.CPU.NoCores > 1)
{
if (platformCPUFeature(CPU_FEATURE_MOBILE)) {
if (Platform.CPU.NoCores > 1) {
sm_defaults=sm_macbookpro_defaults;
} else {
sm_defaults=sm_macbook_defaults;
}
else
switch (Platform.CPU.NoCores)
{
case 1: sm_defaults=sm_macmini_defaults; break;
case 2: sm_defaults=sm_imac_defaults; break;
default: sm_defaults=sm_macpro_defaults; break;
} else {
switch (Platform.CPU.NoCores) {
case 1: sm_defaults=sm_macmini_defaults; break;
case 2: sm_defaults=sm_imac_defaults; break;
default: sm_defaults=sm_macpro_defaults; break;
}
}
for (i=0;sm_defaults[i][0][0];i++)
if (!strcmp (sm_defaults[i][0],name))
for (i=0;sm_defaults[i][0][0];i++) {
if (!strcmp (sm_defaults[i][0],name)) {
return sm_defaults[i][1];
}
}
// Shouldn't happen
printf ("Error: no default for '%s' known\n", name);
return "";
}
static int sm_get_fsb (char *name, int table_num)
static int sm_get_fsb(char *name, int table_num)
{
return Platform.CPU.FSBFrequency/1000000;
}
static int sm_get_cpu (char *name, int table_num)
{
/* round CPU frequency */
//return round2(Platform.CPU.CPUFrequency/1000000, 10);
//return roundup2(Platform.CPU.CPUFrequency/1000000, 100);
return Platform.CPU.CPUFrequency/1000000;
}
static int sm_get_cputype (char *name, int table_num)
{
int cores = Platform.CPU.NoCores;
if (cores == 1)
if (Platform.CPU.NoCores == 1) {
return 0x0101; // <01 01> Intel Core Solo?
else if (cores == 2)
} else if (Platform.CPU.NoCores == 2) {
return 0x0301; // <01 03> Intel Core 2 Duo
else if (cores >= 4)
} else if (Platform.CPU.NoCores >= 4) {
return 0x0501; // <01 05> Quad-Core Intel Xeon
else
} else {
return 0x0301; // Default to Core 2 Duo
}
}
static int sm_get_memtype (char *name, int table_num)
{
if(Platform.RAM.Type)
return Platform.RAM.Type;
else
return SMB_MEM_TYPE_DDR2;
if (table_num < MAX_RAM_SLOTS &&
Platform.RAM.DIMM[table_num].InUse &&
Platform.RAM.DIMM[table_num].Type != 0)
{
return Platform.RAM.DIMM[table_num].Type;
}
return SMB_MEM_TYPE_DDR2;
}
static int sm_get_memspeed (char *name, int table_num)
{
if(Platform.RAM.Type)
return round2( Platform.RAM.Frequency / 500000, 2);
else
return 667;
if (Platform.RAM.Frequency != 0) {
return Platform.RAM.Frequency/1000000;
}
return 667;
}
static char *sm_get_memvendor (char *name, int table_num)
{
{
if (table_num < MAX_RAM_SLOTS &&
Platform.RAM.DIMM[table_num].InUse &&
strlen(Platform.RAM.DIMM[table_num].Vendor) > 0)
{
DBG("Vendor[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].Vendor);
return Platform.RAM.DIMM[table_num].Vendor;
}
return "N/A";
}
static char *sm_get_memserial (char *name, int table_num)
{
if (table_num < MAX_RAM_SLOTS &&
Platform.RAM.DIMM[table_num].InUse &&
strlen(Platform.RAM.DIMM[table_num].SerialNo) > 0)
{
DBG("SerialNo[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].SerialNo);
return Platform.RAM.DIMM[table_num].SerialNo;
}
return "N/A";
}
static char *sm_get_mempartno (char *name, int table_num)
{
if (table_num < MAX_RAM_SLOTS &&
Platform.RAM.DIMM[table_num].InUse &&
strlen(Platform.RAM.DIMM[table_num].PartNo) > 0)
{
DBG("PartNo[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].PartNo);
return Platform.RAM.DIMM[table_num].PartNo;
}
return "N/A";
}
{.name="SMmanufacter",.table_type= 1,.value_type=SMSTRING,.offset=0x04,.auto_str=sm_get_defstr},
{.name="SMproductname",.table_type= 1,.value_type=SMSTRING,.offset=0x05,.auto_str=sm_get_defstr},
{.name="SMsystemversion",.table_type= 1,.value_type=SMSTRING,.offset=0x06,.auto_str=sm_get_defstr},
{.name="SMserial",.table_type= 1,.value_type=SMSTRING,.offset=0x07,.auto_str=sm_get_defstr},
{.name="SMUUID",.table_type= 1, .value_type=SMOWORD,.offset=0x08,.auto_oword=0},
{.name="SMfamily",.table_type= 1,.value_type=SMSTRING,.offset=0x1a,.auto_str=sm_get_defstr},
{.name="SMserial",.table_type= 1,.value_type=SMSTRING,.offset=0x07,.auto_str=sm_get_defstr},
{.name="SMUUID",.table_type= 1, .value_type=SMOWORD,.offset=0x08,.auto_oword=0},
{.name="SMfamily",.table_type= 1,.value_type=SMSTRING,.offset=0x1a,.auto_str=sm_get_defstr},
{.name="SMboardmanufacter",.table_type= 2, .value_type=SMSTRING,.offset=0x04,.auto_str=sm_get_defstr},
{.name="SMboardproduct",.table_type= 2, .value_type=SMSTRING,.offset=0x05,.auto_str=sm_get_defstr},
{.name="SMexternalclock",.table_type= 4,.value_type=SMWORD,.offset=0x12,.auto_int=sm_get_fsb},
{.name="SMmaximalclock",.table_type= 4,.value_type=SMWORD,.offset=0x14,.auto_int=sm_get_cpu},
{.name="SMmemdevloc",.table_type=17,.value_type=SMSTRING,.offset=0x10,.auto_str=0},
{.name="SMmembankloc",.table_type=17,.value_type=SMSTRING,.offset=0x11,.auto_str=0},
{.name="SMmemtype",.table_type=17,.value_type=SMBYTE,.offset=0x12,.auto_int=sm_get_memtype},
{.name="SMmemspeed",.table_type=17,.value_type=SMWORD,.offset=0x15,.auto_int=sm_get_memspeed},
{.name="SMexternalclock",.table_type= 4,.value_type=SMWORD,.offset=0x12,.auto_int=sm_get_fsb},
{.name="SMmaximalclock",.table_type= 4,.value_type=SMWORD,.offset=0x14,.auto_int=sm_get_cpu},
{.name="SMmemdevloc",.table_type=17,.value_type=SMSTRING,.offset=0x10,.auto_str=0},
{.name="SMmembankloc",.table_type=17,.value_type=SMSTRING,.offset=0x11,.auto_str=0},
{.name="SMmemtype",.table_type=17,.value_type=SMBYTE,.offset=0x12,.auto_int=sm_get_memtype},
{.name="SMmemspeed",.table_type=17,.value_type=SMWORD,.offset=0x15,.auto_int=sm_get_memspeed},
{.name="SMmemmanufacter",.table_type=17,.value_type=SMSTRING,.offset=0x17,.auto_str=sm_get_memvendor},
{.name="SMmemserial",.table_type=17,.value_type=SMSTRING,.offset=0x18,.auto_str=sm_get_memserial},
{.name="SMmempart",.table_type=17,.value_type=SMSTRING,.offset=0x1A,.auto_str=sm_get_mempartno},
{.name="SMcputype",.table_type=131,.value_type=SMWORD,.offset=0x04,.auto_int=sm_get_cputype},
{.name="SMbusspeed",.table_type=132,.value_type=SMWORD,.offset=0x04,.auto_str=0}
{.name="SMmempart",.table_type=17,.value_type=SMSTRING,.offset=0x1A,.auto_str=sm_get_mempartno},
{.name="SMcputype",.table_type=131,.value_type=SMWORD,.offset=0x04,.auto_int=sm_get_cputype},
{.name="SMbusspeed",.table_type=132,.value_type=SMWORD,.offset=0x04,.auto_str=0}
};
struct smbios_table_description smbios_table_descriptions[]=
{.type=132,.len=0x06,.numfunc=sm_one}
};
static inline struct SMBEntryPoint * getAddressOfSmbiosTable()
struct SMBEntryPoint *getAddressOfSmbiosTable(void)
{
/* First see if we can even find the damn SMBIOS table
* The logic here is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
* for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
*/
void *smbios_addr = (void*)SMBIOS_RANGE_START;
for(; (smbios_addr <= (void*)SMBIOS_RANGE_END) && (*(uint32_t*)smbios_addr != SMBIOS_ANCHOR_UINT32_LE); smbios_addr += 16)
;
if(smbios_addr <= (void*)SMBIOS_RANGE_END)
{
/* NOTE: The specification does not specifically state what to do in the event of finding an
* SMBIOS anchor on an invalid table. It might be better to move this code into the for loop
* so that searching can continue.
*/
uint8_t csum = checksum8(smbios_addr, sizeof(struct SMBEntryPoint));
/* The table already contains the checksum so we merely need to see if its checksum is now zero. */
if(csum != 0)
{
printf("Found SMBIOS anchor but bad table checksum. Assuming no SMBIOS.\n");
sleep(5);
smbios_addr = 0;
}
}
else
{
/* If this happens, it's possible that a PnP BIOS call can be done to retrieve the address of the table.
* The latest versions of the spec state that modern programs should not even attempt to do this. */
printf("Unable to find SMBIOS table.\n");
sleep(5);
smbios_addr = 0;
}
return smbios_addr;
* The logic here is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
* for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
*/
void *smbios_addr = (void*)SMBIOS_RANGE_START;
for (; (smbios_addr<=(void*)SMBIOS_RANGE_END) && (*(uint32_t*)smbios_addr!=SMBIOS_ANCHOR_UINT32_LE); smbios_addr+=16) ;
if (smbios_addr <= (void*)SMBIOS_RANGE_END) {
/* NOTE: The specification does not specifically state what to do in the event of finding an
* SMBIOS anchor on an invalid table. It might be better to move this code into the for loop
* so that searching can continue.
*/
uint8_t csum = checksum8(smbios_addr, sizeof(struct SMBEntryPoint));
/* The table already contains the checksum so we merely need to see if its checksum is now zero. */
if (csum != 0) {
printf("Found SMBIOS anchor but bad table checksum. Assuming no SMBIOS.\n");
sleep(5);
smbios_addr = 0;
}
} else {
/* If this happens, it's possible that a PnP BIOS call can be done to retrieve the address of the table.
* The latest versions of the spec state that modern programs should not even attempt to do this.
*/
printf("Unable to find SMBIOS table.\n");
sleep(5);
smbios_addr = 0;
}
return smbios_addr;
}
/* Compute necessary space requirements for new smbios */
struct SMBEntryPoint *
smbios_dry_run (struct SMBEntryPoint * origsmbios)
struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios)
{
struct SMBEntryPoint *ret;
char *smbiostables=0;
char *tablesptr;
int origsmbiosnum=0;
int i, j;
int tablespresent[256];
BOOL do_auto=1;
struct SMBEntryPoint*ret;
char*smbiostables;
char*tablesptr;
intorigsmbiosnum;
inti, j;
inttablespresent[256];
booldo_auto=true;
getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig);
bzero(tablespresent, sizeof(tablespresent));
for (i=0;i<256;i++)
tablespresent[i]=0;
ret=(struct SMBEntryPoint *)AllocateKernelMemory(sizeof (struct SMBEntryPoint));
if (origsmbios)
{
smbiostables=(char *)origsmbios->dmi.tableAddress;
origsmbiosnum=origsmbios->dmi.structureCount;
}
getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig);
ret = (struct SMBEntryPoint *)AllocateKernelMemory(sizeof(struct SMBEntryPoint));
if (origsmbios) {
smbiostables = (char *)origsmbios->dmi.tableAddress;
origsmbiosnum = origsmbios->dmi.structureCount;
} else {
smbiostables = NULL;
origsmbiosnum = 0;
}
// _SM_
ret->anchor[0]=0x5f;
ret->anchor[1]=0x53;
ret->anchor[2]=0x4d;
ret->anchor[3]=0x5f;
ret->entryPointLength=sizeof (*ret);
ret->majorVersion=2;
ret->minorVersion=1;
ret->maxStructureSize=0;
ret->entryPointRevision=0;
for (i=0;i<5;i++)
ret->formattedArea[i]=0;
ret->anchor[0] = 0x5f;
ret->anchor[1] = 0x53;
ret->anchor[2] = 0x4d;
ret->anchor[3] = 0x5f;
ret->entryPointLength = sizeof(*ret);
ret->majorVersion = 2;
ret->minorVersion = 1;
ret->maxStructureSize = 0;
ret->entryPointRevision = 0;
for (i=0;i<5;i++) {
ret->formattedArea[i] = 0;
}
//_DMI_
ret->dmi.anchor[0]=0x5f;
ret->dmi.anchor[1]=0x44;
ret->dmi.anchor[2]=0x4d;
ret->dmi.anchor[3]=0x49;
ret->dmi.anchor[4]=0x5f;
ret->dmi.tableLength=0;
ret->dmi.tableAddress=0;
ret->dmi.structureCount=0;
ret->dmi.bcdRevision=0x21;
tablesptr=smbiostables;
if (smbiostables)
for (i=0;i<origsmbiosnum;i++)
{
struct smbios_table_header *cur
=(struct smbios_table_header *) tablesptr;
char *stringsptr;
int stringlen;
tablesptr+=cur->length;
stringsptr=tablesptr;
for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++);
tablesptr+=2;
stringlen=tablesptr-stringsptr-1;
if (stringlen==1)
stringlen=0;
for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]);
j++)
{
const char *str;
int size;
char altname[40];
sprintf (altname, "%s_%d",smbios_properties[j].name,
tablespresent[cur->type]+1);
if (smbios_properties[j].table_type==cur->type
&& smbios_properties[j].value_type==SMSTRING
&& (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)
|| getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)))
stringlen+=size+1;
else if (smbios_properties[j].table_type==cur->type
&& smbios_properties[j].value_type==SMSTRING
&& do_auto && smbios_properties[j].auto_str)
stringlen+=strlen(smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[cur->type]))+1;
ret->dmi.anchor[0] = 0x5f;
ret->dmi.anchor[1] = 0x44;
ret->dmi.anchor[2] = 0x4d;
ret->dmi.anchor[3] = 0x49;
ret->dmi.anchor[4] = 0x5f;
ret->dmi.tableLength = 0;
ret->dmi.tableAddress = 0;
ret->dmi.structureCount = 0;
ret->dmi.bcdRevision = 0x21;
tablesptr = smbiostables;
if (smbiostables) {
for (i=0; i<origsmbiosnum; i++) {
struct smbios_table_header*cur = (struct smbios_table_header *)tablesptr;
char*stringsptr;
intstringlen;
tablesptr += cur->length;
stringsptr = tablesptr;
for (; tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++);
tablesptr += 2;
stringlen = tablesptr - stringsptr - 1;
if (stringlen == 1) {
stringlen = 0;
}
if (stringlen==0)
stringlen=1;
for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {
const char*str;
intsize;
charaltname[40];
sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[cur->type] + 1);
if (smbios_properties[j].table_type == cur->type &&
smbios_properties[j].value_type == SMSTRING &&
(getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)))
{
stringlen += size + 1;
} else if (smbios_properties[j].table_type == cur->type &&
smbios_properties[j].value_type == SMSTRING &&
do_auto && smbios_properties[j].auto_str)
{
stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[cur->type])) + 1;
}
}
if (stringlen == 0) {
stringlen = 1;
}
stringlen++;
if (ret->maxStructureSize<cur->length+stringlen)
if (ret->maxStructureSize < cur->length+stringlen) {
ret->maxStructureSize=cur->length+stringlen;
ret->dmi.tableLength+=cur->length+stringlen;
}
ret->dmi.tableLength += cur->length+stringlen;
ret->dmi.structureCount++;
tablespresent[cur->type]++;
}
for (i=0;i<sizeof (smbios_table_descriptions)
/sizeof(smbios_table_descriptions[0]);i++)
{
int numnec=-1;
char buffer[40];
sprintf (buffer, "SMtable%d", i);
if (!getIntForKey(buffer,&numnec,&bootInfo->smbiosConfig))
numnec=-1;
if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc)
numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type);
while (tablespresent[smbios_table_descriptions[i].type]<numnec)
{
int stringlen=0;
for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]);
j++)
{
const char *str;
int size;
char altname[40];
sprintf (altname, "%s_%d",smbios_properties[j].name,
tablespresent[smbios_table_descriptions[i].type]+1);
if (smbios_properties[j].table_type
==smbios_table_descriptions[i].type
&& smbios_properties[j].value_type==SMSTRING
&& (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)
|| getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)))
stringlen+=size+1;
else if (smbios_properties[j].table_type
==smbios_table_descriptions[i].type
&& smbios_properties[j].value_type==SMSTRING
&& do_auto && smbios_properties[j].auto_str)
stringlen+=strlen(smbios_properties[j].auto_str
(smbios_properties[j].name,
tablespresent[smbios_table_descriptions[i].type]))+1;
}
for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) {
intnumnec=-1;
charbuffer[40];
sprintf(buffer, "SMtable%d", i);
if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) {
numnec = -1;
}
if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) {
numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type);
}
while (tablespresent[smbios_table_descriptions[i].type] < numnec) {
intstringlen = 0;
for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {
const char*str;
intsize;
charaltname[40];
sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type] + 1);
if (smbios_properties[j].table_type == smbios_table_descriptions[i].type &&
smbios_properties[j].value_type == SMSTRING &&
(getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)))
{
stringlen += size + 1;
} else if (smbios_properties[j].table_type == smbios_table_descriptions[i].type &&
smbios_properties[j].value_type==SMSTRING &&
do_auto && smbios_properties[j].auto_str)
{
stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type])) + 1;
}
}
if (stringlen==0)
stringlen=1;
if (stringlen == 0) {
stringlen = 1;
}
stringlen++;
if (ret->maxStructureSize<smbios_table_descriptions[i].len+stringlen)
ret->maxStructureSize=smbios_table_descriptions[i].len+stringlen;
ret->dmi.tableLength+=smbios_table_descriptions[i].len+stringlen;
if (ret->maxStructureSize < smbios_table_descriptions[i].len+stringlen) {
ret->maxStructureSize = smbios_table_descriptions[i].len + stringlen;
}
ret->dmi.tableLength += smbios_table_descriptions[i].len + stringlen;
ret->dmi.structureCount++;
tablespresent[smbios_table_descriptions[i].type]++;
}
return ret;
}
void
smbios_real_run (struct SMBEntryPoint * origsmbios,
struct SMBEntryPoint * newsmbios)
void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios)
{
char *smbiostables=0;
char *smbiostables;
char *tablesptr, *newtablesptr;
int origsmbiosnum=0;
int origsmbiosnum;
// bitmask of used handles
uint8_t handles[8192];
uint16_t nexthandle=0;
int i, j;
int tablespresent[256];
BOOL do_auto=1;
bool do_auto=true;
getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig);
bzero(tablespresent, sizeof(tablespresent));
bzero(handles, sizeof(handles));
getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig);
for (i=0;i<256;i++)
tablespresent[i]=0;
memset (handles,0,8192);
newsmbios->dmi.tableAddress=(uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength);
if (origsmbios)
{
smbiostables=(char *) origsmbios->dmi.tableAddress;
origsmbiosnum=origsmbios->dmi.structureCount;
}
tablesptr=smbiostables;
newtablesptr=(char *) newsmbios->dmi.tableAddress;
if (smbiostables)
for (i=0;i<origsmbiosnum;i++)
{
struct smbios_table_header *oldcur
=(struct smbios_table_header *) tablesptr,
*newcur=(struct smbios_table_header *) newtablesptr;
char *stringsptr;
int nstrings=0;
handles[(oldcur->handle)/8]|=1<<((oldcur->handle)%8);
memcpy (newcur,oldcur, oldcur->length);
tablesptr+=oldcur->length;
stringsptr=tablesptr;
newtablesptr+=oldcur->length;
for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++)
if (tablesptr[0]==0)
newsmbios->dmi.tableAddress = (uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength);
if (origsmbios) {
smbiostables = (char *)origsmbios->dmi.tableAddress;
origsmbiosnum = origsmbios->dmi.structureCount;
} else {
smbiostables = NULL;
origsmbiosnum = 0;
}
tablesptr = smbiostables;
newtablesptr = (char *)newsmbios->dmi.tableAddress;
if (smbiostables) {
for (i=0; i<origsmbiosnum; i++) {
struct smbios_table_header*oldcur = (struct smbios_table_header *) tablesptr;
struct smbios_table_header*newcur = (struct smbios_table_header *) newtablesptr;
char*stringsptr;
intnstrings = 0;
handles[(oldcur->handle) / 8] |= 1 << ((oldcur->handle) % 8);
memcpy(newcur,oldcur, oldcur->length);
tablesptr += oldcur->length;
stringsptr = tablesptr;
newtablesptr += oldcur->length;
for (;tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++) {
if (tablesptr[0] == 0) {
nstrings++;
if (tablesptr!=stringsptr)
}
}
if (tablesptr != stringsptr) {
nstrings++;
tablesptr+=2;
memcpy (newtablesptr,stringsptr,tablesptr-stringsptr);
}
tablesptr += 2;
memcpy(newtablesptr, stringsptr, tablesptr-stringsptr);
//point to next possible space for a string
newtablesptr+=tablesptr-stringsptr-1;
if (nstrings==0)
newtablesptr += tablesptr - stringsptr - 1;
if (nstrings == 0) {
newtablesptr--;
for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]);
j++)
{
const char *str;
int size;
int num;
char altname[40];
sprintf (altname, "%s_%d",smbios_properties[j].name,
tablespresent[newcur->type]+1);
if (smbios_properties[j].table_type==newcur->type)
switch (smbios_properties[j].value_type)
{
}
for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {
const char*str;
intsize;
intnum;
charaltname[40];
sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1);
if (smbios_properties[j].table_type == newcur->type) {
switch (smbios_properties[j].value_type) {
case SMSTRING:
if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)
||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))
if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))
{
memcpy (newtablesptr, str,size);
newtablesptr[size]=0;
newtablesptr+=size+1;
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings;
memcpy(newtablesptr, str, size);
newtablesptr[size] = 0;
newtablesptr += size + 1;
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;
} else if (do_auto && smbios_properties[j].auto_str) {
str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]);
size = strlen(str);
memcpy(newtablesptr, str, size);
newtablesptr[size] = 0;
newtablesptr += size + 1;
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;
}
else if (do_auto && smbios_properties[j].auto_str)
{
str=smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[newcur->type]);
size=strlen (str);
memcpy (newtablesptr, str,size);
newtablesptr[size]=0;
newtablesptr+=size+1;
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings;
}
break;
case SMOWORD:
if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)
||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))
if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))
{
int k=0, t=0, kk=0;
const char *ptr=str;
memset(((char*)newcur)+smbios_properties[j].offset, 0, 16);
while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n'))
intk=0, t=0, kk=0;
const char*ptr = str;
memset(((char*)newcur) + smbios_properties[j].offset, 0, 16);
while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) {
ptr++;
if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X'))
ptr+=2;
for (;ptr-str<size && *ptr && k<16;ptr++)
{
if (*ptr>='0' && *ptr<='9')
}
if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) {
ptr += 2;
}
for (;ptr-str<size && *ptr && k<16;ptr++) {
if (*ptr>='0' && *ptr<='9') {
(t=(t<<4)|(*ptr-'0')),kk++;
if (*ptr>='a' && *ptr<='f')
}
if (*ptr>='a' && *ptr<='f') {
(t=(t<<4)|(*ptr-'a'+10)),kk++;
if (*ptr>='A' && *ptr<='F')
}
if (*ptr>='A' && *ptr<='F') {
(t=(t<<4)|(*ptr-'A'+10)),kk++;
if (kk==2)
{
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t;
}
if (kk == 2) {
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t;
k++;
kk=0;
t=0;
kk = 0;
t = 0;
}
}
}
break;
case SMBYTE:
if (getIntForKey(altname,&num,&bootInfo->smbiosConfig)
||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig))
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num;
else if (do_auto && smbios_properties[j].auto_int)
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))
=smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||
getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))
{
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;
} else if (do_auto && smbios_properties[j].auto_int) {
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
}
break;
case SMWORD:
if (getIntForKey(altname,&num,&bootInfo->smbiosConfig)
||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig))
*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num;
else if (do_auto && smbios_properties[j].auto_int)
*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))
=smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||
getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))
{
*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;
} else if (do_auto && smbios_properties[j].auto_int) {
*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
}
break;
}
}
}
if (nstrings==0)
{
newtablesptr[0]=0;
if (nstrings == 0) {
newtablesptr[0] = 0;
newtablesptr++;
}
newtablesptr[0]=0;
newtablesptr[0] = 0;
newtablesptr++;
tablespresent[newcur->type]++;
}
for (i=0;i<sizeof (smbios_table_descriptions)
/sizeof(smbios_table_descriptions[0]);i++)
{
int numnec=-1;
char buffer[40];
sprintf (buffer, "SMtable%d", i);
if (!getIntForKey(buffer,&numnec,&bootInfo->smbiosConfig))
numnec=-1;
if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc)
numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type);
while (tablespresent[smbios_table_descriptions[i].type]<numnec)
{
struct smbios_table_header *newcur=(struct smbios_table_header *) newtablesptr;
int nstrings=0;
memset (newcur,0, smbios_table_descriptions[i].len);
while (handles[(nexthandle)/8]&(1<<((nexthandle)%8)))
}
for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) {
intnumnec = -1;
charbuffer[40];
sprintf(buffer, "SMtable%d", i);
if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) {
numnec = -1;
}
if (numnec == -1 && do_auto && smbios_table_descriptions[i].numfunc) {
numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type);
}
while (tablespresent[smbios_table_descriptions[i].type] < numnec) {
struct smbios_table_header*newcur = (struct smbios_table_header *) newtablesptr;
intnstrings = 0;
memset(newcur,0, smbios_table_descriptions[i].len);
while (handles[(nexthandle)/8] & (1 << ((nexthandle) % 8))) {
nexthandle++;
newcur->handle=nexthandle;
handles[nexthandle/8]|=1<<(nexthandle%8);
newcur->type=smbios_table_descriptions[i].type;
newcur->length=smbios_table_descriptions[i].len;
newtablesptr+=smbios_table_descriptions[i].len;
for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]);
j++)
{
const char *str;
int size;
int num;
char altname[40];
sprintf (altname, "%s_%d",smbios_properties[j].name,
tablespresent[newcur->type]+1);
if (smbios_properties[j].table_type==newcur->type)
switch (smbios_properties[j].value_type)
{
}
newcur->handle = nexthandle;
handles[nexthandle / 8] |= 1 << (nexthandle % 8);
newcur->type = smbios_table_descriptions[i].type;
newcur->length = smbios_table_descriptions[i].len;
newtablesptr += smbios_table_descriptions[i].len;
for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {
const char*str;
intsize;
intnum;
charaltname[40];
sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1);
if (smbios_properties[j].table_type == newcur->type) {
switch (smbios_properties[j].value_type) {
case SMSTRING:
if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)
||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))
if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))
{
memcpy (newtablesptr, str,size);
newtablesptr[size]=0;
newtablesptr+=size+1;
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings;
memcpy(newtablesptr, str, size);
newtablesptr[size] = 0;
newtablesptr += size + 1;
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;
} else if (do_auto && smbios_properties[j].auto_str) {
str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]);
size = strlen(str);
memcpy(newtablesptr, str, size);
newtablesptr[size] = 0;
newtablesptr += size + 1;
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;
}
else if (do_auto && smbios_properties[j].auto_str)
{
str=smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]);
size=strlen (str);
memcpy (newtablesptr, str,size);
newtablesptr[size]=0;
newtablesptr+=size+1;
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings;
}
break;
case SMOWORD:
if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)
||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))
if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||
getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))
{
int k=0, t=0, kk=0;
const char *ptr=str;
memset(((char*)newcur)+smbios_properties[j].offset, 0, 16);
while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n'))
intk=0, t=0, kk=0;
const char*ptr = str;
memset(((char*)newcur) + smbios_properties[j].offset, 0, 16);
while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) {
ptr++;
if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X'))
ptr+=2;
for (;ptr-str<size && *ptr && k<16;ptr++)
{
if (*ptr>='0' && *ptr<='9')
}
if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) {
ptr += 2;
}
for (;ptr-str<size && *ptr && k<16;ptr++) {
if (*ptr>='0' && *ptr<='9') {
(t=(t<<4)|(*ptr-'0')),kk++;
if (*ptr>='a' && *ptr<='f')
}
if (*ptr>='a' && *ptr<='f') {
(t=(t<<4)|(*ptr-'a'+10)),kk++;
if (*ptr>='A' && *ptr<='F')
}
if (*ptr>='A' && *ptr<='F') {
(t=(t<<4)|(*ptr-'A'+10)),kk++;
if (kk==2)
{
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t;
}
if (kk == 2) {
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t;
k++;
kk=0;
t=0;
kk = 0;
t = 0;
}
}
}
break;
case SMBYTE:
if (getIntForKey(altname,&num,&bootInfo->smbiosConfig)
||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig))
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num;
else if (do_auto && smbios_properties[j].auto_int)
*((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))
=smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||
getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))
{
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;
} else if (do_auto && smbios_properties[j].auto_int) {
*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
}
break;
case SMWORD:
if (getIntForKey(altname,&num,&bootInfo->smbiosConfig)
||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig))
*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num;
else if (do_auto && smbios_properties[j].auto_int)
*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))
=smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||
getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))
{
*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;
} else if (do_auto && smbios_properties[j].auto_int) {
*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);
}
break;
}
}
}
if (nstrings==0)
{
newtablesptr[0]=0;
if (nstrings == 0) {
newtablesptr[0] = 0;
newtablesptr++;
}
newtablesptr[0]=0;
newtablesptr[0] = 0;
newtablesptr++;
tablespresent[smbios_table_descriptions[i].type]++;
}
}
newsmbios->dmi.checksum=0;
newsmbios->dmi.checksum=256-checksum8 (&newsmbios->dmi,sizeof (newsmbios->dmi));
newsmbios->checksum=0;
newsmbios->checksum=256-checksum8 (newsmbios,sizeof (*newsmbios));
verbose("Patched DMI Table.\n");
newsmbios->dmi.checksum = 0;
newsmbios->dmi.checksum = 256 - checksum8(&newsmbios->dmi, sizeof(newsmbios->dmi));
newsmbios->checksum = 0;
newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(*newsmbios));
verbose("Patched DMI Table\n");
}
inline struct SMBEntryPoint *
getSmbios()
struct SMBEntryPoint *getSmbios(void)
{
const char *smbios_filename;
char dirSpec[512];
int len;
struct SMBEntryPoint *orig_address;
struct SMBEntryPoint *new_address;
orig_address=getAddressOfSmbiosTable();
if (!getValueForKey("SMBIOS", &smbios_filename, &len, &bootInfo->bootConfig))
smbios_filename = "smbios.plist";
sprintf(dirSpec, "%s", smbios_filename);
if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1)
{
sprintf(dirSpec, "/Extra/%s", smbios_filename);
if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1)
{
sprintf(dirSpec, "bt(0,0)/Extra/%s", smbios_filename);
if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1)
{
verbose("No SMBIOS replacement found.\n");
}
}
}
//if( (loadConfigFile("/Extra/smbios.plist", &bootInfo->smbiosConfig)) == -1 )
//loadConfigFile("bt(0,0)/Extra/smbios.plist", &bootInfo->smbiosConfig); // TODO: do we need this ?
orig_address=getAddressOfSmbiosTable();
new_address = smbios_dry_run(orig_address);
smbios_real_run(orig_address, new_address);
return new_address;
trunk/i386/libsaio/smbios_patcher.h
66
77
88
9
910
1011
1112
......
5455
5556
5657
58
59
5760
#define __LIBSAIO_SMBIOS_PATCHER_H
#include "libsaio.h"
#include "SMBIOS.h"
extern EFI_GUID gEfiAcpiTableGuid;
extern EFI_GUID gEfiAcpi20TableGuid;
};
extern struct SMBEntryPoint *getAddressOfSmbiosTable(void);
extern struct SMBEntryPoint *getSmbios(void);
#endif /* !__LIBSAIO_SMBIOS_PATCHER_H */
trunk/i386/libsaio/mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* Copyright 2010 AsereBLN. All rights reserved. <aserebln@googlemail.com>
*
* mem.c - obtain system memory information
*/
#include "libsaio.h"
#include "pci.h"
#include "platform.h"
#include "cpu.h"
#include "mem.h"
#ifndef DEBUG_MEM
#define DEBUG_MEM 0
#endif
#if DEBUG_MEM
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
void scan_memory(PlatformInfo_t *p)
{
/* NYI */
}
trunk/i386/libsaio/pci_root.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright 2009 netkas
*/
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#ifndef DEBUG_PCIROOT
#define DEBUG_PCIROOT 0
#endif
#if DEBUG_PCIROOT
#define DBG(x...) printf(x)
#else
#define DBG(x...)
#endif
static int rootuid = 10; //value means function wasnt ran yet
static unsigned int findrootuid(unsigned char * dsdt, int len)
{
int i;
for (i=0; i<64 && i<len-5; i++) //not far than 64 symbols from pci root
{
if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)
{
return dsdt[i+4];
}
}
return 11;
}
static unsigned int findpciroot(unsigned char * dsdt,int len)
{
int i;
for (i=0; i<len-4; i++) {
if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08)) {
return findrootuid(dsdt+i, len-i);
}
}
return 10;
}
int getPciRootUID(void)
{
void *new_dsdt;
const char *dsdt_filename;
const char *val;
int fd;
int dsdt_uid;
int len,fsize;
if (rootuid < 10) {
return rootuid;
}
rootuid = 0;/* default uid = 0 */
if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) {
if (isdigit(val[0])) {
rootuid = val[0] - '0';
}
goto out;
}
#if 0
/* Chameleon compatibility */
if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) {
if (isdigit(val[0])) {
rootuid = val[0] - '0';
}
goto out;
}
/* PCEFI compatibility */
if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) {
rootuid = 0;
goto out;
}
if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) {
rootuid = 1;
goto out;
}
#endif
if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig)) {
dsdt_filename="/Extra/DSDT.aml";
}
if ((fd = open_bvdev("bt(0,0)", dsdt_filename, 0)) < 0) {
verbose("[WARNING] %s not found\n", dsdt_filename);
goto out;
}
fsize = file_size(fd);
if ((new_dsdt = malloc(fsize)) == NULL) {
verbose("[ERROR] alloc DSDT memory failed\n");
close (fd);
goto out;
}
if (read (fd, new_dsdt, fsize) != fsize) {
verbose("[ERROR] read %s failed\n", dsdt_filename);
close (fd);
goto out;
}
close (fd);
dsdt_uid = findpciroot(new_dsdt, fsize);
free(new_dsdt);
if (dsdt_uid >= 0 && dsdt_uid <= 9) {
rootuid = dsdt_uid;
} else {
verbose("Could not determine PCI-Root-UID value from DSDT!\n");
}
out:
verbose("Using PCI-Root-UID value %d\n", rootuid);
return rootuid;
}
trunk/i386/libsaio/mem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
* Copyright 2010 AsereBLN. All rights reserved. <aserebln@googlemail.com>
*
* mem.h
*/
#ifndef __LIBSAIO_MEM_H
#define __LIBSAIO_MEM_H
#include "platform.h"
extern void scan_memory(PlatformInfo_t *);
#endif/* __LIBSAIO_MEM_H */
trunk/i386/libsaio/pci_root.h
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* Copyright 2008 mackerintel
*/
#ifndef __LIBSAIO_PCI_ROOT_H
#define __LIBSAIO_PCI_ROOT_H
#include "libsaio.h"
extern int getPciRootUID(void);
#endif /* !__LIBSAIO_DSDT_PATCHER_H */
trunk/i386/libsaio/usb.c
88
99
1010
11
1112
1213
1314
......
2324
2425
2526
26
27
27
2828
2929
3030
31
32
33
31
32
3433
35
36
37
34
35
36
37
38
3839
3940
40
41
4142
4243
4344
......
4849
4950
5051
51
52
53
52
53
5454
5555
5656
......
5858
5959
6060
61
62
63
61
62
6463
65
64
6665
6766
6867
......
7170
7271
7372
74
75
73
7674
7775
7876
79
80
81
77
78
8279
83
80
81
8482
83
8584
8685
8786
88
87
8988
9089
91
90
9291
93
94
95
92
93
9694
95
9796
98
97
9998
99
100100
101101
102
103
102
103
104104
105
105106
106
107
107
108108
109109
110110
111
112111
113112
114113
115114
116115
117
118
119
116
117
120118
119
121120
122121
123
122
124123
124
125125
126126
127127
128
128
129129
130
130131
131
132
132
133
133134
135
134136
135137
136138
137139
138
139
140
140141
141142
142143
143
144
144145
145146
146147
*/
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
int ehci_acquire (pci_dt_t *pci_dev)
{
int j,k;
intj, k;
uint32_tbase;
uint8_teecp;
uint8_tlegacy[8];
BOOL isOwnershipConflict;
BOOL alwaysHardBIOSReset;
boolisOwnershipConflict;
boolalwaysHardBIOSReset;
if (!getBoolForKey("EHCIhard", &alwaysHardBIOSReset, &bootInfo->bootConfig))
alwaysHardBIOSReset = 1;
alwaysHardBIOSReset = false;
if (!getBoolForKey(kEHCIhard, &alwaysHardBIOSReset, &bootInfo->bootConfig)) {
alwaysHardBIOSReset = true;
}
pci_config_write16(pci_dev->dev.addr, 0x04, 0x0002);
base = pci_config_read32(pci_dev->dev.addr, 0x10);
verbose("EHCI controller [%04x:%04x] at %02x:%2x.%x DMA @%x\n",
pci_dev->vendor_id, pci_dev->device_id,
pci_dev->dev.bits.bus, pci_dev->dev.bits.dev, pci_dev->dev.bits.func,
DBG("Config space too small: no legacy implementation\n");
return 1;
}
eecp=*((unsigned char*)(base + 9));
if (!eecp)
{
eecp = *((unsigned char*)(base + 9));
if (!eecp) {
DBG("No extended capabilities: no legacy implementation\n");
return 1;
}
DBG("eecp=%x\n",eecp);
// bad way to do it
//pci_conf_write(pci_dev->dev.addr, eecp, 4, 0x01000001);
for (j = 0; j < 8; j++)
{
// pci_conf_write(pci_dev->dev.addr, eecp, 4, 0x01000001);
for (j = 0; j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
DBG("%02x ",legacy[j]);
DBG("%02x ", legacy[j]);
}
DBG("\n");
// Definitely needed during reboot on 10.4.6
isOwnershipConflict = ((legacy[3] & 1 != 0) && (legacy[2] & 1 != 0));
if (!alwaysHardBIOSReset && isOwnershipConflict)
{
if (!alwaysHardBIOSReset && isOwnershipConflict) {
DBG("EHCI - Ownership conflict - attempting soft reset ...\n");
DBG("EHCI - toggle OS Ownership to 0\n");
pci_config_write8(pci_dev->dev.addr, eecp + 3, 0);
for (k = 0; k < 25; k++)
{
for (j = 0; j < 8; j++)
for (k = 0; k < 25; k++) {
for (j = 0; j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
if (legacy[3] == 0)
}
if (legacy[3] == 0) {
break;
}
delay(10);
}
}
DBG("Found USBLEGSUP_ID - value %x:%x - writing OSOwned\n", legacy[3],legacy[2]);
pci_config_write8(pci_dev->dev.addr, eecp + 3, 1);
// wait for kEHCI_USBLEGSUP_BIOSOwned bit to clear
for (k = 0; k < 25; k++)
{
for (j = 0;j < 8; j++)
for (k = 0; k < 25; k++) {
for (j = 0;j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
}
DBG ("%x:%x,",legacy[3],legacy[2]);
if (legacy[2] == 0)
if (legacy[2] == 0) {
break;
}
delay(10);
}
for (j = 0;j < 8; j++)
for (j = 0;j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
}
isOwnershipConflict = ((legacy[2]) != 0);
if (isOwnershipConflict)
{
if (isOwnershipConflict) {
// Soft reset has failed. Assume SMI being ignored
// Hard reset
// Force Clear BIOS BIT
DBG("EHCI - Ownership conflict - attempting hard reset ...\n");
DBG ("%x:%x\n",legacy[3],legacy[2]);
DBG("EHCI - Force BIOS Ownership to 0\n");
pci_config_write8(pci_dev->dev.addr, eecp + 2, 0);
for (k = 0; k < 25; k++)
{
for (j = 0; j < 8; j++)
for (k = 0; k < 25; k++) {
for (j = 0; j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
}
DBG ("%x:%x,",legacy[3],legacy[2]);
if ((legacy[2]) == 0)
if ((legacy[2]) == 0) {
break;
}
delay(10);
}
// Disable further SMI events
for (j = 4; j < 8; j++)
for (j = 4; j < 8; j++) {
pci_config_write8(pci_dev->dev.addr, eecp + j, 0);
}
}
for (j = 0; j < 8; j++)
for (j = 0; j < 8; j++) {
legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j);
}
DBG ("%x:%x\n",legacy[3],legacy[2]);
// Final Ownership Resolution Check...
if (legacy[2]&1)
{
if (legacy[2] & 1) {
DBG("EHCI controller unable to take control from BIOS\n");
return 0;
}
DBG("EHCI Acquire OS Ownership done\n");
return 1;
}
trunk/i386/libsaio/device_inject.c
66
77
88
9
910
1011
12
1113
1214
1315
......
2931
3032
3133
32
33
34
3435
3536
3637
37
38
3839
3940
4041
42
4143
4244
4345
......
129131
130132
131133
132
134
133135
134136
135137
......
170172
171173
172174
173
174
175
175
176
177
176178
177
178
179
180
179
181180
182181
182
183183
184
185
186
187
188
189
190
191
184
192185
193186
194187
195
188
196189
197
198
199
190
191
200192
201193
202194
203195
204
205
206
207
196
197
208198
209199
210200
*/
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
#include "pci_root.h"
#include "device_inject.h"
char *efi_inject_get_devprop_string(uint32_t *len)
{
if(string)
{
if(string) {
*len = string->length;
return devprop_generate_string(string);
}
printf("efi_inject_get_devprop_string NULL trying stringdata\n");
verbose("efi_inject_get_devprop_string NULL trying stringdata\n");
return NULL;
}
/* XXX AsereBLN replace by strtoul */
uint32_t ascii_hex_to_int(char *buff)
{
uint32_tvalue = 0, i, digit;
/* Use the static "device-properties" boot config key contents if available,
* otheriwse use the generated one.
*/
if (!getValueForKey(DEVICE_PROPERTIES_PROP, &val, &cnt, &bootInfo->bootConfig) && string)
if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string)
{
val = (const char*)string;
cnt = strlength * 2;
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
{
uint32_t PciRootID = 0;
const char *val;
int len;
struct DevPropDevice*device;
const charpciroot_string[] = "PciRoot(0x";
const charpci_device_string[] = "Pci(0x";
struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
if(!device || !string || !path) {
if(device)
free(device);
if (string == NULL || path == NULL) {
return NULL;
}
device = malloc(sizeof(struct DevPropDevice));
const char pciroot_string[]= "PciRoot(0x";
const char pci_device_string[]= "Pci(0x";
if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig))
PciRootID = atoi(val);
if(strncmp(path, pciroot_string, strlen(pciroot_string)))
{
if (strncmp(path, pciroot_string, strlen(pciroot_string))) {
printf("ERROR parsing device path\n");
return NULL;
}
memset(device, 0, sizeof(struct DevPropDevice));
device->acpi_dev_path._UID = PciRootID;
device->acpi_dev_path._UID = getPciRootUID();
int numpaths = 0;
intx, curr = 0;
charbuff[] = "00";
for(x = 0; x < strlen(path); x++)
{
if(!strncmp(&path[x], pci_device_string, strlen(pci_device_string)))
{
for (x = 0; x < strlen(path); x++) {
if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) {
x+=strlen(pci_device_string);
curr=x;
while(path[++x] != ',');
trunk/i386/libsaio/device_inject.h
6363
6464
6565
66
67
68
69
70
66
67
7168
7269
73
74
75
70
71
72
7673
7774
struct DevPropDevice **entries;
};
voidsetupEfiDevices ();
char*efi_inject_get_devprop_string(uint32_t *len);
int devprop_add_nvidia_template(struct DevPropDevice *device);
int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
char*efi_inject_get_devprop_string(uint32_t *len);
intdevprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
struct DevPropString*devprop_create_string(void);
struct DevPropDevice*devprop_add_device(struct DevPropString *string, char *path);
int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(struct DevPropString *string);
void devprop_free_string(struct DevPropString *string);
intdevprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(struct DevPropString *string);
voiddevprop_free_string(struct DevPropString *string);
#endif /* !__LIBSAIO_DEVICE_INJECT_H */
trunk/i386/libsaio/dsdt_patcher.c
33
44
55
6
67
78
89
910
1011
12
1113
1214
1315
......
7779
7880
7981
82
8083
8184
8285
......
8588
8689
8790
88
91
8992
9093
9194
9295
93
9496
95
97
98
99
96100
97
101
102
103
98104
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
105
106
107
119108
120
109
121110
122
123
124
111
112
125113
114
126115
127116
128
129
117
130118
119
131120
132121
133
134
122
135123
136
137
138
139
124
125
126
127
128
129
130
131
140132
141
133
142134
143
144
135
145136
146137
147138
......
216207
217208
218209
219
220
210
211
212
213
214
215
216
217
221218
219
220
221
222
223
224
225
226
227
228
229
222230
223231
224232
......
307315
308316
309317
310
311
312318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
313339
314340
315341
......
377403
378404
379405
406
380407
381408
382409
383410
384411
412
385413
386414
387415
388416
389
417
418
390419
391
420
392421
393422
*/
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "acpi.h"
#include "efi_tables.h"
#include "fake_efi.h"
#include "dsdt_patcher.h"
#include "platform.h"
#ifndef DEBUG_DSDT
#define DEBUG_DSDT 0
{
//addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");
//addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi10_p = (uint32_t)getAddressOfAcpiTable();
acpi20_p = (uint32_t)getAddressOfAcpi20Table();
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
}
/* Setup ACPI. Replace DSDT if DSDT.aml is found */
int setupAcpi()
int setupAcpi(void)
{
int fd, version;
void *new_dsdt;
const char *dsdt_filename;
char dirspec[512];
int len;
boolean_t drop_ssdt=NO;
bool tmp;
bool drop_ssdt;
bool fix_restart;
//DBG("Enter setupACPI\n");
if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig)) {
dsdt_filename = "/Extra/DSDT.aml";
}
if (!getValueForKey("DSDT", &dsdt_filename, &len, &bootInfo->bootConfig))
dsdt_filename="DSDT.aml";
// Check booting partition
sprintf(dirspec,"%s",dsdt_filename);
fd=open (dirspec,0);
if (fd<0)
{// Check Extra on booting partition
sprintf(dirspec,"/Extra/%s",dsdt_filename);
fd=open (dirspec,0);
if (fd<0)
{// Fall back to booter partition
sprintf(dirspec,"bt(0,0)/Extra/%s",dsdt_filename);
fd=open (dirspec,0);
if (fd<0)
{
verbose("No DSDT replacement found. Leaving ACPI data as is\n");
return setupAcpiNoMod();
}
}
if ((fd = open_bvdev("bt(0,0)", dsdt_filename, 0)) < 0) {
verbose("No DSDT replacement found. Leaving ACPI data as is\n");
return setupAcpiNoMod();
}
// Load replacement DSDT
new_dsdt=(void*)AllocateKernelMemory(file_size (fd));
if (!new_dsdt)
{
new_dsdt = (void*)AllocateKernelMemory(file_size (fd));
if (!new_dsdt) {
printf("Couldn't allocate memory for DSDT\n");
close(fd);
return setupAcpiNoMod();
}
if (read (fd, new_dsdt, file_size (fd))!=file_size (fd))
{
if (read(fd, new_dsdt, file_size(fd)) != file_size(fd)) {
printf("Couldn't read file\n");
close(fd);
return setupAcpiNoMod();
}
close (fd);
close(fd);
DBG("New DSDT Loaded in memory\n");
{
BOOL tmp;
drop_ssdt=getBoolForKey("DropSSDT",&tmp, &bootInfo->bootConfig)&&tmp;
drop_ssdt = getBoolForKey(kDropSSDT, &tmp, &bootInfo->bootConfig) && tmp;
if (Platform.CPU.Vendor == 0x756E6547) {/* Intel */
fix_restart = true;
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);
} else {
fix_restart = false;
}
// Do the same procedure for both versions of ACPI
for (version=0;version<2;version++)
{
for (version=0; version<2; version++) {
struct acpi_2_rsdp *rsdp, *rsdp_mod;
struct acpi_2_rsdt *rsdt, *rsdt_mod;
int rsdplength;
continue;
}
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
if (fix_restart && fadt->Length < 0x81) {
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x81);
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x81;
} else {
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
if (fix_restart) {
fadt_mod->Flags |= 0x400;
fadt_mod->Reset_SpaceID = 0x01;
fadt_mod->Reset_BitWidth = 0x08;
fadt_mod->Reset_BitOffset = 0x00;
fadt_mod->Reset_AccessWidth = 0x01;
fadt_mod->Reset_Address = 0x0cf9;
fadt_mod->Reset_Value = 0x06;
verbose("FACP: Restart Fix applied\n");
}
// Patch DSDT Address
DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
printf("FADT incorrect or after 4GB. Dropping XSDT\n");
goto drop_xsdt;
}
fadt_mod=(struct acpi_2_fadt*)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
if (fix_restart && fadt->Length < 0x81) {
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x81);
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x81;
} else {
fadt_mod = (struct acpi_2_fadt*)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
if (fix_restart) {
fadt_mod->Flags |= 0x400;
fadt_mod->Reset_SpaceID = 0x01;
fadt_mod->Reset_BitWidth = 0x08;
fadt_mod->Reset_BitOffset = 0x00;
fadt_mod->Reset_AccessWidth = 0x01;
fadt_mod->Reset_Address = 0x0cf9;
fadt_mod->Reset_Value = 0x06;
verbose("FACP: Restart Fix applied\n");
}
// Patch DSDT Address
DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
verbose("Patched ACPI version %d DSDT\n", version+1);
if (version)
{
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi20_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
}
else
{
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi10_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
}
}
#if DEBUG_DSDT
#if DEBUG_DSDT
printf("(Press a key to continue...)\n");
getc();
#endif
#endif
return 1;
}
trunk/i386/libsaio/ntfs.c
295295
296296
297297
298
298
299299
300
300
301301
302302
303303
304304
305305
306
306
307307
308308
309309
return;
}
BOOL NTFSProbe(const void * buffer)
bool NTFSProbe(const void * buffer)
{
BOOL result = FALSE;
bool result = false;
const struct bootfile* part_bootfile = buffer;// NTFS boot sector structure
// Looking for NTFS signature.
if (strncmp((const char *)part_bootfile->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) == 0)
result = TRUE;
result = true;
return result;
}
trunk/i386/libsaio/nvidia.c
4949
5050
5151
52
5253
5354
5455
......
6566
6667
6768
69
6870
6971
7072
......
7476
7577
7678
77
78
79
80
81
82
83
84
79
80
81
82
83
84
85
86
8587
86
87
88
89
90
91
88
89
90
91
9292
9393
94
95
96
97
98
9994
10095
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
13496
13597
13698
......
141103
142104
143105
106
107
108
109
110
111
112
113
144114
145115
146116
......
175145
176146
177147
178
179
180
181
182
183
184
185
186
187
188
189
190
191
148
149
150
151
152
192153
193154
194155
......
201162
202163
203164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
204220
205221
206222
......
213229
214230
215231
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239232
240233
241234
......
267260
268261
269262
263
270264
271265
266
267
272268
273269
274270
......
282278
283279
284280
285
286281
287282
288283
289284
285
286
290287
291288
292289
293290
291
292
293
294
295
296
294297
295298
296299
......
303306
304307
305308
306
307
308
309
310
311
312
309
310
311
313312
314313
315
316
317
318
319
320
321
322
323
314
315
316
324317
325318
326
319
320
327321
328322
329323
330324
331325
332326
333
327
328
329
330
331
332
333
334
335
336
337
338
339
334340
335341
336342
......
338344
339345
340346
341
342
343
347
348
349
350
351
344352
345353
346354
......
515523
516524
517525
518
519
520
521
526
527
528
529
530
522531
532
523533
524534
525535
526536
527
537
528538
529
530
539
540
531541
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
542
543
548544
549
550
551
552
545
546
547
548
549
550
551
552
553553
554554
555
555
556556
557
558
559
557560
558561
559
562
560563
561564
562565
......
571574
572575
573576
574
575
576
577
577
578
578579
579
580
580581
581582
582583
583
584584
585585
586
587
588
589
590
591
592
593
594
595
596
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
597601
598602
599
600603
601604
602
605
603606
604607
605
606608
607609
608610
609
610
611
611
612
613
612614
613
615
616
617
618
619
620
621
622
623
614624
615
616
617
618
619
625
620626
621
622
623
624
625
626
627
628
629
630
631
632
633627
634628
635
629
636630
637631
638
639
632
640633
641634
642635
643636
644637
645
638
646639
647640
648641
649642
650643
651
652
644
653645
654
646
655647
656648
657
658
659
649
650
660651
661
662
663
664
652
653
654
655
656
665657
666
667
668
658
659
669660
670
671
672
673661
674
675
676
677662
678
679
680
681
682
663
664
683665
684666
685667
686
687668
688669
689670
690
691
671
672
692673
693674
694
695
675
676
677
678
696679
697
680
698681
699
700
701
702
703
704
705
706
707
708
709682
683
710684
711685
712
686
713687
714688
715
716
689
717690
718
691
719692
720693
721694
722
723695
724696
725697
726698
727699
728
729
730
731
732
733
700
701
702
734703
704
735705
736706
737
738
739
740
741
742
743
744707
745708
746709
*/
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
#include "platform.h"
#define DBG(x...)
#endif
#define NVIDIA_ROM_SIZE 0x10000
#define PATCH_ROM_SUCCESS 1
#define PATCH_ROM_SUCCESS_HAS_LVDS 2
#define PATCH_ROM_FAILED 0
extern uint32_t devices_number;
const char *nvidia_compatible_0[]={ "@0,compatible","NVDA,NVMac"};
const char *nvidia_compatible_1[]={ "@1,compatible","NVDA,NVMac"};
const char *nvidia_device_type_0[]={ "@0,device_type","display"};
const char *nvidia_device_type_1[]={ "@1,device_type","display"};
const char *nvidia_device_type[]={ "device_type","NVDA,Parent"};
const char *nvidia_name_0[]={ "@0,name","NVDA,Display-A"};
const char *nvidia_name_1[]={ "@1,name","NVDA,Display-B"};
const char *nvidia_slot_name[]={ "AAPL,slot-name","Slot-1"};
const char *nvidia_compatible_0[]={ "@0,compatible","NVDA,NVMac" };
const char *nvidia_compatible_1[]={ "@1,compatible","NVDA,NVMac" };
const char *nvidia_device_type_0[]={ "@0,device_type","display" };
const char *nvidia_device_type_1[]={ "@1,device_type","display" };
const char *nvidia_device_type[]={ "device_type","NVDA,Parent" };
const char *nvidia_name_0[]={ "@0,name","NVDA,Display-A" };
const char *nvidia_name_1[]={ "@1,name","NVDA,Display-B" };
const char *nvidia_slot_name[]={ "AAPL,slot-name","Slot-1" };
uint8_t default_NVCAP[]= {
0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0d, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0a,
0x00, 0x00, 0x00, 0x00
static uint8_t default_NVCAP[]= {
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
0x00, 0x00, 0x00, 0x00
};
uint16_t swap16(uint16_t toswap) {
return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8));
}
// Known cards as of 2008/08/26
static struct nv_chipsets_t NVKnownChipsets[] = {
{ 0x00000000, "Unknown" },
{ 0x10DE0301, "GeForce FX 5800 Ultra" },
{ 0x10DE0302, "GeForce FX 5800" },
{ 0x10DE0308, "Quadro FX 2000" },
{ 0x10DE0309, "Quadro FX 1000" },
{ 0x10DE0311, "GeForce FX 5600 Ultra" },
{ 0x10DE0312, "GeForce FX 5600" },
{ 0x10DE0314, "GeForce FX 5600XT" },
{ 0x10DE031A, "GeForce FX Go5600" },
{ 0x10DE031B, "GeForce FX Go5650" },
{ 0x10DE031C, "Quadro FX Go700" },
{ 0x10DE0324, "GeForce FX Go5200" },
{ 0x10DE0325, "GeForce FX Go5250" },
{ 0x10DE0326, "GeForce FX 5500" },
{ 0x10DE0328, "GeForce FX Go5200 32M/64M" },
{ 0x10DE032A, "Quadro NVS 55/280 PCI" },
{ 0x10DE032B, "Quadro FX 500/600 PCI" },
{ 0x10DE032C, "GeForce FX Go53xx Series" },
{ 0x10DE032D, "GeForce FX Go5100" },
{ 0x10DE0330, "GeForce FX 5900 Ultra" },
{ 0x10DE0331, "GeForce FX 5900" },
{ 0x10DE0332, "GeForce FX 5900XT" },
{ 0x10DE0333, "GeForce FX 5950 Ultra" },
{ 0x10DE0334, "GeForce FX 5900ZT" },
{ 0x10DE0338, "Quadro FX 3000" },
{ 0x10DE033F, "Quadro FX 700" },
{ 0x10DE0341, "GeForce FX 5700 Ultra" },
{ 0x10DE0342, "GeForce FX 5700" },
{ 0x10DE0343, "GeForce FX 5700LE" },
{ 0x10DE0344, "GeForce FX 5700VE" },
{ 0x10DE0347, "GeForce FX Go5700" },
{ 0x10DE0348, "GeForce FX Go5700" },
{ 0x10DE034C, "Quadro FX Go1000" },
{ 0x10DE034E, "Quadro FX 1100" },
{ 0x10DE0040, "GeForce 6800 Ultra" },
{ 0x10DE0041, "GeForce 6800" },
{ 0x10DE0042, "GeForce 6800 LE" },
{ 0x10DE0047, "GeForce 6800 GS" },
{ 0x10DE0048, "GeForce 6800 XT" },
{ 0x10DE004E, "Quadro FX 4000" },
{ 0x10DE0090, "GeForce 7800 GTX" },
{ 0x10DE0091, "GeForce 7800 GTX" },
{ 0x10DE0092, "GeForce 7800 GT" },
{ 0x10DE0093, "GeForce 7800 GS" },
{ 0x10DE0095, "GeForce 7800 SLI" },
{ 0x10DE0098, "GeForce Go 7800" },
{ 0x10DE0099, "GeForce Go 7800 GTX" },
{ 0x10DE009D, "Quadro FX 4500" },
{ 0x10DE00C0, "GeForce 6800 GS" },
{ 0x10DE00C1, "GeForce 6800" },
{ 0x10DE00C2, "GeForce 6800 LE" },
{ 0x10DE0168, "GeForce Go 6400" },
{ 0x10DE0169, "GeForce 6250" },
{ 0x10DE016A, "GeForce 7100 GS" },
{ 0x10DE0211, "GeForce 6800" },
{ 0x10DE0212, "GeForce 6800 LE" },
{ 0x10DE0215, "GeForce 6800 GT" },
{ 0x10DE0218, "GeForce 6800 XT" },
{ 0x10DE0221, "GeForce 6200" },
{ 0x10DE0222, "GeForce 6200 A-LE" },
{ 0x10DE0090, "GeForce 7800 GTX" },
{ 0x10DE0091, "GeForce 7800 GTX" },
{ 0x10DE0092, "GeForce 7800 GT" },
{ 0x10DE0093, "GeForce 7800 GS" },
{ 0x10DE0095, "GeForce 7800 SLI" },
{ 0x10DE0098, "GeForce Go 7800" },
{ 0x10DE0099, "GeForce Go 7800 GTX" },
{ 0x10DE009D, "Quadro FX 4500" },
{ 0x10DE0191, "GeForce 8800 GTX" },
{ 0x10DE0193, "GeForce 8800 GTS" },
{ 0x10DE0194, "GeForce 8800 Ultra" },
{ 0x10DE019D, "Quadro FX 5600" },
{ 0x10DE019E, "Quadro FX 4600" },
{ 0x10DE01D1, "GeForce 7300 LE" },
{ 0x10DE01D3, "GeForce 7300 SE" },
{ 0x10DE01D6, "GeForce Go 7200" },
{ 0x10DE01DD, "GeForce 7500 LE" },
{ 0x10DE01DE, "Quadro FX 350" },
{ 0x10DE01DF, "GeForce 7300 GS" },
{ 0x10DE0211, "GeForce 6800" },
{ 0x10DE0212, "GeForce 6800 LE" },
{ 0x10DE0215, "GeForce 6800 GT" },
{ 0x10DE0218, "GeForce 6800 XT" },
{ 0x10DE0221, "GeForce 6200" },
{ 0x10DE0222, "GeForce 6200 A-LE" },
{ 0x10DE0240, "GeForce 6150" },
{ 0x10DE0241, "GeForce 6150 LE" },
{ 0x10DE0242, "GeForce 6100" },
{ 0x10DE0244, "GeForce Go 6150" },
{ 0x10DE0247, "GeForce Go 6100" },
{ 0x10DE0290, "GeForce 7900 GTX" },
{ 0x10DE0291, "GeForce 7900 GT" },
{ 0x10DE0292, "GeForce 7900 GS" },
{ 0x10DE0298, "GeForce Go 7900 GS" },
{ 0x10DE0299, "GeForce Go 7900 GTX" },
{ 0x10DE029A, "Quadro FX 2500M" },
{ 0x10DE029B, "Quadro FX 1500M" },
{ 0x10DE029C, "Quadro FX 5500" },
{ 0x10DE029D, "Quadro FX 3500" },
{ 0x10DE029E, "Quadro FX 1500" },
{ 0x10DE029F, "Quadro FX 4500 X2" },
{ 0x10DE0301, "GeForce FX 5800 Ultra" },
{ 0x10DE0302, "GeForce FX 5800" },
{ 0x10DE0308, "Quadro FX 2000" },
{ 0x10DE0309, "Quadro FX 1000" },
{ 0x10DE0311, "GeForce FX 5600 Ultra" },
{ 0x10DE0312, "GeForce FX 5600" },
{ 0x10DE0314, "GeForce FX 5600XT" },
{ 0x10DE031A, "GeForce FX Go5600" },
{ 0x10DE031B, "GeForce FX Go5650" },
{ 0x10DE031C, "Quadro FX Go700" },
{ 0x10DE0324, "GeForce FX Go5200" },
{ 0x10DE0325, "GeForce FX Go5250" },
{ 0x10DE0326, "GeForce FX 5500" },
{ 0x10DE0328, "GeForce FX Go5200 32M/64M" },
{ 0x10DE032A, "Quadro NVS 55/280 PCI" },
{ 0x10DE032B, "Quadro FX 500/600 PCI" },
{ 0x10DE032C, "GeForce FX Go53xx Series" },
{ 0x10DE032D, "GeForce FX Go5100" },
{ 0x10DE0330, "GeForce FX 5900 Ultra" },
{ 0x10DE0331, "GeForce FX 5900" },
{ 0x10DE0332, "GeForce FX 5900XT" },
{ 0x10DE0333, "GeForce FX 5950 Ultra" },
{ 0x10DE0334, "GeForce FX 5900ZT" },
{ 0x10DE0338, "Quadro FX 3000" },
{ 0x10DE033F, "Quadro FX 700" },
{ 0x10DE0341, "GeForce FX 5700 Ultra" },
{ 0x10DE0342, "GeForce FX 5700" },
{ 0x10DE0343, "GeForce FX 5700LE" },
{ 0x10DE0344, "GeForce FX 5700VE" },
{ 0x10DE0347, "GeForce FX Go5700" },
{ 0x10DE0348, "GeForce FX Go5700" },
{ 0x10DE034C, "Quadro FX Go1000" },
{ 0x10DE034E, "Quadro FX 1100" },
{ 0x10DE0391, "GeForce 7600 GT" },
{ 0x10DE0392, "GeForce 7600 GS" },
{ 0x10DE0393, "GeForce 7300 GT" },
{ 0x10DE039B, "GeForce Go 7900 SE" },
{ 0x10DE039C, "Quadro FX 550M" },
{ 0x10DE039E, "Quadro FX 560" },
{ 0x10DE0290, "GeForce 7900 GTX" },
{ 0x10DE0291, "GeForce 7900 GT" },
{ 0x10DE0292, "GeForce 7900 GS" },
{ 0x10DE0298, "GeForce Go 7900 GS" },
{ 0x10DE0299, "GeForce Go 7900 GTX" },
{ 0x10DE029A, "Quadro FX 2500M" },
{ 0x10DE029B, "Quadro FX 1500M" },
{ 0x10DE029C, "Quadro FX 5500" },
{ 0x10DE029D, "Quadro FX 3500" },
{ 0x10DE029E, "Quadro FX 1500" },
{ 0x10DE029F, "Quadro FX 4500 X2" },
{ 0x10DE0240, "GeForce 6150" },
{ 0x10DE0241, "GeForce 6150 LE" },
{ 0x10DE0242, "GeForce 6100" },
{ 0x10DE0244, "GeForce Go 6150" },
{ 0x10DE0247, "GeForce Go 6100" },
/*************** G8x ***************/
{ 0x10DE0191, "GeForce 8800 GTX" },
{ 0x10DE0193, "GeForce 8800 GTS" },
{ 0x10DE0194, "GeForce 8800 Ultra" },
{ 0x10DE019D, "Quadro FX 5600" },
{ 0x10DE019E, "Quadro FX 4600" },
{ 0x10DE0400, "GeForce 8600 GTS" },
{ 0x10DE0401, "GeForce 8600 GT" },
{ 0x10DE0402, "GeForce 8600 GT" },
{ 0x10DE042D, "Quadro FX 360M" },
{ 0x10DE042E, "GeForce 9300M G" },
{ 0x10DE042F, "Quadro NVS 290" },
{ 0x10DE05E0, "GeForce GTX 295" },
{ 0x10DE05E1, "GeForce GTX 280" },
{ 0x10DE05E2, "GeForce GTX 260" },
{ 0x10DE05E3, "GeForce GTX 285" },
{ 0x10DE05E6, "GeForce GTX 275" },
{ 0x10DE0600, "GeForce 8800 GTS 512" },
{ 0x10DE0602, "GeForce 8800 GT" },
{ 0x10DE0604, "GeForce 9800 GX2" },
{ 0x10DE0612, "GeForce 9800 GTX" },
{ 0x10DE0613, "GeForce 9800 GTX+" },
{ 0x10DE0614, "GeForce 9800 GT" },
{ 0x10DE0615, "GeForce 250 GTS" },
{ 0x10DE061A, "Quadro FX 3700" },
{ 0x10DE061C, "Quadro FX 3600M" },
{ 0x10DE0622, "GeForce 9600 GT" },
{ 0x10DE0623, "GeForce 9600 GS" },
{ 0x10DE0626, "GeForce GT 130" },
{ 0x10DE0627, "GeForce GT 140" },
{ 0x10DE0628, "GeForce 9800M GTS" },
{ 0x10DE062A, "GeForce 9700M GTS" },
{ 0x10DE062C, "GeForce 9800M GTS" },
{ 0x10DE0640, "GeForce 9500 GT" },
{ 0x10DE0641, "GeForce 9400 GT" },
{ 0x10DE0642, "GeForce 8400 GS" },
{ 0x10DE0643, "GeForce 9500 GT" },
{ 0x10DE0644, "GeForce 9500 GS" },
{ 0x10DE0645, "GeForce 9500 GS" },
{ 0x10DE0646, "GeForce GT 120" },
{ 0x10DE0647, "GeForce 9600M GT" },
{ 0x10DE0648, "GeForce 9600M GS" },
{ 0x10DE0649, "GeForce 9600M GT" },
{ 0x10DE06E9, "GeForce 9300M GS" },
{ 0x10DE06EA, "Quadro NVS 150M" },
{ 0x10DE06EB, "Quadro NVS 160M" },
/*************** GT2xx *************/
{ 0x10DE05E0, "GeForce GTX 295" },
{ 0x10DE05E1, "GeForce GTX 280" },
{ 0x10DE05E2, "GeForce GTX 260" },
{ 0x10DE05E3, "GeForce GTX 285" },
{ 0x10DE05E6, "GeForce GTX 275" },
{ 0x10DE0A20, "GeForce GT220" },
{ 0x10DE0A60, "GeForce G210" },
{ 0x10DE0A65, "GeForce 210" }
};
uint32_t swap32(uint32_t toswap) {
return ((toswap & 0x000000FF) << 24) |
((toswap & 0x0000FF00) << 8 ) |
((toswap & 0x00FF0000) >> 8 ) |
((toswap & 0xFF000000) >> 24);
}
uint8_t read8(uint8_t *ptr, uint16_t offset) {
return ptr[offset];
static uint16_t swap16(uint16_t x)
{
return (((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8));
}
uint16_t read16(uint8_t *ptr, uint16_t offset) {
static uint16_t read16(uint8_t *ptr, uint16_t offset)
{
uint8_t ret[2];
ret[0] = ptr[offset+1];
ret[1] = ptr[offset];
return *((uint16_t*)&ret);
}
uint32_t read32(uint8_t *ptr, uint16_t offset) {
#if 0
static uint32_t swap32(uint32_t x)
{
return ((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8 ) | ((x & 0x00FF0000) >> 8 ) | ((x & 0xFF000000) >> 24);
}
static uint8_t read8(uint8_t *ptr, uint16_t offset)
{
return ptr[offset];
}
static uint32_t read32(uint8_t *ptr, uint16_t offset)
{
uint8_t ret[4];
ret[0] = ptr[offset+3];
ret[1] = ptr[offset+2];
ret[3] = ptr[offset];
return *((uint32_t*)&ret);
}
int patch_nvidia_rom(uint8_t *rom) {
if(!rom || (rom[0] != 0x55 && rom[1] != 0xaa)) {
#endif
static int patch_nvidia_rom(uint8_t *rom)
{
if (!rom || (rom[0] != 0x55 && rom[1] != 0xaa)) {
printf("False ROM signature: 0x%02x%02x\n", rom[0], rom[1]);
return PATCH_ROM_FAILED;
}
return (has_lvds ? PATCH_ROM_SUCCESS_HAS_LVDS : PATCH_ROM_SUCCESS);
}
char *get_nvidia_model(uint32_t id) {
int i=0;
for(i = 0; i < (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) {
if(NVKnownChipsets[i].device == id)
static char *get_nvidia_model(uint32_t id) {
inti;
for (i=1; i< (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) {
if (NVKnownChipsets[i].device == id) {
return NVKnownChipsets[i].name;
}
}
return NVKnownChipsets[0].name;
}
uint32_t load_nvidia_bios_file(char *filename, char *buffer)
static uint32_t load_nvidia_bios_file(const char *filename, uint8_t *buf, int bufsize)
{
intfd, size;
chardirspec[128];
intfd;
intsize;
// Check booting partition
sprintf(dirspec, "%s", filename);
fd = open(dirspec, 0);
if (fd < 0)
{
// Check Extra on booting partition
sprintf(dirspec, "/Extra/%s", filename);
fd = open(dirspec, 0);
if (fd < 0)
{
// Fall back to booter partition
sprintf(dirspec, "bt(0,0)/Extra/%s", filename);
fd=open (dirspec, 0);
if (fd < 0)
return 0;
}
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
return 0;
}
size = read(fd, buffer, file_size (fd));
close (fd);
return size;
size = file_size(fd);
if (size > bufsize) {
printf("Filesize of %s is bigger than expected! Truncating to 0x%x Bytes!\n", filename, bufsize);
size = bufsize;
}
size = read(fd, (char *)buf, size);
close(fd);
return size;
}
int devprop_add_nvidia_template(struct DevPropDevice *device)
static int devprop_add_nvidia_template(struct DevPropDevice *device)
{
chartmp[16];
intlen;
if(!device)
return 0;
if(!DP_ADD_TEMP_VAL(device, nvidia_compatible_0))
return 0;
if(!DP_ADD_TEMP_VAL(device, nvidia_device_type_0))
return 0;
if(!DP_ADD_TEMP_VAL(device, nvidia_device_type))
return 0;
char tmp[10];
sprintf(tmp, "Slot-%x",devices_number);
devprop_add_value(device, "AAPL,slot-name", tmp, strlen(tmp));
len = sprintf(tmp, "Slot-%x", devices_number);
devprop_add_value(device, "AAPL,slot-name", (uint8_t *)tmp, len + 1);
devices_number++;
return 1;
}
bool setup_nvidia_devprop(pci_dt_t *nvda_dev)
{
intlen;
char*devicepath;
uint8_t*nvRom, *rom;
volatile uint8_t *regs;
uint32_tvideoRam, nvBiosOveride, nvBiosSize;
uint32_tbar[7];
uint8_tnvPatch = 0;
charbiosVersion[32];
char*model;
const char*nvFilename;
struct DevPropDevice*device;
char*devicepath;
struct pci_rom_pci_header_t*rom_pci_header;
volatile uint8_t*regs;
uint8_t*rom;
uint8_t*nvRom;
uint32_tvideoRam;
uint32_tnvBiosOveride;
uint32_tbar[7];
uint32_tboot_display;
intnvPatch;
charbiosVersion[32];
charnvFilename[32];
char*model;
booldoit;
devicepath = get_pci_dev_path(nvda_dev);
bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 );
regs = (uint8_t *) (bar[0] & ~0x0f);
// Amount of VRAM in kilobytes
videoRam = (REG32(0x10020c) & 0xfff00000) >> 10;
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n",
model, (videoRam / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
devicepath);
model, (videoRam / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
devicepath);
rom = malloc(0x10000);
rom = malloc(NVIDIA_ROM_SIZE);
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->bootConfig) && doit) {
verbose("Looking for nvidia video bios file %s\n", nvFilename);
nvBiosOveride = load_nvidia_bios_file(nvFilename, rom, NVIDIA_ROM_SIZE);
DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride);
} else {
// Otherwise read bios from card
nvBiosOveride = 0;
if(!rom)
{
verbose(" ROM malloc failed.\n");
return 0;
}
// TODO: we should really check for the signature before copying the rom, i think.
if (!getValueForKey("VideoROM", &nvFilename, &len, &bootInfo->bootConfig))
nvFilename="NVIDIA.ROM";
// Load video bios overide
nvBiosOveride = nvBiosSize = load_nvidia_bios_file((char *)nvFilename, (char *)rom);
// Otherwise read bios from card
if (nvBiosOveride == 0)
{
// TODO: we should really check for the signature
// before copying the rom, i think.
// PRAMIN first
nvRom = (uint8_t*)&regs[NV_PRAMIN_OFFSET];
bcopy((uint32_t *)nvRom, rom, 0x10000);
bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE);
// Valid Signature ?
if(rom[0] != 0x55 && rom[1] != 0xaa)
{
if (rom[0] != 0x55 && rom[1] != 0xaa) {
// PROM next
// Enable PROM access
(REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED;
nvRom = (uint8_t*)&regs[NV_PROM_OFFSET];
bcopy((uint8_t *)nvRom, rom, 0x10000);
bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE);
// disable PROM access
(REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED;
// Valid Signature ?
if(rom[0] != 0x55 && rom[1] != 0xaa)
{
if (rom[0] != 0x55 && rom[1] != 0xaa) {
// 0xC0000 last
bcopy((char *)0xc0000, rom, 0x10000);
bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE);
// Valid Signature ?
if(rom[0] != 0x55 && rom[1] != 0xaa)
{
verbose(" Unable to locate video bios.\n");
if (rom[0] != 0x55 && rom[1] != 0xaa) {
verbose("Unable to locate video bios.\n");
return 0;
}
else
DBG(" ROM Address 0x%x Signature 0x%02x%02x\n",
nvRom, (uint8_t)rom[0], (uint8_t)rom[1]);
} else {
DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
} else {
DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
DBG(" PROM Address 0x%x Signature 0x%02x%02x\n",
nvRom, (uint8_t)rom[0], (uint8_t)rom[1]);
} else {
DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
DBG(" PRAM Address 0x%x Signature 0x%02x%02x\n",
nvRom, (uint8_t)rom[0], (uint8_t)rom[1]);
}
else
DBG(" %s Signature 0x%02x%02x %d bytes\n",
nvFilename, (uint8_t)rom[0], (uint8_t)rom[1], nvBiosOveride);
nvPatch = patch_nvidia_rom(rom);
if(nvPatch == PATCH_ROM_FAILED)
{
printf(" ROM Patching Failed.\n");
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) {
printf("nVidia ROM Patching Failed!\n");
return false;
}
structpci_rom_pci_header_t *rom_pci_header;
rom_pci_header = (struct pci_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]);
// check for 'PCIR' sig
if (rom_pci_header->signature == 0x50434952)
if (rom_pci_header->device != nvda_dev->device_id)
if (rom_pci_header->signature == 0x50434952) {
if (rom_pci_header->device != nvda_dev->device_id) {
// Get Model from the OpROM
model = get_nvidia_model((rom_pci_header->vendor << 16) | rom_pci_header->device);
else
printf("incorrect PCI ROM sig: 0x%x\n", rom_pci_header->signature);
} else {
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
}
}
if (!string)
if (!string) {
string = devprop_create_string();
struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice));
device = devprop_add_device(string, devicepath);
if(!device)
{
printf("Failed initializing dev-prop string dev-entry, press any key...\n");
free(rom);
getc();
return false;
}
device = devprop_add_device(string, devicepath);
/* FIXME: for primary graphics card only */
uint32_t boot_display = 0x00000001;
boot_display = 1;
devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
if(nvPatch == PATCH_ROM_SUCCESS_HAS_LVDS)
{
if(nvPatch == PATCH_ROM_SUCCESS_HAS_LVDS) {
uint8_t built_in = 0x01;
devprop_add_value(device, "@0,built-in", (uint8_t*)&built_in, 1);
devprop_add_value(device, "@0,built-in", &built_in, 1);
}
videoRam *= 1024;
sprintf(biosVersion, "xx.xx.xx - %s", (nvBiosOveride > 0) ? nvFilename : "internal");
devprop_add_nvidia_template(device);
devprop_add_value(device, "NVCAP", default_NVCAP, 20);
devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&videoRam, 4);
devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, (strlen(biosVersion) + 1));
BOOL set_vbios_prop = false;
getBoolForKey("VBIOS", &set_vbios_prop, &bootInfo->bootConfig);
if (set_vbios_prop)
devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1);
devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1);
if (getBoolForKey(kVBIOS, &doit, &bootInfo->bootConfig) && doit) {
devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512));
}
stringdata = malloc(sizeof(uint8_t) * string->length);
if(!stringdata)
{
printf("no stringdata press a key...\n");
getc();
return false;
}
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
stringlength = string->length;
trunk/i386/libsaio/ati.c
2222
2323
2424
25
2526
2627
2728
......
4445
4546
4647
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
8686
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
107106
108
109
110
111107
112108
113109
......
116112
117113
118114
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
174170
175171
176172
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
232228
233229
234
230
235231
236
237
232
233
238234
239235
240
236
241237
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
277276
278
279
280277
281
278
282279
283
284
285
286
280
281
282
283
287284
288285
289
286
290287
291288
292289
293290
294291
295
292
296293
297
298
299
300
301
302
303
304
305
306
307
308
309
294
295
296
297
298
299
300
301
310302
311303
312
313
304
305
314306
315307
316
308
317309
318310
319
320
311
312
321313
322314
323315
324
325
326
316
317
318
327319
328320
329
330
331
332
333
334
335
321
322
323
324
325
326
327
336328
337329
338
339
340
330
331
332
341333
342
343
334
344335
345336
346337
......
354345
355346
356347
357
348
358349
359350
360351
361352
362
353
363354
364355
365
366
367
356
357
358
359
368360
369
370
371
372
373
374
375
376
361
362
377363
378
379
364
365
366
367
368
369
380370
381371
382
372
383373
384
385
374
375
386376
387
388
389
390
391
392
393
394
395
396
377
378
397379
398
399
400
401
380
381
382
383
384
385
386
387
402388
403389
404
405
406
407
390
391
392
393
394
395
408396
397
409398
410399
411400
412401
413
414
415
416
402
403
404
405
406
407
417408
409
418410
419411
420412
421413
422
414
423415
424
416
417
418
419
425420
426
427
421
428422
429
430
431423
432
424
433425
426
434427
435
428
436429
437430
438431
439
432
440433
441434
442435
......
524517
525518
526519
527
520
528521
529522
530523
......
613606
614607
615608
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
635624
636625
637
626
638627
639
640
641
642
643
628
629
630
631
632
644633
645634
646
647635
648
636
649637
650
651
638
652639
653
654
655
640
656641
657642
658643
659644
660645
661646
662
663
664
647
648
649
650
651
665652
666653
667654
668
655
669656
670
671
657
672658
673659
674
660
661
662
675663
676664
677665
......
683671
684672
685673
686
687674
688
689
675
690676
691
677
692678
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
716701
717
718
719
720
721
722
723
724
725
726
727
728
702
703
704
705
706
707
708
709
710
711
712
729713
730
731
714
715
716
732717
733
734
735
736
737
738
718
719
720
721
722
723
724
725
726
727
728
739729
740
741
742
743
744
745
746
747
748
749
750
751
752
730
731
732
733
734
735
736
737
738
739
740
741
742
753743
754
755
756
757
758
744
759745
760
761
762
763
746
747
748
749
750
751
752
764753
765
766
767
768
769
770
754
755
771756
772
757
773758
774759
775760
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
#include "platform.h"
extern uint32_t devices_number;
const char *ati_compatible_0[]={ "@0,compatible","ATY,%s"};
const char *ati_compatible_1[]={ "@1,compatible","ATY,%s"};
const char *ati_device_type_0[]={ "@0,device_type","display"};
const char *ati_device_type_1[]={ "@1,device_type","display"};
const char *ati_device_type[]={ "device_type","ATY,%sParent"};
const char *ati_name_0[]={ "@0,name","ATY,%s"};
const char *ati_name_1[]={ "@1,name","ATY,%s"};
const char *ati_name[]={ "name","ATY,%sParent"};
const char *ati_efidisplay_0[]={ "@0,ATY,EFIDisplay","TMDSB"};
struct ati_data_key ati_connector_type_0={ 0x04, "@0,connector-type", {0x00, 0x04, 0x00, 0x00} };
struct ati_data_key ati_connector_type_1={ 0x04, "@1,connector-type",{0x04, 0x00, 0x00, 0x00}};
struct ati_data_key ati_display_con_fl_type_0={ 0x04, "@0,display-connect-flags",{0x00, 0x00, 0x04, 0x00}};
const char *ati_display_type_0[]={ "@0,display-type","LCD"};
const char *ati_display_type_1[]={ "@1,display-type","NONE"};
struct ati_data_key ati_aux_power_conn={ 0x04, "AAPL,aux-power-connected",{0x01, 0x00, 0x00, 0x00}};
struct ati_data_key ati_backlight_ctrl={ 0x04, "AAPL,backlight-control",{0x00, 0x00, 0x00, 0x00}};
//const char *ati_slot_name[]={ "AAPL,slot-name","Slot-1"};
struct ati_data_key ati_aapl01_coher={ 0x04, "AAPL01,Coherency",{0x01, 0x00, 0x00, 0x00}};
const char *ati_card_no[]={ "ATY,Card#","109-B77101-00"};
const char *ati_copyright[]={ "ATY,Copyright","Copyright AMD Inc. All Rights Reserved. 2005-2009"};
const char *ati_efi_compile_d[]={ "ATY,EFICompileDate","Jan 26 2009"};
struct ati_data_key ati_efi_disp_conf={ 0x08, "ATY,EFIDispConfig",{0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}};
struct ati_data_key ati_efi_drv_type={ 0x01, "ATY,EFIDriverType",{0x02}};
struct ati_data_key ati_efi_enbl_mode={ 0x01, "ATY,EFIEnabledMode",{0x01}};
struct ati_data_key ati_efi_init_stat={ 0x04, "ATY,EFIHWInitStatus",{0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_efi_orientation={ 0x02, "ATY,EFIOrientation",{0x02, 0x00}};
const char *ati_efi_version[]={ "ATY,EFIVersion","01.00.318"};
const char *ati_efi_versionB[]={ "ATY,EFIVersionB","113-SBSJ1G04-00R-02"};
const char *ati_efi_versionE[]={ "ATY,EFIVersionE","113-B7710A-318"};
struct ati_data_key ati_mclk={ 0x04, "ATY,MCLK",{0x70, 0x2e, 0x11, 0x00}};
struct ati_data_key ati_mem_rev_id={ 0x02, "ATY,MemRevisionID",{0x03, 0x00}};
struct ati_data_key ati_mem_vend_id={ 0x02, "ATY,MemVendorID",{0x02, 0x00}};
const char *ati_mrt[]={ "ATY,MRT"," "};
const char *ati_romno[]={ "ATY,Rom#","113-B7710C-176"};
struct ati_data_key ati_sclk={ 0x04, "ATY,SCLK",{0x28, 0xdb, 0x0b, 0x00}};
struct ati_data_key ati_vendor_id={ 0x02, "ATY,VendorID",{0x02, 0x10}};
struct ati_data_key ati_platform_info = { 0x80, "ATY,PlatformInfo", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_mvad={ 0x40, "MVAD",{0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03}};
struct ati_data_key ati_saved_config={ 0x100, "saved-config",{0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
const char *ati_compatible_0[]= { "@0,compatible", "ATY,%s" };
const char *ati_compatible_1[]= { "@1,compatible", "ATY,%s" };
const char *ati_device_type_0[]= { "@0,device_type", "display" };
const char *ati_device_type_1[]= { "@1,device_type", "display" };
const char *ati_device_type[]= { "device_type", "ATY,%sParent" };
const char *ati_name_0[]= { "@0,name", "ATY,%s" };
const char *ati_name_1[]= { "@1,name", "ATY,%s" };
const char *ati_name[]= { "name", "ATY,%sParent" };
const char *ati_efidisplay_0[]= { "@0,ATY,EFIDisplay", "TMDSB" };
struct ati_data_key ati_connector_type_0= { 0x04, "@0,connector-type", {0x00, 0x04, 0x00, 0x00} };
struct ati_data_key ati_connector_type_1= { 0x04, "@1,connector-type", {0x04, 0x00, 0x00, 0x00} };
struct ati_data_key ati_display_con_fl_type_0= { 0x04, "@0,display-connect-flags", {0x00, 0x00, 0x04, 0x00} };
const char *ati_display_type_0[]= { "@0,display-type", "LCD" };
const char *ati_display_type_1[]= { "@1,display-type", "NONE" };
struct ati_data_key ati_aux_power_conn= { 0x04, "AAPL,aux-power-connected", {0x01, 0x00, 0x00, 0x00} };
struct ati_data_key ati_backlight_ctrl= { 0x04, "AAPL,backlight-control", {0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_aapl01_coher= { 0x04, "AAPL01,Coherency", {0x01, 0x00, 0x00, 0x00} };
const char *ati_card_no[]= { "ATY,Card#", "109-B77101-00" };
const char *ati_copyright[]= { "ATY,Copyright", "Copyright AMD Inc. All Rights Reserved. 2005-2009" };
const char *ati_efi_compile_d[]= { "ATY,EFICompileDate", "Jan 26 2009" };
struct ati_data_key ati_efi_disp_conf= { 0x08, "ATY,EFIDispConfig", {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} };
struct ati_data_key ati_efi_drv_type= { 0x01, "ATY,EFIDriverType", {0x02} };
struct ati_data_key ati_efi_enbl_mode= { 0x01, "ATY,EFIEnabledMode", {0x01} };
struct ati_data_key ati_efi_init_stat= { 0x04, "ATY,EFIHWInitStatus", {0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_efi_orientation= { 0x02, "ATY,EFIOrientation", {0x02, 0x00} };
const char *ati_efi_version[]= { "ATY,EFIVersion", "01.00.318" };
const char *ati_efi_versionB[]= { "ATY,EFIVersionB", "113-SBSJ1G04-00R-02" };
const char *ati_efi_versionE[]= { "ATY,EFIVersionE", "113-B7710A-318" };
struct ati_data_key ati_mclk= { 0x04, "ATY,MCLK", {0x70, 0x2e, 0x11, 0x00} };
struct ati_data_key ati_mem_rev_id= { 0x02, "ATY,MemRevisionID", {0x03, 0x00} };
struct ati_data_key ati_mem_vend_id= { 0x02, "ATY,MemVendorID", {0x02, 0x00} };
const char *ati_mrt[]= { "ATY,MRT", " " };
const char *ati_romno[]= { "ATY,Rom#", "113-B7710C-176" };
struct ati_data_key ati_sclk= { 0x04, "ATY,SCLK", {0x28, 0xdb, 0x0b, 0x00} };
struct ati_data_key ati_vendor_id= { 0x02, "ATY,VendorID", {0x02, 0x10} };
struct ati_data_key ati_platform_info= { 0x80, "ATY,PlatformInfo", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_mvad= { 0x40, "MVAD", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03} };
struct ati_data_key ati_saved_config= { 0x100, "saved-config", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
///non 48xx keys
const char *ati_efidisplay_0_n4[]={ "@0,ATY,EFIDisplay","TMDSA"};
struct ati_data_key ati_connector_type_0_n4={ 0x04, "@0,connector-type", {0x04, 0x00, 0x00, 0x00} };
struct ati_data_key ati_connector_type_1_n4={ 0x04, "@1,connector-type",{0x00, 0x02, 0x00, 0x00}};
struct ati_data_key ati_aapl_emc_disp_list_n4={ 0x40, "AAPL,EMC-Display-List",{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1b, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1c, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_fb_offset_n4={ 0x08, "ATY,FrameBufferOffset",{0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}};
struct ati_data_key ati_hwgpio_n4={ 0x04, "ATY,HWGPIO",{0x23, 0xa8, 0x48, 0x00}};
struct ati_data_key ati_iospace_offset_n4={ 0x08, "ATY,IOSpaceOffset",{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00}};
struct ati_data_key ati_mclk_n4={ 0x04, "ATY,MCLK",{0x00, 0x35, 0x0c, 0x00}};
struct ati_data_key ati_sclk_n4={ 0x04, "ATY,SCLK",{0x60, 0xae, 0x0a, 0x00}};
struct ati_data_key ati_refclk_n4={ 0x04, "ATY,RefCLK",{0x8c, 0x0a, 0x00, 0x00}};
struct ati_data_key ati_regspace_offset_n4={ 0x08, "ATY,RegisterSpaceOffset",{0x00, 0x00, 0x00, 0x00, 0x90, 0xa2, 0x00, 0x00}};
struct ati_data_key ati_vram_memsize_0={ 0x08, "@0,VRAM,memsize",{0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_vram_memsize_1={ 0x08, "@1,VRAM,memsize",{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_aapl_blackscr_prefs_0_n4={ 0x04, "AAPL00,blackscreen-preferences",{0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_aapl_blackscr_prefs_1_n4={ 0x04, "AAPL01,blackscreen-preferences",{0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_swgpio_info_n4={ 0x04, "ATY,SWGPIO Info",{0x00, 0x48, 0xa8, 0x23}};
struct ati_data_key ati_efi_orientation_n4={ 0x01, "ATY,EFIOrientation",{0x08}};
struct ati_data_key ati_mvad_n4={ 0x100, "MVAD",{0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
struct ati_data_key ati_saved_config_n4={ 0x100, "saved-config",{0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
//const char *ati_slot_name_n4[]={ "AAPL,slot-name","Slot-2"};
const char *ati_efidisplay_0_n4[]= { "@0,ATY,EFIDisplay", "TMDSA" };
struct ati_data_key ati_connector_type_0_n4= { 0x04, "@0,connector-type", {0x04, 0x00, 0x00, 0x00} };
struct ati_data_key ati_connector_type_1_n4= { 0x04, "@1,connector-type", {0x00, 0x02, 0x00, 0x00} };
struct ati_data_key ati_aapl_emc_disp_list_n4= { 0x40, "AAPL,EMC-Display-List", {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1b, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1c, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_fb_offset_n4= { 0x08, "ATY,FrameBufferOffset", {0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00} };
struct ati_data_key ati_hwgpio_n4= { 0x04, "ATY,HWGPIO", {0x23, 0xa8, 0x48, 0x00} };
struct ati_data_key ati_iospace_offset_n4= { 0x08, "ATY,IOSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00} };
struct ati_data_key ati_mclk_n4= { 0x04, "ATY,MCLK", {0x00, 0x35, 0x0c, 0x00} };
struct ati_data_key ati_sclk_n4= { 0x04, "ATY,SCLK", {0x60, 0xae, 0x0a, 0x00} };
struct ati_data_key ati_refclk_n4= { 0x04, "ATY,RefCLK", {0x8c, 0x0a, 0x00, 0x00} };
struct ati_data_key ati_regspace_offset_n4= { 0x08, "ATY,RegisterSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x90, 0xa2, 0x00, 0x00} };
struct ati_data_key ati_vram_memsize_0= { 0x08, "@0,VRAM,memsize", {0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_vram_memsize_1= { 0x08, "@1,VRAM,memsize", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_aapl_blackscr_prefs_0_n4= { 0x04, "AAPL00,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_aapl_blackscr_prefs_1_n4= { 0x04, "AAPL01,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_swgpio_info_n4= { 0x04, "ATY,SWGPIO Info", {0x00, 0x48, 0xa8, 0x23} };
struct ati_data_key ati_efi_orientation_n4= { 0x01, "ATY,EFIOrientation", {0x08} };
struct ati_data_key ati_mvad_n4= { 0x100, "MVAD", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct ati_data_key ati_saved_config_n4= { 0x100, "saved-config", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct pcir_s {
uint32_t signature;
uint16_t vid;
// Known cards as of 2008/08/26
static struct ati_chipsets_t ATIKnownChipsets[] = {
{ 0x00000000, "Unknown" },
{ 0x10029589, "ATI Radeon 2600 Series"} ,
{ 0x10029588, "ATI Radeon 2600 Series"} ,
{ 0x100294C3, "ATI Radeon 2400 Series"} ,
{ 0x100294C4, "ATI Radeon 2400 Series"} ,
{ 0x100294C6, "ATI Radeon 2400 Series"} ,
{ 0x10029400, "ATI Radeon 2900 Series"} ,
{ 0x10029405, "ATI Radeon 2900GT Series"} ,
{ 0x10029581, "ATI Radeon 2600 Series"} ,
{ 0x10029583, "ATI Radeon 2600 Series"} ,
{ 0x10029586, "ATI Radeon 2600 Series"} ,
{ 0x10029587, "ATI Radeon 2600 Series"} ,
{ 0x100294C9, "ATI Radeon 2400 Series"} ,
{ 0x10029501, "ATI Radeon 3800 Series"} ,
{ 0x10029505, "ATI Radeon 3800 Series"} ,
{ 0x10029515, "ATI Radeon 3800 Series"} ,
{ 0x10029507, "ATI Radeon 3800 Series"} ,
{ 0x10029500, "ATI Radeon 3800 Series"} ,
{ 0x1002950F, "ATI Radeon 3800X2 Series"} ,
{ 0x100295C5, "ATI Radeon 3400 Series"} ,
{ 0x100295C7, "ATI Radeon 3400 Series"} ,
{ 0x100295C0, "ATI Radeon 3400 Series"} ,
{ 0x10029596, "ATI Radeon 3600 Series"} ,
{ 0x10029590, "ATI Radeon 3600 Series"} ,
{ 0x10029599, "ATI Radeon 3600 Series"} ,
{ 0x10029597, "ATI Radeon 3600 Series"} ,
{ 0x10029598, "ATI Radeon 3600 Series"} ,
{ 0x10029442, "ATI Radeon 4850 Series"} ,
{ 0x10029440, "ATI Radeon 4870 Series"} ,
{ 0x1002944C, "ATI Radeon 4830 Series"} ,
{ 0x10029460, "ATI Radeon 4890 Series"} ,
{ 0x10029462, "ATI Radeon 4890 Series"} ,
{ 0x10029441, "ATI Radeon 4870X2 Series"} ,
{ 0x10029443, "ATI Radeon 4850X2 Series"} ,
{ 0x10029444, "ATI Radeon 4800 Series"} ,
{ 0x10029446, "ATI Radeon 4800 Series"} ,
{ 0x1002944E, "ATI Radeon 4730 Series"} ,
{ 0x10029450, "ATI Radeon 4800 Series"} ,
{ 0x10029452, "ATI Radeon 4800 Series"} ,
{ 0x10029456, "ATI Radeon 4800 Series"} ,
{ 0x1002944A, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002945A, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002945B, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002944B, "ATI Radeon 4800 Mobility Series"} ,
{ 0x10029490, "ATI Radeon 4600 Series"} ,
{ 0x10029498, "ATI Radeon 4600 Series"} ,
{ 0x1002949E, "ATI Radeon 4600 Series"} ,
{ 0x10029480, "ATI Radeon 4600 Series"} ,
{ 0x10029488, "ATI Radeon 4600 Series"} ,
{ 0x10029540, "ATI Radeon 4500 Series"} ,
{ 0x10029541, "ATI Radeon 4500 Series"} ,
{ 0x1002954E, "ATI Radeon 4500 Series"} ,
{ 0x10029552, "ATI Radeon 4300 Mobility Series"} ,
{ 0x10029553, "ATI Radeon 4500 Mobility Series"} ,
{ 0x1002954F, "ATI Radeon 4300 Series"},
{ 0x00000000, "Unknown" } ,
{ 0x10029589, "ATI Radeon 2600 Series"} ,
{ 0x10029588, "ATI Radeon 2600 Series"} ,
{ 0x100294C3, "ATI Radeon 2400 Series"} ,
{ 0x100294C4, "ATI Radeon 2400 Series"} ,
{ 0x100294C6, "ATI Radeon 2400 Series"} ,
{ 0x10029400, "ATI Radeon 2900 Series"} ,
{ 0x10029405, "ATI Radeon 2900GT Series"} ,
{ 0x10029581, "ATI Radeon 2600 Series"} ,
{ 0x10029583, "ATI Radeon 2600 Series"} ,
{ 0x10029586, "ATI Radeon 2600 Series"} ,
{ 0x10029587, "ATI Radeon 2600 Series"} ,
{ 0x100294C9, "ATI Radeon 2400 Series"} ,
{ 0x10029501, "ATI Radeon 3800 Series"} ,
{ 0x10029505, "ATI Radeon 3800 Series"} ,
{ 0x10029515, "ATI Radeon 3800 Series"} ,
{ 0x10029507, "ATI Radeon 3800 Series"} ,
{ 0x10029500, "ATI Radeon 3800 Series"} ,
{ 0x1002950F, "ATI Radeon 3800X2 Series"} ,
{ 0x100295C5, "ATI Radeon 3400 Series"} ,
{ 0x100295C7, "ATI Radeon 3400 Series"} ,
{ 0x100295C0, "ATI Radeon 3400 Series"} ,
{ 0x10029596, "ATI Radeon 3600 Series"} ,
{ 0x10029590, "ATI Radeon 3600 Series"} ,
{ 0x10029599, "ATI Radeon 3600 Series"} ,
{ 0x10029597, "ATI Radeon 3600 Series"} ,
{ 0x10029598, "ATI Radeon 3600 Series"} ,
{ 0x10029442, "ATI Radeon 4850 Series"} ,
{ 0x10029440, "ATI Radeon 4870 Series"} ,
{ 0x1002944C, "ATI Radeon 4830 Series"} ,
{ 0x10029460, "ATI Radeon 4890 Series"} ,
{ 0x10029462, "ATI Radeon 4890 Series"} ,
{ 0x10029441, "ATI Radeon 4870X2 Series"} ,
{ 0x10029443, "ATI Radeon 4850X2 Series"} ,
{ 0x10029444, "ATI Radeon 4800 Series"} ,
{ 0x10029446, "ATI Radeon 4800 Series"} ,
{ 0x1002944E, "ATI Radeon 4730 Series"} ,
{ 0x10029450, "ATI Radeon 4800 Series"} ,
{ 0x10029452, "ATI Radeon 4800 Series"} ,
{ 0x10029456, "ATI Radeon 4800 Series"} ,
{ 0x1002944A, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002945A, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002945B, "ATI Radeon 4800 Mobility Series"} ,
{ 0x1002944B, "ATI Radeon 4800 Mobility Series"} ,
{ 0x10029490, "ATI Radeon 4600 Series"} ,
{ 0x10029498, "ATI Radeon 4600 Series"} ,
{ 0x1002949E, "ATI Radeon 4600 Series"} ,
{ 0x10029480, "ATI Radeon 4600 Series"} ,
{ 0x10029488, "ATI Radeon 4600 Series"} ,
{ 0x10029540, "ATI Radeon 4500 Series"} ,
{ 0x10029541, "ATI Radeon 4500 Series"} ,
{ 0x1002954E, "ATI Radeon 4500 Series"} ,
{ 0x10029552, "ATI Radeon 4300 Mobility Series"} ,
{ 0x10029553, "ATI Radeon 4500 Mobility Series"} ,
{ 0x1002954F, "ATI Radeon 4300 Series"}
};
static struct ati_chipsets_t ATIKnownFramebuffers[] = {
{ 0x00000000, "Megalodon" },
{ 0x10029589, "Lamna"} ,
{ 0x10029588, "Lamna"} ,
{ 0x100294C3, "Iago"} ,
{ 0x100294C4, "Iago"} ,
{ 0x100294C6, "Iago"} ,
{ 0x10029400, "Franklin"} ,
{ 0x10029405, "Franklin"} ,
{ 0x10029581, "Hypoprion"} ,
{ 0x10029583, "Hypoprion"} ,
{ 0x10029586, "Hypoprion"} ,
{ 0x10029587, "Hypoprion"} ,
{ 0x100294C9, "Iago"} ,
{ 0x10029501, "Megalodon"} ,
{ 0x10029505, "Megalodon"} ,
{ 0x10029515, "Megalodon"} ,
{ 0x10029507, "Megalodon"} ,
{ 0x10029500, "Megalodon"} ,
{ 0x1002950F, "Triakis"} ,
{ 0x100295C5, "Iago"} ,
{ 0x100295C7, "Iago"} ,
{ 0x100295C0, "Iago"} ,
{ 0x10029596, "Megalodon"} ,
{ 0x10029590, "Megalodon"} ,
{ 0x10029599, "Megalodon"} ,
{ 0x10029597, "Megalodon"} ,
{ 0x10029598, "Megalodon"} ,
{ 0x10029442, "Motmot"} ,
{ 0x10029440, "Motmot"} ,
{ 0x1002944C, "Motmot"} ,
{ 0x10029460, "Motmot"} ,
{ 0x10029462, "Motmot"} ,
{ 0x10029441, "Motmot"} ,
{ 0x10029443, "Motmot"} ,
{ 0x10029444, "Motmot"} ,
{ 0x10029446, "Motmot"} ,
{ 0x1002944E, "Motmot"} ,
{ 0x10029450, "Motmot"} ,
{ 0x10029452, "Motmot"} ,
{ 0x10029456, "Motmot"} ,
{ 0x1002944A, "Motmot"} ,
{ 0x1002945A, "Motmot"} ,
{ 0x1002945B, "Motmot"} ,
{ 0x1002944B, "Motmot"} ,
{ 0x10029490, "Motmot"} ,
{ 0x10029498, "Motmot"} ,
{ 0x1002949E, "Motmot"} ,
{ 0x10029480, "Motmot"} ,
{ 0x10029488, "Motmot"} ,
{ 0x10029540, "Motmot"} ,
{ 0x10029541, "Motmot"} ,
{ 0x1002954E, "Motmot"} ,
{ 0x10029552, "Motmot"} ,
{ 0x10029553, "Motmot"} ,
{ 0x1002954F, "Motmot"} ,
{ 0x00000000, "Megalodon" },
{ 0x10029589, "Lamna"} ,
{ 0x10029588, "Lamna"} ,
{ 0x100294C3, "Iago"} ,
{ 0x100294C4, "Iago"} ,
{ 0x100294C6, "Iago"} ,
{ 0x10029400, "Franklin"} ,
{ 0x10029405, "Franklin"} ,
{ 0x10029581, "Hypoprion"} ,
{ 0x10029583, "Hypoprion"} ,
{ 0x10029586, "Hypoprion"} ,
{ 0x10029587, "Hypoprion"} ,
{ 0x100294C9, "Iago"} ,
{ 0x10029501, "Megalodon"} ,
{ 0x10029505, "Megalodon"} ,
{ 0x10029515, "Megalodon"} ,
{ 0x10029507, "Megalodon"} ,
{ 0x10029500, "Megalodon"} ,
{ 0x1002950F, "Triakis"} ,
{ 0x100295C5, "Iago"} ,
{ 0x100295C7, "Iago"} ,
{ 0x100295C0, "Iago"} ,
{ 0x10029596, "Megalodon"} ,
{ 0x10029590, "Megalodon"} ,
{ 0x10029599, "Megalodon"} ,
{ 0x10029597, "Megalodon"} ,
{ 0x10029598, "Megalodon"} ,
{ 0x10029442, "Motmot"} ,
{ 0x10029440, "Motmot"} ,
{ 0x1002944C, "Motmot"} ,
{ 0x10029460, "Motmot"} ,
{ 0x10029462, "Motmot"} ,
{ 0x10029441, "Motmot"} ,
{ 0x10029443, "Motmot"} ,
{ 0x10029444, "Motmot"} ,
{ 0x10029446, "Motmot"} ,
{ 0x1002944E, "Motmot"} ,
{ 0x10029450, "Motmot"} ,
{ 0x10029452, "Motmot"} ,
{ 0x10029456, "Motmot"} ,
{ 0x1002944A, "Motmot"} ,
{ 0x1002945A, "Motmot"} ,
{ 0x1002945B, "Motmot"} ,
{ 0x1002944B, "Motmot"} ,
{ 0x10029490, "Motmot"} ,
{ 0x10029498, "Motmot"} ,
{ 0x1002949E, "Motmot"} ,
{ 0x10029480, "Motmot"} ,
{ 0x10029488, "Motmot"} ,
{ 0x10029540, "Motmot"} ,
{ 0x10029541, "Motmot"} ,
{ 0x1002954E, "Motmot"} ,
{ 0x10029552, "Motmot"} ,
{ 0x10029553, "Motmot"} ,
{ 0x1002954F, "Motmot"}
};
unsigned int accessROM(pci_dt_t *ati_dev, unsigned int mode)
static uint32_t accessROM(pci_dt_t *ati_dev, unsigned int mode)
{
uint32_tbar[7];
volatile uint8_t *regs;
uint32_tbar[7];
volatile uint32_t*regs;
bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
regs = (uint8_t *) (bar[2] & ~0x0f);
regs = (uint32_t *) (bar[2] & ~0x0f);
if(mode)
{
if(mode != 1) return 0xe00002c7;
REG32W(0x179c, 0x00080000);
REG32W(0x1798, 0x00080721);
REG32W(0x17a0, 0x00080621);
REG32W(0x1600, 0x14030300);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
REG32W(0x17a0, 0x21);
REG32W(0x1798, 0x21);
REG32W(0x1798, 0x21);
} else {
REG32W(0x1600, 0x14030302);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00080000);
REG32W(0x17a0, 0x00080621);
REG32W(0x1798, 0x00080721);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
REG32W(0x1604, 0x0400e9fc);
REG32W(0x161c, 0x00);
REG32W(0x1620, 0x9f);
REG32W(0x1618, 0x00040004);
REG32W(0x161c, 0x00);
REG32W(0x1604, 0xe9fc);
REG32W(0x179c, 0x00080000);
REG32W(0x1798, 0x00080721);
REG32W(0x17a0, 0x00080621);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
if (mode) {
if (mode != 1) {
return 0xe00002c7;
}
REG32W(0x179c, 0x00080000);
REG32W(0x1798, 0x00080721);
REG32W(0x17a0, 0x00080621);
REG32W(0x1600, 0x14030300);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
REG32W(0x17a0, 0x21);
REG32W(0x1798, 0x21);
REG32W(0x1798, 0x21);
} else {
REG32W(0x1600, 0x14030302);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00080000);
REG32W(0x17a0, 0x00080621);
REG32W(0x1798, 0x00080721);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
REG32W(0x1604, 0x0400e9fc);
REG32W(0x161c, 0x00);
REG32W(0x1620, 0x9f);
REG32W(0x1618, 0x00040004);
REG32W(0x161c, 0x00);
REG32W(0x1604, 0xe9fc);
REG32W(0x179c, 0x00080000);
REG32W(0x1798, 0x00080721);
REG32W(0x17a0, 0x00080621);
REG32W(0x1798, 0x21);
REG32W(0x17a0, 0x21);
REG32W(0x179c, 0x00);
}
return 0;
}
return 0;
}
unsigned char * readAtomBIOS(pci_dt_t *ati_dev)
static uint8_t *readAtomBIOS(pci_dt_t *ati_dev)
{
uint32_tbar[7];
unsigned int * BIOSBase = NULL;
unsigned int counter;
volatile uint8_t *regs;
uint32_tbar[7];
uint32_t*BIOSBase;
uint32_tcounter;
volatile uint32_t*regs;
bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
regs = (uint8_t *) (bar[2] & ~0x0f);
regs = (volatile uint32_t *) (bar[2] & ~0x0f);
accessROM(ati_dev, 0);
REG32W(0xa8, 0);
REG32R(0xac);
REG32W(0xa8, 0);
REG32R(0xac);
BIOSBase = malloc(0x10000);
if(BIOSBase)
{
REG32W(0xa8, 0);
BIOSBase[0] = REG32R(0xac);
counter = 4;
do
{
REG32W(0xa8, counter);
BIOSBase[counter/4] = REG32R(0xac);
counter +=4;
}
while(counter != 0x10000);
}
REG32W(0xa8, 0);
BIOSBase[0] = REG32R(0xac);
counter = 4;
do {
REG32W(0xa8, counter);
BIOSBase[counter/4] = REG32R(0xac);
counter +=4;
} while (counter != 0x10000);
accessROM((pci_dt_t *)regs, 1);
if ((* (UInt16 *)BIOSBase) != 0xAA55) {
printf("Wrong BIOS signature: %04x\n", (* (UInt16 *)BIOSBase));
if (*(uint16_t *)BIOSBase != 0xAA55) {
printf("Wrong BIOS signature: %04x\n", *(uint16_t *)BIOSBase);
return 0;
}
return (unsigned char *)BIOSBase;
return (uint8_t *)BIOSBase;
}
#define R5XX_CONFIG_MEMSIZE 0x00F8
#define R6XX_CONFIG_MEMSIZE 0x5428
#define R5XX_CONFIG_MEMSIZE0x00F8
#define R6XX_CONFIG_MEMSIZE0x5428
uint32_t getvramsizekb(pci_dt_t *ati_dev)
{
uint32_tbar[7];
volatile uint8_t *regs;
uint32_tRamSize = 0;
uint32_tbar[7];
uint32_tsize;
volatile uint32_t*regs;
bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
regs = (uint8_t *) (bar[2] & ~0x0f);
if (ati_dev->device_id < 0x9400)
RamSize = (REG32R(R5XX_CONFIG_MEMSIZE)) >> 10;
else
RamSize = (REG32R(R6XX_CONFIG_MEMSIZE)) >> 10;
return RamSize;
regs = (uint32_t *) (bar[2] & ~0x0f);
if (ati_dev->device_id < 0x9400) {
size = (REG32R(R5XX_CONFIG_MEMSIZE)) >> 10;
} else {
size = (REG32R(R6XX_CONFIG_MEMSIZE)) >> 10;
}
return size;
}
#define AVIVO_D1CRTC_CONTROL 0x6080
#define AVIVO_CRTC_EN (1<<0)
#define AVIVO_D2CRTC_CONTROL 0x6880
#define AVIVO_D1CRTC_CONTROL0x6080
#define AVIVO_CRTC_EN(1<<0)
#define AVIVO_D2CRTC_CONTROL0x6880
bool
radeon_card_posted(pci_dt_t *ati_dev)
static bool radeon_card_posted(pci_dt_t *ati_dev)
{
// if devid matches biosimage(from legacy) devid - posted card, fails with X2/crossfire cards.
/*char *biosimage = 0xC0000;
{
if (rom_pci_header->device == ati_dev->device_id)
{
return TRUE;
return true;
printf("Card was POSTed\n");
}
}
}
return FALSE;
return false;
printf("Card was not POSTed\n");
*/
//fails yet
uint32_tbar[7];
volatile uint8_t *regs;
//fails yet
uint32_tbar[7];
uint32_tval;
volatile uint32_t*regs;
bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
regs = (uint8_t *) (bar[2] & ~0x0f);
uint32_t val;
val = REG32R(AVIVO_D1CRTC_CONTROL) | REG32R(AVIVO_D2CRTC_CONTROL);
if (val & AVIVO_CRTC_EN)
return TRUE;
bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18);
regs = (uint32_t *) (bar[2] & ~0x0f);
return FALSE;
val = REG32R(AVIVO_D1CRTC_CONTROL) | REG32R(AVIVO_D2CRTC_CONTROL);
if (val & AVIVO_CRTC_EN) {
return true;
} else {
return false;
}
}
uint32_t load_ati_bios_file(char *filename, char *buffer)
static uint32_t load_ati_bios_file(const char *filename, uint8_t *buf, int bufsize)
{
intfd, size;
chardirspec[128];
intfd;
intsize;
// Check Extra on booting partition
sprintf(dirspec, "/Extra/%s", filename);
fd = open(dirspec, 0);
if (fd < 0)
{
// Fall back to booter partition
sprintf(dirspec, "bt(0,0)/Extra/%s", filename);
fd=open (dirspec, 0);
if (fd < 0)
return 0;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
return 0;
}
size = read(fd, buffer, file_size (fd));
close (fd);
return size;
size = file_size(fd);
if (size > bufsize) {
printf("Filesize of %s is bigger than expected! Truncating to 0x%x Bytes!\n", filename, bufsize);
size = bufsize;
}
size = read(fd, (char *)buf, size);
close(fd);
return size;
}
char *get_ati_model(uint32_t id) {
int i=0;
for(i = 0; i < (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) {
if(ATIKnownChipsets[i].device == id)
static char *get_ati_model(uint32_t id)
{
inti;
for (i=0; i< (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) {
if (ATIKnownChipsets[i].device == id) {
return ATIKnownChipsets[i].name;
}
}
return ATIKnownChipsets[0].name;
}
char *get_ati_fb(uint32_t id) {
int i=0;
for(i = 0; i < (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) {
if(ATIKnownFramebuffers[i].device == id)
static char *get_ati_fb(uint32_t id)
{
inti;
for (i=0; i< (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) {
if (ATIKnownFramebuffers[i].device == id) {
return ATIKnownFramebuffers[i].name;
}
}
return ATIKnownFramebuffers[0].name;
}
int devprop_add_iopciconfigspace(struct DevPropDevice *device, pci_dt_t *ati_dev)
static int devprop_add_iopciconfigspace(struct DevPropDevice *device, pci_dt_t *ati_dev)
{
if(!device)
inti;
uint8_t*config_space;
if (!device || !ati_dev) {
return 0;
if(!ati_dev)
return 0;
}
printf("dumping pci config space, 256 bytes\n");
int i;
uint8_t *config_space;
config_space = malloc(256);
for(i=0; i<=255; i++)
for (i=0; i<=255; i++) {
config_space[i] = pci_config_read8( ati_dev->dev.addr, i);
}
devprop_add_value(device, "ATY,PCIConfigSpace", config_space, 256);
free(config_space);
free (config_space);
return 1;
}
int devprop_add_ati_template_4xxx(struct DevPropDevice *device)
static int devprop_add_ati_template_4xxx(struct DevPropDevice *device)
{
if(!device)
return 0;
return 1;
}
int devprop_add_ati_template(struct DevPropDevice *device)
static int devprop_add_ati_template(struct DevPropDevice *device)
{
if(!device)
return 0;
bool setup_ati_devprop(pci_dt_t *ati_dev)
{
//intlen;
char*devicepath;
//volatile uint8_t *regs;
//uint32_tbar[7];
char*model;
char*framebuffer;
chartmpString[64];
char*rom=0;
uint32_trom_size=0;
char*biosimage = 0;
uint32_tbiosimage_size = 0;
uint8_ttoFree = 0;
char romfilename[32];
const char *val;
int len1;
uint32_tvram_size=0;
uint8_tcmd=0;
struct DevPropDevice*device;
char*devicepath;
char*model;
char*framebuffer;
chartmp[64];
uint8_t*rom = NULL;
uint32_trom_size = 0;
uint8_t*bios;
uint32_tbios_size;
uint32_tvram_size;
uint32_tboot_display;
uint8_tcmd;
booldoit;
booltoFree;
devicepath = get_pci_dev_path(ati_dev);
cmd = pci_config_read8( ati_dev->dev.addr, 4);
cmd = pci_config_read8(ati_dev->dev.addr, 4);
verbose("old pci command - %x\n", cmd);
if( cmd == 0) {
pci_config_write8(ati_dev->dev.addr, 4, 6);
cmd = pci_config_read8( ati_dev->dev.addr, 4);
verbose("new pci command - %x\n", cmd);
};
if (cmd == 0) {
pci_config_write8(ati_dev->dev.addr, 4, 6);
cmd = pci_config_read8(ati_dev->dev.addr, 4);
verbose("new pci command - %x\n", cmd);
}
model = get_ati_model((ati_dev->vendor_id << 16) | ati_dev->device_id);
framebuffer = get_ati_fb((ati_dev->vendor_id << 16) | ati_dev->device_id);
if (!string)
if (!string) {
string = devprop_create_string();
struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice));
}
device = devprop_add_device(string, devicepath);
if(!device)
{
if (!device) {
printf("Failed initializing dev-prop string dev-entry, press any key...\n");
getc();
return false;
}
/* FIXME: for primary graphics card only */
uint32_t boot_display = 0x00000001;
if(radeon_card_posted(ati_dev)) boot_display=0x01;
else boot_display=0x00;
if (radeon_card_posted(ati_dev)) {
boot_display = 1;
} else {
boot_display = 0;
}
verbose("boot display - %x\n", boot_display);
devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
if(framebuffer[0] == 'M' && framebuffer[1] == 'o' && framebuffer[2] == 't') //faster than strcmp ;)
if (framebuffer[0] == 'M' && framebuffer[1] == 'o' && framebuffer[2] == 't') {
devprop_add_ati_template_4xxx(device);
else
{
} else {
devprop_add_ati_template(device);
vram_size = getvramsizekb(ati_dev) * 1024;
if ((vram_size > 0x80000000) || (vram_size == 0)) vram_size = 0x10000000; //vram reported wrong, defaulting to 256 mb
if ((vram_size > 0x80000000) || (vram_size == 0)) {
vram_size = 0x10000000;//vram reported wrong, defaulting to 256 mb
}
devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&vram_size, 4);
ati_vram_memsize_0.data[6] = (vram_size >> 16) & 0xFF; //4,5 are 0x00 anyway
ati_vram_memsize_0.data[7] = (vram_size >> 24) & 0xFF;
}
devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
devprop_add_value(device, "ATY,DeviceID", (uint8_t*)&ati_dev->device_id, 2);
//fb setup
char tmp[10];
//fb setup
sprintf(tmp, "Slot-%x",devices_number);
devprop_add_value(device, "AAPL,slot-name", (uint8_t*)tmp, strlen(tmp));
devprop_add_value(device, "AAPL,slot-name", (uint8_t*)tmp, strlen(tmp) + 1);
devices_number++;
sprintf(tmpString, ati_compatible_0[1], framebuffer);
devprop_add_value(device, (char *) ati_compatible_0[0], (uint8_t *)tmpString, strlen(tmpString)+1);
sprintf(tmpString, ati_compatible_1[1], framebuffer);
devprop_add_value(device, (char *) ati_compatible_1[0], (uint8_t *)tmpString, strlen(tmpString)+1);
sprintf(tmpString, ati_device_type[1], framebuffer);
devprop_add_value(device, (char *) ati_device_type[0], (uint8_t *)tmpString, strlen(tmpString)+1);
sprintf(tmpString, ati_name[1], framebuffer);
devprop_add_value(device, (char *) ati_name[0], (uint8_t *)tmpString, strlen(tmpString)+1);
sprintf(tmpString, ati_name_0[1], framebuffer);
devprop_add_value(device, (char *) ati_name_0[0], (uint8_t *)tmpString, strlen(tmpString)+1);
sprintf(tmpString, ati_name_1[1], framebuffer);
devprop_add_value(device, (char *) ati_name_1[0], (uint8_t *)tmpString, strlen(tmpString)+1);
//code for loading bios from file, in form - rom_devid_vendif.rom
if (getValueForKey("-useatirom", &val, &len1, &bootInfo->bootConfig))
{
sprintf(romfilename, "ati_%04x_%04x.rom", (uint16_t)ati_dev->device_id, (uint16_t)ati_dev->vendor_id);
verbose("looking for file /Extra/%s\n", romfilename);
sprintf(tmp, ati_compatible_0[1], framebuffer);
devprop_add_value(device, (char *) ati_compatible_0[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, ati_compatible_1[1], framebuffer);
devprop_add_value(device, (char *) ati_compatible_1[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, ati_device_type[1], framebuffer);
devprop_add_value(device, (char *) ati_device_type[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, ati_name[1], framebuffer);
devprop_add_value(device, (char *) ati_name[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, ati_name_0[1], framebuffer);
devprop_add_value(device, (char *) ati_name_0[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, ati_name_1[1], framebuffer);
devprop_add_value(device, (char *) ati_name_1[0], (uint8_t *)tmp, strlen(tmp) + 1);
sprintf(tmp, "/Extra/%04x_%04x.rom", (uint16_t)ati_dev->vendor_id, (uint16_t)ati_dev->device_id);
if (getBoolForKey(kUseAtiROM, &doit, &bootInfo->bootConfig) && doit) {
verbose("looking for ati video bios file %s\n", tmp);
rom = malloc(0x20000);
rom_size = load_ati_bios_file((char *)romfilename, (char *)rom);
if(rom_size > 0x10000) rom_size = 0x10000; //we dont need rest anyway;
if(rom_size == 0) printf("file not found\n");
};
{
if(rom_size == 0)
{
if(boot_display) // no custom rom
biosimage = 0; //try to dump from legacy space, otherwise can result in 100% fan speed
else
biosimage = (char *)readAtomBIOS(ati_dev); //readAtomBios result in bug on some cards (100% fan speed and black screen),
//not using it for posted card, rading from legacy space instead
rom_size = load_ati_bios_file(tmp, rom, 0x20000);
if (rom_size > 0x10000) {
rom_size = 0x10000; //we dont need rest anyway;
}
if (rom_size == 0) {
printf("ATI ROM File '%s' not found\n", tmp);
}
}
if (rom_size == 0) {
if (boot_display) {// no custom rom
bios = NULL;// try to dump from legacy space, otherwise can result in 100% fan speed
} else {
biosimage = rom; //going custom rom way
verbose("Using rom %s\n", romfilename);
// readAtomBios result in bug on some cards (100% fan speed and black screen),
// not using it for posted card, rading from legacy space instead
bios = readAtomBIOS(ati_dev);
}
if(biosimage == 0)
{
biosimage = (char *)0xC0000;
toFree = 0;
verbose("Not going to use bios image file\n");
} else toFree = 1;
} else {
bios = rom;//going custom rom way
verbose("Using rom %s\n", tmp);
}
if (bios == NULL) {
bios = (uint8_t *)0x000C0000;
toFree = false;
verbose("Not going to use bios image file\n");
} else {
toFree = true;
}
if ((uint8_t)biosimage[0] == 0x55 && (uint8_t)biosimage[1] == 0xaa)
{
printf("Found bios image\n");
biosimage_size = (uint8_t)biosimage[2] * 512;
struct pci_rom_pci_header_t *rom_pci_header;
rom_pci_header = (struct pci_rom_pci_header_t*)(biosimage + (uint8_t)biosimage[24] + (uint8_t)biosimage[25]*256);
if (rom_pci_header->signature == 0x52494350)
{
if (rom_pci_header->device != ati_dev->device_id)
{
verbose("Bios image (%x) doesnt match card (%x), ignoring\n", rom_pci_header->device, ati_dev->device_id);
if (bios[0] == 0x55 && bios[1] == 0xaa) {
printf("Found bios image\n");
bios_size = bios[2] * 512;
struct pci_rom_pci_header_t *rom_pci_header;
rom_pci_header = (struct pci_rom_pci_header_t*)(bios + bios[24] + bios[25]*256);
if (rom_pci_header->signature == 0x52494350) {
if (rom_pci_header->device != ati_dev->device_id) {
verbose("Bios image (%x) doesnt match card (%x), ignoring\n", rom_pci_header->device, ati_dev->device_id);
} else {
if (toFree) {
verbose("Adding binimage to card %x from mmio space with size %x\n", ati_dev->device_id, bios_size);
} else {
if(toFree)
verbose("Adding binimage to card %x from mmio space with size %x\n", ati_dev->device_id, biosimage_size);
else
verbose("Adding binimage to card %x from legacy space with size %x\n", ati_dev->device_id, biosimage_size);
devprop_add_value(device, "ATY,bin_image", (uint8_t*) biosimage, biosimage_size);
verbose("Adding binimage to card %x from legacy space with size %x\n", ati_dev->device_id, bios_size);
}
} else verbose("Wrong pci header signature %x\n", rom_pci_header->signature);
} else verbose("Bios image not found at %x, content %x %x\n", biosimage, (uint8_t)biosimage[0], (uint8_t)biosimage[1]);
if(toFree) free(biosimage);
devprop_add_value(device, "ATY,bin_image", bios, bios_size);
}
} else {
verbose("Wrong pci header signature %x\n", rom_pci_header->signature);
}
} else {
verbose("Bios image not found at %x, content %x %x\n", bios, bios[0], bios[1]);
}
stringdata = malloc(sizeof(uint8_t) * string->length);
if(!stringdata)
{
printf("no stringdata press a key...\n");
getc();
return false;
if (toFree) {
free(bios);
}
stringdata = malloc(sizeof(uint8_t) * string->length);
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
stringlength = string->length;
trunk/i386/libsaio/sys.c
6161
6262
6363
64
6465
66
6567
6668
6769
......
110112
111113
112114
113
114
115
116
115117
116118
117119
......
367369
368370
369371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
370390
371391
372392
......
392412
393413
394414
395
396
397
398
399
400
401
402
403
415
404416
405417
406418
......
418430
419431
420432
421
433
422434
423
424
425
426
435
436
437
427438
428
439
440
441
429442
430
431
432
443
444
445
433446
434
447
448
435449
436
437
438
450
451
452
453
454
455
456
457
439458
440
459
460
461
462
463
464
465
466
467
441468
442
469
470
471
472
443473
444
474
475
476
477
478
479
445480
446
447
481
482
483
484
485
486
487
488
489
448490
449
491
492
493
450494
451
452
453
454
455
456
495
496
497
457498
458
459
460
461
462
463
464
465
466
467
468
469
470
471
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
472534
473535
474536
......
700762
701763
702764
703
704
765
766
705767
706768
707
769
708770
709771
710772
......
719781
720782
721783
722
784
723785
724786
725787
......
741803
742804
743805
744
806
745807
746808
747809
......
898960
899961
900962
901
963
902964
903965
904966
#include <AvailabilityMacros.h>
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "ramdisk.h"
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
# include <Kernel/libkern/crypto/md5.h>
#else
BVRef gBootVolume;
// zef - ramdisk variables
extern BVRef gRAMDiskVolume;
extern BOOL gRAMDiskBTAliased;
//extern BVRef gRAMDiskVolume;
//extern bool gRAMDiskBTAliased;
//static BVRef getBootVolumeRef( const char * path, const char ** outPath );
static BVRef newBootVolumeRef( int biosdev, int partno );
}
//==========================================================================
// GetFreeFD()
static int GetFreeFd(void)
{
intfd;
// Locate a free descriptor slot.
for (fd = 0; fd < NFILES; fd++) {
if (iob[fd].i_flgs == 0) {
return fd;
}
}
stop("Out of file descriptors");
// not reached
return -1;
}
//==========================================================================
// iob_from_fdesc()
//
// Return a pointer to an allocated 'iob' based on the file descriptor
int fdesc;
struct iob * io;
// Locate a free descriptor slot.
for (fdesc = 0; fdesc < NFILES; fdesc++)
if (iob[fdesc].i_flgs == 0)
goto gotfile;
stop("Out of file descriptors");
gotfile:
fdesc = GetFreeFd();
io = &iob[fdesc];
bzero(io, sizeof(*io));
//==========================================================================
// open() - Open the file specified by 'path' for reading.
int open(const char * path, int flags)
static int open_bvr(BVRef bvr, const char *filePath, int flags)
{
int fdesc, i;
struct iob * io;
const char * filePath;
BVRef bvr;
struct iob*io;
intfdesc;
inti;
// Locate a free descriptor slot.
if (bvr == NULL) {
return -1;
}
for (fdesc = 0; fdesc < NFILES; fdesc++)
if (iob[fdesc].i_flgs == 0)
goto gotfile;
fdesc = GetFreeFd();
io = &iob[fdesc];
bzero(io, sizeof(*io));
stop("Out of file descriptors");
// Mark the descriptor as taken.
io->i_flgs = F_ALLOC;
gotfile:
io = &iob[fdesc];
bzero(io, sizeof(*io));
// Find the next available memory block in the download buffer.
io->i_buf = (char *) LOAD_ADDR;
for (i = 0; i < NFILES; i++) {
if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) {
continue;
}
io->i_buf = max(iob[i].i_filesize + iob[i].i_buf, io->i_buf);
}
// Mark the descriptor as taken.
// Load entire file into memory. Unnecessary open() calls must be avoided.
gFSLoadAddress = io->i_buf;
io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
if (io->i_filesize < 0) {
close(fdesc);
return -1;
}
return fdesc;
}
io->i_flgs = F_ALLOC;
int open(const char *path, int flags)
{
const char*filepath;
BVRefbvr;
// Resolve the boot volume from the file spec.
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) {
return open_bvr(bvr, filepath, flags);
}
return -1;
}
if ((bvr = getBootVolumeRef(path, &filePath)) == NULL)
goto error;
int open_bvdev(const char *bvd, const char *path, int flags)
{
const struct devsw*dp;
const char*cp;
BVRefbvr;
inti;
intlen;
intunit;
intpartition;
// Find the next available memory block in the download buffer.
if ((i = open(path, flags)) >= 0) {
return i;
}
io->i_buf = (char *) LOAD_ADDR;
for (i = 0; i < NFILES; i++)
{
if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) continue;
io->i_buf = max(iob[i].i_filesize + iob[i].i_buf, io->i_buf);
}
if (bvd == NULL || (len = strlen(bvd)) < 2) {
return -1;
}
// Load entire file into memory. Unnecessary open() calls must
// be avoided.
gFSLoadAddress = io->i_buf;
io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
if (io->i_filesize < 0) {
goto error;
}
return fdesc;
error:
close(fdesc);
return -1;
for (dp=devsw; dp->name; dp++) {
if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) {
unit = 0;
partition = 0;
/* get optional unit and partition */
if (len >= 5 && bvd[2] == '(') { /* min must be present xx(0) */
cp = &bvd[3];
i = 0;
while ((cp - path) < len && isdigit(*cp)) {
i = i * 10 + *cp++ - '0';
unit = i;
}
if (*cp++ == ',') {
i = 0;
while ((cp - path) < len && isdigit(*cp)) {
i = i * 10 + *cp++ - '0';
partition = i;
}
}
}
// turbo - bt(0,0) hook
if ((dp->biosdev + unit) == 0x101) {
// zef - use the ramdisk if available and the alias is active.
if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) {
bvr = gRAMDiskVolume;
} else {
bvr = gBIOSBootVolume;
}
} else {
bvr = newBootVolumeRef(dp->biosdev + unit, partition);
}
return open_bvr(bvr, path, flags);
}
}
return -1;
}
//==========================================================================
BVRef selectBootVolume( BVRef chain )
{
BOOL filteredChain = FALSE;
BOOL foundPrimary = FALSE;
bool filteredChain = false;
bool foundPrimary = false;
BVRef bvr, bvr1 = 0, bvr2 = 0;
if (chain->filtered) filteredChain = TRUE;
if (chain->filtered) filteredChain = true;
if (multiboot_partition_set)
for ( bvr = chain; bvr; bvr = bvr->next )
char testStr[64];
int cnt;
if (getValueForKey("Default Partition", &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain)
if (getValueForKey(kDefaultPartition, &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain)
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
*/
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = TRUE;
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = true;
// zhell -- Undo a regression that was introduced from r491 to 492.
// if gBIOSBootVolume is set already, no change is required
if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume)
if (biosdev == 0x101)
{
// zef - use the ramdisk if available and the alias is active.
if (gRAMDiskVolume != NULL && gRAMDiskBTAliased == 1)
if (gRAMDiskVolume != NULL && gRAMDiskBTAliased)
bvr = gRAMDiskVolume;
else
bvr = gBIOSBootVolume;
trunk/i386/libsaio/load.c
3838
3939
4040
41
41
4242
4343
4444
......
250250
251251
252252
253
253
254254
255255
256256
static unsigned long gBinaryAddress;
BOOL gHaveKernelCache;
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
// Public Functions
}
if (vmsize && (strcmp(segname, "__PRELINK") == 0))
gHaveKernelCache = 1;
gHaveKernelCache = true;
// Copy from file load area.
if (vmsize>0 && filesize>0)
trunk/i386/libsaio/ntfs.h
2121
2222
2323
24
24
2525
*/
extern void NTFSGetDescription(CICell ih, char *str, long strMaxLen);
extern BOOL NTFSProbe (const void *buf);
extern bool NTFSProbe (const void *buf);
trunk/i386/libsaio/acpi.h
7272
7373
7474
75
76
77
75
76
77
78
79
80
81
82
83
84
85
86
7887
79
88
8089
8190
8291
uint32_t FIRMWARE_CTRL;
uint32_t DSDT;
/*We absolutely don't care about theese fields*/
uint8_t notimp1[88];
uint64_t X_FIRMWARE_CTRL;
uint64_t X_DSDT;
uint8_tnotimp1[68];
/*Reset Fix*/
uint32_tFlags;
uint8_tReset_SpaceID;
uint8_tReset_BitWidth;
uint8_tReset_BitOffset;
uint8_tReset_AccessWidth;
uint64_tReset_Address;
uint8_tReset_Value;
uint8_tReserved[3];
uint64_tX_FIRMWARE_CTRL;
uint64_tX_DSDT;
/*We absolutely don't care about theese fields*/
uint8_t notimp2[96];
uint8_tnotimp2[96];
} __attribute__((packed));
#endif /* !__LIBSAIO_ACPI_H */
trunk/i386/libsaio/ati.h
3737
3838
3939
40
41
42
43
44
4540
4641
4742
uint8_t data[];
};
struct bios {
uint16_tsignature;/* 0x55AA */
uint8_tsize;/* Size in multiples of 512 */
};
#define REG8(reg) ((volatile uint8_t *)regs)[(reg)]
#define REG16(reg) ((volatile uint16_t *)regs)[(reg) >> 1]
#define REG32R(reg) ((volatile uint32_t *)regs)[(reg) >> 2]
trunk/i386/libsaio/platform.c
11
22
33
4
45
56
67
78
89
9
10
11
1210
11
12
1313
1414
1515
......
2323
2424
2525
26
26
2727
28
29
30
31
32
33
28
29
30
31
32
3433
3534
36
35
3736
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
37
6838
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
39
40
41
9142
92
93
/*
* platform.c
*
* AsereBLN: cleanup
*/
#include "libsaio.h"
#include "bootstruct.h"
#include "pci.h"
#include "freq_detect.h"
#include "nvidia.h"
#include "spd.h"
#include "platform.h"
#include "cpu.h"
#include "mem.h"
#ifndef DEBUG_PLATFORM
#define DEBUG_PLATFORM 0
PlatformInfo_t Platform;
void scan_cpu_amd()
bool platformCPUFeature(uint32_t feature)
{
// AMD
// TODO: Retrieve cpu brand string
// TODO: Retrieve cpu core count
// TODO: Retrieve cpu mobile info
if (Platform.CPU.Features & feature) {
return true;
} else {
return false;
}
}
void scan_cpu_intel()
void scan_platform(void)
{
uint32_tcpuid_reg[4];
// Get Number of cores per package
/*
Initially set the EAX register to 4 and the ECX register to 0 prior to executing the CPUID instruction.
After executing the CPUID instruction, (EAX[31:26] + 1) contains the number of cores.
*/
cpuid_reg[2]=1;
do_cpuid(4, cpuid_reg);
do_cpuid(4, cpuid_reg); // FIXME: why does this only work the 2nd time ?
Platform.CPU.NoCores = bitfield(cpuid_reg[0], 31, 26) + 1;
// Find Number of Concurrent Threads Processed (HyperThreading)
do_cpuid(1,cpuid_reg);
if(bitfield(cpuid_reg[1], 23, 16) > 1)
Platform.CPU.NoThreads=Platform.CPU.NoCores;
else
Platform.CPU.NoThreads=Platform.CPU.NoCores * 2;
// Mobile CPU ?
if (rdmsr64(0x17) & (1<<28))
Platform.CPU.Mobile = 1;
else
Platform.CPU.Mobile = 0;
}
void scan_platform()
{
uint32_tcpuid_reg[4];
memset(&Platform, 0, sizeof(Platform));
build_pci_dt();
calculate_freq();
// Copy the values from calculate_freq()
Platform.CPU.TSCFrequency = tscFrequency;
Platform.CPU.FSBFrequency = fsbFrequency;
Platform.CPU.CPUFrequency = cpuFrequency;
do_cpuid(0, cpuid_reg);
Platform.CPU.Vendor = cpuid_reg[1];
do_cpuid(1, cpuid_reg);
Platform.CPU.Model = bitfield(cpuid_reg[0], 7, 4);
Platform.CPU.Family = bitfield(cpuid_reg[0], 11, 8);
Platform.CPU.ExtModel = bitfield(cpuid_reg[0], 19, 16);
Platform.CPU.ExtFamily = bitfield(cpuid_reg[0], 27, 20);
// Get vendor specific cpu data
if((Platform.CPU.Vendor == 0x756E6547 /* Intel */) && ((Platform.CPU.Family == 0x06) || (Platform.CPU.Family == 0x0f)))
scan_cpu_intel();
else if((Platform.CPU.Vendor == 0x68747541 /* AMD */) && (Platform.CPU.Family == 0x0f))
scan_cpu_amd();
scan_cpu(&Platform);
scan_memory(&Platform);
scan_spd(&Platform);
}
trunk/i386/libsaio/cpu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* Copyright 2008 Islam Ahmed Zaid. All rights reserved. <azismed@gmail.com>
* AsereBLN: 2009: cleanup and bugfix
*/
#include "libsaio.h"
#include "platform.h"
#include "cpu.h"
#ifndef DEBUG_CPU
#define DEBUG_CPU 0
#endif
#if DEBUG_CPU
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
static inline uint64_t rdtsc64(void)
{
uint64_t ret;
__asm__ volatile("rdtsc" : "=A" (ret));
return ret;
}
static inline uint64_t rdmsr64(uint32_t msr)
{
uint64_t ret;
__asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
return ret;
}
static inline void do_cpuid(uint32_t selector, uint32_t *data)
{
asm volatile ("cpuid"
: "=a" (data[0]),
"=b" (data[1]),
"=c" (data[2]),
"=d" (data[3])
: "a" (selector));
}
static inline void do_cpuid2(uint32_t selector, uint32_t selector2, uint32_t *data)
{
asm volatile ("cpuid"
: "=a" (data[0]),
"=b" (data[1]),
"=c" (data[2]),
"=d" (data[3])
: "a" (selector), "c" (selector2));
}
// DFE: enable_PIT2 and disable_PIT2 come from older xnu
/*
* Enable or disable timer 2.
* Port 0x61 controls timer 2:
* bit 0 gates the clock,
* bit 1 gates output to speaker.
*/
static inline void enable_PIT2(void)
{
/* Enable gate, disable speaker */
__asm__ volatile(
" inb $0x61,%%al \n\t"
" and $0xFC,%%al \n\t" /* & ~0x03 */
" or $1,%%al \n\t"
" outb %%al,$0x61 \n\t"
: : : "%al" );
}
static inline void disable_PIT2(void)
{
/* Disable gate and output to speaker */
__asm__ volatile(
" inb $0x61,%%al \n\t"
" and $0xFC,%%al \n\t"/* & ~0x03 */
" outb %%al,$0x61 \n\t"
: : : "%al" );
}
// DFE: set_PIT2_mode0, poll_PIT2_gate, and measure_tsc_frequency are
// roughly based on Linux code
/* Set the 8254 channel 2 to mode 0 with the specified value.
In mode 0, the counter will initially set its gate low when the
timer expires. For this to be useful, you ought to set it high
before calling this function. The enable_PIT2 function does this.
*/
static inline void set_PIT2_mode0(uint16_t value)
{
__asm__ volatile(
" movb $0xB0,%%al \n\t"
" outb%%al,$0x43\n\t"
" movb%%dl,%%al\n\t"
" outb%%al,$0x42\n\t"
" movb%%dh,%%al\n\t"
" outb%%al,$0x42"
: : "d"(value) /*: no clobber */ );
}
/* Returns the number of times the loop ran before the PIT2 signaled */
static inline unsigned long poll_PIT2_gate(void)
{
unsigned long count = 0;
unsigned char nmi_sc_val;
do {
++count;
__asm__ volatile(
"inb$0x61,%0"
: "=q"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */);
} while( (nmi_sc_val & 0x20) == 0);
return count;
}
/*
* DFE: Measures the TSC frequency in Hz (64-bit) using the ACPI PM timer
*/
static uint64_t measure_tsc_frequency(void)
{
uint64_t tscStart;
uint64_t tscEnd;
uint64_t tscDelta = 0xffffffffffffffffULL;
unsigned long pollCount;
uint64_t retval = 0;
int i;
/* Time how many TSC ticks elapse in 30 msec using the 8254 PIT
* counter 2. We run this loop 3 times to make sure the cache
* is hot and we take the minimum delta from all of the runs.
* That is to say that we're biased towards measuring the minimum
* number of TSC ticks that occur while waiting for the timer to
* expire. That theoretically helps avoid inconsistencies when
* running under a VM if the TSC is not virtualized and the host
* steals time. The TSC is normally virtualized for VMware.
*/
for(i = 0; i < 10; ++i)
{
enable_PIT2();
set_PIT2_mode0(CALIBRATE_LATCH);
tscStart = rdtsc64();
pollCount = poll_PIT2_gate();
tscEnd = rdtsc64();
/* The poll loop must have run at least a few times for accuracy */
if(pollCount <= 1)
continue;
/* The TSC must increment at LEAST once every millisecond. We
* should have waited exactly 30 msec so the TSC delta should
* be >= 30. Anything less and the processor is way too slow.
*/
if((tscEnd - tscStart) <= CALIBRATE_TIME_MSEC)
continue;
// tscDelta = min(tscDelta, (tscEnd - tscStart))
if( (tscEnd - tscStart) < tscDelta )
tscDelta = tscEnd - tscStart;
}
/* tscDelta is now the least number of TSC ticks the processor made in
* a timespan of 0.03 s (e.g. 30 milliseconds)
* Linux thus divides by 30 which gives the answer in kiloHertz because
* 1 / ms = kHz. But we're xnu and most of the rest of the code uses
* Hz so we need to convert our milliseconds to seconds. Since we're
* dividing by the milliseconds, we simply multiply by 1000.
*/
/* Unlike linux, we're not limited to 32-bit, but we do need to take care
* that we're going to multiply by 1000 first so we do need at least some
* arithmetic headroom. For now, 32-bit should be enough.
* Also unlike Linux, our compiler can do 64-bit integer arithmetic.
*/
if(tscDelta > (1ULL<<32))
retval = 0;
else
{
retval = tscDelta * 1000 / 30;
}
disable_PIT2();
return retval;
}
/*
* Calculates the FSB and CPU frequencies using specific MSRs for each CPU
* - multi. is read from a specific MSR. In the case of Intel, there is:
* a max multi. (used to calculate the FSB freq.),
* and a current multi. (used to calculate the CPU freq.)
* - fsbFrequency = tscFrequency / multi
* - cpuFrequency = fsbFrequency * multi
*/
void scan_cpu(PlatformInfo_t *p)
{
uint64_ttscFrequency, fsbFrequency, cpuFrequency;
uint64_tmsr, flex_ratio;
uint8_tmaxcoef, maxdiv, currcoef, currdiv;
maxcoef = maxdiv = currcoef = currdiv = 0;
/* get cpuid values */
do_cpuid(0x00000000, p->CPU.CPUID[CPUID_0]);
do_cpuid(0x00000001, p->CPU.CPUID[CPUID_1]);
do_cpuid(0x00000002, p->CPU.CPUID[CPUID_2]);
do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]);
do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]);
do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]);
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) {
do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]);
}
#if DEBUG_CPU
{
inti;
printf("CPUID Raw Values:\n");
for (i=0; i<CPUID_MAX; i++) {
printf("%02d: %08x-%08x-%08x-%08x\n", i,
p->CPU.CPUID[i][0], p->CPU.CPUID[i][1],
p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]);
}
}
#endif
p->CPU.Vendor= p->CPU.CPUID[CPUID_0][1];
p->CPU.Model= bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4);
p->CPU.Family= bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8);
p->CPU.ExtModel= bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16);
p->CPU.ExtFamily= bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20);
p->CPU.NoThreads= bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16);
p->CPU.NoCores= bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1;
p->CPU.Model += (p->CPU.ExtModel << 4);
/* setup features */
if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MMX;
}
if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE;
}
if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE2;
}
if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE3;
}
if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE41;
}
if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE42;
}
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_EM64T;
}
//if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) {
if (p->CPU.NoThreads > p->CPU.NoCores) {
p->CPU.Features |= CPU_FEATURE_HTT;
}
tscFrequency = measure_tsc_frequency();
fsbFrequency = 0;
cpuFrequency = 0;
if ((p->CPU.Vendor == 0x756E6547 /* Intel */) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) {
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) {
/* Nehalem CPU model */
if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e)) {
msr = rdmsr64(MSR_PLATFORM_INFO);
DBG("msr(%d): platform_info %08x\n", __LINE__, msr & 0xffffffff);
currcoef = (msr >> 8) & 0xff;
msr = rdmsr64(MSR_FLEX_RATIO);
DBG("msr(%d): flex_ratio %08x\n", __LINE__, msr & 0xffffffff);
if ((msr >> 16) & 0x01) {
flex_ratio = (msr >> 8) & 0xff;
if (currcoef > flex_ratio) {
currcoef = flex_ratio;
}
}
if (currcoef) {
fsbFrequency = (tscFrequency / currcoef);
}
cpuFrequency = tscFrequency;
} else {
msr = rdmsr64(IA32_PERF_STATUS);
DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, msr & 0xffffffff);
currcoef = (msr >> 8) & 0x1f;
/* Non-integer bus ratio for the max-multi*/
maxdiv = (msr >> 46) & 0x01;
/* Non-integer bus ratio for the current-multi (undocumented)*/
currdiv = (msr >> 14) & 0x01;
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) // This will always be model >= 3
{
/* On these models, maxcoef defines TSC freq */
maxcoef = (msr >> 40) & 0x1f;
} else {
/* On lower models, currcoef defines TSC freq */
/* XXX */
maxcoef = currcoef;
}
if (maxcoef) {
if (maxdiv) {
fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1));
} else {
fsbFrequency = (tscFrequency / maxcoef);
}
if (currdiv) {
cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2);
} else {
cpuFrequency = (fsbFrequency * currcoef);
}
DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : "");
}
}
}
/* Mobile CPU ? */
if (rdmsr64(0x17) & (1<<28)) {
p->CPU.Features |= CPU_FEATURE_MOBILE;
}
}
#if 0
else if((p->CPU.Vendor == 0x68747541 /* AMD */) && (p->CPU.Family == 0x0f)) {
if(p->CPU.ExtFamily == 0x00 /* K8 */) {
msr = rdmsr64(K8_FIDVID_STATUS);
currcoef = (msr & 0x3f) / 2 + 4;
currdiv = (msr & 0x01) * 2;
} else if(p->CPU.ExtFamily >= 0x01 /* K10+ */) {
msr = rdmsr64(K10_COFVID_STATUS);
if(p->CPU.ExtFamily == 0x01 /* K10 */)
currcoef = (msr & 0x3f) + 0x10;
else /* K11+ */
currcoef = (msr & 0x3f) + 0x08;
currdiv = (2 << ((msr >> 6) & 0x07));
}
if (currcoef) {
if (currdiv) {
fsbFrequency = ((tscFrequency * currdiv) / currcoef);
DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv);
} else {
fsbFrequency = (tscFrequency / currcoef);
DBG("%d\n", currcoef);
}
fsbFrequency = (tscFrequency / currcoef);
cpuFrequency = tscFrequency;
}
}
if (!fsbFrequency) {
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
}
#endif
p->CPU.MaxCoef = maxcoef;
p->CPU.MaxDiv = maxdiv;
p->CPU.CurrCoef = currcoef;
p->CPU.CurrDiv = currdiv;
p->CPU.TSCFrequency = tscFrequency;
p->CPU.FSBFrequency = fsbFrequency;
p->CPU.CPUFrequency = cpuFrequency;
#if DEBUG_CPU
DBG("CPU: Vendor/Model/ExtModel: 0x%x/0x%x/0x%x\n", p->CPU.Vendor, p->CPU.Model, p->CPU.ExtModel);
DBG("CPU: Family/ExtFamily: 0x%x/0x%x\n", p->CPU.Family, p->CPU.ExtFamily);
DBG("CPU: MaxCoef/CurrCoef: 0x%x/0x%x\n", p->CPU.MaxCoef, p->CPU.CurrCoef);
DBG("CPU: MaxDiv/CurrDiv: 0x%x/0x%x\n", p->CPU.MaxDiv, p->CPU.CurrDiv);
DBG("CPU: TSCFreq: %dMHz\n", p->CPU.TSCFrequency / 1000000);
DBG("CPU: FSBFreq: %dMHz\n", p->CPU.FSBFrequency / 1000000);
DBG("CPU: CPUFreq: %dMHz\n", p->CPU.CPUFrequency / 1000000);
DBG("CPU: NoCores/NoThreads: %d/%d\n", p->CPU.NoCores, p->CPU.NoThreads);
DBG("CPU: Features: 0x%08x\n", p->CPU.Features);
printf("(Press a key to continue...)\n");
getc();
#endif
}
trunk/i386/libsaio/platform.h
88
99
1010
11
12
13
11
12
1413
15
14
15
16
17
18
19
20
21
22
1623
24
25
26
27
28
29
30
31
32
33
34
1735
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
4058
4159
42
43
44
45
60
61
62
63
4664
4765
48
66
4967
68
69
70
5071
51
52
53
72
73
74
75
76
77
5478
5579
5680
57
58
59
60
61
6281
63
64
65
66
67
68
69
70
82
83
84
85
86
87
88
89
90
7191
72
92
7393
74
75
76
77
78
79
80
94
95
96
97
98
8199
82100
83
84
85
86
87
88
89
90
91
92
93
101
102
103
94104
95105
96106
97107
98108
99109
100
#include "libsaio.h"
#define bit(n)(1ULL << (n))
#define bitmask(h,l)((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
#define bitfield(x,h,l)(((x) & bitmask(h,l)) >> l)
extern bool platformCPUFeature(uint32_t);
extern void scan_platform(void);
extern void scan_platform();
/* CPUID index into cpuid_raw */
#define CPUID_00
#define CPUID_11
#define CPUID_22
#define CPUID_33
#define CPUID_44
#define CPUID_805
#define CPUID_816
#define CPUID_MAX7
/* CPU Features */
#define CPU_FEATURE_MMX0x00000001// MMX Instruction Set
#define CPU_FEATURE_SSE0x00000002// SSE Instruction Set
#define CPU_FEATURE_SSE20x00000004// SSE2 Instruction Set
#define CPU_FEATURE_SSE30x00000008// SSE3 Instruction Set
#define CPU_FEATURE_SSE410x00000010// SSE41 Instruction Set
#define CPU_FEATURE_SSE420x00000020// SSE42 Instruction Set
#define CPU_FEATURE_EM64T0x00000040// 64Bit Support
#define CPU_FEATURE_HTT0x00000080// HyperThreading
#define CPU_FEATURE_MOBILE0x00000100// Mobile CPU
/* SMBIOS Memory Types */
#define SMB_MEM_TYPE_UNDEFINED0
#define SMB_MEM_TYPE_OTHER1
#define SMB_MEM_TYPE_UNKNOWN2
#define SMB_MEM_TYPE_DRAM3
#define SMB_MEM_TYPE_EDRAM4
#define SMB_MEM_TYPE_VRAM5
#define SMB_MEM_TYPE_SRAM6
#define SMB_MEM_TYPE_RAM7
#define SMB_MEM_TYPE_ROM8
#define SMB_MEM_TYPE_FLASH9
#define SMB_MEM_TYPE_EEPROM10
#define SMB_MEM_TYPE_FEPROM11
#define SMB_MEM_TYPE_EPROM12
#define SMB_MEM_TYPE_CDRAM13
#define SMB_MEM_TYPE_3DRAM14
#define SMB_MEM_TYPE_SDRAM15
#define SMB_MEM_TYPE_SGRAM16
#define SMB_MEM_TYPE_RDRAM17
#define SMB_MEM_TYPE_DDR18
#define SMB_MEM_TYPE_DDR219
#define SMB_MEM_TYPE_FBDIMM20
#define SMB_MEM_TYPE_DDR324// Supported in 10.5.6+ AppleSMBIOS
#define SMB_MEM_TYPE_UNDEFINED0
#define SMB_MEM_TYPE_OTHER1
#define SMB_MEM_TYPE_UNKNOWN2
#define SMB_MEM_TYPE_DRAM3
#define SMB_MEM_TYPE_EDRAM4
#define SMB_MEM_TYPE_VRAM5
#define SMB_MEM_TYPE_SRAM6
#define SMB_MEM_TYPE_RAM7
#define SMB_MEM_TYPE_ROM8
#define SMB_MEM_TYPE_FLASH9
#define SMB_MEM_TYPE_EEPROM10
#define SMB_MEM_TYPE_FEPROM11
#define SMB_MEM_TYPE_EPROM12
#define SMB_MEM_TYPE_CDRAM13
#define SMB_MEM_TYPE_3DRAM14
#define SMB_MEM_TYPE_SDRAM15
#define SMB_MEM_TYPE_SGRAM16
#define SMB_MEM_TYPE_RDRAM17
#define SMB_MEM_TYPE_DDR18
#define SMB_MEM_TYPE_DDR219
#define SMB_MEM_TYPE_FBDIMM20
#define SMB_MEM_TYPE_DDR324// Supported in 10.5.6+ AppleSMBIOS
/* Memory Configuration Types */
#define SMB_MEM_CHANNEL_UNKNOWN0
#define SMB_MEM_CHANNEL_SINGLE1
#define SMB_MEM_CHANNEL_DUAL2
#define SMB_MEM_CHANNEL_TRIPLE3
#define SMB_MEM_CHANNEL_UNKNOWN0
#define SMB_MEM_CHANNEL_SINGLE1
#define SMB_MEM_CHANNEL_DUAL2
#define SMB_MEM_CHANNEL_TRIPLE3
/* Maximum number of ram slots */
#defineMAX_RAM_SLOTS16
#define MAX_RAM_SLOTS8
/* Maximum number of SPD bytes */
#define MAX_SPD_SIZE256
typedef struct _RamSlotInfo_t {
boolInUse;// Module Present
uint32_tModuleSize;// Size of Module in MB
char*spd;// SPD Dump
boolInUse;
uint8_tType;
charVendor[64];
charPartNo[64];
charSerialNo[16];
uint8_tspd[MAX_SPD_SIZE];
} RamSlotInfo_t;
typedef struct _PlatformInfo_t {
boolMobile;// Mobile Platform
boolx86_64;// 64 Bit Capable
struct PCI {
uint8_tNoDevices;// No of PCI devices
} PCI;
struct CPU {
uint32_tVendor;// Vendor
uint32_tModel;// Model
uint32_tExtModel;// Extended Model
uint32_tFamily;// Family
uint32_tExtFamily;// Extended Family
uint8_tNoCores;// No Cores per Package
uint8_tNoThreads;// Threads per Package
uint8_tMaxCoef;// Max Multiplier
uint32_tFeatures;// CPU Features like MMX, SSE2, VT, MobileCPU
uint32_tVendor;// Vendor
uint32_tModel;// Model
uint32_tExtModel;// Extended Model
uint32_tFamily;// Family
uint32_tExtFamily;// Extended Family
uint32_tNoCores;// No Cores per Package
uint32_tNoThreads;// Threads per Package
uint8_tMaxCoef;// Max Multiplier
uint8_tMaxDiv;
uint8_tCurrCoef;// Current Multiplier
uint8_tCurrCoef;// Current Multiplier
uint8_tCurrDiv;
floatMaxRatio;
floatCurrRatio;
uint64_tTSCFrequency;// TSC Frequency Hz
uint64_tFSBFrequency;// FSB Frequency Hz
uint64_tCPUFrequency;// CPU Frequency Hz
boolMobile;// Mobile CPU
uint32_tBrandString[16];// 48 Byte Branding String
uint64_tTSCFrequency;// TSC Frequency Hz
uint64_tFSBFrequency;// FSB Frequency Hz
uint64_tCPUFrequency;// CPU Frequency Hz
uint32_tBrandString[16];// 48 Byte Branding String
uint32_tCPUID[CPUID_MAX][4];// CPUID 0..4, 80..81 Raw Values
} CPU;
struct RAM {
uint64_tFrequency;// Ram Frequency
uint32_tDivider;// Memory divider
floatCAS;// CAS 1/2/2.5/3/4/5/6/7
uint8_tTRC;
uint8_tTRP;
uint8_tRAS;
uint8_tChannels;// Channel Configuration Single,Dual or Triple
uint8_tNoSlots;// Maximum no of slots available
uint8_tType;// Standard SMBIOS v2.5 Memory Type
char*BrandString;// Branding String Memory Controller
RamSlotInfo_tDIMM[MAX_RAM_SLOTS];// Information about each slot
RamSlotInfo_tDIMM[MAX_RAM_SLOTS];// Information about each slot
uint64_tFrequency;// Ram Frequency
//uint8_tType;// Standard SMBIOS v2.5 Memory Type
} RAM;
} PlatformInfo_t;
extern PlatformInfo_t Platform;
#endif /* !__LIBSAIO_PLATFORM_H */
trunk/i386/libsaio/disk.c
5555
5656
5757
58
59
5860
59
6061
6162
6263
......
218219
219220
220221
221
222
222223
223224
224225
......
264265
265266
266267
267
268
268269
269270
270271
......
305306
306307
307308
308
309
309310
310311
311312
......
325326
326327
327328
328
329
329330
330331
331332
......
14651466
14661467
14671468
1468
1469
14691470
14701471
14711472
......
15801581
15811582
15821583
1583
1584
15841585
15851586
15861587
15871588
15881589
1589
1590
15901591
15911592
15921593
15931594
15941595
15951596
1596
1597
15971598
15981599
15991600
16001601
1601
1602
16021603
16031604
16041605
......
16781679
16791680
16801681
1681
1682
1683
16821684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
16831705
16841706
16851707
16861708
1687
1688
1689
1690
1709
1710
16911711
16921712
16931713
1714
1715
1716
1717
1718
1719
1720
1721
16941722
16951723
16961724
......
17151743
17161744
17171745
1746
1747
17181748
17191749
17201750
17211751
17221752
1723
17241753
17251754
17261755
......
18151844
18161845
18171846
1818
1847
18191848
18201849
18211850
......
18541883
18551884
18561885
1857
1886
18581887
18591888
18601889
#define UFS_SUPPORT 0
#endif
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "libsaio.h"
#include "fdisk.h"
#if UFS_SUPPORT
#include "ufs.h"
// Return:
// 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call.
static BOOL cache_valid = FALSE;
static bool cache_valid = false;
static int Biosread( int biosdev, unsigned long long secno )
{
xnsecs = N_CACHE_SECS;
xsec = (secno / divisor) * divisor;
cache_valid = FALSE;
cache_valid = false;
while ((rc = ebiosread(biosdev, secno / divisor, xnsecs / divisor)) && (++tries < 5))
{
xhead = head;
xsec = sec;
xnsecs = ((unsigned int)(sec + N_CACHE_SECS) > di.di.params.phys_spt) ? (di.di.params.phys_spt - sec) : N_CACHE_SECS;
cache_valid = FALSE;
cache_valid = false;
while ((rc = biosread(biosdev, cyl, head, sec, xnsecs)) &&
(++tries < 5))
// If the BIOS reported success, mark the sector cache as valid.
if (rc == 0) {
cache_valid = TRUE;
cache_valid = true;
}
biosbuf = trackbuf + (secno % divisor) * BPS;
xbiosdev = biosdev;
{
verbose("Resetting BIOS device %xh\n", biosdev);
// Reset the biosbuf cache
cache_valid = FALSE;
cache_valid = false;
if(map == gDiskBVMap)
gDiskBVMap = map->next;
else if(prevMap != NULL)
* Adjust the new bvr's fields.
*/
newBVR->next = NULL;
newBVR->filtered = TRUE;
newBVR->filtered = true;
if ( (!allowFlags || newBVR->flags & allowFlags)
&& (!denyFlags || !(newBVR->flags & denyFlags) )
&& (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev)
)
newBVR->visible = TRUE;
newBVR->visible = true;
/*
* Looking for "Hide Partition" entries in "hd(x,y) hd(n,m)" format
* to be able to hide foreign partitions from the boot menu.
*/
if ( (newBVR->flags & kBVFlagForeignBoot)
&& getValueForKey("Hide Partition", &val, &len, &bootInfo->bootConfig)
&& getValueForKey(kHidePartition, &val, &len, &bootInfo->bootConfig)
)
{
sprintf(devsw, "hd(%d,%d)", BIOS_DEV_UNIT(newBVR), newBVR->part_no);
if (strstr(val, devsw) != NULL)
newBVR->visible = FALSE;
newBVR->visible = false;
}
/*
//==========================================================================
void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, BOOL verbose )
/* If Rename Partition has defined an alias, then extract it for description purpose */
static const char * getVolumeLabelAlias( BVRef bvr, const char * str, long strMaxLen)
{
const int MAX_ALIAS_SIZE=31;
static char szAlias[MAX_ALIAS_SIZE+1];
char *q=szAlias;
const char * szAliases = getStringForKey(kRenamePartition, &bootInfo->bootConfig);
if (!str || !*str || !szAliases) return 0; // no renaming wanted
const char * p = strstr(szAliases, str);
if(!p || !(*p)) return 0; // this volume must not be renamed, or option is malformed
p+= strlen(str); // skip the "hd(n,m) " field
// multiple aliases can be found separated by a semi-column
while(*p && *p != ';' && q<(szAlias+MAX_ALIAS_SIZE)) *q++=*p++;
*q='\0';
return szAlias;
}
void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, bool verbose )
{
unsigned char type = (unsigned char) bvr->part_type;
char *p;
p = str;
if (verbose)
{
sprintf( str, "hd(%d,%d) ",
BIOS_DEV_UNIT(bvr), bvr->part_no);
if (verbose) {
sprintf( str, "hd(%d,%d) ", BIOS_DEV_UNIT(bvr), bvr->part_no);
for (; strMaxLen > 0 && *p != '\0'; p++, strMaxLen--);
}
// See if we should get the renamed alias name for this partion:
const char * szAliasName = getVolumeLabelAlias(bvr, str, strMaxLen);
if (szAliasName && *szAliasName)
{
strncpy(bvr->label, szAliasName, strMaxLen);
return; // we're done here no need to seek for real name
}
//
// Get the volume label using filesystem specific functions
// or use the alternate volume label if available.
}
}
/* See if a partion rename is wanted: */
// Set the devices label
sprintf(bvr->label, p);
}
//==========================================================================
int readBootSector( int biosdev, unsigned int secno, void * buffer )
{
struct disk_blk0 * bootSector = (struct disk_blk0 *) buffer;
}
secno += bvr->part_boff;
cache_valid = FALSE;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
}
secno += bvr->part_boff;
cache_valid = FALSE;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
trunk/i386/libsaio/pci_setup.c
11
2
23
34
5
6
47
58
6
7
89
910
1011
......
1213
1314
1415
15
16
1617
1718
1819
1920
20
21
22
21
22
23
2324
24
25
26
27
25
26
27
2828
29
29
3030
3131
3232
#include "libsaio.h"
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
#include "nvidia.h"
#include "ati.h"
extern void set_eth_builtin(pci_dt_t *eth_dev);
extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev);
extern bool setup_ati_devprop(pci_dt_t *ati_dev);
extern int ehci_acquire(pci_dt_t *pci_dev);
extern int uhci_reset(pci_dt_t *pci_dev);
extern void force_enable_hpet(pci_dt_t *lpc_dev);
void setup_pci_devs(pci_dt_t *pci_dt)
{
char *devicepath;
BOOL do_eth_devprop, do_gfx_devprop, fix_ehci, fix_uhci, fix_usb, do_enable_hpet;
bool do_eth_devprop, do_gfx_devprop, fix_ehci, fix_uhci, fix_usb, do_enable_hpet;
pci_dt_t *current = pci_dt;
do_eth_devprop = do_gfx_devprop = fix_ehci = fix_uhci = fix_usb = do_enable_hpet = false;
getBoolForKey("EthernetBuiltIn", &do_eth_devprop, &bootInfo->bootConfig);
getBoolForKey("GraphicsEnabler", &do_gfx_devprop, &bootInfo->bootConfig);
if (getBoolForKey("USBBusFix", &fix_usb, &bootInfo->bootConfig) && fix_usb)
getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);
getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->bootConfig);
if (getBoolForKey(kUSBBusFix, &fix_usb, &bootInfo->bootConfig) && fix_usb) {
fix_ehci = fix_uhci = true;
else
{
getBoolForKey("EHCIacquire", &fix_ehci, &bootInfo->bootConfig);
getBoolForKey("UHCIreset", &fix_uhci, &bootInfo->bootConfig);
} else {
getBoolForKey(kEHCIacquire, &fix_ehci, &bootInfo->bootConfig);
getBoolForKey(kUHCIreset, &fix_uhci, &bootInfo->bootConfig);
}
getBoolForKey("ForceHPET", &do_enable_hpet, &bootInfo->bootConfig);
getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->bootConfig);
while (current)
{
trunk/i386/libsaio/cpu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Copyright 2008 Islam Ahmed Zaid. All rights reserved. <azismed@gmail.com>
* AsereBLN: 2009: cleanup and bugfix
*/
#ifndef __LIBSAIO_CPU_H
#define __LIBSAIO_CPU_H
#include "libsaio.h"
extern void scan_cpu(PlatformInfo_t *);
#define bit(n)(1UL << (n))
#define bitmask(h,l)((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
#define bitfield(x,h,l)(((x) & bitmask(h,l)) >> l)
#defineIA32_PERF_STATUS0x198
#define MSR_FLEX_RATIO0x194
#defineMSR_PLATFORM_INFO0xCE
#define K8_FIDVID_STATUS0xC0010042
#define K10_COFVID_STATUS0xC0010071
#define DEFAULT_FSB100000 /* for now, hardcoding 100MHz for old CPUs */
// DFE: This constant comes from older xnu:
#define CLKNUM1193182/* formerly 1193167 */
// DFE: These two constants come from Linux except CLOCK_TICK_RATE replaced with CLKNUM
#define CALIBRATE_TIME_MSEC30/* 30 msecs */
#define CALIBRATE_LATCH((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000)
#endif /* !__LIBSAIO_CPU_H */
trunk/i386/libsaio/pci.c
88
99
1010
11
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1225
13
26
27
28
29
1430
31
32
1533
1634
35
36
1737
18
19
20
21
22
23
24
25
26
27
28
29
38
39
40
41
42
43
3044
31
45
46
47
48
49
3250
3351
34
52
3553
3654
3755
56
57
3858
39
40
41
42
43
44
45
46
47
48
49
50
59
60
61
62
63
5164
5265
53
54
5566
5667
57
58
59
60
61
62
63
64
68
69
70
71
72
73
74
75
76
77
78
6579
6680
67
81
6882
69
83
7084
71
72
73
74
85
7586
7687
7788
7889
79
90
8091
8192
82
83
84
85
86
87
88
89
93
94
95
96
97
98
99
100
90101
91
92102
93103
94104
95
105
96106
107
97108
109
98110
99111
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117112
118113
119114
120
121
122
123
124115
125
126116
117
118
119
120
121
127122
128123
129
130
124
131125
132126
133
134
127
128
129
135130
136131
137132
138
139
140
133
141134
142
143
135
136
137
144138
145
146139
147140
148141
149142
150143
151
152144
153145
154146
155147
156148
157
149
158150
159
160
151
152
161153
162154
163155
......
166158
167159
168160
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "bootstruct.h"
#include "pci.h"
uint32_t pci_config_read(uint32_t pci_addr, uint8_t reg, uint8_t bytes)
#ifndef DEBUG_PCI
#define DEBUG_PCI 0
#endif
#if DEBUG_PCI
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
pci_dt_t*root_pci_dev;
uint8_t pci_config_read8(uint32_t pci_addr, uint8_t reg)
{
uint32_t data = -1;
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
return inb(PCI_DATA_REG + (reg & 3));
}
uint16_t pci_config_read16(uint32_t pci_addr, uint8_t reg)
{
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
return inw(PCI_DATA_REG + (reg & 2));
}
switch (bytes)
{
case 1:
data = inb(PCI_DATA_REG + (reg & 3));
break;
case 2:
data = inw(PCI_DATA_REG + (reg & 2));
break;
case 4:
data = inl(PCI_DATA_REG);
break;
}
uint32_t pci_config_read32(uint32_t pci_addr, uint8_t reg)
{
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
return inl(PCI_DATA_REG);
}
return data;
void pci_config_write8(uint32_t pci_addr, uint8_t reg, uint8_t data)
{
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
outb(PCI_DATA_REG + (reg & 3), data);
}
void pci_config_write(uint32_t pci_addr, uint8_t reg, uint32_t data, uint8_t bytes)
void pci_config_write16(uint32_t pci_addr, uint8_t reg, uint16_t data)
{
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
outw(PCI_DATA_REG + (reg & 2), data);
}
switch (bytes)
{
case 1:
outb(PCI_DATA_REG + (reg & 3), data);
break;
case 2:
outw(PCI_DATA_REG + (reg & 2), data);
break;
case 4:
outl(PCI_DATA_REG, data);
break;
}
void pci_config_write32(uint32_t pci_addr, uint8_t reg, uint32_t data)
{
pci_addr |= reg & ~3;
outl(PCI_ADDR_REG, pci_addr);
outl(PCI_DATA_REG, data);
}
pci_dt_t *root_pci_dev;
void scan_pci_bus(pci_dt_t *start, uint8_t bus)
{
uint8_t dev, func, secondary_bus, header_type;
uint32_t id, pci_addr;
pci_dt_t *new;
pci_dt_t **current = &start->children;
for (dev = 0; dev < 32; dev++)
for (func = 0; func < 8; func++)
{
pci_dt_t*new;
pci_dt_t**current = &start->children;
uint32_tid;
uint32_tpci_addr;
uint8_tdev;
uint8_tfunc;
uint8_tsecondary_bus;
uint8_theader_type;
for (dev = 0; dev < 32; dev++) {
for (func = 0; func < 8; func++) {
pci_addr = PCIADDR(bus, dev, func);
id = pci_config_read32(pci_addr, PCI_VENDOR_ID);
if (!id || id == 0xffffffff)
if (!id || id == 0xffffffff) {
continue;
}
new = (pci_dt_t*)malloc(sizeof(pci_dt_t));
if (!new)
return;
memset(new, 0, sizeof(pci_dt_t));
bzero(new, sizeof(pci_dt_t));
new->dev.addr= pci_addr;
new->vendor_id= id & 0xffff;
new->device_id= (id >> 16) & 0xffff;
new->class_id= pci_config_read16(pci_addr, PCI_CLASS_DEVICE);
new->parent= start;
new->parent= start;
header_type = pci_config_read8(pci_addr, PCI_HEADER_TYPE);
switch (header_type & 0x7f)
{
case PCI_HEADER_TYPE_BRIDGE:
case PCI_HEADER_TYPE_CARDBUS:
secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS);
if (secondary_bus != 0)
scan_pci_bus(new, secondary_bus);
break;
switch (header_type & 0x7f) {
case PCI_HEADER_TYPE_BRIDGE:
case PCI_HEADER_TYPE_CARDBUS:
secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS);
if (secondary_bus != 0) {
scan_pci_bus(new, secondary_bus);
}
break;
}
*current = new;
current = &new->next;
if ((func == 0) && ((header_type & 0x80) == 0))
if ((func == 0) && ((header_type & 0x80) == 0)) {
break;
}
}
}
}
void enable_pci_devs(void)
{
uint16_t id;
uint32_t rcba, *fd;
id = pci_config_read16(PCIADDR(0, 0x00, 0), 0x00);
/* make sure we're on Intel chipset */
if (id != 0x8086)
return;
rcba = pci_config_read32(PCIADDR(0, 0x1f, 0), 0xf0) & ~1;
fd = (uint32_t *)(rcba + 0x3418);
/* set SMBus Disable (SD) to 0 */
*fd &= ~0x8;
/* and all devices? */
//*fd = 0x1;
}
void build_pci_dt(void)
{
root_pci_dev = malloc(sizeof(pci_dt_t));
if (!root_pci_dev)
return;
bzero(root_pci_dev, sizeof(pci_dt_t));
enable_pci_devs();
scan_pci_bus(root_pci_dev, 0);
#if DEBUG_PCI
dump_pci_dt(root_pci_dev->children);
printf("(Press a key to continue...)\n");
getc();
#endif
}
char dev_path[80];
static char dev_path[256];
char *get_pci_dev_path(pci_dt_t *pci_dt)
{
pci_dt_t *current, *end;
char tmp[30];
pci_dt_t*current;
pci_dt_t*end;
chartmp[64];
dev_path[0] = 0;
end = root_pci_dev;
while (end != pci_dt)
{
while (end != pci_dt) {
current = pci_dt;
while (current->parent != end)
current = current->parent;
while (current->parent != end) {
current = current->parent;
}
end = current;
sprintf(tmp, "%s/Pci(0x%x,0x%x)",
(current->parent == root_pci_dev) ? "PciRoot(0x0)" : "",
current->dev.bits.dev, current->dev.bits.func);
strcat(dev_path, tmp);
}
return dev_path;
}
void dump_pci_dt(pci_dt_t *pci_dt)
{
pci_dt_t *current = pci_dt;
pci_dt_t*current;
while (current)
{
current = pci_dt;
while (current) {
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
current = current->next;
}
}
void lspci(const char *booterParam)
{
if(bootArgs->Video.v_display == VGA_TEXT_MODE)
{
setActiveDisplayPage(1);
clearScreenRows(0, 24);
setCursorPosition(0, 0, 1);
}
dump_pci_dt(root_pci_dev->children);
printf("(Press a key to continue...)");
getc();
if(bootArgs->Video.v_display == VGA_TEXT_MODE)
setActiveDisplayPage(0);
}
int check_vga_nvidia(pci_dt_t *pci_dt)
{
pci_dt_t *current = pci_dt;
while (current)
{
if(current->vendor_id == PCI_CLASS_DISPLAY_VGA)
if(current->class_id == PCI_VENDOR_ID_NVIDIA)
return 1;
check_vga_nvidia(current->children);
current = current->next;
}
return 0;
}
trunk/i386/libsaio/stringTable.c
3333
3434
3535
36
36
3737
38
39
40
41
42
43
44
4538
4639
4740
......
8174
8275
8376
84
77
8578
8679
8780
8881
8982
9083
91
84
9285
9386
9487
......
9790
9891
9992
100
93
10194
10295
10396
......
132125
133126
134127
135
128
136129
137130
138131
139132
140133
141
134
142135
143136
144137
......
198191
199192
200193
201
194
202195
203196
204197
......
208201
209202
210203
211
204
212205
213206
214207
215
208
216209
217210
218211
......
220213
221214
222215
223
216
224217
225218
226219
......
308301
309302
310303
311
304
312305
313306
314307
315
308
316309
317310
318311
......
331324
332325
333326
334
327
335328
336329
337330
338331
339332
340333
334
335
336
337
338
339
340
341
342
343
341344
342345
343346
344347
345
348
346349
347350
348351
349352
350353
351354
352
355
353356
354
357
355358
356
359
357360
358
361
359362
360363
361
364
362365
363366
364367
365
368
366369
367370
368371
......
370373
371374
372375
373
376
374377
375378
376379
......
378381
379382
380383
381
384
382385
383386
384387
......
387390
388391
389392
390
393
391394
392395
393
396
394397
395398
396399
397400
398401
399402
400
403
401404
402405
403406
404407
405408
406409
407
408
410
411
409412
410413
411414
......
413416
414417
415418
416
419
417420
418421
419422
420423
421424
422425
423
426
424427
425428
426429
......
428431
429432
430433
431
434
432435
433436
434437
......
448451
449452
450453
451
454
452455
453456
454457
455
458
456459
457460
458461
459462
460463
461464
462
465
463466
464467
465468
......
470473
471474
472475
473
476
474477
475478
476
479
477480
478481
479
482
480483
481484
482485
483
486
484487
485488
486
489
487490
488491
489492
......
495498
496499
497500
498
501
499502
500503
501
504
502505
503506
504
507
505508
506509
507510
508511
509512
510
513
511514
512515
513516
......
543546
544547
545548
546
549
547550
548551
549552
......
582585
583586
584587
585
586588
587
588
589
590
591
592
593
594
595
589
590
596591
597592
598593
......
632627
633628
634629
635
630
636631
637632
638633
639
634
640635
641636
642637
......
672667
673668
674669
675
670
676671
677672
678673
......
705700
706701
707702
708
703
709704
710705
711706
......
729724
730725
731726
732
727
733728
734729
735730
......
744739
745740
746741
747
742
748743
749744
750745
extern char *Language;
extern char *LoadableFamilies;
int sysConfigValid;
bool sysConfigValid;
//static void eatThru(char val, const char **table_p);
static inline int isspace(char c)
{
return (c == ' ' || c == '\t');
}
/*
* Compare a string to a key with quoted characters
*/
static void eatThru(char val, const char **table_p)
{
register const char *table = *table_p;
register BOOL found = NO;
register bool found = false;
while (*table && !found)
{
if (*table == '\\') table += 2;
else
{
if (*table == val) found = YES;
if (*table == val) found = true;
table++;
}
}
/* Remove key and its associated value from the table. */
BOOL
bool
removeKeyFromTable(const char *key, char *table)
{
register int len;
out:
free(buf);
if(len == -1) return NO;
if(len == -1) return false;
while((*tab = *(tab + len))) {
tab++;
}
return YES;
return true;
}
char *
}
BOOL getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size)
bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size)
{
if (config->dictionary != 0 ) {
// Look up key in XML dictionary
if (value->type != kTagTypeString) {
error("Non-string tag '%s' found in config file\n",
key);
return NO;
return false;
}
*val = value->string;
*size = strlen(value->string);
return YES;
return true;
}
} else {
}
return NO;
return false;
}
#if UNUSED
return line;
}
BOOL getValueForBootKey(const char *line, const char *match, const char **matchval, int *len)
bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len)
{
const char *key, *value;
int key_len, value_len;
BOOL retval = NO;
bool retval = false;
while (*line) {
/* look for keyword or argument */
&& strncmp(match, key, key_len) == 0) {
*matchval = value;
*len = value_len;
retval = YES;
retval = true;
/* Continue to look for this key; last one wins. */
}
}
return retval;
}
/* Return NULL if no option has been successfully retrieved, or the string otherwise */
const char * getStringForKey(const char * key, config_file_t *config)
{
static const char* value =0;
int len=0;
if(!getValueForKey(key, &value, &len, config)) value = 0;
return value;
}
/* Returns TRUE if a value was found, FALSE otherwise.
* The boolean value of the key is stored in 'val'.
*/
BOOL getBoolForKey( const char *key, BOOL *result_val, config_file_t *config )
bool getBoolForKey( const char *key, bool *result_val, config_file_t *config )
{
const char *key_val;
int size;
if (getValueForKey(key, &key_val, &size, config)) {
if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) {
*result_val = YES;
*result_val = true;
} else {
*result_val = NO;
*result_val = false;
}
return YES;
return true;
}
return NO;
return false;
}
BOOL getIntForKey( const char *key, int *value, config_file_t *config )
bool getIntForKey( const char *key, int *value, config_file_t *config )
{
const char *val;
int size, sum;
BOOL negative = NO;
bool negative = false;
if (getValueForKey(key, &val, &size, config))
{
{
if (*val == '-')
{
negative = YES;
negative = true;
val++;
size--;
}
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
return NO;
return false;
sum = (sum * 10) + (*val++ - '0');
}
sum = -sum;
*value = sum;
return YES;
return true;
}
}
return NO;
return false;
}
/*
*
*/
BOOL getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
{
const char *val;
int size = 0;
int sum = 0;
BOOL negative = NO;
BOOL percentage = NO;
bool negative = false;
bool percentage = false;
if (getValueForKey(key, &val, &size, config))
{
{
if (*val == '-')
{
negative = YES;
negative = true;
val++;
size--;
}
if (val[size-1] == '%')
{
percentage = YES;
percentage = true;
size--;
}
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
return NO;
return false;
sum = (sum * 10) + (*val++ - '0');
}
}
*value = (uint16_t) sum;
return YES;
return true;
}
// key not found
return NO;
return false;
}
/*
*get color value from plist format #RRGGBB
*/
BOOL getColorForKey( const char *key, unsigned int *value, config_file_t *config )
bool getColorForKey( const char *key, unsigned int *value, config_file_t *config )
{
const char *val;
int size;
{
val++;
*value = strtol(val, NULL, 16);
return YES;
return true;
}
}
return NO;
return false;
}
BOOL getValueForKey( const char *key, const char **val, int *size, config_file_t *config )
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config )
{
const char *overrideVal;
int overrideSize;
BOOL override, ret;
bool override, ret;
if (getValueForBootKey(bootArgs->CommandLine, key, val, size))
return YES;
return true;
ret = getValueForConfigTableKey(config, key, val, size);
{
if (getValueForConfigTableKey(&bootInfo->overrideConfig, key, &overrideVal, &overrideSize))
{
override = YES;
override = true;
if (ret && (strcmp(key, "Kernel") == 0) && (strcmp(overrideVal, "mach_kernel") == 0))
override = NO;
override = false;
if (ret && (strcmp(key, "Kernel Flags") == 0) && (overrideSize == 0))
override = NO;
override = false;
if (override)
{
*val = overrideVal;
*size = overrideSize;
return YES;
return true;
}
}
}
// (and does not modify dict pointer).
// Prints an error message if there is a parsing error.
//
long ParseXMLFile( char * buffer, TagPtr * dict )
int ParseXMLFile( char * buffer, TagPtr * dict )
{
long length, pos;
TagPtr tag;
int loadConfigFile (const char *configFile, config_file_t *config)
{
int fd, count;
char dirspec[512];
sprintf(dirspec,"%s",configFile);
fd = open(dirspec, 0);
if (fd<0)
{
dirspec[0] = '\0';
sprintf(dirspec,"bt(0,0)%s",configFile);
fd = open(dirspec, 0);
if (fd<0)
return -1;
if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) {
return -1;
}
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid=1;
sysConfigValid = true;
ret=0;
// enable canOverride flag
config->canOverride = TRUE;
config->canOverride = true;
break;
}
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid=1;
sysConfigValid = true;
ret=0;
break;
}
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid=1;
sysConfigValid = true;
ret=0;
break;
}
char * ptr = *argPtr;
const char * strStart;
int len = 0;
BOOL isQuoted = FALSE;
bool isQuoted = false;
*val = '\0';
// Skip the leading double quote character.
if (*ptr == '\"')
{
isQuoted = TRUE;
isQuoted = true;
ptr++;
strStart++;
}
trunk/i386/libsaio/pci.h
3434
3535
3636
37
37
38
39
3840
39
40
41
42
43
44
45
46
47
48
49
50
4151
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
8252
8353
8454
......
826796
827797
828798
829
799
830800
831801
832802
struct pci_dt_t*next;
} pci_dt_t;
#define PCIADDR(bus, dev, func)(1 << 31) | (bus << 16) | (dev << 11) | (func << 8)
#define PCIADDR(bus, dev, func)(1 << 31) | (bus << 16) | (dev << 11) | (func << 8)
#define PCI_ADDR_REG0xcf8
#define PCI_DATA_REG0xcfc
#define PCI_ADDR_REG0xcf8
#define PCI_DATA_REG0xcfc
extern pci_dt_t*root_pci_dev;
extern uint8_tpci_config_read8(uint32_t, uint8_t);
extern uint16_tpci_config_read16(uint32_t, uint8_t);
extern uint32_tpci_config_read32(uint32_t, uint8_t);
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
uint32_t pci_config_read(uint32_t pci_addr, uint8_t reg, uint8_t bytes);
void pci_config_write(uint32_t pci_addr, uint8_t reg, uint32_t data, uint8_t bytes);
static inline uint8_t pci_config_read8(uint32_t pci_addr, uint8_t reg)
{
return (uint8_t)pci_config_read(pci_addr, reg, 1);
}
static inline uint16_t pci_config_read16(uint32_t pci_addr, uint8_t reg)
{
return (uint16_t)pci_config_read(pci_addr, reg, 2);
}
static inline uint32_t pci_config_read32(uint32_t pci_addr, uint8_t reg)
{
return (uint32_t)pci_config_read(pci_addr, reg, 4);
}
static inline void pci_config_write8(uint32_t pci_addr, uint8_t reg, uint8_t data)
{
pci_config_write(pci_addr, reg, data, 1);
}
static inline void pci_config_write16(uint32_t pci_addr, uint8_t reg, uint16_t data)
{
pci_config_write(pci_addr, reg, data, 2);
}
static inline void pci_config_write32(uint32_t pci_addr, uint8_t reg, uint32_t data)
{
pci_config_write(pci_addr, reg, data, 4);
}
extern pci_dt_t *root_pci_dev;
char *get_pci_dev_path(pci_dt_t *pci_dt);
void build_pci_dt(void);
int check_vga_nvidia(pci_dt_t *pci_dt);
//-----------------------------------------------------------------------------
// added by iNDi
#define PCI_CLASS_BRIDGE_HOST0x0600
#define PCI_CLASS_BRIDGE_ISA0x0601
#define PCI_CLASS_BRIDGE_EISA0x0602
#define PCI_CLASS_BRIDGE_MC0x0603
#define PCI_CLASS_BRIDGE_MC0x0603
#define PCI_CLASS_BRIDGE_PCI0x0604
#define PCI_CLASS_BRIDGE_PCMCIA0x0605
#define PCI_CLASS_BRIDGE_NUBUS0x0606
trunk/i386/libsaio/biosfn.c
9999
100100
101101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
102161
103162
104163
......
107166
108167
109168
110
111
112
113
169
170
171
172
173
114174
115175
116176
......
179239
180240
181241
242
243
244
245
246
182247
183248
184249
......
770835
771836
772837
773
774
775
776
838
777839
778
779
840
841
780842
781843
782844
783
845
784846
785
847
786848
787849
788850
return time.i;
}
#if 0
static unsigned long rerangeMemoryMap(unsigned long count)
{
int i, still_changing, newcount = count;
MemoryRange * range = (MemoryRange *)BIOS_ADDR;
struct MemoryRange change_tmp;
/* sort map list by memory addresses (low -> high) */
still_changing = 1;
while (still_changing) {
still_changing = 0;
for (i=1; i<count; i++) {
/* if <current_addr> > <last_addr>, swap */
if (range[i].base < range[i-1].base) {
change_tmp.base = range[i].base;
change_tmp.length = range[i].length;
change_tmp.type = range[i].type;
range[i].base = range[i-1].base;
range[i].length = range[i-1].length;
range[i].type = range[i-1].type;
range[i-1].base = change_tmp.base;
range[i-1].length = change_tmp.length;
range[i-1].type = change_tmp.type;
still_changing=1;
}
}
}
/* clear overlaps */
/* linux's arch/i386/kern/setup.c may have better algorithm */
for (i=1; i<count; i++) {
if ( range[i-1].base + range[i-1].length > range[i].base ) {
range[newcount].base = range[i].base + range[i].length;
range[newcount].length = range[i-1].base + range[i-1].length - range[newcount].base;
range[newcount].type = range[i-1].type;
newcount++;
range[i-1].length = range[i].base - range[i-1].base;
}
}
/*
* 0xb0000000 : 0x10000000 NG
* 0xc0000400 NG
* 0xf2000000 NG
*/
range[newcount].base = 0xb0000000;
range[newcount].length = 0x0f000000;
range[newcount].type = kMemoryRangeUsable;
newcount++;
return newcount;
}
#endif
unsigned long getMemoryMap( MemoryRange * rangeArray,
unsigned long maxRangeCount,
unsigned long * conMemSizePtr,
#define kMemoryMapSignature 'SMAP'
#define kDescriptorSizeMin 20
MemoryRange * range = (MemoryRange *)BIOS_ADDR;
unsigned long count = 0;
unsigned long long conMemSize = 0;
unsigned long long extMemSize = 0;
MemoryRange *range = (MemoryRange *)BIOS_ADDR;
unsigned longcount = 0;
unsigned longrerangedCount;
unsigned long longconMemSize = 0;
unsigned long longextMemSize = 0;
// Prepare for the INT15 E820h call. Each call returns a single
// memory range. A continuation value is returned that must be
*conMemSizePtr = conMemSize / 1024; // size in KB
*extMemSizePtr = extMemSize / 1024; // size in KB
#if 0
rerangedCount = rerangeMemoryMap(count);
range += rerangedCount - count;
#endif
// Copy out data
bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR));
#endif /* APM_SUPPORT */
#ifdef EISA_SUPPORT
BOOL
eisa_present(
void
)
bool eisa_present(void)
{
static BOOL checked;
static BOOL isEISA;
static bool checked = false;
static bool isEISA;
if (!checked) {
if (strncmp((char *)0xfffd9, "EISA", 4) == 0)
isEISA = TRUE;
isEISA = true;
checked = TRUE;
checked = true;
}
return (isEISA);
trunk/i386/libsaio/saio_types.h
3838
3939
4040
41
42
43
44
4541
4642
4743
......
6864
6965
7066
71
67
7268
7369
7470
......
190186
191187
192188
193
194
189
190
195191
196192
197193
#define DEBUG_DISK(x)
#endif
typedef char BOOL;
#define NO 0
#define YES 1
typedef unsigned long entry_t;
typedef struct {
typedef struct {
charplist[4096];// buffer for plist
TagPtrdictionary;// buffer for xml dictionary
BOOL canOverride; // flag to mark a dictionary can be overriden
bool canOverride; // flag to mark a dictionary can be overriden
} config_file_t;
/*
uint32_t modTime;
char label[BVSTRLEN]; /* partition volume label */
char altlabel[BVSTRLEN]; /* partition volume label */
BOOL filtered; /* newFilteredBVChain() will set to TRUE */
BOOL visible; /* will shown in the device list */
bool filtered; /* newFilteredBVChain() will set to TRUE */
bool visible; /* will shown in the device list */
};
enum {
trunk/i386/libsaio/msdos.c
100100
101101
102102
103
104
103
105104
106105
107106
......
118117
119118
120119
121
120
122121
123122
124123
125124
126
125
127126
128127
129128
......
136135
137136
138137
139
138
140139
141140
142141
free(ih);
}
int
MSDOSProbe(const void * buffer)
int MSDOSProbe(const void * buffer)
{
union bootsector *bsp;
struct bpb33 *b33;
/* We only work with 512, 1024, and 2048 byte sectors */
bps = OSSwapLittleToHostInt16(b33->bpbBytesPerSec);
if ((bps < 0x200) || (bps & (bps - 1)) || (bps > 0x800))
return FALSE;
return 0;
/* Check to make sure valid sectors per cluster */
spc = b33->bpbSecPerClust;
if ((spc == 0 ) || (spc & (spc - 1)))
return FALSE;
return 0;
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0) { /* It's FAT32 */
if (!memcmp(((struct extboot *)bsp->bs710.bsExt)->exFileSysType, "FAT32 ", 8))
return 12;
}
return FALSE;
return 0;
}
trunk/i386/libsaio/fake_efi.c
1
12
23
34
......
34
45
5
6
7
68
79
810
911
10
12
1113
1214
......
7981
8082
8183
82
84
8385
8486
8587
......
273275
274276
275277
276
277
278
278
279
280
279281
280282
281283
......
316318
317319
318320
319
320
321
322
323
321
322
323
324
325
326
327
328
324329
325
326
330
331
332
333
327334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
328491
492
493
494
329495
330
331
332
496
497
333498
334
335
336
499
500
501
337502
338503
339504
......
348513
349514
350515
351
516
352517
353518
354519
......
361526
362527
363528
364
529
365530
366531
367532
368533
369
370
534
535
536
537
538
539
371540
372
373
541
542
374543
375
376
377
378
379
380
544
545
546
381547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
382565
383566
384567
385568
386569
570
571
572
573
574
575
576
577
578
579
387580
388581
389582
......
405598
406599
407600
408
601
602
603
604
409605
410606
411607
412608
413609
414
415
610
611
416612
417
418
613
614
419615
616
/*
* Copyright 2007 David F. Elliott. All rights reserved.
*/
#include "libsaio.h"
#include "bootstruct.h" /* for bootArgs */
#include "boot.h"
#include "bootstruct.h"
#include "efi.h"
#include "acpi.h"
#include "fake_efi.h"
#include "efi_tables.h"
#include "freq_detect.h"
#include "platform.h"
#include "dsdt_patcher.h"
#include "smbios_patcher.h"
static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */
/* Default platform system_id (fix by IntVar) */
static EFI_CHAR8 const SYSTEM_ID[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10};//random value gen by uuidgen
static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF";//random value gen by uuidgen
/* Just a ret instruction */
static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3};
*/
/* These should be const but DT__AddProperty takes char* */
static char TSC_Frequency_prop[] = "TSCFrequency";
static char FSB_Frequency_prop[] = "FSBFrequency";
static char CPU_Frequency_prop[] = "CPUFrequency";
static const char const TSC_Frequency_prop[] = "TSCFrequency";
static const char const FSB_Frequency_prop[] = "FSBFrequency";
static const char const CPU_Frequency_prop[] = "CPUFrequency";
/*==========================================================================
* SMBIOS
*/
/* These should be const but DT__AddProperty takes char* */
static char FIRMWARE_REVISION_PROP[] = "firmware-revision";
static char FIRMWARE_ABI_PROP[] = "firmware-abi";
static char FIRMWARE_VENDOR_PROP[] = "firmware-vendor";
static char FIRMWARE_ABI_PROP_VALUE[] = "EFI64";
static char SYSTEM_ID_PROP[] = "system-id";
static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision";
static const char const FIRMWARE_ABI_PROP[] = "firmware-abi";
static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor";
static const char const FIRMWARE_ABI_PROP_VALUE[] = "EFI64";
static const char const SYSTEM_ID_PROP[] = "system-id";
static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber";
static const char const SYSTEM_TYPE_PROP[] = "system-type";
static const char const MODEL_PROP[] = "Model";
void
setupEfiDeviceTree(void)
#define UUID_LEN16
/* Get an smbios option string option to convert to EFI_CHAR16 string */
static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)
{
const char * src= getStringForKey(key, &bootInfo->smbiosConfig);
EFI_CHAR16* dst = 0;
size_t i=0;
if (!key || !(*key) || !len || !src) return 0;
*len = strlen(src);
dst = (EFI_CHAR16*) malloc(((*len)+1)*2);
for (; i<*len; i++) dst[i] = src[i];
dst[*len] = '\0';
return dst;
}
#define DEBUG_SMBIOS 0
/* Get the SystemID from the bios dmi info */
static EFI_CHAR8* getSmbiosUUID()
{
struct SMBEntryPoint*smbios;
struct DMIHeader*dmihdr;
SMBByte*p;
inti, found, isZero, isOnes;
static EFI_CHAR8 uuid[UUID_LEN+1]="";
smbios = getAddressOfSmbiosTable();/* checks for _SM_ anchor and table header checksum */
if (memcmp( &smbios->dmi.anchor[0], "_DMI_", 5) != 0) {
return 0;
}
#if DEBUG_SMBIOS
verbose(">>> SMBIOSAddr=0x%08x\n", smbios);
verbose(">>> DMI: addr=0x%08x, len=0x%d, count=%d\n", smbios->dmi.tableAddress,
smbios->dmi.tableLength, smbios->dmi.structureCount);
#endif
i = 0;
found = 0;
p = (SMBByte *) smbios->dmi.tableAddress;
while (i < smbios->dmi.structureCount && p + 4 <= (SMBByte *)smbios->dmi.tableAddress + smbios->dmi.tableLength) {
dmihdr = (struct DMIHeader *) p;
#if DEBUG_SMBIOS
verbose(">>>>>> DMI(%d): type=0x%02x, len=0x%d\n",i,dmihdr->type,dmihdr->length);
#endif
if (dmihdr->length < 4 || dmihdr->type == 127 /* EOT */) break;
if (dmihdr->type == 1) /* 3.3.2 System Information */
{
if (dmihdr->length >= 0x19) found = 1;
break;
}
p = p + dmihdr->length;
while ((p - (SMBByte *)smbios->dmi.tableAddress + 1 < smbios->dmi.tableLength) && (p[0] != 0x00 || p[1] != 0x00))
{
p++;
}
p += 2;
i++;
}
if (!found) return 0;
verbose("Found SMBIOS System Information Table 1\n");
p += 8;
for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) {
if (p[i] != 0x00) isZero = 0;
if (p[i] != 0xff) isOnes = 0;
}
if (isZero || isOnes) {/* empty or setable means: no uuid present */
verbose("No UUID present in SMBIOS System Information Table\n");
return 0;
}
memcpy(uuid, p, UUID_LEN+1);
return uuid;
}
/* Parse an UUID string into an (EFI_CHAR8*) buffer */
static EFI_CHAR8* getUUIDFromString(const char *source)
{
if (!source) return 0;
char*p = (char *)source;
inti;
charbuf[3];
static EFI_CHAR8 uuid[UUID_LEN+1]="";
buf[2] = '\0';
for (i=0; i<UUID_LEN; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
buf[0] = *p++;
buf[1] = *p++;
uuid[i] = (unsigned char) strtoul(buf, NULL, 16);
if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1) {
p++;
}
}
uuid[UUID_LEN]='\0';
if (*p != '\0') {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
return uuid;
}
// FIXME: can't use my original code here,
// Ironically, trying to reuse convertHexStr2Binary() would RESET the system!
/*
static EFI_CHAR8* getUUIDFromString2(const char * szInUUID)
{
char szUUID[UUID_LEN+1], *p=szUUID;
int size=0;
void* ret;
if (!szInUUID || strlen(szInUUID)<UUID_LEN) return (EFI_CHAR8*) 0;
while(*szInUUID) if (*szInUUID!='-') *p++=*szInUUID++; else szInUUID++;
*p='\0';
ret = convertHexStr2Binary(szUUID, &size);
if (!ret || size!=UUID_LEN)
{
verbose("UUID: cannot convert string <%s> to valid UUID.\n", szUUID);
return (EFI_CHAR8*) 0;
}
return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin
}
*/
/* return a binary UUID value from the overriden SystemID and SMUUID if found,
* or from the bios if not, or from a fixed value if no bios value is found
*/
static EFI_CHAR8* getSystemID()
{// unable to determine UUID for host. Error: 35 fix
const char * sysId = getStringForKey("SystemID", &bootInfo->bootConfig);
EFI_CHAR8* ret = getUUIDFromString(sysId);
if(!sysId || !ret) // try smbios.plist SMUUID override
ret=getUUIDFromString((sysId = getStringForKey("SMUUID",&bootInfo->smbiosConfig)));
if(!sysId || !ret) { // try bios dmi info UUID extraction
ret = getSmbiosUUID();
sysId=0;
}
if(!ret) // no bios dmi UUID available, set a fixed value for system-id
ret=getUUIDFromString((sysId = (const char*) SYSTEM_ID));
verbose("Customizing SystemID with : %s\n", sysId ? sysId :"BIOS internal UUID");
return ret;
}
void setupEfiDeviceTree(void)
{
EFI_CHAR16* ret16=0;
EFI_CHAR8* ret=0;
size_t len=0;
Node *node;
EFI_CHAR8 SystemType=1;
const char *value;
node = DT__FindNode("/", false);
if (node == 0) {
stop("Couldn't get root node");
}
if (node == 0) stop("Couldn't get root node");
/* We could also just do DT__FindNode("/efi/platform", true)
* But I think eventually we want to fill stuff in the efi node
* too so we might as well create it so we have a pointer for it too.
/* We could also just do DT__FindNode("/efi/platform", true)
* But I think eventually we want to fill stuff in the efi node
* too so we might as well create it so we have a pointer for it too.
*/
node = DT__AddChild(node, "efi");
Node *runtimeServicesNode = DT__AddChild(node, "runtime-services");
/* The value of the table property is the 32-bit physical address for the RuntimeServices table.
* Sice the EFI system table already has a pointer to it, we simply use the address of that pointer
* Since the EFI system table already has a pointer to it, we simply use the address of that pointer
* for the pointer to the property data. Warning.. DT finalization calls free on that but we're not
* the only thing to use a non-malloc'd pointer for something in the DT
*/
/* Now fill in the /efi/platform Node */
Node *efiPlatformNode = DT__AddChild(node, "platform");
/* NOTE WELL: If you do add FSB Frequency detection, make sure to store
* the value in the fsbFrequency global and not an malloc'd pointer
* because the DT_AddProperty function does not copy its args.
*/
if(fsbFrequency != 0)
DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &fsbFrequency);
if(Platform.CPU.FSBFrequency != 0)
DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &Platform.CPU.FSBFrequency);
/* Export TSC and CPU frequencies for use by the kernel or KEXTs */
if(Platform.CPU.TSCFrequency != 0)
DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &Platform.CPU.TSCFrequency);
// unable to determine UUID for host. Error: 35 fix
DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, sizeof(SYSTEM_ID), (EFI_UINT32*)&SYSTEM_ID);
if(Platform.CPU.CPUFrequency != 0)
DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency);
/* Export TSC and CPU frequencies for use by the kernel or KEXTs
*/
if(tscFrequency != 0)
DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &tscFrequency);
if(cpuFrequency != 0)
DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &cpuFrequency);
/* Export system-id. Can be disabled with system-id=No in com.apple.Boot.plist */
if((ret=getSystemID()))
DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret);
/* Export system-type. Allowed values are: 0x01 for desktop computer (default), 0x02 for portable computers */
if ((value=getStringForKey("system-type", &bootInfo->bootConfig))) {
if (*value != '1' && *value != '2')
verbose("Error: system-type must be 1 (desktop) or 2 (portable). Defaulting to 1!\n");
else
SystemType = (unsigned char) (*value-'0');
}
DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(EFI_CHAR8), &SystemType);
/* Export SystemSerialNumber if present */
if ((ret16=getSmbiosChar16("SMserial", &len)))
DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, ret16);
/* Export Model if present */
if ((ret16=getSmbiosChar16("SMproductname", &len)))
DT__AddProperty(efiPlatformNode, MODEL_PROP, len, ret16);
/* Fill /efi/device-properties node.
*/
setupDeviceProperties(node);
}
/* Load the smbios.plist override config file if any */
static void setupSmbiosConfigFile()
{
const char * value = getStringForKey(kSMBIOS, &bootInfo->bootConfig);
if (!value) value = "/Extra/smbios.plist";
if (loadConfigFile(value, &bootInfo->smbiosConfig) == -1) {
verbose("No SMBIOS replacement found\n");
}
}
/* Installs all the needed configuration table entries */
void setupEfiConfigurationTable()
{
/* Entrypoint from boot.c */
void setupFakeEfi(void)
{
// Generate efi device strings
// load smbios.plist file if any
setupSmbiosConfigFile();
// Generate efi device strings
setupEfiDevices();
// Initialize the base table
setupEfiTables();
// Initialize the device tree
setupEfiDeviceTree();
// Initialize the device tree
setupEfiDeviceTree();
// Add configuration table entries to both the services table and the device tree
setupEfiConfigurationTable();
// Add configuration table entries to both the services table and the device tree
setupEfiConfigurationTable();
}
trunk/i386/libsaio/misc.c
108108
109109
110110
111
112
113
114
115
116
117
118
119
120
121
122111
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158112
159113
160
114
161115
162116
163117
164118
165119
166
167120
168
flushKeyboardInputBuffer();
}
static inline void
do_cpuid(uint32_t selector, uint32_t *data)
{
asm volatile ("cpuid"
: "=a" (data[0]),
"=b" (data[1]),
"=c" (data[2]),
"=d" (data[3])
: "a"(selector));
}
//==========================================================================
// Check to see that this is a supported hardware configuration.
// If this hardware is supported, return 0.
// If this hardware is not supported, return an error code.
int
checkForSupportedHardware()
{
uint32_t cpuid_result[4];
do_cpuid(1, cpuid_result);
if ((cpuid_result[3] & 0x04000000) == 0) {
// Missing SSE2
return 2;
}
return 0;
}
#ifndef BOOT1
cpu_type_t
detectCpuType ()
{
uint32_tcpuid_reg[4];
do_cpuid(0, cpuid_reg);
if (!memcmp(cpuid_reg+1,"GenuntelineI",12))
{
do_cpuid(0x80000001, cpuid_reg);
if (cpuid_reg[3]&(1<<29))
return CPU_TYPE_X86_64;
}
return CPU_TYPE_I386;
}
//==========================================================================
// Return the platform name for this hardware.
//
#ifndef BOOT1
void
getPlatformName(char *nameBuf)
{
strcpy(nameBuf, "ACPI");
}
#endif
trunk/i386/libsaio/saio_internal.h
3939
4040
4141
42
42
4343
4444
4545
......
8686
8787
8888
89
90
89
90
9191
9292
9393
......
123123
124124
125125
126
126
127127
128128
129129
......
144144
145145
146146
147
148
147
148
149149
150150
151
152
153
154
155
156
151
152
153
154
155
156
157
157158
158159
159160
160161
161162
162163
163
164
164165
165166
166167
......
177178
178179
179180
181
180182
181183
182184
......
193195
194196
195197
196
198
197199
198200
199201
/* biosfn.c */
#ifdef EISA_SUPPORT
extern BOOL eisa_present(void);
extern bool eisa_present(void);
#endif
extern int bgetc(void);
extern int biosread(int dev, int cyl, int head, int sec, int num);
long length, long cache);
/* console.c */
extern BOOL gVerboseMode;
extern BOOL gErrors;
extern bool gVerboseMode;
extern bool gErrors;
extern void putchar(int ch);
extern int getchar(void);
extern int printf(const char *format, ...);
u_int16_t *ucslen, u_int32_t bufsize, int byte_order );
/* load.c */
extern char gHaveKernelCache;
extern bool gHaveKernelCache;
extern long ThinFatFile(void **binary, unsigned long *length);
extern long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize);
/* stringTable.c */
extern char * newStringFromList(char **list, int *size);
extern int stringLength(const char *table, int compress);
extern BOOL getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size);
extern BOOL removeKeyFromTable(const char *key, char *table);
extern bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size);
extern bool removeKeyFromTable(const char *key, char *table);
extern char * newStringForStringTableKey(config_file_t *config, char *key);
extern char * newStringForKey(char *key, config_file_t *configBuff);
extern BOOL getValueForBootKey(const char *line, const char *match, const char **matchval, int *len);
extern BOOL getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff);
extern BOOL getBoolForKey(const char *key, BOOL *val, config_file_t *configBuff);
extern BOOL getIntForKey(const char *key, int *val, config_file_t *configBuff);
extern BOOL getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff);
extern BOOL getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size );
extern bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len);
extern bool getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff);
extern const char * getStringForKey(const char * key, config_file_t *config);
extern bool getBoolForKey(const char *key, bool *val, config_file_t *configBuff);
extern bool getIntForKey(const char *key, int *val, config_file_t *configBuff);
extern bool getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff);
extern bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size );
extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
extern int loadSystemConfig(config_file_t *configBuff);
extern int loadHelperConfig(config_file_t *configBuff);
extern int loadOverrideConfig(config_file_t *configBuff);
extern char * newString(const char *oldString);
extern char * getNextArg(char ** ptr, char * val);
extern long ParseXMLFile( char * buffer, TagPtr * dict );
extern int ParseXMLFile( char * buffer, TagPtr * dict );
/* sys.c */
extern BVRef getBootVolumeRef( const char * path, const char ** outPath );
extern long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr);
extern int openmem(char *buf, int len);
extern int open(const char *str, int how);
extern int open_bvdev(const char *bvd, const char *path, int flags);
extern int close(int fdesc);
extern int file_size(int fdesc);
extern int read(int fdesc, char *buf, int count);
extern void scanBootVolumes(int biosdev, int *count);
extern void scanDisks(int biosdev, int *count);
extern BVRef selectBootVolume(BVRef chain);
extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, BOOL verbose);
extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose);
extern void setRootVolume(BVRef volume);
extern void setBootGlobals(BVRef chain);
trunk/i386/boot0/boot0.s
5555
5656
5757
58
58
5959
6060
6161
;
; Set to 1 to enable verbose mode
;
VERBOSEEQU 1
VERBOSEEQU 0
;
; Various constants.
trunk/i386/boot2/ramdisk.h
1818
1919
2020
21
21
2222
23
23
2424
2525
2626
2727
28
28
//
extern BVRef gRAMDiskVolume;
extern BOOL gRAMDiskBTAliased;
extern bool gRAMDiskBTAliased;
extern void setRAMDiskBTHook(BOOL mode);
extern void setRAMDiskBTHook(bool mode);
extern int mountRAMDisk(const char * param);
extern void processRAMDiskCommand(char ** argPtr, const char * cmd);
extern int loadPrebootRAMDisk();
#endif /* !__BOOT_RAMDISK_H */
#endif /* !__BOOT_RAMDISK_H */
trunk/i386/boot2/picopng.c
290290
291291
292292
293
293
294294
295295
296296
......
339339
340340
341341
342
342
343343
344344
345345
......
908908
909909
910910
911
912
911
912
913913
914914
915915
......
941941
942942
943943
944
944
945945
946946
947947
......
968968
969969
970970
971
971
972972
973973
974974
......
976976
977977
978978
979
979
980980
981981
982982
......
994994
995995
996996
997
997
998998
999999
10001000
return 0;
}
int HuffmanTree_decode(const HuffmanTree *tree, boolean_t *decoded, uint32_t *result, size_t *treepos,
int HuffmanTree_decode(const HuffmanTree *tree, bool *decoded, uint32_t *result, size_t *treepos,
uint32_t bit)
{// Decodes a symbol from the tree
const vector32_t *tree2d = tree->tree2d;
uint32_t Inflator_huffmanDecodeSymbol(const uint8_t *in, size_t *bp, const HuffmanTree *codetree,
size_t inlength)
{// decode a single symbol from given list of bits with given code tree. returns the symbol
boolean_t decoded = FALSE;
bool decoded = false;
uint32_t ct = 0;
size_t treepos = 0;
for (;;) {
return NULL;
size_t pos = 33; // first byte of the first chunk after the header
vector8_t *idat = NULL; // the data from idat chunks
boolean_t IEND = FALSE, known_type = TRUE;
info->key_defined = FALSE;
bool IEND = false, known_type = true;
info->key_defined = false;
// loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is
// put at the start of the in buffer
while (!IEND) {
pos += (4 + chunkLength);
} else if (chunkType == CHUNK_IEND) { // IEND
pos += 4;
IEND = TRUE;
IEND = true;
} else if (chunkType == CHUNK_PLTE) { // PLTE: palette chunk
pos += 4; // go after the 4 letters
vector8_resize(info->palette, 4 * (chunkLength / 3));
PNG_error = 40; // error: this chunk must be 2 bytes for greyscale image
return NULL;
}
info->key_defined = TRUE;
info->key_defined = true;
info->key_r = info->key_g = info->key_b = 256 * in[pos] + in[pos + 1];
pos += 2;
} else if (info->colorType == 2) {
PNG_error = 41; // error: this chunk must be 6 bytes for RGB image
return NULL;
}
info->key_defined = TRUE;
info->key_defined = true;
info->key_r = 256 * in[pos] + in[pos + 1];
pos += 2;
info->key_g = 256 * in[pos] + in[pos + 1];
return NULL;
}
pos += (chunkLength + 4); // skip 4 letters and uninterpreted data of unimplemented chunk
known_type = FALSE;
known_type = false;
}
pos += 4; // step over CRC (which is ignored)
}
trunk/i386/boot2/resume.c
140140
141141
142142
143
143
144144
145145
146146
......
170170
171171
172172
173
173
174
175
176
177
178
179
180
174181
175182
176183
......
206213
207214
208215
209
216
printf("mem_base %x\n", mem_base);
if (!((long long)mem_base + allocSize < 1024 * bootInfo->extmem + 0x100000))
if (!(long long)mem_base+allocSize<1024*bootInfo->extmem+0x100000)
{
printf ("Not enough space to restore image. Press any key to proceed with normal boot.\n");
getc ();
previewTotalSectors = 0;
previewLoadedSectors = 0;
previewSaveunder = 0;
if(check_vga_nvidia(root_pci_dev) ==1 ) setVideoMode( VGA_TEXT_MODE, 0 );
#if 0
AsereBLN:
check_vga_nvidia() didn't work as expected (recursion level > 0 & return value).
Unforutnaltely I cannot find a note why to switch back to text mode for nVidia cards only
and because it check_vga_nvidia does not work (cards normally are behind a bridge) I will
remove it completely
setVideoMode( VGA_TEXT_MODE, 0 );
#endif
}
else
ReadFileAtOffset (image_filename, (char *)buffer, sizeof(IOHibernateImageHeader), imageSize);
#endif
WakeKernel(header);
}
}
trunk/i386/boot2/graphics.c
349349
350350
351351
352
352
353353
354354
355355
......
515515
516516
517517
518
518
519519
520520
521521
......
587587
588588
589589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626590
627591
628592
......
10761040
10771041
10781042
1079
1080
10811043
10821044
10831045
......
10921054
10931055
10941056
1095
1057
10961058
10971059
10981060
unsigned char value;
} * bp = (struct RLEBlock *) rleData;
out = cp = (char *) malloc( outBytes );
out = cp = malloc( outBytes );
if ( out == NULL ) return NULL;
while ( rleBlocks-- )
PNG_info_t *info;
int error = 0;
pngFile = open(filename, 0);
pngFile = open_bvdev("bt(0,0)", filename, 0);
if (pngFile == -1) {
error = -1;
goto failed;
return error;
}
int loadPixmapFromPng(const char *filename, pixmap_t *p)
{
uint16_t width=0,height=0;
uint8_t *imagedata = 0;
pixmap_t *pm=malloc(sizeof(pixmap_t));
if(!pm) return 0;
if((loadPngImage(filename, &width, &height, &imagedata))!=0) return 0;
pm->width = width;
pm->height = height;
pm->pixels = (pixel_t *)imagedata;
flipRB(pm);
*p=*pm;
return 1;
}
int loadPixmapFromEmbeddedPng(uint8_t *pngData, uint32_t pngSize, pixmap_t *p)
{
uint16_t width=0,height=0;
uint8_t *imagedata = 0;
pixmap_t *pm=malloc(sizeof(pixmap_t));
if(!pm) return 0;
if((loadEmbeddedPngImage(pngData, pngSize, &width, &height, &imagedata))!=0) return 0;
pm->width = width;
pm->height = height;
pm->pixels = (pixel_t *)imagedata;
flipRB(pm);
*p=*pm;
return 1;
}
void blendImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
uint8_t *data)
{
char * propStr;
unsigned long count = 0;
#define _isdigit(c) ((c) >= '0' && (c) <= '9')
propStr = newStringForKey( (char *) propKey , &bootInfo->bootConfig );
if ( propStr )
{
numbers[count++] = val;
p = delimiter;
}
while ( ( *p != '\0' ) && !_isdigit(*p) )
while ( ( *p != '\0' ) && !isdigit(*p) )
p++;
}
trunk/i386/boot2/boot.c
5757
5858
5959
60
6061
6162
62
63
6364
6465
6566
6667
6768
6869
69
70
70
71
7172
7273
7374
......
7677
7778
7879
79
80
8081
8182
83
8284
83
84
8585
86
8687
87
88
8988
9089
9190
......
10099
101100
102101
103
102
104103
105
106
104
105
107106
108
109
110
111
112
107
108
113109
114110
115111
116112
117113
118
114
119115
120
121
122
116
123117
124118
125
126
127
128
119
120
121
122
129123
130
131
132
133
124
125
134126
135127
136128
......
182174
183175
184176
185
186
187
188
189
190
177
178
179
180
191181
192182
193183
......
211201
212202
213203
214
215
216
217
218
219
220
221
222
223
224
225
226
227
204
205
206
228207
229208
230
231
232
233
234
235
209
210
211
212
236213
237214
238215
......
246223
247224
248225
249
250
251
252226
253227
254228
255229
256230
257
258
259
260
231
232
233
234
261235
262236
263237
264238
265239
240
266241
267
268
269242
270
271243
272244
273245
274
275246
276247
277248
278249
279250
280
281251
282252
283253
......
286256
287257
288258
289
290
291
292
293
259
260
294261
295262
296263
......
300267
301268
302269
303
270
304271
305272
306273
307274
308
309
275
276
310277
311278
312279
313280
314281
315282
316
283
317284
318285
319
320
286
287
321288
322289
323290
324
325
326
291
292
327293
328294
329295
330296
331
332
297
298
333299
334300
335301
336
337
338
339
302
303
304
305
306
340307
341308
342309
......
349316
350317
351318
352
353
354
355
356
357
358
359
360
361
362
363
364
319
320
321
322
323
324
325
365326
366327
367
328
368329
369
370
330
371331
372332
373333
374334
375335
376336
377
378
379
337
338
339
380340
381341
382342
......
385345
386346
387347
388
389
348
349
390350
391351
392
352
393353
394354
395355
......
422382
423383
424384
425
426
427
428
385
386
387
388
429389
430390
431391
432392
433393
434
435
436
394
395
437396
438397
439398
440399
441400
442
443
444
445
446
447
448
449
450401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
451416
452
453
454
455
417
418
419
420
421
456422
457
458
459423
460
461
424
425
426
462427
463
464
465
466
428
429
430
467431
468432
469433
470434
471435
472
436
473437
474438
475439
......
485449
486450
487451
488
489
452
490453
491454
492455
......
502465
503466
504467
505
468
506469
507470
508471
......
510473
511474
512475
513
476
514477
515478
516479
......
593556
594557
595558
596
597
559
598560
599561
600
601
562
602563
603564
604
605
565
566
606567
607
608
609
568
610569
611
570
612571
613572
614
615573
616574
617575
618576
619
620
577
621578
622579
623
624
580
581
625582
583
584
626585
627586
628587
#include "libsa.h"
#include "ramdisk.h"
#include "gui.h"
#include "platform.h"
long gBootMode; /* defaults to 0 == kBootModeNormal */
BOOL gOverrideKernel;
bool gOverrideKernel;
static char gBootKernelCacheFile[512];
static char gCacheNameAdler[64 + 256];
char *gPlatformName = gCacheNameAdler;
char gRootDevice[512];
char gMKextName[512];
char gMacOSVersion[8];
BOOL gEnableCDROMRescan;
BOOL gScanSingleDrive;
bool gEnableCDROMRescan;
bool gScanSingleDrive;
int bvCount = 0;
//intmenucount = 0;
BVRef bvr;
BVRef menuBVR;
BVRef bvChain;
BOOL useGUI = TRUE;
bool useGUI;
//static void selectBiosDevice(void);
static unsigned long Adler32(unsigned char *buffer, long length);
static
unsigned long Adler32(unsigned char *buffer, long length);
static bool gUnloadPXEOnExit = false;
static BOOL gUnloadPXEOnExit = 0;
/*
* How long to wait (in seconds) to load the
* kernel after displaying the "boot:" prompt.
//==========================================================================
// Zero the BSS.
static void zeroBSS()
static void zeroBSS(void)
{
extern char _DATA__bss__begin, _DATA__bss__end;
extern char _DATA__common__begin, _DATA__common__end;
extern char _DATA__bss__begin, _DATA__bss__end;
extern char _DATA__common__begin, _DATA__common__end;
bzero( &_DATA__bss__begin,
(&_DATA__bss__end - &_DATA__bss__begin) );
bzero( &_DATA__common__begin,
(&_DATA__common__end - &_DATA__common__begin) );
bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));
bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));
}
//==========================================================================
// Malloc error function
static void malloc_error(char *addr, size_t size)
static void malloc_error(char *addr, size_t size, const char *file, int line)
{
printf("\nMemory allocation error (0x%x, 0x%x)\n",
(unsigned)addr, (unsigned)size);
asm volatile ("hlt");
stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);
}
/*!
Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
*/
void initialize_runtime()
//==========================================================================
//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
//
void initialize_runtime(void)
{
zeroBSS();
// Initialize malloc
malloc_init(0, 0, 0, malloc_error);
zeroBSS();
malloc_init(0, 0, 0, malloc_error);
}
//==========================================================================
}
}
BOOL dummyVal;
if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal)
{
printf("Press any key to continue...");
getc();
bool dummyVal;
if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {
printf("Press any key to continue...");
getc();
}
// If we were in text mode, switch to graphics mode.
}
//==========================================================================
// Scan and record the system's hardware information.
static void scanHardware()
{
extern void scan_platform();
scan_platform();
}
/*!
This is the entrypoint from real-mode which functions exactly as it did before.
Multiboot does its own runtime initialization, does some of its own things, and then
calls common_boot.
*/
// This is the entrypoint from real-mode which functions exactly as it did
// before. Multiboot does its own runtime initialization, does some of its
// own things, and then calls common_boot.
void boot(int biosdev)
{
initialize_runtime();
// Enable A20 gate before accessing memory above 1Mb.
enableA20();
return common_boot(biosdev);
initialize_runtime();
// Enable A20 gate before accessing memory above 1Mb.
enableA20();
common_boot(biosdev);
}
//==========================================================================
// If biosdev is kBIOSDevNetwork, then this function will return if
// booting was unsuccessful. This allows the PXE firmware to try the
// next boot device on its list.
#define DLOG(x) outb(0x80, (x))
void common_boot(int biosdev)
{
int status;
char *bootFile;
unsigned long adler32;
BOOL quiet;
BOOL firstRun = YES;
BOOL instantMenu;
BOOL rescanPrompt;
bool quiet;
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
unsigned int denyBVFlags = kBVFlagEFISystem;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
gUnloadPXEOnExit = true;
gUnloadPXEOnExit = 1;
// Record the device that the booter was loaded from.
gBIOSDev = biosdev & kBIOSDevMask;
// Initialize boot info structure.
initKernBootStruct();
// Setup VGA text mode.
// Not sure if it is safe to call setVideoMode() before the
// config table has been loaded. Call video_mode() instead.
#if DEBUG
printf("before video_mode\n");
#endif
printf("after video_mode\n");
#endif
// Check to see that this hardware is supported.
status = checkForSupportedHardware();
if (status != 0) {
printf("This hardware configuration is not supported by Darwin/x86. (%d)", status);
}
// Scan and record the system's hardware information.
scan_platform();
// First get info for boot volume.
scanBootVolumes(gBIOSDev, 0);
// Load boot.plist config file
status = loadSystemConfig(&bootInfo->bootConfig);
if ( getBoolForKey( kQuietBootKey, &quiet, &bootInfo->bootConfig ) && quiet ) {
if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
gBootMode |= kBootModeQuiet;
}
// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config
if ( getBoolForKey( kInsantMenuKey, &instantMenu, &bootInfo->bootConfig ) && instantMenu ) {
firstRun = FALSE;
if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) {
firstRun = false;
}
// Loading preboot ramdisk if exists.
loadPrebootRAMDisk();
// Disable rescan option by default
gEnableCDROMRescan = FALSE;
gEnableCDROMRescan = false;
// Enable it with Rescan=y in system config
if ( getBoolForKey( kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig ) && gEnableCDROMRescan ) {
gEnableCDROMRescan = TRUE;
if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) {
gEnableCDROMRescan = true;
}
// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
rescanPrompt = FALSE;
if ( getBoolForKey( kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig ) && rescanPrompt
&& biosDevIsCDROM(gBIOSDev) ) {
rescanPrompt = false;
if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) {
gEnableCDROMRescan = promptForRescanOption();
}
// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.
if ( getBoolForKey( kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig ) && gScanSingleDrive ) {
gScanSingleDrive = TRUE;
if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) {
gScanSingleDrive = true;
}
// Create a list of partitions on device(s).
if (gScanSingleDrive)
scanBootVolumes( gBIOSDev, &bvCount );
else
scanDisks( gBIOSDev, &bvCount );
if (gScanSingleDrive) {
scanBootVolumes(gBIOSDev, &bvCount);
} else {
scanDisks(gBIOSDev, &bvCount);
}
// Create a separated bvr chain using the specified filters.
bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
getc();
#endif
// Scan hardware configuration.
scanHardware();
// Check if GUI=n switch is present in config file
if ( getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig) && !useGUI )
useGUI = FALSE;
// Try initialising the GUI unless disabled
if( useGUI )
initGUI();
// Load boot logo image
loadBootGraphics();
useGUI = true;
// Override useGUI default
getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig);
if (useGUI) {
/* XXX AsereBLN handle error */
initGUI();
}
setBootGlobals(bvChain);
// Parse args, load and start kernel.
while (1)
{
while (1) {
const char *val;
int len;
int trycache;
long flags, cachetime, kerneltime, exttime, sleeptime, time;
int ret = -1;
void *binary = (void *)kLoadAddr;
BOOL tryresume;
BOOL tryresumedefault;
BOOL forceresume;
bool tryresume;
bool tryresumedefault;
bool forceresume;
config_file_t systemVersion;// system.plist of booting partition
// Initialize globals.
sysConfigValid = 0;
gErrors = 0;
sysConfigValid = false;
gErrors = false;
status = getBootOptions(firstRun);
firstRun = NO;
firstRun = false;
if (status == -1) continue;
status = processBootOptions();
// Turn off any GUI elements
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
gui.devicelist.draw = NO;
gui.bootprompt.draw = NO;
gui.menu.draw = NO;
gui.infobox.draw = NO;
gui.devicelist.draw = false;
gui.bootprompt.draw = false;
gui.menu.draw = false;
gui.infobox.draw = false;
drawBackground();
updateVRAM();
}
// Find out which version mac os we're booting.
if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion) )
if (getValueForKey("ProductVersion", &val, &len, &systemVersion))
{
if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion)) {
if (getValueForKey(kProductVersion, &val, &len, &systemVersion)) {
// getValueForKey uses const char for val
// so copy it and trim
strncpy(gMacOSVersion, val, MIN(len, 4));
gMacOSVersion[MIN(len, 4)] = '\0';
}
archCpuType=detectCpuType ();
if (getValueForKey("arch", &val, &len, &bootInfo->bootConfig))
{
if(strncmp(val,"x86_64",6) == 0)
archCpuType=CPU_TYPE_X86_64;
else
archCpuType=CPU_TYPE_I386;
}
if (platformCPUFeature(CPU_FEATURE_EM64T)) {
archCpuType = CPU_TYPE_X86_64;
} else {
archCpuType = CPU_TYPE_I386;
}
if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) {
if (strncmp(val, "i386", 4) == 0) {
archCpuType = CPU_TYPE_I386;
}
}
if (getValueForKey(k32BitModeFlag, &val, &len, &bootInfo->bootConfig)) {
archCpuType = CPU_TYPE_I386;
}
if (!getBoolForKey ("Wake", &tryresume, &bootInfo->bootConfig))
{
tryresume = TRUE;
tryresumedefault = TRUE;
if (!getBoolForKey (kWake, &tryresume, &bootInfo->bootConfig)) {
tryresume = true;
tryresumedefault = true;
} else {
tryresumedefault = false;
}
else
tryresumedefault = FALSE;
if (!getBoolForKey ("ForceWake", &forceresume, &bootInfo->bootConfig))
forceresume = FALSE;
if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->bootConfig)) {
forceresume = false;
}
if (forceresume)
{
tryresume = TRUE;
tryresumedefault = FALSE;
if (forceresume) {
tryresume = true;
tryresumedefault = false;
}
while (tryresume) {
const char *tmp;
BVRef bvr;
if (!getValueForKey("WakeImage", &val, &len, &bootInfo->bootConfig))
if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->bootConfig))
val="/private/var/vm/sleepimage";
// Do this first to be sure that root volume is mounted
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
break;
if (!forceresume && sleeptime+3<bvr->modTime)
{
if (!forceresume && sleeptime+3<bvr->modTime) {
printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",bvr->modTime-sleeptime);
break;
}
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig) == YES) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
strlcpy(gBootKernelCacheFile, val, len+1);
} else {
sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32);
// Check for cache file.
trycache = (((gBootMode & kBootModeSafe) == 0) &&
(gOverrideKernel == NO) &&
!gOverrideKernel &&
(gBootFileType == kBlockDeviceType) &&
(gMKextName[0] == '\0') &&
(gBootKernelCacheFile[0] != '\0'));
sleep(8);
#endif
if (ret <= 0)
{
if (ret <= 0) {
printf("Can't find %s\n", bootFile);
if(gui.initialised == YES)
{
if(gui.initialised) {
sleep(1);
drawBackground();
gui.devicelist.draw = YES;
gui.redraw = YES;
gui.devicelist.draw = true;
gui.redraw = true;
}
if ( gBootFileType == kNetworkDeviceType )
{
if (gBootFileType == kNetworkDeviceType) {
// Return control back to PXE. Don't unload PXE base code.
gUnloadPXEOnExit = 0;
gUnloadPXEOnExit = false;
break;
}
} else {
/* Won't return if successful. */
ret = ExecKernel(binary);
}
} /* while(1) */
}
// chainboot
if(status==1)
if(getVideoMode() == GRAPHICS_MODE) // if we are already in graphics-mode,
if (status==1) {
if (getVideoMode() == GRAPHICS_MODE) {// if we are already in graphics-mode,
setVideoMode(VGA_TEXT_MODE, 0);// switch back to text mode
}
}
if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {
nbpUnloadBaseCode();
trunk/i386/boot2/picopng.h
2020
2121
2222
23
23
2424
2525
2626
uint32_t colorType, bitDepth;
uint32_t compressionMethod, filterMethod, interlaceMethod;
uint32_t key_r, key_g, key_b;
boolean_t key_defined; // is a transparent color key given?
bool key_defined; // is a transparent color key given?
vector8_t *palette;
vector8_t *image;
} PNG_info_t;
trunk/i386/boot2/graphics.h
1919
2020
2121
22
23
2422
2523
2624
......
4442
4543
4644
47
45
#define DEFAULT_SCREEN_HEIGHT 768
int loadPngImage(const char *filename, uint16_t *width, uint16_t *height, uint8_t **imageData);
int loadPixmapFromPng(const char *filename, pixmap_t *p);
int loadPixmapFromEmbeddedPng(uint8_t *pngData, uint32_t pngSize, pixmap_t *p);
unsigned long lookUpCLUTIndex( unsigned char index, unsigned char depth );
char *getVBEModeInfoString();
void getGraphicModeParams(unsigned long params[]);
#endif /* !__BOOT_GRAPHICS_H */
#endif /* !__BOOT_GRAPHICS_H */
trunk/i386/boot2/boot.h
3434
3535
3636
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
6189
6290
6391
64
6592
66
67
68
69
70
93
94
95
96
97
98
7199
72100
73101
......
81109
82110
83111
84
112
85113
86114
87
115
88116
89117
90118
91
92
93
119
120
121
94122
95
123
124
125
96126
97127
98128
......
106136
107137
108138
109
110139
111140
112141
......
148177
149178
150179
151
180
152181
153182
154
183
155184
156185
157186
......
184213
185214
186215
187
188
216
189217
190218
/*
* Keys used in system Boot.plist
*/
#define kGraphicsModeKey "Graphics Mode"
#define kTextModeKey "Text Mode"
#define kQuietBootKey "Quiet Boot"
#define kKernelFlagsKey "Kernel Flags"
#define kMKextCacheKey "MKext Cache"
#define kKernelNameKey "Kernel"
#define kKernelCacheKey "Kernel Cache"
#define kBootDeviceKey "Boot Device"
#define kTimeoutKey "Timeout"
#define kRootDeviceKey "rd"
#define kBootUUIDKey "boot-uuid"
#define kHelperRootUUIDKey "Root UUID"
#define kPlatformKey "platform"
#define kACPIKey "acpi"
#define kCDROMPromptKey "CD-ROM Prompt"
#define kCDROMOptionKey "CD-ROM Option Key"
#define kRescanPromptKey "Rescan Prompt"
#define kRescanKey "Rescan"
#define kScanSingleDriveKey "Scan Single Drive"
#define kInsantMenuKey "Instant Menu"
#define kDefaultKernel "mach_kernel"
#define kGUIKey "GUI"
#define kBootBannerKey "Boot Banner"
#define kWaitForKeypressKey "Wait"
#define kGraphicsModeKey"Graphics Mode"
#define kTextModeKey"Text Mode"
#define kQuietBootKey"Quiet Boot"
#define kKernelFlagsKey"Kernel Flags"
#define kMKextCacheKey"MKext Cache"
#define kKernelNameKey"Kernel"
#define kKernelCacheKey"Kernel Cache"
#define kBootDeviceKey"Boot Device"
#define kTimeoutKey"Timeout"
#define kRootDeviceKey"rd"
#define kBootUUIDKey"boot-uuid"
#define kHelperRootUUIDKey"Root UUID"
#define kPlatformKey"platform"
#define kACPIKey"acpi"
#define kCDROMPromptKey"CD-ROM Prompt"
#define kCDROMOptionKey"CD-ROM Option Key"
#define kRescanPromptKey"Rescan Prompt"
#define kRescanKey"Rescan"
#define kScanSingleDriveKey"Scan Single Drive"
#define kInsantMenuKey"Instant Menu"
#define kDefaultKernel"mach_kernel"
#define kGUIKey"GUI"
#define kBootBannerKey"Boot Banner"
#define kWaitForKeypressKey"Wait"
/* AsereBLN: added the other keys */
#define kUseAtiROM"UseAtiROM"/* ati.c */
#define kWake"Wake"/* boot.c */
#define kForceWake"ForceWake"/* boot.c */
#define kWakeImage"WakeImage"/* boot.c */
#define kProductVersion"ProductVersion"/* boot.c */
#define karch"arch"/* boot.c */
#define kDSDT"DSDT"/* dsdt_patcher.c */
#define kDropSSDT"DropSSDT"/* dsdt_patcher.c */
#define kRestartFix"RestartFix"/* dsdt_patcher.c */
#define kSMBIOS"SMBIOS"/* fake_efi.c */
#define kSystemID"system-id"/* fake_efi.c */
#define kSystemType"system-type"/* fake_efi.c */
#define kUseNvidiaROM"UseNvidiaROM"/* nvidia.c */
#define kVBIOS"VBIOS"/* nvidia.c */
#define kPCIRootUID"PCIRootUID"/* pci_root.c */
#define kEthernetBuiltIn"EthernetBuiltIn"/* pci_setup.c */
#define kGraphicsEnabler"GraphicsEnabler"/* pci_setup.c */
#define kUSBBusFix"USBBusFix"/* pci_setup.c */
#define kEHCIacquire"EHCIacquire"/* pci_setup.c */
#define kUHCIreset"UHCIreset"/* pci_setup.c */
#define kForceHPET"ForceHPET"/* pci_setup.c */
#define kSMBIOSdefaults"SMBIOSdefaults"/* smbios_patcher.c */
#define kEHCIhard"EHCIhard"/* usb.c */
#define kDefaultPartition"Default Partition"/* sys.c */
#define kDeviceProperties"device-properties"/* device_inject.c */
#define kHidePartition"Hide Partition"/* disk.c */
#define kRenamePartition"Rename Partition"/* disk.c */
/*
* Flags to the booter or kernel
*
*/
#define kVerboseModeFlag "-v"
#define kSafeModeFlag "-x"
#define kOldSafeModeFlag "-f"
#define kIgnoreBootFileFlag "-F"
#define kSingleUserModeFlag "-s"
#define kVerboseModeFlag"-v"
#define kSafeModeFlag"-x"
#define kOldSafeModeFlag"-f"
#define kIgnoreBootFileFlag"-F"
#define kSingleUserModeFlag"-s"
#define k32BitModeFlag"-x32"
/*
* Booter behavior control
*/
extern int gBIOSDev;
extern long gBootMode;
extern BOOL sysConfigValid;
extern bool sysConfigValid;
extern char bootBanner[];
extern char bootPrompt[];
extern BOOL gOverrideKernel;
extern bool gOverrideKernel;
extern char *gPlatformName;
extern char gMKextName[];
extern char gRootDevice[];
extern BOOL gEnableCDROMRescan;
extern BOOL gScanSingleDrive;
extern BOOL useGUI;
extern bool gEnableCDROMRescan;
extern bool gScanSingleDrive;
extern bool useGUI;
// Boot Modes
/*
* Boot Modes
*/
enum {
kBootModeNormal = 0,
kBootModeSafe = 1,
/*
* graphics.c
*/
extern void printVBEModeInfo();
extern void setVideoMode(int mode, int drawgraphics);
extern int getVideoMode();
/*
* options.c
*/
extern int getBootOptions(BOOL firstRun);
extern int getBootOptions(bool firstRun);
extern int processBootOptions();
extern int selectAlternateBootDevice(int bootdevice);
extern BOOL promptForRescanOption(void);
extern bool promptForRescanOption(void);
void showHelp();
void showTextFile();
void HibernateBoot(char *boot_device);
/* bmdecompress.c */
void *
DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel);
void * DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel);
#endif /* !__BOOT2_BOOT_H */
trunk/i386/boot2/drivers.c
145145
146146
147147
148
149
150
151
152
148
149
150
151
152
153153
154154
155155
......
471471
472472
473473
474
474
475475
476476
477477
......
727727
728728
729729
730
730
731731
732732
733733
static long
InitDriverSupport( void )
{
gExtensionsSpec = (char *) malloc( 4096 );
gDriverSpec = (char *) malloc( 4096 );
gFileSpec = (char *) malloc( 4096 );
gTempSpec = (char *) malloc( 4096 );
gFileName = (char *) malloc( 4096 );
gExtensionsSpec = malloc( 4096 );
gDriverSpec = malloc( 4096 );
gFileSpec = malloc( 4096 );
gTempSpec = malloc( 4096 );
gFileName = malloc( 4096 );
if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName )
stop("InitDriverSupport error");
module->executablePath = tmpExecutablePath;
module->bundlePath = tmpBundlePath;
module->bundlePathLength = bundlePathLength;
module->plistAddr = (void *)malloc(length);
module->plistAddr = malloc(length);
if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0))
break;
return -2;
}
tmpModule = (ModulePtr)malloc(sizeof(Module));
tmpModule = malloc(sizeof(Module));
if (tmpModule == 0)
{
XMLFreeTag(moduleDict);
trunk/i386/boot2/mboot.c
389389
390390
391391
392
392
393393
394394
395395
......
403403
404404
405405
406
406
407407
408408
409409
......
415415
416416
417417
418
418
419419
420420
421421
......
466466
467467
468468
469
469
470470
471
471
472472
473473
474474
const char *val;
int size;
if(getValueForBootKey(mi->mi_cmdline, "biosdev", &val, &size) != NO)
if(getValueForBootKey(mi->mi_cmdline, "biosdev", &val, &size))
{
char *endptr;
int intVal = strtol(val, &endptr, 16 /* always hex */);
doSelectDevice = true;
}
if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size) != NO)
if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size))
{
char *endptr;
int intVal = strtol(val, &endptr, 0);
}
}
if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size) != NO)
if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size))
{
char *endptr;
int intVal = strtol(val, &endptr, 0);
return -1;
struct multiboot_module *module = modules + (biosdev - 0x100);
dip->biosdev = biosdev;
dip->uses_ebios = TRUE;
dip->uses_ebios = true;// XXX aserebln uses_ebios isn't a boolean at all
dip->di.params.phys_sectors = (module->mm_mod_end - module->mm_mod_start + 511) / 512;
dip->valid = TRUE;
dip->valid = true;
return 0;
}
trunk/i386/boot2/gui.c
1212
1313
1414
15
16
1517
1618
17
18
19
20
21
19
2220
23
24
25
21
22
23
2624
2725
2826
......
3735
3836
3937
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
38
39
40
7941
8042
8143
......
10870
10971
11072
111
73
11274
11375
11476
11577
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
116115
117116
118117
......
137136
138137
139138
140
141139
142140
143
144141
145142
146
143
144
147145
148
149
146
150147
151
148
152149
153
150
151
152
153
154
155
156
154157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
155259
156260
157261
......
203307
204308
205309
206
310
207311
208312
209313
......
245349
246350
247351
248
352
249353
250
354
355
356
357
358
359
360
251361
252
253
254
255
256
257
258
259
260
261
362
363
364
365
366
262367
263
264
265
266
267
268
269
270
271
368
369
272370
273
274
275
276
277
371
372
278373
279
280
281
282
283
284
374
375
376
377
378
285379
286
287
288
289
290
291
380
381
292382
293
294
295
296
297
383
384
385
386
387
298388
299
300
301
302
303
304
305
306
307
389
390
308391
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
371424
425
372426
373
374
375
376
377
427
428
429
430
378431
379
380
381
382
383
384
385
386
387
432
433
388434
389
390
435
436
437
391438
392
393
394
395
396
397
398
399
439
440
441
442
400443
401
402
403
404
405
406
407
408
409
410
411
412
444
445
413446
414
447
415448
416
417
449
450
418451
419
420
421
422
423
424
425
426
452
453
454
427455
428
429
430
431
432
456
457
433458
434
435
436
437
438
439
440
441
442
459
460
443461
444
445
446
447
448
462
463
464
465
466
449467
450
451
452
453
454
455
456
457
458
459
460
468
469
461470
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
471
472
492473
493
474
475
494476
495
496
497
498
477
478
499479
500
480
481
501482
502
483
484
503485
504
505
486
487
506488
507
508
509
510
511
512
513
489
490
491
492
493
494
495
514496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
515520
516
521
517522
518
519
520
521
523
524
522525
523
524
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
525559
526
527
528
560
561
562
563
564
565
566
567
529568
530
569
570
571
531572
532
533
534
535
536
537
538
539
540
573
574
541575
576
577
578
579
580
581
582
583
584
542585
586
587
588
543589
544590
545591
546592
547593
548594
549
595
550596
551
552
553
554
555
556
557
558
559
597
598
599
560600
561
601
562602
563
564
565
566
567
568
569
603
604
605
606
607
608
570609
571
572610
573611
574
575612
576
577
578
613
579614
580
615
616
617
618
619
620
581621
582
583
584622
585623
586624
587
588625
589626
590627
......
680717
681718
682719
683
720
684721
685722
686
723
687724
688725
689726
......
729766
730767
731768
732
769
733770
734771
735772
......
742779
743780
744781
745
782
746783
747
748
784
785
749786
750787
751788
......
784821
785822
786823
787
788
789
824
825
826
790827
791828
792829
......
851888
852889
853890
854
891
855892
856893
857894
......
879916
880917
881918
882
883
919
884920
885921
886922
......
9651001
9661002
9671003
968
969
1004
9701005
9711006
9721007
......
10531088
10541089
10551090
1056
1057
1091
10581092
10591093
10601094
......
10791113
10801114
10811115
1082
1116
10831117
10841118
10851119
......
11051139
11061140
11071141
1108
1142
11091143
11101144
11111145
......
11911225
11921226
11931227
1194
1228
11951229
11961230
11971231
......
12231257
12241258
12251259
1226
1260
12271261
12281262
12291263
......
12681302
12691303
12701304
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
13341305
13351306
13361307
......
14641435
14651436
14661437
1467
1468
1469
1438
1439
1440
14701441
14711442
14721443
......
14821453
14831454
14841455
1485
1486
1456
1457
14871458
14881459
14891460
......
16021573
16031574
16041575
1605
1576
16061577
16071578
16081579
16091580
16101581
16111582
1612
1583
16131584
16141585
16151586
......
16341605
16351606
16361607
1637
1638
1608
1609
16391610
16401611
16411612
......
16791650
16801651
16811652
1682
16831653
1654
16841655
1685
1686
16871656
16881657
1689
1690
1658
16911659
1692
1660
1661
1662
16931663
1694
1695
1696
1697
1698
1699
17001664
1701
1702
1703
1704
1665
1666
17051667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
17061680
17071681
17081682
17091683
1710
1711
1684
17121685
17131686
17141687
17151688
1716
1689
17171690
17181691
1719
1720
1721
1722
1692
1693
1694
17231695
1724
1696
1697
17251698
1726
1699
17271700
1728
1701
17291702
1730
1731
1703
1704
17321705
1733
1706
17341707
1735
1708
17361709
1737
1710
17381711
17391712
1740
1713
17411714
17421715
17431716
1744
1745
1746
1747
1748
1717
1718
1719
1720
1721
17491722
1750
1751
1752
1753
1754
1755
1756
1723
1724
1725
1726
1727
1728
17571729
17581730
1759
17601731
1761
17621732
17631733
17641734
17651735
1766
1736
17671737
1768
1769
1770
1771
1738
1739
17721740
1773
1774
1775
1776
1777
1778
1741
1742
1743
1744
17791745
17801746
17811747
17821748
17831749
1784
1785
17861750
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
#include "appleboot.h"
#include "vers.h"
//#define EMBED_THEME
#ifdef EMBED_THEME
#include "art.h"
#define LOADPNG(img) \
if(!loadThemeImage(#img".png")) \
if(!loadPixmapFromEmbeddedPng(__## img ##_png, __## img ##_png_len, images[imageCnt].image)) \
return 1; \
imageCnt++
#define LOADPNG(img)if (loadEmbeddedThemeImage(#img, __## img ##_png, __## img ##_png_len) != 0) { return 1; }
#else
#define LOADPNG(img) \
if(!loadThemeImage(#img".png")) \
return 1;
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
#define LOADPNG(img)if (loadThemeImage(#img) != 0) { return 1; }
#endif
#define MIN(x, y) ((x) < (y) ? (x) : (y))
extern int gDeviceCount;
image_t images[] = {
{.name = "background",.image = 0},
{.name = "logo",.image = 0},
{.name = "device_generic",.image = 0},
{.name = "device_hfsplus",.image = 0},
{.name = "device_ext3",.image = 0},
{.name = "device_fat16",.image = 0},
{.name = "device_fat32",.image = 0},
{.name = "device_ntfs",.image = 0},
{.name = "device_cdrom",.image = 0},
{.name = "device_selection",.image = 0},
{.name = "device_scroll_prev",.image = 0},
{.name = "device_scroll_next",.image = 0},
{.name = "menu_boot",.image = 0},
{.name = "menu_verbose",.image = 0},
{.name = "menu_ignore_caches",.image = 0},
{.name = "menu_single_user",.image = 0},
{.name = "menu_memory_info",.image = 0},
{.name = "menu_video_info",.image = 0},
{.name = "menu_help",.image = 0},
{.name = "menu_verbose_disabled",.image = 0},
{.name = "menu_ignore_caches_disabled",.image = 0},
{.name = "menu_single_user_disabled",.image = 0},
{.name = "menu_selection",.image = 0},
{.name = "progress_bar",.image = 0},
{.name = "progress_bar_background",.image = 0},
{.name = "text_scroll_prev",.image = 0},
{.name = "text_scroll_next",.image = 0},
{.name = "font_small",.image = 0},
{.name = "font_console",.image = 0},
};
/*
* ATTENTION: the enum and the following array images[] MUST match !!!
*/
enum {
iBackground = 0,
iLogo,
iTextScrollPrev,
iTextScrollNext,
iFontConsole,
iFontSmall,
};
image_t images[] = {
{.name = "background",.image = NULL},
{.name = "logo",.image = NULL},
{.name = "device_generic",.image = NULL},
{.name = "device_hfsplus",.image = NULL},
{.name = "device_ext3",.image = NULL},
{.name = "device_fat16",.image = NULL},
{.name = "device_fat32",.image = NULL},
{.name = "device_ntfs",.image = NULL},
{.name = "device_cdrom",.image = NULL},
{.name = "device_selection",.image = NULL},
{.name = "device_scroll_prev",.image = NULL},
{.name = "device_scroll_next",.image = NULL},
{.name = "menu_boot",.image = NULL},
{.name = "menu_verbose",.image = NULL},
{.name = "menu_ignore_caches",.image = NULL},
{.name = "menu_single_user",.image = NULL},
{.name = "menu_memory_info",.image = NULL},
{.name = "menu_video_info",.image = NULL},
{.name = "menu_help",.image = NULL},
{.name = "menu_verbose_disabled",.image = NULL},
{.name = "menu_ignore_caches_disabled",.image = NULL},
{.name = "menu_single_user_disabled",.image = NULL},
{.name = "menu_selection",.image = NULL},
{.name = "progress_bar",.image = NULL},
{.name = "progress_bar_background",.image = NULL},
{.name = "text_scroll_prev",.image = NULL},
{.name = "text_scroll_next",.image = NULL},
{.name = "font_console",.image = NULL},
{.name = "font_small",.image = NULL},
};
int imageCnt = 0;
extern intgDeviceCount;
{ .text = "Help" }
};
int initFont(font_t *font, image_t *image);
void colorFont(font_t *font, uint32_t color);
int loadGraphics();
void makeRoundedCorners(pixmap_t *p);
BOOL testForQemu();
static int infoMenuSelection = 0;
static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);
int infoMenuSelection = 0;
int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);
static bool infoMenuNativeBoot = false;
BOOL infoMenuNativeBoot = 0;
static unsigned long screen_params[4] = {0, 0, 0, 0};// here we store the used screen resolution
unsigned long screen_params[4];// here we store the used screen resolution
#ifdef EMBED_THEME
static int loadEmbeddedThemeImage(const char *image, unsigned char *image_data, unsigned int image_size)
{
inti;
uint16_twidth;
uint16_theight;
uint8_t*imagedata;
for (i=0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(image, images[i].name) == 0) {
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
width = 0;
height = 0;
imagedata = NULL;
if ((loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) != 0) {
return 1;
}
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
return 1;
}
#else
static int loadThemeImage(const char *image)
{
chardirspec[256];
inti;
uint16_twidth;
uint16_theight;
uint8_t*imagedata;
if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) {
return 1;
}
for (i=0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(image, images[i].name) == 0) {
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
sprintf(dirspec,"/Extra/Themes/%s/%s.png", theme_name, image);
width = 0;
height = 0;
imagedata = NULL;
if ((loadPngImage(dirspec, &width, &height, &imagedata)) != 0) {
printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
sleep(5);
return 1;
}
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
return 1;
}
#endif
static int loadGraphics(void)
{
LOADPNG(background);
LOADPNG(logo);
LOADPNG(device_generic);
LOADPNG(device_hfsplus);
LOADPNG(device_ext3);
LOADPNG(device_fat16);
LOADPNG(device_fat32);
LOADPNG(device_ntfs);
LOADPNG(device_cdrom);
LOADPNG(device_selection);
LOADPNG(device_scroll_prev);
LOADPNG(device_scroll_next);
LOADPNG(menu_boot);
LOADPNG(menu_verbose);
LOADPNG(menu_ignore_caches);
LOADPNG(menu_single_user);
LOADPNG(menu_memory_info);
LOADPNG(menu_video_info);
LOADPNG(menu_help);
LOADPNG(menu_verbose_disabled);
LOADPNG(menu_ignore_caches_disabled);
LOADPNG(menu_single_user_disabled);
LOADPNG(menu_selection);
LOADPNG(progress_bar);
LOADPNG(progress_bar_background);
LOADPNG(text_scroll_prev);
LOADPNG(text_scroll_next);
LOADPNG(font_console);
LOADPNG(font_small);
initFont( &font_console, &images[iFontConsole]);
initFont( &font_small, &images[iFontSmall]);
return 0;
}
pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )
{
window->pixmap = malloc(sizeof(pixmap_t));
if(!window->pixmap)
return 1;
window->pixmap->pixels = malloc( window->width * window->height * 4 );
if(!window->pixmap->pixels)
{
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
}
void loadThemeValues(config_file_t *theme, BOOL overide)
void loadThemeValues(config_file_t *theme, bool overide)
{
BOOL themeEnabled;
unsigned int screen_width = gui.screen.width;
unsigned int screen_height = gui.screen.height;
unsigned int pixel;
intalpha;// transparency level 0 (obligue) - 255 (transparent)
uint32_t color;// color value formatted RRGGBB
int val, len;
const char *string;
if ( (getBoolForKey("Enabled", &themeEnabled, theme ) ) || ( overide ) )
{
unsigned int screen_width = gui.screen.width;
unsigned int screen_height = gui.screen.height;
unsigned int pixel;
intalpha;// transparency level 0 (obligue) - 255 (transparent)
uint32_t color;// color value formatted RRGGBB
/*
* Parse screen parameters
*/
if(getColorForKey("screen_bgcolor", &color, theme ))
gui.screen.bgcolor = (color & 0x00FFFFFF);
int val, len;
const char *string;
/*
* Parse screen parameters
*/
if(getColorForKey("screen_bgcolor", &color, theme ))
gui.screen.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("screen_textmargin_h", &val, theme))
gui.screen.hborder = MIN( gui.screen.width , val );
if(getIntForKey("screen_textmargin_h", &val, theme))
gui.screen.hborder = MIN( gui.screen.width , val );
if(getIntForKey("screen_textmargin_v", &val, theme))
gui.screen.vborder = MIN( gui.screen.height , val );
if(getIntForKey("screen_textmargin_v", &val, theme))
gui.screen.vborder = MIN( gui.screen.height , val );
/*
* Parse background parameters
*/
if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )
gui.background.pos.x = pixel;
/*
* Parse background parameters
*/
if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )
gui.background.pos.x = pixel;
if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )
gui.background.pos.y = pixel;
/*
* Parse logo parameters
*/
if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )
gui.background.pos.y = pixel;
if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )
gui.logo.pos.x = pixel;
if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )
gui.logo.pos.y = pixel;
/*
* Parse logo parameters
*/
if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )
gui.logo.pos.x = pixel;
/*
* Parse progress bar parameters
*/
if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )
gui.progressbar.pos.x = pixel;
if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )
gui.progressbar.pos.y = pixel;
if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )
gui.logo.pos.y = pixel;
/*
* Parse countdown text parameters
*/
if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )
gui.countdown.pos.x = pixel;
if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )
gui.countdown.pos.y = pixel;
/*
* Parse devicelist parameters
*/
if(getIntForKey("devices_max_visible", &val, theme ))
gui.maxdevices = MIN( val, gDeviceCount );
if(getIntForKey("devices_iconspacing", &val, theme ))
gui.devicelist.iconspacing = val;
// check layout for horizontal or vertical
if(getValueForKey( "devices_layout", &string, &len, theme ) )
if (!strcmp (string, "vertical"))
gui.layout = VerticalLayout;
else
gui.layout = HorizontalLayout;
else
gui.layout = HorizontalLayout;
switch (gui.layout)
{
case VerticalLayout:
gui.devicelist.height = ( ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ) * MIN( gui.maxdevices, gDeviceCount ) + ( images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height ) + gui.devicelist.iconspacing );
gui.devicelist.width = ( images[iSelection].image->width + gui.devicelist.iconspacing );
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )
gui.devicelist.pos.x = pixel;
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )
gui.devicelist.pos.y = pixel;
break;
default:
case HorizontalLayout:
gui.devicelist.width = ( ( images[iSelection].image->width + gui.devicelist.iconspacing ) * MIN( gui.maxdevices, gDeviceCount ) + ( images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width ) + gui.devicelist.iconspacing );
gui.devicelist.height = ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )
gui.devicelist.pos.x = pixel;
else
gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )
gui.devicelist.pos.y = pixel;
else
gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;
break;
/*
* Parse progress bar parameters
*/
if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )
gui.progressbar.pos.x = pixel;
if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )
gui.progressbar.pos.y = pixel;
/*
* Parse countdown text parameters
*/
if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )
gui.countdown.pos.x = pixel;
if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )
gui.countdown.pos.y = pixel;
/*
* Parse devicelist parameters
*/
if(getIntForKey("devices_max_visible", &val, theme ))
gui.maxdevices = MIN( val, gDeviceCount );
if(getIntForKey("devices_iconspacing", &val, theme ))
gui.devicelist.iconspacing = val;
// check layout for horizontal or vertical
gui.layout = HorizontalLayout;
if(getValueForKey( "devices_layout", &string, &len, theme)) {
if (!strcmp (string, "vertical")) {
gui.layout = VerticalLayout;
}
}
if(getColorForKey("devices_bgcolor", &color, theme))
gui.devicelist.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("devices_transparency", &alpha, theme))
gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
switch (gui.layout) {
case VerticalLayout:
gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing);
gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);
/*
* Parse infobox parameters
*/
if(getIntForKey("infobox_width", &val, theme))
gui.infobox.width = MIN( screen_width , val );
if(getIntForKey("infobox_height", &val, theme))
gui.infobox.height = MIN( screen_height , val );
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )
gui.devicelist.pos.x = pixel;
if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )
gui.infobox.pos.x = pixel;
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )
gui.devicelist.pos.y = pixel;
break;
if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )
gui.infobox.pos.y = pixel;
if(getIntForKey("infobox_textmargin_h", &val, theme))
gui.infobox.hborder = MIN( gui.infobox.width , val );
if(getIntForKey("infobox_textmargin_v", &val, theme))
gui.infobox.vborder = MIN( gui.infobox.height , val );
case HorizontalLayout:
default:
gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);
gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);
if(getColorForKey("infobox_bgcolor", &color, theme))
gui.infobox.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("infobox_transparency", &alpha, theme))
gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
/*
* Parse menu parameters
*/
if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )
gui.menu.width = pixel;
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )
gui.devicelist.pos.x = pixel;
else
gui.menu.width = images[iMenuSelection].image->width;
gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;
if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )
gui.menu.height = pixel;
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )
gui.devicelist.pos.y = pixel;
else
gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;
if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )
gui.menu.pos.x = pixel;
if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )
gui.menu.pos.y = pixel;
gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;
break;
}
if(getIntForKey("menu_textmargin_h", &val, theme))
gui.menu.hborder = MIN( gui.menu.width , val );
if(getIntForKey("menu_textmargin_v", &val, theme))
gui.menu.vborder = MIN( gui.menu.height , val );
if(getColorForKey("devices_bgcolor", &color, theme))
gui.devicelist.bgcolor = (color & 0x00FFFFFF);
if(getColorForKey("menu_bgcolor", &color, theme))
gui.menu.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("menu_transparency", &alpha, theme))
gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
/*
* Parse bootprompt parameters
*/
if(getIntForKey("devices_transparency", &alpha, theme))
gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )
gui.bootprompt.width = pixel;
if(getIntForKey("bootprompt_height", &val, theme))
gui.bootprompt.height = MIN( screen_height , val );
/*
* Parse infobox parameters
*/
if(getIntForKey("infobox_width", &val, theme))
gui.infobox.width = MIN( screen_width , val );
if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )
gui.bootprompt.pos.x = pixel;
if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )
gui.bootprompt.pos.y = pixel;
if(getIntForKey("bootprompt_textmargin_h", &val, theme))
gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );
if(getIntForKey("bootprompt_textmargin_v", &val, theme))
gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );
if(getIntForKey("infobox_height", &val, theme))
gui.infobox.height = MIN( screen_height , val );
if(getColorForKey("bootprompt_bgcolor", &color, theme))
gui.bootprompt.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("bootprompt_transparency", &alpha, theme))
gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
if(getColorForKey("font_small_color", &color, theme))
gui.screen.font_small_color = (color & 0x00FFFFFF);
if(getColorForKey("font_console_color", &color, theme))
gui.screen.font_console_color = (color & 0x00FFFFFF);
}
}
/*
void freePixmap(pixmap_t *pm)
{
if(pm)
{
if(pm->pixels)
{
free(pm->pixels);
pm->pixels=0;
}
}
pm = 0;
}
*/
if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )
gui.infobox.pos.x = pixel;
const char *theme_name="Default";
if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )
gui.infobox.pos.y = pixel;
int initGUI()
{
int val, len;
char dirspec[256];
if(getIntForKey("infobox_textmargin_h", &val, theme))
gui.infobox.hborder = MIN( gui.infobox.width , val );
#ifdef EMBED_THEME
if(getIntForKey("infobox_textmargin_v", &val, theme))
gui.infobox.vborder = MIN( gui.infobox.height , val );
config_file_t *embedded = &bootInfo->themeDefault;
if(getColorForKey("infobox_bgcolor", &color, theme))
gui.infobox.bgcolor = (color & 0x00FFFFFF);
// build xml dictionary for embedded theme.plist
ParseXMLFile( (char *) __theme_plist, &embedded->dictionary);
if(getIntForKey("infobox_transparency", &alpha, theme))
gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
// parse display size parameters
if(getIntForKey("screen_width", &val, &bootInfo->themeDefault))
screen_params[0] = val;
if(getIntForKey("screen_height", &val, &bootInfo->themeDefault))
screen_params[1] = val;
#else
/*
* Parse menu parameters
*/
if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )
gui.menu.width = pixel;
else
gui.menu.width = images[iMenuSelection].image->width;
if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )
gui.menu.height = pixel;
else
gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;
if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )
gui.menu.pos.x = pixel;
if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )
gui.menu.pos.y = pixel;
if(getIntForKey("menu_textmargin_h", &val, theme))
gui.menu.hborder = MIN( gui.menu.width , val );
if(getIntForKey("menu_textmargin_v", &val, theme))
gui.menu.vborder = MIN( gui.menu.height , val );
if(getColorForKey("menu_bgcolor", &color, theme))
gui.menu.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("menu_transparency", &alpha, theme))
gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
/*
* Return Error since GUI can't run when embedtheme is not used.
* Parse bootprompt parameters
*/
return 1;
#endif
if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )
gui.bootprompt.width = pixel;
// Initalizing GUI strucutre.
bzero(&gui, sizeof(gui_t));
if(getIntForKey("bootprompt_height", &val, theme))
gui.bootprompt.height = MIN( screen_height , val );
if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )
gui.bootprompt.pos.x = pixel;
if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )
gui.bootprompt.pos.y = pixel;
if(getIntForKey("bootprompt_textmargin_h", &val, theme))
gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );
if(getIntForKey("bootprompt_textmargin_v", &val, theme))
gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );
if(getColorForKey("bootprompt_bgcolor", &color, theme))
gui.bootprompt.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("bootprompt_transparency", &alpha, theme))
gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
if(getColorForKey("font_small_color", &color, theme))
gui.screen.font_small_color = (color & 0x00FFFFFF);
if(getColorForKey("font_console_color", &color, theme))
gui.screen.font_console_color = (color & 0x00FFFFFF);
}
int initGUI(void)
{
intval;
#ifdef EMBED_THEME
config_file_t*config;
screen_params[2] = 32;
// find theme name in boot.plist
config = &bootInfo->themeConfig;
if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
return 1;
}
#else
intlen;
chardirspec[256];
getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );
if ((strlen(theme_name) + 27) > sizeof(dirspec)) {
return 1;
}
sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);
if ( !loadConfigFile(dirspec, &bootInfo->themeConfig) )
{
// parse display size parameters
if(getIntForKey("screen_width", &val, &bootInfo->themeConfig))
screen_params[0] = val;
if(getIntForKey("screen_height", &val, &bootInfo->themeConfig))
screen_params[1] = val;
if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
return 1;
}
#endif
// parse display size parameters
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) {
screen_params[0] = val;
}
if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) {
screen_params[1] = val;
}
screen_params[2] = 32;
// Initalizing GUI strucutre.
bzero(&gui, sizeof(gui_t));
// find best matching vesa mode for our requested width & height
getGraphicModeParams(screen_params);
// set our screen structure with the mode width & height
gui.screen.width = screen_params[0];
gui.screen.height = screen_params[1];
// load graphics otherwise fail and return
if( !loadGraphics() )
{
// set embedded theme.plist as defaults
loadThemeValues(&bootInfo->themeDefault, YES);
// set user overides
loadThemeValues(&bootInfo->themeConfig, NO);
colorFont(&font_small, gui.screen.font_small_color);
if (loadGraphics() == 0) {
loadThemeValues(&bootInfo->themeConfig, true);
colorFont(&font_small, gui.screen.font_small_color);
colorFont(&font_console, gui.screen.font_console_color);
// create the screen & window buffers
if( !createBackBuffer( &gui.screen ) )
if( !createWindowBuffer( &gui.screen ) )
if( !createWindowBuffer( &gui.devicelist ) )
if( !createWindowBuffer( &gui.bootprompt ) )
if( !createWindowBuffer( &gui.infobox ) )
if( !createWindowBuffer( &gui.menu ) )
{
if (createBackBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.devicelist) == 0) {
if (createWindowBuffer(&gui.bootprompt) == 0) {
if (createWindowBuffer(&gui.infobox) == 0) {
if (createWindowBuffer(&gui.menu) == 0) {
drawBackground();
// lets copy the screen into the back buffer
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
setVideoMode( GRAPHICS_MODE, 0 );
gui.initialised = YES;
gui.initialised = true;
return 0;
}
}
}
}
}
}
}
}
// something went wrong
return 1;
}
void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p)
{
int devicetype;
if((start+i) == selection)
{
if(param->flags & kBVFlagNativeBoot)
infoMenuNativeBoot = YES;
infoMenuNativeBoot = true;
else
{
infoMenuNativeBoot = NO;
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
infoMenuSelection = 0;
}
if( end < gDeviceCount - 1 )
blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
gui.redraw = YES;
gui.redraw = true;
updateVRAM();
prompt_pos=0;
if(gui.bootprompt.draw == YES )
if(gui.bootprompt.draw == true )
{
gui.bootprompt.draw = NO;
gui.redraw = YES;
gui.bootprompt.draw = false;
gui.redraw = true;
// this causes extra frames to be drawn
//updateVRAM();
}
drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);
gui.menu.draw = NO;
gui.bootprompt.draw = YES;
gui.redraw = YES;
gui.menu.draw = false;
gui.bootprompt.draw = true;
gui.redraw = true;
updateVRAM();
if (gui.redraw)
{
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
gui.redraw = NO;
gui.redraw = false;
}
}
struct putc_info pi;
if( formattedtext = (char *) malloc(1024) )
{
if ((formattedtext = malloc(1024)) != NULL) {
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
struct putc_info pi;
if( formattedtext = (char *) malloc(1024) )
{
if ((formattedtext = malloc(1024)) != NULL) {
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
position_torigin, cursor, bounds;
font_t *font = &font_console;
if( formattedtext = (char *) malloc(1024) )
{
if ((formattedtext = malloc(1024)) != NULL) {
// format the text
pi.str = formattedtext;
pi.last_str = 0;
cursor.y += font->height;
if ( cursor.y > bounds.y )
{
gui.redraw = YES;
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// check y pos and reset to origin.y
if ( cursor.y > ( bounds.y + font->chars[0]->height) )
{
gui.redraw = YES;
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
int start = 0, end = 0, count = 0, space = 0;
BOOL monospaced = NO;
bool monospaced = false;
font->height = data->image->height;
// check if font is monospaced
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
monospaced = YES;
monospaced = true;
font->width = font->chars[count]->width;
}
}
int loadThemeImage(image)
{
char dirspec[256];
sprintf(dirspec,"/Extra/Themes/%s/%s", theme_name, image);
if ((loadPixmapFromPng(dirspec, images[imageCnt].image)) == 1 )
return 1;
dirspec[0] = '\0';
sprintf(dirspec,"bt(0,0)/Extra/Themes/%s/%s", theme_name, image);
return loadPixmapFromPng(dirspec, images[imageCnt].image);
}
int loadGraphics()
{
int i;
for( i=0; i < sizeof(images) / sizeof(images[0]); i++)
{
// create pixmap_t buffer for each image
images[i].image = malloc(sizeof(pixmap_t));
}
LOADPNG(background);
LOADPNG(logo);
LOADPNG(device_generic);
LOADPNG(device_hfsplus);
LOADPNG(device_ext3);
LOADPNG(device_fat16);
LOADPNG(device_fat32);
LOADPNG(device_ntfs);
LOADPNG(device_cdrom);
LOADPNG(device_selection);
LOADPNG(device_scroll_prev);
LOADPNG(device_scroll_next);
LOADPNG(menu_boot);
LOADPNG(menu_verbose);
LOADPNG(menu_ignore_caches);
LOADPNG(menu_single_user);
LOADPNG(menu_memory_info);
LOADPNG(menu_video_info);
LOADPNG(menu_help);
LOADPNG(menu_verbose_disabled);
LOADPNG(menu_ignore_caches_disabled);
LOADPNG(menu_single_user_disabled);
LOADPNG(menu_selection);
LOADPNG(progress_bar);
LOADPNG(progress_bar_background);
LOADPNG(text_scroll_prev);
LOADPNG(text_scroll_next);
LOADPNG(font_console);
LOADPNG(font_small);
initFont( &font_console, &images[iFontConsole]);
initFont( &font_small, &images[iFontSmall]);
return 0;
}
void makeRoundedCorners(pixmap_t *p)
{
int x,y;
blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
}
gui.bootprompt.draw = NO;
gui.infobox.draw = YES;
gui.redraw = YES;
gui.bootprompt.draw = false;
gui.infobox.draw = true;
gui.redraw = true;
updateVRAM();
if( key == kEscapeKey || key == 'q' || key == 'Q')
{
gui.infobox.draw = NO;
gui.redraw = YES;
gui.infobox.draw = false;
gui.redraw = true;
updateVRAM();
break;
}
}
gui.redraw = YES;
gui.redraw = true;
}
int drawInfoMenu()
{
drawInfoMenuItems();
gui.menu.draw = YES;
gui.menu.draw = true;
updateVRAM();
} else {
gui.menu.draw = NO;
gui.redraw = YES;
gui.menu.draw = false;
gui.redraw = true;
updateVRAM();
uint16_t bootImageWidth = 0;
uint16_t bootImageHeight = 0;
uint8_t *bootImageData = NULL;
static bool usePngImage = true;
BOOL usePngImage = YES;
//==========================================================================
// loadBootGraphics
void loadBootGraphics()
static void loadBootGraphics(void)
{
char dirspec[256];
if (bootImageData != NULL) {
return;
}
sprintf(dirspec,"/Extra/Themes/%s/boot.png", theme_name);
if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0)
{
dirspec[0] = '\0';
sprintf(dirspec,"bt(0,0)/Extra/Themes/%s/boot.png", theme_name);
if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0)
#ifdef EMBED_THEME
if((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth,
&bootImageHeight, &bootImageData)) != 0)
#endif
usePngImage = NO;
if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) {
usePngImage = false;
}
#else
char dirspec[256];
if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
usePngImage = false;
return;
}
sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
usePngImage = false;
}
#endif
}
//==========================================================================
// drawBootGraphics
void drawBootGraphics()
void drawBootGraphics(void)
{
int pos;
int length;
const char *dummyVal;
BOOL legacy_logo;
bool legacy_logo;
uint16_t x, y;
if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo)
usePngImage = NO;
else if (bootImageData == NULL)
if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
usePngImage = false;
} else if (bootImageData == NULL) {
loadBootGraphics();
}
// parse screen size parameters
if(getIntForKey("boot_width", &pos, &bootInfo->themeConfig))
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) {
screen_params[0] = pos;
else
} else {
screen_params[0] = DEFAULT_SCREEN_WIDTH;
if(getIntForKey("boot_height", &pos, &bootInfo->themeConfig))
}
if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) {
screen_params[1] = pos;
else
} else {
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
screen_params[2] = 32;
gui.screen.width = screen_params[0];
gui.screen.height = screen_params[1];
// find best matching vesa mode for our requested width & height
getGraphicModeParams(screen_params);
setVideoMode( GRAPHICS_MODE, 0 );
if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig))
drawCheckerBoard();
else
setVideoMode(GRAPHICS_MODE, 0);
if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
drawCheckerBoard();
} else {
// Fill the background to 75% grey (same as BootX).
drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01 );
if ( (bootImageData) && (usePngImage) )
{
x = ( screen_params[0] - MIN( bootImageWidth, screen_params[0] ) ) / 2;
y = ( screen_params[1] - MIN( bootImageHeight, screen_params[1] ) ) / 2;
drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
}
if ((bootImageData) && (usePngImage)) {
x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
// Draw the image in the center of the display.
blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
} else {
uint8_t *appleBootPict;
bootImageData = NULL;
bootImageWidth = kAppleBootWidth;
bootImageHeight = kAppleBootHeight;
// Prepare the data for the default Apple boot image.
appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks,
bootImageWidth * bootImageHeight);
if (appleBootPict)
{
appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
if (appleBootPict) {
convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
if (bootImageData)
{
x = ( screen_params[0] - MIN( kAppleBootWidth, screen_params[0] ) ) / 2;
y = ( screen_params[1] - MIN( kAppleBootHeight, screen_params[1] ) ) / 2;
drawDataRectangle( x, y, kAppleBootWidth, kAppleBootHeight, bootImageData );
if (bootImageData) {
x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
free(bootImageData);
}
free(appleBootPict);
}
}
return;
}
BOOL testForQemu()
{
char *buffer = getVBEInfoString();
char qemutext[] = "Bochs/Plex86";
int i=0;
for(;i<strlen(buffer)-strlen(qemutext);i++)
if(!strncmp(buffer+i, qemutext, strlen(qemutext)))
return YES;
return NO;
}
trunk/i386/boot2/gui.h
1717
1818
1919
20
20
2121
22
23
24
25
26
27
22
23
24
25
26
27
2828
2929
30
30
3131
32
33
34
32
33
34
3535
3636
3737
......
3939
4040
4141
42
43
44
45
46
47
48
49
50
42
43
44
45
46
47
48
49
50
5151
5252
5353
......
5555
5656
5757
58
59
60
61
58
59
60
61
6262
6363
6464
6565
6666
6767
68
69
68
69
7070
7171
7272
7373
7474
7575
76
77
78
76
77
78
7979
8080
8181
......
8383
8484
8585
86
87
88
89
90
91
92
93
94
95
96
97
98
86
87
88
89
90
91
92
93
94
95
96
97
98
9999
100100
101101
......
103103
104104
105105
106
107
106
107
108108
109
109
110110
111
112
113
114
115
116
117
111
112
113
114
115
116
117
118118
119
120
119
120
121121
122
122
123123
124
125
124
125
126126
127127
128128
129
129
130130
131131
132132
133133
134
135
136
137
138134
139135
140136
......
161157
162158
163159
164
160
#ifndef __BOOT2_GUI_H
#define __BOOT2_GUI_H
#define CHARACTERS_COUNT 223
#define CHARACTERS_COUNT223
#define BOOT_NORMAL 0
#define BOOT_VERBOSE 1
#define BOOT_IGNORECACHE 2
#define BOOT_SINGLEUSER 3
#define DO_NOT_BOOT 4
#define CLOSE_INFO_MENU 5
#define BOOT_NORMAL0
#define BOOT_VERBOSE1
#define BOOT_IGNORECACHE2
#define BOOT_SINGLEUSER3
#define DO_NOT_BOOT4
#define CLOSE_INFO_MENU5
#define INFOMENU_NATIVEBOOT_START 1
#define INFOMENU_NATIVEBOOT_END 3
#define INFOMENU_NATIVEBOOT_END3
#define MENU_SHOW_MEMORY_INFO 4
#define MENU_SHOW_VIDEO_INFO 5
#define MENU_SHOW_HELP 6
#define MENU_SHOW_MEMORY_INFO4
#define MENU_SHOW_VIDEO_INFO5
#define MENU_SHOW_HELP6
enum {
HorizontalLayout= 0,
};
enum {
kBackspaceKey= 0x08,
kTabKey= 0x09,
kReturnKey= 0x0d,
kEscapeKey= 0x1b,
kUpArrowkey= 0x4800,
kDownArrowkey= 0x5000,
kASCIIKeyMask= 0x7f,
kF5Key = 0x3f00,
kF10Key = 0x4400
kBackspaceKey= 0x08,
kTabKey= 0x09,
kReturnKey= 0x0d,
kEscapeKey= 0x1b,
kUpArrowkey= 0x4800,
kDownArrowkey= 0x5000,
kASCIIKeyMask= 0x7f,
kF5Key= 0x3f00,
kF10Key= 0x4400
};
/*
*/
typedef struct {
position_t pos;
char *text;
BOOL enabled;
BOOL expandable;
position_tpos;
char*text;
boolenabled;
boolexpandable;
} menuitem_t;
/*
* Image structure.
*/
typedef struct {
pixmap_t *image;
char name[32];
pixmap_t*image;
charname[32];
} image_t;
/*
* Font structure.
*/
typedef struct {
uint16_t height;// Font Height
uint16_t width;// Font Width for monospace font only
pixmap_t *chars[CHARACTERS_COUNT];
uint16_theight;// Font Height
uint16_twidth;// Font Width for monospace font only
pixmap_t*chars[CHARACTERS_COUNT];
} font_t;
/*
*/
typedef struct
{
position_tpos;// X,Y Position of window on screen
pixmap_t*pixmap;// Buffer
uint16_twidth;// Width
uint16_theight;// Height
uint16_thborder;// Horizontal border
uint16_tvborder;// Vertical border
uint16_ticonspacing;// Icon spacing
position_tcursor;// Text Cursor X,Y Position will be multiples of font width & height
uint32_tbgcolor;// Background color AARRGGBB
uint32_tfgcolor;// Foreground color AARRGGBB
uint32_tfont_small_color;// Color for small font AARRGGBB
uint32_tfont_console_color;// Color for consle font AARRGGBB
BOOLdraw;// Draw flag
position_tpos;// X,Y Position of window on screen
pixmap_t*pixmap;// Buffer
uint16_twidth;// Width
uint16_theight;// Height
uint16_thborder;// Horizontal border
uint16_tvborder;// Vertical border
uint16_ticonspacing;// Icon spacing
position_tcursor;// Text Cursor X,Y Position will be multiples of font width & height
uint32_tbgcolor;// Background color AARRGGBB
uint32_tfgcolor;// Foreground color AARRGGBB
uint32_tfont_small_color;// Color for small font AARRGGBB
uint32_tfont_console_color;// Color for consle font AARRGGBB
booldraw;// Draw flag
} window_t;
/*
*/
typedef struct
{
uint8_tmaxdevices;//
uint8_tlayout;// Horizontal or Vertical layout
uint8_tmaxdevices;//
uint8_tlayout;// Horizontal or Vertical layout
pixmap_t*backbuffer;// Off screen buffer
pixmap_t*backbuffer;// Off screen buffer
window_tscreen;//
window_tbackground;// Position of background graphic within screen
window_tlogo;// Logo
window_tbootprompt;// Bootprompt Window
window_tdevicelist;// Devicelist Window
window_tinfobox;// Infobox Window
window_tmenu;// Menu
window_tscreen;//
window_tbackground;// Position of background graphic within screen
window_tlogo;// Logo
window_tbootprompt;// Bootprompt Window
window_tdevicelist;// Devicelist Window
window_tinfobox;// Infobox Window
window_tmenu;// Menu
window_tprogressbar;// Progress bar
window_tcountdown;// Countdown text
window_tprogressbar;// Progress bar
window_tcountdown;// Countdown text
window_tdebug;// Debug
window_tdebug;// Debug
BOOLinitialised;// Initialised
BOOLredraw;// Redraw flag
boolinitialised;// Initialised
boolredraw;// Redraw flag
} gui_t;
gui_t gui;// gui structure
gui_t gui;// gui structure
font_t font_small;
font_t font_console;
extern unsigned long screen_params[4];
void loadBootGraphics();
int initGUI();
void drawBackground();
void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p);
void drawStrCenteredAt(char *ch, font_t *font, pixmap_t *blendInto, position_t p);
#endif /* !__BOOT2_GUI_H */
#endif /* !__BOOT2_GUI_H */
trunk/i386/boot2/ramdisk.c
1313
1414
1515
16
16
1717
1818
1919
......
121121
122122
123123
124
124
125125
126126
127
128
127
129128
130
131
132
129
133130
134131
135132
136133
137
134
138135
139136
140137
......
145142
146143
147144
148
145
149146
150147
151148
......
224221
225222
226223
227
224
// gRAMDiskVolume holds the bvr for the mounted ramdisk image.
BVRef gRAMDiskVolume = NULL;
BOOL gRAMDiskBTAliased = 0;
bool gRAMDiskBTAliased = false;
char gRAMDiskFile[512];
void umountRAMDisk()
return error;
}
void setRAMDiskBTHook(BOOL mode)
void setRAMDiskBTHook(bool mode)
{
gRAMDiskBTAliased = mode;
if (mode == 1)
{
if (mode) {
printf("\nEnabled bt(0,0) alias.");
}
else
{
} else {
printf("\nDisabled bt(0,0) alias.");
}
}
void showInfoRAMDisk()
void showInfoRAMDisk(void)
{
int len;
const char *val;
printf("\nfile: %s %d", gRAMDiskFile,
ramdisk_module->mm_mod_end - ramdisk_module->mm_mod_start);
printf("\nalias: %s", (gRAMDiskBTAliased == 1) ? "enabled" : "disabled");
printf("\nalias: %s", gRAMDiskBTAliased ? "enabled" : "disabled");
// Display ramdisk information if available.
getc();
setActiveDisplayPage(0);
}
}
}
trunk/i386/boot2/options.c
2727
2828
2929
30
3130
32
31
3332
34
33
3534
3635
3736
......
8281
8382
8483
85
84
8685
87
86
8887
8988
90
89
9190
9291
9392
......
112111
113112
114113
115
114
116115
117116
118117
......
160159
161160
162161
163
162
164163
165164
166165
......
179178
180179
181180
182
181
183182
184
185
183
184
186185
187
186
188187
189
188
190189
191190
192191
193192
194
193
195194
196
197
195
196
198197
199
200
198
201199
202200
203
201
204202
205
203
206204
207
208
209
210
205
206
207
211208
212
209
213210
214
215
216
217
211
212
213
214
218215
219
216
220217
221
222
218
219
223220
224221
225222
......
419416
420417
421418
422
419
423420
424421
425422
426423
427424
428
425
429426
430427
431428
432429
433
430
434431
435432
436433
437434
438
435
439436
440437
441438
442439
443440
444441
445
442
446443
447444
448445
449446
450447
451448
452
449
453450
454451
455452
......
653650
654651
655652
656
657653
658
659
654
660655
661
662
663
664
665
666
667
668
656
657
658
659
660
669661
670
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
671686
672687
673
674
675
676
688
689
690
691
692
677693
678694
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
704722
723
705724
706
707
708
709
710
725
726
727
728
711729
712
713
730
714731
715
716
732
733
734
717735
718
719
720
721
722
723
736
737
738
739
740
724741
725742
726743
727
728
744
729745
730746
731747
732748
733
734
749
735750
736751
737
752
738753
739
740754
741
742755
743756
744
745
746
747
748
749
750
757
758
759
760
751761
752
753
762
763
754764
755
756
765
757766
758
759767
760768
761
762
763
764
765
766
767
769
770
771
772
768773
769
770
774
775
771776
772
773
774
775
776
777
778
779
780
781
777782
778
783
779784
780785
781786
782787
783788
784789
785
786
787
788
789
790
791
792
793
790
791
792
793
794
795
796
797
794798
795
796
797
798
799
800
801
799
800
801
802
803
804
805
806
802807
803
804
805
808
809
810
811
806812
807813
808814
809
810
815
811816
812817
813
814818
815
816819
817820
818821
819
820
822
821823
822824
823825
824
825
826
827
826828
829
830
827831
828
829832
830833
831834
832835
833
834
835
836
837
836
837
838
839
838840
839
840
841
842
843
844
845
846
847
848
849
841
842
843
844
845
846
847
848
850849
851
852
853
854
855
850
851
852
853
854
855
856856
857857
858
859
860
861
862
858
859
860
863861
864
862
863
864
865865
866866
867
867
868868
869869
870
871
870
872871
873872
874
875
876
873
874
875
876
877
878
879
880
881
882
883
877884
878
879
880
881
882
883
884
885
886
887
888
889
890885
891
886
892887
893888
894
895
896
897
889
890
891
892
898893
899
900
901
902
903
904
905
906
907
908
909
894
895
910896
897
898
899
900
901
902
903
904
911905
912906
913907
914908
915
916
917
918
919
920
921
922
923
924
925
926
927
909
910
911
912
913
914
915
916
917
918
928919
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
920
921
922
923
946924
947
948
949
950
951
925
926
927
952928
953
954
955
929
930
931
932
933
934
935
936
956937
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
938
939
940
941
985942
986
987
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
988980
989
990
991
992
993
994
995
996
981
982
983
997984
998
999
1000
1001
985
986
987
988
989
990
991
992
993
994
1002995
1003
1004
1005
1006
996
997
998
999
1000
1001
10071002
1008
1009
1010
1011
1003
1004
1005
1006
1007
1008
1009
10121010
1013
1014
1015
1011
1012
10161013
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1014
1015
1016
10281017
1029
1030
1031
1032
1033
1034
1018
1019
10351020
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1021
1022
10811023
1082
1083
1084
1085
1086
1024
1025
1026
1027
1028
10871029
1088
1089
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
10901041
1091
1092
1093
1094
1095
1042
1043
1044
1045
1046
10961047
1097
1098
1099
1100
1048
1049
1050
1051
1052
1053
1054
1055
11011056
1102
1103
1057
1058
1059
11041060
11051061
11061062
......
11081064
11091065
11101066
1111
1112
1067
11131068
11141069
11151070
11161071
11171072
11181073
1119
1074
11201075
11211076
11221077
......
11321087
11331088
11341089
1135
1090
11361091
11371092
11381093
11391094
1140
1141
1095
11421096
11431097
11441098
......
11511105
11521106
11531107
1154
1108
11551109
11561110
11571111
1158
1112
11591113
11601114
1161
1115
11621116
11631117
1164
1118
11651119
11661120
11671121
......
11831137
11841138
11851139
1186
1140
11871141
11881142
11891143
1190
1144
11911145
11921146
11931147
......
12211175
12221176
12231177
1224
1178
12251179
12261180
12271181
......
12391193
12401194
12411195
1242
1196
12431197
12441198
1245
1199
12461200
12471201
12481202
12491203
1250
1204
12511205
12521206
12531207
......
12581212
12591213
12601214
1261
1262
1215
1216
12631217
12641218
12651219
1266
1220
12671221
12681222
12691223
12701224
12711225
1272
1226
12731227
12741228
12751229
......
12821236
12831237
12841238
1285
1239
12861240
12871241
12881242
12891243
12901244
12911245
1292
1246
12931247
12941248
12951249
......
13811335
13821336
13831337
1384
1338
13851339
1386
1340
1341
1342
1343
13871344
1388
1389
1390
1391
1345
1346
13921347
13931348
1394
1395
1396
13971349
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1350
1351
1352
1353
14281354
1429
1430
1431
1432
1433
1434
1435
1436
1437
1355
14381356
14391357
14401358
......
14421360
14431361
14441362
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
14581380
1459
1460
1461
1462
1463
1464
1465
1466
1467
1381
1382
1383
1384
1385
1386
14681387
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
14831402
1484
1485
14861403
1487
1488
1489
1490
1491
1492
14931404
14941405
1495
1406
14961407
1497
1408
1409
1410
1411
1412
14981413
14991414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
15001439
15011440
15021441
15031442
15041443
15051444
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1445
1446
1447
1448
1449
15721450
1573
1574
1575
1576
1577
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
15781471
1579
1580
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
15811488
1582
1583
1584
1585
1586
1587
1588
1589
1590
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
#include "fdisk.h"
#include "ramdisk.h"
#include "gui.h"
#ifdef EMBED_THEME
#include "embedded.h"
#endif
#include "pci.h"
int shouldboot=0;
static bool shouldboot = false;
extern int multiboot_timeout;
extern int multiboot_timeout_set;
* characters was F8.
*/
static BOOL flushKeyboardBuffer()
static bool flushKeyboardBuffer(void)
{
BOOL status = FALSE;
bool status = false;
while ( readKeyboardStatus() ) {
if (bgetc() == 0x4200) status = TRUE;
if (bgetc() == 0x4200) status = true;
}
return status;
}
position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );
char dummy[80];
getBootVolumeDescription( gBootVolume, dummy, 80, YES );
getBootVolumeDescription( gBootVolume, dummy, 80, true );
drawDeviceIcon( gBootVolume, gui.screen.pixmap, p );
drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );
gui.redraw = YES;
gui.redraw = true;
updateVRAM();
}
static char booterCommand[BOOT_STRING_LEN];
static char booterParam[BOOT_STRING_LEN];
static void clearBootArgs()
static void clearBootArgs(void)
{
gBootArgsPtr = gBootArgs;
memset( gBootArgs, '\0', BOOT_STRING_LEN );
gBootArgsPtr = gBootArgs;
memset(gBootArgs, '\0', BOOT_STRING_LEN);
if( bootArgs->Video.v_display == GRAPHICS_MODE )
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
clearGraphicBootPrompt();
}
}
//==========================================================================
static void showBootPrompt( int row, BOOL visible )
static void showBootPrompt(int row, bool visible)
{
extern char bootPrompt[];
extern char bootRescanPrompt[];
extern char bootPrompt[];
extern char bootRescanPrompt[];
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {
changeCursor( 0, row, kCursorTypeUnderline, 0 );
clearScreenRows( row, kScreenLastRow );
}
}
clearBootArgs();
clearBootArgs();
if ( visible )
{
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
if (gEnableCDROMRescan)
if (visible) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
if (gEnableCDROMRescan) {
printf( bootRescanPrompt );
else
} else {
printf( bootPrompt );
}
else
{
if( bootArgs->Video.v_display == GRAPHICS_MODE )
}
}
} else {
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
clearGraphicBootPrompt();
else
} else {
printf("Press Enter to start up the foreign OS. ");
}
}
}
}
//==========================================================================
res = updateInfoMenu(key);
if ( res == CLOSE_INFO_MENU )
gui.menu.draw = NO;
gui.menu.draw = false;
else
{
shouldboot = ( res != DO_NOT_BOOT );
if ( shouldboot )
gui.menu.draw = NO;
gui.menu.draw = false;
switch (res)
{
case BOOT_NORMAL:
gVerboseMode = NO;
gVerboseMode = false;
gBootMode = kBootModeNormal;
break;
case BOOT_VERBOSE:
gVerboseMode = YES;
gVerboseMode = true;
gBootMode = kBootModeNormal;
*gBootArgsPtr++ = '-';
*gBootArgsPtr++ = 'v';
break;
case BOOT_IGNORECACHE:
gVerboseMode = NO;
gVerboseMode = false;
gBootMode = kBootModeNormal;
*gBootArgsPtr++ = '-';
*gBootArgsPtr++ = 'f';
break;
case BOOT_SINGLEUSER:
gVerboseMode = YES;
gVerboseMode = true;
gBootMode = kBootModeNormal;
*gBootArgsPtr++ = '-';
*gBootArgsPtr++ = 's';
}
//==========================================================================
extern void lspci(const char *booterParam);
int
getBootOptions(BOOL firstRun)
void lspci(void)
{
int i;
int key;
int nextRow;
int timeout;
int bvCount;
BVRef bvr;
BVRef menuBVR;
BOOL showPrompt, newShowPrompt, isCDROM;
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
setActiveDisplayPage(1);
clearScreenRows(0, 24);
setCursorPosition(0, 0, 1);
}
// Initialize default menu selection entry.
dump_pci_dt(root_pci_dev->children);
printf("(Press a key to continue...)");
getc();
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
setActiveDisplayPage(0);
}
}
//==========================================================================
int getBootOptions(bool firstRun)
{
int i;
int key;
int nextRow;
int timeout;
int bvCount;
BVRef bvr;
BVRef menuBVR;
bool showPrompt, newShowPrompt, isCDROM;
// Initialize default menu selection entry.
gBootVolume = menuBVR = selectBootVolume(bvChain);
if ( biosDevIsCDROM(gBIOSDev) )
isCDROM = TRUE;
else
isCDROM = FALSE;
if (biosDevIsCDROM(gBIOSDev)) {
isCDROM = true;
} else {
isCDROM = false;
}
// ensure we're in graphics mode if gui is setup
if(gui.initialised == YES)
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
setVideoMode( GRAPHICS_MODE, 0 );
// Allow user to override default timeout.
if (multiboot_timeout_set)
timeout=multiboot_timeout;
else if ( getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig) == NO )
{
/* If there is no timeout key in the file use the default timeout
which is different for CDs vs. hard disks. However, if not booting
a CD and no config file could be loaded set the timeout
to zero which causes the menu to display immediately.
This way, if no partitions can be found, that is the disk is unpartitioned
or simply cannot be read) then an empty menu is displayed.
If some partitions are found, for example a Windows partition, then
these will be displayed in the menu as foreign partitions.
*/
if ( isCDROM )
timeout = kCDBootTimeout;
else
timeout = sysConfigValid?kBootTimeout:0;
}
if (timeout < 0)
if (gui.initialised) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
setVideoMode(GRAPHICS_MODE, 0);
}
}
// Allow user to override default timeout.
if (multiboot_timeout_set) {
timeout = multiboot_timeout;
} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) {
/* If there is no timeout key in the file use the default timeout
which is different for CDs vs. hard disks. However, if not booting
a CD and no config file could be loaded set the timeout
to zero which causes the menu to display immediately.
This way, if no partitions can be found, that is the disk is unpartitioned
or simply cannot be read) then an empty menu is displayed.
If some partitions are found, for example a Windows partition, then
these will be displayed in the menu as foreign partitions.
*/
if (isCDROM) {
timeout = kCDBootTimeout;
} else {
timeout = sysConfigValid ? kBootTimeout : 0;
}
}
if (timeout < 0) {
gBootMode |= kBootModeQuiet;
}
// If the user is holding down a modifier key,
// enter safe mode.
if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) {
gBootMode |= kBootModeSafe;
}
// If the user is holding down a modifier key, enter safe mode.
if ((readKeyboardShiftFlags() & 0x0F) != 0) {
gBootMode |= kBootModeSafe;
}
// If user typed F8, abort quiet mode,
// and display the menu.
// If user typed F8, abort quiet mode, and display the menu.
{
int f8press = FALSE, spress = FALSE, vpress = FALSE, key;
while ( readKeyboardStatus() ) {
bool f8press = false, spress = false, vpress = false;
int key;
while (readKeyboardStatus()) {
key = bgetc ();
if (key == 0x4200) f8press = TRUE;
if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = TRUE;
if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = TRUE;
}
if (f8press)
{
if (key == 0x4200) f8press = true;
if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;
if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;
}
if (f8press) {
gBootMode &= ~kBootModeQuiet;
timeout = 0;
}
if ((gBootMode & kBootModeQuiet) && firstRun && vpress && (gBootArgsPtr + 3 < gBootArgsEnd))
{
if ((gBootMode & kBootModeQuiet) && firstRun && vpress && (gBootArgsPtr + 3 < gBootArgsEnd)) {
*(gBootArgsPtr++) = ' ';
*(gBootArgsPtr++) = '-';
*(gBootArgsPtr++) = 'v';
}
if ((gBootMode & kBootModeQuiet) && firstRun && spress && (gBootArgsPtr + 3 < gBootArgsEnd))
{
if ((gBootMode & kBootModeQuiet) && firstRun && spress && (gBootArgsPtr + 3 < gBootArgsEnd)) {
*(gBootArgsPtr++) = ' ';
*(gBootArgsPtr++) = '-';
*(gBootArgsPtr++) = 's';
*(gBootArgsPtr++) = 's';
}
}
clearBootArgs();
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
setCursorPosition( 0, 0, 0 );
clearScreenRows( 0, kScreenLastRow );
if ( ! ( gBootMode & kBootModeQuiet ) )
{
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
setCursorPosition(0, 0, 0);
clearScreenRows(0, kScreenLastRow);
if (!(gBootMode & kBootModeQuiet)) {
// Display banner and show hardware info.
printf( bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024 );
printf( getVBEInfoString() );
printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);
printf(getVBEInfoString());
}
changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );
changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);
verbose("Scanning device %x...", gBIOSDev);
}
// When booting from CD, default to hard
// drive boot when possible.
if ( isCDROM && firstRun )
{
const char *val;
char *prompt;
// When booting from CD, default to hard drive boot when possible.
if (isCDROM && firstRun) {
const char *val;
char *prompt;
char *name;
int cnt;
int optionKey;
int cnt;
int optionKey;
if (getValueForKey( kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig )) {
cnt += 1;
prompt = malloc(cnt);
strlcpy(prompt, val, cnt);
} else {
if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {
cnt += 1;
prompt = malloc(cnt);
strlcpy(prompt, val, cnt);
} else {
name = malloc(80);
getBootVolumeDescription( gBootVolume, name, 80, NO );
getBootVolumeDescription(gBootVolume, name, 80, false);
prompt = malloc(256);
sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);
free(name);
cnt = 0;
}
if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig ))
{
// The key specified is a special key.
} else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) {
optionKey = val[0];
} else {
// Default to F8.
optionKey = 0x4200;
}
if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {
// The key specified is a special key.
} else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) {
optionKey = val[0];
} else {
// Default to F8.
optionKey = 0x4200;
}
// If the timeout is zero then it must have been set above due to the
// early catch of F8 which means the user wants to set boot options
// which we ought to interpret as meaning he wants to boot the CD.
if(timeout != 0)
key = countdown(prompt, kMenuTopRow, timeout);
else
key = optionKey;
// If the timeout is zero then it must have been set above due to the
// early catch of F8 which means the user wants to set boot options
// which we ought to interpret as meaning he wants to boot the CD.
if (timeout != 0) {
key = countdown(prompt, kMenuTopRow, timeout);
} else {
key = optionKey;
}
if (cnt)
free(prompt);
if (cnt) {
free(prompt);
}
clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );
// Hit the option key ?
if ( key == optionKey )
{
if (key == optionKey) {
gBootMode &= ~kBootModeQuiet;
timeout = 0;
} else {
key = key & 0xFF;
// Try booting hard disk if user pressed 'h'
if ( biosDevIsCDROM(gBIOSDev) && key == 'h' )
{
if (biosDevIsCDROM(gBIOSDev) && key == 'h') {
BVRef bvr;
// Look at partitions hosting OS X other than the CD-ROM
for ( bvr = bvChain; bvr; bvr = bvr->next )
if ( (bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev )
for (bvr = bvChain; bvr; bvr=bvr->next) {
if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {
gBootVolume = bvr;
}
}
}
goto done;
}
}
if ( gBootMode & kBootModeQuiet )
{
// No input allowed from user.
goto done;
}
if (gBootMode & kBootModeQuiet) {
// No input allowed from user.
goto done;
}
if ( firstRun && ( timeout > 0 ) &&
( countdown("Press any key to enter startup options.",
kMenuTopRow, timeout) == 0 ) )
{
// If the user is holding down a modifier key,
// enter safe mode.
if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) {
gBootMode |= kBootModeSafe;
}
goto done;
}
if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {
// If the user is holding down a modifier key,
// enter safe mode.
if ((readKeyboardShiftFlags() & 0x0F) != 0) {
gBootMode |= kBootModeSafe;
}
goto done;
}
if ( gDeviceCount )
{
// Allocate memory for an array of menu items.
menuItems = (MenuItem *) malloc( sizeof(MenuItem) * gDeviceCount );
if ( menuItems == NULL ) goto done;
if (gDeviceCount) {
// Allocate memory for an array of menu items.
menuItems = malloc(sizeof(MenuItem) * gDeviceCount);
if (menuItems == NULL) {
goto done;
}
// Associate a menu item for each BVRef.
for ( bvr = bvChain, i = gDeviceCount - 1, selectIndex = 0;
bvr; bvr = bvr->next)
if (bvr->visible)
{
getBootVolumeDescription( bvr, menuItems[i].name, 80, YES );
for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {
if (bvr->visible) {
getBootVolumeDescription(bvr, menuItems[i].name, 80, true);
menuItems[i].param = (void *) bvr;
if ( bvr == menuBVR ) selectIndex = i;
if (bvr == menuBVR) {
selectIndex = i;
}
i--;
}
}
}
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
// redraw the background buffer
drawBackground();
gui.devicelist.draw = YES;
gui.redraw = YES;
if ( ! ( gBootMode & kBootModeQuiet ) )
gui.devicelist.draw = true;
gui.redraw = true;
if (!(gBootMode & kBootModeQuiet)) {
bool showBootBanner = true;
// Check if "Boot Banner"=N switch is present in config file.
getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig);
if (showBootBanner) {
// Display banner and show hardware info.
gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);
}
{
BOOL showBootBanner = YES;
// Check if "Boot Banner"=N switch is present in config file.
getBoolForKey( kBootBannerKey, &showBootBanner, &bootInfo->bootConfig);
if ( showBootBanner )
{
// Display banner and show hardware info.
gprintf( &gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024 );
}
// redraw background
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);
}
} else {
// Clear screen and hide the blinking cursor.
clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );
changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 );
}
// Clear screen and hide the blinking cursor.
clearScreenRows(kMenuTopRow, kMenuTopRow + 2);
changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);
}
nextRow = kMenuTopRow;
showPrompt = YES;
if ( gDeviceCount )
{
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
printf("Use \30\31 keys to select the startup volume.");
showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );
nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;
}
nextRow = kMenuTopRow;
showPrompt = true;
if (gDeviceCount) {
if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {
printf("Use \30\31 keys to select the startup volume.");
}
showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );
nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;
}
// Show the boot prompt.
showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);
showBootPrompt( nextRow, showPrompt );
do {
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
// redraw background
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
// reset cursor co-ords
gui.debug.cursor = pos( gui.screen.width - 160 , 10 );
}
key = getc();
do {
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
// redraw background
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
// reset cursor co-ords
gui.debug.cursor = pos( gui.screen.width - 160 , 10 );
}
key = getc();
updateMenu( key, (void **) &menuBVR );
newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);
updateMenu( key, (void **) &menuBVR );
newShowPrompt = (gDeviceCount == 0) ||
(menuBVR->flags & kBVFlagNativeBoot);
if ( newShowPrompt != showPrompt )
{
showPrompt = newShowPrompt;
showBootPrompt( nextRow, showPrompt );
}
if ( showPrompt )
updateBootArgs( key );
switch ( key )
{
case kReturnKey:
if (newShowPrompt != showPrompt) {
showPrompt = newShowPrompt;
showBootPrompt( nextRow, showPrompt );
}
if ( gui.menu.draw )
{
key=0;
break;
}
if (showPrompt) {
updateBootArgs(key);
}
if ( *gBootArgs == '?' )
{
char * argPtr = gBootArgs;
switch (key) {
case kReturnKey:
if (gui.menu.draw) {
key=0;
break;
}
if (*gBootArgs == '?') {
char * argPtr = gBootArgs;
// Skip the leading "?" character.
argPtr++;
getNextArg(&argPtr, booterCommand);
getNextArg(&argPtr, booterParam);
/*
* TODO: this needs to be refactored.
*/
if ( strcmp( booterCommand, "video" ) == 0 )
{
if( bootArgs->Video.v_display == GRAPHICS_MODE )
showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
else
printVBEModeInfo();
}
else if ( strcmp( booterCommand, "memory" ) == 0 )
if( bootArgs->Video.v_display == GRAPHICS_MODE )
showInfoBox( "Memory Map", getMemoryInfoString() );
else
printMemoryInfo();
else if ( strcmp( booterCommand, "lspci" ) == 0 )
lspci(booterParam);
else if ( strcmp( booterCommand, "more" ) == 0 )
showTextFile(booterParam);
// Skip the leading "?" character.
argPtr++;
getNextArg(&argPtr, booterCommand);
getNextArg(&argPtr, booterParam);
else if ( strcmp( booterCommand, "rd" ) == 0 )
processRAMDiskCommand(&argPtr, booterParam);
/*
* TODO: this needs to be refactored.
*/
if (strcmp( booterCommand, "video" ) == 0) {
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
showInfoBox(getVBEInfoString(), getVBEModeInfoString());
} else {
printVBEModeInfo();
}
} else if ( strcmp( booterCommand, "memory" ) == 0) {
if (bootArgs->Video.v_display == GRAPHICS_MODE ) {
showInfoBox("Memory Map", getMemoryInfoString());
} else {
printMemoryInfo();
}
} else if (strcmp(booterCommand, "lspci") == 0) {
lspci();
} else if (strcmp(booterCommand, "more") == 0) {
showTextFile(booterParam);
} else if (strcmp(booterCommand, "rd") == 0) {
processRAMDiskCommand(&argPtr, booterParam);
} else if (strcmp(booterCommand, "norescan") == 0) {
if (gEnableCDROMRescan) {
gEnableCDROMRescan = false;
break;
}
} else {
showHelp();
}
key = 0;
showBootPrompt(nextRow, showPrompt);
break;
}
gBootVolume = menuBVR;
setRootVolume(menuBVR);
gBIOSDev = menuBVR->biosdev;
break;
else if ( strcmp( booterCommand, "norescan" ) == 0 )
{
if (gEnableCDROMRescan)
{
gEnableCDROMRescan = FALSE;
break;
}
}
case kEscapeKey:
clearBootArgs();
break;
else
{
showHelp();
}
case kF5Key:
// New behavior:
// Clear gBootVolume to restart the loop
// if the user enabled rescanning the optical drive.
// Otherwise boot the default boot volume.
if (gEnableCDROMRescan) {
gBootVolume = NULL;
clearBootArgs();
}
break;
key = 0;
showBootPrompt( nextRow, showPrompt );
break;
}
case kF10Key:
gScanSingleDrive = false;
scanDisks(gBIOSDev, &bvCount);
gBootVolume = NULL;
clearBootArgs();
break;
gBootVolume = menuBVR;
setRootVolume(menuBVR);
gBIOSDev = menuBVR->biosdev;
break;
case kTabKey:
// New behavior:
// Switch between text & graphic interfaces
// Only Permitted if started in graphics interface
if (useGUI) {
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
setVideoMode(VGA_TEXT_MODE, 0);
case kEscapeKey:
clearBootArgs();
break;
setCursorPosition(0, 0, 0);
clearScreenRows(0, kScreenLastRow);
case kF5Key:
// New behavior:
// Clear gBootVolume to restart the loop
// if the user enabled rescanning the optical drive.
// Otherwise boot the default boot volume.
if (gEnableCDROMRescan)
{
gBootVolume = NULL;
clearBootArgs();
}
break;
// Display banner and show hardware info.
printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);
printf(getVBEInfoString());
case kF10Key:
gScanSingleDrive = FALSE;
scanDisks(gBIOSDev, &bvCount);
gBootVolume = NULL;
clearBootArgs();
break;
clearScreenRows(kMenuTopRow, kMenuTopRow + 2);
changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);
case kTabKey:
// New behavior:
// Switch between text & graphic interfaces
// Only Permitted if started in graphics interface
if (useGUI)
{
if (bootArgs->Video.v_display == GRAPHICS_MODE)
{
setVideoMode( VGA_TEXT_MODE, 0 );
setCursorPosition( 0, 0, 0 );
clearScreenRows( 0, kScreenLastRow );
// Display banner and show hardware info.
printf( bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024 );
printf( getVBEInfoString() );
clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );
changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 );
nextRow = kMenuTopRow;
showPrompt = YES;
if ( gDeviceCount )
{
printf("Use \30\31 keys to select the startup volume.");
showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );
nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;
}
showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);
showBootPrompt( nextRow, showPrompt );
//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );
}
else
{
gui.redraw = YES;
setVideoMode( GRAPHICS_MODE, 0 );
updateVRAM();
}
}
key = 0;
break;
nextRow = kMenuTopRow;
showPrompt = true;
default:
key = 0;
}
}
while ( 0 == key );
if (gDeviceCount) {
printf("Use \30\31 keys to select the startup volume.");
showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);
nextRow += min(gDeviceCount, kMenuMaxItems) + 3;
}
done:
firstRun = NO;
showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);
showBootPrompt(nextRow, showPrompt);
//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );
} else {
gui.redraw = true;
setVideoMode(GRAPHICS_MODE, 0);
updateVRAM();
}
}
key = 0;
break;
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
clearScreenRows( kMenuTopRow, kScreenLastRow );
changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );
}
default:
key = 0;
break;
}
} while (0 == key);
shouldboot = NO;
gui.menu.draw = NO;
if ( menuItems )
done:
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
clearScreenRows(kMenuTopRow, kScreenLastRow);
changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);
}
shouldboot = false;
gui.menu.draw = false;
if (menuItems) {
free(menuItems);
return 0;
menuItems = NULL;
}
return 0;
}
//==========================================================================
extern unsigned char chainbootdev;
extern unsigned char chainbootflag;
BOOL
copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)
bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)
{
int argLen = argName ? strlen(argName) : 0;
int len = argLen + cnt + 1; // +1 to account for space
if (len > *cntRemainingP) {
error("Warning: boot arguments too long, truncating\n");
return NO;
return false;
}
if (argName) {
(*argP)++;
*cntRemainingP -= len;
return YES;
return true;
}
//
// Returns TRUE if an argument was copied, FALSE otherwise
BOOL
bool
processBootArgument(
const char *argName, // The argument to search for
const char *userString, // Typed-in boot arguments
{
const char *val;
int cnt;
BOOL found = NO;
bool found = false;
if (getValueForBootKey(userString, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = YES;
found = true;
} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = YES;
found = true;
} else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {
copyArgument(argName, val, cnt, argP, cntRemainingP);
found = YES;
found = true;
}
if (found && foundVal) {
strlcpy(foundVal, val, cnt+1);
int cntRemaining;
char * argP;
char uuidStr[64];
BOOL uuidSet = NO;
bool uuidSet = false;
char * configKernelFlags;
char * valueBuffer;
valueBuffer = (char *)malloc(VALUE_SIZE);
valueBuffer = malloc(VALUE_SIZE);
skipblanks( &cp );
// Load config table specified by the user, or use the default.
if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) {
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
val = 0;
cnt = 0;
}
// overriding the kernel, which causes the kernelcache not
// to be used.
gOverrideKernel = NO;
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strcpy( bootInfo->bootFile, kernel );
gOverrideKernel = YES;
gOverrideKernel = true;
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = YES;
gOverrideKernel = true;
}
} else {
strcpy( bootInfo->bootFile, kDefaultKernel );
argP = bootArgs->CommandLine;
// Get config table kernel flags, if not ignored.
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == TRUE ||
getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig ) == FALSE) {
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {
val = "";
cnt = 0;
}
configKernelFlags = (char *)malloc(cnt + 1);
configKernelFlags = malloc(cnt + 1);
strlcpy(configKernelFlags, val, cnt + 1);
if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {
// boot-uuid was set either on the command-line
// or in the config file.
uuidSet = YES;
uuidSet = true;
} else {
//
{
getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);
copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining);
uuidSet = YES;
uuidSet = true;
}
}
if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) {
verbose("Setting boot-uuid to: %s\n", uuidStr);
copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);
uuidSet = YES;
uuidSet = true;
}
}
//==========================================================================
// Load the help file and display the file contents on the screen.
void showHelp()
static void showTextBuffer(char *buf, int size)
{
#define BOOT_HELP_PATH "bt(0,0)/Extra/BootHelp.txt"
char*bp;
intline;
intline_offset;
intc;
#ifdef EMBED_THEME
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
showInfoBox( "Help. Press q to quit.\n" , (char *)BootHelp_txt );
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
showInfoBox( "Press q to quit\n",buf );
return;
}
#endif
showTextFile(BOOT_HELP_PATH);
}
void showTextFile(const char * filename)
{
#define MAX_TEXT_FILE_SIZE 65536
int fd;
int size;
int line;
int line_offset;
int c;
char fn[1024];
*fn = '\0';
strcat(fn, filename);
if ( (fd = open(fn, 0)) >= 0 )
{
char * buffer;
char * bp;
size = file_size(fd);
if (size > MAX_TEXT_FILE_SIZE)
size = MAX_TEXT_FILE_SIZE;
buffer = malloc( size + 1 );
read(fd, buffer, size);
close(fd);
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
showInfoBox( "Help. Press q to quit.\n" , buffer );
return;
bp = buf;
while (size-- > 0) {
if (*bp == '\n') {
*bp = '\0';
}
bp = buffer;
while (size > 0) {
while (*bp != '\n') {
bp++;
size--;
}
*bp++ = '\0';
size--;
bp++;
}
*bp = '\1';
line_offset = 0;
setActiveDisplayPage(1);
while (1) {
clearScreenRows(0, 24);
setCursorPosition(0, 0, 1);
bp = buffer;
for (line = 0; *bp != '\1' && line < line_offset; line++) {
while (*bp != '\0') bp++;
bp++;
}
for (line = 0; *bp != '\1' && line < 23; line++) {
setCursorPosition(0, line, 1);
printf("%s\n", bp);
while (*bp != '\0') bp++;
bp++;
}
clearScreenRows(0, 24);
setCursorPosition(0, 0, 1);
bp = buf;
for (line = 0; *bp != '\1' && line < line_offset; line++) {
while (*bp != '\0') {
bp++;
}
bp++;
}
for (line = 0; *bp != '\1' && line < 23; line++) {
setCursorPosition(0, line, 1);
printf("%s\n", bp);
while (*bp != '\0') {
bp++;
}
bp++;
}
setCursorPosition(0, 23, 1);
if (*bp == '\1') {
printf("[Type %sq or space to quit viewer]",
(line_offset > 0) ? "p for previous page, " : "");
} else {
printf("[Type %s%sq to quit viewer]",
(line_offset > 0) ? "p for previous page, " : "",
(*bp != '\1') ? "space for next page, " : "");
}
setCursorPosition(0, 23, 1);
if (*bp == '\1') {
printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");
} else {
printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");
}
c = getc();
if (c == 'q' || c == 'Q') {
break;
}
if ((c == 'p' || c == 'P') && line_offset > 0) {
line_offset -= 23;
}
if (c == ' ') {
if (*bp == '\1') {
break;
} else {
line_offset += 23;
}
}
c = getc();
if (c == 'q' || c == 'Q') {
break;
}
if ((c == 'p' || c == 'P') && line_offset > 0) {
line_offset -= 23;
}
if (c == ' ') {
if (*bp == '\1') {
break;
} else {
line_offset += 23;
}
}
}
free(buffer);
setActiveDisplayPage(0);
}
else
{
printf("\nFile not found: %s\n", fn);
sleep(2);
}
}
static inline int isHexDigit(char ch)
void showHelp(void)
{
return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f');
if (bootArgs->Video.v_display == GRAPHICS_MODE) {
showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);
} else {
showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);
}
}
void showTextFile(const char * filename)
{
#define MAX_TEXT_FILE_SIZE 65536
char*buf;
intfd;
intsize;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
printf("\nFile not found: %s\n", filename);
sleep(2);
return;
}
size = file_size(fd);
if (size > MAX_TEXT_FILE_SIZE) {
size = MAX_TEXT_FILE_SIZE;
}
buf = malloc(size);
read(fd, buf, size);
close(fd);
showTextBuffer(buf, size);
free(buf);
}
// This is a very simplistic prompting scheme that just grabs two hex characters
// Eventually we need to do something more user-friendly like display a menu
// based off of the Multiboot device list
int selectAlternateBootDevice(int bootdevice)
{
int digitsI = 0;
char digits[3] = {0,0,0};
// We've already printed the current boot device so user knows what it is
printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");
printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);
int key = 0;
do {
key = getc();
switch(key & kASCIIKeyMask)
{
case kBackspaceKey:
if(digitsI > 0)
{
int x, y, t;
getCursorPositionAndType(&x, &y, &t);
// Assume x is not 0;
x--;
setCursorPosition(x,y,0); // back up one char
// Overwrite with space without moving cursor position
putca(' ', 0x07, 1);
digitsI--;
}
else
{
// TODO: Beep or something
}
break;
case kReturnKey:
if(1)
{
digits[digitsI] = '\0';
char *end;
int newbootdevice = strtol(digits, &end, 16);
if(end == digits && *end == '\0') // User entered empty string
{
printf("\nUsing default boot device %x\n", bootdevice);
key = 0;
}
else if(end != digits && *end == '\0')
{
bootdevice = newbootdevice;
printf("\n");
key = 0; // We gots da boot device
}
else
{
printf("\nCouldn't parse. try again: ");
digitsI = 0;
}
}
break;
default:
if( isHexDigit(key & kASCIIKeyMask) && digitsI < 2 )
{
putc(key & kASCIIKeyMask);
digits[digitsI++] = key & kASCIIKeyMask;
}
else
{
// TODO: Beep or something
}
};
} while(key != 0);
return bootdevice;
}
int key;
int newbootdevice;
int digitsI = 0;
char *end;
char digits[3] = {0,0,0};
BOOL promptForRescanOption(void)
{
int key;
BOOL result = FALSE;
// We've already printed the current boot device so user knows what it is
printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");
printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);
do {
key = getc();
switch (key & kASCIIKeyMask) {
case kBackspaceKey:
if (digitsI > 0) {
int x, y, t;
getCursorPositionAndType(&x, &y, &t);
// Assume x is not 0;
x--;
setCursorPosition(x,y,0); // back up one char
// Overwrite with space without moving cursor position
putca(' ', 0x07, 1);
digitsI--;
} else {
// TODO: Beep or something
}
break;
printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");
key = getc();
case kReturnKey:
digits[digitsI] = '\0';
newbootdevice = strtol(digits, &end, 16);
if (end == digits && *end == '\0') {
// User entered empty string
printf("\nUsing default boot device %x\n", bootdevice);
key = 0;
} else if(end != digits && *end == '\0') {
bootdevice = newbootdevice;
printf("\n");
key = 0; // We gots da boot device
} else {
printf("\nCouldn't parse. try again: ");
digitsI = 0;
}
break;
switch ( key )
{
case kReturnKey:
result = TRUE;
break;
}
return result;
}
default:
if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) {
putc(key & kASCIIKeyMask);
digits[digitsI++] = key & kASCIIKeyMask;
} else {
// TODO: Beep or something
}
break;
};
} while (key != 0);
return bootdevice;
}
bool promptForRescanOption(void)
{
printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");
if (getc() == kReturnKey) {
return true;
} else {
return false;
}
}
trunk/i386/boot2/Makefile
5959
6060
6161
62
62
6363
64
64
6565
6666
6767
all: $(DIRS_NEEDED) boot
embedtheme: CFLAGS += -DEMBED_THEME
embedtheme: art.h embedded.h all
embedtheme: art.h all
boot: machOconv $(OBJS) $(LIBDEP)
boot: machOconv embedded.h $(OBJS) $(LIBDEP)
$(LD) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \
-nostdlib -arch i386 -Wl,-segalign,20 \
-o $(SYMROOT)/boot.sys $(filter %.o,$^) $(LIBS) -lcc_kext
trunk/i386/libsa/libsa.h
3030
3131
3232
33
3334
3435
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
3570
3671
3772
......
91126
92127
93128
94
95
129
130
131
96132
97133
98134
#include <mach-o/loader.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
/*
* ctype stuff (aserebln)
*/
static inline int isupper(char c)
{
return (c >= 'A' && c <= 'Z');
}
static inline int islower(char c)
{
return (c >= 'a' && c <= 'z');
}
static inline int isalpha(char c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}
static inline int isspace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
}
static inline int isdigit(char c)
{
return (c >= '0' && c <= '9');
}
static inline int isxdigit(char c)
{
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
}
/*
* string.c
*/
#ifndef bcopy
/*
* zalloc.c
*/
extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t));
extern void * malloc(size_t size);
#define malloc(size)safe_malloc(size, __FILE__, __LINE__)
extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int));
extern void * safe_malloc(size_t size,const char *file, int line);
extern void free(void * start);
extern void * realloc(void * ptr, size_t size);
trunk/i386/libsa/efi_tables.h
77
88
99
10
11
10
1211
1312
14
13
1514
1615
1716
#include "efi.h"
uint32_t
crc32(uint32_t crc, const void *buf, size_t size);
uint32_t crc32(uint32_t crc, const void *buf, size_t size);
void efi_guid_unparse_upper(EFI_GUID const *pGuid, char *out);
int efi_guid_is_null(EFI_GUID const *pGuid);
bool efi_guid_is_null(EFI_GUID const *pGuid);
int efi_guid_compare(EFI_GUID const *pG1, EFI_GUID const *pG2);
#endif //ndef _LIBSA_EFI_TABLES_H__
trunk/i386/libsa/zalloc.c
4848
4949
5050
51
51
5252
5353
5454
......
6161
6262
6363
64
64
6565
6666
6767
......
6969
7070
7171
72
72
7373
7474
7575
......
8686
8787
8888
89
89
9090
9191
9292
......
104104
105105
106106
107
107
108108
109109
110110
......
155155
156156
157157
158
158
159159
160160
161161
......
204204
205205
206206
207
207
208208
209209
210210
......
232232
233233
234234
235
235
236236
237237
238238
......
242242
243243
244244
245
245
246246
247247
248248
......
260260
261261
262262
263
263
264264
265265
266266
......
315315
316316
317317
318
318
319319
320320
321321
static short availableNodes, allocedNodes, totalNodes;
static char * zalloc_base;
static char * zalloc_end;
static void (*zerror)(char *, size_t);
static void (*zerror)(char *, size_t, const char *, int);
static void zallocate(char * start,int size);
static void zinsert(zmem * zp, int ndx);
#define ZALLOC_NODES16384
static void malloc_error(char *addr, size_t size)
static void malloc_error(char *addr, size_t size, const char *file, int line)
{
#ifdef i386
asm volatile ("hlt");
}
// define the block of memory that the allocator will use
void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t))
void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t, const char *, int))
{
zalloc_base = start ? start : (char *)ZALLOC_ADDR;
totalNodes = nodes ? nodes : ZALLOC_NODES;
#define BEST_FIT 1
void * malloc(size_t size)
void * safe_malloc(size_t size, const char *file, int line)
{
int i;
#if BEST_FIT
size = ((size + 0xf) & ~0xf);
if (size == 0) {
if (zerror) (*zerror)((char *)0xdeadbeef, 0);
if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line);
}
#if BEST_FIT
smallestSize = 0;
done:
if ((ret == 0) || (ret + size >= zalloc_end))
{
if (zerror) (*zerror)(ret, size);
if (zerror) (*zerror)(ret, size, file, line);
}
if (ret != 0)
{
}
}
if ( !found ) {
if (zerror) (*zerror)(pointer, rp);
if (zerror) (*zerror)(pointer, rp, "free", 0);
else return;
}
#if ZDEBUG
if ((start + tsize) < zavailable[i].start)
{
if (++availableNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 0);
if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0);
}
zinsert(zavailable, i);
zavailable[i].start = start;
}
if (++availableNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 1);
if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0);
}
zavailable[i].start = start;
zavailable[i].size = tsize;
zalloced[allocedNodes].start = start;
zalloced[allocedNodes].size = size;
if (++allocedNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 2);
if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0);
};
}
/* This is the simplest way possible. Should fix this. */
void * realloc(void * start, size_t newsize)
{
void * newstart = malloc(newsize);
void * newstart = safe_malloc(newsize, __FILE__, __LINE__);
bcopy(start, newstart, newsize);
free(start);
return newstart;
trunk/i386/libsa/strtol.c
7474
7575
7676
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
10877
10978
11079
#include "libsa.h"
#include <limits.h>
static inline int
isupper(char c)
{
return (c >= 'A' && c <= 'Z');
}
static inline int
islower(char c)
{
return (c >= 'a' && c <= 'z');
}
static inline int
isalpha(char c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}
static inline int
isspace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
}
static inline int
isdigit(char c)
{
return (c >= '0' && c <= '9');
}
/*
* Convert a string to a long integer.
*
trunk/i386/libsa/efi_tables.c
9797
9898
9999
100
101
100
102101
103102
104103
......
128127
129128
130129
131
130
132131
133132
134133
......
136135
137136
138137
139
138
140139
141
140
142141
143
142
144143
145144
146145
......
161160
162161
163162
164
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t
crc32(uint32_t crc, const void *buf, size_t size)
uint32_t crc32(uint32_t crc, const void *buf, size_t size)
{
const uint8_t *p;
pGuid->Data4[6], pGuid->Data4[7]);
}
int efi_guid_is_null(EFI_GUID const *pGuid)
bool efi_guid_is_null(EFI_GUID const *pGuid)
{
if(pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0)
{
for(i=0; i<8; ++i)
{
if(pGuid->Data4[i] != 0)
return FALSE;
return false;
}
return TRUE;
return true;
}
return FALSE;
return false;
}
#define COMPARE_MEMBER_AND_RETURN_IF_NE(a,b,mem) \
}
return 0;
}
trunk/i386/util/machOconv.c
2323
2424
2525
26
2627
2728
2829
......
3536
3637
3738
38
39
3940
4041
4142
......
8586
8687
8788
88
89
8990
90
91
9192
9293
9394
......
110111
111112
112113
113
114
114115
115116
116117
......
123124
124125
125126
126
127
127128
128129
129130
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <sys/file.h>
struct mach_headermh;
void *cmds;
boolean_tswap_ends;
static boolswap_ends;
static unsigned long swap(
unsigned long x
exit(1);
}
if (mh.magic == MH_MAGIC)
swap_ends = FALSE;
swap_ends = false;
else if (mh.magic == MH_CIGAM)
swap_ends = TRUE;
swap_ends = true;
else {
fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic);
exit(1);
for (ncmds = swap(mh.ncmds), cp = cmds;
ncmds > 0; ncmds--) {
boolean_tisDATA;
boolisDATA;
unsignedvmsize;
#define lcp((struct load_command *)cp)
vmsize = swap(scp->filesize);
else
vmsize = swap(scp->vmsize);
result = vm_allocate(mach_task_self(), &data, vmsize, TRUE);
result = vm_allocate(mach_task_self(), &data, vmsize, true);
if (result != KERN_SUCCESS) {
mach_error("vm_allocate segment data", result);
exit(1);

Archive Download the corresponding diff file

Revision: 23