• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ;
2 ;	Copyright (C) 1999 URURI
3 
4 ;	nasm�ѥޥ���
5 ;	1999/08/21 ���
6 ;	1999/10/10 ���Ĥ��ɲ�
7 ;	1999/10/27 aout�б�
8 ;	1999/11/07 pushf, popf ��NASM�ΥХ��б�
9 ;	1999/12/02 for BCC ( Thanks to Miquel )
10 
11 ; for Windows Visual C++        -> define WIN32
12 ;             Borland or cygwin ->        WIN32 and COFF
13 ; for FreeBSD 2.x               ->        AOUT
14 ; for TownsOS                   ->        __tos__
15 ; otherwise                     ->   none
16 
17 ;̾����դ���
18 
19 BITS 32
20 
21 %ifnidn __OUTPUT_FORMAT__,aout
22 section .note.GNU-stack noalloc noexec nowrite progbits
23 %endif
24 
25 %ifdef YASM
26 	%define segment_code segment .text align=16 use32
27 	%define segment_data segment .data align=16 use32
28 	%define segment_bss  segment .bss align=16 use32
29 %elifdef WIN32
30 	%define segment_code segment .text align=16 class=CODE use32
31 	%define segment_data segment .data align=16 class=DATA use32
32 %ifdef __BORLANDC__
33 	%define segment_bss  segment .data align=16 class=DATA use32
34 %else
35 	%define segment_bss  segment .bss align=16 class=DATA use32
36 %endif
37 %elifdef AOUT
38 	%define _NAMING
39 	%define segment_code segment .text
40 	%define segment_data segment .data
41 	%define segment_bss  segment .bss
42 %else
43 %ifidn __OUTPUT_FORMAT__,elf
44 	section .note.GNU-stack progbits noalloc noexec nowrite align=1
45 %endif
46 	%define segment_code segment .text align=16 class=CODE use32
47 	%define segment_data segment .data align=16 class=DATA use32
48 	%define segment_bss  segment .bss align=16 class=DATA use32
49 %endif
50 
51 %ifdef WIN32
52 	%define _NAMING
53 %endif
54 
55 %ifdef __tos__
56 group CGROUP text
57 group DGROUP data
58 %endif
59 
60 ;ñ�����ư��������
61 
62 %idefine float dword
63 %idefine fsize 4
64 %idefine fsizen(a) (fsize*(a))
65 
66 ;��ɷ��
67 
68 %idefine wsize 2
69 %idefine wsizen(a) (wsize*(a))
70 %idefine dwsize 4
71 %idefine dwsizen(a) (dwsize*(a))
72 
73 ;REG
74 
75 %define r0 eax
76 %define r1 ebx
77 %define r2 ecx
78 %define r3 edx
79 %define r4 esi
80 %define r5 edi
81 %define r6 ebp
82 %define r7 esp
83 
84 ;MMX,3DNow!,SSE
85 
86 %define pmov	movq
87 %define pmovd	movd
88 
89 %define pupldq	punpckldq
90 %define puphdq	punpckhdq
91 %define puplwd	punpcklwd
92 %define puphwd	punpckhwd
93 
94 %define xm0 xmm0
95 %define xm1 xmm1
96 %define xm2 xmm2
97 %define xm3 xmm3
98 %define xm4 xmm4
99 %define xm5 xmm5
100 %define xm6 xmm6
101 %define xm7 xmm7
102 
103 ;�����åե��Ѥ�4�ʥޥ���
104 
105 %define R4(a,b,c,d) (a*64+b*16+c*4+d)
106 
107 ;C�饤���ʴʰץޥ���
108 
109 %imacro globaldef 1
110 	%ifdef _NAMING
111 		%define %1 _%1
112 	%endif
113 	global %1
114 %endmacro
115 
116 %imacro externdef 1
117 	%ifdef _NAMING
118 		%define %1 _%1
119 	%endif
120 	extern %1
121 %endmacro
122 
123 %imacro proc 1
124 	%push	proc
125 	%ifdef _NAMING
126 		global _%1
127 	%else
128 		global %1
129 	%endif
130 
131 	align 32
132 %1:
133 _%1:
134 
135 	%assign %$STACK 0
136 	%assign %$STACKN 0
137 	%assign %$ARG 4
138 %endmacro
139 
140 %imacro endproc 0
141 	%ifnctx proc
142 		%error expected 'proc' before 'endproc'.
143 	%else
144 		%if %$STACK > 0
145 			add esp, %$STACK
146 		%endif
147 
148 		%if %$STACK <> (-%$STACKN)
149 			%error STACKLEVEL mismatch check 'local', 'alloc', 'pushd', 'popd'
150 		%endif
151 
152 		ret
153 		%pop
154 	%endif
155 %endmacro
156 
157 %idefine sp(a) esp+%$STACK+a
158 
159 %imacro arg 1
160 	%00	equ %$ARG
161 	%assign %$ARG %$ARG+%1
162 %endmacro
163 
164 %imacro local 1
165 	%assign %$STACKN %$STACKN-%1
166 	%00 equ %$STACKN
167 %endmacro
168 
169 %imacro alloc 0
170 	sub esp, (-%$STACKN)-%$STACK
171 	%assign %$STACK (-%$STACKN)
172 %endmacro
173 
174 %imacro pushd 1-*
175 	%rep %0
176 		push %1
177 		%assign %$STACK %$STACK+4
178 	%rotate 1
179 	%endrep
180 %endmacro
181 
182 %imacro popd 1-*
183 	%rep %0
184 	%rotate -1
185 		pop %1
186 		%assign %$STACK %$STACK-4
187 	%endrep
188 %endmacro
189 
190 ; bug of NASM-0.98
191 %define pushf db 0x66, 0x9C
192 %define popf  db 0x66, 0x9D
193 
194 %define	ge16(n)		((((n) / 16)*0xFFFFFFFF) & 0xFFFFFFFF)
195 %define	ge15(n)		((((n) / 15)*0xFFFFFFFF) & 0xFFFFFFFF)
196 %define	ge14(n)		((((n) / 14)*0xFFFFFFFF) & 0xFFFFFFFF)
197 %define	ge13(n)		((((n) / 13)*0xFFFFFFFF) & 0xFFFFFFFF)
198 %define	ge12(n)		((((n) / 12)*0xFFFFFFFF) & 0xFFFFFFFF)
199 %define	ge11(n)		((((n) / 11)*0xFFFFFFFF) & 0xFFFFFFFF)
200 %define	ge10(n)		((((n) / 10)*0xFFFFFFFF) & 0xFFFFFFFF)
201 %define	ge9(n)		((((n) /  9)*0xFFFFFFFF) & 0xFFFFFFFF)
202 %define	ge8(n)		(ge9(n) | ((((n) /  8)*0xFFFFFFFF) & 0xFFFFFFFF))
203 %define	ge7(n)		(ge9(n) | ((((n) /  7)*0xFFFFFFFF) & 0xFFFFFFFF))
204 %define	ge6(n)		(ge9(n) | ((((n) /  6)*0xFFFFFFFF) & 0xFFFFFFFF))
205 %define	ge5(n)		(ge9(n) | ((((n) /  5)*0xFFFFFFFF) & 0xFFFFFFFF))
206 %define	ge4(n)		(ge5(n) | ((((n) /  4)*0xFFFFFFFF) & 0xFFFFFFFF))
207 %define	ge3(n)		(ge5(n) | ((((n) /  3)*0xFFFFFFFF) & 0xFFFFFFFF))
208 %define	ge2(n)		(ge3(n) | ((((n) /  2)*0xFFFFFFFF) & 0xFFFFFFFF))
209 %define	ge1(n)		(ge2(n) | ((((n) /  1)*0xFFFFFFFF) & 0xFFFFFFFF))
210 
211 ; macro to align for begining of loop
212 ; %1   does not align if it LE bytes to next alignment
213 ;      4..16
214 ;      default is 12
215 
216 %imacro	loopalignK6	0-1 12
217 %%here:
218 	times (($$-%%here) & 15 & ge1(($$-%%here) & 15) & ~ge4(($$-%%here) & 15)) nop
219 	times (1                & ge4(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) jmp short %%skip
220 	times (((($$-%%here) & 15)-2) & ge4(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) nop
221 %%skip:
222 %endmacro
223 
224 %imacro	loopalignK7	0-1 12
225 %%here:
226 	times (1 & ge1(($$-%%here) & 15)  & ~ge2(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) nop
227 	times (1 & ge2(($$-%%here) & 15)  & ~ge3(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Bh,0C0h
228 	times (1 & ge3(($$-%%here) & 15)  & ~ge4(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,004h,020h
229 	times (1 & ge4(($$-%%here) & 15)  & ~ge5(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,044h,020h,000h
230 	times (1 & ge5(($$-%%here) & 15)  & ~ge6(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,044h,020h,000h,090h
231 	times (1 & ge6(($$-%%here) & 15)  & ~ge7(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,080h,0,0,0,0
232 	times (1 & ge7(($$-%%here) & 15)  & ~ge8(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,004h,005h,0,0,0,0
233 	times (1 & ge8(($$-%%here) & 15)  & ~ge9(($$-%%here) & 15)  & ~ge%1(($$-%%here) & 15)) DB 08Dh,004h,005h,0,0,0,0,90h
234 	times (1 & ge9(($$-%%here) & 15)  & ~ge10(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,007h,90h,90h,90h,90h,90h,90h,90h
235 	times (1 & ge10(($$-%%here) & 15) & ~ge11(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,008h,90h,90h,90h,90h,90h,90h,90h,90h
236 	times (1 & ge11(($$-%%here) & 15) & ~ge12(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,009h,90h,90h,90h,90h,90h,90h,90h,90h,90h
237 	times (1 & ge12(($$-%%here) & 15) & ~ge13(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,00Ah,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h
238 	times (1 & ge13(($$-%%here) & 15) & ~ge14(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,00Bh,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h
239 	times (1 & ge14(($$-%%here) & 15) & ~ge15(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,00Ch,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h
240 	times (1 & ge15(($$-%%here) & 15) & ~ge16(($$-%%here) & 15) & ~ge%1(($$-%%here) & 15)) DB 0EBh,00Dh,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h,90h
241 %%skip:
242 %endmacro
243 
244 %imacro	loopalign	0-1 12
245 	loopalignK7 %1
246 %endmacro
247 %define PACK(x,y,z,w)	(x*64+y*16+z*4+w)
248 
249 %ifidn __OUTPUT_FORMAT__,elf
250 
251 %idefine PIC_BASE(A) _GLOBAL_OFFSET_TABLE_ + $$ - $ wrt ..gotpc
252 %idefine PIC_EBP_REL(A) ebp + A wrt ..gotoff
253 %macro PIC_OFFSETTABLE 0
254 extern  _GLOBAL_OFFSET_TABLE_
255 get_pc.bp:
256 	mov ebp, [esp]
257 	retn
258 %endmacro
259 
260 %else
261 
262 %define PIC_BASE(A) (0)
263 %define PIC_EBP_REL(A) (A)
264 %macro PIC_OFFSETTABLE 0
265 get_pc.bp:
266 	mov ebp, [esp]
267 	retn
268 %endmacro
269 
270 %endif
271