LCOV - code coverage report
Current view: directory - src/trusted/cpu_features/arch/x86 - cpu_x86.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 3 3 100.0 %
Date: 2014-06-18 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : /*
       8                 :  * This module provides a simple abstraction for using the CPUID
       9                 :  * instruction to determine instruction set extensions supported by
      10                 :  * the current processor.
      11                 :  */
      12                 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_CPU_FEATURES_ARCH_X86_CPU_X86_H_
      13                 : #define NATIVE_CLIENT_SRC_TRUSTED_CPU_FEATURES_ARCH_X86_CPU_X86_H_
      14                 : 
      15                 : #include "native_client/src/include/nacl_macros.h"
      16                 : #include "native_client/src/include/portability.h"
      17                 : #include "native_client/src/trusted/validator/ncvalidate.h"
      18                 : 
      19                 : 
      20                 : EXTERN_C_BEGIN
      21                 : 
      22                 : /* List of features supported by x86 CPUs. */
      23                 : typedef enum {
      24                 : #define NACL_X86_CPU_FEATURE(id, reg, idx, fix, ven, str)       \
      25                 :   NACL_CONCAT(NaClCPUFeatureX86_, id),
      26                 : #include "native_client/src/trusted/cpu_features/arch/x86/cpu_x86_features.h"
      27                 : #undef NACL_X86_CPU_FEATURE
      28                 :   /* Leave the following as the last entry. */
      29                 :   NaClCPUFeatureX86_Max
      30                 : } NaClCPUFeatureX86ID;
      31                 : 
      32                 : /* Features we can get about the x86 hardware. */
      33                 : typedef struct cpu_feature_struct_X86 {
      34                 :   char data[NaClCPUFeatureX86_Max];
      35                 : } NaClCPUFeaturesX86;
      36                 : 
      37                 : /* Define the maximum length of a CPUID string.
      38                 :  *
      39                 :  * Note: If you change this length, fix the static initialization of wlid
      40                 :  * in cpu_x86.c to be initialized with an appropriate string.
      41                 :  */
      42                 : #define /* static const int */ kCPUIDStringLength 21
      43                 : 
      44                 : /* Defines the maximum number of feature registers used to hold CPUID.
      45                 :  * Note: This value corresponds to the number of enumerated elements in
      46                 :  * enum CPUFeatureReg defined in cpu_x86.c.
      47                 :  */
      48                 : #define kMaxCPUFeatureReg 12
      49                 : 
      50                 : /* Defines the maximum number of extended control registers.
      51                 :  */
      52                 : #define kMaxCPUXCRReg 1
      53                 : 
      54                 : /* Define a cache for collected CPU runtime information, from which
      55                 :  * queries can answer questions.
      56                 :  */
      57                 : typedef struct NaClCPUData {
      58                 :   /* The following is used to cache whether CPUID is defined for the
      59                 :    * architecture the code is running on.
      60                 :    */
      61                 :   int _has_CPUID;
      62                 :   /* Version ID words used by CPUVersionID. */
      63                 :   uint32_t _vidwords[4];
      64                 :   /* Define the set of CPUID feature register values for the architecture.
      65                 :    * Note: We have two sets (of 4 registers) so that AMD specific flags can be
      66                 :    * picked up.
      67                 :    */
      68                 :   uint32_t _featurev[kMaxCPUFeatureReg];
      69                 :   /* Define the set of extended control register (XCR) values.
      70                 :    */
      71                 :   uint64_t _xcrv[kMaxCPUXCRReg];
      72                 :   /* Define a string to hold and cache the CPUID. In such cases, such races
      73                 :    * will at worst cause the CPUID to not be recognized.
      74                 :    */
      75                 :   char _wlid[kCPUIDStringLength];
      76                 : } NaClCPUData;
      77                 : 
      78                 : /* Collect CPU data about this CPU, and put into the given data structure.
      79                 :  */
      80                 : void NaClCPUDataGet(NaClCPUData* data);
      81                 : 
      82                 : /* GetCPUIDString creates an ASCII string that identifies this CPU's
      83                 :  * vendor ID, family, model, and stepping, as per the CPUID instruction
      84                 :  */
      85                 : char *GetCPUIDString(NaClCPUData* data);
      86                 : 
      87                 : /*
      88                 :  * Platform-independent NaClValidatorInterface functions.
      89                 :  */
      90                 : void NaClSetAllCPUFeaturesX86(NaClCPUFeatures *features);
      91                 : void NaClGetCurrentCPUFeaturesX86(NaClCPUFeatures *cpu_features);
      92                 : int NaClFixCPUFeaturesX86(NaClCPUFeatures *cpu_features);
      93                 : 
      94                 : /*
      95                 :  * Platform-dependent getter/setter.
      96                 :  */
      97            4184 : static INLINE int NaClGetCPUFeatureX86(const NaClCPUFeaturesX86 *features,
      98            4184 :                                        NaClCPUFeatureX86ID id) {
      99            4184 :   return features->data[id];
     100                 : }
     101                 : 
     102                 : void NaClSetCPUFeatureX86(NaClCPUFeaturesX86 *features, NaClCPUFeatureX86ID id,
     103                 :                           int state);
     104                 : const char *NaClGetCPUFeatureX86Name(NaClCPUFeatureX86ID id);
     105                 : 
     106                 : /*
     107                 :  * Platform-independent functions which are only used in platform-dependent
     108                 :  * code.
     109                 :  * TODO(jfb) The ARM and MIPS CPU feature do not offer NaClCopyCPUFeaturesX86
     110                 :  * and NaClArchSupportedX86, should they be removed?
     111                 :  */
     112                 : void NaClClearCPUFeaturesX86(NaClCPUFeaturesX86 *features);
     113                 : void NaClCopyCPUFeaturesX86(NaClCPUFeaturesX86 *target,
     114                 :                             const NaClCPUFeaturesX86 *source);
     115                 : int NaClArchSupportedX86(const NaClCPUFeaturesX86 *features);
     116                 : 
     117                 : EXTERN_C_END
     118                 : 
     119                 : #endif /* NATIVE_CLIENT_SRC_TRUSTED_CPU_FEATURES_ARCH_X86_CPU_X86_H_ */

Generated by: LCOV version 1.7