⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assyntax.h

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 H
📖 第 1 页 / 共 5 页
字号:

#ifndef __ASSYNTAX_H__
#define __ASSYNTAX_H__

/*
 * Copyright 1992 Vrije Universiteit, The Netherlands
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the Vrije Universiteit not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  The Vrije Universiteit makes no
 * representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 *
 * The Vrije Universiteit DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
 * IN NO EVENT SHALL The Vrije Universiteit BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * assyntax.h
 *
 * Select the syntax appropriate to the 386 assembler being used
 * To add support for more assemblers add more columns to the CHOICE
 * macro.  Note that register names must also have uppercase names
 * to avoid macro recursion. e.g., #define ah %ah recurses!
 *
 * NB 1.  Some of the macros for certain assemblers imply that the code is to
 *	  run in protected mode!!  Caveat emptor.
 *
 * NB 2.  486 specific instructions are not included.  This is to discourage
 *	  their accidental use in code that is intended to run on 386 and 486
 *	  systems.
 *
 * Supported assemblers:
 *
 * (a) AT&T SysVr4 as(1):	define ATT_ASSEMBLER
 * (b) GNU Assembler gas:	define GNU_ASSEMBLER (default)
 * (c) Amsterdam Compiler kit:	define ACK_ASSEMBLER
 * (d) The Netwide Assembler:	define NASM_ASSEMBLER
 * (e) Microsoft Assembler:	define MASM_ASSEMBLER (UNTESTED!)
 *
 * The following naming conventions have been used to identify the various
 * data types:
 *		_SR = segment register version
 *	Integer:
 *		_Q = quadword	= 64 bits
 *		_L = long	= 32 bits
 *		_W = short	= 16 bits
 *		_B = byte	=  8 bits
 *	Floating-point:
 *		_X = m80real	= 80 bits
 *		_D = double	= 64 bits
 *		_S = single	= 32 bits
 *
 * Author: Gregory J. Sharp, Sept 1992
 *         Vrije Universiteit, Amsterdam, The Netherlands
 *
 *         [support for Intel syntax added by Josh Vanderhoof, 1999]
 */

#if !(defined(NASM_ASSEMBLER) || defined(MASM_ASSEMBLER))

/* Default to ATT_ASSEMBLER when SVR4 or SYSV are defined */
#if (defined(SVR4) || defined(SYSV)) && !defined(GNU_ASSEMBLER)
#define ATT_ASSEMBLER
#endif

#if !defined(ATT_ASSEMBLER) && !defined(GNU_ASSEMBLER) && !defined(ACK_ASSEMBLER)
#define GNU_ASSEMBLER
#endif

#if (defined(__STDC__) && !defined(UNIXCPP)) || (defined (sun) && defined (i386) && defined (SVR4) && defined (__STDC__) && !defined (__GNUC__))
#define CONCAT(x, y)		x ## y
#define CONCAT3(x, y, z)	x ## y ## z
#else
#define CONCAT(x, y)		x/**/y
#define CONCAT3(x, y, z)	x/**/y/**/z
#endif

#ifdef ACK_ASSEMBLER

/* Assume we write code for 32-bit protected mode! */

/* Redefine register names for GAS & AT&T assemblers */
#define AL		al
#define AH		ah
#define AX		ax
#define EAX		ax
#define BL		bl
#define BH		bh
#define BX		bx
#define EBX		bx
#define CL		cl
#define CH		ch
#define CX		cx
#define ECX		cx
#define DL		dl
#define DH		dh
#define DX		dx
#define EDX		dx
#define BP		bp
#define EBP		bp
#define SI		si
#define ESI		si
#define DI		di
#define EDI		di
#define SP		sp
#define ESP		sp
#define CS		cs
#define SS		ss
#define DS		ds
#define ES		es
#define FS		fs
#define GS		gs
/* Control Registers */
#define CR0		cr0
#define CR1		cr1
#define CR2		cr2
#define CR3		cr3
/* Debug Registers */
#define DR0		dr0
#define DR1		dr1
#define DR2		dr2
#define DR3		dr3
#define DR4		dr4
#define DR5		dr5
#define DR6		dr6
#define DR7		dr7
/* Floating-point Stack */
#define ST		st

#define AS_BEGIN	.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text


#define _WTOG		o16	/* word toggle for _W instructions */
#define _LTOG			/* long toggle for _L instructions */
#define ADDR_TOGGLE	a16
#define OPSZ_TOGGLE	o16
#define USE16		.use16
#define USE32		.use32

#define CHOICE(a,b,c)	c

#else /* AT&T or GAS */

/* Redefine register names for GAS & AT&T assemblers */
#define AL		%al
#define AH		%ah
#define AX		%ax
#define EAX		%eax
#define BL		%bl
#define BH		%bh
#define BX		%bx
#define EBX		%ebx
#define CL		%cl
#define CH		%ch
#define CX		%cx
#define ECX		%ecx
#define DL		%dl
#define DH		%dh
#define DX		%dx
#define EDX		%edx
#define BP		%bp
#define EBP		%ebp
#define SI		%si
#define ESI		%esi
#define DI		%di
#define EDI		%edi
#define SP		%sp
#define ESP		%esp
#define CS		%cs
#define SS		%ss
#define DS		%ds
#define ES		%es
#define FS		%fs
#define GS		%gs
/* Control Registers */
#define CR0		%cr0
#define CR1		%cr1
#define CR2		%cr2
#define CR3		%cr3
/* Debug Registers */
#define DR0		%db0
#define DR1		%db1
#define DR2		%db2
#define DR3		%db3
#define DR4		%db4
#define DR5		%db5
#define DR6		%db6
#define DR7		%db7
/* Floating-point Stack */
#define _STX0		%st(0)
#define _STX1		%st(1)
#define _STX2		%st(2)
#define _STX3		%st(3)
#define _STX4		%st(4)
#define _STX5		%st(5)
#define _STX6		%st(6)
#define _STX7		%st(7)
#define ST(x)		CONCAT(_STX,x)
#ifdef GNU_ASSEMBLER
#define ST0		%st(0)
#else
#define ST0		%st
#endif
/* MMX Registers */
#define MM0		%mm0
#define MM1		%mm1
#define MM2		%mm2
#define MM3		%mm3
#define MM4		%mm4
#define MM5		%mm5
#define MM6		%mm6
#define MM7		%mm7
/* SSE Registers */
#define XMM0		%xmm0
#define XMM1		%xmm1
#define XMM2		%xmm2
#define XMM3		%xmm3
#define XMM4		%xmm4
#define XMM5		%xmm5
#define XMM6		%xmm6
#define XMM7		%xmm7

#define AS_BEGIN
#define USE16
#define USE32

#ifdef GNU_ASSEMBLER

#define ADDR_TOGGLE	aword
#define OPSZ_TOGGLE	word

#define CHOICE(a,b,c)	b

#else
/*
 * AT&T ASSEMBLER SYNTAX
 * *********************
 */
#define CHOICE(a,b,c)	a

#define ADDR_TOGGLE	addr16
#define OPSZ_TOGGLE	data16

#endif /* GNU_ASSEMBLER */
#endif /* ACK_ASSEMBLER */


#if defined(__QNX__) || defined(Lynx) || (defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER) || defined(__ELF__) || defined(__GNU__) || defined(__GNUC__) && !defined(__DJGPP__) && !defined(__MINGW32__)
#define GLNAME(a)	a
#else
#define GLNAME(a)	CONCAT(_,a)
#endif


	/****************************************/
	/*					*/
	/*	Select the various choices	*/
	/*					*/
	/****************************************/


/* Redefine assembler directives */
/*********************************/
#define GLOBL		CHOICE(.globl, .globl, .extern)
#define GLOBAL		GLOBL
#define EXTERN		GLOBL
#ifndef __AOUT__
#define ALIGNTEXT32	CHOICE(.align 32, .balign 32, .align 32)
#define ALIGNTEXT16	CHOICE(.align 16, .balign 16, .align 16)
#define ALIGNTEXT8	CHOICE(.align 8, .balign 8, .align 8)
#define ALIGNTEXT4	CHOICE(.align 4, .balign 4, .align 4)
#define ALIGNTEXT2	CHOICE(.align 2, .balign 2, .align 2)
/* ALIGNTEXT4ifNOP is the same as ALIGNTEXT4, but only if the space is
 * guaranteed to be filled with NOPs.  Otherwise it does nothing.
 */
#define ALIGNTEXT32ifNOP	CHOICE(.align 32, .balign ARG2(32,0x90), /*can't do it*/)
#define ALIGNTEXT16ifNOP	CHOICE(.align 16, .balign ARG2(16,0x90), /*can't do it*/)
#define ALIGNTEXT8ifNOP	CHOICE(.align 8, .balign ARG2(8,0x90), /*can't do it*/)
#define ALIGNTEXT4ifNOP	CHOICE(.align 4, .balign ARG2(4,0x90), /*can't do it*/)
#define ALIGNDATA32	CHOICE(.align 32, .balign ARG2(32,0x0), .align 32)
#define ALIGNDATA16	CHOICE(.align 16, .balign ARG2(16,0x0), .align 16)
#define ALIGNDATA8	CHOICE(.align 8, .balign ARG2(8,0x0), .align 8)
#define ALIGNDATA4	CHOICE(.align 4, .balign ARG2(4,0x0), .align 4)
#define ALIGNDATA2	CHOICE(.align 2, .balign ARG2(2,0x0), .align 2)
#else
/* 'as -aout' on FreeBSD doesn't have .balign */
#define ALIGNTEXT32	CHOICE(.align 32, .align ARG2(5,0x90), .align 32)
#define ALIGNTEXT16	CHOICE(.align 16, .align ARG2(4,0x90), .align 16)
#define ALIGNTEXT8	CHOICE(.align 8, .align ARG2(3,0x90), .align 8)
#define ALIGNTEXT4	CHOICE(.align 4, .align ARG2(2,0x90), .align 4)
#define ALIGNTEXT2	CHOICE(.align 2, .align ARG2(1,0x90), .align 2)
/* ALIGNTEXT4ifNOP is the same as ALIGNTEXT4, but only if the space is
 * guaranteed to be filled with NOPs.  Otherwise it does nothing.
 */
#define ALIGNTEXT32ifNOP	CHOICE(.align 32, .align ARG2(5,0x90), /*can't do it*/)
#define ALIGNTEXT16ifNOP	CHOICE(.align 16, .align ARG2(4,0x90), /*can't do it*/)
#define ALIGNTEXT8ifNOP	CHOICE(.align 8, .align ARG2(3,0x90), /*can't do it*/)
#define ALIGNTEXT4ifNOP	CHOICE(.align 4, .align ARG2(2,0x90), /*can't do it*/)
#define ALIGNDATA32	CHOICE(.align 32, .align ARG2(5,0x0), .align 32)
#define ALIGNDATA16	CHOICE(.align 16, .align ARG2(4,0x0), .align 16)
#define ALIGNDATA8	CHOICE(.align 8, .align ARG2(3,0x0), .align 8)
#define ALIGNDATA4	CHOICE(.align 4, .align ARG2(2,0x0), .align 4)
#define ALIGNDATA2	CHOICE(.align 2, .align ARG2(1,0x0), .align 2)
#endif /* __AOUT__ */
#define FILE(s)		CHOICE(.file s, .file s, .file s)
#define STRING(s)	CHOICE(.string s, .asciz s, .asciz s)
#define D_LONG		CHOICE(.long, .long, .data4)
#define D_WORD		CHOICE(.value, .short, .data2)
#define D_BYTE		CHOICE(.byte, .byte, .data1)
#define SPACE		CHOICE(.comm, .space, .space)
#define COMM		CHOICE(.comm, .comm, .comm)
#define SEG_DATA	CHOICE(.data, .data, .sect .data)
#define SEG_TEXT	CHOICE(.text, .text, .sect .text)
#define SEG_BSS		CHOICE(.bss, .bss, .sect .bss)

#ifdef GNU_ASSEMBLER
#define D_SPACE(n)	. = . + n
#else
#define D_SPACE(n)	.space n
#endif

/* Addressing Modes */
/* Immediate Mode */
#define ADDR(a)		CHOICE(CONCAT($,a), $a, a)
#define CONST(a)	CHOICE(CONCAT($,a), $a, a)

/* Indirect Mode */
#define CONTENT(a)	CHOICE(a, a, (a))	 /* take contents of variable */
#define REGIND(a)	CHOICE((a), (a), (a))	 /* Register a indirect */
/* Register b indirect plus displacement a */
#define REGOFF(a, b)	CHOICE(a(b), a(b), a(b))
/* Reg indirect Base + Index + Displacement  - this is mainly for 16-bit mode
 * which has no scaling
 */
#define REGBID(b,i,d)	CHOICE(d(b,i), d(b,i), d(b)(i))
/* Reg indirect Base + (Index * Scale) */
#define REGBIS(b,i,s)	CHOICE((b,i,s), (b,i,s), (b)(i*s))
/* Reg indirect Base + (Index * Scale) + Displacement */
#define REGBISD(b,i,s,d) CHOICE(d(b,i,s), d(b,i,s), d(b)(i*s))
/* Displaced Scaled Index: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -