- 积分
- 202
- 最后登录
- 2020-11-15
- 精华
- 0
- 阅读权限
- 30
- 主题
- 171
- UID
- 4166712
- 帖子
- 506
- PB币
- 779
- 威望
- 0
- 贡献
- 0
- 技术
- 184
- 活跃
- 651
- UID
- 4166712
- 帖子
- 506
- PB币
- 779
- 贡献
- 0
- 技术
- 184
- 活跃
- 651
|
這是從目前穩定的 BSA Kernel 與 Apple 源碼做比對的分析後結果
了解支援各種處理器的核心是怎麼來的與如何修改
如何提取源碼跟編譯
https://bbs.pcbeta.com/viewthread-1468302-1-1.html
以10.9 xnu 為例
一 支援AMD處理器的修改方法
以下虛線部分不要寫入源碼裡面
- -----插入程式碼----------------------------
- -------------------------------------------
复制代码
/xnu-2422.1.72/bsd/kern/ubc_subr.c
找尋 if (bcmp(expected_hash, actual_hash, SHA1_RESULTLEN) != 0) {
改為
- if (0 && bcmp(expected_hash, actual_hash, SHA1_RESULTLEN) != 0) {
复制代码
/xnu-2422.1.72/iokit/Kernel/IOCatalogue.cpp
屏閉驅動清單
再上頭找到 extern "C" 再 extern "C"上面插入
- -----插入程式碼----------------------------
- /* Sinetek: Array of blacklisted Kexts.
- * Should be moved somewhere convenient?
- */
- const char *blak [] = {
- "com.apple.driver.AppleIntelMeromProfile",
- "com.apple.driver.AppleIntelNehalemProfile",
- "com.apple.driver.AppleIntelPenrynProfile",
- "com.apple.driver.AppleIntelYonahProfile",
- "com.apple.driver.AppleIntelCPUPowerManagement",
- "com.apple.iokit.CHUDKernLib",
- "com.apple.iokit.CHUDProf",
- "com.apple.iokit.CHUDUtils",
- 0, // terminate!
- };
- -------------------------------------------
- extern "C" {
复制代码
/xnu-2422.1.72/libkern/c++/OSKext.cpp
找尋 PE_parse_boot_argn("keepsyms", &sKeepSymbols, sizeof(sKeepSymbols))
- PE_parse_boot_argn("keepsyms", &sKeepSymbols, sizeof(sKeepSymbols));
- -----插入程式碼----------------------------
- sKeepSymbols = 1;
- -------------------------------------------
复制代码
/xnu-2422.1.72/osfmk/i386/AT386/model_dep.c
關機重啟斷電修正
找尋 halt_all_cpus(boolean_t reboot)
程式碼修正
- halt_all_cpus(boolean_t reboot)
- {
- uint32_t ncpus, i;
- ncpus = chudxnu_logical_cpu_count();
- for (i = 0; i < ncpus; i++)
- chudxnu_enable_cpu(i, FALSE);
- if (reboot) {
- printf("MACH Reboot\n");
- PEHaltRestart( kPERestartCPU );
- asm volatile ("movb $0xfe, %al\n"
- "outb %al, $0x64\n"
- "hlt\n");
- } else {
- printf("CPU halted\n");
- PEHaltRestart( kPEHaltCPU );
- }
- while(1);
- }
复制代码
找尋 PE_parse_boot_argn("keepsyms", &keepsyms, sizeof (keepsyms));
- PE_parse_boot_argn("keepsyms", &keepsyms, sizeof (keepsyms));
- -----插入程式碼----------------------------
- keepsyms = 1;
- -------------------------------------------
复制代码
/xnu-2422.1.72/osfmk/i386/cpuid.c
修改支援AMD處理器範例
找尋 static const char *cache_type_str[LCACHE_MAX] = {
- static const char *cache_type_str[LCACHE_MAX] = {
- "Lnone", "L1I", "L1D", "L2U", "L3U"
- };
- -----插入程式碼----------------------------
- /* Sinetek: reimplemented, based on AnV, mercurySquad, thanks go to them.
- * Function is AMD-specific.
- */
- static void
- cpuid_set_AMDcache_info( i386_cpu_info_t * info_p )
- {
- uint32_t reg[4];
- uint32_t linesizes[LCACHE_MAX];
- cache_type_t type;
- uint32_t j;
- uint32_t colors;
- bzero( linesizes, sizeof(linesizes) );
- /* get number of cores in processor */
- /* No HT on AMD so logicals = cores */
- cpuid_fn(0x80000008, reg);
- info_p->cpuid_cores_per_package = bitfield32(reg[ecx], 7, 0) + 1;
- info_p->cpuid_logical_per_package = info_p->cpuid_cores_per_package;
- /* L1 Data */
- {
- type = L1D;
- cpuid_fn(0x80000005, reg);
- uint32_t cpuid_c_linesize = bitfield32(reg[ecx], 7, 0);
- uint32_t cpuid_c_partitions = bitfield32(reg[ecx], 15, 8);
- uint32_t cpuid_c_associativity = bitfield32(reg[ecx], 23, 16);
- uint32_t cpuid_c_size = bitfield32(reg[ecx], 31, 24);
- uint32_t cache_associativity = cpuid_c_associativity;
- // size reported in KB.
- info_p->cache_size[type] = cpuid_c_size * 1024;
- info_p->cache_sharing[type] = 1;
- info_p->cache_partitions[type] = cpuid_c_partitions;
- linesizes[type] = cpuid_c_linesize;
- uint32_t cache_sets = info_p->cache_size[type] / (cpuid_c_partitions * cpuid_c_linesize * cache_associativity);
- colors = ( cpuid_c_linesize * cache_sets ) >> 12;
- if ( colors > vm_cache_geometry_colors )
- vm_cache_geometry_colors = colors;
- }
- /* L1 Instruction */
- {
- type = L1I;
- cpuid_fn(0x80000005, reg);
- uint32_t cpuid_c_linesize = bitfield32(reg[edx], 7, 0);
- uint32_t cpuid_c_partitions = bitfield32(reg[edx], 15, 8);
- uint32_t cpuid_c_associativity = bitfield32(reg[edx], 23, 16);
- uint32_t cpuid_c_size = bitfield32(reg[edx], 31, 24);
- uint32_t cache_associativity = cpuid_c_associativity;
- // size reported in KB.
- info_p->cache_size[type] = cpuid_c_size * 1024;
- info_p->cache_sharing[type] = 1;
- info_p->cache_partitions[type] = cpuid_c_partitions;
- linesizes[type] = cpuid_c_linesize;
- uint32_t cache_sets = info_p->cache_size[type] / (cpuid_c_partitions * cpuid_c_linesize * cache_associativity);
- colors = ( cpuid_c_linesize * cache_sets ) >> 12;
- if ( colors > vm_cache_geometry_colors )
- vm_cache_geometry_colors = colors;
- }
- /* L2 Unified */
- {
- type = L2U;
- cpuid_fn(0x80000006, reg);
- uint32_t cpuid_c_linesize = bitfield32(reg[ecx], 7, 0);
- uint32_t cpuid_c_partitions = bitfield32(reg[ecx], 11, 8);
- uint32_t cpuid_c_associativity = bitfield32(reg[ecx], 15, 12);
- uint32_t cpuid_c_size = bitfield32(reg[ecx], 31, 16);
- // Special formula for associativity: 2^(assoc / 2)
- uint32_t cache_associativity = 1ul << (cpuid_c_associativity / 2);
- // size reported in KB.
- info_p->cache_size[type] = cpuid_c_size * 1024;
- info_p->cache_sharing[type] = 1;
- info_p->cache_partitions[type] = cpuid_c_partitions;
- linesizes[type] = cpuid_c_linesize;
- uint32_t cache_sets = info_p->cache_size[type] / (cpuid_c_partitions * cpuid_c_linesize * cache_associativity);
- colors = ( cpuid_c_linesize * cache_sets ) >> 12;
- if ( colors > vm_cache_geometry_colors )
- vm_cache_geometry_colors = colors;
- // use for cache size etc.
- info_p->cpuid_cache_L2_associativity = cache_associativity;
- info_p->cpuid_cache_size = info_p->cache_size[type];
- info_p->cache_linesize = cpuid_c_linesize;
- }
- /* L3 Unified */
- {
- type = L3U;
- cpuid_fn(0x80000006, reg);
- uint32_t cpuid_c_linesize = bitfield32(reg[edx], 7, 0);
- uint32_t cpuid_c_partitions = bitfield32(reg[edx], 11, 8);
- uint32_t cpuid_c_associativity = bitfield32(reg[edx], 15, 12);
- uint32_t cpuid_c_size = bitfield32(reg[edx], 31, 18);
- // Special formula for associativity: 2^(assoc / 2)
- uint32_t cache_associativity = 1ul << (cpuid_c_associativity / 2);
- if(cpuid_c_size == 0) {
- // no L3
- info_p->cache_size[type] = 0;
- info_p->cache_sharing[type] = 0;
- info_p->cache_partitions[type] = 0;
- } else {
- // size reported in 512 KB packs.
- info_p->cache_size[type] = cpuid_c_size * 1024;
- info_p->cache_sharing[type] = 1;
- info_p->cache_partitions[type] = cpuid_c_partitions;
- linesizes[type] = cpuid_c_linesize;
- uint32_t cache_sets = info_p->cache_size[type] / (cpuid_c_partitions * cpuid_c_linesize * cache_associativity);
- colors = ( cpuid_c_linesize * cache_sets ) >> 12;
- if ( colors > vm_cache_geometry_colors )
- vm_cache_geometry_colors = colors;
- }
- }
- }
- -------------------------------------------
复制代码
找尋 wrmsr64(MSR_IA32_BIOS_SIGN_ID, 0)
下面
info_p->cpuid_features = quad(reg[ecx], reg[edx]);
改為
- info_p->cpuid_features = quad(reg[ecx], reg[edx]) & ~CPUID_FEATURE_PAT;
复制代码
info_p->cpuid_processor_flag = (rdmsr64(MSR_IA32_PLATFORM_ID)>> 50) & 0x7;
改為
- info_p->cpuid_processor_flag = 0;
复制代码
找尋 info_p->cpuid_cpufamily = cpufamily;
- info_p->cpuid_cpufamily = cpufamily;
- DBG("cpuid_set_cpufamily(%p) returning 0x%x\n", info_p, cpufamily);
- -----插入程式碼----------------------------
- /* AnV - Fix AMD CPU Family to Intel Penryn */
- /** This is needed to boot because the dyld assumes that an UNKNOWN
- ** Platform is HASWELL-capable, dropping an SSE4.2 'pcmpistri' on us during bcopies.
- **/
- if (IsAmdCPU())
- {
- cpufamily = CPUFAMILY_INTEL_PENRYN;
- info_p->cpuid_cpufamily = cpufamily;
- }
- -------------------------------------------
- return cpufamily;
复制代码
找尋 cpuid_set_info(void)
- cpuid_set_info(void)
- {
- i386_cpu_info_t *info_p = &cpuid_cpu_info;
- cpuid_set_generic_info(info_p);
- /* verify we are running on a supported CPU */
- if ((strncmp(CPUID_VID_INTEL, info_p->cpuid_vendor,
- min(strlen(CPUID_STRING_UNKNOWN) + 1,
- sizeof(info_p->cpuid_vendor)))) ||
- (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
- panic("Unsupported CPU");
- info_p->cpuid_cpu_type = CPU_TYPE_X86;
- info_p->cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
- /* Must be invoked after set_generic_info */
- cpuid_set_cache_info(info_p);
复制代码
改為
- cpuid_set_info(void)
- {
- i386_cpu_info_t *info_p = &cpuid_cpu_info;
- cpuid_set_generic_info(info_p);
- /* verify we are running on a supported CPU */
- /*if ((strncmp(CPUID_VID_INTEL, info_p->cpuid_vendor,
- min(strlen(CPUID_STRING_UNKNOWN) + 1,
- sizeof(info_p->cpuid_vendor)))) ||
- (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
- panic("Unsupported CPU");*/
- cpuid_set_cpufamily(info_p);
- info_p->cpuid_cpu_type = CPU_TYPE_X86;
- info_p->cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
- /* Must be invoked after set_generic_info */
- /* check if running on AMD, call right cache info function */
- if(!strncmp(CPUID_VID_AMD, info_p->cpuid_vendor,
- min(strlen(CPUID_STRING_UNKNOWN) + 1,
- sizeof(info_p->cpuid_vendor)))) {
- cpuid_set_AMDcache_info(info_p);
- } else cpuid_set_cache_info(info_p);
复制代码
/xnu-2422.1.72/osfmk/i386/cpuid.h
找尋 #define CPUID_MODEL_HASWELL_ULT
- #define CPUID_MODEL_HASWELL_ULT 0x45
- -----插入程式碼----------------------------
- /* kaitek: the following definitions are needed by tsc.c and kern_mib.c */
- #define CPU_FAMILY_PENTIUM_M (0x6)
- #define CPU_FAMILY_PENTIUM_4 (0xF)
- #define CPU_FAMILY_AMD_PHENOM (0x10)
- #define CPU_FAMILY_AMD_SHANGHAI (0x11)
- #define CPU_FAMILY_I5 (0x1E)
- #define CPU_FAMILY_I9 (0x2C)
- #define CPU_FAMILY_SANDY (0x2A)
- -------------------------------------------
复制代码
找尋 i386_vmm_info_t;
- } i386_vmm_info_t;
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- -----插入程式碼----------------------------
- extern boolean_t IsAmdCPU(void);
- extern boolean_t IsIntelCPU(void);
- -------------------------------------------
复制代码
/xnu-2422.1.72/osfmk/i386/lapic_native.c
找尋 if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK)
- if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x14) {
- panic("Local APIC version 0x%x, 0x14 or more expected\n",
复制代码
將 0x14 改為 0x10
- if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x10) {
- panic("Local APIC version 0x%x, 0x10 or more expected\n",
复制代码
待續.....
|
-
5
查看全部评分
-
|