1/*
2 *  TCC - Tiny C Compiler
3 *
4 *  Copyright (c) 2001-2004 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20#define _GNU_SOURCE
21
22// njn: inlined config.h
23//#include "config.h"
24//---------------------------------------------------------------------------
25/* Automatically generated by configure - do not modify */
26#define CONFIG_TCCDIR "tinycc-extras"
27#define GCC_MAJOR 3
28#define HOST_I386 1
29#define TCC_VERSION "0.9.23"
30//---------------------------------------------------------------------------
31
32// njn: comment out CONFIG_TCCBOOT branch
33//#ifdef CONFIG_TCCBOOT
34//
35//#include "tccboot.h"
36//#define CONFIG_TCC_STATIC
37//
38//#else
39
40#include <assert.h>
41#include <stdlib.h>
42#include <stdio.h>
43#include <stdarg.h>
44#include <string.h>
45#include <errno.h>
46#include <math.h>
47#include <unistd.h>
48#include <signal.h>
49#include <fcntl.h>
50#include <setjmp.h>
51#include <time.h>
52#ifdef WIN32
53#include <sys/timeb.h>
54#endif
55#ifndef WIN32
56#include <sys/time.h>
57#include <sys/ucontext.h>
58#endif
59
60//#endif /* !CONFIG_TCCBOOT */
61
62// Dummy variables used to avoid warnings like these:
63// warning: ignoring return value of ‘fwrite’, declared with attribute
64//    warn_unused_result
65char* dummy_char_star;
66size_t dummy_size_t;
67
68// njn: inlined elf.h
69//#include "elf.h"
70//---------------------------------------------------------------------------
71/* This file defines standard ELF types, structures, and macros.
72   Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
73   This file is part of the GNU C Library.
74   Contributed by Ian Lance Taylor <ian@cygnus.com>.
75
76   The GNU C Library is free software; you can redistribute it and/or
77   modify it under the terms of the GNU Library General Public License as
78   published by the Free Software Foundation; either version 2 of the
79   License, or (at your option) any later version.
80
81   The GNU C Library is distributed in the hope that it will be useful,
82   but WITHOUT ANY WARRANTY; without even the implied warranty of
83   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
84   Library General Public License for more details.
85
86   You should have received a copy of the GNU Library General Public
87   License along with the GNU C Library; see the file COPYING.LIB.  If not,
88   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
89   Boston, MA 02111-1307, USA.  */
90
91#ifndef _ELF_H
92#define	_ELF_H 1
93
94#ifndef WIN32
95#include <inttypes.h>
96#else
97#ifndef __int8_t_defined
98#define __int8_t_defined
99typedef signed char int8_t;
100typedef	short int int16_t;
101typedef	int int32_t;
102typedef long long int int64_t;
103#endif
104
105typedef unsigned char		uint8_t;
106typedef unsigned short int	uint16_t;
107typedef unsigned int		uint32_t;
108typedef unsigned long long int	uint64_t;
109#endif
110
111/* Standard ELF types.  */
112
113/* Type for a 16-bit quantity.  */
114typedef uint16_t Elf32_Half;
115typedef uint16_t Elf64_Half;
116
117/* Types for signed and unsigned 32-bit quantities.  */
118typedef uint32_t Elf32_Word;
119typedef	int32_t  Elf32_Sword;
120typedef uint32_t Elf64_Word;
121typedef	int32_t  Elf64_Sword;
122
123/* Types for signed and unsigned 64-bit quantities.  */
124typedef uint64_t Elf32_Xword;
125typedef	int64_t  Elf32_Sxword;
126typedef uint64_t Elf64_Xword;
127typedef	int64_t  Elf64_Sxword;
128
129/* Type of addresses.  */
130typedef uint32_t Elf32_Addr;
131typedef uint64_t Elf64_Addr;
132
133/* Type of file offsets.  */
134typedef uint32_t Elf32_Off;
135typedef uint64_t Elf64_Off;
136
137/* Type for section indices, which are 16-bit quantities.  */
138typedef uint16_t Elf32_Section;
139typedef uint16_t Elf64_Section;
140
141/* Type of symbol indices.  */
142typedef uint32_t Elf32_Symndx;
143typedef uint64_t Elf64_Symndx;
144
145
146/* The ELF file header.  This appears at the start of every ELF file.  */
147
148#define EI_NIDENT (16)
149
150typedef struct
151{
152  unsigned char	e_ident[EI_NIDENT];	/* Magic number and other info */
153  Elf32_Half	e_type;			/* Object file type */
154  Elf32_Half	e_machine;		/* Architecture */
155  Elf32_Word	e_version;		/* Object file version */
156  Elf32_Addr	e_entry;		/* Entry point virtual address */
157  Elf32_Off	e_phoff;		/* Program header table file offset */
158  Elf32_Off	e_shoff;		/* Section header table file offset */
159  Elf32_Word	e_flags;		/* Processor-specific flags */
160  Elf32_Half	e_ehsize;		/* ELF header size in bytes */
161  Elf32_Half	e_phentsize;		/* Program header table entry size */
162  Elf32_Half	e_phnum;		/* Program header table entry count */
163  Elf32_Half	e_shentsize;		/* Section header table entry size */
164  Elf32_Half	e_shnum;		/* Section header table entry count */
165  Elf32_Half	e_shstrndx;		/* Section header string table index */
166} Elf32_Ehdr;
167
168typedef struct
169{
170  unsigned char	e_ident[EI_NIDENT];	/* Magic number and other info */
171  Elf64_Half	e_type;			/* Object file type */
172  Elf64_Half	e_machine;		/* Architecture */
173  Elf64_Word	e_version;		/* Object file version */
174  Elf64_Addr	e_entry;		/* Entry point virtual address */
175  Elf64_Off	e_phoff;		/* Program header table file offset */
176  Elf64_Off	e_shoff;		/* Section header table file offset */
177  Elf64_Word	e_flags;		/* Processor-specific flags */
178  Elf64_Half	e_ehsize;		/* ELF header size in bytes */
179  Elf64_Half	e_phentsize;		/* Program header table entry size */
180  Elf64_Half	e_phnum;		/* Program header table entry count */
181  Elf64_Half	e_shentsize;		/* Section header table entry size */
182  Elf64_Half	e_shnum;		/* Section header table entry count */
183  Elf64_Half	e_shstrndx;		/* Section header string table index */
184} Elf64_Ehdr;
185
186/* Fields in the e_ident array.  The EI_* macros are indices into the
187   array.  The macros under each EI_* macro are the values the byte
188   may have.  */
189
190#define EI_MAG0		0		/* File identification byte 0 index */
191#define ELFMAG0		0x7f		/* Magic number byte 0 */
192
193#define EI_MAG1		1		/* File identification byte 1 index */
194#define ELFMAG1		'E'		/* Magic number byte 1 */
195
196#define EI_MAG2		2		/* File identification byte 2 index */
197#define ELFMAG2		'L'		/* Magic number byte 2 */
198
199#define EI_MAG3		3		/* File identification byte 3 index */
200#define ELFMAG3		'F'		/* Magic number byte 3 */
201
202/* Conglomeration of the identification bytes, for easy testing as a word.  */
203#define	ELFMAG		"\177ELF"
204#define	SELFMAG		4
205
206#define EI_CLASS	4		/* File class byte index */
207#define ELFCLASSNONE	0		/* Invalid class */
208#define ELFCLASS32	1		/* 32-bit objects */
209#define ELFCLASS64	2		/* 64-bit objects */
210#define ELFCLASSNUM	3
211
212#define EI_DATA		5		/* Data encoding byte index */
213#define ELFDATANONE	0		/* Invalid data encoding */
214#define ELFDATA2LSB	1		/* 2's complement, little endian */
215#define ELFDATA2MSB	2		/* 2's complement, big endian */
216#define ELFDATANUM	3
217
218#define EI_VERSION	6		/* File version byte index */
219					/* Value must be EV_CURRENT */
220
221#define EI_OSABI	7		/* OS ABI identification */
222#define ELFOSABI_SYSV		0	/* UNIX System V ABI */
223#define ELFOSABI_HPUX		1	/* HP-UX */
224#define ELFOSABI_FREEBSD        9       /* Free BSD */
225#define ELFOSABI_ARM		97	/* ARM */
226#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
227
228#define EI_ABIVERSION	8		/* ABI version */
229
230#define EI_PAD		9		/* Byte index of padding bytes */
231
232/* Legal values for e_type (object file type).  */
233
234#define ET_NONE		0		/* No file type */
235#define ET_REL		1		/* Relocatable file */
236#define ET_EXEC		2		/* Executable file */
237#define ET_DYN		3		/* Shared object file */
238#define ET_CORE		4		/* Core file */
239#define	ET_NUM		5		/* Number of defined types */
240#define ET_LOPROC	0xff00		/* Processor-specific */
241#define ET_HIPROC	0xffff		/* Processor-specific */
242
243/* Legal values for e_machine (architecture).  */
244
245#define EM_NONE		 0		/* No machine */
246#define EM_M32		 1		/* AT&T WE 32100 */
247#define EM_SPARC	 2		/* SUN SPARC */
248#define EM_386		 3		/* Intel 80386 */
249#define EM_68K		 4		/* Motorola m68k family */
250#define EM_88K		 5		/* Motorola m88k family */
251#define EM_486		 6		/* Intel 80486 */
252#define EM_860		 7		/* Intel 80860 */
253#define EM_MIPS		 8		/* MIPS R3000 big-endian */
254#define EM_S370		 9		/* Amdahl */
255#define EM_MIPS_RS4_BE	10		/* MIPS R4000 big-endian */
256#define EM_RS6000	11		/* RS6000 */
257
258#define EM_PARISC	15		/* HPPA */
259#define EM_nCUBE	16		/* nCUBE */
260#define EM_VPP500	17		/* Fujitsu VPP500 */
261#define EM_SPARC32PLUS	18		/* Sun's "v8plus" */
262#define EM_960		19		/* Intel 80960 */
263#define EM_PPC		20		/* PowerPC */
264
265#define EM_V800		36		/* NEC V800 series */
266#define EM_FR20		37		/* Fujitsu FR20 */
267#define EM_RH32		38		/* TRW RH32 */
268#define EM_MMA		39		/* Fujitsu MMA */
269#define EM_ARM		40		/* ARM */
270#define EM_FAKE_ALPHA	41		/* Digital Alpha */
271#define EM_SH		42		/* Hitachi SH */
272#define EM_SPARCV9	43		/* SPARC v9 64-bit */
273#define EM_TRICORE	44		/* Siemens Tricore */
274#define EM_ARC		45		/* Argonaut RISC Core */
275#define EM_H8_300	46		/* Hitachi H8/300 */
276#define EM_H8_300H	47		/* Hitachi H8/300H */
277#define EM_H8S		48		/* Hitachi H8S */
278#define EM_H8_500	49		/* Hitachi H8/500 */
279#define EM_IA_64	50		/* Intel Merced */
280#define EM_MIPS_X	51		/* Stanford MIPS-X */
281#define EM_COLDFIRE	52		/* Motorola Coldfire */
282#define EM_68HC12	53		/* Motorola M68HC12 */
283#define EM_NUM		54
284
285/* If it is necessary to assign new unofficial EM_* values, please
286   pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
287   chances of collision with official or non-GNU unofficial values.  */
288
289#define EM_ALPHA	0x9026
290#define EM_C60          0x9c60
291
292/* Legal values for e_version (version).  */
293
294#define EV_NONE		0		/* Invalid ELF version */
295#define EV_CURRENT	1		/* Current version */
296#define EV_NUM		2
297
298/* Section header.  */
299
300typedef struct
301{
302  Elf32_Word	sh_name;		/* Section name (string tbl index) */
303  Elf32_Word	sh_type;		/* Section type */
304  Elf32_Word	sh_flags;		/* Section flags */
305  Elf32_Addr	sh_addr;		/* Section virtual addr at execution */
306  Elf32_Off	sh_offset;		/* Section file offset */
307  Elf32_Word	sh_size;		/* Section size in bytes */
308  Elf32_Word	sh_link;		/* Link to another section */
309  Elf32_Word	sh_info;		/* Additional section information */
310  Elf32_Word	sh_addralign;		/* Section alignment */
311  Elf32_Word	sh_entsize;		/* Entry size if section holds table */
312} Elf32_Shdr;
313
314typedef struct
315{
316  Elf64_Word	sh_name;		/* Section name (string tbl index) */
317  Elf64_Word	sh_type;		/* Section type */
318  Elf64_Xword	sh_flags;		/* Section flags */
319  Elf64_Addr	sh_addr;		/* Section virtual addr at execution */
320  Elf64_Off	sh_offset;		/* Section file offset */
321  Elf64_Xword	sh_size;		/* Section size in bytes */
322  Elf64_Word	sh_link;		/* Link to another section */
323  Elf64_Word	sh_info;		/* Additional section information */
324  Elf64_Xword	sh_addralign;		/* Section alignment */
325  Elf64_Xword	sh_entsize;		/* Entry size if section holds table */
326} Elf64_Shdr;
327
328/* Special section indices.  */
329
330#define SHN_UNDEF	0		/* Undefined section */
331#define SHN_LORESERVE	0xff00		/* Start of reserved indices */
332#define SHN_LOPROC	0xff00		/* Start of processor-specific */
333#define SHN_HIPROC	0xff1f		/* End of processor-specific */
334#define SHN_ABS		0xfff1		/* Associated symbol is absolute */
335#define SHN_COMMON	0xfff2		/* Associated symbol is common */
336#define SHN_HIRESERVE	0xffff		/* End of reserved indices */
337
338/* Legal values for sh_type (section type).  */
339
340#define SHT_NULL	 0		/* Section header table entry unused */
341#define SHT_PROGBITS	 1		/* Program data */
342#define SHT_SYMTAB	 2		/* Symbol table */
343#define SHT_STRTAB	 3		/* String table */
344#define SHT_RELA	 4		/* Relocation entries with addends */
345#define SHT_HASH	 5		/* Symbol hash table */
346#define SHT_DYNAMIC	 6		/* Dynamic linking information */
347#define SHT_NOTE	 7		/* Notes */
348#define SHT_NOBITS	 8		/* Program space with no data (bss) */
349#define SHT_REL		 9		/* Relocation entries, no addends */
350#define SHT_SHLIB	 10		/* Reserved */
351#define SHT_DYNSYM	 11		/* Dynamic linker symbol table */
352#define	SHT_NUM		 12		/* Number of defined types.  */
353#define SHT_LOOS	 0x60000000	/* Start OS-specific */
354#define SHT_LOSUNW	 0x6ffffffb	/* Sun-specific low bound.  */
355#define SHT_SUNW_COMDAT  0x6ffffffb
356#define SHT_SUNW_syminfo 0x6ffffffc
357#define SHT_GNU_verdef	 0x6ffffffd	/* Version definition section.  */
358#define SHT_GNU_verneed	 0x6ffffffe	/* Version needs section.  */
359#define SHT_GNU_versym	 0x6fffffff	/* Version symbol table.  */
360#define SHT_HISUNW	 0x6fffffff	/* Sun-specific high bound.  */
361#define SHT_HIOS	 0x6fffffff	/* End OS-specific type */
362#define SHT_LOPROC	 0x70000000	/* Start of processor-specific */
363#define SHT_HIPROC	 0x7fffffff	/* End of processor-specific */
364#define SHT_LOUSER	 0x80000000	/* Start of application-specific */
365#define SHT_HIUSER	 0x8fffffff	/* End of application-specific */
366
367/* Legal values for sh_flags (section flags).  */
368
369#define SHF_WRITE	(1 << 0)	/* Writable */
370#define SHF_ALLOC	(1 << 1)	/* Occupies memory during execution */
371#define SHF_EXECINSTR	(1 << 2)	/* Executable */
372#define SHF_MASKPROC	0xf0000000	/* Processor-specific */
373
374/* Symbol table entry.  */
375
376typedef struct
377{
378  Elf32_Word	st_name;		/* Symbol name (string tbl index) */
379  Elf32_Addr	st_value;		/* Symbol value */
380  Elf32_Word	st_size;		/* Symbol size */
381  unsigned char	st_info;		/* Symbol type and binding */
382  unsigned char	st_other;		/* No defined meaning, 0 */
383  Elf32_Section	st_shndx;		/* Section index */
384} Elf32_Sym;
385
386typedef struct
387{
388  Elf64_Word	st_name;		/* Symbol name (string tbl index) */
389  unsigned char	st_info;		/* Symbol type and binding */
390  unsigned char st_other;		/* No defined meaning, 0 */
391  Elf64_Section	st_shndx;		/* Section index */
392  Elf64_Addr	st_value;		/* Symbol value */
393  Elf64_Xword	st_size;		/* Symbol size */
394} Elf64_Sym;
395
396/* The syminfo section if available contains additional information about
397   every dynamic symbol.  */
398
399typedef struct
400{
401  Elf32_Half si_boundto;		/* Direct bindings, symbol bound to */
402  Elf32_Half si_flags;			/* Per symbol flags */
403} Elf32_Syminfo;
404
405typedef struct
406{
407  Elf64_Half si_boundto;		/* Direct bindings, symbol bound to */
408  Elf64_Half si_flags;			/* Per symbol flags */
409} Elf64_Syminfo;
410
411/* Possible values for si_boundto.  */
412#define SYMINFO_BT_SELF		0xffff	/* Symbol bound to self */
413#define SYMINFO_BT_PARENT	0xfffe	/* Symbol bound to parent */
414#define SYMINFO_BT_LOWRESERVE	0xff00	/* Beginning of reserved entries */
415
416/* Possible bitmasks for si_flags.  */
417#define SYMINFO_FLG_DIRECT	0x0001	/* Direct bound symbol */
418#define SYMINFO_FLG_PASSTHRU	0x0002	/* Pass-thru symbol for translator */
419#define SYMINFO_FLG_COPY	0x0004	/* Symbol is a copy-reloc */
420#define SYMINFO_FLG_LAZYLOAD	0x0008	/* Symbol bound to object to be lazy
421					   loaded */
422/* Syminfo version values.  */
423#define SYMINFO_NONE		0
424#define SYMINFO_CURRENT		1
425#define SYMINFO_NUM		2
426
427
428/* Special section index.  */
429
430#define SHN_UNDEF	0		/* No section, undefined symbol.  */
431
432/* How to extract and insert information held in the st_info field.  */
433
434#define ELF32_ST_BIND(val)		(((unsigned char) (val)) >> 4)
435#define ELF32_ST_TYPE(val)		((val) & 0xf)
436#define ELF32_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
437
438/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field.  */
439#define ELF64_ST_BIND(val)		ELF32_ST_BIND (val)
440#define ELF64_ST_TYPE(val)		ELF32_ST_TYPE (val)
441#define ELF64_ST_INFO(bind, type)	ELF32_ST_INFO ((bind), (type))
442
443/* Legal values for ST_BIND subfield of st_info (symbol binding).  */
444
445#define STB_LOCAL	0		/* Local symbol */
446#define STB_GLOBAL	1		/* Global symbol */
447#define STB_WEAK	2		/* Weak symbol */
448#define	STB_NUM		3		/* Number of defined types.  */
449#define STB_LOOS	10		/* Start of OS-specific */
450#define STB_HIOS	12		/* End of OS-specific */
451#define STB_LOPROC	13		/* Start of processor-specific */
452#define STB_HIPROC	15		/* End of processor-specific */
453
454/* Legal values for ST_TYPE subfield of st_info (symbol type).  */
455
456#define STT_NOTYPE	0		/* Symbol type is unspecified */
457#define STT_OBJECT	1		/* Symbol is a data object */
458#define STT_FUNC	2		/* Symbol is a code object */
459#define STT_SECTION	3		/* Symbol associated with a section */
460#define STT_FILE	4		/* Symbol's name is file name */
461#define	STT_NUM		5		/* Number of defined types.  */
462#define STT_LOOS	11		/* Start of OS-specific */
463#define STT_HIOS	12		/* End of OS-specific */
464#define STT_LOPROC	13		/* Start of processor-specific */
465#define STT_HIPROC	15		/* End of processor-specific */
466
467
468/* Symbol table indices are found in the hash buckets and chain table
469   of a symbol hash table section.  This special index value indicates
470   the end of a chain, meaning no further symbols are found in that bucket.  */
471
472#define STN_UNDEF	0		/* End of a chain.  */
473
474
475/* How to extract and insert information held in the st_other field.  */
476
477#define ELF32_ST_VISIBILITY(o)	((o) & 0x03)
478
479/* For ELF64 the definitions are the same.  */
480#define ELF64_ST_VISIBILITY(o)	ELF32_ST_VISIBILITY (o)
481
482/* Symbol visibility specification encoded in the st_other field.  */
483#define STV_DEFAULT	0		/* Default symbol visibility rules */
484#define STV_INTERNAL	1		/* Processor specific hidden class */
485#define STV_HIDDEN	2		/* Sym unavailable in other modules */
486#define STV_PROTECTED	3		/* Not preemptible, not exported */
487
488
489/* Relocation table entry without addend (in section of type SHT_REL).  */
490
491typedef struct
492{
493  Elf32_Addr	r_offset;		/* Address */
494  Elf32_Word	r_info;			/* Relocation type and symbol index */
495} Elf32_Rel;
496
497/* I have seen two different definitions of the Elf64_Rel and
498   Elf64_Rela structures, so we'll leave them out until Novell (or
499   whoever) gets their act together.  */
500/* The following, at least, is used on Sparc v9, MIPS, and Alpha.  */
501
502typedef struct
503{
504  Elf64_Addr	r_offset;		/* Address */
505  Elf64_Xword	r_info;			/* Relocation type and symbol index */
506} Elf64_Rel;
507
508/* Relocation table entry with addend (in section of type SHT_RELA).  */
509
510typedef struct
511{
512  Elf32_Addr	r_offset;		/* Address */
513  Elf32_Word	r_info;			/* Relocation type and symbol index */
514  Elf32_Sword	r_addend;		/* Addend */
515} Elf32_Rela;
516
517typedef struct
518{
519  Elf64_Addr	r_offset;		/* Address */
520  Elf64_Xword	r_info;			/* Relocation type and symbol index */
521  Elf64_Sxword	r_addend;		/* Addend */
522} Elf64_Rela;
523
524/* How to extract and insert information held in the r_info field.  */
525
526#define ELF32_R_SYM(val)		((val) >> 8)
527#define ELF32_R_TYPE(val)		((val) & 0xff)
528#define ELF32_R_INFO(sym, type)		(((sym) << 8) + ((type) & 0xff))
529
530#define ELF64_R_SYM(i)			((i) >> 32)
531#define ELF64_R_TYPE(i)			((i) & 0xffffffff)
532#define ELF64_R_INFO(sym,type)		(((sym) << 32) + (type))
533
534/* Program segment header.  */
535
536typedef struct
537{
538  Elf32_Word	p_type;			/* Segment type */
539  Elf32_Off	p_offset;		/* Segment file offset */
540  Elf32_Addr	p_vaddr;		/* Segment virtual address */
541  Elf32_Addr	p_paddr;		/* Segment physical address */
542  Elf32_Word	p_filesz;		/* Segment size in file */
543  Elf32_Word	p_memsz;		/* Segment size in memory */
544  Elf32_Word	p_flags;		/* Segment flags */
545  Elf32_Word	p_align;		/* Segment alignment */
546} Elf32_Phdr;
547
548typedef struct
549{
550  Elf64_Word	p_type;			/* Segment type */
551  Elf64_Word	p_flags;		/* Segment flags */
552  Elf64_Off	p_offset;		/* Segment file offset */
553  Elf64_Addr	p_vaddr;		/* Segment virtual address */
554  Elf64_Addr	p_paddr;		/* Segment physical address */
555  Elf64_Xword	p_filesz;		/* Segment size in file */
556  Elf64_Xword	p_memsz;		/* Segment size in memory */
557  Elf64_Xword	p_align;		/* Segment alignment */
558} Elf64_Phdr;
559
560/* Legal values for p_type (segment type).  */
561
562#define	PT_NULL		0		/* Program header table entry unused */
563#define PT_LOAD		1		/* Loadable program segment */
564#define PT_DYNAMIC	2		/* Dynamic linking information */
565#define PT_INTERP	3		/* Program interpreter */
566#define PT_NOTE		4		/* Auxiliary information */
567#define PT_SHLIB	5		/* Reserved */
568#define PT_PHDR		6		/* Entry for header table itself */
569#define	PT_NUM		7		/* Number of defined types.  */
570#define PT_LOOS		0x60000000	/* Start of OS-specific */
571#define PT_HIOS		0x6fffffff	/* End of OS-specific */
572#define PT_LOPROC	0x70000000	/* Start of processor-specific */
573#define PT_HIPROC	0x7fffffff	/* End of processor-specific */
574
575/* Legal values for p_flags (segment flags).  */
576
577#define PF_X		(1 << 0)	/* Segment is executable */
578#define PF_W		(1 << 1)	/* Segment is writable */
579#define PF_R		(1 << 2)	/* Segment is readable */
580#define PF_MASKPROC	0xf0000000	/* Processor-specific */
581
582/* Legal values for note segment descriptor types for core files. */
583
584#define NT_PRSTATUS	1		/* Contains copy of prstatus struct */
585#define NT_FPREGSET	2		/* Contains copy of fpregset struct */
586#define NT_PRPSINFO	3		/* Contains copy of prpsinfo struct */
587#define NT_PRXREG	4		/* Contains copy of prxregset struct */
588#define NT_PLATFORM	5		/* String from sysinfo(SI_PLATFORM) */
589#define NT_AUXV		6		/* Contains copy of auxv array */
590#define NT_GWINDOWS	7		/* Contains copy of gwindows struct */
591#define NT_PSTATUS	10		/* Contains copy of pstatus struct */
592#define NT_PSINFO	13		/* Contains copy of psinfo struct */
593#define NT_PRCRED	14		/* Contains copy of prcred struct */
594#define NT_UTSNAME	15		/* Contains copy of utsname struct */
595#define NT_LWPSTATUS	16		/* Contains copy of lwpstatus struct */
596#define NT_LWPSINFO	17		/* Contains copy of lwpinfo struct */
597
598/* Legal values for the  note segment descriptor types for object files.  */
599
600#define NT_VERSION	1		/* Contains a version string.  */
601
602
603/* Dynamic section entry.  */
604
605typedef struct
606{
607  Elf32_Sword	d_tag;			/* Dynamic entry type */
608  union
609    {
610      Elf32_Word d_val;			/* Integer value */
611      Elf32_Addr d_ptr;			/* Address value */
612    } d_un;
613} Elf32_Dyn;
614
615typedef struct
616{
617  Elf64_Sxword	d_tag;			/* Dynamic entry type */
618  union
619    {
620      Elf64_Xword d_val;		/* Integer value */
621      Elf64_Addr d_ptr;			/* Address value */
622    } d_un;
623} Elf64_Dyn;
624
625/* Legal values for d_tag (dynamic entry type).  */
626
627#define DT_NULL		0		/* Marks end of dynamic section */
628#define DT_NEEDED	1		/* Name of needed library */
629#define DT_PLTRELSZ	2		/* Size in bytes of PLT relocs */
630#define DT_PLTGOT	3		/* Processor defined value */
631#define DT_HASH		4		/* Address of symbol hash table */
632#define DT_STRTAB	5		/* Address of string table */
633#define DT_SYMTAB	6		/* Address of symbol table */
634#define DT_RELA		7		/* Address of Rela relocs */
635#define DT_RELASZ	8		/* Total size of Rela relocs */
636#define DT_RELAENT	9		/* Size of one Rela reloc */
637#define DT_STRSZ	10		/* Size of string table */
638#define DT_SYMENT	11		/* Size of one symbol table entry */
639#define DT_INIT		12		/* Address of init function */
640#define DT_FINI		13		/* Address of termination function */
641#define DT_SONAME	14		/* Name of shared object */
642#define DT_RPATH	15		/* Library search path */
643#define DT_SYMBOLIC	16		/* Start symbol search here */
644#define DT_REL		17		/* Address of Rel relocs */
645#define DT_RELSZ	18		/* Total size of Rel relocs */
646#define DT_RELENT	19		/* Size of one Rel reloc */
647#define DT_PLTREL	20		/* Type of reloc in PLT */
648#define DT_DEBUG	21		/* For debugging; unspecified */
649#define DT_TEXTREL	22		/* Reloc might modify .text */
650#define DT_JMPREL	23		/* Address of PLT relocs */
651#define	DT_BIND_NOW	24		/* Process relocations of object */
652#define	DT_INIT_ARRAY	25		/* Array with addresses of init fct */
653#define	DT_FINI_ARRAY	26		/* Array with addresses of fini fct */
654#define	DT_INIT_ARRAYSZ	27		/* Size in bytes of DT_INIT_ARRAY */
655#define	DT_FINI_ARRAYSZ	28		/* Size in bytes of DT_FINI_ARRAY */
656#define	DT_NUM		29		/* Number used */
657#define DT_LOOS		0x60000000	/* Start of OS-specific */
658#define DT_HIOS		0x6fffffff	/* End of OS-specific */
659#define DT_LOPROC	0x70000000	/* Start of processor-specific */
660#define DT_HIPROC	0x7fffffff	/* End of processor-specific */
661#define	DT_PROCNUM	DT_MIPS_NUM	/* Most used by any processor */
662
663/* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the
664   Dyn.d_un.d_val field of the Elf*_Dyn structure.  This follows Sun's
665   approach.  */
666#define DT_VALRNGLO	0x6ffffd00
667#define DT_POSFLAG_1	0x6ffffdfd	/* Flags for DT_* entries, effecting
668					   the following DT_* entry.  */
669#define DT_SYMINSZ	0x6ffffdfe	/* Size of syminfo table (in bytes) */
670#define DT_SYMINENT	0x6ffffdff	/* Entry size of syminfo */
671#define DT_VALRNGHI	0x6ffffdff
672
673/* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
674   Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
675
676   If any adjustment is made to the ELF object after it has been
677   built these entries will need to be adjusted.  */
678#define DT_ADDRRNGLO	0x6ffffe00
679#define DT_SYMINFO	0x6ffffeff	/* syminfo table */
680#define DT_ADDRRNGHI	0x6ffffeff
681
682/* The versioning entry types.  The next are defined as part of the
683   GNU extension.  */
684#define DT_VERSYM	0x6ffffff0
685
686/* These were chosen by Sun.  */
687#define DT_FLAGS_1	0x6ffffffb	/* State flags, see DF_1_* below.  */
688#define	DT_VERDEF	0x6ffffffc	/* Address of version definition
689					   table */
690#define	DT_VERDEFNUM	0x6ffffffd	/* Number of version definitions */
691#define	DT_VERNEED	0x6ffffffe	/* Address of table with needed
692					   versions */
693#define	DT_VERNEEDNUM	0x6fffffff	/* Number of needed versions */
694#define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag))	/* Reverse order! */
695#define DT_VERSIONTAGNUM 16
696
697/* Sun added these machine-independent extensions in the "processor-specific"
698   range.  Be compatible.  */
699#define DT_AUXILIARY    0x7ffffffd      /* Shared object to load before self */
700#define DT_FILTER       0x7fffffff      /* Shared object to get values from */
701#define DT_EXTRATAGIDX(tag)	((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
702#define DT_EXTRANUM	3
703
704/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
705   entry in the dynamic section.  */
706#define DF_1_NOW	0x00000001	/* Set RTLD_NOW for this object.  */
707#define DF_1_GLOBAL	0x00000002	/* Set RTLD_GLOBAL for this object.  */
708#define DF_1_GROUP	0x00000004	/* Set RTLD_GROUP for this object.  */
709#define DF_1_NODELETE	0x00000008	/* Set RTLD_NODELETE for this object.*/
710#define DF_1_LOADFLTR	0x00000010	/* Trigger filtee loading at runtime.*/
711#define DF_1_INITFIRST	0x00000020	/* Set RTLD_INITFIRST for this object*/
712#define DF_1_NOOPEN	0x00000040	/* Set RTLD_NOOPEN for this object.  */
713
714/* Version definition sections.  */
715
716typedef struct
717{
718  Elf32_Half	vd_version;		/* Version revision */
719  Elf32_Half	vd_flags;		/* Version information */
720  Elf32_Half	vd_ndx;			/* Version Index */
721  Elf32_Half	vd_cnt;			/* Number of associated aux entries */
722  Elf32_Word	vd_hash;		/* Version name hash value */
723  Elf32_Word	vd_aux;			/* Offset in bytes to verdaux array */
724  Elf32_Word	vd_next;		/* Offset in bytes to next verdef
725					   entry */
726} Elf32_Verdef;
727
728typedef struct
729{
730  Elf64_Half	vd_version;		/* Version revision */
731  Elf64_Half	vd_flags;		/* Version information */
732  Elf64_Half	vd_ndx;			/* Version Index */
733  Elf64_Half	vd_cnt;			/* Number of associated aux entries */
734  Elf64_Word	vd_hash;		/* Version name hash value */
735  Elf64_Word	vd_aux;			/* Offset in bytes to verdaux array */
736  Elf64_Word	vd_next;		/* Offset in bytes to next verdef
737					   entry */
738} Elf64_Verdef;
739
740
741/* Legal values for vd_version (version revision).  */
742#define VER_DEF_NONE	0		/* No version */
743#define VER_DEF_CURRENT	1		/* Current version */
744#define VER_DEF_NUM	2		/* Given version number */
745
746/* Legal values for vd_flags (version information flags).  */
747#define VER_FLG_BASE	0x1		/* Version definition of file itself */
748#define VER_FLG_WEAK	0x2		/* Weak version identifier */
749
750/* Auxialiary version information.  */
751
752typedef struct
753{
754  Elf32_Word	vda_name;		/* Version or dependency names */
755  Elf32_Word	vda_next;		/* Offset in bytes to next verdaux
756					   entry */
757} Elf32_Verdaux;
758
759typedef struct
760{
761  Elf64_Word	vda_name;		/* Version or dependency names */
762  Elf64_Word	vda_next;		/* Offset in bytes to next verdaux
763					   entry */
764} Elf64_Verdaux;
765
766
767/* Version dependency section.  */
768
769typedef struct
770{
771  Elf32_Half	vn_version;		/* Version of structure */
772  Elf32_Half	vn_cnt;			/* Number of associated aux entries */
773  Elf32_Word	vn_file;		/* Offset of filename for this
774					   dependency */
775  Elf32_Word	vn_aux;			/* Offset in bytes to vernaux array */
776  Elf32_Word	vn_next;		/* Offset in bytes to next verneed
777					   entry */
778} Elf32_Verneed;
779
780typedef struct
781{
782  Elf64_Half	vn_version;		/* Version of structure */
783  Elf64_Half	vn_cnt;			/* Number of associated aux entries */
784  Elf64_Word	vn_file;		/* Offset of filename for this
785					   dependency */
786  Elf64_Word	vn_aux;			/* Offset in bytes to vernaux array */
787  Elf64_Word	vn_next;		/* Offset in bytes to next verneed
788					   entry */
789} Elf64_Verneed;
790
791
792/* Legal values for vn_version (version revision).  */
793#define VER_NEED_NONE	 0		/* No version */
794#define VER_NEED_CURRENT 1		/* Current version */
795#define VER_NEED_NUM	 2		/* Given version number */
796
797/* Auxiliary needed version information.  */
798
799typedef struct
800{
801  Elf32_Word	vna_hash;		/* Hash value of dependency name */
802  Elf32_Half	vna_flags;		/* Dependency specific information */
803  Elf32_Half	vna_other;		/* Unused */
804  Elf32_Word	vna_name;		/* Dependency name string offset */
805  Elf32_Word	vna_next;		/* Offset in bytes to next vernaux
806					   entry */
807} Elf32_Vernaux;
808
809typedef struct
810{
811  Elf64_Word	vna_hash;		/* Hash value of dependency name */
812  Elf64_Half	vna_flags;		/* Dependency specific information */
813  Elf64_Half	vna_other;		/* Unused */
814  Elf64_Word	vna_name;		/* Dependency name string offset */
815  Elf64_Word	vna_next;		/* Offset in bytes to next vernaux
816					   entry */
817} Elf64_Vernaux;
818
819
820/* Legal values for vna_flags.  */
821#define VER_FLG_WEAK	0x2		/* Weak version identifier */
822
823
824/* Auxiliary vector.  */
825
826/* This vector is normally only used by the program interpreter.  The
827   usual definition in an ABI supplement uses the name auxv_t.  The
828   vector is not usually defined in a standard <elf.h> file, but it
829   can't hurt.  We rename it to avoid conflicts.  The sizes of these
830   types are an arrangement between the exec server and the program
831   interpreter, so we don't fully specify them here.  */
832
833typedef struct
834{
835  int a_type;			/* Entry type */
836  union
837    {
838      long int a_val;		/* Integer value */
839      void *a_ptr;		/* Pointer value */
840      void (*a_fcn) (void);	/* Function pointer value */
841    } a_un;
842} Elf32_auxv_t;
843
844typedef struct
845{
846  long int a_type;		/* Entry type */
847  union
848    {
849      long int a_val;		/* Integer value */
850      void *a_ptr;		/* Pointer value */
851      void (*a_fcn) (void);	/* Function pointer value */
852    } a_un;
853} Elf64_auxv_t;
854
855/* Legal values for a_type (entry type).  */
856
857#define AT_NULL		0		/* End of vector */
858#define AT_IGNORE	1		/* Entry should be ignored */
859#define AT_EXECFD	2		/* File descriptor of program */
860#define AT_PHDR		3		/* Program headers for program */
861#define AT_PHENT	4		/* Size of program header entry */
862#define AT_PHNUM	5		/* Number of program headers */
863#define AT_PAGESZ	6		/* System page size */
864#define AT_BASE		7		/* Base address of interpreter */
865#define AT_FLAGS	8		/* Flags */
866#define AT_ENTRY	9		/* Entry point of program */
867#define AT_NOTELF	10		/* Program is not ELF */
868#define AT_UID		11		/* Real uid */
869#define AT_EUID		12		/* Effective uid */
870#define AT_GID		13		/* Real gid */
871#define AT_EGID		14		/* Effective gid */
872
873/* Some more special a_type values describing the hardware.  */
874#define AT_PLATFORM	15		/* String identifying platform.  */
875#define AT_HWCAP	16		/* Machine dependent hints about
876					   processor capabilities.  */
877
878/* This entry gives some information about the FPU initialization
879   performed by the kernel.  */
880#define AT_FPUCW	17		/* Used FPU control word.  */
881
882
883/* Note section contents.  Each entry in the note section begins with
884   a header of a fixed form.  */
885
886typedef struct
887{
888  Elf32_Word n_namesz;			/* Length of the note's name.  */
889  Elf32_Word n_descsz;			/* Length of the note's descriptor.  */
890  Elf32_Word n_type;			/* Type of the note.  */
891} Elf32_Nhdr;
892
893typedef struct
894{
895  Elf64_Word n_namesz;			/* Length of the note's name.  */
896  Elf64_Word n_descsz;			/* Length of the note's descriptor.  */
897  Elf64_Word n_type;			/* Type of the note.  */
898} Elf64_Nhdr;
899
900/* Known names of notes.  */
901
902/* Solaris entries in the note section have this name.  */
903#define ELF_NOTE_SOLARIS	"SUNW Solaris"
904
905/* Note entries for GNU systems have this name.  */
906#define ELF_NOTE_GNU		"GNU"
907
908
909/* Defined types of notes for Solaris.  */
910
911/* Value of descriptor (one word) is desired pagesize for the binary.  */
912#define ELF_NOTE_PAGESIZE_HINT	1
913
914
915/* Defined note types for GNU systems.  */
916
917/* ABI information.  The descriptor consists of words:
918   word 0: OS descriptor
919   word 1: major version of the ABI
920   word 2: minor version of the ABI
921   word 3: subminor version of the ABI
922*/
923#define ELF_NOTE_ABI		1
924
925/* Known OSes.  These value can appear in word 0 of an ELF_NOTE_ABI
926   note section entry.  */
927#define ELF_NOTE_OS_LINUX	0
928#define ELF_NOTE_OS_GNU		1
929#define ELF_NOTE_OS_SOLARIS2	2
930
931
932/* Motorola 68k specific definitions.  */
933
934/* m68k relocs.  */
935
936#define R_68K_NONE	0		/* No reloc */
937#define R_68K_32	1		/* Direct 32 bit  */
938#define R_68K_16	2		/* Direct 16 bit  */
939#define R_68K_8		3		/* Direct 8 bit  */
940#define R_68K_PC32	4		/* PC relative 32 bit */
941#define R_68K_PC16	5		/* PC relative 16 bit */
942#define R_68K_PC8	6		/* PC relative 8 bit */
943#define R_68K_GOT32	7		/* 32 bit PC relative GOT entry */
944#define R_68K_GOT16	8		/* 16 bit PC relative GOT entry */
945#define R_68K_GOT8	9		/* 8 bit PC relative GOT entry */
946#define R_68K_GOT32O	10		/* 32 bit GOT offset */
947#define R_68K_GOT16O	11		/* 16 bit GOT offset */
948#define R_68K_GOT8O	12		/* 8 bit GOT offset */
949#define R_68K_PLT32	13		/* 32 bit PC relative PLT address */
950#define R_68K_PLT16	14		/* 16 bit PC relative PLT address */
951#define R_68K_PLT8	15		/* 8 bit PC relative PLT address */
952#define R_68K_PLT32O	16		/* 32 bit PLT offset */
953#define R_68K_PLT16O	17		/* 16 bit PLT offset */
954#define R_68K_PLT8O	18		/* 8 bit PLT offset */
955#define R_68K_COPY	19		/* Copy symbol at runtime */
956#define R_68K_GLOB_DAT	20		/* Create GOT entry */
957#define R_68K_JMP_SLOT	21		/* Create PLT entry */
958#define R_68K_RELATIVE	22		/* Adjust by program base */
959/* Keep this the last entry.  */
960#define R_68K_NUM	23
961
962/* Intel 80386 specific definitions.  */
963
964/* i386 relocs.  */
965
966#define R_386_NONE	0		/* No reloc */
967#define R_386_32	1		/* Direct 32 bit  */
968#define R_386_PC32	2		/* PC relative 32 bit */
969#define R_386_GOT32	3		/* 32 bit GOT entry */
970#define R_386_PLT32	4		/* 32 bit PLT address */
971#define R_386_COPY	5		/* Copy symbol at runtime */
972#define R_386_GLOB_DAT	6		/* Create GOT entry */
973#define R_386_JMP_SLOT	7		/* Create PLT entry */
974#define R_386_RELATIVE	8		/* Adjust by program base */
975#define R_386_GOTOFF	9		/* 32 bit offset to GOT */
976#define R_386_GOTPC	10		/* 32 bit PC relative offset to GOT */
977/* Keep this the last entry.  */
978#define R_386_NUM	11
979
980/* SUN SPARC specific definitions.  */
981
982/* Values for Elf64_Ehdr.e_flags.  */
983
984#define EF_SPARCV9_MM		3
985#define EF_SPARCV9_TSO		0
986#define EF_SPARCV9_PSO		1
987#define EF_SPARCV9_RMO		2
988#define EF_SPARC_EXT_MASK	0xFFFF00
989#define EF_SPARC_SUN_US1	0x000200
990#define EF_SPARC_HAL_R1		0x000400
991
992/* SPARC relocs.  */
993
994#define R_SPARC_NONE	0		/* No reloc */
995#define R_SPARC_8	1		/* Direct 8 bit */
996#define R_SPARC_16	2		/* Direct 16 bit */
997#define R_SPARC_32	3		/* Direct 32 bit */
998#define R_SPARC_DISP8	4		/* PC relative 8 bit */
999#define R_SPARC_DISP16	5		/* PC relative 16 bit */
1000#define R_SPARC_DISP32	6		/* PC relative 32 bit */
1001#define R_SPARC_WDISP30	7		/* PC relative 30 bit shifted */
1002#define R_SPARC_WDISP22	8		/* PC relative 22 bit shifted */
1003#define R_SPARC_HI22	9		/* High 22 bit */
1004#define R_SPARC_22	10		/* Direct 22 bit */
1005#define R_SPARC_13	11		/* Direct 13 bit */
1006#define R_SPARC_LO10	12		/* Truncated 10 bit */
1007#define R_SPARC_GOT10	13		/* Truncated 10 bit GOT entry */
1008#define R_SPARC_GOT13	14		/* 13 bit GOT entry */
1009#define R_SPARC_GOT22	15		/* 22 bit GOT entry shifted */
1010#define R_SPARC_PC10	16		/* PC relative 10 bit truncated */
1011#define R_SPARC_PC22	17		/* PC relative 22 bit shifted */
1012#define R_SPARC_WPLT30	18		/* 30 bit PC relative PLT address */
1013#define R_SPARC_COPY	19		/* Copy symbol at runtime */
1014#define R_SPARC_GLOB_DAT 20		/* Create GOT entry */
1015#define R_SPARC_JMP_SLOT 21		/* Create PLT entry */
1016#define R_SPARC_RELATIVE 22		/* Adjust by program base */
1017#define R_SPARC_UA32	23		/* Direct 32 bit unaligned */
1018
1019/* Additional Sparc64 relocs.  */
1020
1021#define R_SPARC_PLT32	24		/* Direct 32 bit ref to PLT entry */
1022#define R_SPARC_HIPLT22	25		/* High 22 bit PLT entry */
1023#define R_SPARC_LOPLT10	26		/* Truncated 10 bit PLT entry */
1024#define R_SPARC_PCPLT32	27		/* PC rel 32 bit ref to PLT entry */
1025#define R_SPARC_PCPLT22	28		/* PC rel high 22 bit PLT entry */
1026#define R_SPARC_PCPLT10	29		/* PC rel trunc 10 bit PLT entry */
1027#define R_SPARC_10	30		/* Direct 10 bit */
1028#define R_SPARC_11	31		/* Direct 11 bit */
1029#define R_SPARC_64	32		/* Direct 64 bit */
1030#define R_SPARC_OLO10	33		/* ?? */
1031#define R_SPARC_HH22	34		/* Top 22 bits of direct 64 bit */
1032#define R_SPARC_HM10	35		/* High middle 10 bits of ... */
1033#define R_SPARC_LM22	36		/* Low middle 22 bits of ... */
1034#define R_SPARC_PC_HH22	37		/* Top 22 bits of pc rel 64 bit */
1035#define R_SPARC_PC_HM10	38		/* High middle 10 bit of ... */
1036#define R_SPARC_PC_LM22	39		/* Low miggle 22 bits of ... */
1037#define R_SPARC_WDISP16	40		/* PC relative 16 bit shifted */
1038#define R_SPARC_WDISP19	41		/* PC relative 19 bit shifted */
1039#define R_SPARC_7	43		/* Direct 7 bit */
1040#define R_SPARC_5	44		/* Direct 5 bit */
1041#define R_SPARC_6	45		/* Direct 6 bit */
1042#define R_SPARC_DISP64	46		/* PC relative 64 bit */
1043#define R_SPARC_PLT64	47		/* Direct 64 bit ref to PLT entry */
1044#define R_SPARC_HIX22	48		/* High 22 bit complemented */
1045#define R_SPARC_LOX10	49		/* Truncated 11 bit complemented */
1046#define R_SPARC_H44	50		/* Direct high 12 of 44 bit */
1047#define R_SPARC_M44	51		/* Direct mid 22 of 44 bit */
1048#define R_SPARC_L44	52		/* Direct low 10 of 44 bit */
1049#define R_SPARC_REGISTER 53		/* Global register usage */
1050#define R_SPARC_UA64	54		/* Direct 64 bit unaligned */
1051#define R_SPARC_UA16	55		/* Direct 16 bit unaligned */
1052/* Keep this the last entry.  */
1053#define R_SPARC_NUM	56
1054
1055/* For Sparc64, legal values for d_tag of Elf64_Dyn.  */
1056
1057#define DT_SPARC_REGISTER 0x70000001
1058#define DT_SPARC_NUM	2
1059
1060/* Bits present in AT_HWCAP, primarily for Sparc32.  */
1061
1062#define HWCAP_SPARC_FLUSH	1	/* The cpu supports flush insn.  */
1063#define HWCAP_SPARC_STBAR	2
1064#define HWCAP_SPARC_SWAP	4
1065#define HWCAP_SPARC_MULDIV	8
1066#define HWCAP_SPARC_V9		16	/* The cpu is v9, so v8plus is ok.  */
1067
1068/* MIPS R3000 specific definitions.  */
1069
1070/* Legal values for e_flags field of Elf32_Ehdr.  */
1071
1072#define EF_MIPS_NOREORDER   1		/* A .noreorder directive was used */
1073#define EF_MIPS_PIC	    2		/* Contains PIC code */
1074#define EF_MIPS_CPIC	    4		/* Uses PIC calling sequence */
1075#define EF_MIPS_XGOT	    8
1076#define EF_MIPS_64BIT_WHIRL 16
1077#define EF_MIPS_ABI2	    32
1078#define EF_MIPS_ABI_ON32    64
1079#define EF_MIPS_ARCH	    0xf0000000	/* MIPS architecture level */
1080
1081/* Legal values for MIPS architecture level.  */
1082
1083#define EF_MIPS_ARCH_1	    0x00000000	/* -mips1 code.  */
1084#define EF_MIPS_ARCH_2	    0x10000000	/* -mips2 code.  */
1085#define EF_MIPS_ARCH_3	    0x20000000	/* -mips3 code.  */
1086#define EF_MIPS_ARCH_4	    0x30000000	/* -mips4 code.  */
1087#define EF_MIPS_ARCH_5	    0x40000000	/* -mips5 code.  */
1088
1089/* The following are non-official names and should not be used.  */
1090
1091#define E_MIPS_ARCH_1	  0x00000000	/* -mips1 code.  */
1092#define E_MIPS_ARCH_2	  0x10000000	/* -mips2 code.  */
1093#define E_MIPS_ARCH_3	  0x20000000	/* -mips3 code.  */
1094#define E_MIPS_ARCH_4	  0x30000000	/* -mips4 code.  */
1095#define E_MIPS_ARCH_5	  0x40000000	/* -mips5 code.  */
1096
1097/* Special section indices.  */
1098
1099#define SHN_MIPS_ACOMMON 0xff00		/* Allocated common symbols */
1100#define SHN_MIPS_TEXT	 0xff01		/* Allocated test symbols.  */
1101#define SHN_MIPS_DATA	 0xff02		/* Allocated data symbols.  */
1102#define SHN_MIPS_SCOMMON 0xff03		/* Small common symbols */
1103#define SHN_MIPS_SUNDEFINED 0xff04	/* Small undefined symbols */
1104
1105/* Legal values for sh_type field of Elf32_Shdr.  */
1106
1107#define SHT_MIPS_LIBLIST       0x70000000 /* Shared objects used in link */
1108#define SHT_MIPS_MSYM	       0x70000001
1109#define SHT_MIPS_CONFLICT      0x70000002 /* Conflicting symbols */
1110#define SHT_MIPS_GPTAB	       0x70000003 /* Global data area sizes */
1111#define SHT_MIPS_UCODE	       0x70000004 /* Reserved for SGI/MIPS compilers */
1112#define SHT_MIPS_DEBUG	       0x70000005 /* MIPS ECOFF debugging information*/
1113#define SHT_MIPS_REGINFO       0x70000006 /* Register usage information */
1114#define SHT_MIPS_PACKAGE       0x70000007
1115#define SHT_MIPS_PACKSYM       0x70000008
1116#define SHT_MIPS_RELD	       0x70000009
1117#define SHT_MIPS_IFACE         0x7000000b
1118#define SHT_MIPS_CONTENT       0x7000000c
1119#define SHT_MIPS_OPTIONS       0x7000000d /* Miscellaneous options.  */
1120#define SHT_MIPS_SHDR	       0x70000010
1121#define SHT_MIPS_FDESC	       0x70000011
1122#define SHT_MIPS_EXTSYM	       0x70000012
1123#define SHT_MIPS_DENSE	       0x70000013
1124#define SHT_MIPS_PDESC	       0x70000014
1125#define SHT_MIPS_LOCSYM	       0x70000015
1126#define SHT_MIPS_AUXSYM	       0x70000016
1127#define SHT_MIPS_OPTSYM	       0x70000017
1128#define SHT_MIPS_LOCSTR	       0x70000018
1129#define SHT_MIPS_LINE	       0x70000019
1130#define SHT_MIPS_RFDESC	       0x7000001a
1131#define SHT_MIPS_DELTASYM      0x7000001b
1132#define SHT_MIPS_DELTAINST     0x7000001c
1133#define SHT_MIPS_DELTACLASS    0x7000001d
1134#define SHT_MIPS_DWARF         0x7000001e /* DWARF debugging information.  */
1135#define SHT_MIPS_DELTADECL     0x7000001f
1136#define SHT_MIPS_SYMBOL_LIB    0x70000020
1137#define SHT_MIPS_EVENTS	       0x70000021 /* Event section.  */
1138#define SHT_MIPS_TRANSLATE     0x70000022
1139#define SHT_MIPS_PIXIE	       0x70000023
1140#define SHT_MIPS_XLATE	       0x70000024
1141#define SHT_MIPS_XLATE_DEBUG   0x70000025
1142#define SHT_MIPS_WHIRL	       0x70000026
1143#define SHT_MIPS_EH_REGION     0x70000027
1144#define SHT_MIPS_XLATE_OLD     0x70000028
1145#define SHT_MIPS_PDR_EXCEPTION 0x70000029
1146
1147/* Legal values for sh_flags field of Elf32_Shdr.  */
1148
1149#define SHF_MIPS_GPREL	 0x10000000	/* Must be part of global data area */
1150#define SHF_MIPS_MERGE	 0x20000000
1151#define SHF_MIPS_ADDR	 0x40000000
1152#define SHF_MIPS_STRINGS 0x80000000
1153#define SHF_MIPS_NOSTRIP 0x08000000
1154#define SHF_MIPS_LOCAL	 0x04000000
1155#define SHF_MIPS_NAMES	 0x02000000
1156#define SHF_MIPS_NODUPE	 0x01000000
1157
1158
1159/* Symbol tables.  */
1160
1161/* MIPS specific values for `st_other'.  */
1162#define STO_MIPS_DEFAULT		0x0
1163#define STO_MIPS_INTERNAL		0x1
1164#define STO_MIPS_HIDDEN			0x2
1165#define STO_MIPS_PROTECTED		0x3
1166#define STO_MIPS_SC_ALIGN_UNUSED	0xff
1167
1168/* MIPS specific values for `st_info'.  */
1169#define STB_MIPS_SPLIT_COMMON		13
1170
1171/* Entries found in sections of type SHT_MIPS_GPTAB.  */
1172
1173typedef union
1174{
1175  struct
1176    {
1177      Elf32_Word gt_current_g_value;	/* -G value used for compilation */
1178      Elf32_Word gt_unused;		/* Not used */
1179    } gt_header;			/* First entry in section */
1180  struct
1181    {
1182      Elf32_Word gt_g_value;		/* If this value were used for -G */
1183      Elf32_Word gt_bytes;		/* This many bytes would be used */
1184    } gt_entry;				/* Subsequent entries in section */
1185} Elf32_gptab;
1186
1187/* Entry found in sections of type SHT_MIPS_REGINFO.  */
1188
1189typedef struct
1190{
1191  Elf32_Word	ri_gprmask;		/* General registers used */
1192  Elf32_Word	ri_cprmask[4];		/* Coprocessor registers used */
1193  Elf32_Sword	ri_gp_value;		/* $gp register value */
1194} Elf32_RegInfo;
1195
1196/* Entries found in sections of type SHT_MIPS_OPTIONS.  */
1197
1198typedef struct
1199{
1200  unsigned char kind;		/* Determines interpretation of the
1201				   variable part of descriptor.  */
1202  unsigned char size;		/* Size of descriptor, including header.  */
1203  Elf32_Section section;	/* Section header index of section affected,
1204				   0 for global options.  */
1205  Elf32_Word info;		/* Kind-specific information.  */
1206} Elf_Options;
1207
1208/* Values for `kind' field in Elf_Options.  */
1209
1210#define ODK_NULL	0	/* Undefined.  */
1211#define ODK_REGINFO	1	/* Register usage information.  */
1212#define ODK_EXCEPTIONS	2	/* Exception processing options.  */
1213#define ODK_PAD		3	/* Section padding options.  */
1214#define ODK_HWPATCH	4	/* Hardware workarounds performed */
1215#define ODK_FILL	5	/* record the fill value used by the linker. */
1216#define ODK_TAGS	6	/* reserve space for desktop tools to write. */
1217#define ODK_HWAND	7	/* HW workarounds.  'AND' bits when merging. */
1218#define ODK_HWOR	8	/* HW workarounds.  'OR' bits when merging.  */
1219
1220/* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries.  */
1221
1222#define OEX_FPU_MIN	0x1f	/* FPE's which MUST be enabled.  */
1223#define OEX_FPU_MAX	0x1f00	/* FPE's which MAY be enabled.  */
1224#define OEX_PAGE0	0x10000	/* page zero must be mapped.  */
1225#define OEX_SMM		0x20000	/* Force sequential memory mode?  */
1226#define OEX_FPDBUG	0x40000	/* Force floating point debug mode?  */
1227#define OEX_PRECISEFP	OEX_FPDBUG
1228#define OEX_DISMISS	0x80000	/* Dismiss invalid address faults?  */
1229
1230#define OEX_FPU_INVAL	0x10
1231#define OEX_FPU_DIV0	0x08
1232#define OEX_FPU_OFLO	0x04
1233#define OEX_FPU_UFLO	0x02
1234#define OEX_FPU_INEX	0x01
1235
1236/* Masks for `info' in Elf_Options for an ODK_HWPATCH entry.  */
1237
1238#define OHW_R4KEOP	0x1	/* R4000 end-of-page patch.  */
1239#define OHW_R8KPFETCH	0x2	/* may need R8000 prefetch patch.  */
1240#define OHW_R5KEOP	0x4	/* R5000 end-of-page patch.  */
1241#define OHW_R5KCVTL	0x8	/* R5000 cvt.[ds].l bug.  clean=1.  */
1242
1243#define OPAD_PREFIX	0x1
1244#define OPAD_POSTFIX	0x2
1245#define OPAD_SYMBOL	0x4
1246
1247/* Entry found in `.options' section.  */
1248
1249typedef struct
1250{
1251  Elf32_Word hwp_flags1;	/* Extra flags.  */
1252  Elf32_Word hwp_flags2;	/* Extra flags.  */
1253} Elf_Options_Hw;
1254
1255/* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries.  */
1256
1257#define OHWA0_R4KEOP_CHECKED	0x00000001
1258#define OHWA1_R4KEOP_CLEAN	0x00000002
1259
1260/* MIPS relocs.  */
1261
1262#define R_MIPS_NONE		0	/* No reloc */
1263#define R_MIPS_16		1	/* Direct 16 bit */
1264#define R_MIPS_32		2	/* Direct 32 bit */
1265#define R_MIPS_REL32		3	/* PC relative 32 bit */
1266#define R_MIPS_26		4	/* Direct 26 bit shifted */
1267#define R_MIPS_HI16		5	/* High 16 bit */
1268#define R_MIPS_LO16		6	/* Low 16 bit */
1269#define R_MIPS_GPREL16		7	/* GP relative 16 bit */
1270#define R_MIPS_LITERAL		8	/* 16 bit literal entry */
1271#define R_MIPS_GOT16		9	/* 16 bit GOT entry */
1272#define R_MIPS_PC16		10	/* PC relative 16 bit */
1273#define R_MIPS_CALL16		11	/* 16 bit GOT entry for function */
1274#define R_MIPS_GPREL32		12	/* GP relative 32 bit */
1275
1276#define R_MIPS_SHIFT5		16
1277#define R_MIPS_SHIFT6		17
1278#define R_MIPS_64		18
1279#define R_MIPS_GOT_DISP		19
1280#define R_MIPS_GOT_PAGE		20
1281#define R_MIPS_GOT_OFST		21
1282#define R_MIPS_GOT_HI16		22
1283#define R_MIPS_GOT_LO16		23
1284#define R_MIPS_SUB		24
1285#define R_MIPS_INSERT_A		25
1286#define R_MIPS_INSERT_B		26
1287#define R_MIPS_DELETE		27
1288#define R_MIPS_HIGHER		28
1289#define R_MIPS_HIGHEST		29
1290#define R_MIPS_CALL_HI16	30
1291#define R_MIPS_CALL_LO16	31
1292#define R_MIPS_SCN_DISP		32
1293#define R_MIPS_REL16		33
1294#define R_MIPS_ADD_IMMEDIATE	34
1295#define R_MIPS_PJUMP		35
1296#define R_MIPS_RELGOT		36
1297#define R_MIPS_JALR		37
1298/* Keep this the last entry.  */
1299#define R_MIPS_NUM		38
1300
1301/* Legal values for p_type field of Elf32_Phdr.  */
1302
1303#define PT_MIPS_REGINFO	0x70000000	/* Register usage information */
1304#define PT_MIPS_RTPROC  0x70000001	/* Runtime procedure table. */
1305#define PT_MIPS_OPTIONS 0x70000002
1306
1307/* Special program header types.  */
1308
1309#define PF_MIPS_LOCAL	0x10000000
1310
1311/* Legal values for d_tag field of Elf32_Dyn.  */
1312
1313#define DT_MIPS_RLD_VERSION  0x70000001	/* Runtime linker interface version */
1314#define DT_MIPS_TIME_STAMP   0x70000002	/* Timestamp */
1315#define DT_MIPS_ICHECKSUM    0x70000003	/* Checksum */
1316#define DT_MIPS_IVERSION     0x70000004	/* Version string (string tbl index) */
1317#define DT_MIPS_FLAGS	     0x70000005	/* Flags */
1318#define DT_MIPS_BASE_ADDRESS 0x70000006	/* Base address */
1319#define DT_MIPS_MSYM	     0x70000007
1320#define DT_MIPS_CONFLICT     0x70000008	/* Address of CONFLICT section */
1321#define DT_MIPS_LIBLIST	     0x70000009	/* Address of LIBLIST section */
1322#define DT_MIPS_LOCAL_GOTNO  0x7000000a	/* Number of local GOT entries */
1323#define DT_MIPS_CONFLICTNO   0x7000000b	/* Number of CONFLICT entries */
1324#define DT_MIPS_LIBLISTNO    0x70000010	/* Number of LIBLIST entries */
1325#define DT_MIPS_SYMTABNO     0x70000011	/* Number of DYNSYM entries */
1326#define DT_MIPS_UNREFEXTNO   0x70000012	/* First external DYNSYM */
1327#define DT_MIPS_GOTSYM	     0x70000013	/* First GOT entry in DYNSYM */
1328#define DT_MIPS_HIPAGENO     0x70000014	/* Number of GOT page table entries */
1329#define DT_MIPS_RLD_MAP	     0x70000016	/* Address of run time loader map.  */
1330#define DT_MIPS_DELTA_CLASS  0x70000017	/* Delta C++ class definition.  */
1331#define DT_MIPS_DELTA_CLASS_NO    0x70000018 /* Number of entries in
1332						DT_MIPS_DELTA_CLASS.  */
1333#define DT_MIPS_DELTA_INSTANCE    0x70000019 /* Delta C++ class instances.  */
1334#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in
1335						DT_MIPS_DELTA_INSTANCE.  */
1336#define DT_MIPS_DELTA_RELOC  0x7000001b /* Delta relocations.  */
1337#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in
1338					     DT_MIPS_DELTA_RELOC.  */
1339#define DT_MIPS_DELTA_SYM    0x7000001d /* Delta symbols that Delta
1340					   relocations refer to.  */
1341#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in
1342					   DT_MIPS_DELTA_SYM.  */
1343#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the
1344					     class declaration.  */
1345#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in
1346						DT_MIPS_DELTA_CLASSSYM.  */
1347#define DT_MIPS_CXX_FLAGS    0x70000022 /* Flags indicating for C++ flavor.  */
1348#define DT_MIPS_PIXIE_INIT   0x70000023
1349#define DT_MIPS_SYMBOL_LIB   0x70000024
1350#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025
1351#define DT_MIPS_LOCAL_GOTIDX 0x70000026
1352#define DT_MIPS_HIDDEN_GOTIDX 0x70000027
1353#define DT_MIPS_PROTECTED_GOTIDX 0x70000028
1354#define DT_MIPS_OPTIONS	     0x70000029 /* Address of .options.  */
1355#define DT_MIPS_INTERFACE    0x7000002a /* Address of .interface.  */
1356#define DT_MIPS_DYNSTR_ALIGN 0x7000002b
1357#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */
1358#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve
1359						    function stored in GOT.  */
1360#define DT_MIPS_PERF_SUFFIX  0x7000002e /* Default suffix of dso to be added
1361					   by rld on dlopen() calls.  */
1362#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */
1363#define DT_MIPS_GP_VALUE     0x70000030 /* GP value for aux GOTs.  */
1364#define DT_MIPS_AUX_DYNAMIC  0x70000031 /* Address of aux .dynamic.  */
1365#define DT_MIPS_NUM	     0x32
1366
1367/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry.  */
1368
1369#define RHF_NONE		   0		/* No flags */
1370#define RHF_QUICKSTART		   (1 << 0)	/* Use quickstart */
1371#define RHF_NOTPOT		   (1 << 1)	/* Hash size not power of 2 */
1372#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2)	/* Ignore LD_LIBRARY_PATH */
1373#define RHF_NO_MOVE		   (1 << 3)
1374#define RHF_SGI_ONLY		   (1 << 4)
1375#define RHF_GUARANTEE_INIT	   (1 << 5)
1376#define RHF_DELTA_C_PLUS_PLUS	   (1 << 6)
1377#define RHF_GUARANTEE_START_INIT   (1 << 7)
1378#define RHF_PIXIE		   (1 << 8)
1379#define RHF_DEFAULT_DELAY_LOAD	   (1 << 9)
1380#define RHF_REQUICKSTART	   (1 << 10)
1381#define RHF_REQUICKSTARTED	   (1 << 11)
1382#define RHF_CORD		   (1 << 12)
1383#define RHF_NO_UNRES_UNDEF	   (1 << 13)
1384#define RHF_RLD_ORDER_SAFE	   (1 << 14)
1385
1386/* Entries found in sections of type SHT_MIPS_LIBLIST.  */
1387
1388typedef struct
1389{
1390  Elf32_Word l_name;		/* Name (string table index) */
1391  Elf32_Word l_time_stamp;	/* Timestamp */
1392  Elf32_Word l_checksum;	/* Checksum */
1393  Elf32_Word l_version;		/* Interface version */
1394  Elf32_Word l_flags;		/* Flags */
1395} Elf32_Lib;
1396
1397typedef struct
1398{
1399  Elf64_Word l_name;		/* Name (string table index) */
1400  Elf64_Word l_time_stamp;	/* Timestamp */
1401  Elf64_Word l_checksum;	/* Checksum */
1402  Elf64_Word l_version;		/* Interface version */
1403  Elf64_Word l_flags;		/* Flags */
1404} Elf64_Lib;
1405
1406
1407/* Legal values for l_flags.  */
1408
1409#define LL_NONE		  0
1410#define LL_EXACT_MATCH	  (1 << 0)	/* Require exact match */
1411#define LL_IGNORE_INT_VER (1 << 1)	/* Ignore interface version */
1412#define LL_REQUIRE_MINOR  (1 << 2)
1413#define LL_EXPORTS	  (1 << 3)
1414#define LL_DELAY_LOAD	  (1 << 4)
1415#define LL_DELTA	  (1 << 5)
1416
1417/* Entries found in sections of type SHT_MIPS_CONFLICT.  */
1418
1419typedef Elf32_Addr Elf32_Conflict;
1420
1421
1422/* HPPA specific definitions.  */
1423
1424/* Legal values for e_flags field of Elf32_Ehdr.  */
1425
1426#define EF_PARISC_TRAPNL	1	/* Trap nil pointer dereference.  */
1427#define EF_PARISC_EXT		2	/* Program uses arch. extensions.  */
1428#define EF_PARISC_ARCH		0xffff0000 /* Architecture version.  */
1429/* Defined values are:
1430				0x020b	PA-RISC 1.0 big-endian
1431				0x0210	PA-RISC 1.1 big-endian
1432				0x028b	PA-RISC 1.0 little-endian
1433				0x0290	PA-RISC 1.1 little-endian
1434*/
1435
1436/* Legal values for sh_type field of Elf32_Shdr.  */
1437
1438#define SHT_PARISC_GOT		0x70000000 /* GOT for external data.  */
1439#define SHT_PARISC_ARCH		0x70000001 /* Architecture extensions.  */
1440#define SHT_PARISC_GLOBAL	0x70000002 /* Definition of $global$.  */
1441#define SHT_PARISC_MILLI	0x70000003 /* Millicode routines.  */
1442#define SHT_PARISC_UNWIND	0x70000004 /* Unwind information.  */
1443#define SHT_PARISC_PLT		0x70000005 /* Procedure linkage table.  */
1444#define SHT_PARISC_SDATA	0x70000006 /* Short initialized data.  */
1445#define SHT_PARISC_SBSS		0x70000007 /* Short uninitialized data.  */
1446#define SHT_PARISC_SYMEXTN	0x70000008 /* Argument/relocation info.  */
1447#define SHT_PARISC_STUBS	0x70000009 /* Linker stubs.  */
1448
1449/* Legal values for sh_flags field of Elf32_Shdr.  */
1450
1451#define SHF_PARISC_GLOBAL	0x10000000 /* Section defines dp.  */
1452#define SHF_PARISC_SHORT	0x20000000 /* Section with short addressing. */
1453
1454/* Legal values for ST_TYPE subfield of st_info (symbol type).  */
1455
1456#define STT_PARISC_MILLICODE	13	/* Millicode function entry point.  */
1457
1458/* HPPA relocs.  */
1459
1460#define R_PARISC_NONE		0	/* No reloc.  */
1461#define R_PARISC_DIR32		1	/* Direct 32-bit reference.  */
1462#define R_PARISC_DIR21L		2	/* Left 21 bits of eff. address.  */
1463#define R_PARISC_DIR17R		3	/* Right 17 bits of eff. address.  */
1464#define R_PARISC_DIR14R		4	/* Right 14 bits of eff. address.  */
1465#define R_PARISC_PCREL21L	5	/* PC-relative, left 21 bits.  */
1466#define R_PARISC_PCREL14R	6	/* PC-relative, right 14 bits.  */
1467#define R_PARISC_PCREL17C	7	/* Conditional PC-relative, ignore
1468					   if displacement > 17bits.  */
1469#define R_PARISC_PCREL17F	8	/* Conditional PC-relative, must
1470					   fit in 17bits.  */
1471#define R_PARISC_DPREL21L	9	/* DP-relative, left 21 bits.  */
1472#define R_PARISC_DPREL14R	10	/* DP-relative, right 14 bits.  */
1473#define R_PARISC_DPREL14F	11	/* DP-relative, must bit in 14 bits. */
1474#define R_PARISC_DLTREL21L	12	/* DLT-relative, left 21 bits.  */
1475#define R_PARISC_DLTREL14R	13	/* DLT-relative, right 14 bits.  */
1476#define R_PARISC_DLTREL14F	14	/* DLT-relative, must fit in 14 bits.*/
1477#define R_PARISC_DLTIND21L	15	/* DLT-relative indirect, left
1478					   21 bits.  */
1479#define R_PARISC_DLTIND14R	16	/* DLT-relative indirect, right
1480					   14 bits.  */
1481#define R_PARISC_DLTIND14F	17	/* DLT-relative indirect, must fit
1482					   int 14 bits.  */
1483#define R_PARISC_PLABEL32	18	/* Direct 32-bit reference to proc.  */
1484
1485/* Alpha specific definitions.  */
1486
1487/* Legal values for e_flags field of Elf64_Ehdr.  */
1488
1489#define EF_ALPHA_32BIT		1	/* All addresses must be < 2GB.  */
1490#define EF_ALPHA_CANRELAX	2	/* Relocations for relaxing exist.  */
1491
1492/* Legal values for sh_type field of Elf64_Shdr.  */
1493
1494/* These two are primerily concerned with ECOFF debugging info.  */
1495#define SHT_ALPHA_DEBUG		0x70000001
1496#define SHT_ALPHA_REGINFO	0x70000002
1497
1498/* Legal values for sh_flags field of Elf64_Shdr.  */
1499
1500#define SHF_ALPHA_GPREL		0x10000000
1501
1502/* Legal values for st_other field of Elf64_Sym.  */
1503#define STO_ALPHA_NOPV		0x80	/* No PV required.  */
1504#define STO_ALPHA_STD_GPLOAD	0x88	/* PV only used for initial ldgp.  */
1505
1506/* Alpha relocs.  */
1507
1508#define R_ALPHA_NONE		0	/* No reloc */
1509#define R_ALPHA_REFLONG		1	/* Direct 32 bit */
1510#define R_ALPHA_REFQUAD		2	/* Direct 64 bit */
1511#define R_ALPHA_GPREL32		3	/* GP relative 32 bit */
1512#define R_ALPHA_LITERAL		4	/* GP relative 16 bit w/optimization */
1513#define R_ALPHA_LITUSE		5	/* Optimization hint for LITERAL */
1514#define R_ALPHA_GPDISP		6	/* Add displacement to GP */
1515#define R_ALPHA_BRADDR		7	/* PC+4 relative 23 bit shifted */
1516#define R_ALPHA_HINT		8	/* PC+4 relative 16 bit shifted */
1517#define R_ALPHA_SREL16		9	/* PC relative 16 bit */
1518#define R_ALPHA_SREL32		10	/* PC relative 32 bit */
1519#define R_ALPHA_SREL64		11	/* PC relative 64 bit */
1520#define R_ALPHA_OP_PUSH		12	/* OP stack push */
1521#define R_ALPHA_OP_STORE	13	/* OP stack pop and store */
1522#define R_ALPHA_OP_PSUB		14	/* OP stack subtract */
1523#define R_ALPHA_OP_PRSHIFT	15	/* OP stack right shift */
1524#define R_ALPHA_GPVALUE		16
1525#define R_ALPHA_GPRELHIGH	17
1526#define R_ALPHA_GPRELLOW	18
1527#define R_ALPHA_IMMED_GP_16	19
1528#define R_ALPHA_IMMED_GP_HI32	20
1529#define R_ALPHA_IMMED_SCN_HI32	21
1530#define R_ALPHA_IMMED_BR_HI32	22
1531#define R_ALPHA_IMMED_LO32	23
1532#define R_ALPHA_COPY		24	/* Copy symbol at runtime */
1533#define R_ALPHA_GLOB_DAT	25	/* Create GOT entry */
1534#define R_ALPHA_JMP_SLOT	26	/* Create PLT entry */
1535#define R_ALPHA_RELATIVE	27	/* Adjust by program base */
1536/* Keep this the last entry.  */
1537#define R_ALPHA_NUM		28
1538
1539
1540/* PowerPC specific declarations */
1541
1542/* PowerPC relocations defined by the ABIs */
1543#define R_PPC_NONE		0
1544#define R_PPC_ADDR32		1	/* 32bit absolute address */
1545#define R_PPC_ADDR24		2	/* 26bit address, 2 bits ignored.  */
1546#define R_PPC_ADDR16		3	/* 16bit absolute address */
1547#define R_PPC_ADDR16_LO		4	/* lower 16bit of absolute address */
1548#define R_PPC_ADDR16_HI		5	/* high 16bit of absolute address */
1549#define R_PPC_ADDR16_HA		6	/* adjusted high 16bit */
1550#define R_PPC_ADDR14		7	/* 16bit address, 2 bits ignored */
1551#define R_PPC_ADDR14_BRTAKEN	8
1552#define R_PPC_ADDR14_BRNTAKEN	9
1553#define R_PPC_REL24		10	/* PC relative 26 bit */
1554#define R_PPC_REL14		11	/* PC relative 16 bit */
1555#define R_PPC_REL14_BRTAKEN	12
1556#define R_PPC_REL14_BRNTAKEN	13
1557#define R_PPC_GOT16		14
1558#define R_PPC_GOT16_LO		15
1559#define R_PPC_GOT16_HI		16
1560#define R_PPC_GOT16_HA		17
1561#define R_PPC_PLTREL24		18
1562#define R_PPC_COPY		19
1563#define R_PPC_GLOB_DAT		20
1564#define R_PPC_JMP_SLOT		21
1565#define R_PPC_RELATIVE		22
1566#define R_PPC_LOCAL24PC		23
1567#define R_PPC_UADDR32		24
1568#define R_PPC_UADDR16		25
1569#define R_PPC_REL32		26
1570#define R_PPC_PLT32		27
1571#define R_PPC_PLTREL32		28
1572#define R_PPC_PLT16_LO		29
1573#define R_PPC_PLT16_HI		30
1574#define R_PPC_PLT16_HA		31
1575#define R_PPC_SDAREL16		32
1576#define R_PPC_SECTOFF		33
1577#define R_PPC_SECTOFF_LO	34
1578#define R_PPC_SECTOFF_HI	35
1579#define R_PPC_SECTOFF_HA	36
1580/* Keep this the last entry.  */
1581#define R_PPC_NUMm		37
1582
1583/* The remaining relocs are from the Embedded ELF ABI, and are not
1584   in the SVR4 ELF ABI.  */
1585#define R_PPC_EMB_NADDR32	101
1586#define R_PPC_EMB_NADDR16	102
1587#define R_PPC_EMB_NADDR16_LO	103
1588#define R_PPC_EMB_NADDR16_HI	104
1589#define R_PPC_EMB_NADDR16_HA	105
1590#define R_PPC_EMB_SDAI16	106
1591#define R_PPC_EMB_SDA2I16	107
1592#define R_PPC_EMB_SDA2REL	108
1593#define R_PPC_EMB_SDA21		109	/* 16 bit offset in SDA */
1594#define R_PPC_EMB_MRKREF	110
1595#define R_PPC_EMB_RELSEC16	111
1596#define R_PPC_EMB_RELST_LO	112
1597#define R_PPC_EMB_RELST_HI	113
1598#define R_PPC_EMB_RELST_HA	114
1599#define R_PPC_EMB_BIT_FLD	115
1600#define R_PPC_EMB_RELSDA	116	/* 16 bit relative offset in SDA */
1601
1602/* Diab tool relocations.  */
1603#define R_PPC_DIAB_SDA21_LO	180	/* like EMB_SDA21, but lower 16 bit */
1604#define R_PPC_DIAB_SDA21_HI	181	/* like EMB_SDA21, but high 16 bit */
1605#define R_PPC_DIAB_SDA21_HA	182	/* like EMB_SDA21, adjusted high 16 */
1606#define R_PPC_DIAB_RELSDA_LO	183	/* like EMB_RELSDA, but lower 16 bit */
1607#define R_PPC_DIAB_RELSDA_HI	184	/* like EMB_RELSDA, but high 16 bit */
1608#define R_PPC_DIAB_RELSDA_HA	185	/* like EMB_RELSDA, adjusted high 16 */
1609
1610/* This is a phony reloc to handle any old fashioned TOC16 references
1611   that may still be in object files.  */
1612#define R_PPC_TOC16		255
1613
1614
1615/* ARM specific declarations */
1616
1617/* Processor specific flags for the ELF header e_flags field.  */
1618#define EF_ARM_RELEXEC     0x01
1619#define EF_ARM_HASENTRY    0x02
1620#define EF_ARM_INTERWORK   0x04
1621#define EF_ARM_APCS_26     0x08
1622#define EF_ARM_APCS_FLOAT  0x10
1623#define EF_ARM_PIC         0x20
1624#define EF_ALIGN8          0x40		/* 8-bit structure alignment is in use */
1625#define EF_NEW_ABI         0x80
1626#define EF_OLD_ABI         0x100
1627
1628/* Additional symbol types for Thumb */
1629#define STT_ARM_TFUNC      0xd
1630
1631/* ARM-specific values for sh_flags */
1632#define SHF_ARM_ENTRYSECT  0x10000000   /* Section contains an entry point */
1633#define SHF_ARM_COMDEF     0x80000000   /* Section may be multiply defined
1634					   in the input to a link step */
1635
1636/* ARM-specific program header flags */
1637#define PF_ARM_SB          0x10000000   /* Segment contains the location
1638					   addressed by the static base */
1639
1640/* ARM relocs.  */
1641#define R_ARM_NONE		0	/* No reloc */
1642#define R_ARM_PC24		1	/* PC relative 26 bit branch */
1643#define R_ARM_ABS32		2	/* Direct 32 bit  */
1644#define R_ARM_REL32		3	/* PC relative 32 bit */
1645#define R_ARM_PC13		4
1646#define R_ARM_ABS16		5	/* Direct 16 bit */
1647#define R_ARM_ABS12		6	/* Direct 12 bit */
1648#define R_ARM_THM_ABS5		7
1649#define R_ARM_ABS8		8	/* Direct 8 bit */
1650#define R_ARM_SBREL32		9
1651#define R_ARM_THM_PC22		10
1652#define R_ARM_THM_PC8		11
1653#define R_ARM_AMP_VCALL9	12
1654#define R_ARM_SWI24		13
1655#define R_ARM_THM_SWI8		14
1656#define R_ARM_XPC25		15
1657#define R_ARM_THM_XPC22		16
1658#define R_ARM_COPY		20	/* Copy symbol at runtime */
1659#define R_ARM_GLOB_DAT		21	/* Create GOT entry */
1660#define R_ARM_JUMP_SLOT		22	/* Create PLT entry */
1661#define R_ARM_RELATIVE		23	/* Adjust by program base */
1662#define R_ARM_GOTOFF		24	/* 32 bit offset to GOT */
1663#define R_ARM_GOTPC		25	/* 32 bit PC relative offset to GOT */
1664#define R_ARM_GOT32		26	/* 32 bit GOT entry */
1665#define R_ARM_PLT32		27	/* 32 bit PLT address */
1666#define R_ARM_GNU_VTENTRY	100
1667#define R_ARM_GNU_VTINHERIT	101
1668#define R_ARM_THM_PC11		102	/* thumb unconditional branch */
1669#define R_ARM_THM_PC9		103	/* thumb conditional branch */
1670#define R_ARM_RXPC25		249
1671#define R_ARM_RSBREL32		250
1672#define R_ARM_THM_RPC22		251
1673#define R_ARM_RREL32		252
1674#define R_ARM_RABS22		253
1675#define R_ARM_RPC24		254
1676#define R_ARM_RBASE		255
1677/* Keep this the last entry.  */
1678#define R_ARM_NUM		256
1679
1680/* TMS320C67xx specific declarations */
1681/* XXX: no ELF standard yet */
1682
1683/* TMS320C67xx relocs. */
1684#define R_C60_32       1
1685#define R_C60_GOT32	3		/* 32 bit GOT entry */
1686#define R_C60_PLT32	4		/* 32 bit PLT address */
1687#define R_C60_COPY	5		/* Copy symbol at runtime */
1688#define R_C60_GLOB_DAT	6		/* Create GOT entry */
1689#define R_C60_JMP_SLOT	7		/* Create PLT entry */
1690#define R_C60_RELATIVE	8		/* Adjust by program base */
1691#define R_C60_GOTOFF	9		/* 32 bit offset to GOT */
1692#define R_C60_GOTPC	10		/* 32 bit PC relative offset to GOT */
1693
1694#define R_C60HI16      0x55       // high 16 bit MVKH embedded
1695#define R_C60LO16      0x54       // low 16 bit MVKL embedded
1696
1697#endif	/* elf.h */
1698//---------------------------------------------------------------------------
1699
1700
1701// njn: inlined stab.h
1702//#include "stab.h"
1703//---------------------------------------------------------------------------
1704#ifndef __GNU_STAB__
1705
1706/* Indicate the GNU stab.h is in use.  */
1707
1708#define __GNU_STAB__
1709
1710#define __define_stab(NAME, CODE, STRING) NAME=CODE,
1711
1712enum __stab_debug_code
1713{
1714// njn: inlined stab.def
1715//#include "stab.def"
1716//---------------------------------------------------------------------------
1717/* Table of DBX symbol codes for the GNU system.
1718   Copyright (C) 1988, 1997 Free Software Foundation, Inc.
1719   This file is part of the GNU C Library.
1720
1721   The GNU C Library is free software; you can redistribute it and/or
1722   modify it under the terms of the GNU Library General Public License as
1723   published by the Free Software Foundation; either version 2 of the
1724   License, or (at your option) any later version.
1725
1726   The GNU C Library is distributed in the hope that it will be useful,
1727   but WITHOUT ANY WARRANTY; without even the implied warranty of
1728   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1729   Library General Public License for more details.
1730
1731   You should have received a copy of the GNU Library General Public
1732   License along with the GNU C Library; see the file COPYING.LIB.  If not,
1733   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1734   Boston, MA 02111-1307, USA.  */
1735
1736/* This contains contribution from Cygnus Support.  */
1737
1738/* Global variable.  Only the name is significant.
1739   To find the address, look in the corresponding external symbol.  */
1740__define_stab (N_GSYM, 0x20, "GSYM")
1741
1742/* Function name for BSD Fortran.  Only the name is significant.
1743   To find the address, look in the corresponding external symbol.  */
1744__define_stab (N_FNAME, 0x22, "FNAME")
1745
1746/* Function name or text-segment variable for C.  Value is its address.
1747   Desc is supposedly starting line number, but GCC doesn't set it
1748   and DBX seems not to miss it.  */
1749__define_stab (N_FUN, 0x24, "FUN")
1750
1751/* Data-segment variable with internal linkage.  Value is its address.
1752   "Static Sym".  */
1753__define_stab (N_STSYM, 0x26, "STSYM")
1754
1755/* BSS-segment variable with internal linkage.  Value is its address.  */
1756__define_stab (N_LCSYM, 0x28, "LCSYM")
1757
1758/* Name of main routine.  Only the name is significant.
1759   This is not used in C.  */
1760__define_stab (N_MAIN, 0x2a, "MAIN")
1761
1762/* Global symbol in Pascal.
1763   Supposedly the value is its line number; I'm skeptical.  */
1764__define_stab (N_PC, 0x30, "PC")
1765
1766/* Number of symbols:  0, files,,funcs,lines according to Ultrix V4.0. */
1767__define_stab (N_NSYMS, 0x32, "NSYMS")
1768
1769/* "No DST map for sym: name, ,0,type,ignored"  according to Ultrix V4.0. */
1770__define_stab (N_NOMAP, 0x34, "NOMAP")
1771
1772/* New stab from Solaris.  I don't know what it means, but it
1773   don't seem to contain useful information.  */
1774__define_stab (N_OBJ, 0x38, "OBJ")
1775
1776/* New stab from Solaris.  I don't know what it means, but it
1777   don't seem to contain useful information.  Possibly related to the
1778   optimization flags used in this module.  */
1779__define_stab (N_OPT, 0x3c, "OPT")
1780
1781/* Register variable.  Value is number of register.  */
1782__define_stab (N_RSYM, 0x40, "RSYM")
1783
1784/* Modula-2 compilation unit.  Can someone say what info it contains?  */
1785__define_stab (N_M2C, 0x42, "M2C")
1786
1787/* Line number in text segment.  Desc is the line number;
1788   value is corresponding address.  */
1789__define_stab (N_SLINE, 0x44, "SLINE")
1790
1791/* Similar, for data segment.  */
1792__define_stab (N_DSLINE, 0x46, "DSLINE")
1793
1794/* Similar, for bss segment.  */
1795__define_stab (N_BSLINE, 0x48, "BSLINE")
1796
1797/* Sun's source-code browser stabs.  ?? Don't know what the fields are.
1798   Supposedly the field is "path to associated .cb file".  THIS VALUE
1799   OVERLAPS WITH N_BSLINE!  */
1800__define_stab (N_BROWS, 0x48, "BROWS")
1801
1802/* GNU Modula-2 definition module dependency.  Value is the modification time
1803   of the definition file.  Other is non-zero if it is imported with the
1804   GNU M2 keyword %INITIALIZE.  Perhaps N_M2C can be used if there
1805   are enough empty fields? */
1806__define_stab(N_DEFD, 0x4a, "DEFD")
1807
1808/* THE FOLLOWING TWO STAB VALUES CONFLICT.  Happily, one is for Modula-2
1809   and one is for C++.   Still,... */
1810/* GNU C++ exception variable.  Name is variable name.  */
1811__define_stab (N_EHDECL, 0x50, "EHDECL")
1812/* Modula2 info "for imc":  name,,0,0,0  according to Ultrix V4.0.  */
1813__define_stab (N_MOD2, 0x50, "MOD2")
1814
1815/* GNU C++ `catch' clause.  Value is its address.  Desc is nonzero if
1816   this entry is immediately followed by a CAUGHT stab saying what exception
1817   was caught.  Multiple CAUGHT stabs means that multiple exceptions
1818   can be caught here.  If Desc is 0, it means all exceptions are caught
1819   here.  */
1820__define_stab (N_CATCH, 0x54, "CATCH")
1821
1822/* Structure or union element.  Value is offset in the structure.  */
1823__define_stab (N_SSYM, 0x60, "SSYM")
1824
1825/* Name of main source file.
1826   Value is starting text address of the compilation.  */
1827__define_stab (N_SO, 0x64, "SO")
1828
1829/* Automatic variable in the stack.  Value is offset from frame pointer.
1830   Also used for type descriptions.  */
1831__define_stab (N_LSYM, 0x80, "LSYM")
1832
1833/* Beginning of an include file.  Only Sun uses this.
1834   In an object file, only the name is significant.
1835   The Sun linker puts data into some of the other fields.  */
1836__define_stab (N_BINCL, 0x82, "BINCL")
1837
1838/* Name of sub-source file (#include file).
1839   Value is starting text address of the compilation.  */
1840__define_stab (N_SOL, 0x84, "SOL")
1841
1842/* Parameter variable.  Value is offset from argument pointer.
1843   (On most machines the argument pointer is the same as the frame pointer.  */
1844__define_stab (N_PSYM, 0xa0, "PSYM")
1845
1846/* End of an include file.  No name.
1847   This and N_BINCL act as brackets around the file's output.
1848   In an object file, there is no significant data in this entry.
1849   The Sun linker puts data into some of the fields.  */
1850__define_stab (N_EINCL, 0xa2, "EINCL")
1851
1852/* Alternate entry point.  Value is its address.  */
1853__define_stab (N_ENTRY, 0xa4, "ENTRY")
1854
1855/* Beginning of lexical block.
1856   The desc is the nesting level in lexical blocks.
1857   The value is the address of the start of the text for the block.
1858   The variables declared inside the block *precede* the N_LBRAC symbol.  */
1859__define_stab (N_LBRAC, 0xc0, "LBRAC")
1860
1861/* Place holder for deleted include file.  Replaces a N_BINCL and everything
1862   up to the corresponding N_EINCL.  The Sun linker generates these when
1863   it finds multiple identical copies of the symbols from an include file.
1864   This appears only in output from the Sun linker.  */
1865__define_stab (N_EXCL, 0xc2, "EXCL")
1866
1867/* Modula-2 scope information.  Can someone say what info it contains?  */
1868__define_stab (N_SCOPE, 0xc4, "SCOPE")
1869
1870/* End of a lexical block.  Desc matches the N_LBRAC's desc.
1871   The value is the address of the end of the text for the block.  */
1872__define_stab (N_RBRAC, 0xe0, "RBRAC")
1873
1874/* Begin named common block.  Only the name is significant.  */
1875__define_stab (N_BCOMM, 0xe2, "BCOMM")
1876
1877/* End named common block.  Only the name is significant
1878   (and it should match the N_BCOMM).  */
1879__define_stab (N_ECOMM, 0xe4, "ECOMM")
1880
1881/* End common (local name): value is address.
1882   I'm not sure how this is used.  */
1883__define_stab (N_ECOML, 0xe8, "ECOML")
1884
1885/* These STAB's are used on Gould systems for Non-Base register symbols
1886   or something like that.  FIXME.  I have assigned the values at random
1887   since I don't have a Gould here.  Fixups from Gould folk welcome... */
1888__define_stab (N_NBTEXT, 0xF0, "NBTEXT")
1889__define_stab (N_NBDATA, 0xF2, "NBDATA")
1890__define_stab (N_NBBSS,  0xF4, "NBBSS")
1891__define_stab (N_NBSTS,  0xF6, "NBSTS")
1892__define_stab (N_NBLCS,  0xF8, "NBLCS")
1893
1894/* Second symbol entry containing a length-value for the preceding entry.
1895   The value is the length.  */
1896__define_stab (N_LENG, 0xfe, "LENG")
1897
1898/* The above information, in matrix format.
1899
1900			STAB MATRIX
1901	_________________________________________________
1902	| 00 - 1F are not dbx stab symbols		|
1903	| In most cases, the low bit is the EXTernal bit|
1904
1905	| 00 UNDEF  | 02 ABS	| 04 TEXT   | 06 DATA	|
1906	| 01  |EXT  | 03  |EXT	| 05  |EXT  | 07  |EXT	|
1907
1908	| 08 BSS    | 0A INDR	| 0C FN_SEQ | 0E   	|
1909	| 09  |EXT  | 0B 	| 0D	    | 0F	|
1910
1911	| 10 	    | 12 COMM	| 14 SETA   | 16 SETT	|
1912	| 11	    | 13	| 15 	    | 17	|
1913
1914	| 18 SETD   | 1A SETB	| 1C SETV   | 1E WARNING|
1915	| 19	    | 1B	| 1D 	    | 1F FN	|
1916
1917	|_______________________________________________|
1918	| Debug entries with bit 01 set are unused.	|
1919	| 20 GSYM   | 22 FNAME	| 24 FUN    | 26 STSYM	|
1920	| 28 LCSYM  | 2A MAIN	| 2C	    | 2E	|
1921	| 30 PC	    | 32 NSYMS	| 34 NOMAP  | 36	|
1922	| 38 OBJ    | 3A	| 3C OPT    | 3E	|
1923	| 40 RSYM   | 42 M2C	| 44 SLINE  | 46 DSLINE |
1924	| 48 BSLINE*| 4A DEFD	| 4C        | 4E	|
1925	| 50 EHDECL*| 52	| 54 CATCH  | 56        |
1926	| 58        | 5A        | 5C        | 5E	|
1927	| 60 SSYM   | 62	| 64 SO	    | 66 	|
1928	| 68 	    | 6A	| 6C	    | 6E	|
1929	| 70	    | 72	| 74	    | 76	|
1930	| 78	    | 7A	| 7C	    | 7E	|
1931	| 80 LSYM   | 82 BINCL	| 84 SOL    | 86	|
1932	| 88	    | 8A	| 8C	    | 8E	|
1933	| 90	    | 92	| 94	    | 96	|
1934	| 98	    | 9A	| 9C	    | 9E	|
1935	| A0 PSYM   | A2 EINCL	| A4 ENTRY  | A6	|
1936	| A8	    | AA	| AC	    | AE	|
1937	| B0	    | B2	| B4	    | B6	|
1938	| B8	    | BA	| BC	    | BE	|
1939	| C0 LBRAC  | C2 EXCL	| C4 SCOPE  | C6	|
1940	| C8	    | CA	| CC	    | CE	|
1941	| D0	    | D2	| D4	    | D6	|
1942	| D8	    | DA	| DC	    | DE	|
1943	| E0 RBRAC  | E2 BCOMM	| E4 ECOMM  | E6	|
1944	| E8 ECOML  | EA	| EC	    | EE	|
1945	| F0	    | F2	| F4	    | F6	|
1946	| F8	    | FA	| FC	    | FE LENG	|
1947	+-----------------------------------------------+
1948 * 50 EHDECL is also MOD2.
1949 * 48 BSLINE is also BROWS.
1950 */
1951//---------------------------------------------------------------------------
1952LAST_UNUSED_STAB_CODE
1953};
1954
1955#undef __define_stab
1956
1957#endif /* __GNU_STAB_ */
1958//---------------------------------------------------------------------------
1959
1960#ifndef O_BINARY
1961#define O_BINARY 0
1962#endif
1963
1964// njn: inlined libtcc.h
1965//#include "libtcc.h"
1966//---------------------------------------------------------------------------
1967#ifndef LIBTCC_H
1968#define LIBTCC_H
1969
1970#ifdef __cplusplus
1971extern "C" {
1972#endif
1973
1974struct TCCState;
1975
1976typedef struct TCCState TCCState;
1977
1978/* create a new TCC compilation context */
1979TCCState *tcc_new(void);
1980
1981/* free a TCC compilation context */
1982void tcc_delete(TCCState *s);
1983
1984/* add debug information in the generated code */
1985void tcc_enable_debug(TCCState *s);
1986
1987/* set error/warning display callback */
1988void tcc_set_error_func(TCCState *s, void *error_opaque,
1989                        void (*error_func)(void *opaque, const char *msg));
1990
1991/* set/reset a warning */
1992int tcc_set_warning(TCCState *s, const char *warning_name, int value);
1993
1994/*****************************/
1995/* preprocessor */
1996
1997/* add include path */
1998int tcc_add_include_path(TCCState *s, const char *pathname);
1999
2000/* add in system include path */
2001int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
2002
2003/* define preprocessor symbol 'sym'. Can put optional value */
2004void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
2005
2006/* undefine preprocess symbol 'sym' */
2007void tcc_undefine_symbol(TCCState *s, const char *sym);
2008
2009/*****************************/
2010/* compiling */
2011
2012/* add a file (either a C file, dll, an object, a library or an ld
2013   script). Return -1 if error. */
2014int tcc_add_file(TCCState *s, const char *filename);
2015
2016/* compile a string containing a C source. Return non zero if
2017   error. */
2018int tcc_compile_string(TCCState *s, const char *buf);
2019
2020/*****************************/
2021/* linking commands */
2022
2023/* set output type. MUST BE CALLED before any compilation */
2024#define TCC_OUTPUT_MEMORY   0 /* output will be ran in memory (no
2025                                 output file) (default) */
2026#define TCC_OUTPUT_EXE      1 /* executable file */
2027#define TCC_OUTPUT_DLL      2 /* dynamic library */
2028#define TCC_OUTPUT_OBJ      3 /* object file */
2029int tcc_set_output_type(TCCState *s, int output_type);
2030
2031#define TCC_OUTPUT_FORMAT_ELF    0 /* default output format: ELF */
2032#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
2033#define TCC_OUTPUT_FORMAT_COFF   2 /* COFF */
2034
2035/* equivalent to -Lpath option */
2036int tcc_add_library_path(TCCState *s, const char *pathname);
2037
2038/* the library name is the same as the argument of the '-l' option */
2039int tcc_add_library(TCCState *s, const char *libraryname);
2040
2041/* add a symbol to the compiled program */
2042int tcc_add_symbol(TCCState *s, const char *name, unsigned long val);
2043
2044/* output an executable, library or object file. DO NOT call
2045   tcc_relocate() before. */
2046int tcc_output_file(TCCState *s, const char *filename);
2047
2048/* link and run main() function and return its value. DO NOT call
2049   tcc_relocate() before. */
2050int tcc_run(TCCState *s, int argc, char **argv);
2051
2052/* do all relocations (needed before using tcc_get_symbol()). Return
2053   non zero if link error. */
2054int tcc_relocate(TCCState *s);
2055
2056/* return symbol value. return 0 if OK, -1 if symbol not found */
2057int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name);
2058
2059#ifdef __cplusplus
2060}
2061#endif
2062
2063#endif
2064//---------------------------------------------------------------------------
2065
2066/* parser debug */
2067//#define PARSE_DEBUG
2068/* preprocessor debug */
2069//#define PP_DEBUG
2070/* include file debug */
2071//#define INC_DEBUG
2072
2073//#define MEM_DEBUG
2074
2075/* assembler debug */
2076//#define ASM_DEBUG
2077
2078/* target selection */
2079//#define TCC_TARGET_I386   /* i386 code generator */
2080//#define TCC_TARGET_ARM    /* ARMv4 code generator */
2081//#define TCC_TARGET_C67    /* TMS320C67xx code generator */
2082
2083/* default target is I386 */
2084#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
2085    !defined(TCC_TARGET_C67)
2086#define TCC_TARGET_I386
2087#endif
2088
2089#if !defined(WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
2090    !defined(TCC_TARGET_C67)
2091#define CONFIG_TCC_BCHECK /* enable bound checking code */
2092#endif
2093
2094#if defined(WIN32) && !defined(TCC_TARGET_PE)
2095#define CONFIG_TCC_STATIC
2096#endif
2097
2098/* define it to include assembler support */
2099#if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67)
2100#define CONFIG_TCC_ASM
2101#endif
2102
2103/* object format selection */
2104#if defined(TCC_TARGET_C67)
2105#define TCC_TARGET_COFF
2106#endif
2107
2108#define FALSE 0
2109#define false 0
2110#define TRUE 1
2111#define true 1
2112typedef int BOOL;
2113
2114/* path to find crt1.o, crti.o and crtn.o. Only needed when generating
2115   executables or dlls */
2116#define CONFIG_TCC_CRT_PREFIX "/usr/lib"
2117
2118#define INCLUDE_STACK_SIZE  32
2119#define IFDEF_STACK_SIZE    64
2120#define VSTACK_SIZE         256
2121#define STRING_MAX_SIZE     1024
2122#define PACK_STACK_SIZE     8
2123
2124#define TOK_HASH_SIZE       8192 /* must be a power of two */
2125#define TOK_ALLOC_INCR      512  /* must be a power of two */
2126#define TOK_MAX_SIZE        4 /* token max size in int unit when stored in string */
2127
2128/* token symbol management */
2129typedef struct TokenSym {
2130    struct TokenSym *hash_next;
2131    struct Sym *sym_define; /* direct pointer to define */
2132    struct Sym *sym_label; /* direct pointer to label */
2133    struct Sym *sym_struct; /* direct pointer to structure */
2134    struct Sym *sym_identifier; /* direct pointer to identifier */
2135    int tok; /* token number */
2136    int len;
2137    char str[1];
2138} TokenSym;
2139
2140typedef struct CString {
2141    int size; /* size in bytes */
2142    void *data; /* either 'char *' or 'int *' */
2143    int size_allocated;
2144    void *data_allocated; /* if non NULL, data has been malloced */
2145} CString;
2146
2147/* type definition */
2148typedef struct CType {
2149    int t;
2150    struct Sym *ref;
2151} CType;
2152
2153/* constant value */
2154typedef union CValue {
2155    long double ld;
2156    double d;
2157    float f;
2158    int i;
2159    unsigned int ui;
2160    unsigned int ul; /* address (should be unsigned long on 64 bit cpu) */
2161    long long ll;
2162    unsigned long long ull;
2163    struct CString *cstr;
2164    void *ptr;
2165    int tab[sizeof(long double) / sizeof(int)];
2166} CValue;
2167
2168/* value on stack */
2169typedef struct SValue {
2170    CType type;      /* type */
2171    unsigned short r;      /* register + flags */
2172    unsigned short r2;     /* second register, used for 'long long'
2173                              type. If not used, set to VT_CONST */
2174    CValue c;              /* constant, if VT_CONST */
2175    struct Sym *sym;       /* symbol, if (VT_SYM | VT_CONST) */
2176} SValue;
2177
2178/* symbol management */
2179typedef struct Sym {
2180    long v;    /* symbol token */
2181    long r;    /* associated register */
2182    long c;    /* associated number */
2183    CType type;    /* associated type */
2184    struct Sym *next; /* next related symbol */
2185    struct Sym *prev; /* prev symbol in stack */
2186    struct Sym *prev_tok; /* previous symbol for this token */
2187} Sym;
2188
2189/* section definition */
2190/* XXX: use directly ELF structure for parameters ? */
2191/* special flag to indicate that the section should not be linked to
2192   the other ones */
2193#define SHF_PRIVATE 0x80000000
2194
2195typedef struct Section {
2196    unsigned long data_offset; /* current data offset */
2197    unsigned char *data;       /* section data */
2198    unsigned long data_allocated; /* used for realloc() handling */
2199    int sh_name;             /* elf section name (only used during output) */
2200    int sh_num;              /* elf section number */
2201    int sh_type;             /* elf section type */
2202    int sh_flags;            /* elf section flags */
2203    int sh_info;             /* elf section info */
2204    int sh_addralign;        /* elf section alignment */
2205    int sh_entsize;          /* elf entry size */
2206    unsigned long sh_size;   /* section size (only used during output) */
2207    unsigned long sh_addr;      /* address at which the section is relocated */
2208    unsigned long sh_offset;      /* address at which the section is relocated */
2209    int nb_hashed_syms;      /* used to resize the hash table */
2210    struct Section *link;    /* link to another section */
2211    struct Section *reloc;   /* corresponding section for relocation, if any */
2212    struct Section *hash;     /* hash table for symbols */
2213    struct Section *next;
2214    char name[1];           /* section name */
2215} Section;
2216
2217typedef struct DLLReference {
2218    int level;
2219    char name[1];
2220} DLLReference;
2221
2222/* GNUC attribute definition */
2223typedef struct AttributeDef {
2224    int aligned;
2225    int packed;
2226    Section *section;
2227    unsigned char func_call; /* FUNC_CDECL, FUNC_STDCALL, FUNC_FASTCALLx */
2228    unsigned char dllexport;
2229} AttributeDef;
2230
2231#define SYM_STRUCT     0x40000000 /* struct/union/enum symbol space */
2232#define SYM_FIELD      0x20000000 /* struct/union field symbol space */
2233#define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
2234
2235/* stored in 'Sym.c' field */
2236#define FUNC_NEW       1 /* ansi function prototype */
2237#define FUNC_OLD       2 /* old function prototype */
2238#define FUNC_ELLIPSIS  3 /* ansi function prototype with ... */
2239
2240/* stored in 'Sym.r' field */
2241#define FUNC_CDECL     0 /* standard c call */
2242#define FUNC_STDCALL   1 /* pascal c call */
2243#define FUNC_FASTCALL1 2 /* first param in %eax */
2244#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
2245#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
2246
2247/* field 'Sym.t' for macros */
2248#define MACRO_OBJ      0 /* object like macro */
2249#define MACRO_FUNC     1 /* function like macro */
2250
2251/* field 'Sym.r' for C labels */
2252#define LABEL_DEFINED  0 /* label is defined */
2253#define LABEL_FORWARD  1 /* label is forward defined */
2254#define LABEL_DECLARED 2 /* label is declared but never used */
2255
2256/* type_decl() types */
2257#define TYPE_ABSTRACT  1 /* type without variable */
2258#define TYPE_DIRECT    2 /* type with variable */
2259
2260#define IO_BUF_SIZE 8192
2261
2262typedef struct BufferedFile {
2263    uint8_t *buf_ptr;
2264    uint8_t *buf_end;
2265    int fd;
2266    int line_num;    /* current line number - here to simplify code */
2267    int ifndef_macro;  /* #ifndef macro / #endif search */
2268    int ifndef_macro_saved; /* saved ifndef_macro */
2269    int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
2270    char inc_type;          /* type of include */
2271    char inc_filename[512]; /* filename specified by the user */
2272    char filename[1024];    /* current filename - here to simplify code */
2273    unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
2274} BufferedFile;
2275
2276#define CH_EOB   '\\'       /* end of buffer or '\0' char in file */
2277#define CH_EOF   (-1)   /* end of file */
2278
2279/* parsing state (used to save parser state to reparse part of the
2280   source several times) */
2281typedef struct ParseState {
2282    int *macro_ptr;
2283    int line_num;
2284    int tok;
2285    CValue tokc;
2286} ParseState;
2287
2288/* used to record tokens */
2289typedef struct TokenString {
2290    int *str;
2291    int len;
2292    int allocated_len;
2293    int last_line_num;
2294} TokenString;
2295
2296/* include file cache, used to find files faster and also to eliminate
2297   inclusion if the include file is protected by #ifndef ... #endif */
2298typedef struct CachedInclude {
2299    int ifndef_macro;
2300    int hash_next; /* -1 if none */
2301    char type; /* '"' or '>' to give include type */
2302    char filename[1]; /* path specified in #include */
2303} CachedInclude;
2304
2305#define CACHED_INCLUDES_HASH_SIZE 512
2306
2307/* parser */
2308static struct BufferedFile *file;
2309static int ch, tok;
2310static CValue tokc;
2311static CString tokcstr; /* current parsed string, if any */
2312/* additional informations about token */
2313static int tok_flags;
2314#define TOK_FLAG_BOL   0x0001 /* beginning of line before */
2315#define TOK_FLAG_BOF   0x0002 /* beginning of file before */
2316#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
2317
2318static int *macro_ptr, *macro_ptr_allocated;
2319static int *unget_saved_macro_ptr;
2320static int unget_saved_buffer[TOK_MAX_SIZE + 1];
2321static int unget_buffer_enabled;
2322static int parse_flags;
2323#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
2324#define PARSE_FLAG_TOK_NUM    0x0002 /* return numbers instead of TOK_PPNUM */
2325#define PARSE_FLAG_LINEFEED   0x0004 /* line feed is returned as a
2326                                        token. line feed is also
2327                                        returned at eof */
2328#define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
2329
2330static Section *text_section, *data_section, *bss_section; /* predefined sections */
2331static Section *cur_text_section; /* current section where function code is
2332                              generated */
2333#ifdef CONFIG_TCC_ASM
2334static Section *last_text_section; /* to handle .previous asm directive */
2335#endif
2336/* bound check related sections */
2337static Section *bounds_section; /* contains global data bound description */
2338static Section *lbounds_section; /* contains local data bound description */
2339/* symbol sections */
2340static Section *symtab_section, *strtab_section;
2341
2342/* debug sections */
2343static Section *stab_section, *stabstr_section;
2344
2345/* loc : local variable index
2346   ind : output code index
2347   rsym: return symbol
2348   anon_sym: anonymous symbol index
2349*/
2350static long rsym, anon_sym, ind, loc;
2351/* expression generation modifiers */
2352static int const_wanted; /* true if constant wanted */
2353static int nocode_wanted; /* true if no code generation wanted for an expression */
2354static int global_expr;  /* true if compound literals must be allocated
2355                            globally (used during initializers parsing */
2356static CType func_vt; /* current function return type (used by return
2357                         instruction) */
2358static int func_vc;
2359static long last_line_num, last_ind, func_ind; /* debug last line number and pc */
2360static int tok_ident;
2361static TokenSym **table_ident;
2362static TokenSym *hash_ident[TOK_HASH_SIZE];
2363static char token_buf[STRING_MAX_SIZE + 1];
2364static char *funcname;
2365static Sym *global_stack, *local_stack;
2366static Sym *define_stack;
2367static Sym *global_label_stack, *local_label_stack;
2368/* symbol allocator */
2369#define SYM_POOL_NB (8192 / sizeof(Sym))
2370static Sym *sym_free_first;
2371
2372static SValue vstack[VSTACK_SIZE], *vtop;
2373/* some predefined types */
2374static CType char_pointer_type, func_old_type, int_type;
2375/* true if isid(c) || isnum(c) */
2376static unsigned char isidnum_table[256];
2377
2378/* compile with debug symbol (and use them if error during execution) */
2379static int do_debug = 0;
2380
2381/* compile with built-in memory and bounds checker */
2382static int do_bounds_check = 0;
2383
2384/* display benchmark infos */
2385#if !defined(LIBTCC)
2386static int do_bench = 0;
2387#endif
2388static int total_lines;
2389static int total_bytes;
2390
2391/* use GNU C extensions */
2392static int gnu_ext = 1;
2393
2394/* use Tiny C extensions */
2395static int tcc_ext = 1;
2396
2397/* max number of callers shown if error */
2398static int num_callers = 6;
2399static const char **rt_bound_error_msg;
2400
2401/* XXX: get rid of this ASAP */
2402static struct TCCState *tcc_state;
2403
2404/* give the path of the tcc libraries */
2405static const char *tcc_lib_path = CONFIG_TCCDIR;
2406
2407struct TCCState {
2408    int output_type;
2409
2410    BufferedFile **include_stack_ptr;
2411    int *ifdef_stack_ptr;
2412
2413    /* include file handling */
2414    char **include_paths;
2415    int nb_include_paths;
2416    char **sysinclude_paths;
2417    int nb_sysinclude_paths;
2418    CachedInclude **cached_includes;
2419    int nb_cached_includes;
2420
2421    char **library_paths;
2422    int nb_library_paths;
2423
2424    /* array of all loaded dlls (including those referenced by loaded
2425       dlls) */
2426    DLLReference **loaded_dlls;
2427    int nb_loaded_dlls;
2428
2429    /* sections */
2430    Section **sections;
2431    int nb_sections; /* number of sections, including first dummy section */
2432
2433    /* got handling */
2434    Section *got;
2435    Section *plt;
2436    unsigned long *got_offsets;
2437    int nb_got_offsets;
2438    /* give the correspondance from symtab indexes to dynsym indexes */
2439    int *symtab_to_dynsym;
2440
2441    /* temporary dynamic symbol sections (for dll loading) */
2442    Section *dynsymtab_section;
2443    /* exported dynamic symbol section */
2444    Section *dynsym;
2445
2446    int nostdinc; /* if true, no standard headers are added */
2447    int nostdlib; /* if true, no standard libraries are added */
2448
2449    int nocommon; /* if true, do not use common symbols for .bss data */
2450
2451    /* if true, static linking is performed */
2452    int static_link;
2453
2454    /* if true, all symbols are exported */
2455    int rdynamic;
2456
2457    /* if true, only link in referenced objects from archive */
2458    int alacarte_link;
2459
2460    /* address of text section */
2461    unsigned long text_addr;
2462    int has_text_addr;
2463
2464    /* output format, see TCC_OUTPUT_FORMAT_xxx */
2465    int output_format;
2466
2467    /* C language options */
2468    int char_is_unsigned;
2469    int leading_underscore;
2470
2471    /* warning switches */
2472    int warn_write_strings;
2473    int warn_unsupported;
2474    int warn_error;
2475    int warn_none;
2476    int warn_implicit_function_declaration;
2477
2478    /* error handling */
2479    void *error_opaque;
2480    void (*error_func)(void *opaque, const char *msg);
2481    int error_set_jmp_enabled;
2482    jmp_buf error_jmp_buf;
2483    int nb_errors;
2484
2485    /* tiny assembler state */
2486    Sym *asm_labels;
2487
2488    /* see include_stack_ptr */
2489    BufferedFile *include_stack[INCLUDE_STACK_SIZE];
2490
2491    /* see ifdef_stack_ptr */
2492    int ifdef_stack[IFDEF_STACK_SIZE];
2493
2494    /* see cached_includes */
2495    int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
2496
2497    /* pack stack */
2498    int pack_stack[PACK_STACK_SIZE];
2499    int *pack_stack_ptr;
2500};
2501
2502/* The current value can be: */
2503#define VT_VALMASK   0x00ff
2504#define VT_CONST     0x00f0  /* constant in vc
2505                              (must be first non register value) */
2506#define VT_LLOCAL    0x00f1  /* lvalue, offset on stack */
2507#define VT_LOCAL     0x00f2  /* offset on stack */
2508#define VT_CMP       0x00f3  /* the value is stored in processor flags (in vc) */
2509#define VT_JMP       0x00f4  /* value is the consequence of jmp true (even) */
2510#define VT_JMPI      0x00f5  /* value is the consequence of jmp false (odd) */
2511#define VT_LVAL      0x0100  /* var is an lvalue */
2512#define VT_SYM       0x0200  /* a symbol value is added */
2513#define VT_MUSTCAST  0x0400  /* value must be casted to be correct (used for
2514                                char/short stored in integer registers) */
2515#define VT_MUSTBOUND 0x0800  /* bound checking must be done before
2516                                dereferencing value */
2517#define VT_BOUNDED   0x8000  /* value is bounded. The address of the
2518                                bounding function call point is in vc */
2519#define VT_LVAL_BYTE     0x1000  /* lvalue is a byte */
2520#define VT_LVAL_SHORT    0x2000  /* lvalue is a short */
2521#define VT_LVAL_UNSIGNED 0x4000  /* lvalue is unsigned */
2522#define VT_LVAL_TYPE     (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
2523
2524/* types */
2525#define VT_INT        0  /* integer type */
2526#define VT_BYTE       1  /* signed byte type */
2527#define VT_SHORT      2  /* short type */
2528#define VT_VOID       3  /* void type */
2529#define VT_PTR        4  /* pointer */
2530#define VT_ENUM       5  /* enum definition */
2531#define VT_FUNC       6  /* function type */
2532#define VT_STRUCT     7  /* struct/union definition */
2533#define VT_FLOAT      8  /* IEEE float */
2534#define VT_DOUBLE     9  /* IEEE double */
2535#define VT_LDOUBLE   10  /* IEEE long double */
2536#define VT_BOOL      11  /* ISOC99 boolean type */
2537#define VT_LLONG     12  /* 64 bit integer */
2538#define VT_LONG      13  /* long integer (NEVER USED as type, only
2539                            during parsing) */
2540#define VT_BTYPE      0x000f /* mask for basic type */
2541#define VT_UNSIGNED   0x0010  /* unsigned type */
2542#define VT_ARRAY      0x0020  /* array type (also has VT_PTR) */
2543#define VT_BITFIELD   0x0040  /* bitfield modifier */
2544#define VT_CONSTANT   0x0800  /* const modifier */
2545#define VT_VOLATILE   0x1000  /* volatile modifier */
2546#define VT_SIGNED     0x2000  /* signed type */
2547
2548/* storage */
2549#define VT_EXTERN  0x00000080  /* extern definition */
2550#define VT_STATIC  0x00000100  /* static variable */
2551#define VT_TYPEDEF 0x00000200  /* typedef definition */
2552#define VT_INLINE  0x00000400  /* inline definition */
2553
2554#define VT_STRUCT_SHIFT 16   /* shift for bitfield shift values */
2555
2556/* type mask (except storage) */
2557#define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
2558#define VT_TYPE    (~(VT_STORAGE))
2559
2560/* token values */
2561
2562/* warning: the following compare tokens depend on i386 asm code */
2563#define TOK_ULT 0x92
2564#define TOK_UGE 0x93
2565#define TOK_EQ  0x94
2566#define TOK_NE  0x95
2567#define TOK_ULE 0x96
2568#define TOK_UGT 0x97
2569#define TOK_LT  0x9c
2570#define TOK_GE  0x9d
2571#define TOK_LE  0x9e
2572#define TOK_GT  0x9f
2573
2574#define TOK_LAND  0xa0
2575#define TOK_LOR   0xa1
2576
2577#define TOK_DEC   0xa2
2578#define TOK_MID   0xa3 /* inc/dec, to void constant */
2579#define TOK_INC   0xa4
2580#define TOK_UDIV  0xb0 /* unsigned division */
2581#define TOK_UMOD  0xb1 /* unsigned modulo */
2582#define TOK_PDIV  0xb2 /* fast division with undefined rounding for pointers */
2583#define TOK_CINT   0xb3 /* number in tokc */
2584#define TOK_CCHAR 0xb4 /* char constant in tokc */
2585#define TOK_STR   0xb5 /* pointer to string in tokc */
2586#define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
2587#define TOK_LCHAR    0xb7
2588#define TOK_LSTR     0xb8
2589#define TOK_CFLOAT   0xb9 /* float constant */
2590#define TOK_LINENUM  0xba /* line number info */
2591#define TOK_CDOUBLE  0xc0 /* double constant */
2592#define TOK_CLDOUBLE 0xc1 /* long double constant */
2593#define TOK_UMULL    0xc2 /* unsigned 32x32 -> 64 mul */
2594#define TOK_ADDC1    0xc3 /* add with carry generation */
2595#define TOK_ADDC2    0xc4 /* add with carry use */
2596#define TOK_SUBC1    0xc5 /* add with carry generation */
2597#define TOK_SUBC2    0xc6 /* add with carry use */
2598#define TOK_CUINT    0xc8 /* unsigned int constant */
2599#define TOK_CLLONG   0xc9 /* long long constant */
2600#define TOK_CULLONG  0xca /* unsigned long long constant */
2601#define TOK_ARROW    0xcb
2602#define TOK_DOTS     0xcc /* three dots */
2603#define TOK_SHR      0xcd /* unsigned shift right */
2604#define TOK_PPNUM    0xce /* preprocessor number */
2605
2606#define TOK_SHL   0x01 /* shift left */
2607#define TOK_SAR   0x02 /* signed shift right */
2608
2609/* assignement operators : normal operator or 0x80 */
2610#define TOK_A_MOD 0xa5
2611#define TOK_A_AND 0xa6
2612#define TOK_A_MUL 0xaa
2613#define TOK_A_ADD 0xab
2614#define TOK_A_SUB 0xad
2615#define TOK_A_DIV 0xaf
2616#define TOK_A_XOR 0xde
2617#define TOK_A_OR  0xfc
2618#define TOK_A_SHL 0x81
2619#define TOK_A_SAR 0x82
2620
2621#ifndef offsetof
2622#define offsetof(type, field) ((size_t) &((type *)0)->field)
2623#endif
2624
2625#ifndef countof
2626#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
2627#endif
2628
2629/* WARNING: the content of this string encodes token numbers */
2630static char tok_two_chars[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266";
2631
2632#define TOK_EOF       (-1)  /* end of file */
2633#define TOK_LINEFEED  10    /* line feed */
2634
2635/* all identificators and strings have token above that */
2636#define TOK_IDENT 256
2637
2638/* only used for i386 asm opcodes definitions */
2639#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
2640
2641#define DEF_BWL(x) \
2642 DEF(TOK_ASM_ ## x ## b, #x "b") \
2643 DEF(TOK_ASM_ ## x ## w, #x "w") \
2644 DEF(TOK_ASM_ ## x ## l, #x "l") \
2645 DEF(TOK_ASM_ ## x, #x)
2646
2647#define DEF_WL(x) \
2648 DEF(TOK_ASM_ ## x ## w, #x "w") \
2649 DEF(TOK_ASM_ ## x ## l, #x "l") \
2650 DEF(TOK_ASM_ ## x, #x)
2651
2652#define DEF_FP1(x) \
2653 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
2654 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
2655 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
2656 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
2657
2658#define DEF_FP(x) \
2659 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
2660 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
2661 DEF_FP1(x)
2662
2663#define DEF_ASMTEST(x) \
2664 DEF_ASM(x ## o) \
2665 DEF_ASM(x ## no) \
2666 DEF_ASM(x ## b) \
2667 DEF_ASM(x ## c) \
2668 DEF_ASM(x ## nae) \
2669 DEF_ASM(x ## nb) \
2670 DEF_ASM(x ## nc) \
2671 DEF_ASM(x ## ae) \
2672 DEF_ASM(x ## e) \
2673 DEF_ASM(x ## z) \
2674 DEF_ASM(x ## ne) \
2675 DEF_ASM(x ## nz) \
2676 DEF_ASM(x ## be) \
2677 DEF_ASM(x ## na) \
2678 DEF_ASM(x ## nbe) \
2679 DEF_ASM(x ## a) \
2680 DEF_ASM(x ## s) \
2681 DEF_ASM(x ## ns) \
2682 DEF_ASM(x ## p) \
2683 DEF_ASM(x ## pe) \
2684 DEF_ASM(x ## np) \
2685 DEF_ASM(x ## po) \
2686 DEF_ASM(x ## l) \
2687 DEF_ASM(x ## nge) \
2688 DEF_ASM(x ## nl) \
2689 DEF_ASM(x ## ge) \
2690 DEF_ASM(x ## le) \
2691 DEF_ASM(x ## ng) \
2692 DEF_ASM(x ## nle) \
2693 DEF_ASM(x ## g)
2694
2695#define TOK_ASM_int TOK_INT
2696
2697enum tcc_token {
2698    TOK_LAST = TOK_IDENT - 1,
2699#define DEF(id, str) id,
2700// njn: inlined tcctok.h
2701//#include "tcctok.h"
2702//---------------------------------------------------------------------------
2703/* keywords */
2704     DEF(TOK_INT, "int")
2705     DEF(TOK_VOID, "void")
2706     DEF(TOK_CHAR, "char")
2707     DEF(TOK_IF, "if")
2708     DEF(TOK_ELSE, "else")
2709     DEF(TOK_WHILE, "while")
2710     DEF(TOK_BREAK, "break")
2711     DEF(TOK_RETURN, "return")
2712     DEF(TOK_FOR, "for")
2713     DEF(TOK_EXTERN, "extern")
2714     DEF(TOK_STATIC, "static")
2715     DEF(TOK_UNSIGNED, "unsigned")
2716     DEF(TOK_GOTO, "goto")
2717     DEF(TOK_DO, "do")
2718     DEF(TOK_CONTINUE, "continue")
2719     DEF(TOK_SWITCH, "switch")
2720     DEF(TOK_CASE, "case")
2721
2722     DEF(TOK_CONST1, "const")
2723     DEF(TOK_CONST2, "__const") /* gcc keyword */
2724     DEF(TOK_CONST3, "__const__") /* gcc keyword */
2725     DEF(TOK_VOLATILE1, "volatile")
2726     DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
2727     DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
2728     DEF(TOK_LONG, "long")
2729     DEF(TOK_REGISTER, "register")
2730     DEF(TOK_SIGNED1, "signed")
2731     DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
2732     DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
2733     DEF(TOK_AUTO, "auto")
2734     DEF(TOK_INLINE1, "inline")
2735     DEF(TOK_INLINE2, "__inline") /* gcc keyword */
2736     DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
2737     DEF(TOK_RESTRICT1, "restrict")
2738     DEF(TOK_RESTRICT2, "__restrict")
2739     DEF(TOK_RESTRICT3, "__restrict__")
2740     DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
2741
2742     DEF(TOK_FLOAT, "float")
2743     DEF(TOK_DOUBLE, "double")
2744     DEF(TOK_BOOL, "_Bool")
2745     DEF(TOK_SHORT, "short")
2746     DEF(TOK_STRUCT, "struct")
2747     DEF(TOK_UNION, "union")
2748     DEF(TOK_TYPEDEF, "typedef")
2749     DEF(TOK_DEFAULT, "default")
2750     DEF(TOK_ENUM, "enum")
2751     DEF(TOK_SIZEOF, "sizeof")
2752     DEF(TOK_ATTRIBUTE1, "__attribute")
2753     DEF(TOK_ATTRIBUTE2, "__attribute__")
2754     DEF(TOK_ALIGNOF1, "__alignof")
2755     DEF(TOK_ALIGNOF2, "__alignof__")
2756     DEF(TOK_TYPEOF1, "typeof")
2757     DEF(TOK_TYPEOF2, "__typeof")
2758     DEF(TOK_TYPEOF3, "__typeof__")
2759     DEF(TOK_LABEL, "__label__")
2760     DEF(TOK_ASM1, "asm")
2761     DEF(TOK_ASM2, "__asm")
2762     DEF(TOK_ASM3, "__asm__")
2763
2764/*********************************************************************/
2765/* the following are not keywords. They are included to ease parsing */
2766/* preprocessor only */
2767     DEF(TOK_DEFINE, "define")
2768     DEF(TOK_INCLUDE, "include")
2769     DEF(TOK_INCLUDE_NEXT, "include_next")
2770     DEF(TOK_IFDEF, "ifdef")
2771     DEF(TOK_IFNDEF, "ifndef")
2772     DEF(TOK_ELIF, "elif")
2773     DEF(TOK_ENDIF, "endif")
2774     DEF(TOK_DEFINED, "defined")
2775     DEF(TOK_UNDEF, "undef")
2776     DEF(TOK_ERROR, "error")
2777     DEF(TOK_WARNING, "warning")
2778     DEF(TOK_LINE, "line")
2779     DEF(TOK_PRAGMA, "pragma")
2780     DEF(TOK___LINE__, "__LINE__")
2781     DEF(TOK___FILE__, "__FILE__")
2782     DEF(TOK___DATE__, "__DATE__")
2783     DEF(TOK___TIME__, "__TIME__")
2784     DEF(TOK___FUNCTION__, "__FUNCTION__")
2785     DEF(TOK___VA_ARGS__, "__VA_ARGS__")
2786
2787/* special identifiers */
2788     DEF(TOK___FUNC__, "__func__")
2789
2790/* attribute identifiers */
2791/* XXX: handle all tokens generically since speed is not critical */
2792     DEF(TOK_SECTION1, "section")
2793     DEF(TOK_SECTION2, "__section__")
2794     DEF(TOK_ALIGNED1, "aligned")
2795     DEF(TOK_ALIGNED2, "__aligned__")
2796     DEF(TOK_PACKED1, "packed")
2797     DEF(TOK_PACKED2, "__packed__")
2798     DEF(TOK_UNUSED1, "unused")
2799     DEF(TOK_UNUSED2, "__unused__")
2800     DEF(TOK_CDECL1, "cdecl")
2801     DEF(TOK_CDECL2, "__cdecl")
2802     DEF(TOK_CDECL3, "__cdecl__")
2803     DEF(TOK_STDCALL1, "stdcall")
2804     DEF(TOK_STDCALL2, "__stdcall")
2805     DEF(TOK_STDCALL3, "__stdcall__")
2806     DEF(TOK_DLLEXPORT, "dllexport")
2807     DEF(TOK_NORETURN1, "noreturn")
2808     DEF(TOK_NORETURN2, "__noreturn__")
2809     DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
2810     DEF(TOK_builtin_constant_p, "__builtin_constant_p")
2811     DEF(TOK_REGPARM1, "regparm")
2812     DEF(TOK_REGPARM2, "__regparm__")
2813
2814/* pragma */
2815     DEF(TOK_pack, "pack")
2816#if !defined(TCC_TARGET_I386)
2817     /* already defined for assembler */
2818     DEF(TOK_ASM_push, "push")
2819     DEF(TOK_ASM_pop, "pop")
2820#endif
2821
2822/* builtin functions or variables */
2823     DEF(TOK_memcpy, "memcpy")
2824     DEF(TOK_memset, "memset")
2825     DEF(TOK_alloca, "alloca")
2826     DEF(TOK___divdi3, "__divdi3")
2827     DEF(TOK___moddi3, "__moddi3")
2828     DEF(TOK___udivdi3, "__udivdi3")
2829     DEF(TOK___umoddi3, "__umoddi3")
2830#if defined(TCC_TARGET_ARM)
2831     DEF(TOK___divsi3, "__divsi3")
2832     DEF(TOK___modsi3, "__modsi3")
2833     DEF(TOK___udivsi3, "__udivsi3")
2834     DEF(TOK___umodsi3, "__umodsi3")
2835     DEF(TOK___sardi3, "__ashrdi3")
2836     DEF(TOK___shrdi3, "__lshrdi3")
2837     DEF(TOK___shldi3, "__ashldi3")
2838     DEF(TOK___slltold, "__slltold")
2839     DEF(TOK___fixunssfsi, "__fixunssfsi")
2840     DEF(TOK___fixunsdfsi, "__fixunsdfsi")
2841     DEF(TOK___fixunsxfsi, "__fixunsxfsi")
2842     DEF(TOK___fixsfdi, "__fixsfdi")
2843     DEF(TOK___fixdfdi, "__fixdfdi")
2844     DEF(TOK___fixxfdi, "__fixxfdi")
2845#elif defined(TCC_TARGET_C67)
2846     DEF(TOK__divi, "_divi")
2847     DEF(TOK__divu, "_divu")
2848     DEF(TOK__divf, "_divf")
2849     DEF(TOK__divd, "_divd")
2850     DEF(TOK__remi, "_remi")
2851     DEF(TOK__remu, "_remu")
2852     DEF(TOK___sardi3, "__sardi3")
2853     DEF(TOK___shrdi3, "__shrdi3")
2854     DEF(TOK___shldi3, "__shldi3")
2855#else
2856     /* XXX: same names on i386 ? */
2857     DEF(TOK___sardi3, "__sardi3")
2858     DEF(TOK___shrdi3, "__shrdi3")
2859     DEF(TOK___shldi3, "__shldi3")
2860#endif
2861     DEF(TOK___tcc_int_fpu_control, "__tcc_int_fpu_control")
2862     DEF(TOK___tcc_fpu_control, "__tcc_fpu_control")
2863     DEF(TOK___ulltof, "__ulltof")
2864     DEF(TOK___ulltod, "__ulltod")
2865     DEF(TOK___ulltold, "__ulltold")
2866     DEF(TOK___fixunssfdi, "__fixunssfdi")
2867     DEF(TOK___fixunsdfdi, "__fixunsdfdi")
2868     DEF(TOK___fixunsxfdi, "__fixunsxfdi")
2869     DEF(TOK___chkstk, "__chkstk")
2870
2871/* bound checking symbols */
2872#ifdef CONFIG_TCC_BCHECK
2873     DEF(TOK___bound_ptr_add, "__bound_ptr_add")
2874     DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
2875     DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
2876     DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
2877     DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
2878     DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
2879     DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
2880     DEF(TOK___bound_local_new, "__bound_local_new")
2881     DEF(TOK___bound_local_delete, "__bound_local_delete")
2882     DEF(TOK_malloc, "malloc")
2883     DEF(TOK_free, "free")
2884     DEF(TOK_realloc, "realloc")
2885     DEF(TOK_memalign, "memalign")
2886     DEF(TOK_calloc, "calloc")
2887     DEF(TOK_memmove, "memmove")
2888     DEF(TOK_strlen, "strlen")
2889     DEF(TOK_strcpy, "strcpy")
2890#endif
2891
2892/* Tiny Assembler */
2893
2894 DEF_ASM(byte)
2895 DEF_ASM(align)
2896 DEF_ASM(skip)
2897 DEF_ASM(space)
2898 DEF_ASM(string)
2899 DEF_ASM(asciz)
2900 DEF_ASM(ascii)
2901 DEF_ASM(globl)
2902 DEF_ASM(global)
2903 DEF_ASM(text)
2904 DEF_ASM(data)
2905 DEF_ASM(bss)
2906 DEF_ASM(previous)
2907 DEF_ASM(fill)
2908 DEF_ASM(org)
2909 DEF_ASM(quad)
2910
2911#ifdef TCC_TARGET_I386
2912
2913/* WARNING: relative order of tokens is important. */
2914 DEF_ASM(al)
2915 DEF_ASM(cl)
2916 DEF_ASM(dl)
2917 DEF_ASM(bl)
2918 DEF_ASM(ah)
2919 DEF_ASM(ch)
2920 DEF_ASM(dh)
2921 DEF_ASM(bh)
2922 DEF_ASM(ax)
2923 DEF_ASM(cx)
2924 DEF_ASM(dx)
2925 DEF_ASM(bx)
2926 DEF_ASM(sp)
2927 DEF_ASM(bp)
2928 DEF_ASM(si)
2929 DEF_ASM(di)
2930 DEF_ASM(eax)
2931 DEF_ASM(ecx)
2932 DEF_ASM(edx)
2933 DEF_ASM(ebx)
2934 DEF_ASM(esp)
2935 DEF_ASM(ebp)
2936 DEF_ASM(esi)
2937 DEF_ASM(edi)
2938 DEF_ASM(mm0)
2939 DEF_ASM(mm1)
2940 DEF_ASM(mm2)
2941 DEF_ASM(mm3)
2942 DEF_ASM(mm4)
2943 DEF_ASM(mm5)
2944 DEF_ASM(mm6)
2945 DEF_ASM(mm7)
2946 DEF_ASM(xmm0)
2947 DEF_ASM(xmm1)
2948 DEF_ASM(xmm2)
2949 DEF_ASM(xmm3)
2950 DEF_ASM(xmm4)
2951 DEF_ASM(xmm5)
2952 DEF_ASM(xmm6)
2953 DEF_ASM(xmm7)
2954 DEF_ASM(cr0)
2955 DEF_ASM(cr1)
2956 DEF_ASM(cr2)
2957 DEF_ASM(cr3)
2958 DEF_ASM(cr4)
2959 DEF_ASM(cr5)
2960 DEF_ASM(cr6)
2961 DEF_ASM(cr7)
2962 DEF_ASM(tr0)
2963 DEF_ASM(tr1)
2964 DEF_ASM(tr2)
2965 DEF_ASM(tr3)
2966 DEF_ASM(tr4)
2967 DEF_ASM(tr5)
2968 DEF_ASM(tr6)
2969 DEF_ASM(tr7)
2970 DEF_ASM(db0)
2971 DEF_ASM(db1)
2972 DEF_ASM(db2)
2973 DEF_ASM(db3)
2974 DEF_ASM(db4)
2975 DEF_ASM(db5)
2976 DEF_ASM(db6)
2977 DEF_ASM(db7)
2978 DEF_ASM(dr0)
2979 DEF_ASM(dr1)
2980 DEF_ASM(dr2)
2981 DEF_ASM(dr3)
2982 DEF_ASM(dr4)
2983 DEF_ASM(dr5)
2984 DEF_ASM(dr6)
2985 DEF_ASM(dr7)
2986 DEF_ASM(es)
2987 DEF_ASM(cs)
2988 DEF_ASM(ss)
2989 DEF_ASM(ds)
2990 DEF_ASM(fs)
2991 DEF_ASM(gs)
2992 DEF_ASM(st)
2993
2994 DEF_BWL(mov)
2995
2996 /* generic two operands */
2997 DEF_BWL(add)
2998 DEF_BWL(or)
2999 DEF_BWL(adc)
3000 DEF_BWL(sbb)
3001 DEF_BWL(and)
3002 DEF_BWL(sub)
3003 DEF_BWL(xor)
3004 DEF_BWL(cmp)
3005
3006 /* unary ops */
3007 DEF_BWL(inc)
3008 DEF_BWL(dec)
3009 DEF_BWL(not)
3010 DEF_BWL(neg)
3011 DEF_BWL(mul)
3012 DEF_BWL(imul)
3013 DEF_BWL(div)
3014 DEF_BWL(idiv)
3015
3016 DEF_BWL(xchg)
3017 DEF_BWL(test)
3018
3019 /* shifts */
3020 DEF_BWL(rol)
3021 DEF_BWL(ror)
3022 DEF_BWL(rcl)
3023 DEF_BWL(rcr)
3024 DEF_BWL(shl)
3025 DEF_BWL(shr)
3026 DEF_BWL(sar)
3027
3028 DEF_ASM(shldw)
3029 DEF_ASM(shldl)
3030 DEF_ASM(shld)
3031 DEF_ASM(shrdw)
3032 DEF_ASM(shrdl)
3033 DEF_ASM(shrd)
3034
3035 DEF_ASM(pushw)
3036 DEF_ASM(pushl)
3037 DEF_ASM(push)
3038 DEF_ASM(popw)
3039 DEF_ASM(popl)
3040 DEF_ASM(pop)
3041 DEF_BWL(in)
3042 DEF_BWL(out)
3043
3044 DEF_WL(movzb)
3045
3046 DEF_ASM(movzwl)
3047 DEF_ASM(movsbw)
3048 DEF_ASM(movsbl)
3049 DEF_ASM(movswl)
3050
3051 DEF_WL(lea)
3052
3053 DEF_ASM(les)
3054 DEF_ASM(lds)
3055 DEF_ASM(lss)
3056 DEF_ASM(lfs)
3057 DEF_ASM(lgs)
3058
3059 DEF_ASM(call)
3060 DEF_ASM(jmp)
3061 DEF_ASM(lcall)
3062 DEF_ASM(ljmp)
3063
3064 DEF_ASMTEST(j)
3065
3066 DEF_ASMTEST(set)
3067 DEF_ASMTEST(cmov)
3068
3069 DEF_WL(bsf)
3070 DEF_WL(bsr)
3071 DEF_WL(bt)
3072 DEF_WL(bts)
3073 DEF_WL(btr)
3074 DEF_WL(btc)
3075
3076 DEF_WL(lsl)
3077
3078 /* generic FP ops */
3079 DEF_FP(add)
3080 DEF_FP(mul)
3081
3082 DEF_ASM(fcom)
3083 DEF_ASM(fcom_1) /* non existant op, just to have a regular table */
3084 DEF_FP1(com)
3085
3086 DEF_FP(comp)
3087 DEF_FP(sub)
3088 DEF_FP(subr)
3089 DEF_FP(div)
3090 DEF_FP(divr)
3091
3092 DEF_BWL(xadd)
3093 DEF_BWL(cmpxchg)
3094
3095 /* string ops */
3096 DEF_BWL(cmps)
3097 DEF_BWL(scmp)
3098 DEF_BWL(ins)
3099 DEF_BWL(outs)
3100 DEF_BWL(lods)
3101 DEF_BWL(slod)
3102 DEF_BWL(movs)
3103 DEF_BWL(smov)
3104 DEF_BWL(scas)
3105 DEF_BWL(ssca)
3106 DEF_BWL(stos)
3107 DEF_BWL(ssto)
3108
3109 /* generic asm ops */
3110
3111#define ALT(x)
3112#define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
3113#define DEF_ASM_OP0L(name, opcode, group, instr_type)
3114#define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
3115#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
3116#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
3117// njn: inlined i386-asm.h
3118//#include "i386-asm.h"
3119//---------------------------------------------------------------------------
3120     DEF_ASM_OP0(pusha, 0x60) /* must be first OP0 */
3121     DEF_ASM_OP0(popa, 0x61)
3122     DEF_ASM_OP0(clc, 0xf8)
3123     DEF_ASM_OP0(cld, 0xfc)
3124     DEF_ASM_OP0(cli, 0xfa)
3125     DEF_ASM_OP0(clts, 0x0f06)
3126     DEF_ASM_OP0(cmc, 0xf5)
3127     DEF_ASM_OP0(lahf, 0x9f)
3128     DEF_ASM_OP0(sahf, 0x9e)
3129     DEF_ASM_OP0(pushfl, 0x9c)
3130     DEF_ASM_OP0(popfl, 0x9d)
3131     DEF_ASM_OP0(pushf, 0x9c)
3132     DEF_ASM_OP0(popf, 0x9d)
3133     DEF_ASM_OP0(stc, 0xf9)
3134     DEF_ASM_OP0(std, 0xfd)
3135     DEF_ASM_OP0(sti, 0xfb)
3136     DEF_ASM_OP0(aaa, 0x37)
3137     DEF_ASM_OP0(aas, 0x3f)
3138     DEF_ASM_OP0(daa, 0x27)
3139     DEF_ASM_OP0(das, 0x2f)
3140     DEF_ASM_OP0(aad, 0xd50a)
3141     DEF_ASM_OP0(aam, 0xd40a)
3142     DEF_ASM_OP0(cbw, 0x6698)
3143     DEF_ASM_OP0(cwd, 0x6699)
3144     DEF_ASM_OP0(cwde, 0x98)
3145     DEF_ASM_OP0(cdq, 0x99)
3146     DEF_ASM_OP0(cbtw, 0x6698)
3147     DEF_ASM_OP0(cwtl, 0x98)
3148     DEF_ASM_OP0(cwtd, 0x6699)
3149     DEF_ASM_OP0(cltd, 0x99)
3150     DEF_ASM_OP0(int3, 0xcc)
3151     DEF_ASM_OP0(into, 0xce)
3152     DEF_ASM_OP0(iret, 0xcf)
3153     DEF_ASM_OP0(rsm, 0x0faa)
3154     DEF_ASM_OP0(hlt, 0xf4)
3155     DEF_ASM_OP0(wait, 0x9b)
3156     DEF_ASM_OP0(nop, 0x90)
3157     DEF_ASM_OP0(xlat, 0xd7)
3158
3159     /* strings */
3160ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWL))
3161ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWL))
3162
3163ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
3164ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
3165
3166ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWL))
3167ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWL))
3168
3169ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWL))
3170ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWL))
3171
3172ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWL))
3173ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWL))
3174
3175ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWL))
3176ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWL))
3177
3178     /* bits */
3179
3180ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
3181ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
3182
3183ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3184ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3185
3186ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3187ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3188
3189ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3190ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3191
3192ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3193ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3194
3195     /* prefixes */
3196     DEF_ASM_OP0(aword, 0x67)
3197     DEF_ASM_OP0(addr16, 0x67)
3198     DEF_ASM_OP0(word, 0x66)
3199     DEF_ASM_OP0(data16, 0x66)
3200     DEF_ASM_OP0(lock, 0xf0)
3201     DEF_ASM_OP0(rep, 0xf3)
3202     DEF_ASM_OP0(repe, 0xf3)
3203     DEF_ASM_OP0(repz, 0xf3)
3204     DEF_ASM_OP0(repne, 0xf2)
3205     DEF_ASM_OP0(repnz, 0xf2)
3206
3207     DEF_ASM_OP0(invd, 0x0f08)
3208     DEF_ASM_OP0(wbinvd, 0x0f09)
3209     DEF_ASM_OP0(cpuid, 0x0fa2)
3210     DEF_ASM_OP0(wrmsr, 0x0f30)
3211     DEF_ASM_OP0(rdtsc, 0x0f31)
3212     DEF_ASM_OP0(rdmsr, 0x0f32)
3213     DEF_ASM_OP0(rdpmc, 0x0f33)
3214     DEF_ASM_OP0(ud2, 0x0f0b)
3215
3216     /* NOTE: we took the same order as gas opcode definition order */
3217ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWL, OPT_ADDR, OPT_EAX))
3218ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWL, OPT_EAX, OPT_ADDR))
3219ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3220ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3221ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWL, OPT_IM, OPT_REG))
3222ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_REG | OPT_EA))
3223
3224ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WL, OPT_SEG, OPT_EA | OPT_REG))
3225ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_SEG))
3226
3227ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WL, OPT_CR, OPT_REG32))
3228ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WL, OPT_DB, OPT_REG32))
3229ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WL, OPT_TR, OPT_REG32))
3230ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_CR))
3231ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_DB))
3232ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_TR))
3233
3234ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
3235ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
3236ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
3237ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
3238ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
3239
3240ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
3241ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
3242ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
3243ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
3244ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
3245
3246ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
3247ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
3248ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WL, OPT_SEG))
3249
3250ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_REG, OPT_EAX))
3251ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_EAX, OPT_REG))
3252ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3253ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3254
3255ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
3256ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
3257ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
3258ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
3259
3260ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
3261ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
3262ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
3263ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
3264
3265ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WL, OPT_EA, OPT_REG))
3266
3267ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3268ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3269ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3270ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3271ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3272
3273     /* arith */
3274ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
3275ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3276ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
3277ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
3278ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, OPT_EA | OPT_REG))
3279
3280ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3281ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3282ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWL, OPT_IM, OPT_EAX))
3283ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
3284
3285ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WL, OPT_REGW))
3286ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3287ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WL, OPT_REGW))
3288ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3289
3290ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3291ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3292
3293ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3294ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3295
3296ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WL, OPT_REG | OPT_EA, OPT_REG))
3297ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
3298ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW))
3299ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
3300ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW))
3301
3302ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3303ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
3304ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3305ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
3306
3307     /* shifts */
3308ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
3309ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
3310ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_EA | OPT_REG))
3311
3312ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
3313ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
3314ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
3315ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
3316ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
3317ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
3318
3319ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
3320ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
3321ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
3322ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
3323
3324ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
3325ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
3326ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
3327ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
3328
3329ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
3330ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
3331    DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
3332    DEF_ASM_OP0(leave, 0xc9)
3333    DEF_ASM_OP0(ret, 0xc3)
3334ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
3335    DEF_ASM_OP0(lret, 0xcb)
3336ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
3337
3338ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
3339    DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
3340    DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
3341    DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
3342    DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
3343    DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
3344    DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
3345
3346     /* float */
3347     /* specific fcomp handling */
3348ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
3349
3350ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
3351ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
3352ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
3353ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
3354ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
3355ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
3356ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
3357ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3358ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3359ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3360ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3361
3362     DEF_ASM_OP0(fucompp, 0xdae9)
3363     DEF_ASM_OP0(ftst, 0xd9e4)
3364     DEF_ASM_OP0(fxam, 0xd9e5)
3365     DEF_ASM_OP0(fld1, 0xd9e8)
3366     DEF_ASM_OP0(fldl2t, 0xd9e9)
3367     DEF_ASM_OP0(fldl2e, 0xd9ea)
3368     DEF_ASM_OP0(fldpi, 0xd9eb)
3369     DEF_ASM_OP0(fldlg2, 0xd9ec)
3370     DEF_ASM_OP0(fldln2, 0xd9ed)
3371     DEF_ASM_OP0(fldz, 0xd9ee)
3372
3373     DEF_ASM_OP0(f2xm1, 0xd9f0)
3374     DEF_ASM_OP0(fyl2x, 0xd9f1)
3375     DEF_ASM_OP0(fptan, 0xd9f2)
3376     DEF_ASM_OP0(fpatan, 0xd9f3)
3377     DEF_ASM_OP0(fxtract, 0xd9f4)
3378     DEF_ASM_OP0(fprem1, 0xd9f5)
3379     DEF_ASM_OP0(fdecstp, 0xd9f6)
3380     DEF_ASM_OP0(fincstp, 0xd9f7)
3381     DEF_ASM_OP0(fprem, 0xd9f8)
3382     DEF_ASM_OP0(fyl2xp1, 0xd9f9)
3383     DEF_ASM_OP0(fsqrt, 0xd9fa)
3384     DEF_ASM_OP0(fsincos, 0xd9fb)
3385     DEF_ASM_OP0(frndint, 0xd9fc)
3386     DEF_ASM_OP0(fscale, 0xd9fd)
3387     DEF_ASM_OP0(fsin, 0xd9fe)
3388     DEF_ASM_OP0(fcos, 0xd9ff)
3389     DEF_ASM_OP0(fchs, 0xd9e0)
3390     DEF_ASM_OP0(fabs, 0xd9e1)
3391     DEF_ASM_OP0(fninit, 0xdbe3)
3392     DEF_ASM_OP0(fnclex, 0xdbe2)
3393     DEF_ASM_OP0(fnop, 0xd9d0)
3394     DEF_ASM_OP0(fwait, 0x9b)
3395
3396    /* fp load */
3397    DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
3398    DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
3399    DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
3400ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
3401    DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
3402    DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
3403    DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
3404    DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
3405    DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
3406
3407    /* fp store */
3408    DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
3409    DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
3410    DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
3411    DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
3412ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
3413    DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
3414    DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
3415    DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
3416    DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
3417    DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
3418
3419    DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
3420    DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
3421    DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
3422    DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
3423    DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
3424
3425    /* exchange */
3426    DEF_ASM_OP0(fxch, 0xd9c9)
3427ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
3428
3429    /* misc FPU */
3430    DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
3431    DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
3432
3433    DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
3434    DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
3435    DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
3436    DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
3437    DEF_ASM_OP0(fnstsw, 0xdfe0)
3438ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
3439ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
3440    DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
3441ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
3442ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
3443    DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
3444    DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
3445    DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
3446    DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
3447    DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
3448    DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
3449    DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
3450    DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
3451    DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
3452    DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
3453    DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
3454
3455    /* segments */
3456    DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
3457    DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
3458    DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
3459    DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
3460    DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
3461    DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
3462ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
3463    DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
3464    DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
3465    DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
3466    DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
3467    DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
3468    DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA)
3469    DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
3470    DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
3471
3472    /* 486 */
3473    DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
3474ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
3475ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
3476    DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
3477
3478    DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA)
3479    DEF_ASM_OP2(boundw, 0x62, 0, OPC_MODRM | OPC_D16, OPT_REG16, OPT_EA)
3480
3481    /* pentium */
3482    DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
3483
3484    /* pentium pro */
3485    ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
3486
3487    DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3488    DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3489    DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3490    DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3491    DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3492    DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3493    DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3494    DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3495
3496    DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3497    DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3498    DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3499    DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3500
3501    /* mmx */
3502    DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
3503    DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMX )
3504ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_REG32 ))
3505    DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3506ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
3507    DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3508    DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3509    DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3510    DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3511    DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3512    DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3513    DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3514    DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3515    DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3516    DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3517    DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3518    DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3519    DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3520    DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3521    DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3522    DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3523    DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3524    DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3525    DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3526    DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3527    DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3528    DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3529    DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3530ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3531    DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3532ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3533    DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3534ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3535    DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3536ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
3537    DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3538ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
3539    DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3540ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
3541    DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3542ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
3543    DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3544ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
3545    DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3546    DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3547    DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3548    DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3549    DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3550    DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3551    DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3552    DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3553    DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3554    DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3555    DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3556    DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3557    DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3558    DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3559
3560#undef ALT
3561#undef DEF_ASM_OP0
3562#undef DEF_ASM_OP0L
3563#undef DEF_ASM_OP1
3564#undef DEF_ASM_OP2
3565#undef DEF_ASM_OP3
3566//---------------------------------------------------------------------------
3567
3568#define ALT(x)
3569#define DEF_ASM_OP0(name, opcode)
3570#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name)
3571#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name)
3572#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name)
3573#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name)
3574// njn: inlined i386-asm.h
3575//#include "i386-asm.h"
3576//---------------------------------------------------------------------------
3577     DEF_ASM_OP0(pusha, 0x60) /* must be first OP0 */
3578     DEF_ASM_OP0(popa, 0x61)
3579     DEF_ASM_OP0(clc, 0xf8)
3580     DEF_ASM_OP0(cld, 0xfc)
3581     DEF_ASM_OP0(cli, 0xfa)
3582     DEF_ASM_OP0(clts, 0x0f06)
3583     DEF_ASM_OP0(cmc, 0xf5)
3584     DEF_ASM_OP0(lahf, 0x9f)
3585     DEF_ASM_OP0(sahf, 0x9e)
3586     DEF_ASM_OP0(pushfl, 0x9c)
3587     DEF_ASM_OP0(popfl, 0x9d)
3588     DEF_ASM_OP0(pushf, 0x9c)
3589     DEF_ASM_OP0(popf, 0x9d)
3590     DEF_ASM_OP0(stc, 0xf9)
3591     DEF_ASM_OP0(std, 0xfd)
3592     DEF_ASM_OP0(sti, 0xfb)
3593     DEF_ASM_OP0(aaa, 0x37)
3594     DEF_ASM_OP0(aas, 0x3f)
3595     DEF_ASM_OP0(daa, 0x27)
3596     DEF_ASM_OP0(das, 0x2f)
3597     DEF_ASM_OP0(aad, 0xd50a)
3598     DEF_ASM_OP0(aam, 0xd40a)
3599     DEF_ASM_OP0(cbw, 0x6698)
3600     DEF_ASM_OP0(cwd, 0x6699)
3601     DEF_ASM_OP0(cwde, 0x98)
3602     DEF_ASM_OP0(cdq, 0x99)
3603     DEF_ASM_OP0(cbtw, 0x6698)
3604     DEF_ASM_OP0(cwtl, 0x98)
3605     DEF_ASM_OP0(cwtd, 0x6699)
3606     DEF_ASM_OP0(cltd, 0x99)
3607     DEF_ASM_OP0(int3, 0xcc)
3608     DEF_ASM_OP0(into, 0xce)
3609     DEF_ASM_OP0(iret, 0xcf)
3610     DEF_ASM_OP0(rsm, 0x0faa)
3611     DEF_ASM_OP0(hlt, 0xf4)
3612     DEF_ASM_OP0(wait, 0x9b)
3613     DEF_ASM_OP0(nop, 0x90)
3614     DEF_ASM_OP0(xlat, 0xd7)
3615
3616     /* strings */
3617ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWL))
3618ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWL))
3619
3620ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
3621ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
3622
3623ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWL))
3624ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWL))
3625
3626ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWL))
3627ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWL))
3628
3629ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWL))
3630ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWL))
3631
3632ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWL))
3633ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWL))
3634
3635     /* bits */
3636
3637ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
3638ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
3639
3640ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3641ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3642
3643ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3644ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3645
3646ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3647ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3648
3649ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
3650ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
3651
3652     /* prefixes */
3653     DEF_ASM_OP0(aword, 0x67)
3654     DEF_ASM_OP0(addr16, 0x67)
3655     DEF_ASM_OP0(word, 0x66)
3656     DEF_ASM_OP0(data16, 0x66)
3657     DEF_ASM_OP0(lock, 0xf0)
3658     DEF_ASM_OP0(rep, 0xf3)
3659     DEF_ASM_OP0(repe, 0xf3)
3660     DEF_ASM_OP0(repz, 0xf3)
3661     DEF_ASM_OP0(repne, 0xf2)
3662     DEF_ASM_OP0(repnz, 0xf2)
3663
3664     DEF_ASM_OP0(invd, 0x0f08)
3665     DEF_ASM_OP0(wbinvd, 0x0f09)
3666     DEF_ASM_OP0(cpuid, 0x0fa2)
3667     DEF_ASM_OP0(wrmsr, 0x0f30)
3668     DEF_ASM_OP0(rdtsc, 0x0f31)
3669     DEF_ASM_OP0(rdmsr, 0x0f32)
3670     DEF_ASM_OP0(rdpmc, 0x0f33)
3671     DEF_ASM_OP0(ud2, 0x0f0b)
3672
3673     /* NOTE: we took the same order as gas opcode definition order */
3674ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWL, OPT_ADDR, OPT_EAX))
3675ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWL, OPT_EAX, OPT_ADDR))
3676ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3677ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3678ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWL, OPT_IM, OPT_REG))
3679ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_REG | OPT_EA))
3680
3681ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WL, OPT_SEG, OPT_EA | OPT_REG))
3682ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_SEG))
3683
3684ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WL, OPT_CR, OPT_REG32))
3685ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WL, OPT_DB, OPT_REG32))
3686ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WL, OPT_TR, OPT_REG32))
3687ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_CR))
3688ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_DB))
3689ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_TR))
3690
3691ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
3692ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
3693ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
3694ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
3695ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
3696
3697ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
3698ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
3699ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
3700ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
3701ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
3702
3703ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
3704ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
3705ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WL, OPT_SEG))
3706
3707ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_REG, OPT_EAX))
3708ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_EAX, OPT_REG))
3709ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3710ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3711
3712ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
3713ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
3714ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
3715ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
3716
3717ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
3718ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
3719ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
3720ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
3721
3722ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WL, OPT_EA, OPT_REG))
3723
3724ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3725ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3726ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3727ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3728ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
3729
3730     /* arith */
3731ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
3732ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3733ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
3734ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
3735ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, OPT_EA | OPT_REG))
3736
3737ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
3738ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
3739ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWL, OPT_IM, OPT_EAX))
3740ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
3741
3742ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WL, OPT_REGW))
3743ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3744ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WL, OPT_REGW))
3745ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3746
3747ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3748ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3749
3750ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3751ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3752
3753ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WL, OPT_REG | OPT_EA, OPT_REG))
3754ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
3755ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW))
3756ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
3757ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW))
3758
3759ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3760ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
3761ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
3762ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
3763
3764     /* shifts */
3765ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
3766ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
3767ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_EA | OPT_REG))
3768
3769ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
3770ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
3771ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
3772ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
3773ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
3774ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
3775
3776ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
3777ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
3778ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
3779ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
3780
3781ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
3782ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
3783ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
3784ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
3785
3786ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
3787ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
3788    DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
3789    DEF_ASM_OP0(leave, 0xc9)
3790    DEF_ASM_OP0(ret, 0xc3)
3791ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
3792    DEF_ASM_OP0(lret, 0xcb)
3793ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
3794
3795ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
3796    DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
3797    DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
3798    DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
3799    DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
3800    DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
3801    DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
3802
3803     /* float */
3804     /* specific fcomp handling */
3805ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
3806
3807ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
3808ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
3809ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
3810ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
3811ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
3812ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
3813ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
3814ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3815ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3816ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3817ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
3818
3819     DEF_ASM_OP0(fucompp, 0xdae9)
3820     DEF_ASM_OP0(ftst, 0xd9e4)
3821     DEF_ASM_OP0(fxam, 0xd9e5)
3822     DEF_ASM_OP0(fld1, 0xd9e8)
3823     DEF_ASM_OP0(fldl2t, 0xd9e9)
3824     DEF_ASM_OP0(fldl2e, 0xd9ea)
3825     DEF_ASM_OP0(fldpi, 0xd9eb)
3826     DEF_ASM_OP0(fldlg2, 0xd9ec)
3827     DEF_ASM_OP0(fldln2, 0xd9ed)
3828     DEF_ASM_OP0(fldz, 0xd9ee)
3829
3830     DEF_ASM_OP0(f2xm1, 0xd9f0)
3831     DEF_ASM_OP0(fyl2x, 0xd9f1)
3832     DEF_ASM_OP0(fptan, 0xd9f2)
3833     DEF_ASM_OP0(fpatan, 0xd9f3)
3834     DEF_ASM_OP0(fxtract, 0xd9f4)
3835     DEF_ASM_OP0(fprem1, 0xd9f5)
3836     DEF_ASM_OP0(fdecstp, 0xd9f6)
3837     DEF_ASM_OP0(fincstp, 0xd9f7)
3838     DEF_ASM_OP0(fprem, 0xd9f8)
3839     DEF_ASM_OP0(fyl2xp1, 0xd9f9)
3840     DEF_ASM_OP0(fsqrt, 0xd9fa)
3841     DEF_ASM_OP0(fsincos, 0xd9fb)
3842     DEF_ASM_OP0(frndint, 0xd9fc)
3843     DEF_ASM_OP0(fscale, 0xd9fd)
3844     DEF_ASM_OP0(fsin, 0xd9fe)
3845     DEF_ASM_OP0(fcos, 0xd9ff)
3846     DEF_ASM_OP0(fchs, 0xd9e0)
3847     DEF_ASM_OP0(fabs, 0xd9e1)
3848     DEF_ASM_OP0(fninit, 0xdbe3)
3849     DEF_ASM_OP0(fnclex, 0xdbe2)
3850     DEF_ASM_OP0(fnop, 0xd9d0)
3851     DEF_ASM_OP0(fwait, 0x9b)
3852
3853    /* fp load */
3854    DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
3855    DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
3856    DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
3857ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
3858    DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
3859    DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
3860    DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
3861    DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
3862    DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
3863
3864    /* fp store */
3865    DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
3866    DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
3867    DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
3868    DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
3869ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
3870    DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
3871    DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
3872    DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
3873    DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
3874    DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
3875
3876    DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
3877    DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
3878    DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
3879    DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
3880    DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
3881
3882    /* exchange */
3883    DEF_ASM_OP0(fxch, 0xd9c9)
3884ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
3885
3886    /* misc FPU */
3887    DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
3888    DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
3889
3890    DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
3891    DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
3892    DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
3893    DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
3894    DEF_ASM_OP0(fnstsw, 0xdfe0)
3895ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
3896ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
3897    DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
3898ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
3899ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
3900    DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
3901    DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
3902    DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
3903    DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
3904    DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
3905    DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
3906    DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
3907    DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
3908    DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
3909    DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
3910    DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
3911
3912    /* segments */
3913    DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
3914    DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
3915    DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
3916    DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
3917    DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
3918    DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
3919ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
3920    DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
3921    DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
3922    DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
3923    DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
3924    DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
3925    DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA)
3926    DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
3927    DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
3928
3929    /* 486 */
3930    DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
3931ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
3932ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
3933    DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
3934
3935    DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA)
3936    DEF_ASM_OP2(boundw, 0x62, 0, OPC_MODRM | OPC_D16, OPT_REG16, OPT_EA)
3937
3938    /* pentium */
3939    DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
3940
3941    /* pentium pro */
3942    ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
3943
3944    DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3945    DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3946    DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3947    DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3948    DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3949    DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3950    DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3951    DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3952
3953    DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3954    DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3955    DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
3956    DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
3957
3958    /* mmx */
3959    DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
3960    DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMX )
3961ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_REG32 ))
3962    DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3963ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
3964    DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3965    DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3966    DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3967    DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3968    DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3969    DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3970    DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3971    DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3972    DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3973    DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3974    DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3975    DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3976    DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3977    DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3978    DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3979    DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3980    DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3981    DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3982    DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3983    DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3984    DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3985    DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3986    DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3987ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3988    DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3989ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3990    DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3991ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
3992    DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3993ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
3994    DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3995ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
3996    DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3997ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
3998    DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
3999ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
4000    DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4001ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
4002    DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4003    DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4004    DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4005    DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4006    DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4007    DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4008    DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4009    DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4010    DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4011    DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4012    DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4013    DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4014    DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4015    DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
4016
4017#undef ALT
4018#undef DEF_ASM_OP0
4019#undef DEF_ASM_OP0L
4020#undef DEF_ASM_OP1
4021#undef DEF_ASM_OP2
4022#undef DEF_ASM_OP3
4023//---------------------------------------------------------------------------
4024
4025#endif
4026//---------------------------------------------------------------------------
4027#undef DEF
4028};
4029
4030static const char tcc_keywords[] =
4031#define DEF(id, str) str "\0"
4032// njn: inlined tcctok.h
4033//#include "tcctok.h"
4034//---------------------------------------------------------------------------
4035/* keywords */
4036     DEF(TOK_INT, "int")
4037     DEF(TOK_VOID, "void")
4038     DEF(TOK_CHAR, "char")
4039     DEF(TOK_IF, "if")
4040     DEF(TOK_ELSE, "else")
4041     DEF(TOK_WHILE, "while")
4042     DEF(TOK_BREAK, "break")
4043     DEF(TOK_RETURN, "return")
4044     DEF(TOK_FOR, "for")
4045     DEF(TOK_EXTERN, "extern")
4046     DEF(TOK_STATIC, "static")
4047     DEF(TOK_UNSIGNED, "unsigned")
4048     DEF(TOK_GOTO, "goto")
4049     DEF(TOK_DO, "do")
4050     DEF(TOK_CONTINUE, "continue")
4051     DEF(TOK_SWITCH, "switch")
4052     DEF(TOK_CASE, "case")
4053
4054     DEF(TOK_CONST1, "const")
4055     DEF(TOK_CONST2, "__const") /* gcc keyword */
4056     DEF(TOK_CONST3, "__const__") /* gcc keyword */
4057     DEF(TOK_VOLATILE1, "volatile")
4058     DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
4059     DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
4060     DEF(TOK_LONG, "long")
4061     DEF(TOK_REGISTER, "register")
4062     DEF(TOK_SIGNED1, "signed")
4063     DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
4064     DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
4065     DEF(TOK_AUTO, "auto")
4066     DEF(TOK_INLINE1, "inline")
4067     DEF(TOK_INLINE2, "__inline") /* gcc keyword */
4068     DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
4069     DEF(TOK_RESTRICT1, "restrict")
4070     DEF(TOK_RESTRICT2, "__restrict")
4071     DEF(TOK_RESTRICT3, "__restrict__")
4072     DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
4073
4074     DEF(TOK_FLOAT, "float")
4075     DEF(TOK_DOUBLE, "double")
4076     DEF(TOK_BOOL, "_Bool")
4077     DEF(TOK_SHORT, "short")
4078     DEF(TOK_STRUCT, "struct")
4079     DEF(TOK_UNION, "union")
4080     DEF(TOK_TYPEDEF, "typedef")
4081     DEF(TOK_DEFAULT, "default")
4082     DEF(TOK_ENUM, "enum")
4083     DEF(TOK_SIZEOF, "sizeof")
4084     DEF(TOK_ATTRIBUTE1, "__attribute")
4085     DEF(TOK_ATTRIBUTE2, "__attribute__")
4086     DEF(TOK_ALIGNOF1, "__alignof")
4087     DEF(TOK_ALIGNOF2, "__alignof__")
4088     DEF(TOK_TYPEOF1, "typeof")
4089     DEF(TOK_TYPEOF2, "__typeof")
4090     DEF(TOK_TYPEOF3, "__typeof__")
4091     DEF(TOK_LABEL, "__label__")
4092     DEF(TOK_ASM1, "asm")
4093     DEF(TOK_ASM2, "__asm")
4094     DEF(TOK_ASM3, "__asm__")
4095
4096/*********************************************************************/
4097/* the following are not keywords. They are included to ease parsing */
4098/* preprocessor only */
4099     DEF(TOK_DEFINE, "define")
4100     DEF(TOK_INCLUDE, "include")
4101     DEF(TOK_INCLUDE_NEXT, "include_next")
4102     DEF(TOK_IFDEF, "ifdef")
4103     DEF(TOK_IFNDEF, "ifndef")
4104     DEF(TOK_ELIF, "elif")
4105     DEF(TOK_ENDIF, "endif")
4106     DEF(TOK_DEFINED, "defined")
4107     DEF(TOK_UNDEF, "undef")
4108     DEF(TOK_ERROR, "error")
4109     DEF(TOK_WARNING, "warning")
4110     DEF(TOK_LINE, "line")
4111     DEF(TOK_PRAGMA, "pragma")
4112     DEF(TOK___LINE__, "__LINE__")
4113     DEF(TOK___FILE__, "__FILE__")
4114     DEF(TOK___DATE__, "__DATE__")
4115     DEF(TOK___TIME__, "__TIME__")
4116     DEF(TOK___FUNCTION__, "__FUNCTION__")
4117     DEF(TOK___VA_ARGS__, "__VA_ARGS__")
4118
4119/* special identifiers */
4120     DEF(TOK___FUNC__, "__func__")
4121
4122/* attribute identifiers */
4123/* XXX: handle all tokens generically since speed is not critical */
4124     DEF(TOK_SECTION1, "section")
4125     DEF(TOK_SECTION2, "__section__")
4126     DEF(TOK_ALIGNED1, "aligned")
4127     DEF(TOK_ALIGNED2, "__aligned__")
4128     DEF(TOK_PACKED1, "packed")
4129     DEF(TOK_PACKED2, "__packed__")
4130     DEF(TOK_UNUSED1, "unused")
4131     DEF(TOK_UNUSED2, "__unused__")
4132     DEF(TOK_CDECL1, "cdecl")
4133     DEF(TOK_CDECL2, "__cdecl")
4134     DEF(TOK_CDECL3, "__cdecl__")
4135     DEF(TOK_STDCALL1, "stdcall")
4136     DEF(TOK_STDCALL2, "__stdcall")
4137     DEF(TOK_STDCALL3, "__stdcall__")
4138     DEF(TOK_DLLEXPORT, "dllexport")
4139     DEF(TOK_NORETURN1, "noreturn")
4140     DEF(TOK_NORETURN2, "__noreturn__")
4141     DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
4142     DEF(TOK_builtin_constant_p, "__builtin_constant_p")
4143     DEF(TOK_REGPARM1, "regparm")
4144     DEF(TOK_REGPARM2, "__regparm__")
4145
4146/* pragma */
4147     DEF(TOK_pack, "pack")
4148#if !defined(TCC_TARGET_I386)
4149     /* already defined for assembler */
4150     DEF(TOK_ASM_push, "push")
4151     DEF(TOK_ASM_pop, "pop")
4152#endif
4153
4154/* builtin functions or variables */
4155     DEF(TOK_memcpy, "memcpy")
4156     DEF(TOK_memset, "memset")
4157     DEF(TOK_alloca, "alloca")
4158     DEF(TOK___divdi3, "__divdi3")
4159     DEF(TOK___moddi3, "__moddi3")
4160     DEF(TOK___udivdi3, "__udivdi3")
4161     DEF(TOK___umoddi3, "__umoddi3")
4162#if defined(TCC_TARGET_ARM)
4163     DEF(TOK___divsi3, "__divsi3")
4164     DEF(TOK___modsi3, "__modsi3")
4165     DEF(TOK___udivsi3, "__udivsi3")
4166     DEF(TOK___umodsi3, "__umodsi3")
4167     DEF(TOK___sardi3, "__ashrdi3")
4168     DEF(TOK___shrdi3, "__lshrdi3")
4169     DEF(TOK___shldi3, "__ashldi3")
4170     DEF(TOK___slltold, "__slltold")
4171     DEF(TOK___fixunssfsi, "__fixunssfsi")
4172     DEF(TOK___fixunsdfsi, "__fixunsdfsi")
4173     DEF(TOK___fixunsxfsi, "__fixunsxfsi")
4174     DEF(TOK___fixsfdi, "__fixsfdi")
4175     DEF(TOK___fixdfdi, "__fixdfdi")
4176     DEF(TOK___fixxfdi, "__fixxfdi")
4177#elif defined(TCC_TARGET_C67)
4178     DEF(TOK__divi, "_divi")
4179     DEF(TOK__divu, "_divu")
4180     DEF(TOK__divf, "_divf")
4181     DEF(TOK__divd, "_divd")
4182     DEF(TOK__remi, "_remi")
4183     DEF(TOK__remu, "_remu")
4184     DEF(TOK___sardi3, "__sardi3")
4185     DEF(TOK___shrdi3, "__shrdi3")
4186     DEF(TOK___shldi3, "__shldi3")
4187#else
4188     /* XXX: same names on i386 ? */
4189     DEF(TOK___sardi3, "__sardi3")
4190     DEF(TOK___shrdi3, "__shrdi3")
4191     DEF(TOK___shldi3, "__shldi3")
4192#endif
4193     DEF(TOK___tcc_int_fpu_control, "__tcc_int_fpu_control")
4194     DEF(TOK___tcc_fpu_control, "__tcc_fpu_control")
4195     DEF(TOK___ulltof, "__ulltof")
4196     DEF(TOK___ulltod, "__ulltod")
4197     DEF(TOK___ulltold, "__ulltold")
4198     DEF(TOK___fixunssfdi, "__fixunssfdi")
4199     DEF(TOK___fixunsdfdi, "__fixunsdfdi")
4200     DEF(TOK___fixunsxfdi, "__fixunsxfdi")
4201     DEF(TOK___chkstk, "__chkstk")
4202
4203/* bound checking symbols */
4204#ifdef CONFIG_TCC_BCHECK
4205     DEF(TOK___bound_ptr_add, "__bound_ptr_add")
4206     DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
4207     DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
4208     DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
4209     DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
4210     DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
4211     DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
4212     DEF(TOK___bound_local_new, "__bound_local_new")
4213     DEF(TOK___bound_local_delete, "__bound_local_delete")
4214     DEF(TOK_malloc, "malloc")
4215     DEF(TOK_free, "free")
4216     DEF(TOK_realloc, "realloc")
4217     DEF(TOK_memalign, "memalign")
4218     DEF(TOK_calloc, "calloc")
4219     DEF(TOK_memmove, "memmove")
4220     DEF(TOK_strlen, "strlen")
4221     DEF(TOK_strcpy, "strcpy")
4222#endif
4223
4224/* Tiny Assembler */
4225
4226 DEF_ASM(byte)
4227 DEF_ASM(align)
4228 DEF_ASM(skip)
4229 DEF_ASM(space)
4230 DEF_ASM(string)
4231 DEF_ASM(asciz)
4232 DEF_ASM(ascii)
4233 DEF_ASM(globl)
4234 DEF_ASM(global)
4235 DEF_ASM(text)
4236 DEF_ASM(data)
4237 DEF_ASM(bss)
4238 DEF_ASM(previous)
4239 DEF_ASM(fill)
4240 DEF_ASM(org)
4241 DEF_ASM(quad)
4242
4243#ifdef TCC_TARGET_I386
4244
4245/* WARNING: relative order of tokens is important. */
4246 DEF_ASM(al)
4247 DEF_ASM(cl)
4248 DEF_ASM(dl)
4249 DEF_ASM(bl)
4250 DEF_ASM(ah)
4251 DEF_ASM(ch)
4252 DEF_ASM(dh)
4253 DEF_ASM(bh)
4254 DEF_ASM(ax)
4255 DEF_ASM(cx)
4256 DEF_ASM(dx)
4257 DEF_ASM(bx)
4258 DEF_ASM(sp)
4259 DEF_ASM(bp)
4260 DEF_ASM(si)
4261 DEF_ASM(di)
4262 DEF_ASM(eax)
4263 DEF_ASM(ecx)
4264 DEF_ASM(edx)
4265 DEF_ASM(ebx)
4266 DEF_ASM(esp)
4267 DEF_ASM(ebp)
4268 DEF_ASM(esi)
4269 DEF_ASM(edi)
4270 DEF_ASM(mm0)
4271 DEF_ASM(mm1)
4272 DEF_ASM(mm2)
4273 DEF_ASM(mm3)
4274 DEF_ASM(mm4)
4275 DEF_ASM(mm5)
4276 DEF_ASM(mm6)
4277 DEF_ASM(mm7)
4278 DEF_ASM(xmm0)
4279 DEF_ASM(xmm1)
4280 DEF_ASM(xmm2)
4281 DEF_ASM(xmm3)
4282 DEF_ASM(xmm4)
4283 DEF_ASM(xmm5)
4284 DEF_ASM(xmm6)
4285 DEF_ASM(xmm7)
4286 DEF_ASM(cr0)
4287 DEF_ASM(cr1)
4288 DEF_ASM(cr2)
4289 DEF_ASM(cr3)
4290 DEF_ASM(cr4)
4291 DEF_ASM(cr5)
4292 DEF_ASM(cr6)
4293 DEF_ASM(cr7)
4294 DEF_ASM(tr0)
4295 DEF_ASM(tr1)
4296 DEF_ASM(tr2)
4297 DEF_ASM(tr3)
4298 DEF_ASM(tr4)
4299 DEF_ASM(tr5)
4300 DEF_ASM(tr6)
4301 DEF_ASM(tr7)
4302 DEF_ASM(db0)
4303 DEF_ASM(db1)
4304 DEF_ASM(db2)
4305 DEF_ASM(db3)
4306 DEF_ASM(db4)
4307 DEF_ASM(db5)
4308 DEF_ASM(db6)
4309 DEF_ASM(db7)
4310 DEF_ASM(dr0)
4311 DEF_ASM(dr1)
4312 DEF_ASM(dr2)
4313 DEF_ASM(dr3)
4314 DEF_ASM(dr4)
4315 DEF_ASM(dr5)
4316 DEF_ASM(dr6)
4317 DEF_ASM(dr7)
4318 DEF_ASM(es)
4319 DEF_ASM(cs)
4320 DEF_ASM(ss)
4321 DEF_ASM(ds)
4322 DEF_ASM(fs)
4323 DEF_ASM(gs)
4324 DEF_ASM(st)
4325
4326 DEF_BWL(mov)
4327
4328 /* generic two operands */
4329 DEF_BWL(add)
4330 DEF_BWL(or)
4331 DEF_BWL(adc)
4332 DEF_BWL(sbb)
4333 DEF_BWL(and)
4334 DEF_BWL(sub)
4335 DEF_BWL(xor)
4336 DEF_BWL(cmp)
4337
4338 /* unary ops */
4339 DEF_BWL(inc)
4340 DEF_BWL(dec)
4341 DEF_BWL(not)
4342 DEF_BWL(neg)
4343 DEF_BWL(mul)
4344 DEF_BWL(imul)
4345 DEF_BWL(div)
4346 DEF_BWL(idiv)
4347
4348 DEF_BWL(xchg)
4349 DEF_BWL(test)
4350
4351 /* shifts */
4352 DEF_BWL(rol)
4353 DEF_BWL(ror)
4354 DEF_BWL(rcl)
4355 DEF_BWL(rcr)
4356 DEF_BWL(shl)
4357 DEF_BWL(shr)
4358 DEF_BWL(sar)
4359
4360 DEF_ASM(shldw)
4361 DEF_ASM(shldl)
4362 DEF_ASM(shld)
4363 DEF_ASM(shrdw)
4364 DEF_ASM(shrdl)
4365 DEF_ASM(shrd)
4366
4367 DEF_ASM(pushw)
4368 DEF_ASM(pushl)
4369 DEF_ASM(push)
4370 DEF_ASM(popw)
4371 DEF_ASM(popl)
4372 DEF_ASM(pop)
4373 DEF_BWL(in)
4374 DEF_BWL(out)
4375
4376 DEF_WL(movzb)
4377
4378 DEF_ASM(movzwl)
4379 DEF_ASM(movsbw)
4380 DEF_ASM(movsbl)
4381 DEF_ASM(movswl)
4382
4383 DEF_WL(lea)
4384
4385 DEF_ASM(les)
4386 DEF_ASM(lds)
4387 DEF_ASM(lss)
4388 DEF_ASM(lfs)
4389 DEF_ASM(lgs)
4390
4391 DEF_ASM(call)
4392 DEF_ASM(jmp)
4393 DEF_ASM(lcall)
4394 DEF_ASM(ljmp)
4395
4396 DEF_ASMTEST(j)
4397
4398 DEF_ASMTEST(set)
4399 DEF_ASMTEST(cmov)
4400
4401 DEF_WL(bsf)
4402 DEF_WL(bsr)
4403 DEF_WL(bt)
4404 DEF_WL(bts)
4405 DEF_WL(btr)
4406 DEF_WL(btc)
4407
4408 DEF_WL(lsl)
4409
4410 /* generic FP ops */
4411 DEF_FP(add)
4412 DEF_FP(mul)
4413
4414 DEF_ASM(fcom)
4415 DEF_ASM(fcom_1) /* non existant op, just to have a regular table */
4416 DEF_FP1(com)
4417
4418 DEF_FP(comp)
4419 DEF_FP(sub)
4420 DEF_FP(subr)
4421 DEF_FP(div)
4422 DEF_FP(divr)
4423
4424 DEF_BWL(xadd)
4425 DEF_BWL(cmpxchg)
4426
4427 /* string ops */
4428 DEF_BWL(cmps)
4429 DEF_BWL(scmp)
4430 DEF_BWL(ins)
4431 DEF_BWL(outs)
4432 DEF_BWL(lods)
4433 DEF_BWL(slod)
4434 DEF_BWL(movs)
4435 DEF_BWL(smov)
4436 DEF_BWL(scas)
4437 DEF_BWL(ssca)
4438 DEF_BWL(stos)
4439 DEF_BWL(ssto)
4440
4441 /* generic asm ops */
4442
4443#define ALT(x)
4444#define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
4445#define DEF_ASM_OP0L(name, opcode, group, instr_type)
4446#define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
4447#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
4448#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
4449// njn: inlined i386-asm.h
4450//#include "i386-asm.h"
4451//---------------------------------------------------------------------------
4452     DEF_ASM_OP0(pusha, 0x60) /* must be first OP0 */
4453     DEF_ASM_OP0(popa, 0x61)
4454     DEF_ASM_OP0(clc, 0xf8)
4455     DEF_ASM_OP0(cld, 0xfc)
4456     DEF_ASM_OP0(cli, 0xfa)
4457     DEF_ASM_OP0(clts, 0x0f06)
4458     DEF_ASM_OP0(cmc, 0xf5)
4459     DEF_ASM_OP0(lahf, 0x9f)
4460     DEF_ASM_OP0(sahf, 0x9e)
4461     DEF_ASM_OP0(pushfl, 0x9c)
4462     DEF_ASM_OP0(popfl, 0x9d)
4463     DEF_ASM_OP0(pushf, 0x9c)
4464     DEF_ASM_OP0(popf, 0x9d)
4465     DEF_ASM_OP0(stc, 0xf9)
4466     DEF_ASM_OP0(std, 0xfd)
4467     DEF_ASM_OP0(sti, 0xfb)
4468     DEF_ASM_OP0(aaa, 0x37)
4469     DEF_ASM_OP0(aas, 0x3f)
4470     DEF_ASM_OP0(daa, 0x27)
4471     DEF_ASM_OP0(das, 0x2f)
4472     DEF_ASM_OP0(aad, 0xd50a)
4473     DEF_ASM_OP0(aam, 0xd40a)
4474     DEF_ASM_OP0(cbw, 0x6698)
4475     DEF_ASM_OP0(cwd, 0x6699)
4476     DEF_ASM_OP0(cwde, 0x98)
4477     DEF_ASM_OP0(cdq, 0x99)
4478     DEF_ASM_OP0(cbtw, 0x6698)
4479     DEF_ASM_OP0(cwtl, 0x98)
4480     DEF_ASM_OP0(cwtd, 0x6699)
4481     DEF_ASM_OP0(cltd, 0x99)
4482     DEF_ASM_OP0(int3, 0xcc)
4483     DEF_ASM_OP0(into, 0xce)
4484     DEF_ASM_OP0(iret, 0xcf)
4485     DEF_ASM_OP0(rsm, 0x0faa)
4486     DEF_ASM_OP0(hlt, 0xf4)
4487     DEF_ASM_OP0(wait, 0x9b)
4488     DEF_ASM_OP0(nop, 0x90)
4489     DEF_ASM_OP0(xlat, 0xd7)
4490
4491     /* strings */
4492ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWL))
4493ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWL))
4494
4495ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
4496ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
4497
4498ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWL))
4499ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWL))
4500
4501ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWL))
4502ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWL))
4503
4504ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWL))
4505ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWL))
4506
4507ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWL))
4508ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWL))
4509
4510     /* bits */
4511
4512ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
4513ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
4514
4515ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
4516ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
4517
4518ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
4519ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
4520
4521ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
4522ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
4523
4524ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
4525ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
4526
4527     /* prefixes */
4528     DEF_ASM_OP0(aword, 0x67)
4529     DEF_ASM_OP0(addr16, 0x67)
4530     DEF_ASM_OP0(word, 0x66)
4531     DEF_ASM_OP0(data16, 0x66)
4532     DEF_ASM_OP0(lock, 0xf0)
4533     DEF_ASM_OP0(rep, 0xf3)
4534     DEF_ASM_OP0(repe, 0xf3)
4535     DEF_ASM_OP0(repz, 0xf3)
4536     DEF_ASM_OP0(repne, 0xf2)
4537     DEF_ASM_OP0(repnz, 0xf2)
4538
4539     DEF_ASM_OP0(invd, 0x0f08)
4540     DEF_ASM_OP0(wbinvd, 0x0f09)
4541     DEF_ASM_OP0(cpuid, 0x0fa2)
4542     DEF_ASM_OP0(wrmsr, 0x0f30)
4543     DEF_ASM_OP0(rdtsc, 0x0f31)
4544     DEF_ASM_OP0(rdmsr, 0x0f32)
4545     DEF_ASM_OP0(rdpmc, 0x0f33)
4546     DEF_ASM_OP0(ud2, 0x0f0b)
4547
4548     /* NOTE: we took the same order as gas opcode definition order */
4549ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWL, OPT_ADDR, OPT_EAX))
4550ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWL, OPT_EAX, OPT_ADDR))
4551ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
4552ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
4553ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWL, OPT_IM, OPT_REG))
4554ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_REG | OPT_EA))
4555
4556ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WL, OPT_SEG, OPT_EA | OPT_REG))
4557ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_SEG))
4558
4559ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WL, OPT_CR, OPT_REG32))
4560ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WL, OPT_DB, OPT_REG32))
4561ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WL, OPT_TR, OPT_REG32))
4562ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_CR))
4563ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_DB))
4564ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_TR))
4565
4566ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
4567ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
4568ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
4569ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
4570ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
4571
4572ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
4573ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
4574ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
4575ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
4576ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
4577
4578ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
4579ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
4580ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WL, OPT_SEG))
4581
4582ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_REG, OPT_EAX))
4583ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_EAX, OPT_REG))
4584ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
4585ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
4586
4587ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
4588ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
4589ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
4590ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
4591
4592ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
4593ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
4594ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
4595ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
4596
4597ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WL, OPT_EA, OPT_REG))
4598
4599ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
4600ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
4601ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
4602ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
4603ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
4604
4605     /* arith */
4606ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
4607ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
4608ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
4609ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
4610ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, OPT_EA | OPT_REG))
4611
4612ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
4613ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
4614ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWL, OPT_IM, OPT_EAX))
4615ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
4616
4617ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WL, OPT_REGW))
4618ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4619ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WL, OPT_REGW))
4620ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4621
4622ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4623ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4624
4625ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4626ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4627
4628ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WL, OPT_REG | OPT_EA, OPT_REG))
4629ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
4630ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW))
4631ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
4632ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW))
4633
4634ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4635ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
4636ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
4637ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
4638
4639     /* shifts */
4640ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
4641ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
4642ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_EA | OPT_REG))
4643
4644ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
4645ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
4646ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
4647ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
4648ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
4649ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
4650
4651ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
4652ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
4653ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
4654ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
4655
4656ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
4657ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
4658ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
4659ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
4660
4661ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
4662ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
4663    DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
4664    DEF_ASM_OP0(leave, 0xc9)
4665    DEF_ASM_OP0(ret, 0xc3)
4666ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
4667    DEF_ASM_OP0(lret, 0xcb)
4668ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
4669
4670ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
4671    DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
4672    DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
4673    DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
4674    DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
4675    DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
4676    DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
4677
4678     /* float */
4679     /* specific fcomp handling */
4680ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
4681
4682ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
4683ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
4684ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
4685ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
4686ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
4687ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
4688ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
4689ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
4690ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
4691ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
4692ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
4693
4694     DEF_ASM_OP0(fucompp, 0xdae9)
4695     DEF_ASM_OP0(ftst, 0xd9e4)
4696     DEF_ASM_OP0(fxam, 0xd9e5)
4697     DEF_ASM_OP0(fld1, 0xd9e8)
4698     DEF_ASM_OP0(fldl2t, 0xd9e9)
4699     DEF_ASM_OP0(fldl2e, 0xd9ea)
4700     DEF_ASM_OP0(fldpi, 0xd9eb)
4701     DEF_ASM_OP0(fldlg2, 0xd9ec)
4702     DEF_ASM_OP0(fldln2, 0xd9ed)
4703     DEF_ASM_OP0(fldz, 0xd9ee)
4704
4705     DEF_ASM_OP0(f2xm1, 0xd9f0)
4706     DEF_ASM_OP0(fyl2x, 0xd9f1)
4707     DEF_ASM_OP0(fptan, 0xd9f2)
4708     DEF_ASM_OP0(fpatan, 0xd9f3)
4709     DEF_ASM_OP0(fxtract, 0xd9f4)
4710     DEF_ASM_OP0(fprem1, 0xd9f5)
4711     DEF_ASM_OP0(fdecstp, 0xd9f6)
4712     DEF_ASM_OP0(fincstp, 0xd9f7)
4713     DEF_ASM_OP0(fprem, 0xd9f8)
4714     DEF_ASM_OP0(fyl2xp1, 0xd9f9)
4715     DEF_ASM_OP0(fsqrt, 0xd9fa)
4716     DEF_ASM_OP0(fsincos, 0xd9fb)
4717     DEF_ASM_OP0(frndint, 0xd9fc)
4718     DEF_ASM_OP0(fscale, 0xd9fd)
4719     DEF_ASM_OP0(fsin, 0xd9fe)
4720     DEF_ASM_OP0(fcos, 0xd9ff)
4721     DEF_ASM_OP0(fchs, 0xd9e0)
4722     DEF_ASM_OP0(fabs, 0xd9e1)
4723     DEF_ASM_OP0(fninit, 0xdbe3)
4724     DEF_ASM_OP0(fnclex, 0xdbe2)
4725     DEF_ASM_OP0(fnop, 0xd9d0)
4726     DEF_ASM_OP0(fwait, 0x9b)
4727
4728    /* fp load */
4729    DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
4730    DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
4731    DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
4732ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
4733    DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
4734    DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
4735    DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
4736    DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
4737    DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
4738
4739    /* fp store */
4740    DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
4741    DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
4742    DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
4743    DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
4744ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
4745    DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
4746    DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
4747    DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
4748    DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
4749    DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
4750
4751    DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
4752    DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
4753    DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
4754    DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
4755    DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
4756
4757    /* exchange */
4758    DEF_ASM_OP0(fxch, 0xd9c9)
4759ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
4760
4761    /* misc FPU */
4762    DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
4763    DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
4764
4765    DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
4766    DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
4767    DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
4768    DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
4769    DEF_ASM_OP0(fnstsw, 0xdfe0)
4770ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
4771ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
4772    DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
4773ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
4774ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
4775    DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
4776    DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
4777    DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
4778    DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
4779    DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
4780    DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
4781    DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
4782    DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
4783    DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
4784    DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
4785    DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
4786
4787    /* segments */
4788    DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
4789    DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
4790    DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
4791    DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
4792    DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
4793    DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
4794ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
4795    DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
4796    DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
4797    DEF_ASM_OP1(