projg2 / cpuid2cpuflags

Tool to generate CPU_FLAGS_* for your CPU
GNU General Public License v2.0
108 stars 20 forks source link

ppc support #2

Closed ghost closed 6 years ago

ghost commented 8 years ago

Hi,

I checked this issue out and apparently the way grepwood implemented it is the easiest.

The only thing analogous to x86's cpuid instruction on PowerPC is copying the value of the Processor Version Register. This special register is read-only and it is restricted to supervisors only. Some kernels like Linux and FreeBSD do the smart thing and trap its value in memory and expose it for userspace applications to have a look at. That makes reading /proc/self/auxv fair enough a method. The PVR is a 32bit register and its first half contains the version, the other revision. More info: http://www.cebix.net/downloads/bebox/pem32b.pdf pages 78-79

Example: the PVR on Cell Broadband Engine is 0x 0070 0501. From arch/powerpc/kernel/cputable.c:

        {       /* Cell Broadband Engine */
                .pvr_mask               = 0xffff0000,
                .pvr_value              = 0x00700000,
                .cpu_name               = "Cell Broadband Engine",
                .cpu_features           = CPU_FTRS_CELL,
                .cpu_user_features      = COMMON_USER_PPC64 |
                        PPC_FEATURE_CELL | PPC_FEATURE_HAS_ALTIVEC_COMP |
                        PPC_FEATURE_SMT,
                .mmu_features           = MMU_FTRS_CELL,
                .icache_bsize           = 128,
                .dcache_bsize           = 128,
                .num_pmcs               = 4,
                .pmc_type               = PPC_PMC_IBM,
                .oprofile_cpu_type      = "ppc64/cell-be",
                .oprofile_type          = PPC_OPROFILE_CELL,
                .platform               = "ppc-cell-be",

We can see that version clearly matches 0x0070. Checking for PPC_FEATURE_HAS_ALTIVEC is legit, because of $(grep PPC_FEATURE_HAS_ALTIVEC arch/powerpc) in the kernel source tree. These 2 macros are always equal.

mgorny commented 7 years ago

I'm sorry but I'm currently not expanding support for architectures that do not have CPUFLAGS*. The support for PPC is planned eventually but it strongly relies on some Gentoo developer (or possibly user) taking the effort to design CPU_FLAGS_PPC, i.e. find all relevant flags used in Gentoo, collect and describe them, prepare profile updates.