3333#include <linux/backlight.h>
3434#include <linux/bug.h>
3535#include <linux/kdebug.h>
36+ #include <linux/debugfs.h>
3637
38+ #include <asm/emulated_ops.h>
3739#include <asm/pgtable.h>
3840#include <asm/uaccess.h>
3941#include <asm/system.h>
@@ -757,36 +759,44 @@ static int emulate_instruction(struct pt_regs *regs)
757759
758760 /* Emulate the mfspr rD, PVR. */
759761 if ((instword & PPC_INST_MFSPR_PVR_MASK ) == PPC_INST_MFSPR_PVR ) {
762+ PPC_WARN_EMULATED (mfpvr );
760763 rd = (instword >> 21 ) & 0x1f ;
761764 regs -> gpr [rd ] = mfspr (SPRN_PVR );
762765 return 0 ;
763766 }
764767
765768 /* Emulating the dcba insn is just a no-op. */
766- if ((instword & PPC_INST_DCBA_MASK ) == PPC_INST_DCBA )
769+ if ((instword & PPC_INST_DCBA_MASK ) == PPC_INST_DCBA ) {
770+ PPC_WARN_EMULATED (dcba );
767771 return 0 ;
772+ }
768773
769774 /* Emulate the mcrxr insn. */
770775 if ((instword & PPC_INST_MCRXR_MASK ) == PPC_INST_MCRXR ) {
771776 int shift = (instword >> 21 ) & 0x1c ;
772777 unsigned long msk = 0xf0000000UL >> shift ;
773778
779+ PPC_WARN_EMULATED (mcrxr );
774780 regs -> ccr = (regs -> ccr & ~msk ) | ((regs -> xer >> shift ) & msk );
775781 regs -> xer &= ~0xf0000000UL ;
776782 return 0 ;
777783 }
778784
779785 /* Emulate load/store string insn. */
780- if ((instword & PPC_INST_STRING_GEN_MASK ) == PPC_INST_STRING )
786+ if ((instword & PPC_INST_STRING_GEN_MASK ) == PPC_INST_STRING ) {
787+ PPC_WARN_EMULATED (string );
781788 return emulate_string_inst (regs , instword );
789+ }
782790
783791 /* Emulate the popcntb (Population Count Bytes) instruction. */
784792 if ((instword & PPC_INST_POPCNTB_MASK ) == PPC_INST_POPCNTB ) {
793+ PPC_WARN_EMULATED (popcntb );
785794 return emulate_popcntb_inst (regs , instword );
786795 }
787796
788797 /* Emulate isel (Integer Select) instruction */
789798 if ((instword & PPC_INST_ISEL_MASK ) == PPC_INST_ISEL ) {
799+ PPC_WARN_EMULATED (isel );
790800 return emulate_isel (regs , instword );
791801 }
792802
@@ -984,6 +994,8 @@ void SoftwareEmulation(struct pt_regs *regs)
984994
985995#ifdef CONFIG_MATH_EMULATION
986996 errcode = do_mathemu (regs );
997+ if (errcode >= 0 )
998+ PPC_WARN_EMULATED (math );
987999
9881000 switch (errcode ) {
9891001 case 0 :
@@ -1005,6 +1017,9 @@ void SoftwareEmulation(struct pt_regs *regs)
10051017
10061018#elif defined(CONFIG_8XX_MINIMAL_FPEMU )
10071019 errcode = Soft_emulate_8xx (regs );
1020+ if (errcode >= 0 )
1021+ PPC_WARN_EMULATED (8 xx );
1022+
10081023 switch (errcode ) {
10091024 case 0 :
10101025 emulate_single_step (regs );
@@ -1088,6 +1103,7 @@ void altivec_assist_exception(struct pt_regs *regs)
10881103
10891104 flush_altivec_to_thread (current );
10901105
1106+ PPC_WARN_EMULATED (altivec );
10911107 err = emulate_altivec (regs );
10921108 if (err == 0 ) {
10931109 regs -> nip += 4 ; /* skip emulated instruction */
@@ -1286,3 +1302,79 @@ void kernel_bad_stack(struct pt_regs *regs)
12861302void __init trap_init (void )
12871303{
12881304}
1305+
1306+
1307+ #ifdef CONFIG_PPC_EMULATED_STATS
1308+
1309+ #define WARN_EMULATED_SETUP (type ) .type = { .name = #type }
1310+
1311+ struct ppc_emulated ppc_emulated = {
1312+ #ifdef CONFIG_ALTIVEC
1313+ WARN_EMULATED_SETUP (altivec ),
1314+ #endif
1315+ WARN_EMULATED_SETUP (dcba ),
1316+ WARN_EMULATED_SETUP (dcbz ),
1317+ WARN_EMULATED_SETUP (fp_pair ),
1318+ WARN_EMULATED_SETUP (isel ),
1319+ WARN_EMULATED_SETUP (mcrxr ),
1320+ WARN_EMULATED_SETUP (mfpvr ),
1321+ WARN_EMULATED_SETUP (multiple ),
1322+ WARN_EMULATED_SETUP (popcntb ),
1323+ WARN_EMULATED_SETUP (spe ),
1324+ WARN_EMULATED_SETUP (string ),
1325+ WARN_EMULATED_SETUP (unaligned ),
1326+ #ifdef CONFIG_MATH_EMULATION
1327+ WARN_EMULATED_SETUP (math ),
1328+ #elif defined(CONFIG_8XX_MINIMAL_FPEMU )
1329+ WARN_EMULATED_SETUP (8 xx ),
1330+ #endif
1331+ #ifdef CONFIG_VSX
1332+ WARN_EMULATED_SETUP (vsx ),
1333+ #endif
1334+ };
1335+
1336+ u32 ppc_warn_emulated ;
1337+
1338+ void ppc_warn_emulated_print (const char * type )
1339+ {
1340+ if (printk_ratelimit ())
1341+ pr_warning ("%s used emulated %s instruction\n" , current -> comm ,
1342+ type );
1343+ }
1344+
1345+ static int __init ppc_warn_emulated_init (void )
1346+ {
1347+ struct dentry * dir , * d ;
1348+ unsigned int i ;
1349+ struct ppc_emulated_entry * entries = (void * )& ppc_emulated ;
1350+
1351+ if (!powerpc_debugfs_root )
1352+ return - ENODEV ;
1353+
1354+ dir = debugfs_create_dir ("emulated_instructions" ,
1355+ powerpc_debugfs_root );
1356+ if (!dir )
1357+ return - ENOMEM ;
1358+
1359+ d = debugfs_create_u32 ("do_warn" , S_IRUGO | S_IWUSR , dir ,
1360+ & ppc_warn_emulated );
1361+ if (!d )
1362+ goto fail ;
1363+
1364+ for (i = 0 ; i < sizeof (ppc_emulated )/sizeof (* entries ); i ++ ) {
1365+ d = debugfs_create_u32 (entries [i ].name , S_IRUGO | S_IWUSR , dir ,
1366+ (u32 * )& entries [i ].val .counter );
1367+ if (!d )
1368+ goto fail ;
1369+ }
1370+
1371+ return 0 ;
1372+
1373+ fail :
1374+ debugfs_remove_recursive (dir );
1375+ return - ENOMEM ;
1376+ }
1377+
1378+ device_initcall (ppc_warn_emulated_init );
1379+
1380+ #endif /* CONFIG_PPC_EMULATED_STATS */
0 commit comments