[RFC] x86 instruction decoder with userspace test code

Masami Hiramatsu mhiramat@redhat.com
Mon May 4 16:37:00 GMT 2009


Hi,

I've rewritten the x86(-64) instruction decoder with instruction
attribute table and a generator according to Peter's comments.

Currently, an opcode map file (x86-opcode-map.txt) is based on opcode
maps in Intel(R) Software Developers Manual Vol.2: Appendix.A, and it
contains below two types of opcode tables.

1-byte/2-bytes/3-bytes opcodes, which has 256 elements, are
written as below;
---
Table: table-name
Referrer: escaped-name
opcode: mnemonic|GrpXXX [operand1[,operand2...]] [(extra1)[,(extra2)...] [| 2nd-mnemonic ...]
 (or)
opcode: escape # escaped-name
EndTable
---

Group opcodes, which has 8 elements, are written as below;
---
GrpTable: GrpXXX
reg:  mnemonic [operand1[,operand2...]] [(extra1)[,(extra2)...] [| 2nd-mnemonic ...]
EndTable
---

These opcode maps do NOT include SSE and most of FP opcodes,
because those opcodes are not used in the kernel.

The generator(gen-insn-attr-x86.awk) translates the opcode maps
into a file which defines instruction attribute tables. The instruction
attributes are defined in inat.h and inat.c.


I attached insn decoder with user space test, which was originally
written by Jim. You can test the decoder can decode instruction length,
as following:

> Pull all the attached files into a directory and have a go -- e.g.,
> $ make
> $ objdump -d vmlinux | awk -f distill.awk | ./test_get_len [x86_64]

Known issues:
- 0x9b is an instruction (fwait), but the objdump treats it as a
  prefix.  For example 9b df ... can be disassembled as
	fstsw ...	// wait, then store status word
  or
	fwait		// wait
	fnstsw ...	// store status word without waiting
  and this instruction decoder decode 0x9b as an instruction.

  Anyway, according to Jim's investigation, the single-step stopped
  after the fwait, so it's no problem.

- Illegal instruction sequences(in some data/note sections), such
  as an x86_64 instruction that starts with 0x40, or a misplaced
  0x65 prefix. We can filtered out those instructions which start
  with "rex" or includes "(bad)".


I'll put x86-opcode-map.txt under arch/x86/lib, gen-insn-attr-x86.awk
under arch/x86/scripts/ and generate attribute tables at build time.

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: distill.awk
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gen-insn-attr-x86.awk
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: inat.c
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: inat.h
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment.h>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: insn.c
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0001.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: insn.h
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0001.h>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: insn_x86_user.h
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0002.h>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_get_len.c
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment-0002.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: x86-opcode-map.txt
URL: <http://sourceware.org/pipermail/systemtap/attachments/20090504/e7778fbb/attachment.txt>


More information about the Systemtap mailing list