This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[commit] Add some macros to opcode/i386.h
- From: dje at google dot com (Doug Evans)
- To: binutils at sourceware dot org
- Date: Wed, 28 Jan 2009 16:38:01 -0800 (PST)
- Subject: [commit] Add some macros to opcode/i386.h
Hi. I've committed the following, approved on the gdb list by Dan.
2009-01-28 Doug Evans <dje@google.com>
* opcode/i386.h: Add multiple inclusion protection.
(EAX_REG_NUM,ECX_REG_NUM,EDX_REGNUM,EBX_REG_NUM,ESI_REG_NUM)
(EDI_REG_NUM): New macros.
(MODRM_MOD_FIELD,MODRM_REG_FIELD,MODRM_RM_FIELD): New macros.
(SIB_SCALE_FIELD,SIB_INDEX_FIELD,SIB_BASE_FIELD): New macros.
(REX_PREFIX_P): New macro.
Index: include/opcode/i386.h
===================================================================
RCS file: /cvs/src/src/include/opcode/i386.h,v
retrieving revision 1.79
diff -u -p -u -p -r1.79 i386.h
--- include/opcode/i386.h 3 Apr 2008 14:03:20 -0000 1.79
+++ include/opcode/i386.h 28 Jan 2009 08:31:34 -0000
@@ -35,6 +35,9 @@
The affected opcode map is dceX, dcfX, deeX, defX. */
+#ifndef OPCODE_I386_H
+#define OPCODE_I386_H
+
#ifndef SYSV386_COMPAT
/* Set non-zero for broken, compatible instructions. Set to zero for
non-broken opcodes at your peril. gcc generates SystemV/386
@@ -72,8 +75,14 @@
#define NOP_OPCODE (char) 0x90
/* register numbers */
-#define EBP_REG_NUM 5
+#define EAX_REG_NUM 0
+#define ECX_REG_NUM 1
+#define EDX_REG_NUM 2
+#define EBX_REG_NUM 3
#define ESP_REG_NUM 4
+#define EBP_REG_NUM 5
+#define ESI_REG_NUM 6
+#define EDI_REG_NUM 7
/* modrm_byte.regmem for twobyte escape */
#define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
@@ -87,9 +96,22 @@
#define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
#define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
+/* Extract fields from the mod/rm byte. */
+#define MODRM_MOD_FIELD(modrm) (((modrm) >> 6) & 3)
+#define MODRM_REG_FIELD(modrm) (((modrm) >> 3) & 7)
+#define MODRM_RM_FIELD(modrm) (((modrm) >> 0) & 7)
+
+/* Extract fields from the sib byte. */
+#define SIB_SCALE_FIELD(sib) (((sib) >> 6) & 3)
+#define SIB_INDEX_FIELD(sib) (((sib) >> 3) & 7)
+#define SIB_BASE_FIELD(sib) (((sib) >> 0) & 7)
+
/* x86-64 extension prefix. */
#define REX_OPCODE 0x40
+/* Non-zero if OPCODE is the rex prefix. */
+#define REX_PREFIX_P(opcode) (((opcode) & 0xf0) == REX_OPCODE)
+
/* Indicates 64 bit operand size. */
#define REX_W 8
/* High extension to reg field of modrm byte. */
@@ -113,3 +135,5 @@
/* max size of register name in insn mnemonics. */
#define MAX_REG_NAME_SIZE 8
+
+#endif /* OPCODE_I386_H */