Chameleon

Chameleon Commit Details

Date:2010-09-24 07:02:30 (13 years 7 months ago)
Author:Evan Lojewski
Commit:548
Parents: 547
Message:Bugfixes (hpet, gui, etc)
Changes:
M/branches/meklort/i386/modules/KernelPatcher/kernel_patcher.c
M/branches/meklort/i386/boot2/boot.c
M/branches/meklort/i386/modules/HPET/HPET.c
M/branches/meklort/i386/boot2/boot.h
M/branches/meklort/i386/boot2/modules.c
M/branches/meklort/i386/libsaio/device_inject.c
M/branches/meklort/i386/libsaio/pci.c

File differences

branches/meklort/i386/libsaio/device_inject.c
3131
3232
3333
34
34
35
3536
3637
3738
......
4142
4243
4344
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
6364
64
65
66
67
68
65
66
67
68
69
6970
7071
7172
......
7374
7475
7576
77
7678
79
7780
7881
7982
8083
8184
8285
83
86
8487
8588
8689
8790
8891
89
92
9093
9194
9295
9396
94
97
9598
9699
97100
98101
99
102
100103
101104
102
105
103106
104107
105108
106
107
108
109
110
111
112
113
109114
110115
111116
112117
118
113119
120
114121
122
115123
124
116125
117126
118127
......
125134
126135
127136
137
128138
139
129140
141
130142
143
131144
132145
133146
......
141154
142155
143156
157
144158
159
145160
146161
147162
......
171186
172187
173188
189
174190
191
175192
193
194
176195
177196
178197
......
184203
185204
186205
206
187207
208
188209
189210
190211
191212
192213
214
193215
216
194217
195218
196219
......
219242
220243
221244
245
222246
247
223248
249
224250
251
225252
226
253
254
255
227256
228257
229258
......
231260
232261
233262
263
234264
265
235266
267
236268
269
237270
238271
239272
......
247280
248281
249282
283
250284
251
285
286
252287
253288
254289
......
265300
266301
267302
268
303
269304
270305
271306
......
296331
297332
298333
334
299335
336
300337
301338
302339
char *efi_inject_get_devprop_string(uint32_t *len)
{
if(string) {
if(string)
{
*len = string->length;
return devprop_generate_string(string);
}
void setupDeviceProperties(Node *node)
{
const char *val;
uint8_t *binStr;
int cnt, cnt2;
static char DEVICE_PROPERTIES_PROP[] = "device-properties";
/* Generate devprop string.
*/
uint32_t strlength;
char *string = efi_inject_get_devprop_string(&strlength);
/* Use the static "device-properties" boot config key contents if available,
* otheriwse use the generated one.
*/
if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string)
{
val = (const char*)string;
cnt = strlength * 2;
}
const char *val;
uint8_t *binStr;
int cnt, cnt2;
static char DEVICE_PROPERTIES_PROP[] = "device-properties";
/* Generate devprop string.
*/
uint32_t strlength;
char *string = efi_inject_get_devprop_string(&strlength);
/* Use the static "device-properties" boot config key contents if available,
* otheriwse use the generated one.
*/
if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string)
{
val = (const char*)string;
cnt = strlength * 2;
}
if (cnt > 1)
{
binStr = convertHexStr2Binary(val, &cnt2);
if (cnt2 > 0) DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, binStr);
}
if (cnt > 1)
{
binStr = convertHexStr2Binary(val, &cnt2);
if (cnt2 > 0) DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, binStr);
}
}
struct DevPropString *devprop_create_string(void)
string = (struct DevPropString*)malloc(sizeof(struct DevPropString));
if(string == NULL)
{
return NULL;
}
memset(string, 0, sizeof(struct DevPropString));
string->length = 12;
string->WHAT2 = 0x01000000;
return string;
}
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
{
struct DevPropDevice*device;
const charpciroot_string[] = "PciRoot(0x";
const charpci_device_string[] = "Pci(0x";
if (string == NULL || path == NULL) {
return NULL;
}
device = malloc(sizeof(struct DevPropDevice));
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 = 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] != ',');
if(x-curr == 2)
{
sprintf(buff, "%c%c", path[curr], path[curr+1]);
}
else if(x-curr == 1)
{
sprintf(buff, "%c", path[curr]);
}
else
{
printf("ERROR parsing device path\n");
curr = x;
while(path[++x] != ')');
if(x-curr == 2)
{
sprintf(buff, "%c%c", path[curr], path[curr+1]);
}
else if(x-curr == 1)
{
sprintf(buff, "%c", path[curr]);
}
else
{
printf("ERROR parsing device path\n");
}
if(!numpaths)
{
return NULL;
}
device->numentries = 0x00;
string->length += device->length;
if(!string->entries)
{
if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)))== NULL)
{
return 0;
}
}
string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));
string->entries[string->numentries-1] = device;
{
if(!nm || !vl || !len)
{
return 0;
}
uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);
uint8_t *data = (uint8_t*)malloc(length);
{
if(!data)
{
return 0;
}
memset(data, 0, length);
uint32_t off= 0;
uint8_t *newdata = (uint8_t*)malloc((length + offset));
if(!newdata)
{
return 0;
}
if(device->data)
{
if(offset > 1)
{
memcpy(newdata, device->data, offset);
}
}
memcpy(newdata + offset, data, length);
device->length += length;
device->numentries++;
if(!device->data)
{
device->data = (uint8_t*)malloc(sizeof(uint8_t));
}
else
{
free(device->data);
}
free(data);
device->data = newdata;
char *ptr = buffer;
if(!buffer)
{
return NULL;
}
sprintf(buffer, "%08x%08x%04x%04x", dp_swap32(string->length), string->WHAT2,
dp_swap16(string->numentries), string->WHAT3);
buffer += 24;
dp_swap16(string->entries[i]->acpi_dev_path.length),
string->entries[i]->acpi_dev_path._HID,
dp_swap32(string->entries[i]->acpi_dev_path._UID));
buffer += 24;
for(x=0;x < string->entries[i]->num_pci_devpaths; x++)
{
void devprop_free_string(struct DevPropString *string)
{
if(!string)
{
return;
}
int i;
for(i = 0; i < string->numentries; i++)
branches/meklort/i386/libsaio/pci.c
179179
180180
181181
182
182
183183
184184
185185
return dev_path;
}
#if DEBUG_PCI
#ifndef OPTION_ROM
void dump_pci_dt(pci_dt_t *pci_dt)
{
pci_dt_t*current;
branches/meklort/i386/boot2/boot.c
5757
5858
5959
60
61
6062
6163
6264
......
185187
186188
187189
188
189
190
191
192
190
193191
194
195
196
197
198
192
199193
194
195
200196
197
201198
202199
203200
#include "libsa.h"
#include "ramdisk.h"
#include "platform.h"
#include "graphics.h"
#include "modules.h"
long gBootMode; /* defaults to 0 == kBootModeNormal */
getc();
}
// If we were in text mode, switch to graphics mode.
// This will draw the boot graphics unless we are in
// verbose mode.
if(gVerboseMode)
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
setVideoMode( GRAPHICS_MODE, 0 );
}
setVideoMode( GRAPHICS_MODE, 0 );
}
// Draw gray screen. NOTE: no boot image, that's in the gui module
if(!gVerboseMode) drawColorRectangle(0, 0, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 0x01);
setupBooterLog();
finalizeBootStruct();
branches/meklort/i386/boot2/boot.h
6767
6868
6969
70
7170
7271
7372
#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 */
branches/meklort/i386/boot2/modules.c
4545
4646
4747
48
48
4949
5050
5151
......
8585
8686
8787
88
88
8989
90
9091
9192
9293
......
105106
106107
107108
109
110
111
108112
109113
110114
......
127131
128132
129133
130
134
131135
132
133136
134137
135138
......
144147
145148
146149
150
147151
148152
149153
150154
151155
152156
153
157
154158
155159
156160
......
349353
350354
351355
352
356
353357
354358
355359
......
10371041
10381042
10391043
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1044
10511045
10521046
10531047
......
11231117
11241118
11251119
1120
11261121
11271122
1128
1129
1123
1124
11301125
1126
11311127
11321128
11331129
......
12251221
12261222
12271223
1228
1224
12291225
12301226
12311227
/*
* Initialize the module system by loading the Symbols.dylib module.
* Once laoded, locate the _lookup_symbol function so that internal
* Once loaded, locate the _lookup_symbol function so that internal
* symbols can be resolved.
*/
int init_module_system()
{
if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0)
{
char* tmp = malloc(strlen(name) + 1); // TODO: look into this
char* tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
DBG("Attempting to load %s\n", tmp);
load_module(tmp);
}
*/
int load_module(char* module)
{
void (*module_start)(void) = NULL;
// Check to see if the module has already been loaded
if(is_module_loaded(module))
{
unsigned int moduleSize = file_size(fh);
char* module_base = (char*) malloc(moduleSize);
if (read(fh, module_base, moduleSize) == moduleSize)
if (moduleSize && read(fh, module_base, moduleSize) == moduleSize)
{
void (*module_start)(void) = NULL;
//printf("Module %s read in.\n", modString);
DBG("Module %s Loaded.\n", module);
}
else {
// The module does not have a valid start function
printf("Unable to start %s\n", module);
getc();
}
}
else
{
printf("Unable to read in module %s\n.", module);
DBG("Unable to read in module %s\n.", module);
getc();
}
close(fh);
return NULL; // Module is in the incorrect format
}*/
while(cmd < ((struct mach_header*)binary)->ncmds)// TODO: for loop instead
while(cmd < ((struct mach_header*)binary)->ncmds)
{
cmd++;
void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/)
{
moduleList_t* entry;
/*
DBG("\%s.dylib Version %d.%d.%d loaded\n"
"\tCompatibility Version: %d.%d.%d\n",
name,
(version >> 16) & 0xFFFF,
(version >> 8) & 0x00FF,
(version >> 0) & 0x00FF,
(compat >> 16) & 0xFFFF,
(compat >> 8) & 0x00FF,
(compat >> 0) & 0x00FF);
*/
if(loadedModules == NULL)
{
loadedModules = entry = malloc(sizeof(moduleList_t));
}
}
#if DEBUG_MODULES
if(strcmp(name, SYMBOL_DYLD_STUB_BINDER) != 0)
{
printf("Unable to locate symbol %s\n", name);
getc();
verbose("Unable to locate symbol %s\n", name);
//getc();
}
#endif
return 0xFFFFFFFF;
}
}
/* Nedded to devide 64bit numbers correctly. TODO: look into why modules need this
/* Nedded to divide 64bit numbers correctly. TODO: look into why modules need this
* And why it isn't needed when compiled into boot2
*/
branches/meklort/i386/modules/HPET/HPET.c
6363
6464
6565
66
66
67
68
6769
6870
6971
......
116118
117119
118120
119
120121
121122
122123
......
125126
126127
127128
128
129
129130
130131
131132
......
166167
167168
168169
169
170
170171
171172
172173
{ 0x8086, 0x27b8, "ICH7" },
{ 0x8086, 0x27b9, "ICH7M" },
{ 0x8086, 0x27bd, "ICH7M DH" },
{ 0x8086, 0x27bc, "NM10" },
{ 0x8086, 0x2810, "ICH8R" },
{ 0x8086, 0x2811, "ICH8M-E" },
{ 0x8086, 0x2812, "ICH8DH" },
uint32_tval, hpet_address = 0xFED00000;
int i;
/* LPC on Intel ICH is always (?) at 00:1f.0 */
for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++)
{
if ((lpc_controllers_via[i].vendor == lpc_dev->vendor_id)
val = pci_config_read32(lpc_dev->dev.addr, 0x68);
DBG("VIA %s LPC Interface [%04x:%04x], MMIO\n",
lpc_controllers[i].name, lpc_dev->vendor_id, lpc_dev->device_id);
lpc_controllers_via[i].name, lpc_dev->vendor_id, lpc_dev->device_id);
if (val & 0x80) {
hpet_address = (val & ~0x3ff);
rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000);
DBG("Intel(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n",
lpc_controllers[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba);
lpc_controllers_intel[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba);
if (rcba == 0)
printf(" RCBA disabled; cannot force enable HPET\n");
branches/meklort/i386/modules/KernelPatcher/kernel_patcher.c
220220
221221
222222
223
224
225223
226224
227
228
229
230
231225
232226
227
233228
234229
235230
// Locate the symbol in the list, if it exists, update it's address
kernSymbols_t *symbol = lookup_kernel_symbol(symbolName);
if(symbol)
{
//printf("Located %sbit symbol %s at 0x%lX\n", is64 ? "64" : "32", symbolName, addr);
//getc();
symbol->addr = addr;
}
return 0xFFFFFFFF; // fixme
}

Archive Download the corresponding diff file

Revision: 548