Anda di halaman 1dari 4

[ < ] [ > ] [ << ] [ Up ] [ >> ]

[Top] [Contents] [Index] [ ? ]

6. Opcodes support
Opcodes support comes in the form of machine generated opcode tables as well as supporting routines. 6.1 Generated files List of generated files 6.2 The .opc file Target specific C code 6.3 Special assembler parsing needs Support for unusual syntax [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

6.1 Generated files


The basic interface is defined by i n c l u d e / o p c o d e / c g e n . h which is included by the machine generated < a r c h > d e s c . h . o p c o d e / c g e n . h can stand on its own for the target independent stuff, but to get target specific parts of the interface use < a r c h > d e s c . h . The generated files are: < a r c h > d e s c . h Defines macros, enums, and types used to describe the chip. < a r c h > d e s c . c Tables of various things describing the chip. This does not include assembler syntax nor semantic information. < a r c h > i b l d . c Routines for constructing and deconstructing instructions. < a r c h > o p c . h Declarations necessary for assembly/disassembly that aren't used elsewhere and thus left out of < a r c h > d e s c . h . < a r c h > o p c . c Assembler syntax tables. < a r c h > a s m . c Assembler support routines.

< a r c h > d i s . c Disassembler support routines. < a r c h > o p i n s t . c Operand instance tables. These describe which hardware elements are read and which are written for each instruction. This file isn't generated for all architectures, only ones that can make use of the data. For example the M32R uses them to emit warnings if the output of one parallel instruction is the input of another, and to control creating parallel instructions during optimizing assembly. [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

6.2 The .opc file


Files with suffix . o p c (e.g. m 3 2 r . o p c ) contain target specific C code that accompanies the cpu description file. The . o p c file is split into 4 sections: - opc.h This section contains additions to the generated $ t a r g e t o p c . h file. Typically defined here are these macros: #define CGEN_DIS_HASH_SIZE N Specifies the size of the hash table to use during disassembly. A hash table is built of the selected mach's instructions in order to speed up disassembly. #define CGEN_DIS_HASH(buffer, value) Given BUFFER, a pointer to the instruction being disassembled and VALUE, the value of the instruction as a host integer, return an index into the hash chain for the instruction. The result must be in the range 0 to CGEN_DIS_HASH_SIZE-1. VALUE is only usable if all instructions fit in a portable integer (32 bits). N.B. The result must depend on opcode portions of the instruction only. Normally one wants to use between 6 and 8 bits of opcode info for the hash table. However, some instruction sets don't use the same set of bits for all insns. Certainly they'll have at least one opcode bit in common with all insns, but beyond that it can vary. Here's a possible definition for sparc.
# u n d e fC G E N _ D I S _ H A S H _ S I Z E # d e f i n eC G E N _ D I S _ H A S H _ S I Z E2 5 6 # u n d e fC G E N _ D I S _ H A S H e x t e r nc o n s tu n s i g n e di n ts p a r c _ c g e n _ o p c o d e _ b i t s [ ] ; # d e f i n eC G E N _ D I S _ H A S H ( b u f f e r ,i n s n )\

( ( ( ( i n s n )> >2 4 )&0 x c 0 )\ |( ( ( i n s n )&s p a r c _ c g e n _ o p c o d e _ b i t s [ ( ( i n s n )> >3 0 )&3 ] )> >1 9 ) )

s p a r c _ c g e n _ o p c o d e _ b i t swould

be defined in the a s m . c section as

/ *I ti si m p o r t a n tt h a tw eo n l yl o o ka ti n s nc o d eb i t s a st h a ti sh o wt h eo p c o d et a b l ei sh a s h e d . O P C O D E _ B I T Si sat a b l eo fv a l i db i t sf o re a c ho ft h e m a i nt y p e s( 0 , 1 , 2 , 3 ) . * / c o n s tu n s i g n e di n ts p a r c _ c g e n _ o p c o d e _ b i t s [ 4 ]={ 0 x 0 1 c 0 0 0 0 0 ,0 x 0 ,0 x 0 1 f 8 0 0 0 0 ,0 x 0 1 f 8 0 0 0 0 } ;

- opc.c - asm.c This section contains additions to the generated $ t a r g e t a s m . c file. Typically defined here are functions used by operands with a p a r s edefine-operand handler spec. - dis.c This section contains additions to the generated $ t a r g e t d i s . c file. Typically defined here these macros: #define CGEN_PRINT_NORMAL(cd, info, value, attrs, pc, length) #define CGEN_PRINT_ADDRESS(cd, info, value, attrs, pc, length) #define CGEN_PRINT_INSN function_name #define CGEN_BFD_ARCH bfd_arch_<name> #define CGEN_COMPUTE_ISA(info) [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

6.3 Special assembler parsing needs


Often parsing of assembly instructions requires more than what a program-generated assembler can handle. For example one version of an instruction may only accept certain registers, rather than the entire set. Here's an example taken from the m 3 2 r architecture. 32 bit addresses are built up with a two instruction sequence: one to load the high 16 bits of a register, and another to o r -in the lower 16 bits.
s e t hr 0 , h i g h ( s o m e _ s y m b o l ) o r 3 r 0 , r 0 , l o w ( s o m e _ s y m b o l )

When assembling, special code must be called to recognize the h i g hand l o wpseudo-ops and generate the appropriate relocations. This is indicated by specifying a "parse handler" for the operand in question. Here is the d e f i n e o p e r a n dfor the lower 16 bit operand.
( d e f i n e o p e r a n d ( n a m eu l o 1 6 ) ( c o m m e n t" 1 6b i tu n s i g n e di m m e d i a t e ,f o rl o w ( ) " ) ( a t t r s ) ( t y p eh u l o 1 6 ) ( i n d e xf u i m m 1 6 ) ( h a n d l e r s( p a r s e" u l o 1 6 " ) ) )

The generated parser will call a function named p a r s e _ u l o 1 6for the immediate operand of the o r 3instruction. The name of the function is constructed by prepended "parse_" to the argument of the p a r s espec.
e r r m s g=p a r s e _ u l o 1 6( c d ,s t r p ,M 3 2 R _ O P E R A N D _ U L O 1 6 ,& f i e l d s > f _ u i m m 1 6 ) ;

But where does one put the p a r s e _ u l o 1 6function? Answer: in the a s m . c section of m 3 2 r . o p c . [ << ] [ >> ] [Top] [Contents] [Index] [ ? ]

This document was generated by Doug Evans on January, 28 2010 using texi2html 1.78 .

Anda mungkin juga menyukai