Chameleon

Chameleon Commit Details

Date:2010-11-17 20:02:58 (13 years 5 months ago)
Author:Evan Lojewski
Commit:636
Parents: 635
Message:Embed Symbols.dylib in boot, incomplete.
Changes:
D/branches/meklort/i386/modules/Symbols
A/branches/meklort/i386/boot2/Symbols.c
M/branches/meklort/i386/modules/Makefile
M/branches/meklort/i386/boot2/modules.c
M/branches/meklort/i386/boot2/Makefile

File differences

branches/meklort/i386/boot2/modules.c
2222
2323
2424
25
26
2527
2628
2729
......
5456
5557
5658
59
60
61
62
63
64
65
66
5767
5868
5969
......
6676
6777
6878
79
80
81
6982
7083
7184
unsigned long long textAddress = 0;
unsigned long long textSection = 0;
void* symbols_module_start = (void*)0xFFFFFFFF;// This will be modified post compile
/** Internal symbols, however there are accessor methods **/
moduleHook_t* moduleCallbacks = NULL;
moduleList_t* loadedModules = NULL;
int init_module_system()
{
// Intialize module system
if(symbols_module_start == (void*)0xFFFFFFFF)
{
printf("Module system not compiled in\n");
}
// TODO: Load embeded module
/*
if(load_module(SYMBOLS_MODULE))
{
lookup_symbol = (void*)lookup_all_symbols(SYMBOL_LOOKUP_SYMBOL);
}
return 0;
*/
return -1;
}
branches/meklort/i386/boot2/Symbols.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Symbols.c
*
* Module loader support module. This module is the first module to ever be loaded.
* It contains a copy of each symbol inside ov the current version of chameleon as well
* as a strcmp function. Chameleon calls lookup_symbol to resolve internal symbols
* when they are requested by a module. This module does *not* depend on any intenrla
* symbols, as such it can be loaded without a symbol table initialized.
*
* Copyright (c) 2009 Evan Lojewski. All rights reserved.
*/
#include "Symbols.h"
static int strcmp(const char * s1, const char * s2);
void Symbols_start()
{
// load_dependency("Symbols", 300);
}
unsigned int lookup_symbol(const char* symbol)
{
int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;
int lowerLimit = 0;
int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
int result;
while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)
{
if(result > 0)// We need to search a HIGHER index
{
if(compareIndex != lowerLimit)
{
lowerLimit = compareIndex;
}
else
{
return 0xFFFFFFFF;// Symbol not found
}
compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
}
else // We Need to search a LOWER index
{
if(compareIndex != upperLimit)
{
upperLimit = compareIndex;
}
else
{
return 0xFFFFFFFF;// Symbol not found
}
compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
}
}
return symbolList[compareIndex].addr;
}
/*
* strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point
*/
static int strcmp(const char * s1, const char * s2)
{
while (*s1 && (*s1 == *s2)) {
s1++;
s2++;
}
return (*s1 - *s2);
}
branches/meklort/i386/boot2/Makefile
5555
5656
5757
58
59
60
61
62
63
64
65
66
67
68
5869
5970
6071
6172
62
73
6374
6475
6576
66
77
78
79
6780
6881
6982
......
7487
7588
7689
90
91
92
93
94
95
96
97
98
99
100
77101
78102
79103
......
84108
85109
86110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
87125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
88145
89146
90147
MAXBOOTSIZE = 458240
#
# Strings used to retrieve the start location for the Symbols.dylib module
#
SYMBOLS_MODULE = Symbols.dylib
SYMBOL_START= _symbols_module_start
SYMBOL_ADDR = $(shell printf "%d" 0x`nm -s __DATA __data $(SYMROOT)/boot.sys | grep " $(SYMBOL_START)$$" | cut -f 1 -d " "`)
DATA_OFFSET = $(shell otool -l $(SYMROOT)/boot.sys | grep __data -A 4 | grep __DATA -A 3 | tail -n 1 | cut -f 6 -d " ")
DATA_ADDR = $(shell printf "%d" `otool -l $(SYMROOT)/boot.sys | grep __data -A 4 | grep __DATA -A 3 | head -n 2 | tail -n 1 | cut -f 8 -d " "`)
PATCH_ADDR = $(shell echo ${SYMBOL_ADDR}-${DATA_ADDR}+${DATA_OFFSET} | bc)
optionrom: CFLAGS += -DOPTION_ROM
all embedtheme optionrom: $(DIRS_NEEDED) boot
boot: machOconv embedded.h $(OBJS) $(LIBDEP)
boot: embedded.h $(OBJS) $(LIBDEP)
$(LD) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \
-nostdlib -arch i386 -Wl,-segalign,20 \
-o $(SYMROOT)/boot.sys $(filter %.o,$^) $(LIBS) -lcc_kext
machOconv $(SYMROOT)/boot.sys $(SYMROOT)/boot
@make embed_symbols# this is done in a sub process after boot.sys exists so the strings are populated correctly
size $(SYMROOT)/boot.sys
ls -l $(SYMROOT)/boot
@( size=`ls -l $(SYMROOT)/boot | awk '{ print $$5}'` ; \
exit 1;\
fi)
embed_symbols: machOconv Symbols.dylib
@echo ================= Embedding Symbols.dylib =================
machOconv $(SYMROOT)/boot.sys $(SYMROOT)/boot
stat -f%z $(SYMROOT)/boot | perl -ane "print pack('V',@F[0]);" | dd conv=notrunc of=${SYMROOT}/boot.sys bs=1 count=4 seek=$(PATCH_ADDR)
machOconv $(SYMROOT)/boot.sys $(SYMROOT)/boot
dd if=${SYMROOT}/${SYMBOLS_MODULE} of=${SYMROOT}/boot bs=1 seek=`stat -f%z $(SYMROOT)/boot`
${RM} $(SYMROOT)/${SYMBOLS_MODULE}
prompt.o: vers.h
vers.h:
@echo "#define I386BOOT_VERSION \"5.0.132\"" > $(SYMROOT)/vers.h
embedded.h:
@cd $(SYMROOT)/../../doc && xxd -i BootHelp.txt > $(SYMROOT)/embedded.h
Symbols.dylib: Symbols.o
@echo ================= Compiling ${SYMBOLS_MODULE} =================
@ld -arch i386 \
-undefined dynamic_lookup \
-alias _Symbols_start start \
-dylib -read_only_relocs suppress \
-S -x -dead_strip_dylibs \
-no_uuid \
-bind_at_load \
-current_version 1.0.0 \
-compatibility_version 1.0.0 \
-final_output Symbols \
${OBJROOT}/Symbols.o \
-o $(SYMROOT)/${SYMBOLS_MODULE}
@size $(SYMROOT)/${SYMBOLS_MODULE}
Symbols.o:
@rm -rf $(SYMROOT)/Symbols.h
@echo "typedef struct {" >> $(SYMROOT)/Symbols.h
@echo "char*symbol;" >> $(SYMROOT)/Symbols.h
@echo "unsigned intaddr;" >> $(SYMROOT)/Symbols.h
@echo "} symbol_t;" >> $(SYMROOT)/Symbols.h
@echo "" >> $(SYMROOT)/Symbols.h
@nm -g $(SYMROOT)/boot.sys | tr . _ | awk '{print "static char "$$3"_string[] = \""$$3"\";"}' >> $(SYMROOT)/Symbols.h
@echo "symbol_t symbolList[] = {" >> $(SYMROOT)/Symbols.h
@nm -g $(SYMROOT)/boot.sys | tr . _ | awk '{print "{.symbol = "$$3"_string, .addr = 0x"$$1"},";}' >> $(SYMROOT)/Symbols.h
@echo "};" >> $(SYMROOT)/Symbols.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c Symbols.c $(INC) -o $(OBJROOT)/Symbols.o
install_i386:: all $(INSTALLDIR)
cp $(SYMROOT)/boot $(OTHER_FILES) $(INSTALLDIR)
cd $(INSTALLDIR); chmod u+w boot $(OTHER_FILES)
branches/meklort/i386/modules/Makefile
2626
2727
2828
29
30
29
3130
31
3232
3333
3434
VPATH = $(OBJROOT):$(SYMROOT)
# The order of building is important.
# TODO: exclude Symbols from find so it isn't compiled twice
SUBDIRS = Symbols Resolution KernelPatcher GUI KextPatcher GraphicsEnabler ACPIPatcher HPET USBFix Memory Networking NetbookInstaller
SUBDIRS = Resolution KernelPatcher GUI KextPatcher GraphicsEnabler ACPIPatcher HPET USBFix Memory Networking NetbookInstaller
#SUBDIRS = USB
#SUBDIRS = Symbols # This is made during the boot2 build stage
all embedtheme optionrom tags debug install installhdrs:
@rm -rf $(OBJROOT)

Archive Download the corresponding diff file

Revision: 636