LCOV - code coverage report
Current view: top level - libcpu - bpf_disasm.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 354 373 94.9 %
Date: 2024-04-17 19:42:11 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 108 116 93.1 %

           Branch data     Line data    Source code
       1                 :            : /* Disassembler for BPF.
       2                 :            :    Copyright (C) 2016, 2018 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            : 
       5                 :            :    This file is free software; you can redistribute it and/or modify
       6                 :            :    it under the terms of either
       7                 :            : 
       8                 :            :      * the GNU Lesser General Public License as published by the Free
       9                 :            :        Software Foundation; either version 3 of the License, or (at
      10                 :            :        your option) any later version
      11                 :            : 
      12                 :            :    or
      13                 :            : 
      14                 :            :      * the GNU General Public License as published by the Free
      15                 :            :        Software Foundation; either version 2 of the License, or (at
      16                 :            :        your option) any later version
      17                 :            : 
      18                 :            :    or both in parallel, as here.
      19                 :            : 
      20                 :            :    elfutils is distributed in the hope that it will be useful, but
      21                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      22                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      23                 :            :    General Public License for more details.
      24                 :            : 
      25                 :            :    You should have received copies of the GNU General Public License and
      26                 :            :    the GNU Lesser General Public License along with this program.  If
      27                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      28                 :            : 
      29                 :            : #ifdef HAVE_CONFIG_H
      30                 :            : # include <config.h>
      31                 :            : #endif
      32                 :            : 
      33                 :            : #include <assert.h>
      34                 :            : #include <string.h>
      35                 :            : #include <stdio.h>
      36                 :            : #include <gelf.h>
      37                 :            : #include <inttypes.h>
      38                 :            : #include "bpf.h"
      39                 :            : 
      40                 :            : #include "common.h"
      41                 :            : #include "libeblP.h"
      42                 :            : 
      43                 :            : static const char class_string[8][8] = {
      44                 :            :   [BPF_LD]    = "ld",
      45                 :            :   [BPF_LDX]   = "ldx",
      46                 :            :   [BPF_ST]    = "st",
      47                 :            :   [BPF_STX]   = "stx",
      48                 :            :   [BPF_ALU]   = "alu",
      49                 :            :   [BPF_JMP]   = "jmp",
      50                 :            :   [BPF_RET]   = "6",          /* completely unused in ebpf */
      51                 :            :   [BPF_ALU64] = "alu64",
      52                 :            : };
      53                 :            : 
      54                 :            : 
      55                 :            : #define REG(N)          "r%" #N "$d"
      56                 :            : #define REGU(N)         "(u32)" REG(N)
      57                 :            : #define REGS(N)         "(s64)" REG(N)
      58                 :            : 
      59                 :            : #define IMMS(N)         "%" #N "$d"
      60                 :            : #define IMMX(N)         "%" #N "$#x"
      61                 :            : 
      62                 :            : #define OFF(N)          "%" #N "$+d"
      63                 :            : #define JMP(N)          "%" #N "$#x"
      64                 :            : 
      65                 :            : #define A32(O, S)       REG(1) " = " REGU(1) " " #O " " S
      66                 :            : #define A64(O, S)       REG(1) " " #O "= " S
      67                 :            : #define J64(D, O, S)    "if " D " " #O " " S " goto " JMP(3)
      68                 :            : #define LOAD(T)         REG(1) " = *(" #T " *)(" REG(2) OFF(3) ")"
      69                 :            : #define STORE(T, S)     "*(" #T " *)(" REG(1) OFF(3) ") = " S
      70                 :            : #define XADD(T, S)      "lock *(" #T " *)(" REG(1) OFF(3) ") += " S
      71                 :            : #define LDSKB(T, S)     "r0 = *(" #T " *)skb[" S "]"
      72                 :            : 
      73                 :            : static void
      74                 :          0 : bswap_bpf_insn (struct bpf_insn *p)
      75                 :            : {
      76                 :            :   /* Note that the dst_reg and src_reg fields are 4-bit bitfields.
      77                 :            :      That means these two nibbles are (typically) laid out in the
      78                 :            :      opposite order between big- and little-endian hosts.  This is
      79                 :            :      not required by any standard, but does happen to be true for
      80                 :            :      at least ppc, s390, arm and mips as big-endian hosts.  */
      81                 :          0 :   int t = p->dst_reg;
      82                 :          0 :   p->dst_reg = p->src_reg;
      83                 :          0 :   p->src_reg = t;
      84                 :            : 
      85                 :            :   /* The other 2 and 4 byte fields are trivially converted.  */
      86                 :          0 :   CONVERT (p->off);
      87                 :          0 :   CONVERT (p->imm);
      88                 :          0 : }
      89                 :            : 
      90                 :            : int
      91                 :          2 : bpf_disasm (Ebl *ebl, const uint8_t **startp, const uint8_t *end,
      92                 :            :             GElf_Addr addr, const char *fmt __attribute__((unused)),
      93                 :            :             DisasmOutputCB_t outcb,
      94                 :            :             DisasmGetSymCB_t symcb __attribute__((unused)),
      95                 :            :             void *outcbarg,
      96                 :            :             void *symcbarg __attribute__((unused)))
      97                 :            : {
      98                 :          2 :   const bool need_bswap = MY_ELFDATA != ebl->data;
      99                 :          2 :   const uint8_t *start = *startp;
     100                 :          2 :   char buf[128];
     101                 :          2 :   int len, retval = 0;
     102                 :            : 
     103         [ +  + ]:        514 :   while (start + sizeof(struct bpf_insn) <= end)
     104                 :            :     {
     105                 :        512 :       struct bpf_insn i;
     106                 :        512 :       unsigned code, class, jmp;
     107                 :        512 :       const char *code_fmt;
     108                 :            : 
     109         [ -  + ]:        512 :       memcpy(&i, start, sizeof(struct bpf_insn));
     110         [ -  + ]:        512 :       if (need_bswap)
     111                 :          0 :         bswap_bpf_insn (&i);
     112                 :            : 
     113                 :        512 :       start += sizeof(struct bpf_insn);
     114                 :        512 :       addr += sizeof(struct bpf_insn);
     115                 :        512 :       jmp = addr + i.off * sizeof(struct bpf_insn);
     116                 :            : 
     117                 :        512 :       code = i.code;
     118   [ +  +  +  +  :        512 :       switch (code)
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  +  
                      + ]
     119                 :            :         {
     120                 :          2 :         case BPF_LD | BPF_IMM | BPF_DW:
     121                 :            :           {
     122                 :          2 :             struct bpf_insn i2;
     123                 :          2 :             uint64_t imm64;
     124                 :            : 
     125         [ -  + ]:          2 :             if (start + sizeof(struct bpf_insn) > end)
     126                 :            :               {
     127                 :          0 :                 start -= sizeof(struct bpf_insn);
     128                 :          0 :                 *startp = start;
     129                 :          0 :                 goto done;
     130                 :            :               }
     131         [ -  + ]:          2 :             memcpy(&i2, start, sizeof(struct bpf_insn));
     132         [ -  + ]:          2 :             if (need_bswap)
     133                 :          0 :               bswap_bpf_insn (&i2);
     134                 :          2 :             start += sizeof(struct bpf_insn);
     135                 :          2 :             addr += sizeof(struct bpf_insn);
     136                 :            : 
     137                 :          2 :             imm64 = (uint32_t)i.imm | ((uint64_t)i2.imm << 32);
     138      [ -  -  + ]:          2 :             switch (i.src_reg)
     139                 :            :               {
     140                 :            :               case 0:
     141                 :            :                 code_fmt = REG(1) " = %2$#" PRIx64;
     142                 :            :                 break;
     143                 :          0 :               case BPF_PSEUDO_MAP_FD:
     144                 :          0 :                 code_fmt = REG(1) " = map_fd(%2$#" PRIx64 ")";
     145                 :          0 :                 break;
     146                 :          0 :               default:
     147                 :          0 :                 code_fmt = REG(1) " = ld_pseudo(%3$d, %2$#" PRIx64 ")";
     148                 :          0 :                 break;
     149                 :            :               }
     150                 :          2 :             len = snprintf(buf, sizeof(buf), code_fmt,
     151                 :          2 :                            i.dst_reg, imm64, i.src_reg);
     152                 :            :           }
     153                 :          2 :           break;
     154                 :            : 
     155                 :            :         case BPF_JMP | BPF_EXIT:
     156                 :          2 :           len = snprintf(buf, sizeof(buf), "exit");
     157                 :          2 :           break;
     158                 :            :         case BPF_JMP | BPF_JA:
     159                 :          2 :           len = snprintf(buf, sizeof(buf), "goto " JMP(1), jmp);
     160                 :          2 :           break;
     161                 :          2 :         case BPF_JMP | BPF_CALL:
     162                 :          2 :           code_fmt = "call " IMMS(1);
     163                 :          2 :           goto do_imm;
     164                 :            : 
     165                 :          2 :         case BPF_ALU | BPF_END | BPF_TO_LE:
     166                 :            :           /* The imm field contains {16,32,64}.  */
     167                 :          2 :           code_fmt = REG(1) " = le" IMMS(2) "(" REG(1) ")";
     168                 :          2 :           goto do_dst_imm;
     169                 :          2 :         case BPF_ALU | BPF_END | BPF_TO_BE:
     170                 :          2 :           code_fmt = REG(1) " = be" IMMS(2) "(" REG(1) ")";
     171                 :          2 :           goto do_dst_imm;
     172                 :            : 
     173                 :          2 :         case BPF_ALU | BPF_ADD | BPF_K:
     174                 :          2 :           code_fmt = A32(+, IMMS(2));
     175                 :          2 :           goto do_dst_imm;
     176                 :          2 :         case BPF_ALU | BPF_SUB | BPF_K:
     177                 :          2 :           code_fmt = A32(-, IMMS(2));
     178                 :          2 :           goto do_dst_imm;
     179                 :          2 :         case BPF_ALU | BPF_MUL | BPF_K:
     180                 :          2 :           code_fmt = A32(*, IMMS(2));
     181                 :          2 :           goto do_dst_imm;
     182                 :          2 :         case BPF_ALU | BPF_DIV | BPF_K:
     183                 :          2 :           code_fmt = A32(/, IMMS(2));
     184                 :          2 :           goto do_dst_imm;
     185                 :          2 :         case BPF_ALU | BPF_OR | BPF_K:
     186                 :          2 :           code_fmt = A32(|, IMMX(2));
     187                 :          2 :           goto do_dst_imm;
     188                 :          2 :         case BPF_ALU | BPF_AND | BPF_K:
     189                 :          2 :           code_fmt = A32(&, IMMX(2));
     190                 :          2 :           goto do_dst_imm;
     191                 :          2 :         case BPF_ALU | BPF_LSH | BPF_K:
     192                 :          2 :           code_fmt = A32(<<, IMMS(2));
     193                 :          2 :           goto do_dst_imm;
     194                 :          2 :         case BPF_ALU | BPF_RSH | BPF_K:
     195                 :          2 :           code_fmt = A32(>>, IMMS(2));
     196                 :          2 :           goto do_dst_imm;
     197                 :          2 :         case BPF_ALU | BPF_MOD | BPF_K:
     198                 :          2 :           code_fmt = A32(%%, IMMS(2));
     199                 :          2 :           goto do_dst_imm;
     200                 :          2 :         case BPF_ALU | BPF_XOR | BPF_K:
     201                 :          2 :           code_fmt = A32(^, IMMX(2));
     202                 :          2 :           goto do_dst_imm;
     203                 :          2 :         case BPF_ALU | BPF_MOV | BPF_K:
     204                 :          2 :           code_fmt = REG(1) " = " IMMX(2);
     205                 :          2 :           goto do_dst_imm;
     206                 :          2 :         case BPF_ALU | BPF_ARSH | BPF_K:
     207                 :          2 :           code_fmt = REG(1) " = (u32)((s32)" REG(1) " >> " IMMS(2) ")";
     208                 :          2 :           goto do_dst_imm;
     209                 :            : 
     210                 :          2 :         case BPF_ALU | BPF_ADD | BPF_X:
     211                 :          2 :           code_fmt = A32(+, REGU(2));
     212                 :          2 :           goto do_dst_src;
     213                 :          2 :         case BPF_ALU | BPF_SUB | BPF_X:
     214                 :          2 :           code_fmt = A32(-, REGU(2));
     215                 :          2 :           goto do_dst_src;
     216                 :          2 :         case BPF_ALU | BPF_MUL | BPF_X:
     217                 :          2 :           code_fmt = A32(*, REGU(2));
     218                 :          2 :           goto do_dst_src;
     219                 :          2 :         case BPF_ALU | BPF_DIV | BPF_X:
     220                 :          2 :           code_fmt = A32(/, REGU(2));
     221                 :          2 :           goto do_dst_src;
     222                 :          2 :         case BPF_ALU | BPF_OR | BPF_X:
     223                 :          2 :           code_fmt = A32(|, REGU(2));
     224                 :          2 :           goto do_dst_src;
     225                 :          2 :         case BPF_ALU | BPF_AND | BPF_X:
     226                 :          2 :           code_fmt = A32(&, REGU(2));
     227                 :          2 :           goto do_dst_src;
     228                 :          2 :         case BPF_ALU | BPF_LSH | BPF_X:
     229                 :          2 :           code_fmt = A32(<<, REGU(2));
     230                 :          2 :           goto do_dst_src;
     231                 :          2 :         case BPF_ALU | BPF_RSH | BPF_X:
     232                 :          2 :           code_fmt = A32(>>, REGU(2));
     233                 :          2 :           goto do_dst_src;
     234                 :          2 :         case BPF_ALU | BPF_MOD | BPF_X:
     235                 :          2 :           code_fmt = A32(%%, REGU(2));
     236                 :          2 :           goto do_dst_src;
     237                 :          2 :         case BPF_ALU | BPF_XOR | BPF_X:
     238                 :          2 :           code_fmt = A32(^, REGU(2));
     239                 :          2 :           goto do_dst_src;
     240                 :          2 :         case BPF_ALU | BPF_MOV | BPF_X:
     241                 :          2 :           code_fmt = REG(1) " = " REGU(2);
     242                 :          2 :           goto do_dst_src;
     243                 :          2 :         case BPF_ALU | BPF_ARSH | BPF_X:
     244                 :          2 :           code_fmt = REG(1) " = (u32)((s32)" REG(1) " >> " REG(2) ")";
     245                 :          2 :           goto do_dst_src;
     246                 :            : 
     247                 :          2 :         case BPF_ALU64 | BPF_ADD | BPF_K:
     248                 :          2 :           code_fmt = A64(+, IMMS(2));
     249                 :          2 :           goto do_dst_imm;
     250                 :          2 :         case BPF_ALU64 | BPF_SUB | BPF_K:
     251                 :          2 :           code_fmt = A64(-, IMMS(2));
     252                 :          2 :           goto do_dst_imm;
     253                 :          2 :         case BPF_ALU64 | BPF_MUL | BPF_K:
     254                 :          2 :           code_fmt = A64(*, IMMS(2));
     255                 :          2 :           goto do_dst_imm;
     256                 :          2 :         case BPF_ALU64 | BPF_DIV | BPF_K:
     257                 :          2 :           code_fmt = A64(/, IMMS(2));
     258                 :          2 :           goto do_dst_imm;
     259                 :          2 :         case BPF_ALU64 | BPF_OR | BPF_K:
     260                 :          2 :           code_fmt = A64(|, IMMS(2));
     261                 :          2 :           goto do_dst_imm;
     262                 :          2 :         case BPF_ALU64 | BPF_AND | BPF_K:
     263                 :          2 :           code_fmt = A64(&, IMMS(2));
     264                 :          2 :           goto do_dst_imm;
     265                 :          2 :         case BPF_ALU64 | BPF_LSH | BPF_K:
     266                 :          2 :           code_fmt = A64(<<, IMMS(2));
     267                 :          2 :           goto do_dst_imm;
     268                 :          2 :         case BPF_ALU64 | BPF_RSH | BPF_K:
     269                 :          2 :           code_fmt = A64(>>, IMMS(2));
     270                 :          2 :           goto do_dst_imm;
     271                 :          2 :         case BPF_ALU64 | BPF_MOD | BPF_K:
     272                 :          2 :           code_fmt = A64(%%, IMMS(2));
     273                 :          2 :           goto do_dst_imm;
     274                 :          2 :         case BPF_ALU64 | BPF_XOR | BPF_K:
     275                 :          2 :           code_fmt = A64(^, IMMS(2));
     276                 :          2 :           goto do_dst_imm;
     277                 :          2 :         case BPF_ALU64 | BPF_MOV | BPF_K:
     278                 :          2 :           code_fmt = REG(1) " = " IMMS(2);
     279                 :          2 :           goto do_dst_imm;
     280                 :          2 :         case BPF_ALU64 | BPF_ARSH | BPF_K:
     281                 :          2 :           code_fmt = REG(1) " = (s64)" REG(1) " >> " IMMS(2);
     282                 :          2 :           goto do_dst_imm;
     283                 :            : 
     284                 :          2 :         case BPF_ALU64 | BPF_ADD | BPF_X:
     285                 :          2 :           code_fmt = A64(+, REG(2));
     286                 :          2 :           goto do_dst_src;
     287                 :          2 :         case BPF_ALU64 | BPF_SUB | BPF_X:
     288                 :          2 :           code_fmt = A64(-, REG(2));
     289                 :          2 :           goto do_dst_src;
     290                 :          2 :         case BPF_ALU64 | BPF_MUL | BPF_X:
     291                 :          2 :           code_fmt = A64(*, REG(2));
     292                 :          2 :           goto do_dst_src;
     293                 :          2 :         case BPF_ALU64 | BPF_DIV | BPF_X:
     294                 :          2 :           code_fmt = A64(/, REG(2));
     295                 :          2 :           goto do_dst_src;
     296                 :          2 :         case BPF_ALU64 | BPF_OR | BPF_X:
     297                 :          2 :           code_fmt = A64(|, REG(2));
     298                 :          2 :           goto do_dst_src;
     299                 :          2 :         case BPF_ALU64 | BPF_AND | BPF_X:
     300                 :          2 :           code_fmt = A64(&, REG(2));
     301                 :          2 :           goto do_dst_src;
     302                 :          2 :         case BPF_ALU64 | BPF_LSH | BPF_X:
     303                 :          2 :           code_fmt = A64(<<, REG(2));
     304                 :          2 :           goto do_dst_src;
     305                 :          2 :         case BPF_ALU64 | BPF_RSH | BPF_X:
     306                 :          2 :           code_fmt = A64(>>, REG(2));
     307                 :          2 :           goto do_dst_src;
     308                 :          2 :         case BPF_ALU64 | BPF_MOD | BPF_X:
     309                 :          2 :           code_fmt = A64(%%, REG(2));
     310                 :          2 :           goto do_dst_src;
     311                 :          2 :         case BPF_ALU64 | BPF_XOR | BPF_X:
     312                 :          2 :           code_fmt = A64(^, REG(2));
     313                 :          2 :           goto do_dst_src;
     314                 :          2 :         case BPF_ALU64 | BPF_MOV | BPF_X:
     315                 :          2 :           code_fmt = REG(1) " = " REG(2);
     316                 :          2 :           goto do_dst_src;
     317                 :          2 :         case BPF_ALU64 | BPF_ARSH | BPF_X:
     318                 :          2 :           code_fmt = REG(1) " = (s64)" REG(1) " >> " REG(2);
     319                 :          2 :           goto do_dst_src;
     320                 :            : 
     321                 :          2 :         case BPF_ALU | BPF_NEG:
     322                 :          2 :           code_fmt = REG(1) " = (u32)-" REG(1);
     323                 :          2 :           goto do_dst_src;
     324                 :          2 :         case BPF_ALU64 | BPF_NEG:
     325                 :          2 :           code_fmt = REG(1) " = -" REG(1);
     326                 :          2 :           goto do_dst_src;
     327                 :            : 
     328                 :          2 :         case BPF_JMP | BPF_JEQ | BPF_K:
     329                 :          2 :           code_fmt = J64(REG(1), ==, IMMS(2));
     330                 :          2 :           goto do_dst_imm_jmp;
     331                 :          2 :         case BPF_JMP | BPF_JGT | BPF_K:
     332                 :          2 :           code_fmt = J64(REG(1), >, IMMS(2));
     333                 :          2 :           goto do_dst_imm_jmp;
     334                 :          2 :         case BPF_JMP | BPF_JGE | BPF_K:
     335                 :          2 :           code_fmt = J64(REG(1), >=, IMMS(2));
     336                 :          2 :           goto do_dst_imm_jmp;
     337                 :          2 :         case BPF_JMP | BPF_JSET | BPF_K:
     338                 :          2 :           code_fmt = J64(REG(1), &, IMMS(2));
     339                 :          2 :           goto do_dst_imm_jmp;
     340                 :          2 :         case BPF_JMP | BPF_JNE | BPF_K:
     341                 :          2 :           code_fmt = J64(REG(1), !=, IMMS(2));
     342                 :          2 :           goto do_dst_imm_jmp;
     343                 :          2 :         case BPF_JMP | BPF_JSGT | BPF_K:
     344                 :          2 :           code_fmt = J64(REGS(1), >, IMMS(2));
     345                 :          2 :           goto do_dst_imm_jmp;
     346                 :          2 :         case BPF_JMP | BPF_JSGE | BPF_K:
     347                 :          2 :           code_fmt = J64(REGS(1), >=, IMMS(2));
     348                 :          2 :           goto do_dst_imm_jmp;
     349                 :          2 :         case BPF_JMP | BPF_JLT | BPF_K:
     350                 :          2 :           code_fmt = J64(REG(1), <, IMMS(2));
     351                 :          2 :           goto do_dst_imm_jmp;
     352                 :          2 :         case BPF_JMP | BPF_JLE | BPF_K:
     353                 :          2 :           code_fmt = J64(REG(1), <=, IMMS(2));
     354                 :          2 :           goto do_dst_imm_jmp;
     355                 :          2 :         case BPF_JMP | BPF_JSLT | BPF_K:
     356                 :          2 :           code_fmt = J64(REGS(1), <, IMMS(2));
     357                 :          2 :           goto do_dst_imm_jmp;
     358                 :          2 :         case BPF_JMP | BPF_JSLE | BPF_K:
     359                 :          2 :           code_fmt = J64(REGS(1), <=, IMMS(2));
     360                 :          2 :           goto do_dst_imm_jmp;
     361                 :            : 
     362                 :          2 :         case BPF_JMP | BPF_JEQ | BPF_X:
     363                 :          2 :           code_fmt = J64(REG(1), ==, REG(2));
     364                 :          2 :           goto do_dst_src_jmp;
     365                 :          2 :         case BPF_JMP | BPF_JGT | BPF_X:
     366                 :          2 :           code_fmt = J64(REG(1), >, REG(2));
     367                 :          2 :           goto do_dst_src_jmp;
     368                 :          2 :         case BPF_JMP | BPF_JGE | BPF_X:
     369                 :          2 :           code_fmt = J64(REG(1), >=, REG(2));
     370                 :          2 :           goto do_dst_src_jmp;
     371                 :          2 :         case BPF_JMP | BPF_JSET | BPF_X:
     372                 :          2 :           code_fmt = J64(REG(1), &, REG(2));
     373                 :          2 :           goto do_dst_src_jmp;
     374                 :          2 :         case BPF_JMP | BPF_JNE | BPF_X:
     375                 :          2 :           code_fmt = J64(REG(1), !=, REG(2));
     376                 :          2 :           goto do_dst_src_jmp;
     377                 :          2 :         case BPF_JMP | BPF_JSGT | BPF_X:
     378                 :          2 :           code_fmt = J64(REGS(1), >, REGS(2));
     379                 :          2 :           goto do_dst_src_jmp;
     380                 :          2 :         case BPF_JMP | BPF_JSGE | BPF_X:
     381                 :          2 :           code_fmt = J64(REGS(1), >=, REGS(2));
     382                 :          2 :           goto do_dst_src_jmp;
     383                 :          2 :         case BPF_JMP | BPF_JLT | BPF_X:
     384                 :          2 :           code_fmt = J64(REG(1), <, REG(2));
     385                 :          2 :           goto do_dst_src_jmp;
     386                 :          2 :         case BPF_JMP | BPF_JLE | BPF_X:
     387                 :          2 :           code_fmt = J64(REG(1), <=, REG(2));
     388                 :          2 :           goto do_dst_src_jmp;
     389                 :          2 :         case BPF_JMP | BPF_JSLT | BPF_X:
     390                 :          2 :           code_fmt = J64(REGS(1), <, REGS(2));
     391                 :          2 :           goto do_dst_src_jmp;
     392                 :          2 :         case BPF_JMP | BPF_JSLE | BPF_X:
     393                 :          2 :           code_fmt = J64(REGS(1), <=, REGS(2));
     394                 :          2 :           goto do_dst_src_jmp;
     395                 :            : 
     396                 :          2 :         case BPF_LDX | BPF_MEM | BPF_B:
     397                 :          2 :           code_fmt = LOAD(u8);
     398                 :          2 :           goto do_dst_src_off;
     399                 :          2 :         case BPF_LDX | BPF_MEM | BPF_H:
     400                 :          2 :           code_fmt = LOAD(u16);
     401                 :          2 :           goto do_dst_src_off;
     402                 :          2 :         case BPF_LDX | BPF_MEM | BPF_W:
     403                 :          2 :           code_fmt = LOAD(u32);
     404                 :          2 :           goto do_dst_src_off;
     405                 :          2 :         case BPF_LDX | BPF_MEM | BPF_DW:
     406                 :          2 :           code_fmt = LOAD(u64);
     407                 :          2 :           goto do_dst_src_off;
     408                 :            : 
     409                 :          2 :         case BPF_STX | BPF_MEM | BPF_B:
     410                 :          2 :           code_fmt = STORE(u8, REG(2));
     411                 :          2 :           goto do_dst_src_off;
     412                 :          2 :         case BPF_STX | BPF_MEM | BPF_H:
     413                 :          2 :           code_fmt = STORE(u16, REG(2));
     414                 :          2 :           goto do_dst_src_off;
     415                 :          2 :         case BPF_STX | BPF_MEM | BPF_W:
     416                 :          2 :           code_fmt = STORE(u32, REG(2));
     417                 :          2 :           goto do_dst_src_off;
     418                 :          2 :         case BPF_STX | BPF_MEM | BPF_DW:
     419                 :          2 :           code_fmt = STORE(u64, REG(2));
     420                 :          2 :           goto do_dst_src_off;
     421                 :            : 
     422                 :          2 :         case BPF_STX | BPF_XADD | BPF_W:
     423                 :          2 :           code_fmt = XADD(u32, REG(2));
     424                 :          2 :           goto do_dst_src_off;
     425                 :          2 :         case BPF_STX | BPF_XADD | BPF_DW:
     426                 :          2 :           code_fmt = XADD(u64, REG(2));
     427                 :          2 :           goto do_dst_src_off;
     428                 :            : 
     429                 :          2 :         case BPF_ST | BPF_MEM | BPF_B:
     430                 :          2 :           code_fmt = STORE(u8, IMMS(2));
     431                 :          2 :           goto do_dst_imm_off;
     432                 :          2 :         case BPF_ST | BPF_MEM | BPF_H:
     433                 :          2 :           code_fmt = STORE(u16, IMMS(2));
     434                 :          2 :           goto do_dst_imm_off;
     435                 :          2 :         case BPF_ST | BPF_MEM | BPF_W:
     436                 :          2 :           code_fmt = STORE(u32, IMMS(2));
     437                 :          2 :           goto do_dst_imm_off;
     438                 :          2 :         case BPF_ST | BPF_MEM | BPF_DW:
     439                 :          2 :           code_fmt = STORE(u64, IMMS(2));
     440                 :          2 :           goto do_dst_imm_off;
     441                 :            : 
     442                 :          2 :         case BPF_LD | BPF_ABS | BPF_B:
     443                 :          2 :           code_fmt = LDSKB(u8, IMMS(1));
     444                 :          2 :           goto do_imm;
     445                 :          2 :         case BPF_LD | BPF_ABS | BPF_H:
     446                 :          2 :           code_fmt = LDSKB(u16, IMMS(1));
     447                 :          2 :           goto do_imm;
     448                 :          2 :         case BPF_LD | BPF_ABS | BPF_W:
     449                 :          2 :           code_fmt = LDSKB(u32, IMMS(1));
     450                 :          2 :           goto do_imm;
     451                 :            : 
     452                 :          2 :         case BPF_LD | BPF_IND | BPF_B:
     453                 :          2 :           code_fmt = LDSKB(u8, REG(1) "+" IMMS(2));
     454                 :          2 :           goto do_src_imm;
     455                 :          2 :         case BPF_LD | BPF_IND | BPF_H:
     456                 :          2 :           code_fmt = LDSKB(u16, REG(1) "+" IMMS(2));
     457                 :          2 :           goto do_src_imm;
     458                 :          2 :         case BPF_LD | BPF_IND | BPF_W:
     459                 :          2 :           code_fmt = LDSKB(u32, REG(1) "+" IMMS(2));
     460                 :          2 :           goto do_src_imm;
     461                 :            : 
     462                 :          8 :         do_imm:
     463                 :          8 :           len = snprintf(buf, sizeof(buf), code_fmt, i.imm);
     464                 :          8 :           break;
     465                 :         52 :         do_dst_imm:
     466                 :         52 :           len = snprintf(buf, sizeof(buf), code_fmt, i.dst_reg, i.imm);
     467                 :         52 :           break;
     468                 :          6 :         do_src_imm:
     469                 :          6 :           len = snprintf(buf, sizeof(buf), code_fmt, i.src_reg, i.imm);
     470                 :          6 :           break;
     471                 :         52 :         do_dst_src:
     472                 :         52 :           len = snprintf(buf, sizeof(buf), code_fmt, i.dst_reg, i.src_reg);
     473                 :         52 :           break;
     474                 :         22 :         do_dst_imm_jmp:
     475                 :         22 :           len = snprintf(buf, sizeof(buf), code_fmt, i.dst_reg, i.imm, jmp);
     476                 :         22 :           break;
     477                 :         22 :         do_dst_src_jmp:
     478                 :         22 :           len = snprintf(buf, sizeof(buf), code_fmt,
     479                 :         22 :                          i.dst_reg, i.src_reg, jmp);
     480                 :         22 :           break;
     481                 :          8 :         do_dst_imm_off:
     482                 :          8 :           len = snprintf(buf, sizeof(buf), code_fmt, i.dst_reg, i.imm, i.off);
     483                 :          8 :           break;
     484                 :         20 :         do_dst_src_off:
     485                 :         20 :           len = snprintf(buf, sizeof(buf), code_fmt,
     486                 :         20 :                          i.dst_reg, i.src_reg, i.off);
     487                 :         20 :           break;
     488                 :            : 
     489                 :        316 :         default:
     490                 :        316 :           class = BPF_CLASS(code);
     491                 :        316 :           len = snprintf(buf, sizeof(buf), "invalid class %s",
     492                 :        316 :                          class_string[class]);
     493                 :        316 :           break;
     494                 :            :         }
     495                 :            : 
     496                 :        512 :       *startp = start;
     497                 :        512 :       retval = outcb (buf, len, outcbarg);
     498         [ -  + ]:        512 :       if (retval != 0)
     499                 :          0 :         goto done;
     500                 :            :     }
     501                 :            : 
     502                 :          2 :  done:
     503                 :          2 :   return retval;
     504                 :            : }

Generated by: LCOV version 1.16