Chameleon

Chameleon Commit Details

Date:2010-07-24 10:02:33 (13 years 9 months ago)
Author:blackosx
Commit:215
Parents: 214
Message:Added the GUI rollover device mod to the latest r214 and fixed it so it can be built with the default theme embedded. The booter will now boot with an embedded theme (if built with an embedded theme, and no theme name in the c.a.b.p), a standard RC4 theme and also rollover themes.
Changes:
M/branches/blackosx/artwork/themes/default/device_cdrom.png
M/branches/blackosx/CHANGES
M/branches/blackosx/i386/libsaio/sys.c
M/branches/blackosx/i386/libsaio/hfs.c
M/branches/blackosx/i386/boot1/boot1f32.s
M/branches/blackosx/i386/boot2/drivers.c
M/branches/blackosx/artwork/themes/default/menu_verbose.png
M/branches/blackosx/i386/cdboot/cdboot.s
M/branches/blackosx/artwork/themes/default/device_generic.png
M/branches/blackosx/i386/libsa/memory.h
M/branches/blackosx/i386/libsaio/spd.c
M/branches/blackosx/i386/libsaio/cpu.c
M/branches/blackosx/i386/libsaio/fake_efi.c
M/branches/blackosx/version
M/branches/blackosx/i386/libsaio/pci_setup.c
M/branches/blackosx/i386/libsaio/spd.h
M/branches/blackosx/artwork/themes/default/device_ext3.png
M/branches/blackosx/artwork/themes/default/menu_single_user.png
M/branches/blackosx/i386/libsaio/cpu.h
M/branches/blackosx/i386/boot2/Makefile
M/branches/blackosx/i386/boot2/boot.c
M/branches/blackosx/i386/boot1/boot1.s
M/branches/blackosx/artwork/themes/default/menu_ignore_caches.png
M/branches/blackosx/i386/libsa/libsa.h
M/branches/blackosx/artwork/themes/default/menu_verbose_disabled.png
M/branches/blackosx/i386/libsaio/nvidia.c
M/branches/blackosx/i386/boot2/boot.h
M/branches/blackosx/i386/libsaio/acpi.h
M/branches/blackosx/artwork/themes/default/device_ntfs.png
M/branches/blackosx/i386/boot1/boot1he.s
M/branches/blackosx/artwork/themes/default/menu_single_user_disabled.png
M/branches/blackosx/i386/libsaio/platform.c
M/branches/blackosx/i386/libsaio/msdos.c
M/branches/blackosx/i386/boot2/gui.c
M/branches/blackosx/artwork/themes/default/device_fat32.png
M/branches/blackosx/artwork/themes/default/device_fat16.png
M/branches/blackosx/i386/libsaio/platform.h
M/branches/blackosx/i386/libsaio/usb.c
M/branches/blackosx/i386/libsaio/Makefile
M/branches/blackosx/i386/boot2/gui.h
M/branches/blackosx/artwork/themes/default/device_hfsplus.png
M/branches/blackosx/i386/libsaio/saio_internal.h
M/branches/blackosx/artwork/themes/default/device_selection.png
M/branches/blackosx/artwork/themes/default/menu_ignore_caches_disabled.png
M/branches/blackosx/i386/boot2/options.c
M/branches/blackosx/CREDITS
M/branches/blackosx/i386/libsaio/smbios_patcher.c
M/branches/blackosx/doc/BootHelp.txt

File differences

branches/blackosx/doc/BootHelp.txt
4747
4848
4949
50
50
51
5152
5253
5354
......
7071
7172
7273
73
74
7475
7576
77
78
7679
7780
7881
"Instant Menu"=Yes Force displaying the partition selection menu.
"Default Partition" Sets the default boot partition,
=hd(x,y) where 'x' & 'y' are the disk and partition numbers.
=hd(x,y)| where 'x' & 'y' are the disk and partition numbers
=<UUID> or specify the selected volume UUID string.
"Hide Partition" Remove unwanted partition(s) from the boot menu.
=hd(x,y) [hd(m,n)] only non mac osx boot partitions can be hidden.
EthernetBuiltIn=Yes|No Automatic "built-in"=yes device-properties generation
for ethernet interfaces.
USBBusFix=Yes Enable the EHCI and UHCI fixes (disabled by default).
USBBusFix=Yes Enable all USB fixes below:
EHCIacquire=Yes Enable the EHCI fix (disabled by default).
UHCIreset=Yes Enable the UHCI fix (disabled by default).
USBLegacyOff=Yes Enable the USB Legacy fix (disabled by default).
ForceHPET=Yes|No Force Enable HPET.
Wake=No Disable wake up after hibernation (default: enabled).
branches/blackosx/version
1
1
2.0-RC5 (blackosx_GUI_editv2)
2.0-RC5 (blackosx_GUI_edit_v3)
branches/blackosx/CHANGES
1
2
3
4
1
2
3
4
5
6
57
68
79
- Revised the rollover theme functionality as it was drawing both the normal device image as well as the rollover image.
- Added Conti's fix for overcoming a potential fail with deadbeef error due to a non standard specified resolution, or in my case of testing - on an empty value for the screen_width / screen_height in a theme.plist.
- Added rollover theme functionality while retaining compatibility with existing themes. Note: Compiling with an embedded theme currently fails as I haven't added _o.pngs in to artwork folder. But then if I do, the filesize will exceed the limit.
- Optimized memory detection speed
- Added displaying source device and partition number for file read operations.
- Increased boot2's maximum size from 383.5k to 447.5k.
Updated stage 1 loaders for handling the new size limit.
- Added alternate format for setting the default partition. The user can specify the selected
volume UUID for the "Default Partition" key.
- Implemented SPD memory automatic detection and injection,seems to work really great ...
- Factorized code to prepare a dynamic memory detection algorithm ...
- Optimized smbios table address search
branches/blackosx/i386/libsaio/hfs.c
264264
265265
266266
267
267268
268269
269270
270
271
271272
272273
273274
......
298299
299300
300301
301
302
302
303
304
303305
304306
305307
long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length)
{
char entry[512];
char devStr[12];
long dirID, result, flags;
if (HFSInitPartition(ih) == -1) return -1;
dirID = kHFSRootFolderID;
// Skip a lead '\'. Start in the system folder if there are two.
if (filePath[0] == '/') {
return -1;
}
verbose("Loaded HFS%s file: [%s] %d bytes from %x.\n",
(gIsHFSPlus ? "+" : ""), filePath, (uint32_t)length, ih);
getDeviceStringFromBVR(ih, devStr);
verbose("Read HFS%s file: [%s/%s] %d bytes.\n",
(gIsHFSPlus ? "+" : ""), devStr, filePath, (uint32_t)length);
return length;
}
branches/blackosx/i386/libsaio/spd.c
11
22
3
3
4
5
6
47
58
69
......
8588
8689
8790
88
89
90
91
92
93
9194
9295
9396
9497
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
95123
96124
97
125
98126
99127
100128
101129
102
130
103131
104132
105
106
133
134
107135
108136
109137
110138
111139
112
113
140
141
142
143
144
145
114146
115147
116
148
117149
118150
119151
......
175207
176208
177209
178
210
179211
180
212
181213
182214
183215
184
216
185217
186
187
188
218
219
189220
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
208242
209243
210244
211245
246
212247
213248
214249
215
250
216251
217252
218253
......
225260
226261
227262
263
264
228265
229266
230267
231
232268
233269
234
235
236270
271
237272
238273
239274
240275
241276
242
243
244277
278
279
280
245281
246282
247283
......
260296
261297
262298
263
264
265
299
300
301
266302
267303
268304
269
270
271
305
306
272307
273308
274309
......
277312
278313
279314
280
315
316
281317
282318
283319
......
287323
288324
289325
290
291
292
293
326
294327
295328
296329
......
320353
321354
322355
323
356
324357
325358
326359
......
343376
344377
345378
379
346380
381
347382
/*
* spd.c - serial presence detect memory information
* (restored from pcefi10.5)
*
* Originally restored from pcefi10.5
* Dynamic mem detection original impl. by Rekursor
* System profiler fix and other fixes by Mozodojo.
*/
#include "libsaio.h"
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
t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform.CPU.TSCFrequency / 100);
if (t > 5)
break;// break after 5ms
}
return inb(base + SMBHSTDAT);
}
/* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */
#define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x)
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read from spd *used* values only*/
static void init_spd(char * spd, uint32_t base, int slot)
{
int i;
for (i=0; i< SPD_INDEXES_SIZE; i++) {
READ_SPD(spd, base, slot, spd_indexes[i]);
}
}
/** Get Vendor Name from spd, 2 cases handled DDR3 and DDR2,
have different formats, always return a valid ptr.*/
const char * getVendorName(RamSlotInfo_t* slot)
const char * getVendorName(RamSlotInfo_t* slot, uint32_t base, int slot_num)
{
uint8_t bank = 0;
uint8_t code = 0;
int i = 0;
const char * spd = slot->spd;
char * spd = slot->spd;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { // DDR3
bank = spd[0x75];
code = spd[0x76];
bank = spd[SPD_DDR3_MEMORY_BANK];
code = spd[SPD_DDR3_MEMORY_CODE];
for (i=0; i < VEN_MAP_SIZE; i++)
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
return vendorMap[i].name;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) {
if(spd[0x40]==0x7f) {
for (i=0x40; i<0x48 && spd[i]==0x7f;i++) bank++;
if(spd[64]==0x7f) {
for (i=64; i<72 && spd[i]==0x7f;i++) {
bank++;
READ_SPD(spd, base, slot_num,i+1); // prefetch next spd byte to read for next loop
}
READ_SPD(spd, base, slot_num,i);
code = spd[i];
} else {
code = spd[0x40];
code = spd[64];
bank = 0;
}
for (i=0; i < VEN_MAP_SIZE; i++)
}
if (!ret) sprintf(asciiSerial, "10000000%d", serialnum++);
else sprintf(asciiSerial, "%d", ret);
else sprintf(asciiSerial, "%X", ret);
return asciiSerial;
return strdup(asciiSerial);
}
/** Get DDR3 or DDR2 Part Number, always return a valid ptr */
const char * getDDRPartNum(const char* spd)
const char * getDDRPartNum(char* spd, uint32_t base, int slot)
{
const char * sPart = NULL;
int i;
bool bZero = false;
static char asciiPartNo[32];
int i, start=0, index = 0;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
sPart = &spd[128];
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2)
sPart = &spd[73];
if (sPart) { // Check that the spd part name is zero terminated and that it is ascii:
for (i=0; i<32; i++) {
if (sPart[i]==0) {
bZero = true;
break;
}
else if ( !isascii(sPart[i]) ) {
sPart = NULL;
break;
}
}
}
return ( sPart==NULL || !(*sPart) || !bZero ) ?
"N/A" : sPart;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
start = 128;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) {
start = 73;
}
// Check that the spd part name is zero terminated and that it is ascii:
bzero(asciiPartNo, 32);
char c;
for (i=start; i<start+32; i++) {
READ_SPD(spd, base, slot, i); // only read once the corresponding model part (ddr3 or ddr2)
c = spd[i];
if (isalpha(c) || isdigit(c) || ispunct(c)) // It seems that System Profiler likes only letters and digits...
asciiPartNo[index++] = c;
else if (!isascii(c))
break;
}
return strdup(asciiPartNo);
return NULL;
}
int mapping []= {0,2,1,3,4,6,5,7,8,10,9,11};
/** Read from smbus the SPD content and interpret it for detecting memory attributes */
static void read_smb_intel(pci_dt_t *smbus_dev)
{
int i, x, speed;
int i, speed;
uint8_t spd_size, spd_type;
uint32_t base;
bool dump = false;
bool fullBanks = // needed at least for laptops
Platform.DMI.MemoryModules == Platform.DMI.MaxMemorySlots;
// Search MAX_RAM_SLOTS slots
char spdbuf[256];
for (i = 0; i < MAX_RAM_SLOTS; i++){
slot = &Platform.RAM.DIMM[i];
spd_size = smb_read_byte_intel(base, 0x50 + i, 0);
// Check spd is present
if (spd_size && (spd_size != 0xff) ) {
slot->spd = malloc(spd_size);
if (slot->spd == NULL) continue;
slot->spd = spdbuf;
slot->InUse = true;
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);
//for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x);
init_spd(slot->spd, base, i);
switch (slot->spd[SPD_MEMORY_TYPE]) {
case SPD_MEMORY_TYPE_SDRAM_DDR2:
spd_type = (slot->spd[SPD_MEMORY_TYPE] < ((char) 12) ? slot->spd[SPD_MEMORY_TYPE] : 0);
slot->Type = spd_mem_to_smbios[spd_type];
slot->PartNo = strdup(getDDRPartNum(slot->spd) );
slot->Vendor = strdup(getVendorName(slot) );
slot->SerialNo = strdup(getDDRSerial(slot->spd));
slot->PartNo = getDDRPartNum(slot->spd, base, i);
slot->Vendor = getVendorName(slot, base, i);
slot->SerialNo = getDDRSerial(slot->spd);
// determine spd speed
speed = getDDRspeedMhz(slot->spd);
if (speed > slot->Frequency) slot->Frequency = speed; // just in case dmi wins on spd
if(dump) {
printf("Slot %d Type %d %dMB (%s) %dMHz Vendor=%s, PartNo=%s SerialNo=%s\n",
if (slot->Frequency<speed) slot->Frequency = speed; // should test the mem controller to get potential overclocking info ?
printf("Slot: %d Type %d %dMB (%s) %dMHz Vendor=%s\n PartNo=%s SerialNo=%s\n",
i,
(int)slot->Type,
slot->ModuleSize,
slot->Vendor,
slot->PartNo,
slot->SerialNo);
dumpPhysAddr("spd content: ",slot->spd, spd_size);
if(DEBUG_SPD) {
dumpPhysAddr("spd content: ",slot->spd, spd_size);
getc();
}
}
i>0 && Platform.RAM.DIMM[1].InUse==false && fullBanks && Platform.DMI.MaxMemorySlots==2 ?
mapping[i] : i; // for laptops case, mapping setup would need to be more generic than this
if (slot->spd) {
free(slot->spd);
slot->spd = NULL;
}
slot->spd = NULL;
} // for
}
int i;
while (current) {
#if DEBUG_SPD
#if 0
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,
void scan_spd(PlatformInfo_t *p)
{
printf("\n--> Start of mem detect:\n");
find_and_read_smbus_controller(root_pci_dev);
printf("\n<-- End of mem detect.\n");
}
branches/blackosx/i386/libsaio/spd.h
9494
9595
9696
97
98
9799
98100
99101
#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 */
#define SPD_DDR3_MEMORY_BANK 0x75
#define SPD_DDR3_MEMORY_CODE 0x76
/* DRAM specifications use the following naming conventions for SPD locations */
#define SPD_tRP SPD_MIN_ROW_PRECHARGE_TIME
branches/blackosx/i386/libsaio/Makefile
3939
4040
4141
42
42
4343
4444
4545
46
46
4747
4848
4949
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 \
cpu.o platform.o dsdt_patcher.o \
cpu.o platform.o acpi_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 pci_root.o \
convert.o mem.o
convert.o mem.o aml_generator.o
SAIO_EXTERN_OBJS = console.o
branches/blackosx/i386/libsaio/smbios_patcher.c
142142
143143
144144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
145159
146160
147
148
149
150
151
152
153
154
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
155188
189
190
156191
157192
158193
......
166201
167202
168203
204
169205
170206
171207
......
777813
778814
779815
780
816
781817
782818
783819
return Platform.CPU.CPUFrequency/1000000;
}
static int sm_get_simplecputype()
{
if (Platform.CPU.NoCores >= 4)
{
return 0x0501; // Quad-Core Xeon
}
else if (Platform.CPU.NoCores == 1)
{
return 0x0201; // Core Solo
};
return 0x0301; // Core 2 Duo
}
static int sm_get_cputype (const char *name, int table_num)
{
if (Platform.CPU.NoCores == 1) {
return 0x0101; // <01 01> Intel Core Solo?
} else if (Platform.CPU.NoCores == 2) {
return 0x0301; // <01 03> Intel Core 2 Duo
} else if (Platform.CPU.NoCores >= 4) {
return 0x0501; // <01 05> Quad-Core Intel Xeon
} else {
return 0x0301; // Default to Core 2 Duo
if (Platform.CPU.Vendor == 0x756E6547) // Intel
{
verbose("CPU is Intel, family 0x%x, model 0x%x, ext.model 0x%x\n", Platform.CPU.Family, Platform.CPU.Model, Platform.CPU.ExtModel);
switch (Platform.CPU.Family)
{
case 0x06:
{
switch (Platform.CPU.Model)
{
case 0x0F: // Intel Core (65nm)
case 0x17: // Intel Core (45nm)
case 0x1C: // Intel Atom (45nm)
return sm_get_simplecputype();
case 0x1A: // Intel Core i7 LGA1366 (45nm)
return 0x0701;
case 0x1E: // Intel Core i5, i7 LGA1156 (45nm)
case 0x1F: // Intel Core i5, i7 LGA1156 (45nm) ???
return 0x0601;
case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm)
return 0x0301;
case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core
case 0x2E: // Intel Core i7 LGA1366 (45nm) 6 Core ???
return 0x0601;
}
}
}
}
return sm_get_simplecputype();
}
static int sm_get_memtype (const char *name, int table_num)
return Platform.RAM.DIMM[map].Type;
}
}
return SMB_MEM_TYPE_DDR2;
}
DmiTablePairCount++;
}
else {
printf("DMI table entries list is full! next entries won't be stored\n");
printf("DMI table entries list is full! Next entries won't be stored.\n");
}
#if DEBUG_SMBIOS
printf("DMI header found for table type %d, length = %d\n", dmihdr->type, dmihdr->length);
branches/blackosx/i386/libsaio/usb.c
2222
2323
2424
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
25201
26202
27203
#define DBG(x...)
#endif
struct pciList
{
pci_dt_t* pciDev;
struct pciList* next;
};
struct pciList* usbList = NULL;
int legacy_off (pci_dt_t *pci_dev);
int ehci_acquire (pci_dt_t *pci_dev);
int uhci_reset (pci_dt_t *pci_dev);
// Add usb device to the list
void notify_usb_dev(pci_dt_t *pci_dev)
{
struct pciList* current = usbList;
if(!usbList)
{
usbList = (struct pciList*)malloc(sizeof(struct pciList));
usbList->next = NULL;
usbList->pciDev = pci_dev;
}
else
{
while(current != NULL && current->next != NULL)
{
current = current->next;
}
current->next = (struct pciList*)malloc(sizeof(struct pciList));
current = current->next;
current->pciDev = pci_dev;
current->next = NULL;
}
}
// Loop through the list and call the apropriate patch function
int usb_loop()
{
int retVal = 1;
bool fix_ehci, fix_uhci, fix_usb, fix_legacy;
fix_ehci = fix_uhci = fix_usb = fix_legacy = false;
if (getBoolForKey(kUSBBusFix, &fix_usb, &bootInfo->bootConfig))
{
fix_ehci = fix_uhci = fix_legacy = fix_usb;// Disable all if none set
}
else
{
getBoolForKey(kEHCIacquire, &fix_ehci, &bootInfo->bootConfig);
getBoolForKey(kUHCIreset, &fix_uhci, &bootInfo->bootConfig);
getBoolForKey(kLegacyOff, &fix_legacy, &bootInfo->bootConfig);
}
struct pciList* current = usbList;
while(current && current->next)
{
switch (pci_config_read8(current->pciDev->dev.addr, PCI_CLASS_PROG))
{
// EHCI
case 0x20:
if(fix_ehci) retVal &= ehci_acquire(current->pciDev);
if(fix_legacy) retVal &= legacy_off(current->pciDev);
break;
// UHCI
case 0x00:
if (fix_uhci) retVal &= uhci_reset(current->pciDev);
break;
}
current = current->next;
}
return retVal;
}
int legacy_off (pci_dt_t *pci_dev)
{
// Set usb legacy off modification by Signal64
// NOTE: This *must* be called after the last file is loaded from the drive in the event that we are booting form usb.
// NOTE2: This should be called after any getc() call. (aka, after the Wait=y keyworkd is used)
// AKA: Make this run immediatly before the kernel is called
uint32_tcapaddr, opaddr;
uint8_teecp;
uint32_tusbcmd, usbsts, usbintr;
uint32_tusblegsup, usblegctlsts;
int isOSowned;
int isBIOSowned;
verbose("Setting Legacy USB Off on controller [%04x:%04x] at %02x:%2x.%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);
// capaddr = Capability Registers = dev.addr + offset stored in dev.addr + 0x10 (USBBASE)
capaddr = pci_config_read32(pci_dev->dev.addr, 0x10);
// opaddr = Operational Registers = capaddr + offset (8bit CAPLENGTH in Capability Registers + offset 0)
opaddr = capaddr + *((unsigned char*)(capaddr));
// eecp = EHCI Extended Capabilities offset = capaddr HCCPARAMS bits 15:8
eecp=*((unsigned char*)(capaddr + 9));
DBG("capaddr=%x opaddr=%x eecp=%x\n", capaddr, opaddr, eecp);
usbcmd = *((unsigned int*)(opaddr));// Command Register
usbsts = *((unsigned int*)(opaddr + 4));// Status Register
usbintr = *((unsigned int*)(opaddr + 8));// Interrupt Enable Register
DBG("usbcmd=%08x usbsts=%08x usbintr=%08x\n", usbcmd, usbsts, usbintr);
// read PCI Config 32bit USBLEGSUP (eecp+0)
usblegsup = pci_config_read32(pci_dev->dev.addr, eecp);
// informational only
isBIOSowned = !!((usblegsup) & (1 << (16)));
isOSowned = !!((usblegsup) & (1 << (24)));
// read PCI Config 32bit USBLEGCTLSTS (eecp+4)
usblegctlsts = pci_config_read32(pci_dev->dev.addr, eecp + 4);
DBG("usblegsup=%08x isOSowned=%d isBIOSowned=%d usblegctlsts=%08x\n", usblegsup, isOSowned, isBIOSowned, usblegctlsts);
// Reset registers to Legacy OFF
DBG("Clearing USBLEGCTLSTS\n");
pci_config_write32(pci_dev->dev.addr, eecp + 4, 0);//usblegctlsts
// if delay value is in milliseconds it doesn't appear to work.
// setting value to anything up to 65535 does not add the expected delay here.
delay(100);
usbcmd = *((unsigned int*)(opaddr));
usbsts = *((unsigned int*)(opaddr + 4));
usbintr = *((unsigned int*)(opaddr + 8));
DBG("usbcmd=%08x usbsts=%08x usbintr=%08x\n", usbcmd, usbsts, usbintr);
DBG("Clearing Registers\n");
// clear registers to default
usbcmd = (usbcmd & 0xffffff00);
*((unsigned int*)(opaddr)) = usbcmd;
*((unsigned int*)(opaddr + 8)) = 0;//usbintr - clear interrupt registers
*((unsigned int*)(opaddr + 4)) = 0x1000;//usbsts - clear status registers
pci_config_write32(pci_dev->dev.addr, eecp, 1);//usblegsup
// get the results
usbcmd = *((unsigned int*)(opaddr));
usbsts = *((unsigned int*)(opaddr + 4));
usbintr = *((unsigned int*)(opaddr + 8));
DBG("usbcmd=%08x usbsts=%08x usbintr=%08x\n", usbcmd, usbsts, usbintr);
// read 32bit USBLEGSUP (eecp+0)
usblegsup = pci_config_read32(pci_dev->dev.addr, eecp);
// informational only
isBIOSowned = !!((usblegsup) & (1 << (16)));
isOSowned = !!((usblegsup) & (1 << (24)));
// read 32bit USBLEGCTLSTS (eecp+4)
usblegctlsts = pci_config_read32(pci_dev->dev.addr, eecp + 4);
DBG("usblegsup=%08x isOSowned=%d isBIOSowned=%d usblegctlsts=%08x\n", usblegsup, isOSowned, isBIOSowned, usblegctlsts);
verbose("Legacy USB Off Done\n");
return 1;
}
int ehci_acquire (pci_dt_t *pci_dev)
{
intj, k;
branches/blackosx/i386/libsaio/nvidia.c
337337
338338
339339
340
341
340
341
342342
343343
344
344345
345346
346347
......
352353
353354
354355
355
356
357
358
359
360
361
362
363
364
365
366
367
356368
357369
358370
......
680692
681693
682694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
683711
684712
685713
{ 0x10DE06F9, "Quadro FX 370 LP" },
{ 0x10DE06FA, "Quadro NVS 450" },
{ 0x10DE06FD, "Quadro NVS 295" },
{ 0x10DE087D, "ION 9400M" },
{ 0x10DE087E, "ION LE" },
{ 0x10DE087D, "ION 9400M" },
{ 0x10DE087E, "ION LE" },
{ 0x10DE0A20, "GeForce GT220" },
{ 0x10DE0A23, "GeForce 210" },
{ 0x10DE0A28, "GeForce GT 230M" },
{ 0x10DE0A2A, "GeForce GT 230M" },
{ 0x10DE0A34, "GeForce GT 240M" },
{ 0x10DE0A60, "GeForce G210" },
{ 0x10DE0A78, "Quadro FX 380 LP" },
{ 0x10DE0CA3, "GeForce GT 240" },
{ 0x10DE0CA8, "GeForce GTS 260M" },
{ 0x10DE0CA9, "GeForce GTS 250M" }
{ 0x10DE0CA9, "GeForce GTS 250M" },
{ 0x10DE0CA3, "GeForce GT240" },
{ 0x10DE06C0, "GeForce GTX 480" },
{ 0x10DE06CD, "GeForce GTX 470" },
{ 0x10DE06C4, "GeForce GTX 465" },
{ 0x10DE06CA, "GeForce GTX 480M" },
{ 0x10DE0E22, "GeForce GTX 460" },
{ 0x10DE0E24, "GeForce GTX 460" },
{ 0x10DE06D1, "Tesla C2050" },// TODO: sub-device id: 0x0771
{ 0x10DE06D1, "Tesla C2070" },// TODO: sub-device id: 0x0772
{ 0x10DE06DE, "Tesla M2050" },// TODO: sub-device id: 0x0846
{ 0x10DE06DE, "Tesla M2070" }// TODO: sub-device id: ?
};
static uint16_t swap16(uint16_t x)
videoRam = (REG32(0x10020c) & 0xfff00000) >> 10;
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
// FIXME: dirty fermi hack
if((nvda_dev->device_id & 0xFFE0) == 0x06C0 ||
(nvda_dev->device_id & 0xFFE0) == 0x0E20) {
switch (nvda_dev->device_id) {
case 0x06C0: videoRam = 1572864; break; // gtx 480
case 0x06CD: videoRam = 1310720; break; // gtx 470
case 0x06C4: videoRam = 1048576; break; // gtx 465
case 0x06CA: videoRam = 2097152; break; // gtx 480m
case 0x0E22: videoRam = 1048576; break; // gtx 460
case 0x0E24: videoRam = 1048576; break; // gtx 460
case 0x06D1: videoRam = 3145728; break; // tesla c2050/c2070
case 0x06DE: videoRam = 3145728; break; // tesla m2050/m2070
default: break;
}
}
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,
branches/blackosx/i386/libsaio/sys.c
8787
8888
8989
90
9091
9192
92
93
94
95
93
94
9695
9796
9897
......
403402
404403
405404
406
407405
408406
409407
......
425423
426424
427425
428
429426
430427
431428
......
602599
603600
604601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
605658
606659
607660
......
762815
763816
764817
765
818
766819
767
820
768821
769822
770823
......
774827
775828
776829
777
830
778831
779832
780833
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
800857
801858
802859
803860
804861
805862
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
825882
826883
827884
......
832889
833890
834891
835
836
837
838
839
840
892
893
894
895
896
897
841898
842899
843900
......
10181075
10191076
10201077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
int type;
};
// Device entries must be ordered by bios device numbers.
static struct devsw devsw[] =
{
{ "sd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_SD */
{ "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */
{ "fd", 0x00, kBIOSDevTypeFloppy }, /* DEV_FD */
{ "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */
{ "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */
{ "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */
{ "rd", 0x100, kBIOSDevTypeHardDrive },
{ "bt", 0x101, kBIOSDevTypeHardDrive }, // turbo - type for booter partition
{ 0, 0 }
return io;
}
#if UNUSED
//==========================================================================
// openmem()
return fdesc;
}
#endif
//==========================================================================
// open() - Open the file specified by 'path' for reading.
}
//==========================================================================
// write() - Write up to 'count' bytes of data to the file descriptor
// from the buffer pointed to by buf.
int write(int fdesc, const char * buf, int count)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + count) > (unsigned int)io->i_filesize)
count = io->i_filesize - io->i_offset;
if (count <= 0)
return 0; // end of file
bcopy(buf, io->i_buf + io->i_offset, count);
io->i_offset += count;
return count;
}
int writebyte(int fdesc, char value)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + 1) > (unsigned int)io->i_filesize)
return 0; // end of file
io->i_buf[io->i_offset++] = value;
return 1;
}
int writeint(int fdesc, int value)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + 4) > (unsigned int)io->i_filesize)
return 0; // end of file
bcopy(&value, io->i_buf + io->i_offset, 4);
io->i_offset += 4;
return 4;
}
//==========================================================================
// file_size() - Returns the size of the file described by the file
// descriptor.
BVRef selectBootVolume( BVRef chain )
{
bool filteredChain = false;
bool filteredChain = false;
bool foundPrimary = false;
BVRef bvr, bvr1 = 0, bvr2 = 0;
BVRef bvr, bvr1 = 0, bvr2 = 0;
if (chain->filtered) filteredChain = true;
return bvr;
/*
* Checking "Default Partition" key in system configuration - use format: hd(x,y) -
* Checking "Default Partition" key in system configuration - use format: hd(x,y) or the volume UUID -
* to override the default selection.
* We accept only kBVFlagSystemVolume or kBVFlagForeignBoot volumes.
*/
const char * val;
char testStr[64];
int cnt;
if (getValueForKey(kDefaultPartition, &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain)
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
*testStr = '\0';
if ( bvr->biosdev >= 0x80 && bvr->biosdev < 0x100
&& ( bvr->flags & ( kBVFlagSystemVolume|kBVFlagForeignBoot ) ) )
{
sprintf(testStr, "hd(%d,%d)", bvr->biosdev - 0x80, bvr->part_no);
if (strcmp(testStr, val) == 0)
return bvr;
}
}
}
const char * val;
char testStr[64];
int cnt;
if (getValueForKey(kDefaultPartition, &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain)
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->biosdev >= 0x80 && bvr->biosdev < 0x100
&& ( bvr->flags & ( kBVFlagSystemVolume|kBVFlagForeignBoot ) ) )
{
// Trying to match hd(x,y) format.
sprintf(testStr, "hd(%d,%d)", bvr->biosdev - 0x80, bvr->part_no);
if (strcmp(testStr, val) == 0)
return bvr;
// Trying to match volume UUID.
if (bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0 && strcmp(testStr, val) == 0)
return bvr;
}
}
}
/*
* Scannig the volume chain backwards and trying to find
* a HFS+ volume with valid boot record signature.
* If not found any active partition then we will
* select this volume as the boot volume.
*/
for ( bvr = chain; bvr; bvr = bvr->next )
{
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)
&& gBIOSBootVolume
&& (!filteredChain || (filteredChain && bvr->visible))
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
}
for ( bvr = chain; bvr; bvr = bvr->next )
{
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)
&& gBIOSBootVolume
&& (!filteredChain || (filteredChain && bvr->visible))
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
}
/*
* Use the standrad method for selecting the boot volume.
*/
if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) bvr1 = bvr;
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) bvr2 = bvr;
}
}
bvr = bvr2 ? bvr2 :
bvr1 ? bvr1 : chain;
return bvr;
}
bvr = bvr2 ? bvr2 :
bvr1 ? bvr1 : chain;
return bvr;
}
//==========================================================================
return bvr ? bvr : bvr1;
}
int getDeviceStringFromBVR(const BVRef bvr, char *str)
{
const struct devsw *dp;
if (bvr)
{
*str = '\0';
for (dp = devsw; dp->name && bvr->biosdev >= dp->biosdev; dp++);
dp--;
if (dp->name) sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no);
return true;
}
return false;
}
branches/blackosx/i386/libsaio/acpi.h
5959
6060
6161
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
6288
6389
6490
......
7399
74100
75101
76
77
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
78135
79136
80137
} __attribute__((packed));
// TODO Migrate
struct acpi_2_ssdt {
char Signature[4];
uint32_t Length;
uint8_t Revision;
uint8_t Checksum;
char OEMID[6];
char OEMTableId[8];
uint32_t OEMRevision;
uint32_t CreatorId;
uint32_t CreatorRevision;
} __attribute__((packed));
// TODO Migrate
struct acpi_2_dsdt {
char Signature[4];
uint32_t Length;
uint8_t Revision;
uint8_t Checksum;
char OEMID[6];
char OEMTableId[8];
uint32_t OEMRevision;
uint32_t CreatorId;
uint32_t CreatorRevision;
} __attribute__((packed));
// TODO Migrate
struct acpi_2_fadt {
char Signature[4];
uint32_t Length;
uint32_t DSDT;
uint8_t Model;// JrCs
uint8_t PM_Profile;// JrCs
/*We absolutely don't care about theese fields*/
uint8_t notimp1[66];
uint16_tSCI_Interrupt;
uint32_tSMI_Command_Port;
uint8_tACPI_Enable;
uint8_tACPI_Disable;
uint8_tS4BIOS_Command;
uint8_tPState_Control;
uint32_tPM1A_Event_Block_Address;
uint32_tPM1B_Event_Block_Address;
uint32_tPM1A_Control_Block_Address;
uint32_tPM1B_Control_Block_Address;
uint32_tPM2_Control_Block_Address;
uint32_tPM_Timer_Block_Address;
uint32_tGPE0_Block_Address;
uint32_tGPE1_Block_Address;
uint8_tPM1_Event_Block_Length;
uint8_tPM1_Control_Block_Length;
uint8_tPM2_Control_Block_Length;
uint8_tPM_Timer_Block_Length;
uint8_tGPE0_Block_Length;
uint8_tGPE1_Block_Length;
uint8_tGPE1_Base_Offset;
uint8_tCST_Support;
uint16_tC2_Latency;
uint16_tC3_Latency;
uint16_tCPU_Cache_Size;
uint16_tCache_Flush_Stride;
uint8_tDuty_Cycle_Offset;
uint8_tDuty_Cycle_Width;
uint8_tRTC_Day_Alarm_Index;
uint8_tRTC_Month_Alarm_Index;
uint8_tRTC_Century_Index;
uint16_tBoot_Flags;
uint8_tReserved0;
/* Begin Asere */
//Reset Fix
uint32_t Flags;
branches/blackosx/i386/libsaio/platform.c
3737
3838
3939
40
40
41
42
43
4144
4245
4346
44
47
4548
4649
50
4751
4852
4953
......
5256
5357
5458
55
5659
5760
5861
59
60
61
62
63
6264
/** scan mem for memory autodection purpose */
void scan_mem() {
bool useAutodetection = false;
static bool done = false;
if (done) return;
bool useAutodetection = true;
getBoolForKey(kUseMemDetect, &useAutodetection, &bootInfo->bootConfig);
if (useAutodetection) {
scan_memory(&Platform);
scan_memory(&Platform); // unfortunately still necesary for some comp where spd cant read correct speed
scan_spd(&Platform);
}
done = true;
}
/**
*/
void scan_platform(void)
{
memset(&Platform, 0, sizeof(Platform));
build_pci_dt();
scan_cpu(&Platform);
// disabled for now as options can't be read yet here:
// scan_mem();
// It's working after some changes in strdup
scan_mem();
}
branches/blackosx/i386/libsaio/cpu.c
1717
1818
1919
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
5720
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
11921
12022
12123
......
249151
250152
251153
154
155
156
252157
253158
254159
......
261166
262167
263168
264
169
170
265171
266172
267173
......
279185
280186
281187
282
188
283189
284190
285191
#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)
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_EM64T;
}
if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MSR;
}
//if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) {
if (p->CPU.NoThreads > p->CPU.NoCores) {
p->CPU.Features |= CPU_FEATURE_HTT;
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)) {
if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e
|| p->CPU.Model == 0x1f || p->CPU.Model == 0x25 || p->CPU.Model == 0x2c)) {
msr = rdmsr64(MSR_PLATFORM_INFO);
DBG("msr(%d): platform_info %08x\n", __LINE__, msr & 0xffffffff);
currcoef = (msr >> 8) & 0xff;
}
cpuFrequency = tscFrequency;
} else {
msr = rdmsr64(IA32_PERF_STATUS);
msr = rdmsr64(MSR_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*/
branches/blackosx/i386/libsaio/platform.h
3333
3434
3535
36
3637
3738
3839
......
7576
7677
7778
78
79
79
80
8081
8182
8283
83
84
85
86
87
84
85
86
87
88
8889
8990
9091
#define CPU_FEATURE_EM64T0x00000040// 64Bit Support
#define CPU_FEATURE_HTT0x00000080// HyperThreading
#define CPU_FEATURE_MOBILE0x00000100// Mobile CPU
#define CPU_FEATURE_MSR0x00000200// MSR Support
/* SMBIOS Memory Types */
#define SMB_MEM_TYPE_UNDEFINED0
#define UUID_LEN16
typedef struct _RamSlotInfo_t {
uint32_t ModuleSize;// Size of Module in MB
uint32_t Frequency; // in Mhz
uint32_tModuleSize;// Size of Module in MB
uint32_tFrequency; // in Mhz
const char*Vendor;
const char*PartNo;
const char*SerialNo;
char*spd;// SPD Dump
boolInUse;
uint8_tType;
uint8_t BankConnections; // table type 6, see (3.3.7)
uint8_t BankConnCnt;
char*spd;// SPD Dump
boolInUse;
uint8_tType;
uint8_tBankConnections; // table type 6, see (3.3.7)
uint8_tBankConnCnt;
} RamSlotInfo_t;
branches/blackosx/i386/libsaio/pci_setup.c
66
77
88
9
10
9
1110
1211
1312
1413
1514
16
15
1716
1817
19
18
2019
2120
2221
23
24
25
26
27
28
2922
3023
3124
......
6255
6356
6457
65
66
67
68
69
70
71
72
73
74
75
76
77
78
58
7959
8060
8161
#include "ati.h"
extern void set_eth_builtin(pci_dt_t *eth_dev);
extern int ehci_acquire(pci_dt_t *pci_dev);
extern int uhci_reset(pci_dt_t *pci_dev);
extern void notify_usb_dev(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, 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;
do_eth_devprop = do_gfx_devprop = do_enable_hpet = false;
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(kEHCIacquire, &fix_ehci, &bootInfo->bootConfig);
getBoolForKey(kUHCIreset, &fix_uhci, &bootInfo->bootConfig);
}
getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->bootConfig);
while (current)
break;
case PCI_CLASS_SERIAL_USB:
switch (pci_config_read8(current->dev.addr, PCI_CLASS_PROG))
{
/* EHCI */
case 0x20:
if (fix_ehci)
ehci_acquire(current);
break;
/* UHCI */
case 0x00:
if (fix_uhci)
uhci_reset(current);
break;
}
notify_usb_dev(current);
break;
case PCI_CLASS_BRIDGE_ISA:
branches/blackosx/i386/libsaio/cpu.h
1414
1515
1616
17
18
19
20
21
17
18
19
20
21
22
23
2224
2325
2426
......
2931
3032
3133
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
32141
#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
#defineMSR_IA32_PERF_STATUS0x198
#define MSR_IA32_PERF_CONTROL0x199
#define MSR_IA32_EXT_CONFIG0x00EE
#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 */
#define CALIBRATE_TIME_MSEC30/* 30 msecs */
#define CALIBRATE_LATCH((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000)
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 wrmsr64(uint32_t msr, uint64_t val)
{
__asm__ volatile("wrmsr" : : "c" (msr), "A" (val));
}
static inline void intel_waitforsts(void) {
uint32_t inline_timeout = 100000;
while (rdmsr64(MSR_IA32_PERF_STATUS) & (1 << 21)) { if (!inline_timeout--) break; }
}
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;
}
#endif /* !__LIBSAIO_CPU_H */
branches/blackosx/i386/libsaio/msdos.c
720720
721721
722722
723
724
723725
724726
725727
......
754756
755757
756758
757
758
759
760
761
762
759763
760764
761765
char *ptr = (char *)base;
struct direntry *dirp;
int i;
char devStr[12];
if (MSDOSInitPartition (ih)<0)
return -1;
if (filePath[0] == '/')
ptr+=msdosclustersize;
toread-=msdosclustersize;
}
verbose("Loaded FAT%d file: [%s] %d bytes from %x.\n",
msdosfatbits, filePath, (uint32_t)( toread<0 ) ? wastoread : wastoread-toread, ih);
getDeviceStringFromBVR(ih, devStr);
verbose("Read FAT%d file: [%s/%s] %d bytes.\n",
msdosfatbits, devStr, filePath, (uint32_t)( toread<0 ) ? wastoread : wastoread-toread);
free (buf);
if (toread<0)
return wastoread;
branches/blackosx/i386/libsaio/fake_efi.c
1111
1212
1313
14
14
1515
1616
1717
......
514514
515515
516516
517
518
517
518
519519
520
520
521521
522522
523523
524524
525525
526
527
528
529
530
526
527
528
529
530
531531
532532
#include "fake_efi.h"
#include "efi_tables.h"
#include "platform.h"
#include "dsdt_patcher.h"
#include "acpi_patcher.h"
#include "smbios_patcher.h"
#include "device_inject.h"
#include "convert.h"
/* Entrypoint from boot.c */
void setupFakeEfi(void)
{
// load smbios.plist file if any
setupSmbiosConfigFile();
// load smbios.plist file if any
setupSmbiosConfigFile();
// Generate efi device strings
// Generate efi device strings
setupEfiDevices();
// Initialize the base table
setupEfiTables();
// Initialize the device tree
setupEfiDeviceTree();
// Add configuration table entries to both the services table and the device tree
setupEfiConfigurationTable();
// Initialize the device tree
setupEfiDeviceTree();
// Add configuration table entries to both the services table and the device tree
setupEfiConfigurationTable();
}
branches/blackosx/i386/libsaio/saio_internal.h
183183
184184
185185
186
187
188
186189
187190
188191
......
199202
200203
201204
205
202206
203207
204208
extern int close(int fdesc);
extern int file_size(int fdesc);
extern int read(int fdesc, char *buf, int count);
extern int write(int fdesc, const char *buf, int count);
extern int writebyte(int fdesc, char value);
extern int writeint(int fdesc, int value);
extern int b_lseek(int fdesc, int addr, int ptr);
extern int tell(int fdesc);
extern const char * systemConfigDir(void);
extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose);
extern void setRootVolume(BVRef volume);
extern void setBootGlobals(BVRef chain);
extern int getDeviceStringFromBVR(const BVRef volume, char *str);
extern int gBIOSDev;
extern int gBootFileType;
branches/blackosx/i386/boot1/boot1f32.s
7575
7676
7777
78
78
7979
8080
8181
kBoot1LoadAddrEQU0x7C00; boot1 load address
kBoot1RelocAddrEQU0xE000; boot1 relocated address
kBoot2SectorsEQU(384 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SectorsEQU(448 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SegmentEQU0x2000; boot2 load segment
kBoot2AddressEQUkSectorBytes; boot2 load address
branches/blackosx/i386/boot1/boot1he.s
7979
8080
8181
82
82
8383
8484
8585
kBoot1ExtAddrEQUkBoot1RelocAddr + kSectorBytes; boot1 load address for sector 41-47
kHFSPlusBufferEQUkBoot1RelocAddr + kBoot1ExtSize; HFS+ Volume Header address
kBoot2SectorsEQU(384 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SectorsEQU(448 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SegmentEQU0x2000; boot2 load segment
kBoot2AddressEQUkSectorBytes; boot2 load address
branches/blackosx/i386/boot1/boot1.s
7474
7575
7676
77
77
7878
7979
8080
kBoot1Sector1AddrEQUkBoot1RelocAddr + kSectorBytes; boot1 load address for sector 1
kHFSPlusBufferEQUkBoot1Sector1Addr + kSectorBytes; HFS+ Volume Header address
kBoot2SectorsEQU(384 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SectorsEQU(448 * 1024 - 512) / kSectorBytes; max size of 'boot' file in sectors
kBoot2SegmentEQU0x2000; boot2 load segment
kBoot2AddressEQUkSectorBytes; boot2 load address
branches/blackosx/i386/boot2/boot.c
175175
176176
177177
178
179
180
181
178
179
180
181
182182
183
184
183185
184186
185187
}
bool dummyVal;
if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {
printf("Press any key to continue...");
getc();
}
if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {
printf("Press any key to continue...");
getc();
}
usb_loop();
// If we were in text mode, switch to graphics mode.
// This will draw the boot graphics unless we are in
// verbose mode.
branches/blackosx/i386/boot2/boot.h
4242
4343
4444
45
45
4646
4747
4848
4949
50
50
5151
5252
5353
54
54
5555
5656
5757
58
58
5959
6060
6161
62
63
64
65
62
63
64
65
6666
67
68
69
70
71
72
73
67
68
69
70
71
72
73
74
75
76
77
78
79
7480
75
76
81
82
7783
7884
79
80
81
82
85
86
8387
84
88
89
90
91
92
8593
86
87
88
89
90
9194
9295
9396
......
136139
137140
138141
142
143
144
145
146
139147
140148
141149
......
163171
164172
165173
174
166175
167176
168177
#define kKernelNameKey"Kernel"
#define kKernelCacheKey"Kernel Cache"
#define kBootDeviceKey"Boot Device"
#define kTimeoutKey"Timeout"
#define kTimeoutKey"Timeout"
#define kRootDeviceKey"rd"
#define kBootUUIDKey"boot-uuid"
#define kHelperRootUUIDKey"Root UUID"
#define kPlatformKey"platform"
#define kACPIKey"acpi"
#define kACPIKey"acpi"
#define kCDROMPromptKey"CD-ROM Prompt"
#define kCDROMOptionKey"CD-ROM Option Key"
#define kRescanPromptKey"Rescan Prompt"
#define kRescanKey"Rescan"
#define kRescanKey "Rescan"
#define kScanSingleDriveKey"Scan Single Drive"
#define kInsantMenuKey"Instant Menu"
#define kDefaultKernel"mach_kernel"
#define kGUIKey"GUI"
#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 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"SystemId"/* fake_efi.c */
#define kSystemType"SystemType"/* fake_efi.c */
#define karch"arch"/* boot.c */
#define kDSDT"DSDT"/* acpi_patcher.c */
#define kDropSSDT"DropSSDT"/* acpi_patcher.c */
#define kRestartFix"RestartFix"/* acpi_patcher.c */
#define kRestartFix"RestartFix" /* acpi_patcher.c */
#define kGeneratePStates"GeneratePStates"/* acpi_patcher.c */
#define kGenerateCStates"GenerateCStates"/* acpi_patcher.c */
#define kDeviceProperties"device-properties"/* device_inject.c */
#define kHidePartition"Hide Partition"/* disk.c */
#define kRenamePartition"Rename Partition"/* disk.c */
#define kSMBIOS"SMBIOS"/* fake_efi.c */
#define kSystemID"SystemId"/* fake_efi.c */
#define kSystemType"SystemType"/* fake_efi.c */
#define kUseNvidiaROM"UseNvidiaROM"/* nvidia.c */
#define kVBIOS"VBIOS"/* nvidia.c */
#define kPCIRootUID"PCIRootUID"/* pci_root.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 kForceHPET"ForceHPET"/* pci_setup.c */
#define kUseMemDetect"UseMemDetect" /* platform.c */
#define kSMBIOSdefaults"SMBIOSdefaults"/* smbios_patcher.c */
#define kEHCIhard"EHCIhard"/* usb.c */
#define kUSBBusFix"USBBusFix"/* usb.c */
#define kEHCIacquire"EHCIacquire"/* usb.c */
#define kUHCIreset"UHCIreset"/* usb.c */
#define kLegacyOff"USBLegacyOff"/* usb.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 */
#define kUseMemDetect "UseMemDetect" /* platform.c */
#define kRestartFix "RestartFix" /* dsdt_patcher.c */
/*
* Flags to the booter or kernel
extern void common_boot(int biosdev);
/*
* usb.c
*/
extern int usb_loop();
/*
* graphics.c
*/
extern void printVBEModeInfo();
extern void drawPreview(void *src, uint8_t * saveunder);
extern int getVideoMode(void);
extern void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or);
/*
* drivers.c
*/
branches/blackosx/i386/boot2/drivers.c
198198
199199
200200
201
202
203
204
205
206
207
208
209
201
202
203
204
205
206
207
208
209
210210
211211
212212
213
214
213
215214
216
215
217216
218217
219
220
218
219
220
221
222
223
221224
222225
223226
......
252255
253256
254257
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
255283
256284
257285
......
264292
265293
266294
267
295
296
297
268298
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
299
300
301
285302
286
287
288
289
290
291
292
293
294
295
296
297
298
299303
300304
301305
......
330334
331335
332336
333
337
334338
335339
336340
if ( !(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no)
|| (gRAMDiskVolume && gRAMDiskBTAliased) )
{
// First try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next we'll try the base
strcpy(dirSpecExtra, "bt(0,0)/Extra/");
FileLoadDrivers(dirSpecExtra, 0);
}
}
// Next try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next we'll try the base
strcpy(dirSpecExtra, "bt(0,0)/Extra/");
FileLoadDrivers(dirSpecExtra, 0);
}
}
}
// Also try to load Extensions from boot helper partitions.
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
if (gBootVolume->flags & kBVFlagBooter)
{
strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
FileLoadDrivers(dirSpecExtra, 0);
strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
FileLoadDrivers(dirSpecExtra, 0);
}
}
}
}
//==========================================================================
// FileLoadMKext
static long
FileLoadMKext( const char * dirSpec, const char * extDirSpec )
{
long ret, flags, time, time2;
char altDirSpec[512];
sprintf (altDirSpec, "%s%s", dirSpec, extDirSpec);
ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
{
ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
(((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
{
sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec);
verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0) return 0;
}
}
return -1;
}
//==========================================================================
// FileLoadDrivers
static long
if ( !plugin )
{
long time2;
// First try 10.6's path for loading Extensions.mkext.
if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)
return 0;
// TODO: refactor this part of code.
char altDirSpec[4500];
sprintf (altDirSpec,"%sCaches/com.apple.kext.caches/Startup/",dirSpec);
ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
{
ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
(((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
{
sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec);
verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0) return 0;
}
}
//
// Next try the legacy path.
else if (FileLoadMKext(dirSpec, "") == 0)
return 0;
ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
{
ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
(((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
{
sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec);
verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0) return 0;
}
}
strcat(dirSpec, "Extensions");
}
result = ret;
if (!plugin)
result = FileLoadDrivers(gDriverSpec, 1);
FileLoadDrivers(gDriverSpec, 1);
}
return result;
branches/blackosx/i386/boot2/gui.c
1313
1414
1515
16
16
17
1718
18
19
2019
2120
2221
23
22
2423
2524
2625
......
4241
4342
4443
45
4644
4745
4846
......
8785
8886
8987
90
9188
9289
9390
......
165162
166163
167164
168
165
169166
170167
171168
......
183180
184181
185182
186
187
183
184
185
186
187
188
188189
189
190
191
192
193
190
191
194192
195193
196194
......
205203
206204
207205
206
207
208
208209
209210
210211
......
233234
234235
235236
236
237
238237
239238
240239
......
245244
246245
247246
248
249247
250248
251249
......
615613
616614
617615
618
616
619617
620618
621
619
622620
623621
624
625622
626
627
628
629
630
631
632
633
634
635
636
637623
638624
639625
......
645631
646632
647633
634
648635
649636
650637
......
673660
674661
675662
676
663
677664
678665
679666
......
783770
784771
785772
786
787
788
789
773
774
775
790776
791777
792778
......
805791
806792
807793
808
809
810
811
812
794
795
796
797
813798
814799
815800
......
17301715
17311716
17321717
1733
1718
1719
17341720
17351721
1736
17371722
1738
1723
1724
1725
1726
1727
17391728
17401729
17411730
......
17551744
17561745
17571746
1758
1759
1760
1761
1747
17621748
1749
1750
17631751
1764
1752
17651753
1766
1767
1768
1769
1770
1754
17711755
17721756
1773
1774
17751757
17761758
17771759
#include "vers.h"
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
static const char *theme_name = ""; //THEME_NAME_DEFAULT;
static bool rolloverfail = false;
static bool rolloverfail = false; // blackosx added to this as a flag to be raised if one or more rollover images are missing in the theme folder.
#ifdef EMBED_THEME
#include "art.h"
#define LOADPNG(img) \
if (loadThemeImage(#img) != 0) \
if (loadThemeImage(#img) == 2) \
if (loadEmbeddedThemeImage(#img, __## img ##_png, __## img ##_png_len) != 0) \
return 1;
#else
/*
* ATTENTION: the enum and the following array images[] MUST match !!!
*/
//blackosx - added extra variables to match rollover device images (with _o).
enum {
iBackground = 0,
iLogo,
iFontSmall,
};
//blackosx - added extra rollover device image (with _o) to images array after each normal device image.
image_t images[] = {
{.name = "background",.image = NULL},
{.name = "logo",.image = NULL},
static bool infoMenuNativeBoot = false;
static unsigned long screen_params[4] = {0, 0, 0, 0};// here we store the used screen resolution
static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};// here we store the used screen resolution
#ifdef EMBED_THEME
static int loadEmbeddedThemeImage(const char *image, unsigned char *image_data, unsigned int image_size)
width = 0;
height = 0;
imagedata = NULL;
if ((loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) != 0) {
return 1;
if ((loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) == 0) {
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
else
return 1;
}
}
return 1;
uint8_t*imagedata;
char*cptr; // blackosx added
if (strlen(theme_name)==0) // blackosx - No theme asked for in com.apple.Boot.plist
return 2;
if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) {
return 1;
}
return 1; // This means we have to drop out of using the GUI.
}
else { // We have a match for '_o' in image name, which means a rollover graphic is missing.
//printf("ERROR: GUI: ROLLOVER: could not open '%s/%s.png'!\n", theme_name, image);
//sleep(2);
rolloverfail=true;
return 0;
}
}
// blackosx added extra rollover devices.
static int loadGraphics(void)
{
LOADPNG(background);
#endif
}
// parse display size parameters
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) {
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {
screen_params[0] = val;
}
if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) {
if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {
screen_params[1] = val;
}
screen_params[2] = 32;
// blackosx - This solved an issue when the theme.plist had blank values for screen_height and screen_width.
// Thanks to Al Schar for pointing out Conti's fix and thanks to Conti for the fix.
/* Fix for "Memory allocation error! Addr=0xdeadbeef, Size=0x0" - if no VESA resolution defined in com.apple.Boot.plist */
if(!screen_params[0]) {
screen_params[0] = DEFAULT_SCREEN_WIDTH;
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
/* End Fix ~ Conti */
// Initalizing GUI strucutre.
bzero(&gui, sizeof(gui_t));
gui.screen.height = screen_params[1];
// load graphics otherwise fail and return
if (loadGraphics() == 0) {
loadThemeValues(&bootInfo->themeConfig, true);
colorFont(&font_small, gui.screen.font_small_color);
return 1;
}
void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool rollover) //blackosx - accept extra BOOLEAN variable 'rollover' to check for rollover image
void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool rollover) // blackosx - accept extra BOOLEAN variable
{
int devicetype;
if(gui.menu.draw)
drawInfoMenuItems();
blend( images[iSelection].image, gui.devicelist.pixmap, centeredAt( images[iSelection].image, p ) );
if (rolloverfail == false) // blackosx - if ALL the rollover graphics are in the theme folder
drawDeviceIcon( param, gui.devicelist.pixmap, p, true ); //blackosx - then draw the rollover image.
blend( images[iSelection].image, gui.devicelist.pixmap, centeredAt( images[iSelection].image, p ) );
if (rolloverfail == false)
drawDeviceIcon( param, gui.devicelist.pixmap, p, true );
#if DEBUG
gui.debug.cursor = pos( 10, 100);
dprintf( &gui.screen, "label %s\n", param->label );
#endif
}
else if (rolloverfail ==false)
drawDeviceIcon( param, gui.devicelist.pixmap, p, false ); //blackosx - draw non-highlighted normal device icon
if (rolloverfail == true) // blackosx - draw the device icon on top of the device_selection only if we're not using rollover image.
drawDeviceIcon( param, gui.devicelist.pixmap, p, false ); //blackosx - added false to draw normal icon if it's not selected.
drawDeviceIcon( param, gui.devicelist.pixmap, p, false );
if (rolloverfail == true)
drawDeviceIcon( param, gui.devicelist.pixmap, p, false );
if (gui.layout == HorizontalLayout)
{
p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
return;
}
sprintf(dirspec, "/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 = false;
}
#else
if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0)
usePngImage = false;
#endif
}
//==========================================================================
}
// parse screen size parameters
// blackosx - Thanks to Al Schar for pointing out Conti's fix and thanks to Conti for the fix.
/* Fix for "Memory allocation error! Addr=0xdeadbeef, Size=0x0" - if no VESA resolution defined in com.apple.Boot.plist */
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) {
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
screen_params[0] = pos;
} else {
screen_params[0] = DEFAULT_SCREEN_WIDTH;
}
if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) {
if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
screen_params[1] = pos;
}
screen_params[2] = 32;
if(!screen_params[0]) {
screen_params[0] = DEFAULT_SCREEN_WIDTH;
} else {
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
/* End Fix ~ Conti */
gui.screen.width = screen_params[0];
gui.screen.height = screen_params[1];
branches/blackosx/i386/boot2/gui.h
144144
145145
146146
147
147
148148
149149
150150
int dprintf( window_t * window, const char * fmt, ...);
int gprintf( window_t * window, const char * fmt, ...);
int vprf(const char * fmt, va_list ap);
int vprf(const char * fmt, va_list ap);
int drawInfoMenu();
int updateInfoMenu(int key);
branches/blackosx/i386/boot2/options.c
108108
109109
110110
111
111
112112
113113
114114
115
115
116116
117117
118118
} else {
position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );
position_t p = pos( gui.screen.width / 2 , ( gui.devicelist.pos.y ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) ); // blackosx changed (though not sure as different resolutions show different results)
char dummy[80];
getBootVolumeDescription( gBootVolume, dummy, 80, true );
drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, false ); // blackosx added extra variable to pass. Usage: false = normal image
drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, false );
drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );
// make this screen the new background
branches/blackosx/i386/boot2/Makefile
5454
5555
5656
57
57
5858
5959
6060
$(HFILES) $(OTHERFILES)
DIRS_NEEDED = $(OBJROOT) $(SYMROOT)
BOOT2ADDR = 20200
MAXBOOTSIZE = 392704
MAXBOOTSIZE = 458240
all: $(DIRS_NEEDED) boot
branches/blackosx/i386/cdboot/cdboot.s
114114
115115
116116
117
117
118118
119119
120120
; at build time.
kSectorBytes EQU 2048; sector size in bytes
kBoot2Size EQU 65024; default load size for boot2
kBoot2MaxSize EQU 392704; max size for boot2
kBoot2MaxSize EQU 458240; max size for boot2
kBoot2Address EQU 0x0200 ; boot2 load address
kBoot2Segment EQU 0x2000 ; boot2 load segment
branches/blackosx/i386/libsa/libsa.h
7070
7171
7272
73
74
75
76
77
7378
7479
7580
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
}
//Azi: TODO - add more ponctuation characters as needed; at least these two, i need for PartNo.
static inline int ispunct(char c)
{
return (c == '.' || c == '-');
}
/*
* string.c
branches/blackosx/i386/libsa/memory.h
4848
4949
5050
51
51
5252
5353
5454
......
5757
5858
5959
60
60
6161
6262
6363
......
7878
7979
8080
81
81
8282
8383
84
84
8585
8686
87
88
87
88
8989
90
90
9191
9292
93
94
93
94
9595
9696
97
98
97
98
9999
100100
101101
# define BASE_SEG BOOT2_SEG
#endif
#define STACK_SEG 0x8000// zef: old STACK_SEG 0x5000
#define STACK_SEG 0x1000// zef: old STACK_SEG 0x5000
#define STACK_OFS 0xFFF0 // stack pointer
#define BOOT1U_SEG 0x1000
#define BOOT2_SEG 0x2000
#define BOOT2_OFS 0x0200 // 512 byte disk sector offset
#define BIOS_ADDR 0x8000 // BIOS disk I/O buffer
#define BIOS_ADDR 0x9000 // BIOS disk I/O buffer
#define BIOS_LEN 0x8000 // 32K - divisible by 512 and 2048
#define BOOT0_ADDR 0x7E00 // boot0 gets loaded here
#define BOOT2_ADDR ADDR32(BOOT2_SEG, BOOT2_OFS)
// TODO: BOOT_ADDR ?
#define HIB_ADDR 0x00040000 // special hibernation area
#define HIB_ADDR 0x00040000 // special hibernation area
#define HIB_LEN 0x00060000
#define VIDEO_ADDR 0x000A0000 // unusable space
#define VIDEO_ADDR 0x000A0000 // unusable space
#define VIDEO_LEN 0x00060000
#define KERNEL_ADDR 0x00100000 // 64M kernel + drivers
#define KERNEL_LEN 0x04000000
#define KERNEL_ADDR 0x00100000 // 128M kernel + drivers
#define KERNEL_LEN 0x08000000
#define ZALLOC_ADDR 0x04100000 // 256M zalloc area
#define ZALLOC_ADDR 0x08100000 // 256M zalloc area
#define ZALLOC_LEN 0x10000000
#define LOAD_ADDR 0x14100000 // 95M File load buffer
#define LOAD_LEN 0x05F80000
#define LOAD_ADDR 0x18100000 // 64M File load buffer
#define LOAD_LEN 0x04000000
// Location of data fed to boot2 by the prebooter
#define PREBOOT_DATA 0x1A080000 // Still have enough room for a 95M ramdisk image
// in case of 512MB system memory.
#define PREBOOT_DATA 0x1C100000 // Still have enough room for a 63M ramdisk image
// in case of 512MB system memory.
#define TFTP_ADDR LOAD_ADDR // tftp download buffer
#define TFTP_LEN LOAD_LEN
branches/blackosx/CREDITS
33
44
55
6
7
8
9
10
11
12
13
14
15
16
17
18
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1922
2023
2124
22
23
24
25
26
27
28
29
30
31
32
33
34
35
25
26
27
28
29
30
31
32
33
34
35
36
37
Developers:
----------
Crazor
Dense
fassl
iNDi
JrCs
Kabyl
kaitek
mackerintel
mercurysquad
munky
rekursor
Turbo
zef
Crazor
Dense
fassl
iNDi
JrCs
Kabyl
kaitek
mackerintel
mercurysquad
munky
meklort
mozodojo
rekursor
Turbo
valv
zef
Thanks to:
---------
asereBLN
bumby
cosmo1t
dfe
Galaxy
kalyway
Krazubu
MasterChief
netkas
sckevyn
smith@@
THeKiNG
XyZ
asereBLN
Azimutz
bumby
cosmo1t
dfe
Galaxy
kalyway
Krazubu
MasterChief
netkas
sckevyn
smith@@
THeKiNG

Archive Download the corresponding diff file

Revision: 215