2 ; Smart alignment macros
6 %imacro alignmode 1-2.nolist
8 %define __ALIGN_JMP_THRESHOLD__ 16
10 %define __ALIGN_16BIT_1B__ 0x90
11 %define __ALIGN_16BIT_2B__ 0x90,0x90
12 %define __ALIGN_16BIT_3B__ 0x90,0x90,0x90
13 %define __ALIGN_16BIT_4B__ 0x90,0x90,0x90,0x90
14 %define __ALIGN_16BIT_5B__ 0x90,0x90,0x90,0x90,0x90
15 %define __ALIGN_16BIT_6B__ 0x90,0x90,0x90,0x90,0x90,0x90
16 %define __ALIGN_16BIT_7B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90
17 %define __ALIGN_16BIT_8B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
19 %define __ALIGN_32BIT_1B__ 0x90
20 %define __ALIGN_32BIT_2B__ 0x90,0x90
21 %define __ALIGN_32BIT_3B__ 0x90,0x90,0x90
22 %define __ALIGN_32BIT_4B__ 0x90,0x90,0x90,0x90
23 %define __ALIGN_32BIT_5B__ 0x90,0x90,0x90,0x90,0x90
24 %define __ALIGN_32BIT_6B__ 0x90,0x90,0x90,0x90,0x90,0x90
25 %define __ALIGN_32BIT_7B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90
26 %define __ALIGN_32BIT_8B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
28 %define __ALIGN_64BIT_1B__ 0x90
29 %define __ALIGN_64BIT_2B__ 0x90,0x90
30 %define __ALIGN_64BIT_3B__ 0x90,0x90,0x90
31 %define __ALIGN_64BIT_4B__ 0x90,0x90,0x90,0x90
32 %define __ALIGN_64BIT_5B__ 0x90,0x90,0x90,0x90,0x90
33 %define __ALIGN_64BIT_6B__ 0x90,0x90,0x90,0x90,0x90,0x90
34 %define __ALIGN_64BIT_7B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90
35 %define __ALIGN_64BIT_8B__ 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
37 %define __ALIGN_JMP_THRESHOLD__ 8
39 %define __ALIGN_16BIT_1B__ 0x90
40 %define __ALIGN_16BIT_2B__ 0x89,0xf6
41 %define __ALIGN_16BIT_3B__ 0x8d,0x74,0x00
42 %define __ALIGN_16BIT_4B__ 0x8d,0xb4,0x00,0x00
43 %define __ALIGN_16BIT_5B__ 0x90,0x8d,0xb4,0x00,0x00
44 %define __ALIGN_16BIT_6B__ 0x89,0xf6,0x8d,0xbd,0x00,0x00
45 %define __ALIGN_16BIT_7B__ 0x8d,0x74,0x00,0x8d,0xbd,0x00,0x00
46 %define __ALIGN_16BIT_8B__ 0x8d,0xb4,0x00,0x00,0x8d,0xbd,0x00,0x00
48 %define __ALIGN_32BIT_1B__ 0x90
49 %define __ALIGN_32BIT_2B__ 0x89,0xf6
50 %define __ALIGN_32BIT_3B__ 0x8d,0x76,0x00
51 %define __ALIGN_32BIT_4B__ 0x8d,0x74,0x26,0x00
52 %define __ALIGN_32BIT_5B__ 0x90,0x8d,0x74,0x26,0x00
53 %define __ALIGN_32BIT_6B__ 0x8d,0xb6,0x00,0x00,0x00,0x00
54 %define __ALIGN_32BIT_7B__ 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00
55 %undef __ALIGN_32BIT_8B__
57 %define __ALIGN_64BIT_1B__ 0x90
58 %define __ALIGN_64BIT_2B__ 0x66,0x90
59 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
60 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
61 %define __ALIGN_64BIT_5B__ 0x66,0x66,0x90,0x66,0x90
62 %define __ALIGN_64BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
63 %define __ALIGN_64BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
64 %define __ALIGN_64BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
66 %define __ALIGN_JMP_THRESHOLD__ 16
68 %define __ALIGN_16BIT_1B__ 0x90
69 %define __ALIGN_16BIT_2B__ 0x66,0x90
70 %define __ALIGN_16BIT_3B__ 0x66,0x66,0x90
71 %define __ALIGN_16BIT_4B__ 0x66,0x66,0x66,0x90
72 %define __ALIGN_16BIT_5B__ 0x66,0x66,0x90,0x66,0x90
73 %define __ALIGN_16BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
74 %define __ALIGN_16BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
75 %define __ALIGN_16BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
77 %define __ALIGN_32BIT_1B__ 0x90
78 %define __ALIGN_32BIT_2B__ 0x66,0x90
79 %define __ALIGN_32BIT_3B__ 0x66,0x66,0x90
80 %define __ALIGN_32BIT_4B__ 0x66,0x66,0x66,0x90
81 %define __ALIGN_32BIT_5B__ 0x66,0x66,0x90,0x66,0x90
82 %define __ALIGN_32BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
83 %define __ALIGN_32BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
84 %define __ALIGN_32BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
86 %define __ALIGN_64BIT_1B__ 0x90
87 %define __ALIGN_64BIT_2B__ 0x66,0x90
88 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
89 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
90 %define __ALIGN_64BIT_5B__ 0x66,0x66,0x90,0x66,0x90
91 %define __ALIGN_64BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
92 %define __ALIGN_64BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
93 %define __ALIGN_64BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
95 %define __ALIGN_JMP_THRESHOLD__ 16
97 %define __ALIGN_16BIT_1B__ 0x90
98 %define __ALIGN_16BIT_2B__ 0x66,0x90
99 %define __ALIGN_16BIT_3B__ 0x66,0x66,0x90
100 %define __ALIGN_16BIT_4B__ 0x66,0x66,0x66,0x90
101 %define __ALIGN_16BIT_5B__ 0x66,0x66,0x90,0x66,0x90
102 %define __ALIGN_16BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
103 %define __ALIGN_16BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
104 %define __ALIGN_16BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
106 %define __ALIGN_32BIT_1B__ 0x90
107 %define __ALIGN_32BIT_2B__ 0x8b,0xc0
108 %define __ALIGN_32BIT_3B__ 0x8d,0x04,0x20
109 %define __ALIGN_32BIT_4B__ 0x8d,0x44,0x20,0x00
110 %define __ALIGN_32BIT_5B__ 0x8d,0x44,0x20,0x00,0x90
111 %define __ALIGN_32BIT_6B__ 0x8d,0x80,0x00,0x00,0x00,0x00
112 %define __ALIGN_32BIT_7B__ 0x8d,0x04,0x05,0x00,0x00,0x00,0x00
113 %undef __ALIGN_32BIT_8B__
115 %define __ALIGN_64BIT_1B__ 0x90
116 %define __ALIGN_64BIT_2B__ 0x66,0x90
117 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
118 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
119 %define __ALIGN_64BIT_5B__ 0x66,0x66,0x90,0x66,0x90
120 %define __ALIGN_64BIT_6B__ 0x66,0x66,0x90,0x66,0x66,0x90
121 %define __ALIGN_64BIT_7B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x90
122 %define __ALIGN_64BIT_8B__ 0x66,0x66,0x66,0x90,0x66,0x66,0x66,0x90
124 %define __ALIGN_JMP_THRESHOLD__ 16
126 %define __ALIGN_16BIT_1B__ 0x90
127 %define __ALIGN_16BIT_2B__ 0x66,0x90
128 %define __ALIGN_16BIT_3B__ 0x0f,0x1f,0x00
129 %define __ALIGN_16BIT_4B__ 0x0f,0x1f,0x40,0x00
130 %define __ALIGN_16BIT_5B__ 0x90,0x0f,0x1f,0x40,0x00
131 %define __ALIGN_16BIT_6B__ 0x0f,0x1f,0x00,0x0f,0x1f,0x00
132 %define __ALIGN_16BIT_7B__ 0x0f,0x1f,0x00,0x0f,0x1f,0x40,0x00
133 %define __ALIGN_16BIT_8B__ 0x0f,0x1f,0x40,0x00,0x0f,0x1f,0x40,0x00
135 %define __ALIGN_32BIT_1B__ 0x90
136 %define __ALIGN_32BIT_2B__ 0x66,0x90
137 %define __ALIGN_32BIT_3B__ 0x0f,0x1f,0x00
138 %define __ALIGN_32BIT_4B__ 0x0f,0x1f,0x40,0x00
139 %define __ALIGN_32BIT_5B__ 0x0f,0x1f,0x44,0x00,0x00
140 %define __ALIGN_32BIT_6B__ 0x66,0x0f,0x1f,0x44,0x00,0x00
141 %define __ALIGN_32BIT_7B__ 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
142 %define __ALIGN_32BIT_8B__ 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
144 %define __ALIGN_64BIT_1B__ 0x90
145 %define __ALIGN_64BIT_2B__ 0x66,0x90
146 %define __ALIGN_64BIT_3B__ 0x0f,0x1f,0x00
147 %define __ALIGN_64BIT_4B__ 0x0f,0x1f,0x40,0x00
148 %define __ALIGN_64BIT_5B__ 0x0f,0x1f,0x44,0x00,0x00
149 %define __ALIGN_64BIT_6B__ 0x66,0x0f,0x1f,0x44,0x00,0x00
150 %define __ALIGN_64BIT_7B__ 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
151 %define __ALIGN_64BIT_8B__ 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
153 %error unknown alignment mode: %1
156 %xdefine __ALIGN_JMP_THRESHOLD__ %2
158 %xdefine __ALIGNMODE__ %1,__ALIGN_JMP_THRESHOLD__
161 %unimacro align 1-2+.nolist
162 %imacro align 1-2+.nolist
164 times ((%1) - (($-$$) % (%1))) %2
167 %assign %$pad (%1) - (($-$$) % (%1))
168 %if %$pad > __ALIGN_JMP_THRESHOLD__
170 ; We can't re-use %$pad here as $ will have changed!
171 times ((%1) - (($-$$) % (%1))) nop
175 %ifdef __ALIGN_16BIT_8B__
177 db __ALIGN_16BIT_8B__
179 %assign %$pad %$pad % 8
182 db __ALIGN_16BIT_7B__
184 %assign %$pad %$pad % 7
187 db __ALIGN_16BIT_1B__
189 db __ALIGN_16BIT_2B__
191 db __ALIGN_16BIT_3B__
193 db __ALIGN_16BIT_4B__
195 db __ALIGN_16BIT_5B__
197 db __ALIGN_16BIT_6B__
199 db __ALIGN_16BIT_7B__
202 %ifdef __ALIGN_32BIT_8B__
204 db __ALIGN_32BIT_8B__
206 %assign %$pad %$pad % 8
209 db __ALIGN_32BIT_7B__
211 %assign %$pad %$pad % 7
214 db __ALIGN_32BIT_1B__
216 db __ALIGN_32BIT_2B__
218 db __ALIGN_32BIT_3B__
220 db __ALIGN_32BIT_4B__
222 db __ALIGN_32BIT_5B__
224 db __ALIGN_32BIT_6B__
226 db __ALIGN_32BIT_7B__
229 %ifdef __ALIGN_64BIT_8B__
231 db __ALIGN_64BIT_8B__
233 %assign %$pad %$pad % 8
236 db __ALIGN_64BIT_7B__
238 %assign %$pad %$pad % 7
241 db __ALIGN_64BIT_1B__
243 db __ALIGN_64BIT_2B__
245 db __ALIGN_64BIT_3B__
247 db __ALIGN_64BIT_4B__
249 db __ALIGN_64BIT_5B__
251 db __ALIGN_64BIT_6B__
253 db __ALIGN_64BIT_7B__
256 %error "Invalid __BITS__ value"