Chameleon Applications

Chameleon Applications Commit Details

Date:2011-05-29 03:28:04 (9 years 4 months ago)
Author:ErmaC
Commit:301
Parents: 300
Message:last trunk change.
Changes:
M/branches/iFabio/Chameleon/i386/util/dyldsymboltool.c
M/branches/iFabio/Chameleon/i386/libsaio/cpu.h
M/branches/iFabio/Chameleon/i386/modules/HelloWorld/HelloWorld.cpp
M/branches/iFabio/Chameleon/i386/modules/Cconfig
M/branches/iFabio/Chameleon/i386/modules/HelloWorld/Makefile
M/branches/iFabio/Chameleon/i386/boot2/Makefile
M/branches/iFabio/Chameleon/i386/libsaio/asm.s
M/branches/iFabio/Chameleon/i386/modules/Makefile
M/branches/iFabio/Chameleon/i386/boot1/boot1he.s
M/branches/iFabio/Chameleon/i386/boot2/boot.c
M/branches/iFabio/Chameleon/i386/libsaio/cpu.c
M/branches/iFabio/Chameleon/i386/util/Makefile
M/branches/iFabio/Chameleon/i386/modules/MakeInc.dir
M/branches/iFabio/Chameleon/i386/Makefile
M/branches/iFabio/Chameleon/i386/libsaio/nvidia.c

File differences

branches/iFabio/Chameleon/i386/libsaio/asm.s
338338
339339
340340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
341366
342367
343368
......
345370
346371
347372
373
374
348375
349376
350377
351
378
352379
353380
354381
#endif
jmp _halt
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// disableIRQs() - Azi: DHP
// http://www.insanelymac.com/forum/index.php?s=&showtopic=255866&view=findpost&p=1677779
//
// Port of original patch by: CPARM (who basically did this in boot.c) Thanks!
//
// The ACPI specification dictates that the 8259 (PC-AT compatible) vectors
// must be disabled (that is, masked) when enabling the ACPI APIC operation
// but this isn't done (apparently) on all mobo's and thus we do that here.
//
LABEL(_disableIRQs)
push %eax // Saving register data
movb $0x80, %al // Block NMI
outb %al, $0x70
movb $0xff, %al // Load mask
outb %al, $0x21 // Disable IRQ's 0-7 on Master PIC
outb %al, $0xa1 // Disable IRQ's 8-15 on Slave PIC
popl %eax // Restore register data
ret
#ifndef BOOT1
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// startprog(phyaddr, arg)
// Passes arg to the program in %eax.
//
LABEL(_startprog)
call _disableIRQs // Taking care of a ACPI bug. (Azi: calling the above)
push %ebp
mov %esp, %ebp
mov 0xc(%ebp), %eax // argument to program
mov 0xc(%ebp), %eax // argument to program - bootargs to mach_kernel
mov 0x8(%ebp), %ecx // entry offset
mov $0x28, %ebx // segment
push %ebx
branches/iFabio/Chameleon/i386/libsaio/nvidia.c
569569
570570
571571
572
572
573573
574574
575575
576576
577577
578
578579
579580
580581
581
582
582
583583
584584
585585
......
897897
898898
899899
900
901
902
903
904
905
906
907
908
900909
901910
902911
{ 0x10DE107F, "NVIDIA GF119-ES" },
{ 0x10DE1080, "GeForce GTX 580" },
{ 0x10DE1081, "GeForce GTX 570" },
{ 0x10DE1082, "D13U" },
{ 0x10DE1082, "GeForce GTX 560 Ti" },
{ 0x10DE1083, "D13U" },
{ 0x10DE1086, "GeForce GTX 570" },
{ 0x10DE1088, "GeForce GTX 590" },
{ 0x10DE1098, "D13U" },
{ 0x10DE109A, "Quadro 5010M / N12E-Q5" },
{ 0x10DE10C3, "GeForce 8400 GS" },
{ 0x10DE1200, "GeForce GTX 560 Ti" },
{ 0x10DE1244, "GeForce GTX 550 Ti" },
{ 0x10DE1245, "GeForce GTS 450" },
{ 0x10DE1251, "N12E-GS-A1" },
{ 0x10DE10C3, "GeForce 8400 GS" }
{ 0x10DE1251, "N12E-GS-A1" }
};
static uint16_t swap16(uint16_t x)
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
// workaround code for GT 420/430 & 9600M GT
switch (nvda_dev->device_id)
{
case 0x0DE1: vram_size = 1024*1024*1024; break; // GT 430
case 0x0DE2: vram_size = 1024*1024*1024; break; // GT 420
case 0x0649: vram_size = 512*1024*1024; break; // 9600M GT
default: break;
}
return vram_size;
}
branches/iFabio/Chameleon/i386/libsaio/cpu.c
136136
137137
138138
139
139
140
141
142
143
140144
141145
142146
p->CPU.Model += (p->CPU.ExtModel << 4);
if (p->CPU.Vendor == 0x756E6547 /* Intel */ && p->CPU.Family == 0x06 && p->CPU.Model >= 0x1a){
if (p->CPU.Vendor == 0x756E6547 /* Intel */ &&
p->CPU.Family == 0x06 &&
p->CPU.Model >= CPUID_MODEL_PENRYN &&
p->CPU.Model != CPUID_MODEL_ATOM // MSR is *NOT* available on the Intel Atom CPU
){
msr = rdmsr64(MSR_CORE_THREAD_COUNT);// Undocumented MSR in Nehalem and newer CPUs
p->CPU.NoCores= bitfield((uint32_t)msr, 31, 16);// Using undocumented MSR to get actual values
p->CPU.NoThreads= bitfield((uint32_t)msr, 15, 0);// Using undocumented MSR to get actual values
branches/iFabio/Chameleon/i386/libsaio/cpu.h
3636
3737
3838
39
40
41
42
43
44
45
46
47
48
49
50
51
52
3953
4054
4155
#define CALIBRATE_TIME_MSEC30/* 30 msecs */
#define CALIBRATE_LATCH((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000)
// CPUID Values
#define CPUID_MODEL_YONAH14
#define CPUID_MODEL_MEROM15
#define CPUID_MODEL_PENRYN23
#define CPUID_MODEL_NEHALEM26
#define CPUID_MODEL_ATOM 28
#define CPUID_MODEL_FIELDS30/* Lynnfield, Clarksfield, Jasper */
#define CPUID_MODEL_DALES31/* Havendale, Auburndale */
#define CPUID_MODEL_NEHALEM_EX46
#define CPUID_MODEL_DALES_32NM37/* Clarkdale, Arrandale */
#define CPUID_MODEL_WESTMERE44/* Gulftown, Westmere-EP, Westmere-WS */
#define CPUID_MODEL_WESTMERE_EX47
static inline uint64_t rdtsc64(void)
{
uint64_t ret;
branches/iFabio/Chameleon/i386/boot1/boot1he.s
542542
543543
544544
545
546
547545
548546
549547
......
637635
638636
639637
638
639
640640
641641
642642
hlt
jmp hang
%if VERBOSE
;--------------------------------------------------------------------------
; readLBA - Read sectors from a partition using LBA addressing.
;
popad
ret
%if VERBOSE
;--------------------------------------------------------------------------
; Write a string with 'boot1: ' prefix to the console.
;
branches/iFabio/Chameleon/i386/boot2/Makefile
126126
127127
128128
129
130
129
131130
132131
133132
133
134134
135135
136136
137
138
137139
138140
139141
@${RM} $(SYMROOT)/boot2.sys
@##size $(SYMROOT)/boot.sys
@ls -l $(SYMROOT)/boot
@( size=`ls -l $(SYMROOT)/boot | awk '{ print $$5}'` ; \
if expr "$$size" ">" "$(MAXBOOTSIZE)" > /dev/null ;\
then \
echo "\t******* boot is $$size bytes *******"; \
echo "Booter executable larger than $(MAXBOOTSIZE) bytes" ;\
rm $(SYMROOT)/boot ;\
exit 1;\
else \
echo "\t******* boot is $$size bytes *******"; \
fi)
branches/iFabio/Chameleon/i386/boot2/boot.c
208208
209209
210210
211
212
211
212
213213
214214
215215
if (checkOSVersion("10.7")) {
// Masking out so that Lion doesn't doublefault
outb(0x21, 0xff);/* Maskout all interrupts Pic1 */
outb(0xa1, 0xff);/* Maskout all interrupts Pic2 */
// outb(0x21, 0xff);/* Maskout all interrupts Pic1 */
// outb(0xa1, 0xff);/* Maskout all interrupts Pic2 */
// Jump to kernel's entry point. There's no going back now.
branches/iFabio/Chameleon/i386/modules/MakeInc.dir
1010
1111
1212
13
13
1414
1515
1616
......
5151
5252
5353
54
54
55
56
57
5558
5659
57
60
61
5862
63
5964
6065
6166
62
63
6467
6568
6669
......
8285
8386
8487
85
88
8689
8790
8891
......
97100
98101
99102
100
101103
102
104
105
106
107
108
109
110
111
103112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
104127
105128
106129
......
109132
110133
111134
112
113
114
115
116
117
135
136
137
118138
119
120
121
122
139
140
141
123142
143
124144
125145
126146
......
137157
138158
139159
140
141
160
161
142162
143
144
163
164
145165
146
147
166
167
148168
149169
150170
ifeq ($(BUILT_IN),yes)
override OBJROOT = $(SRCROOT)/obj/i386/boot2_modules/$(DIR)
override SYMROOT = $(SRCROOT)/sym/i386/
override SYMROOT = $(SRCROOT)/obj/i386/
endif
include ${SRCROOT}/Make.rules
LIBSAIODIR = ../../libsaio
BOOT2DIR = ../../boot2
INC = -I$(SRCROOT)/i386/modules/include/ -Iinclude/ -I$(SRCROOT)/i386/modules/module_includes/ -I$(SRCROOT)/i386/libsaio/ -I$(SRCROOT)/i386/libsa/ -I$(SRCROOT)/i386/include/ -I$(SRCROOT)/i386/boot2/
MODULE_INCLUDES := $(foreach x,$(MODULE_DEPENDENCIES),-I$(SRCROOT)/i386/modules/$(x)/include/)
INC = -I$(SRCROOT)/i386/modules/include/ -Iinclude/ -I$(SRCROOT)/i386/libsaio/ -I$(SRCROOT)/i386/libsa/ -I$(SRCROOT)/i386/include/ -I$(SRCROOT)/i386/boot2/ $(MODULE_INCLUDES)
DEFINES := -D__KLIBC__ $(DEFINES)
MODULE_DEPENDENCIES := $(foreach x,$(MODULE_DEPENDENCIES),-weak_library $(SYMROOT)/modules/$(x).dylib)
MODULE_DEPENDENCIES := $(wildcard $(foreach x,$(MODULE_DEPENDENCIES),$(SYMROOT)/modules/$(x).dylib)) \
$(wildcard $(foreach x,$(MODULE_DEPENDENCIES),$(OBJROOT)/../$(x).dylib))
MODULE_DEPENDENCIES_CMD := $(foreach x,$(MODULE_DEPENDENCIES), -weak_library $(x))
INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone
##$(error DEFINED AS $(MODULE_DEFINITION))
MODULE_DEFINITION := $(CONFIG_$(shell echo $(MODULE_NAME) | tr '[:lower:]' '[:upper:]')_MODULE)
ifeq ($(BUILT_IN),yes)
# Make this *BUILT IN*
all: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(SYMROOT)/boot_modules.h $(SYMROOT)/boot_modules.c
all: dylib_LINKER
else
# Module not selected to be built in
endif
endif
dylib: ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(SYMROOT)/modules/$(MODULE_NAME).dylib
$(SYMROOT)/modules/$(MODULE_NAME).dylib:
dylib_LINKER: $(SRCROOT)/sym/i386/boot_modules.c $(SRCROOT)/sym/i386/boot_modules.h dylib
dylib: ${SYMROOT}/modules/ ${OBJROOT} $(SYMROOT)/modules/$(MODULE_NAME).dylib
ifeq ($(BUILT_IN),yes)
$(SYMROOT)/modules/$(MODULE_NAME).dylib: $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(MODULE_DEPENDENCIES)
@echo "\t[LD] $(MODULE_NAME).dylib"
@ld -arch i386 -undefined dynamic_lookup \
-dylib -read_only_relocs suppress \
-S -x -Z -dead_strip_dylibs \
-no_uuid \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
-final_output $(MODULE_NAME) \
$(filter %.o,$^) \
-macosx_version_min 10.6 \
-o $(SYMROOT)/modules/$(MODULE_NAME).dylib
else
$(SYMROOT)/modules/$(MODULE_NAME).dylib: $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(MODULE_DEPENDENCIES) $(SRCROOT)/obj/i386/boot2/Symbols_LINKER_ONLY.dylib
@echo "\t[LD] $(MODULE_NAME).dylib"
@ld -arch i386 \
-alias _$(MODULE_START) start \
-no_uuid \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
-final_output $(MODULE_NAME) \
-L$(OBJROOT)/ \
-L$(OBJROOT)/../ \
-L$(SYMROOT)/ \
$(OBJROOT)/*.o \
-weak_library $(OBJROOT)/../../boot2/Symbols_LINKER_ONLY.dylib \
$(MODULE_DEPENDENCIES) \
$(filter %.o,$^) \
-weak_library $(SRCROOT)/obj/i386/boot2/Symbols_LINKER_ONLY.dylib \
$(MODULE_DEPENDENCIES_CMD) \
-macosx_version_min 10.6 \
-o $(SYMROOT)/modules/$(MODULE_NAME).dylib
@cp -rf include/* ../module_includes/ &> /dev/null || true
-o $@
endif
clean:
@echo "\t[RM] $(SYMROOT)/modules/$(MODULE_NAME).dylib"
@echo "\t[RM] $(OBJROOT)"
.PHONY: $(SYMROOT)/boot_modules.h
.PHONY: $(SYMROOT)/boot_modules.c
.PHONY: $(SRCROOT)/sym/i386/boot_modules.h
.PHONY: $(SRCROOT)/sym/i386/boot_modules.c
$(SYMROOT)/boot_modules.c:
@echo "\tstart_built_in_module(\"$(MODULE_NAME)\", &$(MODULE_START));" >> $@
$(SRCROOT)/sym/i386/boot_modules.c:
echo "\tstart_built_in_module(\"$(MODULE_NAME)\", &$(MODULE_START));" >> $@
$(SYMROOT)/boot_modules.h:
@echo "void $(MODULE_START)(); // $(MODULE_NAME)" >> $@
$(SRCROOT)/sym/i386/boot_modules.h:
echo "void $(MODULE_START)(); // $(MODULE_NAME)" >> $@
#dependencies
branches/iFabio/Chameleon/i386/modules/Cconfig
55
66
77
8
8
99
1010
1111
menu "Modules"
source "i386/modules/Resolution/Cconfig"
source "i386/modules/klibc/Cconfig"
source "i386/modules/uClibc++/Cconfig"
source "i386/modules/uClibcxx/Cconfig"
source "i386/modules/HelloWorld/Cconfig"
source "i386/modules/AMDGraphicsEnabler/Cconfig"
source "i386/modules/ATiGraphicsEnabler/Cconfig"
branches/iFabio/Chameleon/i386/modules/HelloWorld/HelloWorld.cpp
66
77
88
9
10
11
12
13
14
915
1016
1117
#include <iostream>
#include <modules>
extern "C"
{
void HelloWorld_start();
}
using namespace std;
class HW {
branches/iFabio/Chameleon/i386/modules/HelloWorld/Makefile
11
22
33
4
5
6
4
5
76
87
98
MODULE_NAME = HelloWorld
MODULE_VERSION = "1.0.0"
MODULE_COMPAT_VERSION = "1.0.0"
#MODULE_START = $(MODULE_NAME)_start
MODULE_START = __Z16HelloWorld_startv
MODULE_DEPENDENCIES = uClibc++
MODULE_START = $(MODULE_NAME)_start
MODULE_DEPENDENCIES = uClibcxx
DIR = HelloWorld
branches/iFabio/Chameleon/i386/modules/Makefile
1111
1212
1313
14
14
1515
1616
1717
......
5555
5656
5757
58
59
60
61
58
6259
6360
6461
65
62
63
6664
6765
6866
67
6968
7069
71
70
71
7272
73
73
include ${SRCROOT}/Make.rules
# The order of building is important.
SUBDIRS = klibc uClibc++ Resolution HelloWorld \
SUBDIRS = klibc uClibcxx Resolution HelloWorld \
ATiGraphicsEnabler AMDGraphicsEnabler NVIDIAGraphicsEnabler IntelGraphicsEnabler
.PHONY: $(SYMROOT)/boot_modules.c
objroot_dirs:
@rm -rf module_includes
@mkdir module_includes
@rm -rf "$(SYMROOT)/modules/"
@mkdir "$(SYMROOT)/modules/"
@${MKDIRS} "$(SYMROOT)/modules/"
$(SYMROOT)/boot_modules.c: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS})
@echo "// Autogenerated - do not modify" > $@
ifeq ($(BUILT_IN),yes)
echo "// Autogenerated - do not modify" > $@
@echo "#include <modules.h>" >> $@
@echo "#include \"boot_modules.h\"" >> $@
@echo "void start_built_in_modules() {" >> $@
endif
$(SYMROOT)/boot_modules.h: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS})
@echo "// Autogenerated - do not modify" > $@
ifeq ($(BUILT_IN),yes)
echo "// Autogenerated - do not modify" > $@
@echo "void start_built_in_modules(); " > $@
endif
branches/iFabio/Chameleon/i386/Makefile
1515
1616
1717
18
18
19
1920
2021
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2240
2341
2442
include ${SRCROOT}/Make.rules
# The order of building is important.
SUBDIRS = util libsa libsaio boot0 boot1 boot2 cdboot modules
SUBDIRS_PRE = util
SUBDIRS = libsa libsaio boot0 boot1 boot2 cdboot modules
all:
@cd modules; ${MAKE} BUILT_IN=yes all
@for i in ${SUBDIRS_PRE}; \
do \
echo ================= make $@ for $$i =================; \
( cd $$i; ${MAKE} \
"OBJROOT=$(OBJROOT)/$$i" \
"SYMROOT=$(SYMROOT)" \
"DSTROOT=$(DSTROOT)" \
"SRCROOT=$(SRCROOT)" \
"RC_ARCHS=$(RC_ARCHS)" \
"RC_KANJI=$(RC_KANJI)" \
"JAPANESE=$(JAPANESE)" \
"RC_CFLAGS=$(RC_CFLAGS)" $@ \
) || exit $$?; \
done
@cd modules; ${MAKE} BUILT_IN=yes $@
@for i in ${SUBDIRS}; \
do \
echo ================= make $@ for $$i =================; \
branches/iFabio/Chameleon/i386/util/dyldsymboltool.c
4545
4646
4747
48
48
4949
50
50
5151
5252
5353
5454
5555
56
57
58
5956
6057
6158
......
6562
6663
6764
65
66
67
68
69
70
6871
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
69105
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94106
95107
96108
97
109
110
98111
112
113
114
115
99116
100
101
102
103117
104118
105119
......
135149
136150
137151
138
152
139153
140154
141155
int main(int argc, char *argv[])
{
if(argc != 3)
if(argc < 3)
{
fprintf(stderr, "usage: dyldsymboltool bootFile loadAddr outfile\n");
fprintf(stderr, "usage: dyldsymboltool obj1 [obj2 ...] outfile\n");
exit(-1);
}
char line[256];
char* command = malloc(strlen(argv[1]) + sizeof("nm -g "));
FILE *fpipe;
symbols_dylib_t dylib;
symbolList_t*symbols = NULL;
int i;
for(i = 1; i < argc-1; i++)
{
char line[256];
char* command = malloc(strlen(argv[1]) + sizeof("nm -g "));
FILE *fpipe;
// Parse boot.sys (arg1) to get symtab
sprintf(command, "nm -g %s", argv[i]);// TODO: read boot.sym directly, no need for nm
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
if((strlen(line) < strlen(argv[i]) ||
strncmp(line, argv[i], strlen(argv[i])) != 0)
&& line[0] != ' ')
{
uint32_t address = 0;
char* addr = strtok(line, " ");
strtok(NULL, " ");
char* name = strtok(NULL, " ");
name[strlen(name)-1] = 0;// remove newline
sscanf(addr, "%x", &address);
if(strcmp(name, VOID_SYMBOL) == 0) start_addr = address;
add_symbol(&symbols, name, address);
}
}
pclose(fpipe);
free(command);
}
// Parse boot.sys (arg1) to get symtab
sprintf(command, "nm -g %s", argv[1]);// TODO: read boot.sym directly, no need for nm
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
uint32_t address = 0;
char* addr = strtok(line, " ");
strtok(NULL, " ");
char* name = strtok(NULL, " ");
name[strlen(name)-1] = 0;// remove newline
sscanf(addr, "%x", &address);
if(strcmp(name, VOID_SYMBOL) == 0) start_addr = address;
add_symbol(&symbols, name, address);
}
pclose(fpipe);
if(start_addr == 0)
{
fprintf(stderr, "Unable to locate Symbol.dylib start function\n");
exit(1);
//exit(1);
}
else
{
add_symbol(&symbols, START_SYMBOL, start_addr);
}
add_symbol(&symbols, START_SYMBOL, start_addr);
/* Header command info */
dylib.header.ncmds = 2;
dylib.header.sizeofcmds = sizeof(dylib) - sizeof(struct mach_header);// + dylib.symtab.nsyms * sizeof(struct nlist) + dylib.symtab.strsize;
FILE* outfile = fopen(argv[2], "w");
FILE* outfile = fopen(argv[argc-1], "w");
fwrite(&dylib,sizeof(dylib)/* Sizeof header + module name */
, 1, outfile);
branches/iFabio/Chameleon/i386/util/Makefile
44
55
66
7
7
88
99
1010
# and install them directly, rather than generating them again.
#
SRCROOT = $(shell pwd)/../../
OBJROOT = $(SRCROOT)/obj/i386
OBJROOT = $(SRCROOT)/obj/i386/util
SYMROOT = $(SRCROOT)/sym/i386
DSTROOT = $(SRCROOT)/dst/i386
DOCROOT = $(SRCROOT)/doc

Archive Download the corresponding diff file

Revision: 301