diff options
author | jkim <jkim@FreeBSD.org> | 2008-06-23 23:10:11 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2008-06-23 23:10:11 +0000 |
commit | 29b8978e1ff8f6fa6abc582e1782f5bda7b51e9c (patch) | |
tree | 9c44c5b14c64db17a220dd4ceb1407c46508cc9c /sys/i386 | |
parent | 6aed2b53880ff6fddcf3e67bb5bdd3b719d0ccf2 (diff) | |
download | FreeBSD-src-29b8978e1ff8f6fa6abc582e1782f5bda7b51e9c.zip FreeBSD-src-29b8978e1ff8f6fa6abc582e1782f5bda7b51e9c.tar.gz |
Rehash and clean up BPF JIT compiler macros to match AT&T notations.
Diffstat (limited to 'sys/i386')
-rw-r--r-- | sys/i386/i386/bpf_jit_machdep.c | 172 | ||||
-rw-r--r-- | sys/i386/i386/bpf_jit_machdep.h | 114 |
2 files changed, 143 insertions, 143 deletions
diff --git a/sys/i386/i386/bpf_jit_machdep.c b/sys/i386/i386/bpf_jit_machdep.c index 362569e..ed9a4ba 100644 --- a/sys/i386/i386/bpf_jit_machdep.c +++ b/sys/i386/i386/bpf_jit_machdep.c @@ -132,11 +132,11 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) /* create the procedure header */ PUSH(EBP); - MOVrd(EBP, ESP); + MOVrd(ESP, EBP); PUSH(EDI); PUSH(ESI); PUSH(EBX); - MOVodd(EBX, EBP, 8); + MOVodd(8, EBP, EBX); for (i = 0; i < nins; i++) { stream.bpf_pc++; @@ -146,7 +146,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) return NULL; case BPF_RET|BPF_K: - MOVid(EAX, ins->k); + MOVid(ins->k, EAX); POP(EBX); POP(ESI); POP(EDI); @@ -161,103 +161,103 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_LD|BPF_W|BPF_ABS: - MOVid(ECX, ins->k); - MOVrd(ESI, ECX); - ADDib(ECX, sizeof(int)); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + MOVrd(ECX, ESI); + ADDib(sizeof(int), ECX); + CMPodd(0x10, EBP, ECX); JLEb(7); ZERO_EAX(); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobd(EAX, EBX, ESI); + MOVobd(EBX, ESI, EAX); BSWAP(EAX); break; case BPF_LD|BPF_H|BPF_ABS: ZERO_EAX(); - MOVid(ECX, ins->k); - MOVrd(ESI, ECX); - ADDib(ECX, sizeof(short)); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + MOVrd(ECX, ESI); + ADDib(sizeof(short), ECX); + CMPodd(0x10, EBP, ECX); JLEb(5); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobw(AX, EBX, ESI); + MOVobw(EBX, ESI, AX); SWAP_AX(); break; case BPF_LD|BPF_B|BPF_ABS: ZERO_EAX(); - MOVid(ECX, ins->k); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + CMPodd(0x10, EBP, ECX); JLEb(5); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobb(AL, EBX, ECX); + MOVobb(EBX, ECX, AL); break; case BPF_LD|BPF_W|BPF_LEN: - MOVodd(EAX, EBP, 0xc); + MOVodd(0xc, EBP, EAX); break; case BPF_LDX|BPF_W|BPF_LEN: - MOVodd(EDX, EBP, 0xc); + MOVodd(0xc, EBP, EDX); break; case BPF_LD|BPF_W|BPF_IND: - MOVid(ECX, ins->k); - ADDrd(ECX, EDX); - MOVrd(ESI, ECX); - ADDib(ECX, sizeof(int)); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + ADDrd(EDX, ECX); + MOVrd(ECX, ESI); + ADDib(sizeof(int), ECX); + CMPodd(0x10, EBP, ECX); JLEb(7); ZERO_EAX(); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobd(EAX, EBX, ESI); + MOVobd(EBX, ESI, EAX); BSWAP(EAX); break; case BPF_LD|BPF_H|BPF_IND: ZERO_EAX(); - MOVid(ECX, ins->k); - ADDrd(ECX, EDX); - MOVrd(ESI, ECX); - ADDib(ECX, sizeof(short)); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + ADDrd(EDX, ECX); + MOVrd(ECX, ESI); + ADDib(sizeof(short), ECX); + CMPodd(0x10, EBP, ECX); JLEb(5); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobw(AX, EBX, ESI); + MOVobw(EBX, ESI, AX); SWAP_AX(); break; case BPF_LD|BPF_B|BPF_IND: ZERO_EAX(); - MOVid(ECX, ins->k); - ADDrd(ECX, EDX); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + ADDrd(EDX, ECX); + CMPodd(0x10, EBP, ECX); JLEb(5); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVobb(AL, EBX, ECX); + MOVobb(EBX, ECX, AL); break; case BPF_LDX|BPF_MSH|BPF_B: - MOVid(ECX, ins->k); - CMPodd(ECX, EBP, 0x10); + MOVid(ins->k, ECX); + CMPodd(0x10, EBP, ECX); JLEb(7); ZERO_EAX(); POP(EBX); @@ -265,29 +265,29 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) POP(EDI); LEAVE_RET(); ZERO_EDX(); - MOVobb(DL, EBX, ECX); - ANDib(DL, 0xf); - SHLib(EDX, 2); + MOVobb(EBX, ECX, DL); + ANDib(0xf, DL); + SHLib(2, EDX); break; case BPF_LD|BPF_IMM: - MOVid(EAX, ins->k); + MOVid(ins->k, EAX); break; case BPF_LDX|BPF_IMM: - MOVid(EDX, ins->k); + MOVid(ins->k, EDX); break; case BPF_LD|BPF_MEM: - MOVid(ECX, (uintptr_t)mem); - MOVid(ESI, ins->k * 4); - MOVobd(EAX, ECX, ESI); + MOVid((uintptr_t)mem, ECX); + MOVid(ins->k * 4, ESI); + MOVobd(ECX, ESI, EAX); break; case BPF_LDX|BPF_MEM: - MOVid(ECX, (uintptr_t)mem); - MOVid(ESI, ins->k * 4); - MOVobd(EDX, ECX, ESI); + MOVid((uintptr_t)mem, ECX); + MOVid(ins->k * 4, ESI); + MOVobd(ECX, ESI, EDX); break; case BPF_ST: @@ -296,15 +296,15 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) * be optimized if the previous instruction * was already of this type */ - MOVid(ECX, (uintptr_t)mem); - MOVid(ESI, ins->k * 4); - MOVomd(ECX, ESI, EAX); + MOVid((uintptr_t)mem, ECX); + MOVid(ins->k * 4, ESI); + MOVomd(EAX, ECX, ESI); break; case BPF_STX: - MOVid(ECX, (uintptr_t)mem); - MOVid(ESI, ins->k * 4); - MOVomd(ECX, ESI, EDX); + MOVid((uintptr_t)mem, ECX); + MOVid(ins->k * 4, ESI); + MOVomd(EDX, ECX, ESI); break; case BPF_JMP|BPF_JA: @@ -313,7 +313,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JGT|BPF_K: - CMPid(EAX, ins->k); + CMPid(ins->k, EAX); /* 5 is the size of the following JMP */ JG(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5 ); @@ -322,7 +322,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JGE|BPF_K: - CMPid(EAX, ins->k); + CMPid(ins->k, EAX); JGE(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jf] - @@ -330,7 +330,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JEQ|BPF_K: - CMPid(EAX, ins->k); + CMPid(ins->k, EAX); JE(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jf] - @@ -338,8 +338,8 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JSET|BPF_K: - MOVrd(ECX, EAX); - ANDid(ECX, ins->k); + MOVrd(EAX, ECX); + ANDid(ins->k, ECX); JE(stream.refs[stream.bpf_pc + ins->jf] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jt] - @@ -347,7 +347,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JGT|BPF_X: - CMPrd(EAX, EDX); + CMPrd(EDX, EAX); JA(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jf] - @@ -355,7 +355,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JGE|BPF_X: - CMPrd(EAX, EDX); + CMPrd(EDX, EAX); JAE(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jf] - @@ -363,7 +363,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JEQ|BPF_X: - CMPrd(EAX, EDX); + CMPrd(EDX, EAX); JE(stream.refs[stream.bpf_pc + ins->jt] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jf] - @@ -371,8 +371,8 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_JMP|BPF_JSET|BPF_X: - MOVrd(ECX, EAX); - ANDrd(ECX, EDX); + MOVrd(EAX, ECX); + ANDrd(EDX, ECX); JE(stream.refs[stream.bpf_pc + ins->jf] - stream.refs[stream.bpf_pc] + 5); JMP(stream.refs[stream.bpf_pc + ins->jt] - @@ -380,48 +380,48 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_ALU|BPF_ADD|BPF_X: - ADDrd(EAX, EDX); + ADDrd(EDX, EAX); break; case BPF_ALU|BPF_SUB|BPF_X: - SUBrd(EAX, EDX); + SUBrd(EDX, EAX); break; case BPF_ALU|BPF_MUL|BPF_X: - MOVrd(ECX, EDX); - MULrd(EDX); MOVrd(EDX, ECX); + MULrd(EDX); + MOVrd(ECX, EDX); break; case BPF_ALU|BPF_DIV|BPF_X: - CMPid(EDX, 0); + CMPid(0, EDX); JNEb(7); ZERO_EAX(); POP(EBX); POP(ESI); POP(EDI); LEAVE_RET(); - MOVrd(ECX, EDX); + MOVrd(EDX, ECX); ZERO_EDX(); DIVrd(ECX); - MOVrd(EDX, ECX); + MOVrd(ECX, EDX); break; case BPF_ALU|BPF_AND|BPF_X: - ANDrd(EAX, EDX); + ANDrd(EDX, EAX); break; case BPF_ALU|BPF_OR|BPF_X: - ORrd(EAX, EDX); + ORrd(EDX, EAX); break; case BPF_ALU|BPF_LSH|BPF_X: - MOVrd(ECX, EDX); + MOVrd(EDX, ECX); SHL_CLrb(EAX); break; case BPF_ALU|BPF_RSH|BPF_X: - MOVrd(ECX, EDX); + MOVrd(EDX, ECX); SHR_CLrb(EAX); break; @@ -434,34 +434,34 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_ALU|BPF_MUL|BPF_K: - MOVrd(ECX, EDX); - MOVid(EDX, ins->k); - MULrd(EDX); MOVrd(EDX, ECX); + MOVid(ins->k, EDX); + MULrd(EDX); + MOVrd(ECX, EDX); break; case BPF_ALU|BPF_DIV|BPF_K: - MOVrd(ECX, EDX); + MOVrd(EDX, ECX); ZERO_EDX(); - MOVid(ESI, ins->k); + MOVid(ins->k, ESI); DIVrd(ESI); - MOVrd(EDX, ECX); + MOVrd(ECX, EDX); break; case BPF_ALU|BPF_AND|BPF_K: - ANDid(EAX, ins->k); + ANDid(ins->k, EAX); break; case BPF_ALU|BPF_OR|BPF_K: - ORid(EAX, ins->k); + ORid(ins->k, EAX); break; case BPF_ALU|BPF_LSH|BPF_K: - SHLib(EAX, (ins->k) & 255); + SHLib((ins->k) & 0xff, EAX); break; case BPF_ALU|BPF_RSH|BPF_K: - SHRib(EAX, (ins->k) & 255); + SHRib((ins->k) & 0xff, EAX); break; case BPF_ALU|BPF_NEG: @@ -469,11 +469,11 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) break; case BPF_MISC|BPF_TAX: - MOVrd(EDX, EAX); + MOVrd(EAX, EDX); break; case BPF_MISC|BPF_TXA: - MOVrd(EAX, EDX); + MOVrd(EDX, EAX); break; } ins++; diff --git a/sys/i386/i386/bpf_jit_machdep.h b/sys/i386/i386/bpf_jit_machdep.h index d0d4222..1a93ee2 100644 --- a/sys/i386/i386/bpf_jit_machdep.h +++ b/sys/i386/i386/bpf_jit_machdep.h @@ -95,74 +95,74 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); * native Instruction Macros */ -/* mov r32,i32 */ -#define MOVid(r32, i32) do { \ +/* movl i32,r32 */ +#define MOVid(i32, r32) do { \ emitm(&stream, (11 << 4) | (1 << 3) | (r32 & 0x7), 1); \ emitm(&stream, i32, 4); \ } while (0) -/* mov dr32,sr32 */ -#define MOVrd(dr32, sr32) do { \ +/* movl sr32,dr32 */ +#define MOVrd(sr32, dr32) do { \ emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* mov dr32,sr32[off] */ -#define MOVodd(dr32, sr32, off) do { \ +/* movl off(sr32),dr32 */ +#define MOVodd(off, sr32, dr32) do { \ emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ emitm(&stream, \ (1 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ emitm(&stream, off, 1); \ } while (0) -/* mov dr32,sr32[or32] */ -#define MOVobd(dr32, sr32, or32) do { \ +/* movl (sr32,or32,1),dr32 */ +#define MOVobd(sr32, or32, dr32) do { \ emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ emitm(&stream, ((dr32 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* mov dr16,sr32[or32] */ -#define MOVobw(dr32, sr32, or32) do { \ +/* movw (sr32,or32,1),dr16 */ +#define MOVobw(sr32, or32, dr16) do { \ emitm(&stream, 0x66, 1); \ emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ - emitm(&stream, ((dr32 & 0x7) << 3) | 4, 1); \ + emitm(&stream, ((dr16 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* mov dr8,sr32[or32] */ -#define MOVobb(dr8, sr32, or32) do { \ +/* movb (sr32,or32,1),dr8 */ +#define MOVobb(sr32, or32, dr8) do { \ emitm(&stream, 0x8a, 1); \ emitm(&stream, ((dr8 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* mov [dr32][or32],sr32 */ -#define MOVomd(dr32, or32, sr32) do { \ +/* movl sr32,(dr32,or32,1) */ +#define MOVomd(sr32, dr32, or32) do { \ emitm(&stream, 0x89, 1); \ emitm(&stream, ((sr32 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) -/* bswap dr32 */ +/* bswapl dr32 */ #define BSWAP(dr32) do { \ emitm(&stream, 0xf, 1); \ emitm(&stream, (0x19 << 3) | dr32, 1); \ } while (0) -/* xchg al,ah */ +/* xchgb %al,%ah */ #define SWAP_AX() do { \ emitm(&stream, 0x86, 1); \ emitm(&stream, 0xc4, 1); \ } while (0) -/* push r32 */ +/* pushl r32 */ #define PUSH(r32) do { \ emitm(&stream, (5 << 4) | (0 << 3) | (r32 & 0x7), 1); \ } while (0) -/* pop r32 */ +/* popl r32 */ #define POP(r32) do { \ emitm(&stream, (5 << 4) | (1 << 3) | (r32 & 0x7), 1); \ } while (0) @@ -173,67 +173,67 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); emitm(&stream, 0xc3, 1); \ } while (0) -/* add dr32,sr32 */ -#define ADDrd(dr32, sr32) do { \ +/* addl sr32,dr32 */ +#define ADDrd(sr32, dr32) do { \ emitm(&stream, 0x03, 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* add eax,i32 */ +/* addl i32,%eax */ #define ADD_EAXi(i32) do { \ emitm(&stream, 0x05, 1); \ emitm(&stream, i32, 4); \ } while (0) -/* add r32,i32 */ -#define ADDid(r32, i32) do { \ +/* addl i32,r32 */ +#define ADDid(i32, r32) do { \ emitm(&stream, 0x81, 1); \ emitm(&stream, (24 << 3) | r32, 1); \ emitm(&stream, i32, 4); \ } while (0) -/* add r32,i8 */ -#define ADDib(r32, i8) do { \ +/* addl i8,r32 */ +#define ADDib(i8, r32) do { \ emitm(&stream, 0x83, 1); \ emitm(&stream, (24 << 3) | r32, 1); \ emitm(&stream, i8, 1); \ } while (0) -/* sub dr32,sr32 */ -#define SUBrd(dr32, sr32) do { \ +/* subl sr32,dr32 */ +#define SUBrd(sr32, dr32) do { \ emitm(&stream, 0x2b, 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* sub eax,i32 */ +/* subl i32,%eax */ #define SUB_EAXi(i32) do { \ emitm(&stream, 0x2d, 1); \ emitm(&stream, i32, 4); \ } while (0) -/* mul r32 */ +/* mull r32 */ #define MULrd(r32) do { \ emitm(&stream, 0xf7, 1); \ emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ } while (0) -/* div r32 */ +/* divl r32 */ #define DIVrd(r32) do { \ emitm(&stream, 0xf7, 1); \ emitm(&stream, (15 << 4) | (r32 & 0x7), 1); \ } while (0) -/* and r8,i8 */ -#define ANDib(r8, i8) do { \ +/* andb i8,r8 */ +#define ANDib(i8, r8) do { \ emitm(&stream, 0x80, 1); \ emitm(&stream, (7 << 5) | r8, 1); \ emitm(&stream, i8, 1); \ } while (0) -/* and r32,i32 */ -#define ANDid(r32, i32) do { \ +/* andl i32,r32 */ +#define ANDid(i32, r32) do { \ if (r32 == EAX) { \ emitm(&stream, 0x25, 1); \ emitm(&stream, i32, 4); \ @@ -244,22 +244,22 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); } \ } while (0) -/* and dr32,sr32 */ -#define ANDrd(dr32, sr32) do { \ +/* andl sr32,dr32 */ +#define ANDrd(sr32, dr32) do { \ emitm(&stream, 0x23, 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* or dr32,sr32 */ -#define ORrd(dr32, sr32) do { \ +/* orl sr32,dr32 */ +#define ORrd(sr32, dr32) do { \ emitm(&stream, 0x0b, 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* or r32,i32 */ -#define ORid(r32, i32) do { \ +/* orl i32,r32 */ +#define ORid(i32, r32) do { \ if (r32 == EAX) { \ emitm(&stream, 0x0d, 1); \ emitm(&stream, i32, 4); \ @@ -270,55 +270,55 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); } \ } while (0) -/* shl r32,i8 */ -#define SHLib(r32, i8) do { \ +/* shll i8,r32 */ +#define SHLib(i8, r32) do { \ emitm(&stream, 0xc1, 1); \ emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ emitm(&stream, i8, 1); \ } while (0) -/* shl dr32,cl */ +/* shll %cl,dr32 */ #define SHL_CLrb(dr32) do { \ emitm(&stream, 0xd3, 1); \ emitm(&stream, (7 << 5) | (dr32 & 0x7), 1); \ } while (0) -/* shr r32,i8 */ -#define SHRib(r32, i8) do { \ +/* shrl i8,r32 */ +#define SHRib(i8, r32) do { \ emitm(&stream, 0xc1, 1); \ emitm(&stream, (29 << 3) | (r32 & 0x7), 1); \ emitm(&stream, i8, 1); \ } while (0) -/* shr dr32,cl */ +/* shrl %cl,dr32 */ #define SHR_CLrb(dr32) do { \ emitm(&stream, 0xd3, 1); \ emitm(&stream, (29 << 3) | (dr32 & 0x7), 1); \ } while (0) -/* neg r32 */ +/* negl r32 */ #define NEGd(r32) do { \ emitm(&stream, 0xf7, 1); \ emitm(&stream, (27 << 3) | (r32 & 0x7), 1); \ } while (0) -/* cmp dr32,sr32[off] */ -#define CMPodd(dr32, sr32, off) do { \ +/* cmpl off(sr32),dr32 */ +#define CMPodd(off, sr32, dr32) do { \ emitm(&stream, (3 << 4) | 3 | (1 << 3), 1); \ emitm(&stream, \ (1 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ emitm(&stream, off, 1); \ } while (0) -/* cmp dr32,sr32 */ -#define CMPrd(dr32, sr32) do { \ +/* cmpl sr32,dr32 */ +#define CMPrd(sr32, dr32) do { \ emitm(&stream, 0x3b, 1); \ emitm(&stream, \ (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) -/* cmp dr32,i32 */ -#define CMPid(dr32, i32) do { \ +/* cmpl i32,dr32 */ +#define CMPid(i32, dr32) do { \ if (dr32 == EAX){ \ emitm(&stream, 0x3d, 1); \ emitm(&stream, i32, 4); \ @@ -329,7 +329,7 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); } \ } while (0) -/* jne off32 */ +/* jne off8 */ #define JNEb(off8) do { \ emitm(&stream, 0x75, 1); \ emitm(&stream, off8, 1); \ @@ -389,13 +389,13 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); emitm(&stream, off32, 4); \ } while (0) -/* xor eax,eax */ +/* xorl %eax,%eax */ #define ZERO_EAX() do { \ emitm(&stream, 0x31, 1); \ emitm(&stream, 0xc0, 1); \ } while (0) -/* xor edx,edx */ +/* xorl %edx,%edx */ #define ZERO_EDX() do { \ emitm(&stream, 0x31, 1); \ emitm(&stream, 0xd2, 1); \ |