Rev 2665 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2665 | dunkaist | 1 | |
2 | ; Copyright (c) 1999-2012, Tomasz Grysztar. |
||
3 | ; All rights reserved. |
||
4 | |||
5 | |||
6 | mov [current_offset],edi |
||
2287 | heavyiron | 7 | mov [value_undefined],0 |
8 | cmp byte [esi],0 |
||
9 | je get_string_value |
||
10 | cmp byte [esi],'.' |
||
11 | je convert_fp |
||
12 | calculation_loop: |
||
13 | lods byte [esi] |
||
14 | cmp al,1 |
||
15 | je get_byte_number |
||
16 | cmp al,2 |
||
17 | je get_word_number |
||
18 | cmp al,4 |
||
19 | je get_dword_number |
||
20 | cmp al,8 |
||
21 | je get_qword_number |
||
22 | cmp al,0Fh |
||
23 | je value_out_of_range |
||
24 | cmp al,10h |
||
25 | je get_register |
||
26 | cmp al,11h |
||
27 | je get_label |
||
28 | cmp al,')' |
||
29 | je expression_calculated |
||
30 | cmp al,']' |
||
31 | je expression_calculated |
||
32 | cmp al,'!' |
||
33 | je invalid_expression |
||
34 | sub edi,14h |
||
35 | mov ebx,edi |
||
36 | sub ebx,14h |
||
37 | cmp al,0E0h |
||
38 | je calculate_rva |
||
39 | cmp al,0E1h |
||
40 | je calculate_plt |
||
41 | cmp al,0D0h |
||
42 | je calculate_not |
||
43 | cmp al,083h |
||
44 | je calculate_neg |
||
45 | mov dx,[ebx+8] |
||
46 | or dx,[edi+8] |
||
47 | cmp al,80h |
||
48 | je calculate_add |
||
49 | cmp al,81h |
||
50 | je calculate_sub |
||
51 | mov ah,[ebx+12] |
||
2665 | dunkaist | 52 | or ah,[edi+12] |
53 | jz absolute_values_calculation |
||
54 | call recoverable_misuse |
||
55 | absolute_values_calculation: |
||
56 | cmp al,90h |
||
57 | je calculate_mul |
||
58 | cmp al,91h |
||
2287 | heavyiron | 59 | je calculate_div |
60 | or dx,dx |
||
61 | jnz invalid_expression |
||
62 | cmp al,0A0h |
||
63 | je calculate_mod |
||
64 | cmp al,0B0h |
||
65 | je calculate_and |
||
66 | cmp al,0B1h |
||
67 | je calculate_or |
||
68 | cmp al,0B2h |
||
69 | je calculate_xor |
||
70 | cmp al,0C0h |
||
71 | je calculate_shl |
||
72 | cmp al,0C1h |
||
73 | je calculate_shr |
||
74 | jmp invalid_expression |
||
75 | expression_calculated: |
||
76 | sub edi,14h |
||
77 | cmp [value_undefined],0 |
||
78 | je expression_value_ok |
||
79 | xor eax,eax |
||
2665 | dunkaist | 80 | mov [edi],eax |
81 | mov [edi+4],eax |
||
82 | mov [edi+12],eax |
||
83 | expression_value_ok: |
||
84 | ret |
||
85 | get_byte_number: |
||
86 | xor eax,eax |
||
2287 | heavyiron | 87 | lods byte [esi] |
88 | stos dword [edi] |
||
89 | xor al,al |
||
2665 | dunkaist | 90 | stos dword [edi] |
91 | got_number: |
||
92 | and word [edi-8+8],0 |
||
93 | and word [edi-8+12],0 |
||
94 | and dword [edi-8+16],0 |
||
95 | add edi,0Ch |
||
96 | jmp calculation_loop |
||
97 | get_word_number: |
||
98 | xor eax,eax |
||
2287 | heavyiron | 99 | lods word [esi] |
100 | stos dword [edi] |
||
101 | xor ax,ax |
||
102 | stos dword [edi] |
||
103 | jmp got_number |
||
104 | get_dword_number: |
||
105 | movs dword [edi],[esi] |
||
106 | xor eax,eax |
||
107 | stos dword [edi] |
||
108 | jmp got_number |
||
109 | get_qword_number: |
||
110 | movs dword [edi],[esi] |
||
111 | movs dword [edi],[esi] |
||
112 | jmp got_number |
||
2665 | dunkaist | 113 | get_register: |
114 | mov byte [edi+9],0 |
||
115 | and word [edi+12],0 |
||
116 | lods byte [esi] |
||
117 | mov [edi+8],al |
||
118 | mov byte [edi+10],1 |
||
119 | xor eax,eax |
||
2287 | heavyiron | 120 | mov [edi+16],eax |
121 | stos dword [edi] |
||
122 | stos dword [edi] |
||
123 | add edi,0Ch |
||
124 | jmp calculation_loop |
||
125 | get_label: |
||
2665 | dunkaist | 126 | xor eax,eax |
127 | mov [edi+8],eax |
||
128 | mov [edi+12],eax |
||
129 | mov [edi+20],eax |
||
130 | lods dword [esi] |
||
131 | cmp eax,0Fh |
||
132 | jb predefined_label |
||
2287 | heavyiron | 133 | je reserved_word_used_as_symbol |
134 | mov ebx,eax |
||
2665 | dunkaist | 135 | mov ax,[current_pass] |
136 | mov [ebx+18],ax |
||
137 | mov cl,[ebx+9] |
||
138 | shr cl,1 |
||
139 | and cl,1 |
||
140 | neg cl |
||
141 | or byte [ebx+8],8 |
||
142 | test byte [ebx+8],1 |
||
143 | jz label_undefined |
||
144 | cmp ax,[ebx+16] |
||
145 | je unadjusted_label |
||
146 | test byte [ebx+8],4 |
||
147 | jnz label_out_of_scope |
||
148 | test byte [ebx+9],1 |
||
149 | jz unadjusted_label |
||
150 | mov eax,[ebx] |
||
151 | sub eax,dword [adjustment] |
||
152 | stos dword [edi] |
||
153 | mov eax,[ebx+4] |
||
154 | sbb eax,dword [adjustment+4] |
||
155 | stos dword [edi] |
||
156 | sbb cl,[adjustment_sign] |
||
157 | mov [edi-8+13],cl |
||
158 | mov eax,dword [adjustment] |
||
159 | or al,[adjustment_sign] |
||
160 | or eax,dword [adjustment+4] |
||
161 | jz got_label |
||
162 | or [next_pass_needed],-1 |
||
163 | jmp got_label |
||
164 | unadjusted_label: |
||
165 | mov eax,[ebx] |
||
166 | stos dword [edi] |
||
167 | mov eax,[ebx+4] |
||
168 | stos dword [edi] |
||
169 | mov [edi-8+13],cl |
||
170 | got_label: |
||
171 | cmp [symbols_file],0 |
||
172 | je label_reference_ok |
||
173 | cmp [next_pass_needed],0 |
||
174 | jne label_reference_ok |
||
175 | call store_label_reference |
||
176 | label_reference_ok: |
||
177 | mov al,[ebx+11] |
||
178 | mov [edi-8+12],al |
||
179 | mov eax,[ebx+12] |
||
180 | mov [edi-8+8],eax |
||
181 | cmp al,ah |
||
182 | jne labeled_registers_ok |
||
183 | shr eax,16 |
||
184 | add al,ah |
||
185 | jo labeled_registers_ok |
||
186 | xor ah,ah |
||
187 | mov [edi-8+10],ax |
||
188 | mov [edi-8+9],ah |
||
189 | labeled_registers_ok: |
||
190 | mov eax,[ebx+20] |
||
191 | mov [edi-8+16],eax |
||
192 | add edi,0Ch |
||
193 | mov al,[ebx+10] |
||
2287 | heavyiron | 194 | or al,al |
195 | jz calculation_loop |
||
196 | cmp [size_override],-1 |
||
197 | je calculation_loop |
||
198 | cmp [size_override],0 |
||
199 | je check_size |
||
200 | cmp [operand_size],0 |
||
201 | jne calculation_loop |
||
202 | mov [operand_size],al |
||
203 | jmp calculation_loop |
||
204 | check_size: |
||
205 | xchg [operand_size],al |
||
206 | or al,al |
||
207 | jz calculation_loop |
||
208 | cmp al,[operand_size] |
||
209 | jne operand_sizes_do_not_match |
||
210 | jmp calculation_loop |
||
211 | current_offset_label: |
||
212 | mov eax,[current_offset] |
||
2665 | dunkaist | 213 | make_current_offset_label: |
214 | xor edx,edx |
||
215 | xor ch,ch |
||
216 | sub eax,dword [org_origin] |
||
217 | sbb edx,dword [org_origin+4] |
||
218 | sbb ch,[org_origin_sign] |
||
219 | jp current_offset_label_ok |
||
220 | call recoverable_overflow |
||
221 | current_offset_label_ok: |
||
222 | stos dword [edi] |
||
223 | mov eax,edx |
||
224 | stos dword [edi] |
||
225 | mov eax,[org_registers] |
||
226 | stos dword [edi] |
||
227 | mov cl,[labels_type] |
||
228 | mov [edi-12+12],cx |
||
229 | mov eax,[org_symbol] |
||
230 | mov [edi-12+16],eax |
||
231 | add edi,8 |
||
232 | jmp calculation_loop |
||
2287 | heavyiron | 233 | org_origin_label: |
234 | mov eax,[org_start] |
||
235 | jmp make_current_offset_label |
||
236 | counter_label: |
||
237 | mov eax,[counter] |
||
238 | make_dword_label_value: |
||
239 | stos dword [edi] |
||
240 | xor eax,eax |
||
241 | stos dword [edi] |
||
242 | add edi,0Ch |
||
243 | jmp calculation_loop |
||
244 | timestamp_label: |
||
245 | call make_timestamp |
||
246 | make_qword_label_value: |
||
247 | stos dword [edi] |
||
248 | mov eax,edx |
||
249 | stos dword [edi] |
||
250 | add edi,0Ch |
||
251 | jmp calculation_loop |
||
252 | predefined_label: |
||
253 | or eax,eax |
||
254 | jz current_offset_label |
||
255 | cmp eax,1 |
||
256 | je counter_label |
||
257 | cmp eax,2 |
||
258 | je timestamp_label |
||
259 | cmp eax,3 |
||
260 | je org_origin_label |
||
261 | mov edx,invalid_value |
||
262 | jmp error_undefined |
||
2665 | dunkaist | 263 | label_out_of_scope: |
264 | mov edx,symbol_out_of_scope |
||
265 | jmp error_undefined |
||
266 | label_undefined: |
||
267 | mov edx,undefined_symbol |
||
268 | error_undefined: |
||
269 | cmp [current_pass],1 |
||
270 | ja undefined_value |
||
271 | force_next_pass: |
||
272 | or [next_pass_needed],-1 |
||
273 | undefined_value: |
||
274 | or [value_undefined],-1 |
||
275 | and word [edi+12],0 |
||
276 | xor eax,eax |
||
277 | stos dword [edi] |
||
278 | stos dword [edi] |
||
279 | add edi,0Ch |
||
280 | cmp [error_line],0 |
||
281 | jne calculation_loop |
||
282 | mov eax,[current_line] |
||
283 | mov [error_line],eax |
||
284 | mov [error],edx |
||
285 | mov [error_info],ebx |
||
286 | jmp calculation_loop |
||
287 | calculate_add: |
||
288 | mov ecx,[ebx+16] |
||
289 | cmp byte [edi+12],0 |
||
2287 | heavyiron | 290 | je add_values |
291 | mov ecx,[edi+16] |
||
2665 | dunkaist | 292 | cmp byte [ebx+12],0 |
293 | je add_values |
||
294 | call recoverable_misuse |
||
295 | add_values: |
||
296 | mov al,[edi+12] |
||
297 | or [ebx+12],al |
||
298 | mov [ebx+16],ecx |
||
2287 | heavyiron | 299 | mov eax,[edi] |
300 | add [ebx],eax |
||
2665 | dunkaist | 301 | mov eax,[edi+4] |
302 | adc [ebx+4],eax |
||
303 | mov al,[edi+13] |
||
304 | adc [ebx+13],al |
||
305 | jp add_sign_ok |
||
306 | call recoverable_overflow |
||
307 | add_sign_ok: |
||
308 | or dx,dx |
||
309 | jz calculation_loop |
||
310 | push esi |
||
311 | mov esi,ebx |
||
2287 | heavyiron | 312 | lea ebx,[edi+10] |
313 | mov cl,[edi+8] |
||
314 | call add_register |
||
315 | lea ebx,[edi+11] |
||
316 | mov cl,[edi+9] |
||
317 | call add_register |
||
318 | pop esi |
||
319 | jmp calculation_loop |
||
320 | add_register: |
||
321 | or cl,cl |
||
322 | jz add_register_done |
||
323 | add_register_start: |
||
324 | cmp [esi+8],cl |
||
325 | jne add_in_second_slot |
||
2665 | dunkaist | 326 | mov al,[ebx] |
327 | add [esi+10],al |
||
328 | jo value_out_of_range |
||
329 | jnz add_register_done |
||
330 | mov byte [esi+8],0 |
||
331 | ret |
||
332 | add_in_second_slot: |
||
2287 | heavyiron | 333 | cmp [esi+9],cl |
334 | jne create_in_first_slot |
||
2665 | dunkaist | 335 | mov al,[ebx] |
336 | add [esi+11],al |
||
337 | jo value_out_of_range |
||
338 | jnz add_register_done |
||
339 | mov byte [esi+9],0 |
||
340 | ret |
||
341 | create_in_first_slot: |
||
2287 | heavyiron | 342 | cmp byte [esi+8],0 |
343 | jne create_in_second_slot |
||
344 | mov [esi+8],cl |
||
345 | mov al,[ebx] |
||
346 | mov [esi+10],al |
||
347 | ret |
||
348 | create_in_second_slot: |
||
349 | cmp byte [esi+9],0 |
||
350 | jne invalid_expression |
||
351 | mov [esi+9],cl |
||
352 | mov al,[ebx] |
||
353 | mov [esi+11],al |
||
2665 | dunkaist | 354 | add_register_done: |
355 | ret |
||
356 | out_of_range: |
||
357 | jmp calculation_loop |
||
358 | calculate_sub: |
||
359 | xor ah,ah |
||
360 | mov ah,[ebx+12] |
||
361 | mov al,[edi+12] |
||
2287 | heavyiron | 362 | or al,al |
363 | jz sub_values |
||
364 | cmp al,ah |
||
365 | jne invalid_sub |
||
366 | xor ah,ah |
||
2665 | dunkaist | 367 | mov ecx,[edi+16] |
368 | cmp ecx,[ebx+16] |
||
369 | je sub_values |
||
370 | invalid_sub: |
||
371 | call recoverable_misuse |
||
372 | sub_values: |
||
373 | mov [ebx+12],ah |
||
374 | mov eax,[edi] |
||
375 | sub [ebx],eax |
||
376 | mov eax,[edi+4] |
||
377 | sbb [ebx+4],eax |
||
378 | mov al,[edi+13] |
||
379 | sbb [ebx+13],al |
||
380 | jp sub_sign_ok |
||
381 | cmp [error_line],0 |
||
382 | jne sub_sign_ok |
||
383 | call recoverable_overflow |
||
384 | sub_sign_ok: |
||
385 | or dx,dx |
||
386 | jz calculation_loop |
||
387 | push esi |
||
388 | mov esi,ebx |
||
2287 | heavyiron | 389 | lea ebx,[edi+10] |
390 | mov cl,[edi+8] |
||
391 | call sub_register |
||
392 | lea ebx,[edi+11] |
||
393 | mov cl,[edi+9] |
||
394 | call sub_register |
||
2665 | dunkaist | 395 | pop esi |
396 | jmp calculation_loop |
||
397 | sub_register: |
||
398 | or cl,cl |
||
399 | jz add_register_done |
||
400 | neg byte [ebx] |
||
401 | jo value_out_of_range |
||
402 | jmp add_register_start |
||
403 | calculate_mul: |
||
404 | or dx,dx |
||
405 | jz mul_start |
||
406 | cmp word [ebx+8],0 |
||
407 | jne mul_start |
||
408 | xor ecx,ecx |
||
409 | swap_values: |
||
410 | mov eax,[ebx+ecx] |
||
411 | xchg eax,[edi+ecx] |
||
412 | mov [ebx+ecx],eax |
||
413 | add ecx,4 |
||
414 | cmp ecx,16 |
||
415 | jb swap_values |
||
416 | mul_start: |
||
417 | push esi edx |
||
418 | mov esi,ebx |
||
419 | xor bl,bl |
||
420 | cmp byte [esi+13],0 |
||
421 | je mul_first_sign_ok |
||
422 | mov eax,[esi] |
||
423 | mov edx,[esi+4] |
||
424 | not eax |
||
425 | not edx |
||
426 | add eax,1 |
||
427 | adc edx,0 |
||
428 | mov [esi],eax |
||
429 | mov [esi+4],edx |
||
430 | or eax,edx |
||
431 | jz mul_overflow |
||
432 | xor bl,-1 |
||
433 | mul_first_sign_ok: |
||
434 | cmp byte [edi+13],0 |
||
435 | je mul_second_sign_ok |
||
436 | mov eax,[edi] |
||
437 | mov edx,[edi+4] |
||
438 | not eax |
||
439 | not edx |
||
440 | add eax,1 |
||
441 | adc edx,0 |
||
442 | mov [edi],eax |
||
443 | mov [edi+4],edx |
||
444 | or eax,edx |
||
445 | jz mul_overflow |
||
446 | xor bl,-1 |
||
447 | mul_second_sign_ok: |
||
448 | cmp dword [esi+4],0 |
||
449 | jz mul_numbers |
||
450 | cmp dword [edi+4],0 |
||
451 | jz mul_numbers |
||
452 | jnz mul_overflow |
||
453 | mul_numbers: |
||
454 | mov eax,[esi+4] |
||
455 | mul dword [edi] |
||
456 | or edx,edx |
||
457 | jnz mul_overflow |
||
458 | mov ecx,eax |
||
459 | mov eax,[esi] |
||
460 | mul dword [edi+4] |
||
461 | or edx,edx |
||
462 | jnz mul_overflow |
||
463 | add ecx,eax |
||
464 | jc mul_overflow |
||
465 | mov eax,[esi] |
||
466 | mul dword [edi] |
||
467 | add edx,ecx |
||
468 | jc mul_overflow |
||
469 | mov [esi],eax |
||
470 | mov [esi+4],edx |
||
471 | or bl,bl |
||
472 | jz mul_ok |
||
473 | not eax |
||
474 | not edx |
||
475 | add eax,1 |
||
476 | adc edx,0 |
||
477 | mov [esi],eax |
||
478 | mov [esi+4],edx |
||
479 | or eax,edx |
||
480 | jnz mul_ok |
||
481 | not bl |
||
482 | mul_ok: |
||
483 | mov [esi+13],bl |
||
484 | pop edx |
||
485 | or dx,dx |
||
486 | jz mul_calculated |
||
487 | cmp word [edi+8],0 |
||
2287 | heavyiron | 488 | jne invalid_value |
2665 | dunkaist | 489 | cmp byte [esi+8],0 |
490 | je mul_first_register_ok |
||
491 | call get_byte_scale |
||
492 | imul byte [esi+10] |
||
493 | mov dl,ah |
||
494 | cbw |
||
495 | cmp ah,dl |
||
2287 | heavyiron | 496 | jne value_out_of_range |
497 | mov [esi+10],al |
||
498 | or al,al |
||
499 | jnz mul_first_register_ok |
||
500 | mov [esi+8],al |
||
501 | mul_first_register_ok: |
||
2665 | dunkaist | 502 | cmp byte [esi+9],0 |
503 | je mul_calculated |
||
504 | call get_byte_scale |
||
505 | imul byte [esi+11] |
||
506 | mov dl,ah |
||
507 | cbw |
||
508 | cmp ah,dl |
||
2287 | heavyiron | 509 | jne value_out_of_range |
510 | mov [esi+11],al |
||
511 | or al,al |
||
512 | jnz mul_calculated |
||
513 | mov [esi+9],al |
||
514 | mul_calculated: |
||
2665 | dunkaist | 515 | pop esi |
516 | jmp calculation_loop |
||
517 | mul_overflow: |
||
518 | pop edx esi |
||
519 | call recoverable_overflow |
||
520 | jmp calculation_loop |
||
521 | get_byte_scale: |
||
522 | mov al,[edi] |
||
523 | cbw |
||
524 | cwde |
||
525 | cdq |
||
526 | cmp edx,[edi+4] |
||
527 | jne value_out_of_range |
||
528 | cmp eax,[edi] |
||
529 | jne value_out_of_range |
||
530 | ret |
||
531 | calculate_div: |
||
532 | push esi edx |
||
533 | mov esi,ebx |
||
534 | call div_64 |
||
2287 | heavyiron | 535 | pop edx |
536 | or dx,dx |
||
537 | jz div_calculated |
||
2665 | dunkaist | 538 | cmp byte [esi+8],0 |
539 | je div_first_register_ok |
||
540 | call get_byte_scale |
||
541 | or al,al |
||
542 | jz value_out_of_range |
||
543 | mov al,[esi+10] |
||
544 | cbw |
||
2287 | heavyiron | 545 | idiv byte [edi] |
546 | or ah,ah |
||
547 | jnz invalid_use_of_symbol |
||
548 | mov [esi+10],al |
||
549 | div_first_register_ok: |
||
2665 | dunkaist | 550 | cmp byte [esi+9],0 |
551 | je div_calculated |
||
552 | call get_byte_scale |
||
553 | or al,al |
||
554 | jz value_out_of_range |
||
555 | mov al,[esi+11] |
||
556 | cbw |
||
2287 | heavyiron | 557 | idiv byte [edi] |
558 | or ah,ah |
||
559 | jnz invalid_use_of_symbol |
||
560 | mov [esi+11],al |
||
561 | div_calculated: |
||
562 | pop esi |
||
563 | jmp calculation_loop |
||
564 | calculate_mod: |
||
565 | push esi |
||
566 | mov esi,ebx |
||
567 | call div_64 |
||
2665 | dunkaist | 568 | mov [esi],eax |
569 | mov [esi+4],edx |
||
570 | mov [esi+13],bh |
||
571 | pop esi |
||
572 | jmp calculation_loop |
||
573 | calculate_and: |
||
574 | mov eax,[edi] |
||
575 | mov edx,[edi+4] |
||
576 | mov cl,[edi+13] |
||
577 | and [ebx],eax |
||
578 | and [ebx+4],edx |
||
579 | and [ebx+13],cl |
||
580 | jmp calculation_loop |
||
581 | calculate_or: |
||
582 | mov eax,[edi] |
||
583 | mov edx,[edi+4] |
||
584 | mov cl,[edi+13] |
||
585 | or [ebx],eax |
||
586 | or [ebx+4],edx |
||
587 | or [ebx+13],cl |
||
588 | jmp calculation_loop |
||
589 | calculate_xor: |
||
590 | mov eax,[edi] |
||
591 | mov edx,[edi+4] |
||
592 | mov cl,[edi+13] |
||
593 | xor [ebx],eax |
||
594 | xor [ebx+4],edx |
||
595 | xor [ebx+13],cl |
||
596 | jz calculation_loop |
||
597 | or cl,cl |
||
598 | jz xor_size_check |
||
599 | xor eax,[ebx] |
||
600 | xor edx,[ebx+4] |
||
601 | xor_size_check: |
||
602 | mov cl,[value_size] |
||
603 | cmp cl,1 |
||
604 | je xor_byte_result |
||
605 | cmp cl,2 |
||
606 | je xor_word_result |
||
607 | cmp cl,4 |
||
608 | je xor_dword_result |
||
609 | cmp cl,6 |
||
610 | je xor_pword_result |
||
611 | cmp cl,8 |
||
612 | jne calculation_loop |
||
613 | xor edx,[ebx+4] |
||
614 | js xor_result_truncated |
||
615 | jmp calculation_loop |
||
616 | xor_pword_result: |
||
617 | test edx,0FFFF0000h |
||
618 | jnz calculation_loop |
||
619 | cmp word [ebx+6],-1 |
||
620 | jne calculation_loop |
||
621 | xor dx,[ebx+4] |
||
622 | jns calculation_loop |
||
623 | not word [ebx+6] |
||
624 | jmp xor_result_truncated |
||
625 | xor_dword_result: |
||
626 | test edx,edx |
||
627 | jnz calculation_loop |
||
628 | cmp dword [ebx+4],-1 |
||
629 | jne calculation_loop |
||
630 | xor eax,[ebx] |
||
631 | jns calculation_loop |
||
632 | not dword [ebx+4] |
||
633 | jmp xor_result_truncated |
||
634 | xor_word_result: |
||
635 | test edx,edx |
||
636 | jnz calculation_loop |
||
637 | test eax,0FFFF0000h |
||
638 | jnz calculation_loop |
||
639 | cmp dword [ebx+4],-1 |
||
640 | jne calculation_loop |
||
641 | cmp word [ebx+2],-1 |
||
642 | jne calculation_loop |
||
643 | xor ax,[ebx] |
||
644 | jns calculation_loop |
||
645 | not dword [ebx+4] |
||
646 | not word [ebx+2] |
||
647 | jmp xor_result_truncated |
||
648 | xor_byte_result: |
||
649 | test edx,edx |
||
650 | jnz calculation_loop |
||
651 | test eax,0FFFFFF00h |
||
652 | jnz calculation_loop |
||
653 | cmp dword [ebx+4],-1 |
||
654 | jne calculation_loop |
||
655 | cmp word [ebx+2],-1 |
||
656 | jne calculation_loop |
||
657 | cmp byte [ebx+1],-1 |
||
658 | jne calculation_loop |
||
659 | xor al,[ebx] |
||
660 | jns calculation_loop |
||
661 | not dword [ebx+4] |
||
662 | not word [ebx+2] |
||
663 | not byte [ebx+1] |
||
664 | xor_result_truncated: |
||
665 | mov byte [ebx+13],0 |
||
666 | jmp calculation_loop |
||
667 | shr_negative: |
||
668 | mov byte [edi+13],0 |
||
669 | not dword [edi] |
||
670 | not dword [edi+4] |
||
671 | add dword [edi],1 |
||
672 | adc dword [edi+4],0 |
||
673 | jc shl_over |
||
674 | calculate_shl: |
||
675 | cmp byte [edi+13],0 |
||
676 | jne shl_negative |
||
677 | mov edx,[ebx+4] |
||
678 | mov eax,[ebx] |
||
679 | cmp dword [edi+4],0 |
||
680 | jne shl_over |
||
681 | movsx ecx,byte [ebx+13] |
||
682 | xchg ecx,[edi] |
||
683 | cmp ecx,64 |
||
684 | je shl_max |
||
685 | ja shl_over |
||
686 | cmp ecx,32 |
||
687 | jae shl_high |
||
688 | shld [edi],edx,cl |
||
689 | shld edx,eax,cl |
||
690 | shl eax,cl |
||
691 | mov [ebx],eax |
||
692 | mov [ebx+4],edx |
||
693 | jmp shl_done |
||
694 | shl_over: |
||
695 | cmp byte [ebx+13],0 |
||
696 | jne shl_overflow |
||
697 | shl_max: |
||
698 | movsx ecx,byte [ebx+13] |
||
699 | cmp eax,ecx |
||
700 | jne shl_overflow |
||
701 | cmp edx,ecx |
||
702 | jne shl_overflow |
||
703 | xor eax,eax |
||
704 | mov [ebx],eax |
||
705 | mov [ebx+4],eax |
||
706 | jmp calculation_loop |
||
707 | shl_high: |
||
708 | sub cl,32 |
||
709 | shld [edi],edx,cl |
||
710 | shld edx,eax,cl |
||
711 | shl eax,cl |
||
712 | mov [ebx+4],eax |
||
713 | and dword [ebx],0 |
||
714 | cmp edx,[edi] |
||
715 | jne shl_overflow |
||
716 | shl_done: |
||
717 | movsx eax,byte [ebx+13] |
||
718 | cmp eax,[edi] |
||
719 | je calculation_loop |
||
720 | shl_overflow: |
||
721 | call recoverable_overflow |
||
722 | jmp calculation_loop |
||
723 | shl_negative: |
||
724 | mov byte [edi+13],0 |
||
725 | not dword [edi] |
||
726 | not dword [edi+4] |
||
727 | add dword [edi],1 |
||
728 | adc dword [edi+4],0 |
||
729 | jnc calculate_shr |
||
730 | dec dword [edi+4] |
||
731 | calculate_shr: |
||
732 | cmp byte [edi+13],0 |
||
733 | jne shr_negative |
||
734 | cmp byte [ebx+13],0 |
||
735 | je do_shr |
||
736 | mov al,[value_size] |
||
737 | cmp al,1 |
||
738 | je shr_negative_byte |
||
739 | cmp al,2 |
||
740 | je shr_negative_word |
||
741 | cmp al,4 |
||
742 | je shr_negative_dword |
||
743 | cmp al,6 |
||
744 | je shr_negative_pword |
||
745 | cmp al,8 |
||
746 | jne do_shr |
||
747 | shr_negative_qword: |
||
748 | test byte [ebx+7],80h |
||
749 | jz do_shr |
||
750 | shr_truncated: |
||
751 | mov byte [ebx+13],0 |
||
752 | do_shr: |
||
753 | mov edx,[ebx+4] |
||
754 | mov eax,[ebx] |
||
755 | cmp dword [edi+4],0 |
||
756 | jne shr_over |
||
757 | mov ecx,[edi] |
||
758 | cmp ecx,64 |
||
759 | jae shr_over |
||
760 | push esi |
||
761 | movsx esi,byte [ebx+13] |
||
762 | cmp ecx,32 |
||
763 | jae shr_high |
||
764 | shrd eax,edx,cl |
||
765 | shrd edx,esi,cl |
||
766 | mov [ebx],eax |
||
767 | mov [ebx+4],edx |
||
768 | pop esi |
||
769 | jmp calculation_loop |
||
770 | shr_high: |
||
771 | sub cl,32 |
||
772 | shrd edx,esi,cl |
||
773 | mov [ebx],edx |
||
774 | mov [ebx+4],esi |
||
775 | pop esi |
||
776 | jmp calculation_loop |
||
777 | shr_over: |
||
778 | movsx eax,byte [ebx+13] |
||
779 | mov dword [ebx],eax |
||
780 | mov dword [ebx+4],eax |
||
781 | jmp calculation_loop |
||
782 | shr_negative_byte: |
||
783 | cmp dword [ebx+4],-1 |
||
784 | jne do_shr |
||
785 | cmp word [ebx+2],-1 |
||
786 | jne do_shr |
||
787 | cmp byte [ebx+1],-1 |
||
788 | jne do_shr |
||
789 | test byte [ebx],80h |
||
790 | jz do_shr |
||
791 | not dword [ebx+4] |
||
792 | not word [ebx+2] |
||
793 | not byte [ebx+1] |
||
794 | jmp shr_truncated |
||
795 | shr_negative_word: |
||
796 | cmp dword [ebx+4],-1 |
||
797 | jne do_shr |
||
798 | cmp word [ebx+2],-1 |
||
799 | jne do_shr |
||
800 | test byte [ebx+1],80h |
||
801 | jz do_shr |
||
802 | not dword [ebx+4] |
||
803 | not word [ebx+2] |
||
804 | jmp shr_truncated |
||
805 | shr_negative_dword: |
||
806 | cmp dword [ebx+4],-1 |
||
807 | jne do_shr |
||
808 | test byte [ebx+3],80h |
||
809 | jz do_shr |
||
810 | not dword [ebx+4] |
||
811 | jmp shr_truncated |
||
812 | shr_negative_pword: |
||
813 | cmp word [ebx+6],-1 |
||
814 | jne do_shr |
||
815 | test byte [ebx+5],80h |
||
816 | jz do_shr |
||
817 | not word [ebx+6] |
||
818 | jmp shr_truncated |
||
819 | calculate_not: |
||
820 | cmp word [edi+8],0 |
||
821 | jne invalid_expression |
||
822 | cmp byte [edi+12],0 |
||
823 | je not_ok |
||
824 | call recoverable_misuse |
||
825 | not_ok: |
||
826 | mov al,[value_size] |
||
827 | cmp al,1 |
||
828 | je not_byte |
||
829 | cmp al,2 |
||
830 | je not_word |
||
831 | cmp al,4 |
||
832 | je not_dword |
||
833 | cmp al,6 |
||
834 | je not_pword |
||
835 | cmp al,8 |
||
836 | je not_qword |
||
837 | not dword [edi] |
||
838 | not dword [edi+4] |
||
839 | not byte [edi+13] |
||
840 | add edi,14h |
||
841 | jmp calculation_loop |
||
842 | not_qword: |
||
843 | not dword [edi] |
||
844 | not dword [edi+4] |
||
845 | finish_not: |
||
846 | mov byte [edi+13],0 |
||
847 | add edi,14h |
||
848 | jmp calculation_loop |
||
849 | not_byte: |
||
850 | cmp dword [edi+4],0 |
||
2287 | heavyiron | 851 | jne not_qword |
852 | cmp word [edi+2],0 |
||
853 | jne not_qword |
||
854 | cmp byte [edi+1],0 |
||
2665 | dunkaist | 855 | jne not_qword |
856 | not byte [edi] |
||
857 | jmp finish_not |
||
858 | not_word: |
||
859 | cmp dword [edi+4],0 |
||
860 | jne not_qword |
||
861 | cmp word [edi+2],0 |
||
862 | jne not_qword |
||
863 | not word [edi] |
||
864 | jmp finish_not |
||
865 | not_dword: |
||
866 | cmp dword [edi+4],0 |
||
867 | jne not_qword |
||
868 | not dword [edi] |
||
869 | jmp finish_not |
||
870 | not_pword: |
||
871 | cmp word [edi+6],0 |
||
872 | jne not_qword |
||
873 | not word [edi+4] |
||
874 | not dword [edi] |
||
875 | jmp finish_not |
||
876 | calculate_neg: |
||
877 | cmp word [edi+8],0 |
||
878 | jne invalid_expression |
||
879 | cmp byte [edi+12],0 |
||
880 | je neg_ok |
||
881 | call recoverable_misuse |
||
882 | neg_ok: |
||
883 | xor eax,eax |
||
884 | xor edx,edx |
||
885 | xor cl,cl |
||
886 | xchg eax,[edi] |
||
887 | xchg edx,[edi+4] |
||
888 | xchg cl,[edi+13] |
||
889 | sub [edi],eax |
||
890 | sbb [edi+4],edx |
||
891 | sbb [edi+13],cl |
||
892 | jp neg_sign_ok |
||
893 | call recoverable_overflow |
||
894 | neg_sign_ok: |
||
895 | add edi,14h |
||
896 | jmp calculation_loop |
||
897 | calculate_rva: |
||
898 | cmp word [edi+8],0 |
||
899 | jne invalid_expression |
||
900 | mov al,[output_format] |
||
901 | cmp al,5 |
||
902 | je calculate_gotoff |
||
903 | cmp al,4 |
||
904 | je calculate_coff_rva |
||
905 | cmp al,3 |
||
906 | jne invalid_expression |
||
907 | test [format_flags],8 |
||
908 | jnz pe64_rva |
||
909 | mov al,2 |
||
2287 | heavyiron | 910 | bt [resolver_flags],0 |
911 | jc rva_type_ok |
||
912 | xor al,al |
||
913 | rva_type_ok: |
||
2665 | dunkaist | 914 | cmp byte [edi+12],al |
915 | je rva_ok |
||
916 | call recoverable_misuse |
||
917 | rva_ok: |
||
918 | mov byte [edi+12],0 |
||
919 | mov eax,[code_start] |
||
920 | mov eax,[eax+34h] |
||
921 | xor edx,edx |
||
922 | finish_rva: |
||
923 | sub [edi],eax |
||
924 | sbb [edi+4],edx |
||
925 | sbb byte [edi+13],0 |
||
926 | jp rva_finished |
||
927 | call recoverable_overflow |
||
928 | rva_finished: |
||
929 | add edi,14h |
||
930 | jmp calculation_loop |
||
931 | pe64_rva: |
||
932 | mov al,4 |
||
2287 | heavyiron | 933 | bt [resolver_flags],0 |
934 | jc pe64_rva_type_ok |
||
935 | xor al,al |
||
936 | pe64_rva_type_ok: |
||
2665 | dunkaist | 937 | cmp byte [edi+12],al |
938 | je pe64_rva_ok |
||
939 | call recoverable_misuse |
||
940 | pe64_rva_ok: |
||
941 | mov byte [edi+12],0 |
||
942 | mov eax,[code_start] |
||
943 | mov edx,[eax+34h] |
||
944 | mov eax,[eax+30h] |
||
945 | jmp finish_rva |
||
946 | calculate_gotoff: |
||
947 | test [format_flags],8+1 |
||
948 | jnz invalid_expression |
||
949 | calculate_coff_rva: |
||
2287 | heavyiron | 950 | mov dl,5 |
951 | cmp byte [edi+12],2 |
||
2665 | dunkaist | 952 | je change_value_type |
953 | incorrect_change_of_value_type: |
||
954 | call recoverable_misuse |
||
955 | change_value_type: |
||
956 | mov byte [edi+12],dl |
||
957 | add edi,14h |
||
958 | jmp calculation_loop |
||
2287 | heavyiron | 959 | calculate_plt: |
960 | cmp word [edi+8],0 |
||
961 | jne invalid_expression |
||
962 | cmp [output_format],5 |
||
963 | jne invalid_expression |
||
964 | test [format_flags],1 |
||
965 | jnz invalid_expression |
||
966 | mov dl,6 |
||
967 | mov dh,2 |
||
968 | test [format_flags],8 |
||
969 | jz check_value_for_plt |
||
970 | mov dh,4 |
||
971 | check_value_for_plt: |
||
972 | mov eax,[edi] |
||
973 | or eax,[edi+4] |
||
974 | jnz incorrect_change_of_value_type |
||
975 | cmp byte [edi+12],dh |
||
976 | jne incorrect_change_of_value_type |
||
977 | mov eax,[edi+16] |
||
978 | cmp byte [eax],80h |
||
979 | jne incorrect_change_of_value_type |
||
980 | jmp change_value_type |
||
981 | div_64: |
||
982 | xor ebx,ebx |
||
983 | cmp dword [edi],0 |
||
984 | jne divider_ok |
||
985 | cmp dword [edi+4],0 |
||
986 | jne divider_ok |
||
987 | cmp [next_pass_needed],0 |
||
988 | je value_out_of_range |
||
2665 | dunkaist | 989 | jmp div_done |
990 | divider_ok: |
||
991 | cmp byte [esi+13],0 |
||
992 | je div_first_sign_ok |
||
993 | mov eax,[esi] |
||
994 | mov edx,[esi+4] |
||
995 | not eax |
||
996 | not edx |
||
997 | add eax,1 |
||
998 | adc edx,0 |
||
999 | mov [esi],eax |
||
1000 | mov [esi+4],edx |
||
1001 | or eax,edx |
||
1002 | jz value_out_of_range |
||
1003 | xor bx,-1 |
||
1004 | div_first_sign_ok: |
||
1005 | cmp byte [edi+13],0 |
||
1006 | je div_second_sign_ok |
||
1007 | mov eax,[edi] |
||
1008 | mov edx,[edi+4] |
||
1009 | not eax |
||
1010 | not edx |
||
1011 | add eax,1 |
||
1012 | adc edx,0 |
||
1013 | mov [edi],eax |
||
1014 | mov [edi+4],edx |
||
1015 | or eax,edx |
||
1016 | jz value_out_of_range |
||
1017 | xor bl,-1 |
||
1018 | div_second_sign_ok: |
||
1019 | cmp dword [edi+4],0 |
||
1020 | jne div_high |
||
1021 | mov ecx,[edi] |
||
2287 | heavyiron | 1022 | mov eax,[esi+4] |
1023 | xor edx,edx |
||
1024 | div ecx |
||
1025 | mov [esi+4],eax |
||
1026 | mov eax,[esi] |
||
1027 | div ecx |
||
1028 | mov [esi],eax |
||
1029 | mov eax,edx |
||
1030 | xor edx,edx |
||
2665 | dunkaist | 1031 | jmp div_done |
1032 | div_high: |
||
1033 | push ebx |
||
1034 | mov eax,[esi+4] |
||
1035 | xor edx,edx |
||
1036 | div dword [edi+4] |
||
1037 | mov ebx,[esi] |
||
1038 | mov [esi],eax |
||
1039 | and dword [esi+4],0 |
||
1040 | mov ecx,edx |
||
1041 | mul dword [edi] |
||
1042 | div_high_loop: |
||
1043 | cmp ecx,edx |
||
2287 | heavyiron | 1044 | ja div_high_done |
1045 | jb div_high_large_correction |
||
1046 | cmp ebx,eax |
||
1047 | jae div_high_done |
||
1048 | div_high_correction: |
||
1049 | dec dword [esi] |
||
1050 | sub eax,[edi] |
||
1051 | sbb edx,[edi+4] |
||
1052 | jnc div_high_loop |
||
1053 | div_high_done: |
||
1054 | sub ebx,eax |
||
1055 | sbb ecx,edx |
||
2665 | dunkaist | 1056 | mov edx,ecx |
1057 | mov eax,ebx |
||
1058 | pop ebx |
||
1059 | jmp div_done |
||
1060 | div_high_large_correction: |
||
1061 | push eax edx |
||
1062 | mov eax,edx |
||
1063 | sub eax,ecx |
||
2287 | heavyiron | 1064 | xor edx,edx |
1065 | div dword [edi+4] |
||
1066 | shr eax,1 |
||
1067 | jz div_high_small_correction |
||
1068 | sub [esi],eax |
||
1069 | push eax |
||
1070 | mul dword [edi+4] |
||
1071 | sub dword [esp+4],eax |
||
1072 | pop eax |
||
1073 | mul dword [edi] |
||
1074 | sub dword [esp+4],eax |
||
1075 | sbb dword [esp],edx |
||
1076 | pop edx eax |
||
1077 | jmp div_high_loop |
||
1078 | div_high_small_correction: |
||
1079 | pop edx eax |
||
1080 | jmp div_high_correction |
||
1081 | div_done: |
||
1082 | or bh,bh |
||
1083 | jz remainder_ok |
||
1084 | not eax |
||
1085 | not edx |
||
2665 | dunkaist | 1086 | add eax,1 |
1087 | adc edx,0 |
||
1088 | mov ecx,eax |
||
1089 | or ecx,edx |
||
1090 | jnz remainder_ok |
||
1091 | not bh |
||
1092 | remainder_ok: |
||
1093 | or bl,bl |
||
1094 | jz div_ok |
||
1095 | not dword [esi] |
||
2287 | heavyiron | 1096 | not dword [esi+4] |
2665 | dunkaist | 1097 | add dword [esi],1 |
1098 | adc dword [esi+4],0 |
||
1099 | mov ecx,[esi] |
||
1100 | or ecx,[esi+4] |
||
1101 | jnz div_ok |
||
1102 | not bl |
||
1103 | div_ok: |
||
1104 | mov [esi+13],bl |
||
1105 | ret |
||
1106 | store_label_reference: |
||
1107 | mov eax,[display_buffer] |
||
1108 | mov dword [eax-4],2 |
||
1109 | mov dword [eax-8],4 |
||
1110 | sub eax,8+4 |
||
1111 | cmp eax,edi |
||
1112 | jbe out_of_memory |
||
1113 | mov [display_buffer],eax |
||
1114 | mov [eax],ebx |
||
1115 | ret |
||
1116 | convert_fp: |
||
1117 | inc esi |
||
1118 | and word [edi+8],0 |
||
1119 | and word [edi+12],0 |
||
1120 | mov al,[value_size] |
||
1121 | cmp al,2 |
||
1122 | je convert_fp_word |
||
1123 | cmp al,4 |
||
1124 | je convert_fp_dword |
||
1125 | test al,not 8 |
||
1126 | jnz invalid_value |
||
1127 | convert_fp_qword: |
||
1128 | xor eax,eax |
||
1129 | xor edx,edx |
||
1130 | cmp word [esi+8],8000h |
||
1131 | je fp_qword_store |
||
1132 | mov bx,[esi+8] |
||
1133 | mov eax,[esi] |
||
1134 | mov edx,[esi+4] |
||
1135 | add eax,eax |
||
1136 | adc edx,edx |
||
1137 | mov ecx,edx |
||
1138 | shr edx,12 |
||
1139 | shrd eax,ecx,12 |
||
1140 | jnc fp_qword_ok |
||
1141 | add eax,1 |
||
1142 | adc edx,0 |
||
1143 | bt edx,20 |
||
1144 | jnc fp_qword_ok |
||
1145 | and edx,1 shl 20 - 1 |
||
1146 | inc bx |
||
1147 | shr edx,1 |
||
1148 | rcr eax,1 |
||
1149 | fp_qword_ok: |
||
1150 | add bx,3FFh |
||
1151 | cmp bx,7FFh |
||
1152 | jge value_out_of_range |
||
1153 | cmp bx,0 |
||
1154 | jg fp_qword_exp_ok |
||
1155 | or edx,1 shl 20 |
||
1156 | mov cx,bx |
||
1157 | neg cx |
||
1158 | inc cx |
||
1159 | cmp cx,52 |
||
1160 | ja value_out_of_range |
||
1161 | cmp cx,32 |
||
1162 | jbe fp_qword_small_shift |
||
1163 | sub cx,32 |
||
1164 | mov eax,edx |
||
1165 | xor edx,edx |
||
1166 | shr eax,cl |
||
1167 | jmp fp_qword_shift_done |
||
1168 | fp_qword_small_shift: |
||
1169 | mov ebx,edx |
||
1170 | shr edx,cl |
||
1171 | shrd eax,ebx,cl |
||
1172 | fp_qword_shift_done: |
||
1173 | mov bx,0 |
||
1174 | jnc fp_qword_exp_ok |
||
1175 | add eax,1 |
||
1176 | adc edx,0 |
||
1177 | test edx,1 shl 20 |
||
1178 | jz fp_qword_exp_ok |
||
1179 | and edx,1 shl 20 - 1 |
||
1180 | inc bx |
||
1181 | fp_qword_exp_ok: |
||
1182 | shl ebx,20 |
||
1183 | or edx,ebx |
||
1184 | fp_qword_store: |
||
1185 | mov bl,[esi+11] |
||
1186 | shl ebx,31 |
||
1187 | or edx,ebx |
||
1188 | mov [edi],eax |
||
1189 | mov [edi+4],edx |
||
1190 | add esi,13 |
||
1191 | ret |
||
1192 | convert_fp_word: |
||
1193 | xor eax,eax |
||
1194 | cmp word [esi+8],8000h |
||
1195 | je fp_word_store |
||
2287 | heavyiron | 1196 | mov bx,[esi+8] |
1197 | mov ax,[esi+6] |
||
1198 | shl ax,1 |
||
1199 | shr ax,6 |
||
1200 | jnc fp_word_ok |
||
1201 | inc ax |
||
1202 | bt ax,10 |
||
1203 | jnc fp_word_ok |
||
1204 | and ax,1 shl 10 - 1 |
||
1205 | inc bx |
||
1206 | shr ax,1 |
||
1207 | fp_word_ok: |
||
1208 | add bx,0Fh |
||
1209 | cmp bx,01Fh |
||
1210 | jge value_out_of_range |
||
1211 | cmp bx,0 |
||
1212 | jg fp_word_exp_ok |
||
1213 | or ax,1 shl 10 |
||
1214 | mov cx,bx |
||
1215 | neg cx |
||
1216 | inc cx |
||
1217 | cmp cx,10 |
||
1218 | ja value_out_of_range |
||
1219 | xor bx,bx |
||
1220 | shr ax,cl |
||
1221 | jnc fp_word_exp_ok |
||
1222 | inc ax |
||
1223 | test ax,1 shl 10 |
||
1224 | jz fp_word_exp_ok |
||
1225 | and ax,1 shl 10 - 1 |
||
1226 | inc bx |
||
1227 | fp_word_exp_ok: |
||
1228 | shl bx,10 |
||
1229 | or ax,bx |
||
1230 | fp_word_store: |
||
1231 | mov bl,[esi+11] |
||
1232 | shl bx,15 |
||
1233 | or ax,bx |
||
1234 | mov [edi],eax |
||
1235 | xor eax,eax |
||
1236 | mov [edi+4],eax |
||
1237 | add esi,13 |
||
1238 | ret |
||
1239 | convert_fp_dword: |
||
1240 | xor eax,eax |
||
1241 | cmp word [esi+8],8000h |
||
1242 | je fp_dword_store |
||
1243 | mov bx,[esi+8] |
||
1244 | mov eax,[esi+4] |
||
1245 | shl eax,1 |
||
1246 | shr eax,9 |
||
1247 | jnc fp_dword_ok |
||
1248 | inc eax |
||
1249 | bt eax,23 |
||
1250 | jnc fp_dword_ok |
||
1251 | and eax,1 shl 23 - 1 |
||
1252 | inc bx |
||
1253 | shr eax,1 |
||
1254 | fp_dword_ok: |
||
1255 | add bx,7Fh |
||
1256 | cmp bx,0FFh |
||
1257 | jge value_out_of_range |
||
1258 | cmp bx,0 |
||
1259 | jg fp_dword_exp_ok |
||
1260 | or eax,1 shl 23 |
||
1261 | mov cx,bx |
||
1262 | neg cx |
||
1263 | inc cx |
||
1264 | cmp cx,23 |
||
1265 | ja value_out_of_range |
||
1266 | xor bx,bx |
||
1267 | shr eax,cl |
||
1268 | jnc fp_dword_exp_ok |
||
1269 | inc eax |
||
1270 | test eax,1 shl 23 |
||
1271 | jz fp_dword_exp_ok |
||
1272 | and eax,1 shl 23 - 1 |
||
1273 | inc bx |
||
1274 | fp_dword_exp_ok: |
||
1275 | shl ebx,23 |
||
1276 | or eax,ebx |
||
1277 | fp_dword_store: |
||
1278 | mov bl,[esi+11] |
||
1279 | shl ebx,31 |
||
1280 | or eax,ebx |
||
1281 | mov [edi],eax |
||
1282 | xor eax,eax |
||
1283 | mov [edi+4],eax |
||
2665 | dunkaist | 1284 | add esi,13 |
1285 | ret |
||
1286 | get_string_value: |
||
1287 | inc esi |
||
1288 | lods dword [esi] |
||
1289 | mov ecx,eax |
||
2287 | heavyiron | 1290 | cmp ecx,8 |
1291 | ja value_out_of_range |
||
1292 | mov edx,edi |
||
1293 | xor eax,eax |
||
1294 | stos dword [edi] |
||
1295 | stos dword [edi] |
||
1296 | mov edi,edx |
||
1297 | rep movs byte [edi],[esi] |
||
2665 | dunkaist | 1298 | mov edi,edx |
1299 | inc esi |
||
1300 | and word [edi+8],0 |
||
1301 | and word [edi+12],0 |
||
1302 | ret |
||
1303 | |||
1304 | |||
1305 | mov [value_size],1 |
||
1306 | mov [size_override],-1 |
||
1307 | call calculate_value |
||
1308 | or al,al |
||
1309 | jz check_byte_value |
||
1310 | call recoverable_misuse |
||
1311 | check_byte_value: |
||
1312 | mov eax,[edi] |
||
1313 | mov edx,[edi+4] |
||
1314 | cmp byte [edi+13],0 |
||
1315 | je byte_positive |
||
1316 | cmp edx,-1 |
||
1317 | jne range_exceeded |
||
1318 | cmp eax,-80h |
||
1319 | jb range_exceeded |
||
1320 | ret |
||
1321 | byte_positive: |
||
1322 | test edx,edx |
||
1323 | jnz range_exceeded |
||
1324 | cmp eax,100h |
||
1325 | jae range_exceeded |
||
1326 | return_byte_value: |
||
1327 | ret |
||
2287 | heavyiron | 1328 | range_exceeded: |
2665 | dunkaist | 1329 | xor eax,eax |
1330 | xor edx,edx |
||
1331 | recoverable_overflow: |
||
1332 | cmp [error_line],0 |
||
1333 | jne ignore_overflow |
||
1334 | push [current_line] |
||
1335 | pop [error_line] |
||
1336 | mov [error],value_out_of_range |
||
1337 | or [value_undefined],-1 |
||
1338 | ignore_overflow: |
||
1339 | ret |
||
1340 | recoverable_misuse: |
||
1341 | cmp [error_line],0 |
||
1342 | jne ignore_misuse |
||
1343 | push [current_line] |
||
1344 | pop [error_line] |
||
1345 | mov [error],invalid_use_of_symbol |
||
1346 | ignore_misuse: |
||
1347 | ret |
||
1348 | get_word_value: |
||
1349 | mov [value_size],2 |
||
1350 | mov [size_override],-1 |
||
1351 | call calculate_value |
||
1352 | cmp al,2 |
||
1353 | jb check_word_value |
||
1354 | call recoverable_misuse |
||
1355 | check_word_value: |
||
1356 | mov eax,[edi] |
||
1357 | mov edx,[edi+4] |
||
1358 | cmp byte [edi+13],0 |
||
1359 | je word_positive |
||
1360 | cmp edx,-1 |
||
1361 | jne range_exceeded |
||
1362 | cmp eax,-8000h |
||
1363 | jb range_exceeded |
||
1364 | ret |
||
1365 | word_positive: |
||
1366 | test edx,edx |
||
1367 | jnz range_exceeded |
||
1368 | cmp eax,10000h |
||
1369 | jae range_exceeded |
||
1370 | ret |
||
1371 | get_dword_value: |
||
1372 | mov [value_size],4 |
||
1373 | mov [size_override],-1 |
||
1374 | call calculate_value |
||
1375 | cmp al,4 |
||
1376 | jne check_dword_value |
||
1377 | mov [value_type],2 |
||
1378 | mov eax,[edi] |
||
2287 | heavyiron | 1379 | cdq |
2665 | dunkaist | 1380 | cmp edx,[edi+4] |
1381 | jne range_exceeded |
||
1382 | mov ecx,edx |
||
1383 | shr ecx,31 |
||
1384 | cmp cl,[value_sign] |
||
1385 | jne range_exceeded |
||
1386 | ret |
||
1387 | check_dword_value: |
||
1388 | mov eax,[edi] |
||
1389 | mov edx,[edi+4] |
||
1390 | cmp byte [edi+13],0 |
||
1391 | je dword_positive |
||
1392 | cmp edx,-1 |
||
1393 | jne range_exceeded |
||
1394 | bt eax,31 |
||
1395 | jnc range_exceeded |
||
1396 | ret |
||
1397 | dword_positive: |
||
1398 | test edx,edx |
||
1399 | jne range_exceeded |
||
1400 | ret |
||
1401 | get_pword_value: |
||
1402 | mov [value_size],6 |
||
1403 | mov [size_override],-1 |
||
1404 | call calculate_value |
||
1405 | cmp al,4 |
||
1406 | jne check_pword_value |
||
1407 | call recoverable_misuse |
||
1408 | check_pword_value: |
||
1409 | mov eax,[edi] |
||
1410 | mov edx,[edi+4] |
||
1411 | cmp byte [edi+13],0 |
||
1412 | je pword_positive |
||
1413 | cmp edx,-8000h |
||
1414 | jb range_exceeded |
||
1415 | ret |
||
1416 | pword_positive: |
||
1417 | cmp edx,10000h |
||
1418 | jae range_exceeded |
||
1419 | ret |
||
1420 | get_qword_value: |
||
1421 | mov [value_size],8 |
||
1422 | mov [size_override],-1 |
||
1423 | call calculate_value |
||
1424 | check_qword_value: |
||
1425 | mov eax,[edi] |
||
1426 | mov edx,[edi+4] |
||
1427 | cmp byte [edi+13],0 |
||
1428 | je qword_positive |
||
1429 | cmp edx,-80000000h |
||
1430 | jb range_exceeded |
||
1431 | qword_positive: |
||
1432 | ret |
||
1433 | get_count_value: |
||
1434 | mov [value_size],8 |
||
1435 | mov [size_override],-1 |
||
1436 | call calculate_expression |
||
1437 | cmp word [edi+8],0 |
||
1438 | jne invalid_value |
||
1439 | mov [value_sign],0 |
||
1440 | mov al,[edi+12] |
||
1441 | or al,al |
||
1442 | jz check_count_value |
||
1443 | call recoverable_misuse |
||
1444 | check_count_value: |
||
1445 | cmp byte [edi+13],0 |
||
1446 | jne invalid_count_value |
||
1447 | mov eax,[edi] |
||
1448 | mov edx,[edi+4] |
||
1449 | or edx,edx |
||
1450 | jnz invalid_count_value |
||
2287 | heavyiron | 1451 | ret |
1452 | invalid_count_value: |
||
1453 | cmp [error_line],0 |
||
1454 | jne zero_count |
||
1455 | mov eax,[current_line] |
||
1456 | mov [error_line],eax |
||
1457 | mov [error],invalid_value |
||
1458 | zero_count: |
||
1459 | xor eax,eax |
||
1460 | ret |
||
1461 | get_value: |
||
1462 | mov [operand_size],0 |
||
1463 | lods byte [esi] |
||
1464 | call get_size_operator |
||
1465 | cmp al,'(' |
||
1466 | jne invalid_value |
||
1467 | mov al,[operand_size] |
||
1468 | cmp al,1 |
||
1469 | je value_byte |
||
1470 | cmp al,2 |
||
1471 | je value_word |
||
1472 | cmp al,4 |
||
1473 | je value_dword |
||
1474 | cmp al,6 |
||
1475 | je value_pword |
||
1476 | cmp al,8 |
||
1477 | je value_qword |
||
2665 | dunkaist | 1478 | or al,al |
1479 | jnz invalid_value |
||
1480 | mov [value_size],al |
||
1481 | call calculate_value |
||
1482 | mov eax,[edi] |
||
1483 | mov edx,[edi+4] |
||
1484 | ret |
||
1485 | calculate_value: |
||
1486 | call calculate_expression |
||
1487 | cmp word [edi+8],0 |
||
1488 | jne invalid_value |
||
1489 | mov eax,[edi+16] |
||
1490 | mov [symbol_identifier],eax |
||
1491 | mov al,[edi+13] |
||
1492 | mov [value_sign],al |
||
1493 | mov al,[edi+12] |
||
1494 | mov [value_type],al |
||
1495 | ret |
||
1496 | value_qword: |
||
1497 | call get_qword_value |
||
1498 | truncated_value: |
||
1499 | mov [value_sign],0 |
||
1500 | ret |
||
1501 | value_pword: |
||
1502 | call get_pword_value |
||
1503 | movzx edx,dx |
||
1504 | jmp truncated_value |
||
1505 | value_dword: |
||
1506 | call get_dword_value |
||
1507 | xor edx,edx |
||
1508 | jmp truncated_value |
||
1509 | value_word: |
||
1510 | call get_word_value |
||
1511 | xor edx,edx |
||
1512 | movzx eax,ax |
||
1513 | jmp truncated_value |
||
1514 | value_byte: |
||
1515 | call get_byte_value |
||
1516 | xor edx,edx |
||
1517 | movzx eax,al |
||
1518 | jmp truncated_value |
||
1519 | get_address_word_value: |
||
1520 | mov [address_size],2 |
||
1521 | mov [value_size],2 |
||
1522 | jmp calculate_address |
||
2287 | heavyiron | 1523 | get_address_dword_value: |
1524 | mov [address_size],4 |
||
1525 | mov [value_size],4 |
||
1526 | jmp calculate_address |
||
1527 | get_address_qword_value: |
||
1528 | mov [address_size],8 |
||
1529 | mov [value_size],8 |
||
1530 | jmp calculate_address |
||
1531 | get_address_value: |
||
1532 | mov [address_size],0 |
||
1533 | mov [value_size],8 |
||
1534 | calculate_address: |
||
1535 | cmp byte [esi],'.' |
||
1536 | je invalid_address |
||
1537 | call calculate_expression |
||
2665 | dunkaist | 1538 | mov eax,[edi+16] |
1539 | mov [address_symbol],eax |
||
1540 | mov al,[edi+13] |
||
1541 | mov [address_sign],al |
||
1542 | mov al,[edi+12] |
||
1543 | mov [value_type],al |
||
1544 | cmp al,6 |
||
1545 | je special_address_type_32bit |
||
2287 | heavyiron | 1546 | cmp al,5 |
1547 | je special_address_type_32bit |
||
1548 | ja invalid_use_of_symbol |
||
1549 | test al,1 |
||
1550 | jnz invalid_use_of_symbol |
||
1551 | or al,al |
||
1552 | jz address_size_ok |
||
1553 | shl al,5 |
||
1554 | jmp address_symbol_ok |
||
1555 | special_address_type_32bit: |
||
1556 | mov al,40h |
||
1557 | address_symbol_ok: |
||
1558 | mov ah,[address_size] |
||
1559 | or [address_size],al |
||
1560 | shr al,4 |
||
1561 | or ah,ah |
||
1562 | jz address_size_ok |
||
3010 | dunkaist | 1563 | cmp al,ah |
1564 | je address_size_ok |
||
2665 | dunkaist | 1565 | cmp ax,0408h |
3010 | dunkaist | 1566 | je address_sizes_mixed |
1567 | cmp ax,0804h |
||
1568 | jne address_sizes_do_not_agree |
||
1569 | address_sizes_mixed: |
||
1570 | mov [value_type],2 |
||
1571 | mov eax,[edi] |
||
1572 | cdq |
||
1573 | cmp edx,[edi+4] |
||
1574 | je address_size_ok |
||
1575 | cmp [error_line],0 |
||
2665 | dunkaist | 1576 | jne address_size_ok |
1577 | call recoverable_overflow |
||
1578 | address_size_ok: |
||
1579 | xor ebx,ebx |
||
1580 | xor ecx,ecx |
||
1581 | mov cl,[value_type] |
||
2287 | heavyiron | 1582 | shl ecx,16 |
1583 | mov ch,[address_size] |
||
1584 | cmp word [edi+8],0 |
||
1585 | je check_immediate_address |
||
1586 | mov al,[edi+8] |
||
1587 | mov dl,[edi+10] |
||
1588 | call get_address_register |
||
1589 | mov al,[edi+9] |
||
2665 | dunkaist | 1590 | mov dl,[edi+11] |
1591 | call get_address_register |
||
1592 | mov ax,bx |
||
1593 | shr ah,4 |
||
1594 | shr al,4 |
||
1595 | cmp ah,0Ch |
||
1596 | je check_vsib_address |
||
1597 | cmp ah,0Dh |
||
1598 | je check_vsib_address |
||
1599 | cmp al,0Ch |
||
1600 | je check_vsib_address |
||
1601 | cmp al,0Dh |
||
1602 | je check_vsib_address |
||
1603 | or bh,bh |
||
1604 | jz check_address_registers |
||
1605 | or bl,bl |
||
1606 | jz check_address_registers |
||
2287 | heavyiron | 1607 | cmp al,ah |
1608 | jne invalid_address |
||
1609 | check_address_registers: |
||
1610 | or al,ah |
||
1611 | mov ah,[address_size] |
||
1612 | and ah,0Fh |
||
1613 | jz address_registers_sizes_ok |
||
1614 | cmp al,ah |
||
1615 | jne address_sizes_do_not_match |
||
1616 | address_registers_sizes_ok: |
||
1617 | cmp al,4 |
||
1618 | je sib_allowed |
||
1619 | cmp al,8 |
||
1620 | je sib_allowed |
||
1621 | cmp al,0Fh |
||
1622 | je check_ip_relative_address |
||
1623 | or cl,cl |
||
1624 | jz check_word_value |
||
1625 | cmp cl,1 |
||
1626 | je check_word_value |
||
1627 | jmp invalid_address |
||
1628 | address_sizes_do_not_match: |
||
1629 | cmp al,0Fh |
||
1630 | jne invalid_address |
||
1631 | mov al,bh |
||
1632 | and al,0Fh |
||
1633 | cmp al,ah |
||
2665 | dunkaist | 1634 | jne invalid_address |
1635 | check_ip_relative_address: |
||
1636 | or bl,bl |
||
1637 | jnz invalid_address |
||
1638 | cmp bh,0F4h |
||
1639 | je check_dword_value |
||
1640 | cmp bh,0F8h |
||
1641 | jne invalid_address |
||
2287 | heavyiron | 1642 | mov eax,[edi] |
1643 | cdq |
||
2665 | dunkaist | 1644 | cmp edx,[edi+4] |
1645 | jne range_exceeded |
||
1646 | cmp dl,[edi+13] |
||
1647 | jne range_exceeded |
||
1648 | ret |
||
1649 | get_address_register: |
||
1650 | or al,al |
||
1651 | jz address_register_ok |
||
2287 | heavyiron | 1652 | cmp dl,1 |
1653 | jne scaled_register |
||
1654 | or bh,bh |
||
1655 | jnz scaled_register |
||
1656 | mov bh,al |
||
1657 | address_register_ok: |
||
1658 | ret |
||
1659 | scaled_register: |
||
1660 | or bl,bl |
||
1661 | jnz invalid_address |
||
1662 | mov bl,al |
||
1663 | mov cl,dl |
||
1664 | jmp address_register_ok |
||
1665 | sib_allowed: |
||
1666 | or bh,bh |
||
1667 | jnz check_index_with_base |
||
1668 | cmp cl,3 |
||
1669 | je special_index_scale |
||
1670 | cmp cl,5 |
||
1671 | je special_index_scale |
||
1672 | cmp cl,9 |
||
1673 | je special_index_scale |
||
1674 | cmp cl,2 |
||
1675 | jne check_index_scale |
||
1676 | cmp bl,45h |
||
1677 | jne special_index_scale |
||
1678 | cmp [code_type],64 |
||
1679 | je special_index_scale |
||
1680 | cmp [segment_register],4 |
||
1681 | jne special_index_scale |
||
1682 | cmp [value_type],0 |
||
1683 | jne check_index_scale |
||
1684 | mov al,[edi] |
||
1685 | cbw |
||
1686 | cwde |
||
1687 | cmp eax,[edi] |
||
1688 | jne check_index_scale |
||
1689 | cdq |
||
1690 | cmp edx,[edi+4] |
||
1691 | jne check_immediate_address |
||
1692 | special_index_scale: |
||
1693 | mov bh,bl |
||
1694 | dec cl |
||
1695 | check_immediate_address: |
||
1696 | mov al,[address_size] |
||
1697 | and al,0Fh |
||
1698 | cmp al,2 |
||
1699 | je check_word_value |
||
1700 | cmp al,4 |
||
1701 | je check_dword_value |
||
1702 | cmp al,8 |
||
1703 | je check_qword_value |
||
1704 | or al,al |
||
1705 | jnz invalid_value |
||
1706 | cmp [code_type],64 |
||
1707 | jne check_dword_value |
||
1708 | jmp check_qword_value |
||
1709 | check_index_with_base: |
||
1710 | cmp cl,1 |
||
1711 | jne check_index_scale |
||
1712 | cmp bl,44h |
||
1713 | je swap_base_with_index |
||
1714 | cmp bl,84h |
||
1715 | je swap_base_with_index |
||
1716 | cmp [code_type],64 |
||
1717 | je check_for_rbp_base |
||
1718 | cmp bl,45h |
||
1719 | jne check_for_ebp_base |
||
1720 | cmp [segment_register],3 |
||
1721 | je swap_base_with_index |
||
1722 | jmp check_immediate_address |
||
1723 | check_for_ebp_base: |
||
1724 | cmp bh,45h |
||
1725 | jne check_immediate_address |
||
1726 | cmp [segment_register],4 |
||
1727 | jne check_immediate_address |
||
1728 | swap_base_with_index: |
||
1729 | xchg bl,bh |
||
1730 | jmp check_immediate_address |
||
1731 | check_for_rbp_base: |
||
1732 | cmp bh,45h |
||
1733 | je swap_base_with_index |
||
1734 | cmp bh,85h |
||
1735 | je swap_base_with_index |
||
1736 | jmp check_immediate_address |
||
1737 | check_index_scale: |
||
1738 | test cl,not 1111b |
||
1739 | jnz invalid_address |
||
1740 | mov al,cl |
||
1741 | dec al |
||
1742 | and al,cl |
||
2665 | dunkaist | 1743 | jz check_immediate_address |
1744 | jmp invalid_address |
||
1745 | check_vsib_address: |
||
1746 | cmp ah,0Ch |
||
1747 | je swap_vsib_registers |
||
1748 | cmp ah,0Dh |
||
1749 | jne check_vsib_base |
||
1750 | swap_vsib_registers: |
||
1751 | cmp cl,1 |
||
1752 | ja invalid_address |
||
1753 | xchg bl,bh |
||
1754 | mov cl,1 |
||
1755 | check_vsib_base: |
||
1756 | test bh,bh |
||
1757 | jz vsib_base_ok |
||
1758 | mov al,bh |
||
1759 | shr al,4 |
||
1760 | cmp al,4 |
||
1761 | je vsib_base_ok |
||
1762 | cmp [code_type],64 |
||
1763 | jne invalid_address |
||
1764 | cmp al,8 |
||
1765 | jne invalid_address |
||
1766 | vsib_base_ok: |
||
1767 | mov al,bl |
||
1768 | shr al,4 |
||
1769 | cmp al,0Ch |
||
1770 | je check_index_scale |
||
1771 | cmp al,0Dh |
||
1772 | je check_index_scale |
||
1773 | jmp invalid_address |
||
1774 | |||
1775 | |||
1776 | cmp [value_undefined],0 |
||
1777 | jne relative_offset_ok |
||
1778 | test bh,bh |
||
2287 | heavyiron | 1779 | setne ch |
1780 | cmp bx,word [org_registers] |
||
1781 | je origin_registers_ok |
||
1782 | xchg bh,bl |
||
1783 | xchg ch,cl |
||
1784 | cmp bx,word [org_registers] |
||
1785 | jne invalid_value |
||
1786 | origin_registers_ok: |
||
2665 | dunkaist | 1787 | cmp cx,word [org_registers+2] |
1788 | jne invalid_value |
||
1789 | mov bl,[address_sign] |
||
1790 | add eax,dword [org_origin] |
||
1791 | adc edx,dword [org_origin+4] |
||
1792 | adc bl,[org_origin_sign] |
||
1793 | sub eax,edi |
||
1794 | sbb edx,0 |
||
1795 | sbb bl,0 |
||
1796 | mov [value_sign],bl |
||
1797 | mov bl,[value_type] |
||
1798 | mov ecx,[address_symbol] |
||
1799 | mov [symbol_identifier],ecx |
||
1800 | test bl,1 |
||
1801 | jnz relative_offset_unallowed |
||
1802 | cmp bl,6 |
||
1803 | je plt_relative_offset |
||
1804 | mov bh,[labels_type] |
||
3010 | dunkaist | 1805 | cmp bl,bh |
1806 | je set_relative_offset_type |
||
2665 | dunkaist | 1807 | cmp bx,0402h |
3010 | dunkaist | 1808 | je set_relative_offset_type |
1809 | relative_offset_unallowed: |
||
2665 | dunkaist | 1810 | call recoverable_misuse |
1811 | set_relative_offset_type: |
||
1812 | cmp [value_type],0 |
||
1813 | je relative_offset_ok |
||
1814 | mov [value_type],0 |
||
1815 | cmp ecx,[org_symbol] |
||
1816 | je relative_offset_ok |
||
1817 | mov [value_type],3 |
||
2287 | heavyiron | 1818 | relative_offset_ok: |
1819 | ret |
||
2665 | dunkaist | 1820 | plt_relative_offset: |
1821 | mov [value_type],7 |
||
1822 | cmp [labels_type],2 |
||
1823 | je relative_offset_ok |
||
1824 | cmp [labels_type],4 |
||
1825 | jne recoverable_misuse |
||
1826 | ret |
||
1827 | |||
1828 | |||
1829 | xor al,al |
||
2287 | heavyiron | 1830 | calculate_embedded_logical_expression: |
1831 | mov [logical_value_wrapping],al |
||
1832 | call get_logical_value |
||
1833 | logical_loop: |
||
1834 | cmp byte [esi],'|' |
||
1835 | je logical_or |
||
1836 | cmp byte [esi],'&' |
||
1837 | je logical_and |
||
1838 | ret |
||
1839 | logical_or: |
||
1840 | inc esi |
||
1841 | or al,al |
||
1842 | jnz logical_value_already_determined |
||
1843 | push eax |
||
1844 | call get_logical_value |
||
1845 | pop ebx |
||
1846 | or al,bl |
||
1847 | jmp logical_loop |
||
1848 | logical_and: |
||
1849 | inc esi |
||
1850 | or al,al |
||
1851 | jz logical_value_already_determined |
||
1852 | push eax |
||
1853 | call get_logical_value |
||
1854 | pop ebx |
||
1855 | and al,bl |
||
1856 | jmp logical_loop |
||
1857 | logical_value_already_determined: |
||
1858 | push eax |
||
1859 | call skip_logical_value |
||
1860 | jc invalid_expression |
||
2665 | dunkaist | 1861 | pop eax |
1862 | jmp logical_loop |
||
1863 | get_value_for_comparison: |
||
1864 | mov [value_size],8 |
||
1865 | mov [size_override],-1 |
||
1866 | lods byte [esi] |
||
1867 | call calculate_expression |
||
1868 | cmp byte [edi+8],0 |
||
1869 | jne first_register_size_ok |
||
1870 | mov byte [edi+10],0 |
||
1871 | first_register_size_ok: |
||
1872 | cmp byte [edi+9],0 |
||
1873 | jne second_register_size_ok |
||
1874 | mov byte [edi+11],0 |
||
1875 | second_register_size_ok: |
||
1876 | mov eax,[edi+16] |
||
1877 | mov [symbol_identifier],eax |
||
1878 | mov al,[edi+13] |
||
1879 | mov [value_sign],al |
||
1880 | mov bl,[edi+12] |
||
1881 | mov eax,[edi] |
||
1882 | mov edx,[edi+4] |
||
1883 | mov ecx,[edi+8] |
||
1884 | ret |
||
1885 | get_logical_value: |
||
1886 | xor al,al |
||
1887 | check_for_negation: |
||
1888 | cmp byte [esi],'~' |
||
2287 | heavyiron | 1889 | jne negation_ok |
1890 | inc esi |
||
1891 | xor al,-1 |
||
1892 | jmp check_for_negation |
||
1893 | negation_ok: |
||
1894 | push eax |
||
1895 | mov al,[esi] |
||
1896 | cmp al,'{' |
||
1897 | je logical_expression |
||
1898 | cmp al,0FFh |
||
1899 | je invalid_expression |
||
1900 | cmp al,88h |
||
1901 | je check_for_defined |
||
1902 | cmp al,89h |
||
1903 | je check_for_used |
||
1904 | cmp al,'0' |
||
1905 | je given_false |
||
2665 | dunkaist | 1906 | cmp al,'1' |
1907 | je given_true |
||
1908 | call get_value_for_comparison |
||
1909 | mov bh,[value_sign] |
||
1910 | push eax edx [symbol_identifier] ebx ecx |
||
1911 | mov al,[esi] |
||
1912 | or al,al |
||
1913 | jz logical_number |
||
1914 | cmp al,0Fh |
||
2287 | heavyiron | 1915 | je logical_number |
1916 | cmp al,'}' |
||
1917 | je logical_number |
||
1918 | cmp al,'&' |
||
1919 | je logical_number |
||
1920 | cmp al,'|' |
||
1921 | je logical_number |
||
2665 | dunkaist | 1922 | inc esi |
1923 | mov [compare_type],al |
||
1924 | call get_value_for_comparison |
||
1925 | cmp bl,[esp+4] |
||
1926 | jne values_not_relative |
||
1927 | or bl,bl |
||
1928 | jz check_values_registers |
||
1929 | mov ebx,[symbol_identifier] |
||
1930 | cmp ebx,[esp+8] |
||
1931 | jne values_not_relative |
||
1932 | check_values_registers: |
||
1933 | cmp ecx,[esp] |
||
1934 | je values_relative |
||
1935 | ror ecx,16 |
||
1936 | xchg ch,cl |
||
1937 | ror ecx,16 |
||
1938 | xchg ch,cl |
||
1939 | cmp ecx,[esp] |
||
1940 | je values_relative |
||
1941 | values_not_relative: |
||
1942 | cmp [compare_type],0F8h |
||
1943 | jne invalid_comparison |
||
1944 | add esp,12+8 |
||
1945 | jmp return_false |
||
1946 | invalid_comparison: |
||
1947 | call recoverable_misuse |
||
1948 | values_relative: |
||
1949 | pop ebx |
||
1950 | shl ebx,16 |
||
1951 | mov bx,[esp] |
||
1952 | add esp,8 |
||
1953 | pop ecx ebp |
||
1954 | cmp [compare_type],'=' |
||
1955 | je check_equal |
||
1956 | cmp [compare_type],0F1h |
||
1957 | je check_not_equal |
||
1958 | cmp [compare_type],0F8h |
||
1959 | je return_true |
||
1960 | test ebx,0FFFF0000h |
||
1961 | jz check_less_or_greater |
||
1962 | call recoverable_misuse |
||
1963 | check_less_or_greater: |
||
1964 | cmp [compare_type],'>' |
||
1965 | je check_greater |
||
1966 | cmp [compare_type],'<' |
||
1967 | je check_less |
||
1968 | cmp [compare_type],0F2h |
||
1969 | je check_not_less |
||
1970 | cmp [compare_type],0F3h |
||
1971 | je check_not_greater |
||
1972 | jmp invalid_expression |
||
1973 | check_equal: |
||
1974 | cmp bh,[value_sign] |
||
1975 | jne return_false |
||
1976 | cmp eax,ebp |
||
1977 | jne return_false |
||
1978 | cmp edx,ecx |
||
1979 | jne return_false |
||
1980 | jmp return_true |
||
1981 | check_greater: |
||
1982 | cmp bh,[value_sign] |
||
1983 | jg return_true |
||
1984 | jl return_false |
||
1985 | cmp edx,ecx |
||
1986 | jb return_true |
||
1987 | ja return_false |
||
1988 | cmp eax,ebp |
||
1989 | jb return_true |
||
1990 | jae return_false |
||
1991 | check_less: |
||
1992 | cmp bh,[value_sign] |
||
1993 | jg return_false |
||
1994 | jl return_true |
||
1995 | cmp edx,ecx |
||
1996 | jb return_false |
||
1997 | ja return_true |
||
1998 | cmp eax,ebp |
||
1999 | jbe return_false |
||
2000 | ja return_true |
||
2001 | check_not_less: |
||
2002 | cmp bh,[value_sign] |
||
2003 | jg return_true |
||
2004 | jl return_false |
||
2005 | cmp edx,ecx |
||
2006 | jb return_true |
||
2007 | ja return_false |
||
2008 | cmp eax,ebp |
||
2009 | jbe return_true |
||
2010 | ja return_false |
||
2011 | check_not_greater: |
||
2012 | cmp bh,[value_sign] |
||
2013 | jg return_false |
||
2014 | jl return_true |
||
2015 | cmp edx,ecx |
||
2016 | jb return_false |
||
2017 | ja return_true |
||
2018 | cmp eax,ebp |
||
2019 | jb return_false |
||
2020 | jae return_true |
||
2021 | check_not_equal: |
||
2022 | cmp bh,[value_sign] |
||
2023 | jne return_true |
||
2024 | cmp eax,ebp |
||
2025 | jne return_true |
||
2026 | cmp edx,ecx |
||
2027 | jne return_true |
||
2028 | jmp return_false |
||
2029 | logical_number: |
||
2030 | pop ecx ebx eax edx eax |
||
2031 | or bl,bl |
||
2032 | jnz invalid_logical_number |
||
2033 | or cx,cx |
||
2034 | jz logical_number_ok |
||
2035 | invalid_logical_number: |
||
2036 | call recoverable_misuse |
||
2037 | logical_number_ok: |
||
2038 | test bh,bh |
||
2039 | jnz return_true |
||
2040 | or eax,edx |
||
2041 | jnz return_true |
||
2042 | jmp return_false |
||
2043 | check_for_defined: |
||
2287 | heavyiron | 2044 | or bl,-1 |
2045 | lods word [esi] |
||
2046 | cmp ah,'(' |
||
2047 | jne invalid_expression |
||
2048 | check_expression: |
||
2049 | lods byte [esi] |
||
2050 | or al,al |
||
2051 | jz defined_string |
||
2052 | cmp al,'.' |
||
2053 | je defined_fp_value |
||
2054 | cmp al,')' |
||
2055 | je expression_checked |
||
2056 | cmp al,'!' |
||
2057 | je invalid_expression |
||
2058 | cmp al,0Fh |
||
2059 | je check_expression |
||
2060 | cmp al,10h |
||
2061 | je defined_register |
||
2062 | cmp al,11h |
||
2063 | je check_if_symbol_defined |
||
2064 | cmp al,80h |
||
2065 | jae check_expression |
||
2066 | movzx eax,al |
||
2067 | add esi,eax |
||
2068 | jmp check_expression |
||
2069 | defined_register: |
||
2070 | inc esi |
||
2071 | jmp check_expression |
||
2072 | defined_fp_value: |
||
2073 | add esi,12 |
||
2074 | jmp expression_checked |
||
2075 | defined_string: |
||
2076 | lods dword [esi] |
||
2077 | add esi,eax |
||
2078 | inc esi |
||
2079 | jmp expression_checked |
||
2080 | check_if_symbol_defined: |
||
2081 | lods dword [esi] |
||
2082 | cmp eax,-1 |
||
2083 | je invalid_expression |
||
2084 | cmp eax,0Fh |
||
2085 | jb check_expression |
||
2086 | je reserved_word_used_as_symbol |
||
2087 | test byte [eax+8],4 |
||
2088 | jnz no_prediction |
||
2089 | test byte [eax+8],1 |
||
2090 | jz symbol_predicted_undefined |
||
2091 | mov cx,[current_pass] |
||
2092 | sub cx,[eax+16] |
||
2093 | jz check_expression |
||
2094 | cmp cx,1 |
||
2095 | ja symbol_predicted_undefined |
||
2096 | or byte [eax+8],40h+80h |
||
2097 | jmp check_expression |
||
2098 | no_prediction: |
||
2099 | test byte [eax+8],1 |
||
2100 | jz symbol_undefined |
||
2101 | mov cx,[current_pass] |
||
2102 | sub cx,[eax+16] |
||
2103 | jz check_expression |
||
2104 | jmp symbol_undefined |
||
2105 | symbol_predicted_undefined: |
||
2106 | or byte [eax+8],40h |
||
2107 | and byte [eax+8],not 80h |
||
2108 | symbol_undefined: |
||
2109 | xor bl,bl |
||
2110 | jmp check_expression |
||
2111 | expression_checked: |
||
2112 | mov al,bl |
||
2113 | jmp logical_value_ok |
||
2114 | check_for_used: |
||
2115 | lods word [esi] |
||
2116 | cmp ah,2 |
||
2117 | jne invalid_expression |
||
2118 | lods dword [esi] |
||
2119 | cmp eax,0Fh |
||
2120 | jb invalid_use_of_symbol |
||
2121 | je reserved_word_used_as_symbol |
||
2122 | inc esi |
||
2123 | test byte [eax+8],8 |
||
2124 | jz not_used |
||
2125 | mov cx,[current_pass] |
||
2126 | sub cx,[eax+18] |
||
2127 | jz return_true |
||
2128 | cmp cx,1 |
||
2129 | ja not_used |
||
2130 | or byte [eax+8],10h+20h |
||
2131 | jmp return_true |
||
2132 | not_used: |
||
2133 | or byte [eax+8],10h |
||
2134 | and byte [eax+8],not 20h |
||
2135 | jmp return_false |
||
2136 | given_false: |
||
2137 | inc esi |
||
2138 | return_false: |
||
2139 | xor al,al |
||
2140 | jmp logical_value_ok |
||
2141 | given_true: |
||
2142 | inc esi |
||
2143 | return_true: |
||
2144 | or al,-1 |
||
2145 | jmp logical_value_ok |
||
2146 | logical_expression: |
||
2147 | lods byte [esi] |
||
2148 | mov dl,[logical_value_wrapping] |
||
2149 | push edx |
||
2150 | call calculate_embedded_logical_expression |
||
2151 | pop edx |
||
2152 | mov [logical_value_wrapping],dl |
||
2153 | push eax |
||
2154 | lods byte [esi] |
||
2155 | cmp al,'}' |
||
2156 | jne invalid_expression |
||
2157 | pop eax |
||
2158 | logical_value_ok: |
||
2159 | pop ebx |
||
2160 | xor al,bl |
||
2161 | ret |
||
2162 | |||
2163 | |||
2164 | lods byte [esi] |
||
2165 | or al,al |
||
2166 | jz nothing_to_skip |
||
2167 | cmp al,0Fh |
||
2168 | je nothing_to_skip |
||
2169 | cmp al,1 |
||
2170 | je skip_instruction |
||
2171 | cmp al,2 |
||
2172 | je skip_label |
||
2173 | cmp al,3 |
||
2174 | je skip_label |
||
2175 | cmp al,20h |
||
2176 | jb skip_assembler_symbol |
||
2177 | cmp al,'(' |
||
2178 | je skip_expression |
||
2179 | cmp al,'[' |
||
2180 | je skip_address |
||
2181 | skip_done: |
||
2182 | clc |
||
2183 | ret |
||
2184 | skip_label: |
||
2185 | add esi,2 |
||
2186 | skip_instruction: |
||
2187 | add esi,2 |
||
2188 | skip_assembler_symbol: |
||
2189 | inc esi |
||
2190 | jmp skip_done |
||
2191 | skip_address: |
||
2192 | mov al,[esi] |
||
2193 | and al,11110000b |
||
2194 | cmp al,60h |
||
2195 | jb skip_expression |
||
2196 | cmp al,70h |
||
2197 | ja skip_expression |
||
2198 | inc esi |
||
2199 | jmp skip_address |
||
2200 | skip_expression: |
||
2201 | lods byte [esi] |
||
2202 | or al,al |
||
2203 | jz skip_string |
||
2204 | cmp al,'.' |
||
2205 | je skip_fp_value |
||
2206 | cmp al,')' |
||
2207 | je skip_done |
||
2208 | cmp al,']' |
||
2209 | je skip_done |
||
2210 | cmp al,'!' |
||
2211 | je skip_expression |
||
2212 | cmp al,0Fh |
||
2213 | je skip_expression |
||
2214 | cmp al,10h |
||
2215 | je skip_register |
||
2216 | cmp al,11h |
||
2217 | je skip_label_value |
||
2218 | cmp al,80h |
||
2219 | jae skip_expression |
||
2220 | movzx eax,al |
||
2221 | add esi,eax |
||
2222 | jmp skip_expression |
||
2223 | skip_label_value: |
||
2224 | add esi,3 |
||
2225 | skip_register: |
||
2226 | inc esi |
||
2227 | jmp skip_expression |
||
2228 | skip_fp_value: |
||
2229 | add esi,12 |
||
2230 | jmp skip_done |
||
2231 | skip_string: |
||
2232 | lods dword [esi] |
||
2233 | add esi,eax |
||
2234 | inc esi |
||
2235 | jmp skip_done |
||
2236 | nothing_to_skip: |
||
2237 | dec esi |
||
2665 | dunkaist | 2238 | stc |
2239 | ret |
||
2240 | |||
2241 | |||
2242 | lods byte [esi] |
||
2243 | cmp al,'%' |
||
2244 | je environment_variable |
||
2245 | stos byte [edi] |
||
2246 | or al,al |
||
2247 | jnz expand_path |
||
2248 | cmp edi,[memory_end] |
||
2249 | ja out_of_memory |
||
2250 | ret |
||
2251 | environment_variable: |
||
2252 | mov ebx,esi |
||
2253 | find_variable_end: |
||
2254 | lods byte [esi] |
||
2255 | or al,al |
||
2256 | jz not_environment_variable |
||
2257 | cmp al,'%' |
||
2258 | jne find_variable_end |
||
2259 | mov byte [esi-1],0 |
||
2260 | push esi |
||
2261 | mov esi,ebx |
||
2262 | call get_environment_variable |
||
2263 | pop esi |
||
2264 | mov byte [esi-1],'%' |
||
2265 | jmp expand_path |
||
2266 | not_environment_variable: |
||
2267 | mov al,'%' |
||
2268 | stos byte [edi] |
||
2269 | mov esi,ebx |
||
2270 | jmp expand_path |
||
2271 | get_include_directory: |
||
2272 | lods byte [esi] |
||
2273 | cmp al,';' |
||
2274 | je include_directory_ok |
||
2275 | stos byte [edi] |
||
2276 | or al,al |
||
2277 | jnz get_include_directory |
||
2278 | dec esi |
||
2279 | dec edi |
||
2280 | include_directory_ok: |
||
2281 | cmp byte [edi-1],'/' |
||
2282 | je path_separator_ok |
||
2283 | cmp byte [edi-1],'\' |
||
2284 | je path_separator_ok |
||
2285 | mov al,'/' |
||
2286 | stos byte [edi] |
||
2287 | path_separator_ok: |
||
2288 | ret' |
||
2289 | > |