Rev 7836 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7836 | leency | 1 | |
2 | ; Copyright (c) 1999-2021, Tomasz Grysztar. |
||
9459 | leency | 3 | ; All rights reserved. |
7836 | leency | 4 | |
5 | |||
6 | mov edi,characters |
||
7 | xor al,al |
||
8 | make_characters_table: |
||
9 | stosb |
||
10 | inc al |
||
11 | jnz make_characters_table |
||
12 | mov esi,characters+'a' |
||
13 | mov edi,characters+'A' |
||
14 | mov ecx,26 |
||
15 | rep movsb |
||
16 | mov edi,characters |
||
17 | mov esi,symbol_characters+1 |
||
18 | movzx ecx,byte [esi-1] |
||
19 | xor eax,eax |
||
20 | mark_symbol_characters: |
||
21 | lodsb |
||
22 | mov byte [edi+eax],0 |
||
23 | loop mark_symbol_characters |
||
24 | mov edi,locals_counter |
||
25 | mov ax,1 + '0' shl 8 |
||
26 | stos word [edi] |
||
27 | mov edi,[memory_start] |
||
28 | mov [include_paths],edi |
||
29 | mov esi,include_variable |
||
30 | call get_environment_variable |
||
31 | xor al,al |
||
32 | stos byte [edi] |
||
33 | mov [memory_start],edi |
||
34 | mov eax,[additional_memory] |
||
35 | mov [free_additional_memory],eax |
||
36 | mov eax,[additional_memory_end] |
||
37 | mov [labels_list],eax |
||
38 | xor eax,eax |
||
39 | mov [source_start],eax |
||
40 | mov [tagged_blocks],eax |
||
41 | mov [hash_tree],eax |
||
42 | mov [error],eax |
||
43 | mov [macro_status],al |
||
44 | mov [current_line],eax |
||
45 | mov esi,[initial_definitions] |
||
46 | test esi,esi |
||
47 | jz predefinitions_ok |
||
48 | process_predefinitions: |
||
49 | movzx ecx,byte [esi] |
||
50 | test ecx,ecx |
||
51 | jz predefinitions_ok |
||
52 | inc esi |
||
53 | lea eax,[esi+ecx] |
||
54 | push eax |
||
55 | mov ch,10b |
||
56 | call add_preprocessor_symbol |
||
57 | pop esi |
||
58 | mov edi,[memory_start] |
||
59 | mov [edx+8],edi |
||
60 | convert_predefinition: |
||
61 | cmp edi,[memory_end] |
||
62 | jae out_of_memory |
||
63 | lods byte [esi] |
||
64 | or al,al |
||
65 | jz predefinition_converted |
||
66 | cmp al,20h |
||
67 | je convert_predefinition |
||
68 | mov ah,al |
||
69 | mov ebx,characters |
||
70 | xlat byte [ebx] |
||
71 | or al,al |
||
72 | jz predefinition_separator |
||
73 | cmp ah,27h |
||
74 | je predefinition_string |
||
75 | cmp ah,22h |
||
76 | je predefinition_string |
||
77 | mov byte [edi],1Ah |
||
78 | scas word [edi] |
||
79 | xchg al,ah |
||
80 | stos byte [edi] |
||
81 | mov ebx,characters |
||
82 | xor ecx,ecx |
||
83 | predefinition_symbol: |
||
84 | lods byte [esi] |
||
85 | stos byte [edi] |
||
86 | xlat byte [ebx] |
||
87 | or al,al |
||
88 | loopnzd predefinition_symbol |
||
89 | neg ecx |
||
90 | cmp ecx,255 |
||
91 | ja invalid_definition |
||
92 | mov ebx,edi |
||
93 | sub ebx,ecx |
||
94 | mov byte [ebx-2],cl |
||
95 | found_predefinition_separator: |
||
96 | dec edi |
||
97 | mov ah,[esi-1] |
||
98 | predefinition_separator: |
||
99 | xchg al,ah |
||
100 | or al,al |
||
101 | jz predefinition_converted |
||
102 | cmp al,20h |
||
103 | je convert_predefinition |
||
104 | cmp al,3Bh |
||
105 | je invalid_definition |
||
106 | cmp al,5Ch |
||
107 | je predefinition_backslash |
||
108 | stos byte [edi] |
||
109 | jmp convert_predefinition |
||
110 | predefinition_string: |
||
111 | mov al,22h |
||
112 | stos byte [edi] |
||
113 | scas dword [edi] |
||
114 | mov ebx,edi |
||
115 | copy_predefinition_string: |
||
116 | lods byte [esi] |
||
117 | stos byte [edi] |
||
118 | or al,al |
||
119 | jz invalid_definition |
||
120 | cmp al,ah |
||
121 | jne copy_predefinition_string |
||
122 | lods byte [esi] |
||
123 | cmp al,ah |
||
124 | je copy_predefinition_string |
||
125 | dec esi |
||
126 | dec edi |
||
127 | mov eax,edi |
||
128 | sub eax,ebx |
||
129 | mov [ebx-4],eax |
||
130 | jmp convert_predefinition |
||
131 | predefinition_backslash: |
||
132 | mov byte [edi],0 |
||
133 | lods byte [esi] |
||
134 | or al,al |
||
135 | jz invalid_definition |
||
136 | cmp al,20h |
||
137 | je invalid_definition |
||
138 | cmp al,3Bh |
||
139 | je invalid_definition |
||
140 | mov al,1Ah |
||
141 | stos byte [edi] |
||
142 | mov ecx,edi |
||
143 | mov ax,5C01h |
||
144 | stos word [edi] |
||
145 | dec esi |
||
146 | group_predefinition_backslashes: |
||
147 | lods byte [esi] |
||
148 | cmp al,5Ch |
||
149 | jne predefinition_backslashed_symbol |
||
150 | stos byte [edi] |
||
151 | inc byte [ecx] |
||
152 | jmp group_predefinition_backslashes |
||
153 | predefinition_backslashed_symbol: |
||
154 | cmp al,20h |
||
155 | je invalid_definition |
||
156 | cmp al,22h |
||
157 | je invalid_definition |
||
158 | cmp al,27h |
||
159 | je invalid_definition |
||
160 | cmp al,3Bh |
||
161 | je invalid_definition |
||
162 | mov ah,al |
||
163 | mov ebx,characters |
||
164 | xlat byte [ebx] |
||
165 | or al,al |
||
166 | jz predefinition_backslashed_symbol_character |
||
167 | mov al,ah |
||
168 | convert_predefinition_backslashed_symbol: |
||
169 | stos byte [edi] |
||
170 | xlat byte [ebx] |
||
171 | or al,al |
||
172 | jz found_predefinition_separator |
||
173 | inc byte [ecx] |
||
174 | jz invalid_definition |
||
175 | lods byte [esi] |
||
176 | jmp convert_predefinition_backslashed_symbol |
||
177 | predefinition_backslashed_symbol_character: |
||
178 | mov al,ah |
||
179 | stos byte [edi] |
||
180 | inc byte [ecx] |
||
181 | jmp convert_predefinition |
||
182 | predefinition_converted: |
||
183 | mov [memory_start],edi |
||
184 | sub edi,[edx+8] |
||
185 | mov [edx+12],edi |
||
186 | jmp process_predefinitions |
||
187 | predefinitions_ok: |
||
188 | mov esi,[input_file] |
||
189 | mov edx,esi |
||
190 | call open |
||
191 | jc main_file_not_found |
||
192 | mov edi,[memory_start] |
||
193 | call preprocess_file |
||
194 | cmp [macro_status],0 |
||
195 | je process_postponed |
||
196 | mov eax,[error_line] |
||
197 | mov [current_line],eax |
||
198 | jmp incomplete_macro |
||
199 | process_postponed: |
||
200 | mov edx,hash_tree |
||
201 | mov ecx,32 |
||
202 | find_postponed_list: |
||
203 | mov edx,[edx] |
||
204 | or edx,edx |
||
205 | loopnz find_postponed_list |
||
206 | jz preprocessing_finished |
||
207 | process_postponed_list: |
||
208 | mov eax,[edx] |
||
209 | or eax,eax |
||
210 | jz preprocessing_finished |
||
211 | push edx |
||
212 | mov ebx,edx |
||
213 | find_earliest_postponed: |
||
214 | mov eax,[edx] |
||
215 | or eax,eax |
||
216 | jz earliest_postponed_found |
||
217 | mov ebx,edx |
||
218 | mov edx,eax |
||
219 | jmp find_earliest_postponed |
||
220 | earliest_postponed_found: |
||
221 | mov [ebx],eax |
||
222 | call use_postponed_macro |
||
223 | pop edx |
||
224 | cmp [macro_status],0 |
||
225 | je process_postponed_list |
||
226 | mov eax,[error_line] |
||
227 | mov [current_line],eax |
||
228 | jmp incomplete_macro |
||
229 | preprocessing_finished: |
||
230 | mov [source_start],edi |
||
231 | ret |
||
232 | use_postponed_macro: |
||
233 | lea esi,[edi-1] |
||
234 | push ecx esi |
||
235 | mov [struc_name],0 |
||
236 | jmp use_macro |
||
237 | |||
238 | |||
239 | push [memory_end] |
||
240 | push esi |
||
241 | mov al,2 |
||
242 | xor edx,edx |
||
243 | call lseek |
||
244 | push eax |
||
245 | xor al,al |
||
246 | xor edx,edx |
||
247 | call lseek |
||
248 | pop ecx |
||
249 | mov edx,[memory_end] |
||
250 | dec edx |
||
251 | mov byte [edx],1Ah |
||
252 | sub edx,ecx |
||
253 | jc out_of_memory |
||
254 | mov esi,edx |
||
255 | cmp edx,edi |
||
256 | jbe out_of_memory |
||
257 | mov [memory_end],edx |
||
258 | call read |
||
259 | call close |
||
260 | pop edx |
||
261 | xor ecx,ecx |
||
262 | mov ebx,esi |
||
263 | preprocess_source: |
||
264 | inc ecx |
||
265 | mov [current_line],edi |
||
266 | mov eax,edx |
||
267 | stos dword [edi] |
||
268 | mov eax,ecx |
||
269 | stos dword [edi] |
||
270 | mov eax,esi |
||
271 | sub eax,ebx |
||
272 | stos dword [edi] |
||
273 | xor eax,eax |
||
274 | stos dword [edi] |
||
275 | push ebx edx |
||
276 | call convert_line |
||
277 | call preprocess_line |
||
278 | pop edx ebx |
||
279 | next_line: |
||
280 | cmp byte [esi-1],0 |
||
281 | je file_end |
||
282 | cmp byte [esi-1],1Ah |
||
283 | jne preprocess_source |
||
284 | file_end: |
||
285 | pop [memory_end] |
||
286 | clc |
||
287 | ret |
||
288 | |||
289 | |||
290 | push ecx |
||
291 | test [macro_status],0Fh |
||
292 | jz convert_line_data |
||
293 | mov ax,3Bh |
||
294 | stos word [edi] |
||
295 | convert_line_data: |
||
296 | cmp edi,[memory_end] |
||
297 | jae out_of_memory |
||
298 | lods byte [esi] |
||
299 | cmp al,20h |
||
300 | je convert_line_data |
||
301 | cmp al,9 |
||
302 | je convert_line_data |
||
303 | mov ah,al |
||
304 | mov ebx,characters |
||
305 | xlat byte [ebx] |
||
306 | or al,al |
||
307 | jz convert_separator |
||
308 | cmp ah,27h |
||
309 | je convert_string |
||
310 | cmp ah,22h |
||
311 | je convert_string |
||
312 | mov byte [edi],1Ah |
||
313 | scas word [edi] |
||
314 | xchg al,ah |
||
315 | stos byte [edi] |
||
316 | mov ebx,characters |
||
317 | xor ecx,ecx |
||
318 | convert_symbol: |
||
319 | lods byte [esi] |
||
320 | stos byte [edi] |
||
321 | xlat byte [ebx] |
||
322 | or al,al |
||
323 | loopnzd convert_symbol |
||
324 | neg ecx |
||
325 | cmp ecx,255 |
||
326 | ja name_too_long |
||
327 | mov ebx,edi |
||
328 | sub ebx,ecx |
||
329 | mov byte [ebx-2],cl |
||
330 | found_separator: |
||
331 | dec edi |
||
332 | mov ah,[esi-1] |
||
333 | convert_separator: |
||
334 | xchg al,ah |
||
335 | cmp al,20h |
||
336 | jb control_character |
||
337 | je convert_line_data |
||
338 | symbol_character: |
||
339 | cmp al,3Bh |
||
340 | je ignore_comment |
||
341 | cmp al,5Ch |
||
342 | je backslash_character |
||
343 | stos byte [edi] |
||
344 | jmp convert_line_data |
||
345 | control_character: |
||
346 | cmp al,1Ah |
||
347 | je line_end |
||
348 | cmp al,0Dh |
||
349 | je cr_character |
||
350 | cmp al,0Ah |
||
351 | je lf_character |
||
352 | cmp al,9 |
||
353 | je convert_line_data |
||
354 | or al,al |
||
355 | jnz symbol_character |
||
356 | jmp line_end |
||
357 | lf_character: |
||
358 | lods byte [esi] |
||
359 | cmp al,0Dh |
||
360 | je line_end |
||
361 | dec esi |
||
362 | jmp line_end |
||
363 | cr_character: |
||
364 | lods byte [esi] |
||
365 | cmp al,0Ah |
||
366 | je line_end |
||
367 | dec esi |
||
368 | jmp line_end |
||
369 | convert_string: |
||
370 | mov al,22h |
||
371 | stos byte [edi] |
||
372 | scas dword [edi] |
||
373 | mov ebx,edi |
||
374 | copy_string: |
||
375 | lods byte [esi] |
||
376 | stos byte [edi] |
||
377 | cmp al,0Ah |
||
378 | je no_end_quote |
||
379 | cmp al,0Dh |
||
380 | je no_end_quote |
||
381 | or al,al |
||
382 | jz no_end_quote |
||
383 | cmp al,1Ah |
||
384 | je no_end_quote |
||
385 | cmp al,ah |
||
386 | jne copy_string |
||
387 | lods byte [esi] |
||
388 | cmp al,ah |
||
389 | je copy_string |
||
390 | dec esi |
||
391 | dec edi |
||
392 | mov eax,edi |
||
393 | sub eax,ebx |
||
394 | mov [ebx-4],eax |
||
395 | jmp convert_line_data |
||
396 | backslash_character: |
||
397 | mov byte [edi],0 |
||
398 | lods byte [esi] |
||
399 | cmp al,20h |
||
400 | je concatenate_lines |
||
401 | cmp al,9 |
||
402 | je concatenate_lines |
||
403 | cmp al,1Ah |
||
404 | je unexpected_end_of_file |
||
405 | or al,al |
||
406 | jz unexpected_end_of_file |
||
407 | cmp al,0Ah |
||
408 | je concatenate_lf |
||
409 | cmp al,0Dh |
||
410 | je concatenate_cr |
||
411 | cmp al,3Bh |
||
412 | je find_concatenated_line |
||
413 | mov al,1Ah |
||
414 | stos byte [edi] |
||
415 | mov ecx,edi |
||
416 | mov ax,5C01h |
||
417 | stos word [edi] |
||
418 | dec esi |
||
419 | group_backslashes: |
||
420 | lods byte [esi] |
||
421 | cmp al,5Ch |
||
422 | jne backslashed_symbol |
||
423 | stos byte [edi] |
||
424 | inc byte [ecx] |
||
425 | jz name_too_long |
||
426 | jmp group_backslashes |
||
427 | no_end_quote: |
||
428 | mov byte [ebx-5],0 |
||
429 | jmp missing_end_quote |
||
430 | backslashed_symbol: |
||
431 | cmp al,1Ah |
||
432 | je unexpected_end_of_file |
||
433 | or al,al |
||
434 | jz unexpected_end_of_file |
||
435 | cmp al,0Ah |
||
436 | je extra_characters_on_line |
||
437 | cmp al,0Dh |
||
438 | je extra_characters_on_line |
||
439 | cmp al,20h |
||
440 | je extra_characters_on_line |
||
441 | cmp al,9 |
||
442 | je extra_characters_on_line |
||
443 | cmp al,22h |
||
444 | je extra_characters_on_line |
||
445 | cmp al,27h |
||
446 | je extra_characters_on_line |
||
447 | cmp al,3Bh |
||
448 | je extra_characters_on_line |
||
449 | mov ah,al |
||
450 | mov ebx,characters |
||
451 | xlat byte [ebx] |
||
452 | or al,al |
||
453 | jz backslashed_symbol_character |
||
454 | mov al,ah |
||
455 | convert_backslashed_symbol: |
||
456 | stos byte [edi] |
||
457 | xlat byte [ebx] |
||
458 | or al,al |
||
459 | jz found_separator |
||
460 | inc byte [ecx] |
||
461 | jz name_too_long |
||
462 | lods byte [esi] |
||
463 | jmp convert_backslashed_symbol |
||
464 | backslashed_symbol_character: |
||
465 | mov al,ah |
||
466 | stos byte [edi] |
||
467 | inc byte [ecx] |
||
468 | jmp convert_line_data |
||
469 | concatenate_lines: |
||
470 | lods byte [esi] |
||
471 | cmp al,20h |
||
472 | je concatenate_lines |
||
473 | cmp al,9 |
||
474 | je concatenate_lines |
||
475 | cmp al,1Ah |
||
476 | je unexpected_end_of_file |
||
477 | or al,al |
||
478 | jz unexpected_end_of_file |
||
479 | cmp al,0Ah |
||
480 | je concatenate_lf |
||
481 | cmp al,0Dh |
||
482 | je concatenate_cr |
||
483 | cmp al,3Bh |
||
484 | jne extra_characters_on_line |
||
485 | find_concatenated_line: |
||
486 | lods byte [esi] |
||
487 | cmp al,0Ah |
||
488 | je concatenate_lf |
||
489 | cmp al,0Dh |
||
490 | je concatenate_cr |
||
491 | or al,al |
||
492 | jz concatenate_ok |
||
493 | cmp al,1Ah |
||
494 | jne find_concatenated_line |
||
495 | jmp unexpected_end_of_file |
||
496 | concatenate_lf: |
||
497 | lods byte [esi] |
||
498 | cmp al,0Dh |
||
499 | je concatenate_ok |
||
500 | dec esi |
||
501 | jmp concatenate_ok |
||
502 | concatenate_cr: |
||
503 | lods byte [esi] |
||
504 | cmp al,0Ah |
||
505 | je concatenate_ok |
||
506 | dec esi |
||
507 | concatenate_ok: |
||
508 | inc dword [esp] |
||
509 | jmp convert_line_data |
||
510 | ignore_comment: |
||
511 | lods byte [esi] |
||
512 | cmp al,0Ah |
||
513 | je lf_character |
||
514 | cmp al,0Dh |
||
515 | je cr_character |
||
516 | or al,al |
||
517 | jz line_end |
||
518 | cmp al,1Ah |
||
519 | jne ignore_comment |
||
520 | line_end: |
||
521 | xor al,al |
||
522 | stos byte [edi] |
||
523 | pop ecx |
||
524 | ret |
||
525 | |||
526 | |||
527 | mov edi,converted |
||
528 | mov ebx,characters |
||
529 | convert_case: |
||
530 | lods byte [esi] |
||
531 | xlat byte [ebx] |
||
532 | stos byte [edi] |
||
533 | loop convert_case |
||
534 | case_ok: |
||
535 | ret |
||
536 | |||
537 | |||
538 | push edi |
||
539 | mov edx,esi |
||
540 | mov ebp,ecx |
||
541 | call lower_case |
||
542 | pop edi |
||
543 | scan_directives: |
||
544 | mov esi,converted |
||
545 | movzx eax,byte [edi] |
||
546 | or al,al |
||
547 | jz no_directive |
||
548 | mov ecx,ebp |
||
549 | inc edi |
||
550 | mov ebx,edi |
||
551 | add ebx,eax |
||
552 | mov ah,[esi] |
||
553 | cmp ah,[edi] |
||
554 | jb no_directive |
||
555 | ja next_directive |
||
556 | cmp cl,al |
||
557 | jne next_directive |
||
558 | repe cmps byte [esi],[edi] |
||
559 | jb no_directive |
||
560 | je directive_found |
||
561 | next_directive: |
||
562 | mov edi,ebx |
||
563 | add edi,2 |
||
564 | jmp scan_directives |
||
565 | no_directive: |
||
566 | mov esi,edx |
||
567 | mov ecx,ebp |
||
568 | stc |
||
569 | ret |
||
570 | directive_found: |
||
571 | call get_directive_handler_base |
||
572 | directive_handler: |
||
573 | lea esi,[edx+ebp] |
||
574 | movzx ecx,word [ebx] |
||
575 | add eax,ecx |
||
576 | clc |
||
577 | ret |
||
578 | get_directive_handler_base: |
||
579 | mov eax,[esp] |
||
580 | ret |
||
581 | |||
582 | |||
583 | mov eax,esp |
||
584 | sub eax,[stack_limit] |
||
585 | cmp eax,100h |
||
586 | jb stack_overflow |
||
587 | push ecx esi |
||
588 | preprocess_current_line: |
||
589 | mov esi,[current_line] |
||
590 | add esi,16 |
||
591 | cmp word [esi],3Bh |
||
592 | jne line_start_ok |
||
593 | add esi,2 |
||
594 | line_start_ok: |
||
595 | test [macro_status],0F0h |
||
596 | jnz macro_preprocessing |
||
597 | cmp byte [esi],1Ah |
||
598 | jne not_fix_constant |
||
599 | movzx edx,byte [esi+1] |
||
600 | lea edx,[esi+2+edx] |
||
601 | cmp word [edx],031Ah |
||
602 | jne not_fix_constant |
||
603 | mov ebx,characters |
||
604 | movzx eax,byte [edx+2] |
||
605 | xlat byte [ebx] |
||
606 | ror eax,8 |
||
607 | mov al,[edx+3] |
||
608 | xlat byte [ebx] |
||
609 | ror eax,8 |
||
610 | mov al,[edx+4] |
||
611 | xlat byte [ebx] |
||
612 | ror eax,16 |
||
613 | cmp eax,'fix' |
||
614 | je define_fix_constant |
||
615 | not_fix_constant: |
||
616 | call process_fix_constants |
||
617 | jmp initial_preprocessing_ok |
||
618 | macro_preprocessing: |
||
619 | call process_macro_operators |
||
620 | initial_preprocessing_ok: |
||
621 | mov esi,[current_line] |
||
622 | add esi,16 |
||
623 | mov al,[macro_status] |
||
624 | test al,2 |
||
625 | jnz skip_macro_block |
||
626 | test al,1 |
||
627 | jnz find_macro_block |
||
628 | preprocess_instruction: |
||
629 | mov [current_offset],esi |
||
630 | lods byte [esi] |
||
631 | movzx ecx,byte [esi] |
||
632 | inc esi |
||
633 | cmp al,1Ah |
||
634 | jne not_preprocessor_symbol |
||
635 | cmp cl,3 |
||
636 | jb not_preprocessor_directive |
||
637 | push edi |
||
638 | mov edi,preprocessor_directives |
||
639 | call get_directive |
||
640 | pop edi |
||
641 | jc not_preprocessor_directive |
||
642 | mov byte [edx-2],3Bh |
||
643 | jmp near eax |
||
644 | not_preprocessor_directive: |
||
645 | xor ch,ch |
||
646 | call get_preprocessor_symbol |
||
647 | jc not_macro |
||
648 | mov byte [ebx-2],3Bh |
||
649 | mov [struc_name],0 |
||
650 | jmp use_macro |
||
651 | not_macro: |
||
652 | mov [struc_name],esi |
||
653 | add esi,ecx |
||
654 | lods byte [esi] |
||
655 | cmp al,':' |
||
656 | je preprocess_label |
||
657 | cmp al,1Ah |
||
658 | jne not_preprocessor_symbol |
||
659 | lods byte [esi] |
||
660 | cmp al,3 |
||
661 | jne not_symbolic_constant |
||
662 | mov ebx,characters |
||
663 | movzx eax,byte [esi] |
||
664 | xlat byte [ebx] |
||
665 | ror eax,8 |
||
666 | mov al,[esi+1] |
||
667 | xlat byte [ebx] |
||
668 | ror eax,8 |
||
669 | mov al,[esi+2] |
||
670 | xlat byte [ebx] |
||
671 | ror eax,16 |
||
672 | cmp eax,'equ' |
||
673 | je define_equ_constant |
||
674 | mov al,3 |
||
675 | not_symbolic_constant: |
||
676 | mov ch,1 |
||
677 | mov cl,al |
||
678 | call get_preprocessor_symbol |
||
679 | jc not_preprocessor_symbol |
||
680 | push edx esi |
||
681 | mov esi,[struc_name] |
||
682 | mov [struc_label],esi |
||
683 | sub [struc_label],2 |
||
684 | mov cl,[esi-1] |
||
685 | mov ch,10b |
||
686 | call get_preprocessor_symbol |
||
687 | jc struc_name_ok |
||
688 | test edx,edx |
||
9459 | leency | 689 | jz reserved_word_used_as_symbol |
690 | mov ecx,[edx+12] |
||
7836 | leency | 691 | add ecx,3 |
692 | lea ebx,[edi+ecx] |
||
693 | mov ecx,edi |
||
694 | sub ecx,[struc_label] |
||
695 | lea esi,[edi-1] |
||
696 | lea edi,[ebx-1] |
||
697 | std |
||
698 | rep movs byte [edi],[esi] |
||
699 | cld |
||
700 | mov edi,[struc_label] |
||
701 | mov esi,[edx+8] |
||
702 | mov ecx,[edx+12] |
||
703 | add [struc_name],ecx |
||
704 | add [struc_name],3 |
||
705 | call move_data |
||
706 | mov al,3Ah |
||
707 | stos byte [edi] |
||
708 | mov ax,3Bh |
||
709 | stos word [edi] |
||
710 | mov edi,ebx |
||
711 | pop esi |
||
712 | add esi,[edx+12] |
||
713 | add esi,3 |
||
714 | pop edx |
||
715 | jmp use_macro |
||
716 | struc_name_ok: |
||
717 | mov edx,[struc_name] |
||
718 | movzx eax,byte [edx-1] |
||
719 | add edx,eax |
||
720 | push edi |
||
721 | lea esi,[edi-1] |
||
722 | mov ecx,edi |
||
723 | sub ecx,edx |
||
724 | std |
||
725 | rep movs byte [edi],[esi] |
||
726 | cld |
||
727 | pop edi |
||
728 | inc edi |
||
729 | mov al,3Ah |
||
730 | mov [edx],al |
||
731 | inc al |
||
732 | mov [edx+1],al |
||
733 | pop esi edx |
||
734 | inc esi |
||
735 | jmp use_macro |
||
736 | preprocess_label: |
||
737 | dec esi |
||
738 | sub esi,ecx |
||
739 | lea ebp,[esi-2] |
||
740 | mov ch,10b |
||
741 | call get_preprocessor_symbol |
||
742 | jnc symbolic_constant_in_label |
||
743 | lea esi,[esi+ecx+1] |
||
744 | cmp byte [esi],':' |
||
745 | jne preprocess_instruction |
||
746 | inc esi |
||
747 | jmp preprocess_instruction |
||
748 | symbolic_constant_in_label: |
||
749 | test edx,edx |
||
9459 | leency | 750 | jz reserved_word_used_as_symbol |
751 | mov ebx,[edx+8] |
||
7836 | leency | 752 | mov ecx,[edx+12] |
753 | add ecx,ebx |
||
754 | check_for_broken_label: |
||
755 | cmp ebx,ecx |
||
756 | je label_broken |
||
757 | cmp byte [ebx],1Ah |
||
758 | jne label_broken |
||
759 | movzx eax,byte [ebx+1] |
||
760 | lea ebx,[ebx+2+eax] |
||
761 | cmp ebx,ecx |
||
762 | je label_constant_ok |
||
763 | cmp byte [ebx],':' |
||
764 | jne label_broken |
||
765 | inc ebx |
||
766 | cmp byte [ebx],':' |
||
767 | jne check_for_broken_label |
||
768 | inc ebx |
||
769 | jmp check_for_broken_label |
||
770 | label_broken: |
||
771 | call replace_symbolic_constant |
||
772 | jmp line_preprocessed |
||
773 | label_constant_ok: |
||
774 | mov ecx,edi |
||
775 | sub ecx,esi |
||
776 | mov edi,[edx+12] |
||
777 | add edi,ebp |
||
778 | push edi |
||
779 | lea eax,[edi+ecx] |
||
780 | push eax |
||
781 | cmp esi,edi |
||
782 | je replace_label |
||
783 | jb move_rest_of_line_up |
||
784 | rep movs byte [edi],[esi] |
||
785 | jmp replace_label |
||
786 | move_rest_of_line_up: |
||
787 | lea esi,[esi+ecx-1] |
||
788 | lea edi,[edi+ecx-1] |
||
789 | std |
||
790 | rep movs byte [edi],[esi] |
||
791 | cld |
||
792 | replace_label: |
||
793 | mov ecx,[edx+12] |
||
794 | mov edi,[esp+4] |
||
795 | sub edi,ecx |
||
796 | mov esi,[edx+8] |
||
797 | rep movs byte [edi],[esi] |
||
798 | pop edi esi |
||
799 | inc esi |
||
800 | jmp preprocess_instruction |
||
801 | not_preprocessor_symbol: |
||
802 | mov esi,[current_offset] |
||
803 | call process_equ_constants |
||
804 | line_preprocessed: |
||
805 | pop esi ecx |
||
806 | ret |
||
807 | |||
808 | |||
809 | push ebp edi esi |
||
810 | mov ebp,ecx |
||
811 | shl ebp,22 |
||
812 | mov al,ch |
||
9459 | leency | 813 | and al,11b |
814 | movzx ecx,cl |
||
7836 | leency | 815 | cmp al,10b |
9459 | leency | 816 | jne no_preprocessor_special_symbol |
817 | cmp cl,4 |
||
818 | jbe no_preprocessor_special_symbol |
||
819 | mov ax,'__' |
||
820 | cmp ax,[esi] |
||
821 | jne no_preprocessor_special_symbol |
||
822 | cmp ax,[esi+ecx-2] |
||
823 | jne no_preprocessor_special_symbol |
||
824 | add esi,2 |
||
825 | sub ecx,4 |
||
826 | push ebp |
||
827 | mov edi,preprocessor_special_symbols |
||
828 | call get_directive |
||
829 | pop ebp |
||
830 | jc preprocessor_special_symbol_not_recognized |
||
831 | add esi,2 |
||
832 | xor edx,edx |
||
833 | jmp preprocessor_symbol_found |
||
834 | preprocessor_special_symbol_not_recognized: |
||
835 | add ecx,4 |
||
836 | sub esi,2 |
||
837 | no_preprocessor_special_symbol: |
||
838 | mov ebx,hash_tree |
||
7836 | leency | 839 | mov edi,10 |
840 | follow_hashes_roots: |
||
841 | mov edx,[ebx] |
||
842 | or edx,edx |
||
843 | jz preprocessor_symbol_not_found |
||
844 | xor eax,eax |
||
845 | shl ebp,1 |
||
846 | adc eax,0 |
||
847 | lea ebx,[edx+eax*4] |
||
848 | dec edi |
||
849 | jnz follow_hashes_roots |
||
850 | mov edi,ebx |
||
851 | call calculate_hash |
||
852 | mov ebp,eax |
||
853 | and ebp,3FFh |
||
854 | shl ebp,10 |
||
855 | xor ebp,eax |
||
856 | mov ebx,edi |
||
857 | mov edi,22 |
||
858 | follow_hashes_tree: |
||
859 | mov edx,[ebx] |
||
860 | or edx,edx |
||
861 | jz preprocessor_symbol_not_found |
||
862 | xor eax,eax |
||
863 | shl ebp,1 |
||
864 | adc eax,0 |
||
865 | lea ebx,[edx+eax*4] |
||
866 | dec edi |
||
867 | jnz follow_hashes_tree |
||
868 | mov al,cl |
||
869 | mov edx,[ebx] |
||
870 | or edx,edx |
||
871 | jz preprocessor_symbol_not_found |
||
872 | compare_with_preprocessor_symbol: |
||
873 | mov edi,[edx+4] |
||
874 | cmp edi,1 |
||
875 | jbe next_equal_hash |
||
876 | repe cmps byte [esi],[edi] |
||
877 | je preprocessor_symbol_found |
||
878 | mov cl,al |
||
879 | mov esi,[esp] |
||
880 | next_equal_hash: |
||
881 | mov edx,[edx] |
||
882 | or edx,edx |
||
883 | jnz compare_with_preprocessor_symbol |
||
884 | preprocessor_symbol_not_found: |
||
885 | pop esi edi ebp |
||
886 | stc |
||
887 | ret |
||
888 | preprocessor_symbol_found: |
||
889 | pop ebx edi ebp |
||
890 | clc |
||
891 | ret |
||
892 | calculate_hash: |
||
893 | xor ebx,ebx |
||
894 | mov eax,2166136261 |
||
895 | mov ebp,16777619 |
||
896 | fnv1a_hash: |
||
897 | xor al,[esi+ebx] |
||
898 | mul ebp |
||
899 | inc bl |
||
900 | cmp bl,cl |
||
901 | jb fnv1a_hash |
||
902 | ret |
||
903 | add_preprocessor_symbol: |
||
904 | push edi esi |
||
905 | xor eax,eax |
||
906 | or cl,cl |
||
907 | jz reshape_hash |
||
908 | cmp ch,11b |
||
909 | je preprocessor_symbol_name_ok |
||
910 | push ecx |
||
911 | movzx ecx,cl |
||
912 | mov edi,preprocessor_directives |
||
913 | call get_directive |
||
914 | jnc reserved_word_used_as_symbol |
||
915 | pop ecx |
||
916 | preprocessor_symbol_name_ok: |
||
917 | call calculate_hash |
||
918 | reshape_hash: |
||
919 | mov ebp,eax |
||
920 | and ebp,3FFh |
||
921 | shr eax,10 |
||
922 | xor ebp,eax |
||
923 | shl ecx,22 |
||
924 | or ebp,ecx |
||
925 | mov ebx,hash_tree |
||
926 | mov ecx,32 |
||
927 | find_leave_for_symbol: |
||
928 | mov edx,[ebx] |
||
929 | or edx,edx |
||
930 | jz extend_hashes_tree |
||
931 | xor eax,eax |
||
932 | rol ebp,1 |
||
933 | adc eax,0 |
||
934 | lea ebx,[edx+eax*4] |
||
935 | dec ecx |
||
936 | jnz find_leave_for_symbol |
||
937 | mov edx,[ebx] |
||
938 | or edx,edx |
||
939 | jz add_symbol_entry |
||
940 | shr ebp,30 |
||
941 | cmp ebp,11b |
||
942 | je reuse_symbol_entry |
||
943 | cmp dword [edx+4],0 |
||
944 | jne add_symbol_entry |
||
945 | find_entry_to_reuse: |
||
946 | mov edi,[edx] |
||
947 | or edi,edi |
||
948 | jz reuse_symbol_entry |
||
949 | cmp dword [edi+4],0 |
||
950 | jne reuse_symbol_entry |
||
951 | mov edx,edi |
||
952 | jmp find_entry_to_reuse |
||
953 | add_symbol_entry: |
||
954 | mov eax,edx |
||
955 | mov edx,[labels_list] |
||
956 | sub edx,16 |
||
957 | cmp edx,[free_additional_memory] |
||
958 | jb out_of_memory |
||
959 | mov [labels_list],edx |
||
960 | mov [edx],eax |
||
961 | mov [ebx],edx |
||
962 | reuse_symbol_entry: |
||
963 | pop esi edi |
||
964 | mov [edx+4],esi |
||
965 | ret |
||
966 | extend_hashes_tree: |
||
967 | mov edx,[labels_list] |
||
968 | sub edx,8 |
||
969 | cmp edx,[free_additional_memory] |
||
970 | jb out_of_memory |
||
971 | mov [labels_list],edx |
||
972 | xor eax,eax |
||
973 | mov [edx],eax |
||
974 | mov [edx+4],eax |
||
975 | shl ebp,1 |
||
976 | adc eax,0 |
||
977 | mov [ebx],edx |
||
978 | lea ebx,[edx+eax*4] |
||
979 | dec ecx |
||
980 | jnz extend_hashes_tree |
||
981 | mov edx,[labels_list] |
||
982 | sub edx,16 |
||
983 | cmp edx,[free_additional_memory] |
||
984 | jb out_of_memory |
||
985 | mov [labels_list],edx |
||
986 | mov dword [edx],0 |
||
987 | mov [ebx],edx |
||
988 | pop esi edi |
||
989 | mov [edx+4],esi |
||
990 | ret |
||
991 | |||
992 | |||
993 | add edx,5 |
||
994 | add esi,2 |
||
995 | push edx |
||
996 | mov ch,11b |
||
997 | jmp define_preprocessor_constant |
||
998 | define_equ_constant: |
||
999 | add esi,3 |
||
1000 | push esi |
||
1001 | call process_equ_constants |
||
1002 | mov esi,[struc_name] |
||
1003 | mov ch,10b |
||
1004 | define_preprocessor_constant: |
||
1005 | mov byte [esi-2],3Bh |
||
1006 | mov cl,[esi-1] |
||
1007 | call add_preprocessor_symbol |
||
1008 | pop ebx |
||
1009 | mov ecx,edi |
||
1010 | dec ecx |
||
1011 | sub ecx,ebx |
||
1012 | mov [edx+8],ebx |
||
1013 | mov [edx+12],ecx |
||
1014 | jmp line_preprocessed |
||
1015 | define_symbolic_constant: |
||
1016 | lods byte [esi] |
||
1017 | cmp al,1Ah |
||
1018 | jne invalid_name |
||
1019 | lods byte [esi] |
||
1020 | mov cl,al |
||
1021 | mov ch,10b |
||
1022 | call add_preprocessor_symbol |
||
1023 | movzx eax,byte [esi-1] |
||
1024 | add esi,eax |
||
1025 | lea ecx,[edi-1] |
||
1026 | sub ecx,esi |
||
1027 | mov [edx+8],esi |
||
1028 | mov [edx+12],ecx |
||
1029 | jmp line_preprocessed |
||
1030 | |||
1031 | |||
1032 | mov ch,1 |
||
1033 | jmp make_macro |
||
1034 | define_macro: |
||
1035 | xor ch,ch |
||
1036 | make_macro: |
||
1037 | lods byte [esi] |
||
1038 | cmp al,1Ah |
||
1039 | jne invalid_name |
||
1040 | lods byte [esi] |
||
1041 | mov cl,al |
||
1042 | call add_preprocessor_symbol |
||
1043 | mov eax,[current_line] |
||
1044 | mov [edx+12],eax |
||
1045 | movzx eax,byte [esi-1] |
||
1046 | add esi,eax |
||
1047 | mov [edx+8],esi |
||
1048 | mov al,[macro_status] |
||
1049 | and al,0F0h |
||
1050 | or al,1 |
||
1051 | mov [macro_status],al |
||
1052 | mov eax,[current_line] |
||
1053 | mov [error_line],eax |
||
1054 | xor ebp,ebp |
||
1055 | lods byte [esi] |
||
1056 | or al,al |
||
1057 | jz line_preprocessed |
||
1058 | cmp al,'{' |
||
1059 | je found_macro_block |
||
1060 | dec esi |
||
1061 | skip_macro_arguments: |
||
1062 | lods byte [esi] |
||
1063 | cmp al,1Ah |
||
1064 | je skip_macro_argument |
||
1065 | cmp al,'[' |
||
1066 | jne invalid_macro_arguments |
||
1067 | or ebp,-1 |
||
1068 | jz invalid_macro_arguments |
||
1069 | lods byte [esi] |
||
1070 | cmp al,1Ah |
||
1071 | jne invalid_macro_arguments |
||
1072 | skip_macro_argument: |
||
1073 | movzx eax,byte [esi] |
||
1074 | inc esi |
||
1075 | add esi,eax |
||
1076 | lods byte [esi] |
||
1077 | cmp al,':' |
||
1078 | je macro_argument_with_default_value |
||
1079 | cmp al,'=' |
||
1080 | je macro_argument_with_default_value |
||
1081 | cmp al,'*' |
||
1082 | jne macro_argument_end |
||
1083 | lods byte [esi] |
||
1084 | macro_argument_end: |
||
1085 | cmp al,',' |
||
1086 | je skip_macro_arguments |
||
1087 | cmp al,'&' |
||
1088 | je macro_arguments_finisher |
||
1089 | cmp al,']' |
||
1090 | jne end_macro_arguments |
||
1091 | not ebp |
||
1092 | macro_arguments_finisher: |
||
1093 | lods byte [esi] |
||
1094 | end_macro_arguments: |
||
1095 | or ebp,ebp |
||
1096 | jnz invalid_macro_arguments |
||
1097 | or al,al |
||
1098 | jz line_preprocessed |
||
1099 | cmp al,'{' |
||
1100 | je found_macro_block |
||
1101 | jmp invalid_macro_arguments |
||
1102 | macro_argument_with_default_value: |
||
1103 | or [skip_default_argument_value],-1 |
||
1104 | call skip_macro_argument_value |
||
1105 | inc esi |
||
1106 | jmp macro_argument_end |
||
1107 | skip_macro_argument_value: |
||
1108 | cmp byte [esi],'<' |
||
1109 | jne simple_argument |
||
1110 | mov ecx,1 |
||
1111 | inc esi |
||
1112 | enclosed_argument: |
||
1113 | lods byte [esi] |
||
1114 | or al,al |
||
1115 | jz invalid_macro_arguments |
||
1116 | cmp al,1Ah |
||
1117 | je enclosed_symbol |
||
1118 | cmp al,22h |
||
1119 | je enclosed_string |
||
1120 | cmp al,'>' |
||
1121 | je enclosed_argument_end |
||
1122 | cmp al,'<' |
||
1123 | jne enclosed_argument |
||
1124 | inc ecx |
||
1125 | jmp enclosed_argument |
||
1126 | enclosed_symbol: |
||
1127 | movzx eax,byte [esi] |
||
1128 | inc esi |
||
1129 | add esi,eax |
||
1130 | jmp enclosed_argument |
||
1131 | enclosed_string: |
||
1132 | lods dword [esi] |
||
1133 | add esi,eax |
||
1134 | jmp enclosed_argument |
||
1135 | enclosed_argument_end: |
||
1136 | loop enclosed_argument |
||
1137 | lods byte [esi] |
||
1138 | or al,al |
||
1139 | jz argument_value_end |
||
1140 | cmp al,',' |
||
1141 | je argument_value_end |
||
1142 | cmp [skip_default_argument_value],0 |
||
1143 | je invalid_macro_arguments |
||
1144 | cmp al,'{' |
||
1145 | je argument_value_end |
||
1146 | cmp al,'&' |
||
1147 | je argument_value_end |
||
1148 | or ebp,ebp |
||
1149 | jz invalid_macro_arguments |
||
1150 | cmp al,']' |
||
1151 | je argument_value_end |
||
1152 | jmp invalid_macro_arguments |
||
1153 | simple_argument: |
||
1154 | lods byte [esi] |
||
1155 | or al,al |
||
1156 | jz argument_value_end |
||
1157 | cmp al,',' |
||
1158 | je argument_value_end |
||
1159 | cmp al,22h |
||
1160 | je argument_string |
||
1161 | cmp al,1Ah |
||
1162 | je argument_symbol |
||
1163 | cmp [skip_default_argument_value],0 |
||
1164 | je simple_argument |
||
1165 | cmp al,'{' |
||
1166 | je argument_value_end |
||
1167 | cmp al,'&' |
||
1168 | je argument_value_end |
||
1169 | or ebp,ebp |
||
1170 | jz simple_argument |
||
1171 | cmp al,']' |
||
1172 | je argument_value_end |
||
1173 | argument_symbol: |
||
1174 | movzx eax,byte [esi] |
||
1175 | inc esi |
||
1176 | add esi,eax |
||
1177 | jmp simple_argument |
||
1178 | argument_string: |
||
1179 | lods dword [esi] |
||
1180 | add esi,eax |
||
1181 | jmp simple_argument |
||
1182 | argument_value_end: |
||
1183 | dec esi |
||
1184 | ret |
||
1185 | find_macro_block: |
||
1186 | add esi,2 |
||
1187 | lods byte [esi] |
||
1188 | or al,al |
||
1189 | jz line_preprocessed |
||
1190 | cmp al,'{' |
||
1191 | jne unexpected_characters |
||
1192 | found_macro_block: |
||
1193 | or [macro_status],2 |
||
1194 | skip_macro_block: |
||
1195 | lods byte [esi] |
||
1196 | cmp al,1Ah |
||
1197 | je skip_macro_symbol |
||
1198 | cmp al,3Bh |
||
1199 | je skip_macro_symbol |
||
1200 | cmp al,22h |
||
1201 | je skip_macro_string |
||
1202 | or al,al |
||
1203 | jz line_preprocessed |
||
1204 | cmp al,'}' |
||
1205 | jne skip_macro_block |
||
1206 | mov al,[macro_status] |
||
1207 | and [macro_status],0F0h |
||
1208 | test al,8 |
||
1209 | jnz use_instant_macro |
||
1210 | cmp byte [esi],0 |
||
1211 | je line_preprocessed |
||
1212 | mov ecx,edi |
||
1213 | sub ecx,esi |
||
1214 | mov edx,esi |
||
1215 | lea esi,[esi+ecx-1] |
||
1216 | lea edi,[edi+1+16] |
||
1217 | mov ebx,edi |
||
1218 | dec edi |
||
1219 | std |
||
1220 | rep movs byte [edi],[esi] |
||
1221 | cld |
||
1222 | mov edi,edx |
||
1223 | xor al,al |
||
1224 | stos byte [edi] |
||
1225 | mov esi,[current_line] |
||
1226 | mov [current_line],edi |
||
1227 | mov ecx,4 |
||
1228 | rep movs dword [edi],[esi] |
||
1229 | mov edi,ebx |
||
1230 | jmp initial_preprocessing_ok |
||
1231 | skip_macro_symbol: |
||
1232 | movzx eax,byte [esi] |
||
1233 | inc esi |
||
1234 | add esi,eax |
||
1235 | jmp skip_macro_block |
||
1236 | skip_macro_string: |
||
1237 | lods dword [esi] |
||
1238 | add esi,eax |
||
1239 | jmp skip_macro_block |
||
1240 | postpone_directive: |
||
1241 | push esi |
||
1242 | mov esi,edx |
||
1243 | xor ecx,ecx |
||
1244 | call add_preprocessor_symbol |
||
1245 | mov eax,[current_line] |
||
1246 | mov [error_line],eax |
||
1247 | mov [edx+12],eax |
||
1248 | pop esi |
||
1249 | mov [edx+8],esi |
||
1250 | mov al,[macro_status] |
||
1251 | and al,0F0h |
||
1252 | or al,1 |
||
1253 | mov [macro_status],al |
||
1254 | lods byte [esi] |
||
1255 | or al,al |
||
1256 | jz line_preprocessed |
||
1257 | cmp al,'{' |
||
1258 | jne unexpected_characters |
||
1259 | jmp found_macro_block |
||
1260 | rept_directive: |
||
1261 | mov [base_code],0 |
||
1262 | jmp define_instant_macro |
||
1263 | irp_directive: |
||
1264 | mov [base_code],1 |
||
1265 | jmp define_instant_macro |
||
1266 | irps_directive: |
||
1267 | mov [base_code],2 |
||
1268 | jmp define_instant_macro |
||
1269 | irpv_directive: |
||
1270 | mov [base_code],3 |
||
1271 | jmp define_instant_macro |
||
1272 | match_directive: |
||
1273 | mov [base_code],10h |
||
1274 | define_instant_macro: |
||
1275 | mov al,[macro_status] |
||
1276 | and al,0F0h |
||
1277 | or al,8+1 |
||
1278 | mov [macro_status],al |
||
1279 | mov eax,[current_line] |
||
1280 | mov [error_line],eax |
||
1281 | mov [instant_macro_start],esi |
||
1282 | cmp [base_code],10h |
||
1283 | je prepare_match |
||
1284 | skip_parameters: |
||
1285 | lods byte [esi] |
||
1286 | or al,al |
||
1287 | jz parameters_skipped |
||
1288 | cmp al,'{' |
||
1289 | je parameters_skipped |
||
1290 | cmp al,22h |
||
1291 | je skip_quoted_parameter |
||
1292 | cmp al,1Ah |
||
1293 | jne skip_parameters |
||
1294 | lods byte [esi] |
||
1295 | movzx eax,al |
||
1296 | add esi,eax |
||
1297 | jmp skip_parameters |
||
1298 | skip_quoted_parameter: |
||
1299 | lods dword [esi] |
||
1300 | add esi,eax |
||
1301 | jmp skip_parameters |
||
1302 | parameters_skipped: |
||
1303 | dec esi |
||
1304 | mov [parameters_end],esi |
||
1305 | lods byte [esi] |
||
1306 | cmp al,'{' |
||
1307 | je found_macro_block |
||
1308 | or al,al |
||
1309 | jnz invalid_macro_arguments |
||
1310 | jmp line_preprocessed |
||
1311 | prepare_match: |
||
1312 | call skip_pattern |
||
1313 | mov [value_type],80h+10b |
||
1314 | call process_symbolic_constants |
||
1315 | jmp parameters_skipped |
||
1316 | skip_pattern: |
||
1317 | lods byte [esi] |
||
1318 | or al,al |
||
1319 | jz invalid_macro_arguments |
||
1320 | cmp al,',' |
||
1321 | je pattern_skipped |
||
1322 | cmp al,22h |
||
1323 | je skip_quoted_string_in_pattern |
||
1324 | cmp al,1Ah |
||
1325 | je skip_symbol_in_pattern |
||
1326 | cmp al,'=' |
||
1327 | jne skip_pattern |
||
1328 | mov al,[esi] |
||
1329 | cmp al,1Ah |
||
1330 | je skip_pattern |
||
1331 | cmp al,22h |
||
1332 | je skip_pattern |
||
1333 | inc esi |
||
1334 | jmp skip_pattern |
||
1335 | skip_symbol_in_pattern: |
||
1336 | lods byte [esi] |
||
1337 | movzx eax,al |
||
1338 | add esi,eax |
||
1339 | jmp skip_pattern |
||
1340 | skip_quoted_string_in_pattern: |
||
1341 | lods dword [esi] |
||
1342 | add esi,eax |
||
1343 | jmp skip_pattern |
||
1344 | pattern_skipped: |
||
1345 | ret |
||
1346 | |||
1347 | |||
1348 | xor ch,ch |
||
1349 | jmp restore_preprocessor_symbol |
||
1350 | purge_struc: |
||
1351 | mov ch,1 |
||
1352 | jmp restore_preprocessor_symbol |
||
1353 | restore_equ_constant: |
||
1354 | mov ch,10b |
||
1355 | restore_preprocessor_symbol: |
||
1356 | push ecx |
||
1357 | lods byte [esi] |
||
1358 | cmp al,1Ah |
||
1359 | jne invalid_name |
||
1360 | lods byte [esi] |
||
1361 | mov cl,al |
||
1362 | call get_preprocessor_symbol |
||
1363 | jc no_symbol_to_restore |
||
1364 | test edx,edx |
||
9459 | leency | 1365 | jz symbol_restored |
1366 | mov dword [edx+4],0 |
||
7836 | leency | 1367 | jmp symbol_restored |
1368 | no_symbol_to_restore: |
||
1369 | add esi,ecx |
||
1370 | symbol_restored: |
||
1371 | pop ecx |
||
1372 | lods byte [esi] |
||
1373 | cmp al,',' |
||
1374 | je restore_preprocessor_symbol |
||
1375 | or al,al |
||
1376 | jnz extra_characters_on_line |
||
1377 | jmp line_preprocessed |
||
1378 | |||
1379 | |||
1380 | mov [value_type],11b |
||
1381 | jmp process_symbolic_constants |
||
1382 | process_equ_constants: |
||
1383 | mov [value_type],10b |
||
1384 | process_symbolic_constants: |
||
1385 | mov ebp,esi |
||
1386 | lods byte [esi] |
||
1387 | cmp al,1Ah |
||
1388 | je check_symbol |
||
1389 | cmp al,22h |
||
1390 | je ignore_string |
||
1391 | cmp al,'{' |
||
1392 | je check_brace |
||
1393 | or al,al |
||
1394 | jnz process_symbolic_constants |
||
1395 | ret |
||
1396 | ignore_string: |
||
1397 | lods dword [esi] |
||
1398 | add esi,eax |
||
1399 | jmp process_symbolic_constants |
||
1400 | check_brace: |
||
1401 | test [value_type],80h |
||
1402 | jz process_symbolic_constants |
||
1403 | ret |
||
1404 | no_replacing: |
||
1405 | movzx ecx,byte [esi-1] |
||
1406 | add esi,ecx |
||
1407 | jmp process_symbolic_constants |
||
1408 | check_symbol: |
||
1409 | mov cl,[esi] |
||
1410 | inc esi |
||
1411 | mov ch,[value_type] |
||
1412 | call get_preprocessor_symbol |
||
1413 | jc no_replacing |
||
1414 | mov [current_section],edi |
||
1415 | replace_symbolic_constant: |
||
1416 | test edx,edx |
||
9459 | leency | 1417 | jz replace_special_symbolic_constant |
1418 | mov ecx,[edx+12] |
||
7836 | leency | 1419 | mov edx,[edx+8] |
1420 | xchg esi,edx |
||
1421 | call move_data |
||
1422 | mov esi,edx |
||
1423 | process_after_replaced: |
||
1424 | lods byte [esi] |
||
1425 | cmp al,1Ah |
||
1426 | je symbol_after_replaced |
||
1427 | stos byte [edi] |
||
1428 | cmp al,22h |
||
1429 | je string_after_replaced |
||
1430 | cmp al,'{' |
||
1431 | je brace_after_replaced |
||
1432 | or al,al |
||
1433 | jnz process_after_replaced |
||
1434 | mov ecx,edi |
||
1435 | sub ecx,esi |
||
1436 | mov edi,ebp |
||
1437 | call move_data |
||
1438 | mov esi,edi |
||
1439 | ret |
||
1440 | move_data: |
||
1441 | lea eax,[edi+ecx] |
||
1442 | cmp eax,[memory_end] |
||
1443 | jae out_of_memory |
||
1444 | shr ecx,1 |
||
1445 | jnc movsb_ok |
||
1446 | movs byte [edi],[esi] |
||
1447 | movsb_ok: |
||
1448 | shr ecx,1 |
||
1449 | jnc movsw_ok |
||
1450 | movs word [edi],[esi] |
||
1451 | movsw_ok: |
||
1452 | rep movs dword [edi],[esi] |
||
1453 | ret |
||
1454 | string_after_replaced: |
||
1455 | lods dword [esi] |
||
1456 | stos dword [edi] |
||
1457 | mov ecx,eax |
||
1458 | call move_data |
||
1459 | jmp process_after_replaced |
||
1460 | brace_after_replaced: |
||
1461 | test [value_type],80h |
||
1462 | jz process_after_replaced |
||
1463 | mov edx,edi |
||
1464 | mov ecx,[current_section] |
||
1465 | sub edx,ecx |
||
1466 | sub ecx,esi |
||
1467 | rep movs byte [edi],[esi] |
||
1468 | mov ecx,edi |
||
1469 | sub ecx,esi |
||
1470 | mov edi,ebp |
||
1471 | call move_data |
||
1472 | lea esi,[ebp+edx] |
||
1473 | ret |
||
1474 | symbol_after_replaced: |
||
1475 | mov cl,[esi] |
||
1476 | inc esi |
||
1477 | mov ch,[value_type] |
||
1478 | call get_preprocessor_symbol |
||
1479 | jnc replace_symbolic_constant |
||
1480 | movzx ecx,byte [esi-1] |
||
1481 | mov al,1Ah |
||
1482 | mov ah,cl |
||
1483 | stos word [edi] |
||
1484 | call move_data |
||
1485 | jmp process_after_replaced |
||
1486 | replace_special_symbolic_constant: |
||
9459 | leency | 1487 | jmp near eax |
1488 | preprocessed_file_value: |
||
1489 | call get_current_line_from_file |
||
1490 | test ebx,ebx |
||
1491 | jz process_after_replaced |
||
1492 | push esi edi |
||
1493 | mov esi,[ebx] |
||
1494 | mov edi,esi |
||
1495 | xor al,al |
||
1496 | or ecx,-1 |
||
1497 | repne scas byte [edi] |
||
1498 | add ecx,2 |
||
1499 | neg ecx |
||
1500 | pop edi |
||
1501 | lea eax,[edi+1+4+ecx] |
||
1502 | cmp eax,[memory_end] |
||
1503 | ja out_of_memory |
||
1504 | mov al,22h |
||
1505 | stos byte [edi] |
||
1506 | mov eax,ecx |
||
1507 | stos dword [edi] |
||
1508 | rep movs byte [edi],[esi] |
||
1509 | pop esi |
||
1510 | jmp process_after_replaced |
||
1511 | preprocessed_line_value: |
||
1512 | call get_current_line_from_file |
||
1513 | test ebx,ebx |
||
1514 | jz process_after_replaced |
||
1515 | lea eax,[edi+1+4+20] |
||
1516 | cmp eax,[memory_end] |
||
1517 | ja out_of_memory |
||
1518 | mov ecx,[ebx+4] |
||
1519 | call store_number_symbol |
||
1520 | jmp process_after_replaced |
||
1521 | get_current_line_from_file: |
||
1522 | mov ebx,[current_line] |
||
1523 | find_line_from_file: |
||
1524 | test ebx,ebx |
||
1525 | jz line_from_file_found |
||
1526 | test byte [ebx+7],80h |
||
1527 | jz line_from_file_found |
||
1528 | mov ebx,[ebx+8] |
||
1529 | jmp find_line_from_file |
||
1530 | line_from_file_found: |
||
1531 | ret |
||
1532 | |||
1533 | |||
7836 | leency | 1534 | xor dl,dl |
1535 | mov ebp,edi |
||
1536 | before_macro_operators: |
||
1537 | mov edi,esi |
||
1538 | lods byte [esi] |
||
1539 | cmp al,'`' |
||
1540 | je symbol_conversion |
||
1541 | cmp al,'#' |
||
1542 | je concatenation |
||
1543 | cmp al,1Ah |
||
1544 | je symbol_before_macro_operators |
||
1545 | cmp al,3Bh |
||
1546 | je no_more_macro_operators |
||
1547 | cmp al,22h |
||
1548 | je string_before_macro_operators |
||
1549 | xor dl,dl |
||
1550 | or al,al |
||
1551 | jnz before_macro_operators |
||
1552 | mov edi,esi |
||
1553 | ret |
||
1554 | no_more_macro_operators: |
||
1555 | mov edi,ebp |
||
1556 | ret |
||
1557 | symbol_before_macro_operators: |
||
1558 | mov dl,1Ah |
||
1559 | mov ebx,esi |
||
1560 | lods byte [esi] |
||
1561 | movzx ecx,al |
||
1562 | jecxz symbol_before_macro_operators_ok |
||
1563 | mov edi,esi |
||
1564 | cmp byte [esi],'\' |
||
1565 | je escaped_symbol |
||
1566 | symbol_before_macro_operators_ok: |
||
1567 | add esi,ecx |
||
1568 | jmp before_macro_operators |
||
1569 | string_before_macro_operators: |
||
1570 | mov dl,22h |
||
1571 | mov ebx,esi |
||
1572 | lods dword [esi] |
||
1573 | add esi,eax |
||
1574 | jmp before_macro_operators |
||
1575 | escaped_symbol: |
||
1576 | dec byte [edi-1] |
||
1577 | dec ecx |
||
1578 | inc esi |
||
1579 | cmp ecx,1 |
||
1580 | rep movs byte [edi],[esi] |
||
1581 | jne after_macro_operators |
||
1582 | mov al,[esi-1] |
||
1583 | mov ecx,ebx |
||
1584 | mov ebx,characters |
||
1585 | xlat byte [ebx] |
||
1586 | mov ebx,ecx |
||
1587 | or al,al |
||
1588 | jnz after_macro_operators |
||
1589 | sub edi,3 |
||
1590 | mov al,[esi-1] |
||
1591 | stos byte [edi] |
||
1592 | xor dl,dl |
||
1593 | jmp after_macro_operators |
||
1594 | reduce_symbol_conversion: |
||
1595 | inc esi |
||
1596 | symbol_conversion: |
||
1597 | mov edx,esi |
||
1598 | mov al,[esi] |
||
1599 | cmp al,1Ah |
||
1600 | jne symbol_character_conversion |
||
1601 | lods word [esi] |
||
1602 | movzx ecx,ah |
||
1603 | lea ebx,[edi+3] |
||
1604 | jecxz convert_to_quoted_string |
||
1605 | cmp byte [esi],'\' |
||
1606 | jne convert_to_quoted_string |
||
1607 | inc esi |
||
1608 | dec ecx |
||
1609 | dec ebx |
||
1610 | jmp convert_to_quoted_string |
||
1611 | symbol_character_conversion: |
||
1612 | cmp al,22h |
||
1613 | je after_macro_operators |
||
1614 | cmp al,'`' |
||
1615 | je reduce_symbol_conversion |
||
1616 | lea ebx,[edi+5] |
||
1617 | xor ecx,ecx |
||
1618 | or al,al |
||
1619 | jz convert_to_quoted_string |
||
1620 | cmp al,'#' |
||
1621 | je convert_to_quoted_string |
||
1622 | inc ecx |
||
1623 | convert_to_quoted_string: |
||
1624 | sub ebx,edx |
||
1625 | ja shift_line_data |
||
1626 | mov al,22h |
||
1627 | mov dl,al |
||
1628 | stos byte [edi] |
||
1629 | mov ebx,edi |
||
1630 | mov eax,ecx |
||
1631 | stos dword [edi] |
||
1632 | rep movs byte [edi],[esi] |
||
1633 | cmp edi,esi |
||
1634 | je before_macro_operators |
||
1635 | jmp after_macro_operators |
||
1636 | shift_line_data: |
||
1637 | push ecx |
||
1638 | mov edx,esi |
||
1639 | lea esi,[ebp-1] |
||
1640 | add ebp,ebx |
||
1641 | lea edi,[ebp-1] |
||
1642 | lea ecx,[esi+1] |
||
1643 | sub ecx,edx |
||
1644 | std |
||
1645 | rep movs byte [edi],[esi] |
||
1646 | cld |
||
1647 | pop eax |
||
1648 | sub edi,3 |
||
1649 | mov dl,22h |
||
1650 | mov [edi-1],dl |
||
1651 | mov ebx,edi |
||
1652 | mov [edi],eax |
||
1653 | lea esi,[edi+4+eax] |
||
1654 | jmp before_macro_operators |
||
1655 | concatenation: |
||
1656 | cmp dl,1Ah |
||
1657 | je symbol_concatenation |
||
1658 | cmp dl,22h |
||
1659 | je string_concatenation |
||
1660 | no_concatenation: |
||
1661 | cmp esi,edi |
||
1662 | je before_macro_operators |
||
1663 | jmp after_macro_operators |
||
1664 | symbol_concatenation: |
||
1665 | cmp byte [esi],1Ah |
||
1666 | jne no_concatenation |
||
1667 | inc esi |
||
1668 | lods byte [esi] |
||
1669 | movzx ecx,al |
||
1670 | jecxz do_symbol_concatenation |
||
1671 | cmp byte [esi],'\' |
||
1672 | je concatenate_escaped_symbol |
||
1673 | do_symbol_concatenation: |
||
1674 | add [ebx],cl |
||
1675 | jc name_too_long |
||
1676 | rep movs byte [edi],[esi] |
||
1677 | jmp after_macro_operators |
||
1678 | concatenate_escaped_symbol: |
||
1679 | inc esi |
||
1680 | dec ecx |
||
1681 | jz do_symbol_concatenation |
||
1682 | movzx eax,byte [esi] |
||
1683 | cmp byte [characters+eax],0 |
||
1684 | jne do_symbol_concatenation |
||
1685 | sub esi,3 |
||
1686 | jmp no_concatenation |
||
1687 | string_concatenation: |
||
1688 | cmp byte [esi],22h |
||
1689 | je do_string_concatenation |
||
1690 | cmp byte [esi],'`' |
||
1691 | jne no_concatenation |
||
1692 | concatenate_converted_symbol: |
||
1693 | inc esi |
||
1694 | mov al,[esi] |
||
1695 | cmp al,'`' |
||
1696 | je concatenate_converted_symbol |
||
1697 | cmp al,22h |
||
1698 | je do_string_concatenation |
||
1699 | cmp al,1Ah |
||
1700 | jne concatenate_converted_symbol_character |
||
1701 | inc esi |
||
1702 | lods byte [esi] |
||
1703 | movzx ecx,al |
||
1704 | jecxz finish_concatenating_converted_symbol |
||
1705 | cmp byte [esi],'\' |
||
1706 | jne finish_concatenating_converted_symbol |
||
1707 | inc esi |
||
1708 | dec ecx |
||
1709 | finish_concatenating_converted_symbol: |
||
1710 | add [ebx],ecx |
||
1711 | rep movs byte [edi],[esi] |
||
1712 | jmp after_macro_operators |
||
1713 | concatenate_converted_symbol_character: |
||
1714 | or al,al |
||
1715 | jz after_macro_operators |
||
1716 | cmp al,'#' |
||
1717 | je after_macro_operators |
||
1718 | inc dword [ebx] |
||
1719 | movs byte [edi],[esi] |
||
1720 | jmp after_macro_operators |
||
1721 | do_string_concatenation: |
||
1722 | inc esi |
||
1723 | lods dword [esi] |
||
1724 | mov ecx,eax |
||
1725 | add [ebx],eax |
||
1726 | rep movs byte [edi],[esi] |
||
1727 | after_macro_operators: |
||
1728 | lods byte [esi] |
||
1729 | cmp al,'`' |
||
1730 | je symbol_conversion |
||
1731 | cmp al,'#' |
||
1732 | je concatenation |
||
1733 | stos byte [edi] |
||
1734 | cmp al,1Ah |
||
1735 | je symbol_after_macro_operators |
||
1736 | cmp al,3Bh |
||
1737 | je no_more_macro_operators |
||
1738 | cmp al,22h |
||
1739 | je string_after_macro_operators |
||
1740 | xor dl,dl |
||
1741 | or al,al |
||
1742 | jnz after_macro_operators |
||
1743 | ret |
||
1744 | symbol_after_macro_operators: |
||
1745 | mov dl,1Ah |
||
1746 | mov ebx,edi |
||
1747 | lods byte [esi] |
||
1748 | stos byte [edi] |
||
1749 | movzx ecx,al |
||
1750 | jecxz symbol_after_macro_operatorss_ok |
||
1751 | cmp byte [esi],'\' |
||
1752 | je escaped_symbol |
||
1753 | symbol_after_macro_operatorss_ok: |
||
1754 | rep movs byte [edi],[esi] |
||
1755 | jmp after_macro_operators |
||
1756 | string_after_macro_operators: |
||
1757 | mov dl,22h |
||
1758 | mov ebx,edi |
||
1759 | lods dword [esi] |
||
1760 | stos dword [edi] |
||
1761 | mov ecx,eax |
||
1762 | rep movs byte [edi],[esi] |
||
1763 | jmp after_macro_operators |
||
1764 | |||
1765 | |||
1766 | push [free_additional_memory] |
||
1767 | push [macro_symbols] |
||
1768 | mov [macro_symbols],0 |
||
1769 | push [counter_limit] |
||
1770 | push dword [edx+4] |
||
1771 | mov dword [edx+4],1 |
||
1772 | push edx |
||
1773 | mov ebx,esi |
||
1774 | mov esi,[edx+8] |
||
1775 | mov eax,[edx+12] |
||
1776 | mov [macro_line],eax |
||
1777 | mov [counter_limit],0 |
||
1778 | xor ebp,ebp |
||
1779 | process_macro_arguments: |
||
1780 | mov al,[esi] |
||
1781 | or al,al |
||
1782 | jz arguments_end |
||
1783 | cmp al,'{' |
||
1784 | je arguments_end |
||
1785 | inc esi |
||
1786 | cmp al,'[' |
||
1787 | jne get_macro_arguments |
||
1788 | mov ebp,esi |
||
1789 | inc esi |
||
1790 | inc [counter_limit] |
||
1791 | get_macro_arguments: |
||
1792 | call get_macro_argument |
||
1793 | lods byte [esi] |
||
1794 | cmp al,',' |
||
1795 | je next_argument |
||
1796 | cmp al,']' |
||
1797 | je next_arguments_group |
||
1798 | cmp al,'&' |
||
1799 | je arguments_end |
||
1800 | dec esi |
||
1801 | jmp arguments_end |
||
1802 | next_argument: |
||
1803 | cmp byte [ebx],',' |
||
1804 | jne process_macro_arguments |
||
1805 | inc ebx |
||
1806 | jmp process_macro_arguments |
||
1807 | next_arguments_group: |
||
1808 | cmp byte [ebx],',' |
||
1809 | jne arguments_end |
||
1810 | inc ebx |
||
1811 | inc [counter_limit] |
||
1812 | mov esi,ebp |
||
1813 | jmp process_macro_arguments |
||
1814 | get_macro_argument: |
||
1815 | lods byte [esi] |
||
1816 | movzx ecx,al |
||
1817 | mov eax,[counter_limit] |
||
1818 | call add_macro_symbol |
||
1819 | add esi,ecx |
||
1820 | xor eax,eax |
||
1821 | mov [default_argument_value],eax |
||
1822 | cmp byte [esi],'*' |
||
1823 | je required_value |
||
1824 | cmp byte [esi],':' |
||
1825 | je get_default_value |
||
1826 | cmp byte [esi],'=' |
||
1827 | jne default_value_ok |
||
1828 | get_default_value: |
||
1829 | inc esi |
||
1830 | mov [default_argument_value],esi |
||
1831 | or [skip_default_argument_value],-1 |
||
1832 | call skip_macro_argument_value |
||
1833 | jmp default_value_ok |
||
1834 | required_value: |
||
1835 | inc esi |
||
1836 | or [default_argument_value],-1 |
||
1837 | default_value_ok: |
||
1838 | xchg esi,ebx |
||
1839 | mov [edx+12],esi |
||
1840 | mov [skip_default_argument_value],0 |
||
1841 | cmp byte [ebx],'&' |
||
1842 | je greedy_macro_argument |
||
1843 | call skip_macro_argument_value |
||
1844 | call finish_macro_argument |
||
1845 | jmp got_macro_argument |
||
1846 | greedy_macro_argument: |
||
1847 | call skip_foreign_line |
||
1848 | dec esi |
||
1849 | mov eax,[edx+12] |
||
1850 | mov ecx,esi |
||
1851 | sub ecx,eax |
||
1852 | mov [edx+8],ecx |
||
1853 | got_macro_argument: |
||
1854 | xchg esi,ebx |
||
1855 | cmp dword [edx+8],0 |
||
1856 | jne macro_argument_ok |
||
1857 | mov eax,[default_argument_value] |
||
1858 | or eax,eax |
||
1859 | jz macro_argument_ok |
||
1860 | cmp eax,-1 |
||
1861 | je invalid_macro_arguments |
||
1862 | mov [edx+12],eax |
||
1863 | call finish_macro_argument |
||
1864 | macro_argument_ok: |
||
1865 | ret |
||
1866 | finish_macro_argument: |
||
1867 | mov eax,[edx+12] |
||
1868 | mov ecx,esi |
||
1869 | sub ecx,eax |
||
1870 | cmp byte [eax],'<' |
||
1871 | jne argument_value_length_ok |
||
1872 | inc dword [edx+12] |
||
1873 | sub ecx,2 |
||
1874 | or ecx,80000000h |
||
1875 | argument_value_length_ok: |
||
1876 | mov [edx+8],ecx |
||
1877 | ret |
||
1878 | arguments_end: |
||
1879 | cmp byte [ebx],0 |
||
1880 | jne invalid_macro_arguments |
||
1881 | mov eax,[esp+4] |
||
1882 | dec eax |
||
1883 | call process_macro |
||
1884 | pop edx |
||
1885 | pop dword [edx+4] |
||
1886 | pop [counter_limit] |
||
1887 | pop [macro_symbols] |
||
1888 | pop [free_additional_memory] |
||
1889 | jmp line_preprocessed |
||
1890 | use_instant_macro: |
||
1891 | push edi |
||
9459 | leency | 1892 | push [current_line] |
1893 | push esi |
||
1894 | mov eax,[error_line] |
||
7836 | leency | 1895 | mov [current_line],eax |
1896 | mov [macro_line],eax |
||
1897 | mov esi,[instant_macro_start] |
||
1898 | cmp [base_code],10h |
||
1899 | jae do_match |
||
1900 | cmp [base_code],0 |
||
1901 | jne do_irp |
||
1902 | call precalculate_value |
||
1903 | cmp eax,0 |
||
1904 | jl value_out_of_range |
||
1905 | push [free_additional_memory] |
||
1906 | push [macro_symbols] |
||
1907 | mov [macro_symbols],0 |
||
1908 | push [counter_limit] |
||
1909 | mov [struc_name],0 |
||
1910 | mov [counter_limit],eax |
||
1911 | lods byte [esi] |
||
1912 | or al,al |
||
1913 | jz rept_counters_ok |
||
1914 | cmp al,'{' |
||
1915 | je rept_counters_ok |
||
1916 | cmp al,1Ah |
||
1917 | jne invalid_macro_arguments |
||
1918 | add_rept_counter: |
||
1919 | lods byte [esi] |
||
1920 | movzx ecx,al |
||
1921 | xor eax,eax |
||
1922 | call add_macro_symbol |
||
1923 | add esi,ecx |
||
1924 | xor eax,eax |
||
1925 | mov dword [edx+12],eax |
||
1926 | inc eax |
||
1927 | mov dword [edx+8],eax |
||
1928 | lods byte [esi] |
||
1929 | cmp al,':' |
||
1930 | jne rept_counter_added |
||
1931 | push edx |
||
1932 | call precalculate_value |
||
1933 | mov edx,eax |
||
1934 | add edx,[counter_limit] |
||
1935 | jo value_out_of_range |
||
1936 | pop edx |
||
1937 | mov dword [edx+8],eax |
||
1938 | lods byte [esi] |
||
1939 | rept_counter_added: |
||
1940 | cmp al,',' |
||
1941 | jne rept_counters_ok |
||
1942 | lods byte [esi] |
||
1943 | cmp al,1Ah |
||
1944 | jne invalid_macro_arguments |
||
1945 | jmp add_rept_counter |
||
1946 | rept_counters_ok: |
||
1947 | dec esi |
||
1948 | cmp [counter_limit],0 |
||
1949 | je instant_macro_finish |
||
1950 | instant_macro_parameters_ok: |
||
1951 | xor eax,eax |
||
1952 | call process_macro |
||
1953 | instant_macro_finish: |
||
1954 | pop [counter_limit] |
||
1955 | pop [macro_symbols] |
||
1956 | pop [free_additional_memory] |
||
1957 | instant_macro_done: |
||
1958 | pop ebx esi edx |
||
1959 | cmp byte [ebx],0 |
||
1960 | je line_preprocessed |
||
1961 | mov [current_line],edi |
||
1962 | mov ecx,4 |
||
1963 | rep movs dword [edi],[esi] |
||
1964 | test [macro_status],0Fh |
||
1965 | jz instant_macro_attached_line |
||
1966 | mov ax,3Bh |
||
1967 | stos word [edi] |
||
1968 | instant_macro_attached_line: |
||
1969 | mov esi,ebx |
||
1970 | sub edx,ebx |
||
1971 | mov ecx,edx |
||
1972 | call move_data |
||
1973 | jmp initial_preprocessing_ok |
||
1974 | precalculate_value: |
||
1975 | push edi |
||
1976 | call convert_expression |
||
1977 | mov al,')' |
||
1978 | stosb |
||
1979 | push esi |
||
1980 | mov esi,[esp+4] |
||
1981 | mov [error_line],0 |
||
1982 | mov [value_size],0 |
||
1983 | call calculate_expression |
||
1984 | cmp [error_line],0 |
||
1985 | je value_precalculated |
||
1986 | jmp [error] |
||
1987 | value_precalculated: |
||
1988 | mov eax,[edi] |
||
1989 | mov ecx,[edi+4] |
||
1990 | cdq |
||
1991 | cmp edx,ecx |
||
1992 | jne value_out_of_range |
||
1993 | cmp dl,[edi+13] |
||
1994 | jne value_out_of_range |
||
1995 | pop esi edi |
||
1996 | ret |
||
1997 | do_irp: |
||
1998 | cmp byte [esi],1Ah |
||
1999 | jne invalid_macro_arguments |
||
2000 | movzx eax,byte [esi+1] |
||
2001 | lea esi,[esi+2+eax] |
||
2002 | lods byte [esi] |
||
2003 | cmp [base_code],1 |
||
2004 | ja irps_name_ok |
||
2005 | cmp al,':' |
||
2006 | je irp_with_default_value |
||
2007 | cmp al,'=' |
||
2008 | je irp_with_default_value |
||
2009 | cmp al,'*' |
||
2010 | jne irp_name_ok |
||
2011 | lods byte [esi] |
||
2012 | irp_name_ok: |
||
2013 | cmp al,',' |
||
2014 | jne invalid_macro_arguments |
||
2015 | jmp irp_parameters_start |
||
2016 | irp_with_default_value: |
||
2017 | xor ebp,ebp |
||
2018 | or [skip_default_argument_value],-1 |
||
2019 | call skip_macro_argument_value |
||
2020 | cmp byte [esi],',' |
||
2021 | jne invalid_macro_arguments |
||
2022 | inc esi |
||
2023 | jmp irp_parameters_start |
||
2024 | irps_name_ok: |
||
2025 | cmp al,',' |
||
2026 | jne invalid_macro_arguments |
||
2027 | cmp [base_code],3 |
||
2028 | je irp_parameters_start |
||
2029 | mov al,[esi] |
||
2030 | or al,al |
||
2031 | jz instant_macro_done |
||
2032 | cmp al,'{' |
||
2033 | je instant_macro_done |
||
2034 | irp_parameters_start: |
||
2035 | xor eax,eax |
||
2036 | push [free_additional_memory] |
||
2037 | push [macro_symbols] |
||
2038 | mov [macro_symbols],eax |
||
2039 | push [counter_limit] |
||
2040 | mov [counter_limit],eax |
||
2041 | mov [struc_name],eax |
||
2042 | cmp [base_code],3 |
||
2043 | je get_irpv_parameter |
||
2044 | mov ebx,esi |
||
2045 | cmp [base_code],2 |
||
2046 | je get_irps_parameter |
||
2047 | mov edx,[parameters_end] |
||
2048 | mov al,[edx] |
||
2049 | push eax |
||
2050 | mov byte [edx],0 |
||
2051 | get_irp_parameter: |
||
2052 | inc [counter_limit] |
||
2053 | mov esi,[instant_macro_start] |
||
2054 | inc esi |
||
2055 | call get_macro_argument |
||
2056 | cmp byte [ebx],',' |
||
2057 | jne irp_parameters_end |
||
2058 | inc ebx |
||
2059 | jmp get_irp_parameter |
||
2060 | irp_parameters_end: |
||
2061 | mov esi,ebx |
||
2062 | pop eax |
||
2063 | mov [esi],al |
||
2064 | jmp instant_macro_parameters_ok |
||
2065 | get_irps_parameter: |
||
2066 | mov esi,[instant_macro_start] |
||
2067 | inc esi |
||
2068 | lods byte [esi] |
||
2069 | movzx ecx,al |
||
2070 | inc [counter_limit] |
||
2071 | mov eax,[counter_limit] |
||
2072 | call add_macro_symbol |
||
2073 | mov [edx+12],ebx |
||
2074 | cmp byte [ebx],1Ah |
||
2075 | je irps_symbol |
||
2076 | cmp byte [ebx],22h |
||
2077 | je irps_quoted_string |
||
2078 | mov eax,1 |
||
2079 | jmp irps_parameter_ok |
||
2080 | irps_quoted_string: |
||
2081 | mov eax,[ebx+1] |
||
2082 | add eax,1+4 |
||
2083 | jmp irps_parameter_ok |
||
2084 | irps_symbol: |
||
2085 | movzx eax,byte [ebx+1] |
||
2086 | add eax,1+1 |
||
2087 | irps_parameter_ok: |
||
2088 | mov [edx+8],eax |
||
2089 | add ebx,eax |
||
2090 | cmp byte [ebx],0 |
||
2091 | je irps_parameters_end |
||
2092 | cmp byte [ebx],'{' |
||
2093 | jne get_irps_parameter |
||
2094 | irps_parameters_end: |
||
2095 | mov esi,ebx |
||
2096 | jmp instant_macro_parameters_ok |
||
2097 | get_irpv_parameter: |
||
2098 | lods byte [esi] |
||
2099 | cmp al,1Ah |
||
2100 | jne invalid_macro_arguments |
||
2101 | lods byte [esi] |
||
2102 | mov ebp,esi |
||
2103 | mov cl,al |
||
2104 | mov ch,10b |
||
2105 | call get_preprocessor_symbol |
||
2106 | jc instant_macro_finish |
||
2107 | test edx,edx |
||
9459 | leency | 2108 | jz invalid_use_of_symbol |
2109 | push edx |
||
7836 | leency | 2110 | mark_variable_value: |
2111 | inc [counter_limit] |
||
2112 | mov [edx+4],ebp |
||
2113 | next_variable_value: |
||
2114 | mov edx,[edx] |
||
2115 | or edx,edx |
||
2116 | jz variable_values_marked |
||
2117 | mov eax,[edx+4] |
||
2118 | cmp eax,1 |
||
2119 | jbe next_variable_value |
||
2120 | mov esi,ebp |
||
2121 | movzx ecx,byte [esi-1] |
||
2122 | xchg edi,eax |
||
2123 | repe cmps byte [esi],[edi] |
||
2124 | xchg edi,eax |
||
2125 | je mark_variable_value |
||
2126 | jmp next_variable_value |
||
2127 | variable_values_marked: |
||
2128 | pop edx |
||
2129 | push [counter_limit] |
||
2130 | add_irpv_value: |
||
2131 | push edx |
||
2132 | mov esi,[instant_macro_start] |
||
2133 | inc esi |
||
2134 | lods byte [esi] |
||
2135 | movzx ecx,al |
||
2136 | mov eax,[esp+4] |
||
2137 | call add_macro_symbol |
||
2138 | mov ebx,edx |
||
2139 | pop edx |
||
2140 | mov ecx,[edx+12] |
||
2141 | mov eax,[edx+8] |
||
2142 | mov [ebx+12],eax |
||
2143 | mov [ebx+8],ecx |
||
2144 | collect_next_variable_value: |
||
2145 | mov edx,[edx] |
||
2146 | or edx,edx |
||
2147 | jz variable_values_collected |
||
2148 | cmp ebp,[edx+4] |
||
2149 | jne collect_next_variable_value |
||
2150 | dec dword [esp] |
||
2151 | jnz add_irpv_value |
||
2152 | variable_values_collected: |
||
2153 | pop eax |
||
2154 | mov esi,ebp |
||
2155 | movzx ecx,byte [esi-1] |
||
2156 | add esi,ecx |
||
2157 | cmp byte [esi],0 |
||
2158 | je instant_macro_parameters_ok |
||
2159 | cmp byte [esi],'{' |
||
2160 | jne invalid_macro_arguments |
||
2161 | jmp instant_macro_parameters_ok |
||
2162 | |||
2163 | |||
2164 | mov ebx,esi |
||
2165 | call skip_pattern |
||
2166 | call exact_match |
||
2167 | mov edx,edi |
||
2168 | mov al,[ebx] |
||
2169 | cmp al,1Ah |
||
2170 | je free_match |
||
2171 | cmp al,',' |
||
2172 | jne instant_macro_done |
||
2173 | cmp esi,[parameters_end] |
||
2174 | je matched_pattern |
||
2175 | jmp instant_macro_done |
||
2176 | free_match: |
||
2177 | add edx,12 |
||
2178 | cmp edx,[memory_end] |
||
2179 | ja out_of_memory |
||
2180 | mov [edx-12],ebx |
||
2181 | mov [edx-8],esi |
||
2182 | call skip_match_element |
||
2183 | jc try_different_matching |
||
2184 | mov [edx-4],esi |
||
2185 | movzx eax,byte [ebx+1] |
||
2186 | lea ebx,[ebx+2+eax] |
||
2187 | cmp byte [ebx],1Ah |
||
2188 | je free_match |
||
2189 | find_exact_match: |
||
2190 | call exact_match |
||
2191 | cmp esi,[parameters_end] |
||
2192 | je end_matching |
||
2193 | cmp byte [ebx],1Ah |
||
2194 | je free_match |
||
2195 | mov ebx,[edx-12] |
||
2196 | movzx eax,byte [ebx+1] |
||
2197 | lea ebx,[ebx+2+eax] |
||
2198 | mov esi,[edx-4] |
||
2199 | jmp match_more_elements |
||
2200 | try_different_matching: |
||
2201 | sub edx,12 |
||
2202 | cmp edx,edi |
||
2203 | je instant_macro_done |
||
2204 | mov ebx,[edx-12] |
||
2205 | movzx eax,byte [ebx+1] |
||
2206 | lea ebx,[ebx+2+eax] |
||
2207 | cmp byte [ebx],1Ah |
||
2208 | je try_different_matching |
||
2209 | mov esi,[edx-4] |
||
2210 | match_more_elements: |
||
2211 | call skip_match_element |
||
2212 | jc try_different_matching |
||
2213 | mov [edx-4],esi |
||
2214 | jmp find_exact_match |
||
2215 | skip_match_element: |
||
2216 | cmp esi,[parameters_end] |
||
2217 | je cannot_match |
||
2218 | mov al,[esi] |
||
2219 | cmp al,1Ah |
||
2220 | je skip_match_symbol |
||
2221 | cmp al,22h |
||
2222 | je skip_match_quoted_string |
||
2223 | add esi,1 |
||
2224 | ret |
||
2225 | skip_match_quoted_string: |
||
2226 | mov eax,[esi+1] |
||
2227 | add esi,5 |
||
2228 | jmp skip_match_ok |
||
2229 | skip_match_symbol: |
||
2230 | movzx eax,byte [esi+1] |
||
2231 | add esi,2 |
||
2232 | skip_match_ok: |
||
2233 | add esi,eax |
||
2234 | ret |
||
2235 | cannot_match: |
||
2236 | stc |
||
2237 | ret |
||
2238 | exact_match: |
||
2239 | cmp esi,[parameters_end] |
||
2240 | je exact_match_complete |
||
2241 | mov ah,[esi] |
||
2242 | mov al,[ebx] |
||
2243 | cmp al,',' |
||
2244 | je exact_match_complete |
||
2245 | cmp al,1Ah |
||
2246 | je exact_match_complete |
||
2247 | cmp al,'=' |
||
2248 | je match_verbatim |
||
2249 | call match_elements |
||
2250 | je exact_match |
||
2251 | exact_match_complete: |
||
2252 | ret |
||
2253 | match_verbatim: |
||
2254 | inc ebx |
||
2255 | call match_elements |
||
2256 | je exact_match |
||
2257 | dec ebx |
||
2258 | ret |
||
2259 | match_elements: |
||
2260 | mov al,[ebx] |
||
2261 | cmp al,1Ah |
||
2262 | je match_symbols |
||
2263 | cmp al,22h |
||
2264 | je match_quoted_strings |
||
2265 | cmp al,ah |
||
2266 | je symbol_characters_matched |
||
2267 | ret |
||
2268 | symbol_characters_matched: |
||
2269 | lea ebx,[ebx+1] |
||
2270 | lea esi,[esi+1] |
||
2271 | ret |
||
2272 | match_quoted_strings: |
||
2273 | mov ecx,[ebx+1] |
||
2274 | add ecx,5 |
||
2275 | jmp compare_elements |
||
2276 | match_symbols: |
||
2277 | movzx ecx,byte [ebx+1] |
||
2278 | add ecx,2 |
||
2279 | compare_elements: |
||
2280 | mov eax,esi |
||
2281 | mov ebp,edi |
||
2282 | mov edi,ebx |
||
2283 | repe cmps byte [esi],[edi] |
||
2284 | jne elements_mismatch |
||
2285 | mov ebx,edi |
||
2286 | mov edi,ebp |
||
2287 | ret |
||
2288 | elements_mismatch: |
||
2289 | mov esi,eax |
||
2290 | mov edi,ebp |
||
2291 | ret |
||
2292 | end_matching: |
||
2293 | cmp byte [ebx],',' |
||
2294 | jne instant_macro_done |
||
2295 | matched_pattern: |
||
2296 | xor eax,eax |
||
2297 | push [free_additional_memory] |
||
2298 | push [macro_symbols] |
||
2299 | mov [macro_symbols],eax |
||
2300 | push [counter_limit] |
||
2301 | mov [counter_limit],eax |
||
2302 | mov [struc_name],eax |
||
2303 | push esi edi edx |
||
2304 | add_matched_symbol: |
||
2305 | cmp edi,[esp] |
||
2306 | je matched_symbols_ok |
||
2307 | mov esi,[edi] |
||
2308 | inc esi |
||
2309 | lods byte [esi] |
||
2310 | movzx ecx,al |
||
2311 | xor eax,eax |
||
2312 | call add_macro_symbol |
||
2313 | mov eax,[edi+4] |
||
2314 | mov dword [edx+12],eax |
||
2315 | mov ecx,[edi+8] |
||
2316 | sub ecx,eax |
||
2317 | mov dword [edx+8],ecx |
||
2318 | add edi,12 |
||
2319 | jmp add_matched_symbol |
||
2320 | matched_symbols_ok: |
||
2321 | pop edx edi esi |
||
2322 | jmp instant_macro_parameters_ok |
||
2323 | |||
2324 | |||
2325 | push dword [macro_status] |
||
2326 | or [macro_status],10h |
||
2327 | push [counter] |
||
2328 | push [macro_block] |
||
2329 | push [macro_block_line] |
||
2330 | push [macro_block_line_number] |
||
2331 | push [struc_label] |
||
2332 | push [struc_name] |
||
2333 | push eax |
||
2334 | push [current_line] |
||
2335 | lods byte [esi] |
||
2336 | cmp al,'{' |
||
2337 | je macro_instructions_start |
||
2338 | or al,al |
||
2339 | jnz unexpected_characters |
||
2340 | find_macro_instructions: |
||
2341 | mov [macro_line],esi |
||
2342 | add esi,16+2 |
||
2343 | lods byte [esi] |
||
2344 | or al,al |
||
2345 | jz find_macro_instructions |
||
2346 | cmp al,'{' |
||
2347 | je macro_instructions_start |
||
2348 | cmp al,3Bh |
||
2349 | jne unexpected_characters |
||
2350 | call skip_foreign_symbol |
||
2351 | jmp find_macro_instructions |
||
2352 | macro_instructions_start: |
||
2353 | mov ecx,80000000h |
||
2354 | mov [macro_block],esi |
||
2355 | mov eax,[macro_line] |
||
2356 | mov [macro_block_line],eax |
||
2357 | mov [macro_block_line_number],ecx |
||
2358 | xor eax,eax |
||
2359 | mov [counter],eax |
||
2360 | cmp [counter_limit],eax |
||
2361 | je process_macro_line |
||
2362 | inc [counter] |
||
2363 | process_macro_line: |
||
2364 | lods byte [esi] |
||
2365 | or al,al |
||
2366 | jz process_next_line |
||
2367 | cmp al,'}' |
||
2368 | je macro_block_processed |
||
2369 | dec esi |
||
2370 | mov [current_line],edi |
||
2371 | lea eax,[edi+10h] |
||
2372 | cmp eax,[memory_end] |
||
2373 | jae out_of_memory |
||
2374 | mov eax,[esp+4] |
||
2375 | or eax,eax |
||
2376 | jz instant_macro_line_header |
||
2377 | stos dword [edi] |
||
2378 | mov eax,ecx |
||
2379 | stos dword [edi] |
||
2380 | mov eax,[esp] |
||
2381 | stos dword [edi] |
||
2382 | mov eax,[macro_line] |
||
2383 | stos dword [edi] |
||
2384 | jmp macro_line_header_ok |
||
2385 | instant_macro_line_header: |
||
2386 | mov eax,[esp] |
||
2387 | add eax,16 |
||
2388 | find_defining_directive: |
||
2389 | inc eax |
||
2390 | cmp byte [eax-1],3Bh |
||
2391 | je defining_directive_ok |
||
2392 | cmp byte [eax-1],1Ah |
||
2393 | jne find_defining_directive |
||
2394 | push eax |
||
2395 | movzx eax,byte [eax] |
||
2396 | inc eax |
||
2397 | add [esp],eax |
||
2398 | pop eax |
||
2399 | jmp find_defining_directive |
||
2400 | defining_directive_ok: |
||
2401 | stos dword [edi] |
||
2402 | mov eax,ecx |
||
2403 | stos dword [edi] |
||
2404 | mov eax,[macro_line] |
||
2405 | stos dword [edi] |
||
2406 | stos dword [edi] |
||
2407 | macro_line_header_ok: |
||
2408 | or [macro_status],20h |
||
2409 | push ebx ecx |
||
2410 | test [macro_status],0Fh |
||
2411 | jz process_macro_line_element |
||
2412 | mov ax,3Bh |
||
2413 | stos word [edi] |
||
2414 | process_macro_line_element: |
||
2415 | lea eax,[edi+100h] |
||
2416 | cmp eax,[memory_end] |
||
2417 | jae out_of_memory |
||
2418 | lods byte [esi] |
||
2419 | cmp al,'}' |
||
2420 | je macro_line_processed |
||
2421 | or al,al |
||
2422 | jz macro_line_processed |
||
2423 | cmp al,1Ah |
||
2424 | je process_macro_symbol |
||
2425 | cmp al,3Bh |
||
2426 | je macro_foreign_line |
||
2427 | and [macro_status],not 20h |
||
2428 | stos byte [edi] |
||
2429 | cmp al,22h |
||
2430 | jne process_macro_line_element |
||
2431 | copy_macro_string: |
||
2432 | mov ecx,[esi] |
||
2433 | add ecx,4 |
||
2434 | call move_data |
||
2435 | jmp process_macro_line_element |
||
2436 | process_macro_symbol: |
||
2437 | push esi edi |
||
2438 | test [macro_status],20h |
||
2439 | jz not_macro_directive |
||
2440 | movzx ecx,byte [esi] |
||
2441 | inc esi |
||
2442 | mov edi,macro_directives |
||
2443 | call get_directive |
||
2444 | jnc process_macro_directive |
||
2445 | dec esi |
||
2446 | jmp not_macro_directive |
||
2447 | process_macro_directive: |
||
2448 | mov edx,eax |
||
2449 | pop edi eax |
||
2450 | mov byte [edi],0 |
||
2451 | inc edi |
||
2452 | pop ecx ebx |
||
2453 | jmp near edx |
||
2454 | not_macro_directive: |
||
2455 | and [macro_status],not 20h |
||
2456 | movzx ecx,byte [esi] |
||
2457 | inc esi |
||
2458 | mov eax,[counter] |
||
2459 | call get_macro_symbol |
||
2460 | jnc group_macro_symbol |
||
2461 | xor eax,eax |
||
2462 | cmp [counter],eax |
||
2463 | je multiple_macro_symbol_values |
||
2464 | call get_macro_symbol |
||
2465 | jc not_macro_symbol |
||
2466 | replace_macro_symbol: |
||
2467 | pop edi eax |
||
2468 | mov ecx,[edx+8] |
||
2469 | mov edx,[edx+12] |
||
2470 | or edx,edx |
||
2471 | jz replace_macro_counter |
||
2472 | and ecx,not 80000000h |
||
2473 | xchg esi,edx |
||
2474 | call move_data |
||
2475 | mov esi,edx |
||
2476 | jmp process_macro_line_element |
||
2477 | group_macro_symbol: |
||
2478 | xor eax,eax |
||
2479 | cmp [counter],eax |
||
2480 | je replace_macro_symbol |
||
2481 | push esi edx |
||
2482 | sub esi,ecx |
||
2483 | call get_macro_symbol |
||
2484 | mov ebx,edx |
||
2485 | pop edx esi |
||
2486 | jc replace_macro_symbol |
||
2487 | cmp edx,ebx |
||
2488 | ja replace_macro_symbol |
||
2489 | mov edx,ebx |
||
2490 | jmp replace_macro_symbol |
||
2491 | multiple_macro_symbol_values: |
||
2492 | inc eax |
||
2493 | push eax |
||
2494 | call get_macro_symbol |
||
2495 | pop eax |
||
2496 | jc not_macro_symbol |
||
2497 | pop edi |
||
2498 | push ecx |
||
2499 | mov ecx,[edx+8] |
||
2500 | mov edx,[edx+12] |
||
2501 | xchg esi,edx |
||
2502 | btr ecx,31 |
||
2503 | jc enclose_macro_symbol_value |
||
2504 | rep movs byte [edi],[esi] |
||
2505 | jmp macro_symbol_value_ok |
||
2506 | enclose_macro_symbol_value: |
||
2507 | mov byte [edi],'<' |
||
2508 | inc edi |
||
2509 | rep movs byte [edi],[esi] |
||
2510 | mov byte [edi],'>' |
||
2511 | inc edi |
||
2512 | macro_symbol_value_ok: |
||
2513 | cmp eax,[counter_limit] |
||
2514 | je multiple_macro_symbol_values_ok |
||
2515 | mov byte [edi],',' |
||
2516 | inc edi |
||
2517 | mov esi,edx |
||
2518 | pop ecx |
||
2519 | push edi |
||
2520 | sub esi,ecx |
||
2521 | jmp multiple_macro_symbol_values |
||
2522 | multiple_macro_symbol_values_ok: |
||
2523 | pop ecx eax |
||
2524 | mov esi,edx |
||
2525 | jmp process_macro_line_element |
||
2526 | replace_macro_counter: |
||
2527 | mov eax,[counter] |
||
2528 | and eax,not 80000000h |
||
2529 | jz group_macro_counter |
||
2530 | add ecx,eax |
||
2531 | dec ecx |
||
2532 | call store_number_symbol |
||
2533 | jmp process_macro_line_element |
||
2534 | group_macro_counter: |
||
2535 | mov edx,ecx |
||
2536 | xor ecx,ecx |
||
2537 | multiple_macro_counter_values: |
||
2538 | push ecx edx |
||
2539 | add ecx,edx |
||
2540 | call store_number_symbol |
||
2541 | pop edx ecx |
||
2542 | inc ecx |
||
2543 | cmp ecx,[counter_limit] |
||
2544 | je process_macro_line_element |
||
2545 | mov byte [edi],',' |
||
2546 | inc edi |
||
2547 | jmp multiple_macro_counter_values |
||
2548 | store_number_symbol: |
||
2549 | cmp ecx,0 |
||
2550 | jge numer_symbol_sign_ok |
||
2551 | neg ecx |
||
2552 | mov al,'-' |
||
2553 | stos byte [edi] |
||
2554 | numer_symbol_sign_ok: |
||
2555 | mov ax,1Ah |
||
2556 | stos word [edi] |
||
2557 | push edi |
||
2558 | mov eax,ecx |
||
2559 | mov ecx,1000000000 |
||
2560 | xor edx,edx |
||
2561 | xor bl,bl |
||
2562 | store_number_digits: |
||
2563 | div ecx |
||
2564 | push edx |
||
2565 | or bl,bl |
||
2566 | jnz store_number_digit |
||
2567 | cmp ecx,1 |
||
2568 | je store_number_digit |
||
2569 | or al,al |
||
2570 | jz number_digit_ok |
||
2571 | not bl |
||
2572 | store_number_digit: |
||
2573 | add al,30h |
||
2574 | stos byte [edi] |
||
2575 | number_digit_ok: |
||
2576 | mov eax,ecx |
||
2577 | xor edx,edx |
||
2578 | mov ecx,10 |
||
2579 | div ecx |
||
2580 | mov ecx,eax |
||
2581 | pop eax |
||
2582 | or ecx,ecx |
||
2583 | jnz store_number_digits |
||
2584 | pop ebx |
||
2585 | mov eax,edi |
||
2586 | sub eax,ebx |
||
2587 | mov [ebx-1],al |
||
2588 | ret |
||
2589 | not_macro_symbol: |
||
2590 | pop edi esi |
||
2591 | mov al,1Ah |
||
2592 | stos byte [edi] |
||
2593 | mov al,[esi] |
||
2594 | inc esi |
||
2595 | stos byte [edi] |
||
2596 | cmp byte [esi],'.' |
||
2597 | jne copy_raw_symbol |
||
2598 | mov ebx,[esp+8+8] |
||
2599 | or ebx,ebx |
||
2600 | jz copy_raw_symbol |
||
2601 | cmp al,1 |
||
2602 | je copy_struc_name |
||
2603 | xchg esi,ebx |
||
2604 | movzx ecx,byte [esi-1] |
||
2605 | add [edi-1],cl |
||
2606 | jc name_too_long |
||
2607 | rep movs byte [edi],[esi] |
||
2608 | xchg esi,ebx |
||
2609 | copy_raw_symbol: |
||
2610 | movzx ecx,al |
||
2611 | rep movs byte [edi],[esi] |
||
2612 | jmp process_macro_line_element |
||
2613 | copy_struc_name: |
||
2614 | inc esi |
||
2615 | xchg esi,ebx |
||
2616 | movzx ecx,byte [esi-1] |
||
2617 | mov [edi-1],cl |
||
2618 | rep movs byte [edi],[esi] |
||
2619 | xchg esi,ebx |
||
2620 | mov eax,[esp+8+12] |
||
2621 | cmp byte [eax],3Bh |
||
2622 | je process_macro_line_element |
||
2623 | cmp byte [eax],1Ah |
||
2624 | jne disable_replaced_struc_name |
||
2625 | mov byte [eax],3Bh |
||
2626 | jmp process_macro_line_element |
||
2627 | disable_replaced_struc_name: |
||
2628 | mov ebx,[esp+8+8] |
||
2629 | push esi edi |
||
2630 | lea edi,[ebx-3] |
||
2631 | lea esi,[edi-2] |
||
2632 | lea ecx,[esi+1] |
||
2633 | sub ecx,eax |
||
2634 | std |
||
2635 | rep movs byte [edi],[esi] |
||
2636 | cld |
||
2637 | mov word [eax],3Bh |
||
2638 | pop edi esi |
||
2639 | jmp process_macro_line_element |
||
2640 | skip_foreign_symbol: |
||
2641 | lods byte [esi] |
||
2642 | movzx eax,al |
||
2643 | add esi,eax |
||
2644 | skip_foreign_line: |
||
2645 | lods byte [esi] |
||
2646 | cmp al,1Ah |
||
2647 | je skip_foreign_symbol |
||
2648 | cmp al,3Bh |
||
2649 | je skip_foreign_symbol |
||
2650 | cmp al,22h |
||
2651 | je skip_foreign_string |
||
2652 | or al,al |
||
2653 | jnz skip_foreign_line |
||
2654 | ret |
||
2655 | skip_foreign_string: |
||
2656 | lods dword [esi] |
||
2657 | add esi,eax |
||
2658 | jmp skip_foreign_line |
||
2659 | macro_foreign_line: |
||
2660 | call skip_foreign_symbol |
||
2661 | macro_line_processed: |
||
2662 | mov byte [edi],0 |
||
2663 | inc edi |
||
2664 | push eax |
||
2665 | call preprocess_line |
||
2666 | pop eax |
||
2667 | pop ecx ebx |
||
2668 | cmp al,'}' |
||
2669 | je macro_block_processed |
||
2670 | process_next_line: |
||
2671 | inc ecx |
||
2672 | mov [macro_line],esi |
||
2673 | add esi,16+2 |
||
2674 | jmp process_macro_line |
||
2675 | macro_block_processed: |
||
2676 | call close_macro_block |
||
2677 | jc process_macro_line |
||
2678 | pop [current_line] |
||
2679 | add esp,12 |
||
2680 | pop [macro_block_line_number] |
||
2681 | pop [macro_block_line] |
||
2682 | pop [macro_block] |
||
2683 | pop [counter] |
||
2684 | pop eax |
||
2685 | and al,0F0h |
||
2686 | and [macro_status],0Fh |
||
2687 | or [macro_status],al |
||
2688 | ret |
||
2689 | |||
2690 | |||
2691 | lods byte [esi] |
||
2692 | cmp al,1Ah |
||
2693 | jne invalid_argument |
||
2694 | mov byte [edi-1],3Bh |
||
2695 | xor al,al |
||
2696 | stos byte [edi] |
||
2697 | make_local_symbol: |
||
2698 | push ecx |
||
2699 | lods byte [esi] |
||
2700 | movzx ecx,al |
||
2701 | mov eax,[counter] |
||
2702 | call add_macro_symbol |
||
2703 | mov [edx+12],edi |
||
2704 | movzx eax,[locals_counter] |
||
2705 | add eax,ecx |
||
2706 | inc eax |
||
2707 | cmp eax,100h |
||
2708 | jae name_too_long |
||
2709 | lea ebp,[edi+2+eax] |
||
2710 | cmp ebp,[memory_end] |
||
2711 | jae out_of_memory |
||
2712 | mov ah,al |
||
2713 | mov al,1Ah |
||
2714 | stos word [edi] |
||
2715 | rep movs byte [edi],[esi] |
||
2716 | mov al,'?' |
||
2717 | stos byte [edi] |
||
2718 | push esi |
||
2719 | mov esi,locals_counter+1 |
||
2720 | movzx ecx,[locals_counter] |
||
2721 | rep movs byte [edi],[esi] |
||
2722 | pop esi |
||
2723 | mov eax,edi |
||
2724 | sub eax,[edx+12] |
||
2725 | mov [edx+8],eax |
||
2726 | xor al,al |
||
2727 | stos byte [edi] |
||
2728 | mov eax,locals_counter |
||
2729 | movzx ecx,byte [eax] |
||
2730 | counter_loop: |
||
2731 | inc byte [eax+ecx] |
||
2732 | cmp byte [eax+ecx],'9'+1 |
||
2733 | jb counter_ok |
||
2734 | jne letter_digit |
||
2735 | mov byte [eax+ecx],'A' |
||
2736 | jmp counter_ok |
||
2737 | letter_digit: |
||
2738 | cmp byte [eax+ecx],'Z'+1 |
||
2739 | jb counter_ok |
||
2740 | jne small_letter_digit |
||
2741 | mov byte [eax+ecx],'a' |
||
2742 | jmp counter_ok |
||
2743 | small_letter_digit: |
||
2744 | cmp byte [eax+ecx],'z'+1 |
||
2745 | jb counter_ok |
||
2746 | mov byte [eax+ecx],'0' |
||
2747 | loop counter_loop |
||
2748 | inc byte [eax] |
||
2749 | movzx ecx,byte [eax] |
||
2750 | mov byte [eax+ecx],'0' |
||
2751 | counter_ok: |
||
2752 | pop ecx |
||
2753 | lods byte [esi] |
||
2754 | cmp al,'}' |
||
2755 | je macro_block_processed |
||
2756 | or al,al |
||
2757 | jz process_next_line |
||
2758 | cmp al,',' |
||
2759 | jne extra_characters_on_line |
||
2760 | dec edi |
||
2761 | lods byte [esi] |
||
2762 | cmp al,1Ah |
||
2763 | je make_local_symbol |
||
2764 | jmp invalid_argument |
||
2765 | common_block: |
||
2766 | call close_macro_block |
||
2767 | jc process_macro_line |
||
2768 | mov [counter],0 |
||
2769 | jmp new_macro_block |
||
2770 | forward_block: |
||
2771 | cmp [counter_limit],0 |
||
2772 | je common_block |
||
2773 | call close_macro_block |
||
2774 | jc process_macro_line |
||
2775 | mov [counter],1 |
||
2776 | jmp new_macro_block |
||
2777 | reverse_block: |
||
2778 | cmp [counter_limit],0 |
||
2779 | je common_block |
||
2780 | call close_macro_block |
||
2781 | jc process_macro_line |
||
2782 | mov eax,[counter_limit] |
||
2783 | or eax,80000000h |
||
2784 | mov [counter],eax |
||
2785 | new_macro_block: |
||
2786 | mov [macro_block],esi |
||
2787 | mov eax,[macro_line] |
||
2788 | mov [macro_block_line],eax |
||
2789 | mov [macro_block_line_number],ecx |
||
2790 | jmp process_macro_line |
||
2791 | close_macro_block: |
||
2792 | cmp esi,[macro_block] |
||
2793 | je block_closed |
||
2794 | cmp [counter],0 |
||
2795 | je block_closed |
||
2796 | jl reverse_counter |
||
2797 | mov eax,[counter] |
||
2798 | cmp eax,[counter_limit] |
||
2799 | je block_closed |
||
2800 | inc [counter] |
||
2801 | jmp continue_block |
||
2802 | reverse_counter: |
||
2803 | mov eax,[counter] |
||
2804 | dec eax |
||
2805 | cmp eax,80000000h |
||
2806 | je block_closed |
||
2807 | mov [counter],eax |
||
2808 | continue_block: |
||
2809 | mov esi,[macro_block] |
||
2810 | mov eax,[macro_block_line] |
||
2811 | mov [macro_line],eax |
||
2812 | mov ecx,[macro_block_line_number] |
||
2813 | stc |
||
2814 | ret |
||
2815 | block_closed: |
||
2816 | clc |
||
2817 | ret |
||
2818 | get_macro_symbol: |
||
2819 | push ecx |
||
2820 | call find_macro_symbol_leaf |
||
2821 | jc macro_symbol_not_found |
||
2822 | mov edx,[ebx] |
||
2823 | mov ebx,esi |
||
2824 | try_macro_symbol: |
||
2825 | or edx,edx |
||
2826 | jz macro_symbol_not_found |
||
2827 | mov ecx,[esp] |
||
2828 | mov edi,[edx+4] |
||
2829 | repe cmps byte [esi],[edi] |
||
2830 | je macro_symbol_found |
||
2831 | mov esi,ebx |
||
2832 | mov edx,[edx] |
||
2833 | jmp try_macro_symbol |
||
2834 | macro_symbol_found: |
||
2835 | pop ecx |
||
2836 | clc |
||
2837 | ret |
||
2838 | macro_symbol_not_found: |
||
2839 | pop ecx |
||
2840 | stc |
||
2841 | ret |
||
2842 | find_macro_symbol_leaf: |
||
2843 | shl eax,8 |
||
2844 | mov al,cl |
||
2845 | mov ebp,eax |
||
2846 | mov ebx,macro_symbols |
||
2847 | follow_macro_symbols_tree: |
||
2848 | mov edx,[ebx] |
||
2849 | or edx,edx |
||
2850 | jz no_such_macro_symbol |
||
2851 | xor eax,eax |
||
2852 | shr ebp,1 |
||
2853 | adc eax,0 |
||
2854 | lea ebx,[edx+eax*4] |
||
2855 | or ebp,ebp |
||
2856 | jnz follow_macro_symbols_tree |
||
2857 | add ebx,8 |
||
2858 | clc |
||
2859 | ret |
||
2860 | no_such_macro_symbol: |
||
2861 | stc |
||
2862 | ret |
||
2863 | add_macro_symbol: |
||
2864 | push ebx ebp |
||
2865 | call find_macro_symbol_leaf |
||
2866 | jc extend_macro_symbol_tree |
||
2867 | mov eax,[ebx] |
||
2868 | make_macro_symbol: |
||
2869 | mov edx,[free_additional_memory] |
||
2870 | add edx,16 |
||
2871 | cmp edx,[labels_list] |
||
2872 | ja out_of_memory |
||
2873 | xchg edx,[free_additional_memory] |
||
2874 | mov [ebx],edx |
||
2875 | mov [edx],eax |
||
2876 | mov [edx+4],esi |
||
2877 | pop ebp ebx |
||
2878 | ret |
||
2879 | extend_macro_symbol_tree: |
||
2880 | mov edx,[free_additional_memory] |
||
2881 | add edx,16 |
||
2882 | cmp edx,[labels_list] |
||
2883 | ja out_of_memory |
||
2884 | xchg edx,[free_additional_memory] |
||
2885 | xor eax,eax |
||
2886 | mov [edx],eax |
||
2887 | mov [edx+4],eax |
||
2888 | mov [edx+8],eax |
||
2889 | mov [edx+12],eax |
||
2890 | shr ebp,1 |
||
2891 | adc eax,0 |
||
2892 | mov [ebx],edx |
||
2893 | lea ebx,[edx+eax*4] |
||
2894 | or ebp,ebp |
||
2895 | jnz extend_macro_symbol_tree |
||
2896 | add ebx,8 |
||
2897 | xor eax,eax |
||
2898 | jmp make_macro_symbol |
||
2899 | |||
2900 | |||
2901 | lods byte [esi] |
||
2902 | cmp al,22h |
||
2903 | jne invalid_argument |
||
2904 | lods dword [esi] |
||
2905 | cmp byte [esi+eax],0 |
||
2906 | jne extra_characters_on_line |
||
2907 | push esi |
||
2908 | push edi |
||
2909 | mov ebx,[current_line] |
||
2910 | find_current_file_path: |
||
2911 | mov esi,[ebx] |
||
2912 | test byte [ebx+7],80h |
||
2913 | jz copy_current_file_path |
||
2914 | mov ebx,[ebx+8] |
||
2915 | jmp find_current_file_path |
||
2916 | copy_current_file_path: |
||
2917 | lods byte [esi] |
||
2918 | stos byte [edi] |
||
2919 | or al,al |
||
2920 | jnz copy_current_file_path |
||
2921 | cut_current_file_name: |
||
2922 | cmp edi,[esp] |
||
2923 | je current_file_path_ok |
||
2924 | cmp byte [edi-1],'\' |
||
2925 | je current_file_path_ok |
||
2926 | cmp byte [edi-1],'/' |
||
2927 | je current_file_path_ok |
||
2928 | dec edi |
||
2929 | jmp cut_current_file_name |
||
2930 | current_file_path_ok: |
||
2931 | mov esi,[esp+4] |
||
2932 | call expand_path |
||
2933 | pop edx |
||
2934 | mov esi,edx |
||
2935 | call open |
||
2936 | jnc include_path_ok |
||
2937 | mov ebp,[include_paths] |
||
2938 | try_include_directories: |
||
2939 | mov edi,esi |
||
2940 | mov esi,ebp |
||
2941 | cmp byte [esi],0 |
||
2942 | je try_in_current_directory |
||
2943 | push ebp |
||
2944 | push edi |
||
2945 | call get_include_directory |
||
2946 | mov [esp+4],esi |
||
2947 | mov esi,[esp+8] |
||
2948 | call expand_path |
||
2949 | pop edx |
||
2950 | mov esi,edx |
||
2951 | call open |
||
2952 | pop ebp |
||
2953 | jnc include_path_ok |
||
2954 | jmp try_include_directories |
||
2955 | mov edi,esi |
||
2956 | try_in_current_directory: |
||
2957 | mov esi,[esp] |
||
2958 | push edi |
||
2959 | call expand_path |
||
2960 | pop edx |
||
2961 | mov esi,edx |
||
2962 | call open |
||
2963 | jc file_not_found |
||
2964 | include_path_ok: |
||
2965 | mov edi,[esp] |
||
2966 | copy_preprocessed_path: |
||
2967 | lods byte [esi] |
||
2968 | stos byte [edi] |
||
2969 | or al,al |
||
2970 | jnz copy_preprocessed_path |
||
2971 | pop esi |
||
2972 | lea ecx,[edi-1] |
||
2973 | sub ecx,esi |
||
2974 | mov [esi-4],ecx |
||
2975 | push dword [macro_status] |
||
2976 | and [macro_status],0Fh |
||
2977 | call preprocess_file |
||
2978 | pop eax |
||
2979 | and al,0F0h |
||
2980 | and [macro_status],0Fh |
||
2981 | or [macro_status],al |
||
2982 | jmp line_preprocessed' |
||
2983 | >' |