diff options
Diffstat (limited to 'sys/i386/i386/bpf_jit_machdep.h')
-rw-r--r-- | sys/i386/i386/bpf_jit_machdep.h | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/sys/i386/i386/bpf_jit_machdep.h b/sys/i386/i386/bpf_jit_machdep.h index 1a93ee2..4d6cb40 100644 --- a/sys/i386/i386/bpf_jit_machdep.h +++ b/sys/i386/i386/bpf_jit_machdep.h @@ -103,14 +103,14 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* movl sr32,dr32 */ #define MOVrd(sr32, dr32) do { \ - emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ + emitm(&stream, 0x89, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* movl off(sr32),dr32 */ #define MOVodd(off, sr32, dr32) do { \ - emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ + emitm(&stream, 0x8b, 1); \ emitm(&stream, \ (1 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ emitm(&stream, off, 1); \ @@ -118,15 +118,14 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* movl (sr32,or32,1),dr32 */ #define MOVobd(sr32, or32, dr32) do { \ - emitm(&stream, (8 << 4) | 3 | (1 << 3), 1); \ + emitm(&stream, 0x8b, 1); \ emitm(&stream, ((dr32 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) /* 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, 0x8b66, 2); \ emitm(&stream, ((dr16 & 0x7) << 3) | 4, 1); \ emitm(&stream, ((or32 & 0x7) << 3) | (sr32 & 0x7), 1); \ } while (0) @@ -153,8 +152,7 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* xchgb %al,%ah */ #define SWAP_AX() do { \ - emitm(&stream, 0x86, 1); \ - emitm(&stream, 0xc4, 1); \ + emitm(&stream, 0xc486, 2); \ } while (0) /* pushl r32 */ @@ -169,15 +167,14 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* leave/ret */ #define LEAVE_RET() do { \ - emitm(&stream, 0xc9, 1); \ - emitm(&stream, 0xc3, 1); \ + emitm(&stream, 0xc3c9, 2); \ } while (0) /* addl sr32,dr32 */ #define ADDrd(sr32, dr32) do { \ - emitm(&stream, 0x03, 1); \ + emitm(&stream, 0x01, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* addl i32,%eax */ @@ -202,9 +199,9 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* subl sr32,dr32 */ #define SUBrd(sr32, dr32) do { \ - emitm(&stream, 0x2b, 1); \ + emitm(&stream, 0x29, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* subl i32,%eax */ @@ -227,8 +224,12 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* andb i8,r8 */ #define ANDib(i8, r8) do { \ - emitm(&stream, 0x80, 1); \ - emitm(&stream, (7 << 5) | r8, 1); \ + if (r8 == AL) { \ + emitm(&stream, 0x24, 1); \ + } else { \ + emitm(&stream, 0x80, 1); \ + emitm(&stream, (7 << 5) | r8, 1); \ + } \ emitm(&stream, i8, 1); \ } while (0) @@ -236,38 +237,36 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); #define ANDid(i32, r32) do { \ if (r32 == EAX) { \ emitm(&stream, 0x25, 1); \ - emitm(&stream, i32, 4); \ } else { \ emitm(&stream, 0x81, 1); \ emitm(&stream, (7 << 5) | r32, 1); \ - emitm(&stream, i32, 4); \ } \ + emitm(&stream, i32, 4); \ } while (0) /* andl sr32,dr32 */ #define ANDrd(sr32, dr32) do { \ - emitm(&stream, 0x23, 1); \ + emitm(&stream, 0x21, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* orl sr32,dr32 */ #define ORrd(sr32, dr32) do { \ - emitm(&stream, 0x0b, 1); \ + emitm(&stream, 0x09, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* orl i32,r32 */ #define ORid(i32, r32) do { \ if (r32 == EAX) { \ emitm(&stream, 0x0d, 1); \ - emitm(&stream, i32, 4); \ } else { \ emitm(&stream, 0x81, 1); \ emitm(&stream, (25 << 3) | r32, 1); \ - emitm(&stream, i32, 4); \ } \ + emitm(&stream, i32, 4); \ } while (0) /* shll i8,r32 */ @@ -304,7 +303,7 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* cmpl off(sr32),dr32 */ #define CMPodd(off, sr32, dr32) do { \ - emitm(&stream, (3 << 4) | 3 | (1 << 3), 1); \ + emitm(&stream, 0x3b, 1); \ emitm(&stream, \ (1 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ emitm(&stream, off, 1); \ @@ -312,9 +311,9 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* cmpl sr32,dr32 */ #define CMPrd(sr32, dr32) do { \ - emitm(&stream, 0x3b, 1); \ + emitm(&stream, 0x39, 1); \ emitm(&stream, \ - (3 << 6) | ((dr32 & 0x7) << 3) | (sr32 & 0x7), 1); \ + (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* cmpl i32,dr32 */ @@ -337,15 +336,13 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* je off32 */ #define JE(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x84, 1); \ + emitm(&stream, 0x840f, 2); \ emitm(&stream, off32, 4); \ } while (0) /* jle off32 */ #define JLE(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x8e, 1); \ + emitm(&stream, 0x8e0f, 2); \ emitm(&stream, off32, 4); \ } while (0) @@ -357,29 +354,25 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); /* ja off32 */ #define JA(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x87, 1); \ + emitm(&stream, 0x870f, 2); \ emitm(&stream, off32, 4); \ } while (0) /* jae off32 */ #define JAE(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x83, 1); \ + emitm(&stream, 0x830f, 2); \ emitm(&stream, off32, 4); \ } while (0) /* jg off32 */ #define JG(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x8f, 1); \ + emitm(&stream, 0x8f0f, 2); \ emitm(&stream, off32, 4); \ } while (0) /* jge off32 */ #define JGE(off32) do { \ - emitm(&stream, 0x0f, 1); \ - emitm(&stream, 0x8d, 1); \ + emitm(&stream, 0x8d0f, 2); \ emitm(&stream, off32, 4); \ } while (0) @@ -389,16 +382,10 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); emitm(&stream, off32, 4); \ } while (0) -/* xorl %eax,%eax */ -#define ZERO_EAX() do { \ - emitm(&stream, 0x31, 1); \ - emitm(&stream, 0xc0, 1); \ -} while (0) - -/* xorl %edx,%edx */ -#define ZERO_EDX() do { \ +/* xorl r32,r32 */ +#define ZEROrd(r32) do { \ emitm(&stream, 0x31, 1); \ - emitm(&stream, 0xd2, 1); \ + emitm(&stream, (3 << 6) | ((r32 & 0x7) << 3) | (r32 & 0x7), 1); \ } while (0) #endif /* _BPF_JIT_MACHDEP_H_ */ |