Chameleon

Chameleon Commit Details

Date:2014-11-15 03:25:20 (9 years 5 months ago)
Author:ErmaC
Commit:2482
Parents: 2481
Message:Update laoder.h to latest, declare gMI global, Load modules passed in via the multiboot header / first bootloader, fix mboot.h include, Add ?log command to print out bdmesg without needing Wait=y, Add slightly more debugging for modules.
Changes:
M/trunk/i386/boot2/mboot.h
M/trunk/i386/modules/MakeInc.dir
M/trunk/i386/boot2/modules.c
M/trunk/CHANGES
M/trunk/i386/boot2/options.c
M/trunk/i386/boot2/modules.h
M/trunk/i386/include/mach-o/loader.h

File differences

trunk/i386/include/mach-o/loader.h
290290
291291
292292
293
294
295
296
297
293298
299
294300
295301
296302
......
11491155
11501156
11511157
1152
1158
1159
11531160
11541161
11551162
......
11691176
11701177
11711178
1172
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
11731195
11741196
11751197
......
11771199
11781200
11791201
1180
1202
11811203
11821204
11831205
......
12741296
12751297
12761298
1299
1300
1301
1302
12771303
12781304
12791305
......
13891415
13901416
13911417
1418
13921419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
13931463
13941464
13951465
#define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */
#define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat
like environment variable */
#define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
#define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
#define LC_SOURCE_VERSION 0x2A /* source version used to build binary */
#define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */
#defineLC_ENCRYPTION_INFO_64 0x2C /* 64-bit encrypted segment information */
/*
* A variable length string in a load command is represented by an lc_str
* union. The strings are stored just after the load command structure and
*/
struct linkedit_data_command {
uint32_tcmd;/* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO,
or LC_FUNCTION_STARTS */
LC_FUNCTION_STARTS, LC_DATA_IN_CODE,
or LC_DYLIB_CODE_SIGN_DRS */
uint32_tcmdsize;/* sizeof(struct linkedit_data_command) */
uint32_tdataoff;/* file offset of data in __LINKEDIT segment */
uint32_tdatasize;/* file size of data in __LINKEDIT segment */
};
/*
* The version_min_command contains the min OS version on which this
* The encryption_info_command_64 contains the file offset and size of an
* of an encrypted segment (for use in 64-bit targets).
*/
struct encryption_info_command_64 {
uint32_tcmd;/* LC_ENCRYPTION_INFO_64 */
uint32_tcmdsize;/* sizeof(struct encryption_info_command_64) */
uint32_tcryptoff;/* file offset of encrypted range */
uint32_tcryptsize;/* file size of encrypted range */
uint32_tcryptid;/* which enryption system,
0 means not-encrypted yet */
uint32_tpad;/* padding to make this struct's size a multiple
of 8 bytes */
};
/*
* The version_min_command contains the min OS version on which this
* binary was built to run.
*/
struct version_min_command {
LC_VERSION_MIN_IPHONEOS */
uint32_tcmdsize;/* sizeof(struct min_version_command) */
uint32_tversion;/* X.Y.Z is encoded in nibbles xxxx.yy.zz */
uint32_treserved;/* zero */
uint32_tsdk;/* X.Y.Z is encoded in nibbles xxxx.yy.zz */
};
/*
* a uleb128 encoded library ordinal, then a zero terminated
* UTF8 string. If the string is zero length, then the symbol
* is re-export from the specified dylib with the same name.
* If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following
* the flags is two uleb128s: the stub offset and the resolver offset.
* The stub is used by non-lazy pointers. The resolver is used
* by lazy pointers and must be called to get the actual address to use.
*
* After the optional exported symbol information is a byte of
* how many edges (0-255) that this node has leaving it,
uint32_theader_addr;/* files virtual address */
};
/*
* The entry_point_command is a replacement for thread_command.
* It is used for main executables to specify the location (file offset)
* of main(). If -stack_size was used at link time, the stacksize
* field will contain the stack size need for the main thread.
*/
struct entry_point_command {
uint32_t cmd;/* LC_MAIN only used in MH_EXECUTE filetypes */
uint32_t cmdsize;/* 24 */
uint64_t entryoff;/* file (__TEXT) offset of main() */
uint64_t stacksize;/* if not zero, initial stack size */
};
/*
* The source_version_command is an optional load command containing
* the version of the sources used to build the binary.
*/
struct source_version_command {
uint32_t cmd;/* LC_SOURCE_VERSION */
uint32_t cmdsize;/* 16 */
uint64_t version;/* A.B.C.D.E packed as a24.b10.c10.d10.e10 */
};
/*
* The LC_DATA_IN_CODE load commands uses a linkedit_data_command
* to point to an array of data_in_code_entry entries. Each entry
* describes a range of data in a code section.
*/
struct data_in_code_entry {
uint32_toffset; /* from mach_header to start of data range*/
uint16_tlength; /* number of bytes in data range */
uint16_tkind; /* a DICE_KIND_* value */
};
#define DICE_KIND_DATA 0x0001
#define DICE_KIND_JUMP_TABLE8 0x0002
#define DICE_KIND_JUMP_TABLE16 0x0003
#define DICE_KIND_JUMP_TABLE32 0x0004
#define DICE_KIND_ABS_JUMP_TABLE32 0x0005
/*
* Sections of type S_THREAD_LOCAL_VARIABLES contain an array
* of tlv_descriptor structures.
*/
trunk/i386/boot2/mboot.h
1818
1919
2020
21
22
23
2124
#ifndef __ASSEMBLER__
/* Put any desired prototypes or other C stuff here. */
extern struct multiboot_info *gMI;
#endif
trunk/i386/boot2/modules.c
66
77
88
9
910
1011
12
13
1114
1215
1316
......
3538
3639
3740
41
42
43
3844
45
46
47
48
49
50
51
52
53
54
55
3956
4057
4158
......
6279
6380
6481
65
82
6683
67
6884
6985
7086
......
7591
7692
7793
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
78141
79142
80143
......
87150
88151
89152
90
153
91154
92155
93156
......
171234
172235
173236
174
237
175238
176239
177240
......
229292
230293
231294
232
295
233296
234297
235298
......
247310
248311
249312
313
250314
251315
252316
......
489553
490554
491555
556
557
558
559
560
561
562
563
564
492565
493566
494567
#include "bootstruct.h"
#include "modules.h"
#include "boot_modules.h"
#include "mboot.h"
#include <vers.h>
#include <string.h>
#ifdef CONFIG_MODULES
#ifndef CONFIG_MODULE_DEBUG
#define CONFIG_MODULE_DEBUG 0
symbolList_t* moduleSymbols = NULL;
unsigned int (*lookup_symbol)(const char*) = NULL;
char *strrchr(const char *s, int c)
{
const char *found = NULL;
while (*s) {
if (*s == (char)c)
{
found = s;
}
s++;
}
return (char *)found;
}
/*
* Initialize the module system by loading the Symbols.dylib module.
* Once loaded, locate the _lookup_symbol function so that internal
if(module_start && module_start != (void*)0xFFFFFFFF)
{
// Notify the system that it was laoded
module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
module_loaded(SYMBOLS_MODULE, module_start, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
(*module_start)();// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
retVal = 1;
printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data); pause();
}
}
// Look for modules located in the multiboot header.
if(gMI->mi_flags & MULTIBOOT_INFO_HAS_MODS)
{
if(gMI->mi_mods_count)
{
struct multiboot_module* mod = (struct multiboot_module*)gMI->mi_mods_addr;
while(gMI->mi_mods_count--)
{
if(mod->mm_string)
{
// Convert string to module name, check for dylib.
if(strcmp(&mod->mm_string[strlen(mod->mm_string) - sizeof("dylib")], ".dylib") == 0)
{
module_data = (char*)mod->mm_mod_start;
char* last = strrchr(mod->mm_string, '/');
if(last)
{
last++;
}
else
{
last = mod->mm_string;
}
char* name = strdup(last);
name[strlen(last) - sizeof("dylib")] = 0;
DBG("Loading multiboot module %s", name);
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
{
// Notify the system that it was laoded
module_loaded(name, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
(*module_start)();// Start the module
DBG("Module %s Loaded.\n", name); DBGPAUSE();
}
}
}
}
}
}
if(retVal) execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
return retVal;
}
{
start_function();
// Notify the module system that this module really exists, specificaly, let other module link with it
module_loaded(name, author, description, version, compat);
module_loaded(name, start_function, author, description, version, compat);
}
/*
if(module_start && module_start != (void*)0xFFFFFFFF)
{
// Notify the system that it was laoded
module_loaded(module, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
module_loaded(module, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
(*module_start)();// Start the module
DBG("Module %s Loaded.\n", module); DBGPAUSE();
}
/*
* print out the information about the loaded module
*/
void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat)
void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat)
{
moduleList_t* new_entry = malloc(sizeof(moduleList_t));
new_entry->next = loadedModules;
new_entry->compat = compat;
msglog("Module '%s' by '%s' Loaded.\n", name, author);
msglog("\tInitialization: 0x%X\n", start);
msglog("\tDescription: %s\n", description);
msglog("\tVersion: %d\n", version); // todo: sperate to major.minor.bugfix
msglog("\tCompat: %d\n", compat); // todo: ^^^ major.minor.bugfix
case LC_UNIXTHREAD:
break;
case LC_VERSION_MIN_MACOSX:
break;
case LC_DATA_IN_CODE:
break;
case LC_FUNCTION_STARTS:
break;
default:
DBG("Unhandled loadcommand 0x%X\n", loadCommand->cmd & 0x7FFFFFFF);
break;
trunk/i386/boot2/modules.h
6868
6969
7070
71
71
7272
7373
7474
int load_module(char* module);
int is_module_loaded(const char* name);
void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat);
void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat);
trunk/i386/boot2/options.c
5858
5959
6060
61
62
63
64
6165
6266
6367
......
981985
982986
983987
988
989
984990
985991
986992
kScreenLastRow = 24
};
extern char* msgbuf;
void showTextBuffer(char *buf_orig, int size);
//==========================================================================
typedef struct {
}
} else if (strcmp(booterCommand, "lspci") == 0) {
lspci();
} else if (strcmp(booterCommand, "log") == 0) {
showTextBuffer(msgbuf, strlen(msgbuf));
} else if (strcmp(booterCommand, "more") == 0) {
showTextFile(booterParam);
} else if (strcmp(booterCommand, "rd") == 0) {
trunk/i386/modules/MakeInc.dir
124124
125125
126126
127
127128
128
129129
130130
131131
@echo "[LD] $(MODULE_NAME).dylib"
@ld -arch i386 \
-dylib -read_only_relocs suppress \
-alias _$(MODULE_START) start \
-dylib -read_only_relocs suppress \
-S -Z -dead_strip_dylibs \
-no_uuid \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
trunk/CHANGES
1
2
13
24
35
- meklort : Update laoder.h to latest, declare gMI global, Load modules passed in via the multiboot header / first bootloader,
Fix mboot.h include, Add ?log command to print out bdmesg without needing Wait=y, Add slightly more debugging for modules.
- ErmaC : Rename decompress_lzvn function to lzvn_decode follow Apple source name.
- bitshoveler : Fix "sed: RE error: illegal byte sequence", which turns out to be from feeding sed a TIFF file (buildpkg.sh)
- bitshoveler : CacheInit(), CacheRead() prototypes: use u_int32_t instead of long where appropriate (saio_internal.h)

Archive Download the corresponding diff file

Revision: 2482