0
|
1 /*
|
|
2
|
|
3 Package: dyncall
|
|
4 Library: portasm
|
|
5 File: portasm/portasm-x86.S
|
|
6 Description: Portable Assembler Macros for x86
|
|
7 License:
|
|
8
|
|
9 Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>
|
|
10
|
|
11 Permission to use, copy, modify, and distribute this software for any
|
|
12 purpose with or without fee is hereby granted, provided that the above
|
|
13 copyright notice and this permission notice appear in all copies.
|
|
14
|
|
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
22
|
|
23 */
|
|
24
|
|
25
|
|
26
|
|
27 /* Common macros. */
|
|
28 #define XCONCAT(A,B) A##B
|
|
29 /* MASM syntax. */
|
|
30 #if defined(GEN_MASM)
|
|
31 .386
|
|
32 .MODEL FLAT
|
|
33 .CODE
|
|
34 # define BEGIN_ASM
|
|
35 # define END_ASM END
|
|
36 # define GLOBAL(X) _##X PROC
|
|
37 # define BEGIN_PROC(X) OPTION PROLOGUE:NONE, EPILOGUE:NONE
|
|
38 # define END_PROC(X) _##X ENDP
|
|
39 # define PUSH(R) push R
|
|
40 # define POP(R) pop R
|
|
41 # define MOVL(S,D) mov D,S
|
|
42 # define ADDL(S,D) add D,S
|
|
43 # define ANDL(S,D) and D,S
|
|
44 # define SUBL(S,D) sub D,S
|
|
45 # define SHRL(S,D) shr D,S
|
|
46 # define RET() ret
|
|
47 # define CALL_DWORD(R,OFF) call DWORD(R,OFF)
|
|
48 # define REP(X) rep X
|
|
49 # define MOVSB movsb
|
|
50 # define MOVSW movsw
|
|
51 # define MOVSD movsd
|
|
52 # define DWORD(R,OFF) dword ptr [R+OFF]
|
|
53 # define QWORD(R,OFF) qword ptr [R+OFF]
|
|
54 # define LIT(X) X
|
|
55 # define INT(X) int X
|
|
56 # define HEX(X) XCONCAT(X,h)
|
|
57 # define CALL(X) call X
|
|
58 # define LEA(S,D) lea D,S
|
|
59 # define ADD(S,D) add D,S
|
|
60 # define CMP(S,D) cmp D,S
|
|
61 # define JE(T) je T
|
|
62 # define FLDS(OP) fld OP
|
|
63 # define FLDL(OP) fld OP
|
|
64 # define LOCAL(NAME) NAME
|
|
65 #else
|
|
66 /* GNU/SunPro Assembler AT&T Syntax */
|
|
67 .text
|
|
68 # define BEGIN_ASM
|
|
69 # define END_ASM
|
|
70 # include "../autovar/autovar_OS.h"
|
|
71 # if defined(OS_Win32) || defined(OS_Cygwin) || defined(OS_MinGW) || defined(OS_Darwin) || defined(OS_Minix)
|
|
72 # define CSYM(X) _##X
|
|
73 # else
|
|
74 # define CSYM(X) X
|
|
75 # endif
|
|
76 /* Systems that work without '%' prefix: MinGW,Apple */
|
|
77 # define EAX %eax
|
|
78 # define EBX %ebx
|
|
79 # define ECX %ecx
|
|
80 # define EDX %edx
|
|
81 # define ESI %esi
|
|
82 # define EDI %edi
|
|
83 # define EBP %ebp
|
|
84 # define ESP %esp
|
|
85 # define AL %al
|
|
86 # define AH %ah
|
|
87 # define BL %bl
|
|
88 # define BH %bh
|
|
89 # define CL %cl
|
|
90 # define CH %ch
|
|
91 # define DL %dl
|
|
92 # define DH %dh
|
|
93 # define GLOBAL(X) .globl CSYM(X)
|
|
94 # define BEGIN_PROC(X) CSYM(X):
|
|
95 # define END_PROC(X)
|
|
96 # define PUSH(R) pushl R
|
|
97 # define POP(R) popl R
|
|
98 # define MOVL(S,D) movl S,D
|
|
99 # define ADDL(S,D) addl S,D
|
|
100 # define ANDL(S,D) andl S,D
|
|
101 # define SUBL(S,D) subl S,D
|
|
102 # define SHRL(S,D) shrl S,D
|
|
103 # define RET() ret
|
|
104 # define CALL_DWORD(R,OFF) call *DWORD(R,OFF)
|
|
105 # define REP(X) rep; X
|
|
106 # define MOVSB movsb
|
|
107 # define MOVSW movsw
|
|
108 # define MOVSD movsd
|
|
109 # define DWORD(R,OFF) OFF(R)
|
|
110 # define QWORD(R,OFF) OFF(R)
|
|
111 # include "../autovar/autovar_CC.h"
|
|
112 # if defined CC_SUN
|
|
113 # define LIT(X) $X
|
|
114 # else
|
|
115 # define LIT(X) XCONCAT($,X)
|
|
116 # endif
|
|
117 # define INT(X) int X
|
|
118 # define HEX(X) XCONCAT(0x,X)
|
|
119 # define CALL(X) call X
|
|
120 # define LEA(A,B) lea A,B
|
|
121 # define CMP(A,B) cmp A,B
|
|
122 # define JE(X) je X
|
|
123 # define FLDS(X) flds X
|
|
124 # define FLDL(X) fldl X
|
|
125 # define ADD(A,B) add A,B
|
|
126 # define LOCAL(X) .X
|
|
127 #endif
|
|
128
|