LCOV - code coverage report
Current view: directory - src/trusted/validator/x86/decoder - ncopcode_desc.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 55 53 96.4 %
Date: 2014-06-18 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2011 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                 : /* Descriptors to model instructions, opcodes, and instruction operands. */
       8                 : 
       9                 : #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc.h"
      10                 : 
      11                 : #include <assert.h>
      12                 : #include <string.h>
      13                 : 
      14                 : #include "native_client/src/shared/utils/types.h"
      15                 : #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_prefix_impl.h"
      16                 : #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_insts_impl.h"
      17                 : #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_opcode_flags_impl.h"
      18                 : #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_operand_kind_impl.h"
      19                 : #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_operand_flag_impl.h"
      20                 : #include "native_client/src/trusted/validator/x86/decoder/nc_decode_tables.h"
      21                 : 
      22                 : #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc_inl.c"
      23                 : 
      24            4742 : uint8_t NaClGetOpcodeInModRm(uint8_t opcode_ext) {
      25            4742 :   return opcode_ext & 0x0F;
      26                 : }
      27                 : 
      28             270 : uint8_t NaClGetOpcodeInModRmRm(uint8_t opcode_ext) {
      29             270 :   return (opcode_ext >> 4) & 0x0F;
      30                 : }
      31                 : 
      32             283 : uint8_t NaClGetOpcodePlusR(uint8_t opcode_ext) {
      33             283 :   return opcode_ext & 0x0F;
      34                 : }
      35                 : 
      36               0 : uint8_t NaClGetInstNumberOperands(const NaClInst* inst) {
      37               0 :   return NaClGetInstNumberOperandsInline(inst);
      38                 : }
      39                 : 
      40             981 : const NaClOp* NaClGetInstOperand(const NaClDecodeTables* tables,
      41             981 :                                  const NaClInst* inst, uint8_t index) {
      42             981 :   return NaClGetInstOperandInline(tables, inst, index);
      43                 : }
      44                 : 
      45                 : /* Print out the opcode operand flags in a simplified (i.e. more human readable)
      46                 :  * form.
      47                 :  */
      48            4636 : void NaClOpFlagsPrint(struct Gio* f, NaClOpFlags flags) {
      49            4636 :   NaClOpFlag i;
      50            4636 :   Bool first = TRUE;
      51          101992 :   for (i = 0; i < NaClOpFlagEnumSize; ++i) {
      52           46360 :     if (flags & NACL_OPFLAG(i)) {
      53            6747 :       if (first) {
      54            4636 :         first = FALSE;
      55            4636 :       } else {
      56            2111 :         gprintf(f, " ");
      57                 :       }
      58            6747 :       gprintf(f, "%s", NaClOpFlagName(i));
      59            6747 :     }
      60           46360 :   }
      61            4636 : }
      62                 : 
      63                 : /* Print out the opcode operand in a simplified (i.e. more human readable)
      64                 :  * form.
      65                 :  */
      66            4687 : void NaClOpPrint(struct Gio* f, const NaClOp* operand) {
      67            4687 :   gprintf(f, "%s", NaClOpKindName(operand->kind));
      68            4687 :   if (operand->flags) {
      69            4636 :     size_t i;
      70          146166 :     for (i = strlen(NaClOpKindName(operand->kind)); i < 24; ++i) {
      71           68447 :       gprintf(f, " ");
      72           68447 :     }
      73            4636 :     NaClOpFlagsPrint(f, operand->flags);
      74            4636 :   }
      75            4687 :   gprintf(f, "\n");
      76            4687 : }
      77                 : 
      78                 : /* Print instruction flags using a simplified (i.e. more human readable) form */
      79            4668 : void NaClIFlagsPrint(struct Gio* f, NaClIFlags flags) {
      80            4668 :   int i;
      81            4668 :   Bool first = TRUE;
      82          457464 :   for (i = 0; i < NaClIFlagEnumSize; ++i) {
      83          224064 :     if (flags & NACL_IFLAG(i)) {
      84           13807 :       if (first) {
      85            4668 :         first = FALSE;
      86            4668 :       } else {
      87            9139 :         gprintf(f, " ");
      88                 :       }
      89           13807 :       gprintf(f, "%s", NaClIFlagName(i));
      90           13807 :     }
      91          224064 :   }
      92            4668 : }
      93                 : 
      94                 : /* Returns a string defining bytes of the given prefix that are considered
      95                 :  * prefix bytes, independent of the opcode.
      96                 :  */
      97            7706 : const char* OpcodePrefixBytes(NaClInstPrefix prefix) {
      98           10886 :   switch(prefix) {
      99                 :     case NoPrefix:
     100                 :     case Prefix0F:
     101                 :     case Prefix0F0F:
     102                 :     case Prefix0F38:
     103                 :     case Prefix0F3A:
     104                 :     case PrefixD8:
     105                 :     case PrefixD9:
     106                 :     case PrefixDA:
     107                 :     case PrefixDB:
     108                 :     case PrefixDC:
     109                 :     case PrefixDD:
     110                 :     case PrefixDE:
     111                 :     case PrefixDF:
     112                 :     default:  /* This shouldn't happen, but be safe. */
     113            3180 :       return "";
     114                 :     case PrefixF20F:
     115                 :     case PrefixF20F38:
     116             256 :       return "f2";
     117                 :     case PrefixF30F:
     118             250 :       return "f3";
     119                 :     case Prefix660F:
     120                 :     case Prefix660F38:
     121                 :     case Prefix660F3A:
     122             840 :       return "66";
     123                 :   }
     124            4526 : }

Generated by: LCOV version 1.7