1ddecdfceSMircea Gherzan /* 2ddecdfceSMircea Gherzan * Just-In-Time compiler for BPF filters on 32bit ARM 3ddecdfceSMircea Gherzan * 4ddecdfceSMircea Gherzan * Copyright (c) 2011 Mircea Gherzan <mgherzan@gmail.com> 5ddecdfceSMircea Gherzan * 6ddecdfceSMircea Gherzan * This program is free software; you can redistribute it and/or modify it 7ddecdfceSMircea Gherzan * under the terms of the GNU General Public License as published by the 8ddecdfceSMircea Gherzan * Free Software Foundation; version 2 of the License. 9ddecdfceSMircea Gherzan */ 10ddecdfceSMircea Gherzan 11ddecdfceSMircea Gherzan #ifndef PFILTER_OPCODES_ARM_H 12ddecdfceSMircea Gherzan #define PFILTER_OPCODES_ARM_H 13ddecdfceSMircea Gherzan 14ddecdfceSMircea Gherzan #define ARM_R0 0 15ddecdfceSMircea Gherzan #define ARM_R1 1 16ddecdfceSMircea Gherzan #define ARM_R2 2 17ddecdfceSMircea Gherzan #define ARM_R3 3 18ddecdfceSMircea Gherzan #define ARM_R4 4 19ddecdfceSMircea Gherzan #define ARM_R5 5 20ddecdfceSMircea Gherzan #define ARM_R6 6 21ddecdfceSMircea Gherzan #define ARM_R7 7 22ddecdfceSMircea Gherzan #define ARM_R8 8 23ddecdfceSMircea Gherzan #define ARM_R9 9 24ddecdfceSMircea Gherzan #define ARM_R10 10 25ddecdfceSMircea Gherzan #define ARM_FP 11 26ddecdfceSMircea Gherzan #define ARM_IP 12 27ddecdfceSMircea Gherzan #define ARM_SP 13 28ddecdfceSMircea Gherzan #define ARM_LR 14 29ddecdfceSMircea Gherzan #define ARM_PC 15 30ddecdfceSMircea Gherzan 31ddecdfceSMircea Gherzan #define ARM_COND_EQ 0x0 32ddecdfceSMircea Gherzan #define ARM_COND_NE 0x1 33ddecdfceSMircea Gherzan #define ARM_COND_CS 0x2 34ddecdfceSMircea Gherzan #define ARM_COND_HS ARM_COND_CS 35ddecdfceSMircea Gherzan #define ARM_COND_CC 0x3 36ddecdfceSMircea Gherzan #define ARM_COND_LO ARM_COND_CC 37ddecdfceSMircea Gherzan #define ARM_COND_MI 0x4 38ddecdfceSMircea Gherzan #define ARM_COND_PL 0x5 39ddecdfceSMircea Gherzan #define ARM_COND_VS 0x6 40ddecdfceSMircea Gherzan #define ARM_COND_VC 0x7 41ddecdfceSMircea Gherzan #define ARM_COND_HI 0x8 42ddecdfceSMircea Gherzan #define ARM_COND_LS 0x9 43ddecdfceSMircea Gherzan #define ARM_COND_GE 0xa 44ddecdfceSMircea Gherzan #define ARM_COND_LT 0xb 45ddecdfceSMircea Gherzan #define ARM_COND_GT 0xc 46ddecdfceSMircea Gherzan #define ARM_COND_LE 0xd 47ddecdfceSMircea Gherzan #define ARM_COND_AL 0xe 48ddecdfceSMircea Gherzan 49ddecdfceSMircea Gherzan /* register shift types */ 50ddecdfceSMircea Gherzan #define SRTYPE_LSL 0 51ddecdfceSMircea Gherzan #define SRTYPE_LSR 1 52ddecdfceSMircea Gherzan #define SRTYPE_ASR 2 53ddecdfceSMircea Gherzan #define SRTYPE_ROR 3 54ddecdfceSMircea Gherzan 55ddecdfceSMircea Gherzan #define ARM_INST_ADD_R 0x00800000 56ddecdfceSMircea Gherzan #define ARM_INST_ADD_I 0x02800000 57ddecdfceSMircea Gherzan 58ddecdfceSMircea Gherzan #define ARM_INST_AND_R 0x00000000 59ddecdfceSMircea Gherzan #define ARM_INST_AND_I 0x02000000 60ddecdfceSMircea Gherzan 61ddecdfceSMircea Gherzan #define ARM_INST_BIC_R 0x01c00000 62ddecdfceSMircea Gherzan #define ARM_INST_BIC_I 0x03c00000 63ddecdfceSMircea Gherzan 64ddecdfceSMircea Gherzan #define ARM_INST_B 0x0a000000 65ddecdfceSMircea Gherzan #define ARM_INST_BX 0x012FFF10 66ddecdfceSMircea Gherzan #define ARM_INST_BLX_R 0x012fff30 67ddecdfceSMircea Gherzan 68ddecdfceSMircea Gherzan #define ARM_INST_CMP_R 0x01500000 69ddecdfceSMircea Gherzan #define ARM_INST_CMP_I 0x03500000 70ddecdfceSMircea Gherzan 712bea29b7SMircea Gherzan #define ARM_INST_EOR_R 0x00200000 723cbe2041SDaniel Borkmann #define ARM_INST_EOR_I 0x02200000 732bea29b7SMircea Gherzan 74ddecdfceSMircea Gherzan #define ARM_INST_LDRB_I 0x05d00000 75ddecdfceSMircea Gherzan #define ARM_INST_LDRB_R 0x07d00000 76ddecdfceSMircea Gherzan #define ARM_INST_LDRH_I 0x01d000b0 77*5bf705b4SNicolas Schichan #define ARM_INST_LDRH_R 0x019000b0 78ddecdfceSMircea Gherzan #define ARM_INST_LDR_I 0x05900000 79ddecdfceSMircea Gherzan 80ddecdfceSMircea Gherzan #define ARM_INST_LDM 0x08900000 81ddecdfceSMircea Gherzan 82ddecdfceSMircea Gherzan #define ARM_INST_LSL_I 0x01a00000 83ddecdfceSMircea Gherzan #define ARM_INST_LSL_R 0x01a00010 84ddecdfceSMircea Gherzan 85ddecdfceSMircea Gherzan #define ARM_INST_LSR_I 0x01a00020 86ddecdfceSMircea Gherzan #define ARM_INST_LSR_R 0x01a00030 87ddecdfceSMircea Gherzan 88ddecdfceSMircea Gherzan #define ARM_INST_MOV_R 0x01a00000 89ddecdfceSMircea Gherzan #define ARM_INST_MOV_I 0x03a00000 90ddecdfceSMircea Gherzan #define ARM_INST_MOVW 0x03000000 91ddecdfceSMircea Gherzan #define ARM_INST_MOVT 0x03400000 92ddecdfceSMircea Gherzan 93ddecdfceSMircea Gherzan #define ARM_INST_MUL 0x00000090 94ddecdfceSMircea Gherzan 95ddecdfceSMircea Gherzan #define ARM_INST_POP 0x08bd0000 96ddecdfceSMircea Gherzan #define ARM_INST_PUSH 0x092d0000 97ddecdfceSMircea Gherzan 98ddecdfceSMircea Gherzan #define ARM_INST_ORR_R 0x01800000 99ddecdfceSMircea Gherzan #define ARM_INST_ORR_I 0x03800000 100ddecdfceSMircea Gherzan 101ddecdfceSMircea Gherzan #define ARM_INST_REV 0x06bf0f30 102ddecdfceSMircea Gherzan #define ARM_INST_REV16 0x06bf0fb0 103ddecdfceSMircea Gherzan 104ddecdfceSMircea Gherzan #define ARM_INST_RSB_I 0x02600000 105ddecdfceSMircea Gherzan 106ddecdfceSMircea Gherzan #define ARM_INST_SUB_R 0x00400000 107ddecdfceSMircea Gherzan #define ARM_INST_SUB_I 0x02400000 108ddecdfceSMircea Gherzan 109ddecdfceSMircea Gherzan #define ARM_INST_STR_I 0x05800000 110ddecdfceSMircea Gherzan 111ddecdfceSMircea Gherzan #define ARM_INST_TST_R 0x01100000 112ddecdfceSMircea Gherzan #define ARM_INST_TST_I 0x03100000 113ddecdfceSMircea Gherzan 114ddecdfceSMircea Gherzan #define ARM_INST_UDIV 0x0730f010 115ddecdfceSMircea Gherzan 116ddecdfceSMircea Gherzan #define ARM_INST_UMULL 0x00800090 117ddecdfceSMircea Gherzan 118e8b56d55SDaniel Borkmann /* 119e8b56d55SDaniel Borkmann * Use a suitable undefined instruction to use for ARM/Thumb2 faulting. 120e8b56d55SDaniel Borkmann * We need to be careful not to conflict with those used by other modules 121e8b56d55SDaniel Borkmann * (BUG, kprobes, etc) and the register_undef_hook() system. 122e8b56d55SDaniel Borkmann * 123e8b56d55SDaniel Borkmann * The ARM architecture reference manual guarantees that the following 124e8b56d55SDaniel Borkmann * instruction space will produce an undefined instruction exception on 125e8b56d55SDaniel Borkmann * all CPUs: 126e8b56d55SDaniel Borkmann * 127e8b56d55SDaniel Borkmann * ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx ARMv7-AR, section A5.4 128e8b56d55SDaniel Borkmann * Thumb: 1101 1110 xxxx xxxx ARMv7-M, section A5.2.6 129e8b56d55SDaniel Borkmann */ 130e8b56d55SDaniel Borkmann #define ARM_INST_UDF 0xe7fddef1 131e8b56d55SDaniel Borkmann 132ddecdfceSMircea Gherzan /* register */ 133ddecdfceSMircea Gherzan #define _AL3_R(op, rd, rn, rm) ((op ## _R) | (rd) << 12 | (rn) << 16 | (rm)) 134ddecdfceSMircea Gherzan /* immediate */ 135ddecdfceSMircea Gherzan #define _AL3_I(op, rd, rn, imm) ((op ## _I) | (rd) << 12 | (rn) << 16 | (imm)) 136ddecdfceSMircea Gherzan 137ddecdfceSMircea Gherzan #define ARM_ADD_R(rd, rn, rm) _AL3_R(ARM_INST_ADD, rd, rn, rm) 138ddecdfceSMircea Gherzan #define ARM_ADD_I(rd, rn, imm) _AL3_I(ARM_INST_ADD, rd, rn, imm) 139ddecdfceSMircea Gherzan 140ddecdfceSMircea Gherzan #define ARM_AND_R(rd, rn, rm) _AL3_R(ARM_INST_AND, rd, rn, rm) 141ddecdfceSMircea Gherzan #define ARM_AND_I(rd, rn, imm) _AL3_I(ARM_INST_AND, rd, rn, imm) 142ddecdfceSMircea Gherzan 143ddecdfceSMircea Gherzan #define ARM_BIC_R(rd, rn, rm) _AL3_R(ARM_INST_BIC, rd, rn, rm) 144ddecdfceSMircea Gherzan #define ARM_BIC_I(rd, rn, imm) _AL3_I(ARM_INST_BIC, rd, rn, imm) 145ddecdfceSMircea Gherzan 146ddecdfceSMircea Gherzan #define ARM_B(imm24) (ARM_INST_B | ((imm24) & 0xffffff)) 147ddecdfceSMircea Gherzan #define ARM_BX(rm) (ARM_INST_BX | (rm)) 148ddecdfceSMircea Gherzan #define ARM_BLX_R(rm) (ARM_INST_BLX_R | (rm)) 149ddecdfceSMircea Gherzan 150ddecdfceSMircea Gherzan #define ARM_CMP_R(rn, rm) _AL3_R(ARM_INST_CMP, 0, rn, rm) 151ddecdfceSMircea Gherzan #define ARM_CMP_I(rn, imm) _AL3_I(ARM_INST_CMP, 0, rn, imm) 152ddecdfceSMircea Gherzan 1532bea29b7SMircea Gherzan #define ARM_EOR_R(rd, rn, rm) _AL3_R(ARM_INST_EOR, rd, rn, rm) 1543cbe2041SDaniel Borkmann #define ARM_EOR_I(rd, rn, imm) _AL3_I(ARM_INST_EOR, rd, rn, imm) 1552bea29b7SMircea Gherzan 156ddecdfceSMircea Gherzan #define ARM_LDR_I(rt, rn, off) (ARM_INST_LDR_I | (rt) << 12 | (rn) << 16 \ 157ddecdfceSMircea Gherzan | (off)) 158ddecdfceSMircea Gherzan #define ARM_LDRB_I(rt, rn, off) (ARM_INST_LDRB_I | (rt) << 12 | (rn) << 16 \ 159ddecdfceSMircea Gherzan | (off)) 160ddecdfceSMircea Gherzan #define ARM_LDRB_R(rt, rn, rm) (ARM_INST_LDRB_R | (rt) << 12 | (rn) << 16 \ 161ddecdfceSMircea Gherzan | (rm)) 162ddecdfceSMircea Gherzan #define ARM_LDRH_I(rt, rn, off) (ARM_INST_LDRH_I | (rt) << 12 | (rn) << 16 \ 163ddecdfceSMircea Gherzan | (((off) & 0xf0) << 4) | ((off) & 0xf)) 164*5bf705b4SNicolas Schichan #define ARM_LDRH_R(rt, rn, rm) (ARM_INST_LDRH_R | (rt) << 12 | (rn) << 16 \ 165*5bf705b4SNicolas Schichan | (rm)) 166ddecdfceSMircea Gherzan 167ddecdfceSMircea Gherzan #define ARM_LDM(rn, regs) (ARM_INST_LDM | (rn) << 16 | (regs)) 168ddecdfceSMircea Gherzan 169ddecdfceSMircea Gherzan #define ARM_LSL_R(rd, rn, rm) (_AL3_R(ARM_INST_LSL, rd, 0, rn) | (rm) << 8) 170ddecdfceSMircea Gherzan #define ARM_LSL_I(rd, rn, imm) (_AL3_I(ARM_INST_LSL, rd, 0, rn) | (imm) << 7) 171ddecdfceSMircea Gherzan 172ddecdfceSMircea Gherzan #define ARM_LSR_R(rd, rn, rm) (_AL3_R(ARM_INST_LSR, rd, 0, rn) | (rm) << 8) 173ddecdfceSMircea Gherzan #define ARM_LSR_I(rd, rn, imm) (_AL3_I(ARM_INST_LSR, rd, 0, rn) | (imm) << 7) 174ddecdfceSMircea Gherzan 175ddecdfceSMircea Gherzan #define ARM_MOV_R(rd, rm) _AL3_R(ARM_INST_MOV, rd, 0, rm) 176ddecdfceSMircea Gherzan #define ARM_MOV_I(rd, imm) _AL3_I(ARM_INST_MOV, rd, 0, imm) 177ddecdfceSMircea Gherzan 178ddecdfceSMircea Gherzan #define ARM_MOVW(rd, imm) \ 179ddecdfceSMircea Gherzan (ARM_INST_MOVW | ((imm) >> 12) << 16 | (rd) << 12 | ((imm) & 0x0fff)) 180ddecdfceSMircea Gherzan 181ddecdfceSMircea Gherzan #define ARM_MOVT(rd, imm) \ 182ddecdfceSMircea Gherzan (ARM_INST_MOVT | ((imm) >> 12) << 16 | (rd) << 12 | ((imm) & 0x0fff)) 183ddecdfceSMircea Gherzan 184ddecdfceSMircea Gherzan #define ARM_MUL(rd, rm, rn) (ARM_INST_MUL | (rd) << 16 | (rm) << 8 | (rn)) 185ddecdfceSMircea Gherzan 186ddecdfceSMircea Gherzan #define ARM_POP(regs) (ARM_INST_POP | (regs)) 187ddecdfceSMircea Gherzan #define ARM_PUSH(regs) (ARM_INST_PUSH | (regs)) 188ddecdfceSMircea Gherzan 189ddecdfceSMircea Gherzan #define ARM_ORR_R(rd, rn, rm) _AL3_R(ARM_INST_ORR, rd, rn, rm) 190ddecdfceSMircea Gherzan #define ARM_ORR_I(rd, rn, imm) _AL3_I(ARM_INST_ORR, rd, rn, imm) 191ddecdfceSMircea Gherzan #define ARM_ORR_S(rd, rn, rm, type, rs) \ 192ddecdfceSMircea Gherzan (ARM_ORR_R(rd, rn, rm) | (type) << 5 | (rs) << 7) 193ddecdfceSMircea Gherzan 194ddecdfceSMircea Gherzan #define ARM_REV(rd, rm) (ARM_INST_REV | (rd) << 12 | (rm)) 195ddecdfceSMircea Gherzan #define ARM_REV16(rd, rm) (ARM_INST_REV16 | (rd) << 12 | (rm)) 196ddecdfceSMircea Gherzan 197ddecdfceSMircea Gherzan #define ARM_RSB_I(rd, rn, imm) _AL3_I(ARM_INST_RSB, rd, rn, imm) 198ddecdfceSMircea Gherzan 199ddecdfceSMircea Gherzan #define ARM_SUB_R(rd, rn, rm) _AL3_R(ARM_INST_SUB, rd, rn, rm) 200ddecdfceSMircea Gherzan #define ARM_SUB_I(rd, rn, imm) _AL3_I(ARM_INST_SUB, rd, rn, imm) 201ddecdfceSMircea Gherzan 202ddecdfceSMircea Gherzan #define ARM_STR_I(rt, rn, off) (ARM_INST_STR_I | (rt) << 12 | (rn) << 16 \ 203ddecdfceSMircea Gherzan | (off)) 204ddecdfceSMircea Gherzan 205ddecdfceSMircea Gherzan #define ARM_TST_R(rn, rm) _AL3_R(ARM_INST_TST, 0, rn, rm) 206ddecdfceSMircea Gherzan #define ARM_TST_I(rn, imm) _AL3_I(ARM_INST_TST, 0, rn, imm) 207ddecdfceSMircea Gherzan 208ddecdfceSMircea Gherzan #define ARM_UDIV(rd, rn, rm) (ARM_INST_UDIV | (rd) << 16 | (rn) | (rm) << 8) 209ddecdfceSMircea Gherzan 210ddecdfceSMircea Gherzan #define ARM_UMULL(rd_lo, rd_hi, rn, rm) (ARM_INST_UMULL | (rd_hi) << 16 \ 211ddecdfceSMircea Gherzan | (rd_lo) << 12 | (rm) << 8 | rn) 212ddecdfceSMircea Gherzan 213ddecdfceSMircea Gherzan #endif /* PFILTER_OPCODES_ARM_H */ 214