Rev 2665 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2665 | Rev 4039 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ; flat assembler core |
1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2012, Tomasz Grysztar. |
2 | ; Copyright (c) 1999-2013, Tomasz Grysztar. |
3 | ; All rights reserved. |
3 | ; All rights reserved. |
Line 4... | Line 4... | ||
4 | 4 | ||
5 | formatter: |
5 | formatter: |
6 | mov [current_offset],edi |
6 | mov [current_offset],edi |
Line 127... | Line 127... | ||
127 | cmp [symbols_file],0 |
127 | cmp [symbols_file],0 |
128 | je labels_table_ok |
128 | je labels_table_ok |
129 | mov ecx,[memory_end] |
129 | mov ecx,[memory_end] |
130 | sub ecx,[labels_list] |
130 | sub ecx,[labels_list] |
131 | mov edi,[display_buffer] |
131 | mov edi,[tagged_blocks] |
132 | sub edi,8 |
132 | sub edi,8 |
133 | mov [edi],ecx |
133 | mov [edi],ecx |
134 | or dword [edi+4],-1 |
134 | or dword [edi+4],-1 |
135 | sub edi,ecx |
135 | sub edi,ecx |
136 | cmp edi,[current_offset] |
136 | cmp edi,[current_offset] |
137 | jbe out_of_memory |
137 | jbe out_of_memory |
138 | mov [display_buffer],edi |
138 | mov [tagged_blocks],edi |
139 | mov esi,[memory_end] |
139 | mov esi,[memory_end] |
140 | copy_labels: |
140 | copy_labels: |
141 | sub esi,32 |
141 | sub esi,32 |
142 | cmp esi,[labels_list] |
142 | cmp esi,[labels_list] |
143 | jb labels_table_ok |
143 | jb labels_table_ok |
144 | mov ecx,32 shr 2 |
144 | mov ecx,32 shr 2 |
Line 198... | Line 198... | ||
198 | ret |
198 | ret |
199 | format_directive: |
199 | format_directive: |
200 | cmp edi,[code_start] |
200 | cmp edi,[code_start] |
201 | jne unexpected_instruction |
201 | jne unexpected_instruction |
202 | cmp [virtual_data],0 |
202 | mov ebp,[addressing_space] |
- | 203 | test byte [ds:ebp+0Ah],1 |
|
203 | jne unexpected_instruction |
204 | jnz unexpected_instruction |
204 | cmp [output_format],0 |
205 | cmp [output_format],0 |
205 | jne unexpected_instruction |
206 | jne unexpected_instruction |
206 | lods byte [esi] |
207 | lods byte [esi] |
207 | cmp al,1Ch |
208 | cmp al,1Ch |
208 | je format_prefix |
209 | je format_prefix |
209 | cmp al,18h |
210 | cmp al,18h |
Line 278... | Line 279... | ||
278 | cmp al,3 |
279 | cmp al,3 |
279 | je pe_heap |
280 | je pe_heap |
280 | jmp illegal_instruction |
281 | jmp illegal_instruction |
281 | segment_directive: |
282 | segment_directive: |
282 | cmp [virtual_data],0 |
283 | mov al,[output_format] |
283 | jne illegal_instruction |
- | |
284 | mov al,[output_format] |
- | |
285 | cmp al,2 |
284 | cmp al,2 |
286 | je mz_segment |
285 | je mz_segment |
287 | cmp al,5 |
286 | cmp al,5 |
288 | je elf_segment |
287 | je elf_segment |
289 | jmp illegal_instruction |
288 | jmp illegal_instruction |
290 | section_directive: |
289 | section_directive: |
291 | cmp [virtual_data],0 |
290 | mov al,[output_format] |
292 | jne illegal_instruction |
- | |
293 | mov al,[output_format] |
- | |
294 | cmp al,3 |
291 | cmp al,3 |
295 | je pe_section |
292 | je pe_section |
296 | cmp al,4 |
293 | cmp al,4 |
297 | je coff_section |
294 | je coff_section |
298 | cmp al,5 |
295 | cmp al,5 |
Line 408... | Line 405... | ||
408 | mov [edx+8],ecx |
405 | mov [edx+8],ecx |
409 | xor eax,eax |
406 | xor eax,eax |
410 | xor edx,edx |
407 | xor edx,edx |
411 | xor ebp,ebp |
408 | xor ebp,ebp |
412 | mov ch,2 |
409 | mov [address_sign],0 |
- | 410 | mov ch,2 |
|
413 | test [format_flags],8 |
411 | test [format_flags],8 |
414 | jz make_free_label |
412 | jz make_free_label |
415 | mov ch,4 |
413 | mov ch,4 |
416 | jmp make_free_label |
414 | jmp make_free_label |
417 | mark_relocation: |
415 | mark_relocation: |
418 | cmp [value_type],0 |
416 | cmp [value_type],0 |
419 | je relocation_ok |
417 | je relocation_ok |
420 | cmp [virtual_data],0 |
418 | mov ebp,[addressing_space] |
- | 419 | test byte [ds:ebp+0Ah],1 |
|
421 | jne relocation_ok |
420 | jnz relocation_ok |
422 | cmp [output_format],2 |
421 | cmp [output_format],2 |
423 | je mark_mz_relocation |
422 | je mark_mz_relocation |
424 | cmp [output_format],3 |
423 | cmp [output_format],3 |
425 | je mark_pe_relocation |
424 | je mark_pe_relocation |
426 | cmp [output_format],4 |
425 | cmp [output_format],4 |
427 | je mark_coff_relocation |
426 | je mark_coff_relocation |
Line 491... | Line 490... | ||
491 | sub ecx,eax |
490 | sub ecx,eax |
492 | mov edx,edi |
491 | mov edx,edi |
493 | xor eax,eax |
492 | xor eax,eax |
494 | rep stos byte [edi] |
493 | rep stos byte [edi] |
495 | mov dword [org_origin],edi |
494 | mov eax,edx |
496 | mov dword [org_origin+4],eax |
- | |
497 | mov [org_origin_sign],al |
- | |
498 | mov [org_registers],eax |
- | |
499 | mov [org_start],edi |
- | |
500 | mov eax,edx |
- | |
501 | call undefined_data |
495 | call undefined_data |
502 | mov eax,edi |
496 | push ebx |
- | 497 | call create_addressing_space |
|
- | 498 | pop ebx |
|
- | 499 | mov eax,edi |
|
503 | sub eax,[code_start] |
500 | sub eax,[code_start] |
504 | shr eax,4 |
501 | shr eax,4 |
505 | cmp eax,10000h |
502 | cmp eax,10000h |
506 | jae value_out_of_range |
503 | jae value_out_of_range |
507 | mov edx,eax |
504 | mov edx,eax |
Line 513... | Line 510... | ||
513 | segment_type_ok: |
510 | segment_type_ok: |
514 | mov [code_type],al |
511 | mov [code_type],al |
515 | mov eax,edx |
512 | mov eax,edx |
516 | mov ch,1 |
513 | mov ch,1 |
517 | mov [label_size],0 |
514 | mov [address_sign],0 |
518 | xor edx,edx |
515 | xor edx,edx |
519 | xor ebp,ebp |
516 | xor ebp,ebp |
520 | mov [address_symbol],edx |
517 | mov [label_size],0 |
- | 518 | mov [address_symbol],edx |
|
521 | jmp make_free_label |
519 | jmp make_free_label |
522 | mz_entry: |
520 | mz_entry: |
523 | lods byte [esi] |
521 | lods byte [esi] |
524 | cmp al,'(' |
522 | cmp al,'(' |
525 | jne invalid_argument |
523 | jne invalid_argument |
Line 722... | Line 720... | ||
722 | add ecx,11b |
720 | add ecx,11b |
723 | and ecx,not 11b |
721 | and ecx,not 11b |
724 | add ecx,(40h-1Ch) shr 2 |
722 | add ecx,(40h-1Ch) shr 2 |
725 | lea eax,[edi+ecx*4] |
723 | lea eax,[edi+ecx*4] |
726 | cmp edi,[display_buffer] |
724 | cmp edi,[tagged_blocks] |
727 | jae out_of_memory |
725 | jae out_of_memory |
728 | xor eax,eax |
726 | xor eax,eax |
729 | rep stos dword [edi] |
727 | rep stos dword [edi] |
730 | mov edx,40h |
728 | mov edx,40h |
731 | xchg dx,[esi+18h] |
729 | xchg dx,[esi+18h] |
732 | xor al,al |
730 | xor al,al |
Line 760... | Line 758... | ||
760 | shr ecx,3 |
758 | shr ecx,3 |
761 | inc ecx |
759 | inc ecx |
762 | shl ecx,1 |
760 | shl ecx,1 |
763 | lea eax,[edi+ecx*4] |
761 | lea eax,[edi+ecx*4] |
764 | cmp eax,[display_buffer] |
762 | cmp eax,[tagged_blocks] |
765 | jae out_of_memory |
763 | jae out_of_memory |
766 | xor eax,eax |
764 | xor eax,eax |
767 | rep stos dword [edi] |
765 | rep stos dword [edi] |
768 | pop ecx |
766 | pop ecx |
769 | read_stub_code: |
767 | read_stub_code: |
770 | call read |
768 | call read |
Line 824... | Line 822... | ||
824 | mov [esi+0Eh],ax |
822 | mov [esi+0Eh],ax |
825 | mov [esi+16h],ax |
823 | mov [esi+16h],ax |
826 | mov word [esi+14h],100h |
824 | mov word [esi+14h],100h |
827 | mov byte [esi+18h],40h |
825 | mov byte [esi+18h],40h |
828 | mov eax,[display_buffer] |
826 | mov eax,[tagged_blocks] |
829 | sub eax,ecx |
827 | sub eax,ecx |
830 | cmp edi,eax |
828 | cmp edi,eax |
831 | jae out_of_memory |
829 | jae out_of_memory |
832 | mov edx,edi |
830 | mov edx,edi |
833 | shr ecx,2 |
831 | shr ecx,2 |
834 | xor eax,eax |
832 | xor eax,eax |
Line 1051... | Line 1049... | ||
1051 | inc ebx |
1049 | inc ebx |
1052 | shl ebx,cl |
1050 | shl ebx,cl |
1053 | sub ebx,ebp |
1051 | sub ebx,ebp |
1054 | mov ecx,ebx |
1052 | mov ecx,ebx |
1055 | mov eax,[display_buffer] |
1053 | mov eax,[tagged_blocks] |
1056 | sub eax,ecx |
1054 | sub eax,ecx |
1057 | cmp edi,eax |
1055 | cmp edi,eax |
1058 | jae out_of_memory |
1056 | jae out_of_memory |
1059 | shr ecx,2 |
1057 | shr ecx,2 |
1060 | xor eax,eax |
1058 | xor eax,eax |
1061 | rep stos dword [edi] |
1059 | rep stos dword [edi] |
Line 1115... | Line 1113... | ||
1115 | bt [resolver_flags],0 |
1113 | bt [resolver_flags],0 |
1116 | jc pe_labels_type_ok |
1114 | jc pe_labels_type_ok |
1117 | xor bh,bh |
1115 | xor bh,bh |
1118 | pe_labels_type_ok: |
1116 | pe_labels_type_ok: |
1119 | mov [labels_type],bh |
1117 | push eax ebx |
- | 1118 | call init_addressing_space |
|
- | 1119 | mov ebp,ebx |
|
1120 | mov dword [org_origin],eax |
1120 | pop ebx eax |
1121 | mov dword [org_origin+4],ecx |
1121 | mov [ds:ebp],eax |
1122 | mov [org_origin_sign],bl |
1122 | mov [ds:ebp+4],ecx |
1123 | and [org_registers],0 |
1123 | mov [ds:ebp+8],bx |
1124 | mov [org_start],edi |
1124 | mov [ds:ebp+18h],edi |
1125 | bt [format_flags],8 |
1125 | bt [format_flags],8 |
1126 | jnc dll_flag_ok |
1126 | jnc dll_flag_ok |
1127 | or byte [edx+16h+1],20h |
1127 | or byte [edx+16h+1],20h |
1128 | dll_flag_ok: |
1128 | dll_flag_ok: |
1129 | bt [format_flags],9 |
1129 | bt [format_flags],9 |
1130 | jnc wdm_flag_ok |
1130 | jnc wdm_flag_ok |
Line 1140... | Line 1140... | ||
1140 | nx_ok: |
1140 | nx_ok: |
1141 | jmp format_defined |
1141 | jmp format_defined |
1142 | pe_section: |
1142 | pe_section: |
1143 | call close_pe_section |
1143 | call close_pe_section |
1144 | bts [format_flags],5 |
1144 | push eax ebx |
- | 1145 | call create_addressing_space |
|
- | 1146 | mov ebp,ebx |
|
- | 1147 | pop ebx eax |
|
- | 1148 | bts [format_flags],5 |
|
1145 | lea ecx,[ebx+28h] |
1149 | lea ecx,[ebx+28h] |
1146 | add edx,[edx+54h] |
1150 | add edx,[edx+54h] |
1147 | sub edx,[stub_size] |
1151 | sub edx,[stub_size] |
1148 | cmp ecx,edx |
1152 | cmp ecx,edx |
1149 | jbe new_section |
1153 | jbe new_section |
Line 1177... | Line 1181... | ||
1177 | mov [ebx+14h],edi |
1181 | mov [ebx+14h],edi |
1178 | mov edx,[code_start] |
1182 | mov edx,[code_start] |
1179 | mov eax,edi |
1183 | mov eax,edi |
1180 | xor ecx,ecx |
1184 | xor ecx,ecx |
1181 | mov [org_origin_sign],0 |
1185 | sub eax,[ebx+0Ch] |
1182 | sub eax,[ebx+0Ch] |
- | |
1183 | sbb ecx,0 |
1186 | sbb ecx,0 |
1184 | sbb [org_origin_sign],0 |
1187 | sbb byte [ds:ebp+8],0 |
1185 | mov [labels_type],2 |
1188 | mov byte [ds:ebp+9],2 |
1186 | mov [code_type],32 |
1189 | mov [code_type],32 |
1187 | test [format_flags],8 |
1190 | test [format_flags],8 |
1188 | jz pe_section_code_type_ok |
1191 | jz pe_section_code_type_ok |
1189 | mov [labels_type],4 |
1192 | mov byte [ds:ebp+9],4 |
1190 | mov [code_type],64 |
1193 | mov [code_type],64 |
1191 | pe_section_code_type_ok: |
1194 | pe_section_code_type_ok: |
1192 | test [format_flags],4 |
1195 | test [format_flags],4 |
1193 | jnz peplus_section_org |
1196 | jnz peplus_section_org |
1194 | sub eax,[edx+34h] |
1197 | sub eax,[edx+34h] |
1195 | sbb ecx,0 |
1198 | sbb ecx,0 |
1196 | sbb [org_origin_sign],0 |
1199 | sbb byte [ds:ebp+8],0 |
1197 | bt [resolver_flags],0 |
1200 | bt [resolver_flags],0 |
1198 | jc pe_section_org_ok |
1201 | jc pe_section_org_ok |
1199 | mov [labels_type],0 |
1202 | mov byte [ds:ebp+9],0 |
1200 | jmp pe_section_org_ok |
1203 | jmp pe_section_org_ok |
1201 | peplus_section_org: |
1204 | peplus_section_org: |
1202 | sub eax,[edx+30h] |
1205 | sub eax,[edx+30h] |
1203 | sbb ecx,[edx+34h] |
1206 | sbb ecx,[edx+34h] |
1204 | sbb [org_origin_sign],0 |
1207 | sbb byte [ds:ebp+8],0 |
1205 | bt [resolver_flags],0 |
1208 | bt [resolver_flags],0 |
1206 | jc pe_section_org_ok |
1209 | jc pe_section_org_ok |
1207 | mov [labels_type],0 |
1210 | mov byte [ds:ebp+9],0 |
1208 | pe_section_org_ok: |
1211 | pe_section_org_ok: |
1209 | mov dword [org_origin],eax |
1212 | mov [ds:ebp],eax |
1210 | mov dword [org_origin+4],ecx |
1213 | mov [ds:ebp+4],ecx |
1211 | and [org_registers],0 |
1214 | mov [ds:ebp+18h],edi |
1212 | mov [org_start],edi |
- | |
1213 | get_section_flags: |
1215 | get_section_flags: |
1214 | lods byte [esi] |
1216 | lods byte [esi] |
1215 | cmp al,1Ah |
1217 | cmp al,1Ah |
1216 | je set_directory |
1218 | je set_directory |
1217 | cmp al,19h |
1219 | cmp al,19h |
1218 | je section_flag |
1220 | je section_flag |
Line 1539... | Line 1541... | ||
1539 | mov [ecx+7Ch],edx |
1541 | mov [ecx+7Ch],edx |
1540 | cmp edx,[ecx+74h] |
1542 | cmp edx,[ecx+74h] |
1541 | ja value_out_of_range |
1543 | ja value_out_of_range |
1542 | jb instruction_assembled |
1544 | jb instruction_assembled |
1543 | cmp eax,[edx+70h] |
1545 | cmp eax,[ecx+70h] |
1544 | ja value_out_of_range |
1546 | ja value_out_of_range |
1545 | jmp instruction_assembled |
1547 | jmp instruction_assembled |
1546 | mark_pe_relocation: |
1548 | mark_pe_relocation: |
1547 | push eax ebx |
1549 | push eax ebx |
1548 | test [format_flags],4 |
1550 | test [format_flags],4 |
1549 | jz check_standard_pe_relocation_type |
1551 | jz check_standard_pe_relocation_type |
Line 1662... | Line 1664... | ||
1662 | jne reserve_space_for_resource |
1664 | jne reserve_space_for_resource |
1663 | and [resource_size],0 |
1665 | and [resource_size],0 |
1664 | reserve_space_for_resource: |
1666 | reserve_space_for_resource: |
1665 | add edi,[resource_size] |
1667 | add edi,[resource_size] |
1666 | cmp edi,[display_buffer] |
1668 | cmp edi,[tagged_blocks] |
1667 | ja out_of_memory |
1669 | ja out_of_memory |
1668 | jmp resource_done |
1670 | jmp resource_done |
1669 | resource_from_file: |
1671 | resource_from_file: |
1670 | push esi |
1672 | push esi |
1671 | mov esi,edx |
1673 | mov esi,edx |
1672 | call open_binary_file |
1674 | call open_binary_file |
Line 1748... | Line 1750... | ||
1748 | xor eax,eax |
1750 | xor eax,eax |
1749 | mov [esi],eax |
1751 | mov [esi],eax |
1750 | mov [resource_data],edi |
1752 | mov [resource_data],edi |
1751 | lea eax,[edi+16] |
1753 | lea eax,[edi+16] |
1752 | cmp eax,[display_buffer] |
1754 | cmp eax,[tagged_blocks] |
1753 | jae out_of_memory |
1755 | jae out_of_memory |
1754 | xor eax,eax |
1756 | xor eax,eax |
1755 | stos dword [edi] |
1757 | stos dword [edi] |
1756 | call make_timestamp |
1758 | call make_timestamp |
1757 | stos dword [edi] |
1759 | stos dword [edi] |
1758 | xor eax,eax |
1760 | xor eax,eax |
Line 1810... | Line 1812... | ||
1810 | make_type_name_entry: |
1812 | make_type_name_entry: |
1811 | mov eax,[resource_data] |
1813 | mov eax,[resource_data] |
1812 | inc word [eax+12] |
1814 | inc word [eax+12] |
1813 | lea eax,[edi+8] |
1815 | lea eax,[edi+8] |
1814 | cmp eax,[display_buffer] |
1816 | cmp eax,[tagged_blocks] |
1815 | jae out_of_memory |
1817 | jae out_of_memory |
1816 | mov eax,ebx |
1818 | mov eax,ebx |
1817 | stos dword [edi] |
1819 | stos dword [edi] |
1818 | xor eax,eax |
1820 | xor eax,eax |
1819 | stos dword [edi] |
1821 | stos dword [edi] |
1820 | jmp make_type_name_directory |
1822 | jmp make_type_name_directory |
Line 1847... | Line 1849... | ||
1847 | make_type_id_entry: |
1849 | make_type_id_entry: |
1848 | mov eax,[resource_data] |
1850 | mov eax,[resource_data] |
1849 | inc word [eax+14] |
1851 | inc word [eax+14] |
1850 | lea eax,[edi+8] |
1852 | lea eax,[edi+8] |
1851 | cmp eax,[display_buffer] |
1853 | cmp eax,[tagged_blocks] |
1852 | jae out_of_memory |
1854 | jae out_of_memory |
1853 | mov eax,ebx |
1855 | mov eax,ebx |
1854 | stos dword [edi] |
1856 | stos dword [edi] |
1855 | xor eax,eax |
1857 | xor eax,eax |
1856 | stos dword [edi] |
1858 | stos dword [edi] |
1857 | jmp make_type_id_directory |
1859 | jmp make_type_id_directory |
Line 1868... | Line 1870... | ||
1868 | sub edx,[resource_data] |
1870 | sub edx,[resource_data] |
1869 | bts edx,31 |
1871 | bts edx,31 |
1870 | mov [esi+4],edx |
1872 | mov [esi+4],edx |
1871 | lea eax,[edi+16] |
1873 | lea eax,[edi+16] |
1872 | cmp eax,[display_buffer] |
1874 | cmp eax,[tagged_blocks] |
1873 | jae out_of_memory |
1875 | jae out_of_memory |
1874 | xor eax,eax |
1876 | xor eax,eax |
1875 | stos dword [edi] |
1877 | stos dword [edi] |
1876 | call make_timestamp |
1878 | call make_timestamp |
1877 | stos dword [edi] |
1879 | stos dword [edi] |
1878 | xor eax,eax |
1880 | xor eax,eax |
Line 1947... | Line 1949... | ||
1947 | make_resource_name_entry: |
1949 | make_resource_name_entry: |
1948 | mov eax,[esp] |
1950 | mov eax,[esp] |
1949 | inc word [eax+12] |
1951 | inc word [eax+12] |
1950 | lea eax,[edi+8] |
1952 | lea eax,[edi+8] |
1951 | cmp eax,[display_buffer] |
1953 | cmp eax,[tagged_blocks] |
1952 | jae out_of_memory |
1954 | jae out_of_memory |
1953 | mov eax,ebx |
1955 | mov eax,ebx |
1954 | stos dword [edi] |
1956 | stos dword [edi] |
1955 | xor eax,eax |
1957 | xor eax,eax |
1956 | stos dword [edi] |
1958 | stos dword [edi] |
1957 | jmp make_resource_name_directory |
1959 | jmp make_resource_name_directory |
Line 1990... | Line 1992... | ||
1990 | make_resource_id_entry: |
1992 | make_resource_id_entry: |
1991 | mov eax,[esp] |
1993 | mov eax,[esp] |
1992 | inc word [eax+14] |
1994 | inc word [eax+14] |
1993 | lea eax,[edi+8] |
1995 | lea eax,[edi+8] |
1994 | cmp eax,[display_buffer] |
1996 | cmp eax,[tagged_blocks] |
1995 | jae out_of_memory |
1997 | jae out_of_memory |
1996 | mov eax,ebx |
1998 | mov eax,ebx |
1997 | stos dword [edi] |
1999 | stos dword [edi] |
1998 | xor eax,eax |
2000 | xor eax,eax |
1999 | stos dword [edi] |
2001 | stos dword [edi] |
2000 | jmp make_resource_id_directory |
2002 | jmp make_resource_id_directory |
Line 2029... | Line 2031... | ||
2029 | sub edx,[resource_data] |
2031 | sub edx,[resource_data] |
2030 | bts edx,31 |
2032 | bts edx,31 |
2031 | mov [esi+4],edx |
2033 | mov [esi+4],edx |
2032 | lea eax,[edi+16] |
2034 | lea eax,[edi+16] |
2033 | cmp eax,[display_buffer] |
2035 | cmp eax,[tagged_blocks] |
2034 | jae out_of_memory |
2036 | jae out_of_memory |
2035 | xor eax,eax |
2037 | xor eax,eax |
2036 | stos dword [edi] |
2038 | stos dword [edi] |
2037 | call make_timestamp |
2039 | call make_timestamp |
2038 | stos dword [edi] |
2040 | stos dword [edi] |
2039 | xor eax,eax |
2041 | xor eax,eax |
Line 2079... | Line 2081... | ||
2079 | make_language_id_entry: |
2081 | make_language_id_entry: |
2080 | mov eax,[esp] |
2082 | mov eax,[esp] |
2081 | inc word [eax+14] |
2083 | inc word [eax+14] |
2082 | lea eax,[edi+8] |
2084 | lea eax,[edi+8] |
2083 | cmp eax,[display_buffer] |
2085 | cmp eax,[tagged_blocks] |
2084 | jae out_of_memory |
2086 | jae out_of_memory |
2085 | mov eax,ebx |
2087 | mov eax,ebx |
2086 | stos dword [edi] |
2088 | stos dword [edi] |
2087 | mov eax,dword [value] |
2089 | mov eax,dword [value] |
2088 | stos dword [edi] |
2090 | stos dword [edi] |
2089 | jmp make_language_id_directory |
2091 | jmp make_language_id_directory |
Line 2120... | Line 2122... | ||
2120 | xor ax,ax |
2122 | xor ax,ax |
2121 | stos word [edi] |
2123 | stos word [edi] |
2122 | copy_string_data: |
2124 | copy_string_data: |
2123 | lea eax,[edi+2] |
2125 | lea eax,[edi+2] |
2124 | cmp eax,[display_buffer] |
2126 | cmp eax,[tagged_blocks] |
2125 | jae out_of_memory |
2127 | jae out_of_memory |
2126 | mov ax,[edx] |
2128 | mov ax,[edx] |
2127 | or ax,ax |
2129 | or ax,ax |
2128 | jz string_data_copied |
2130 | jz string_data_copied |
2129 | stos word [edi] |
2131 | stos word [edi] |
2130 | inc word [ebx] |
2132 | inc word [ebx] |
Line 2158... | Line 2160... | ||
2158 | mov esi,edi |
2160 | mov esi,edi |
2159 | sub esi,[resource_data] |
2161 | sub esi,[resource_data] |
2160 | xchg esi,[ebx+4] |
2162 | xchg esi,[ebx+4] |
2161 | lea eax,[edi+16] |
2163 | lea eax,[edi+16] |
2162 | cmp eax,[display_buffer] |
2164 | cmp eax,[tagged_blocks] |
2163 | jae out_of_memory |
2165 | jae out_of_memory |
2164 | mov eax,esi |
2166 | mov eax,esi |
2165 | stos dword [edi] |
2167 | stos dword [edi] |
2166 | mov eax,[esi+12] |
2168 | mov eax,[esi+12] |
2167 | stos dword [edi] |
2169 | stos dword [edi] |
2168 | xor eax,eax |
2170 | xor eax,eax |
Line 2188... | Line 2190... | ||
2188 | call lseek |
2190 | call lseek |
2189 | mov edx,edi |
2191 | mov edx,edi |
2190 | mov ecx,[esi+4] |
2192 | mov ecx,[esi+4] |
2191 | add edi,ecx |
2193 | add edi,ecx |
2192 | cmp edi,[display_buffer] |
2194 | cmp edi,[tagged_blocks] |
2193 | ja out_of_memory |
2195 | ja out_of_memory |
2194 | call read |
2196 | call read |
2195 | mov eax,edi |
2197 | mov eax,edi |
2196 | sub eax,[resource_data] |
2198 | sub eax,[resource_data] |
2197 | and eax,11b |
2199 | and eax,11b |
2198 | jz resource_data_alignment_ok |
2200 | jz resource_data_alignment_ok |
Line 2317... | Line 2319... | ||
2317 | mov dword [ebx+14h],eax |
2319 | mov dword [ebx+14h],eax |
2318 | mov [current_section],ebx |
2320 | mov [current_section],ebx |
2319 | xor eax,eax |
2321 | xor eax,eax |
2320 | mov [number_of_sections],eax |
2322 | mov [number_of_sections],eax |
2321 | call setup_coff_section_org |
2323 | mov edx,ebx |
- | 2324 | call init_addressing_space |
|
2322 | mov [code_type],32 |
2325 | mov [ebx+14h],edx |
- | 2326 | mov byte [ebx+9],2 |
|
- | 2327 | mov [code_type],32 |
|
2323 | test [format_flags],8 |
2328 | test [format_flags],8 |
2324 | jz format_defined |
2329 | jz format_defined |
2325 | mov [code_type],64 |
2330 | mov byte [ebx+9],4 |
- | 2331 | mov [code_type],64 |
|
2326 | jmp format_defined |
2332 | jmp format_defined |
2327 | setup_coff_section_org: |
2333 | coff_section: |
2328 | xor eax,eax |
- | |
2329 | mov dword [org_origin],edi |
- | |
2330 | mov dword [org_origin+4],eax |
- | |
2331 | mov [org_origin_sign],al |
- | |
2332 | mov [org_registers],eax |
- | |
2333 | mov [org_start],edi |
- | |
2334 | mov [org_symbol],ebx |
- | |
2335 | test [format_flags],8 |
- | |
2336 | jnz coff_64bit_labels |
- | |
2337 | mov [labels_type],2 |
- | |
2338 | ret |
- | |
2339 | coff_64bit_labels: |
- | |
2340 | mov [labels_type],4 |
- | |
2341 | ret |
- | |
2342 | - | ||
2343 | coff_section: |
- | |
2344 | call close_coff_section |
2334 | call close_coff_section |
2345 | mov ebx,[free_additional_memory] |
2335 | mov ebx,[free_additional_memory] |
2346 | lea eax,[ebx+20h] |
2336 | lea eax,[ebx+20h] |
2347 | cmp eax,[structures_buffer] |
2337 | cmp eax,[structures_buffer] |
2348 | jae out_of_memory |
2338 | jae out_of_memory |
Line 2353... | Line 2343... | ||
2353 | mov [ebx],al |
2343 | mov [ebx],al |
2354 | mov [ebx+8],edi |
2344 | mov [ebx+8],edi |
2355 | mov [ebx+10h],eax |
2345 | mov [ebx+10h],eax |
2356 | mov [ebx+14h],eax |
2346 | mov [ebx+14h],eax |
2357 | call setup_coff_section_org |
2347 | mov edx,ebx |
- | 2348 | call create_addressing_space |
|
2358 | lods word [esi] |
2349 | xchg edx,ebx |
- | 2350 | mov [edx+14h],ebx |
|
- | 2351 | mov byte [edx+9],2 |
|
- | 2352 | test [format_flags],8 |
|
- | 2353 | jz coff_labels_type_ok |
|
- | 2354 | mov byte [edx+9],4 |
|
- | 2355 | coff_labels_type_ok: |
|
- | 2356 | lods word [esi] |
|
2359 | cmp ax,'(' |
2357 | cmp ax,'(' |
2360 | jne invalid_argument |
2358 | jne invalid_argument |
2361 | mov [ebx+4],esi |
2359 | mov [ebx+4],esi |
2362 | mov ecx,[esi] |
2360 | mov ecx,[esi] |
2363 | lea esi,[esi+4+ecx+1] |
2361 | lea esi,[esi+4+ecx+1] |
Line 2440... | Line 2438... | ||
2440 | push ebx eax |
2438 | push ebx eax |
2441 | test [format_flags],8 |
2439 | test [format_flags],8 |
2442 | jnz coff_64bit_relocation |
2440 | jnz coff_64bit_relocation |
2443 | mov al,6 |
2441 | mov al,6 |
2444 | cmp [value_type],5 |
2442 | cmp [value_type],2 |
- | 2443 | je coff_relocation |
|
- | 2444 | cmp [value_type],5 |
|
2445 | jne coff_relocation |
2445 | jne invalid_use_of_symbol |
2446 | inc al |
2446 | inc al |
2447 | jmp coff_relocation |
2447 | jmp coff_relocation |
2448 | coff_64bit_relocation: |
2448 | coff_64bit_relocation: |
2449 | mov al,1 |
2449 | mov al,1 |
2450 | cmp [value_type],4 |
2450 | cmp [value_type],4 |
2451 | je coff_relocation |
2451 | je coff_relocation |
2452 | mov al,2 |
2452 | mov al,2 |
2453 | cmp [value_type],5 |
2453 | cmp [value_type],2 |
- | 2454 | je coff_relocation |
|
- | 2455 | cmp [value_type],5 |
|
2454 | jne coff_relocation |
2456 | jne invalid_use_of_symbol |
2455 | inc al |
2457 | inc al |
2456 | jmp coff_relocation |
2458 | jmp coff_relocation |
2457 | coff_relocation_relative: |
2459 | coff_relocation_relative: |
2458 | push ebx |
2460 | push ebx |
2459 | bt [format_flags],0 |
2461 | bt [format_flags],0 |
2460 | jnc relative_ok |
2462 | jnc relative_ok |
Line 2463... | Line 2465... | ||
2463 | sub ebx,edi |
2465 | sub ebx,edi |
2464 | sub eax,ebx |
2466 | sub eax,ebx |
2465 | add eax,4 |
2467 | add eax,4 |
2466 | relative_ok: |
2468 | relative_ok: |
2467 | push eax |
2469 | mov ebx,[addressing_space] |
- | 2470 | push eax |
|
2468 | mov al,20 |
2471 | mov al,20 |
2469 | test [format_flags],8 |
2472 | test [format_flags],8 |
2470 | jnz relative_coff_64bit_relocation |
2473 | jnz relative_coff_64bit_relocation |
2471 | cmp [labels_type],2 |
2474 | cmp byte [ebx+9],2 |
2472 | jne invalid_use_of_symbol |
2475 | jne invalid_use_of_symbol |
2473 | jmp coff_relocation |
2476 | jmp coff_relocation |
2474 | relative_coff_64bit_relocation: |
2477 | relative_coff_64bit_relocation: |
2475 | mov al,4 |
2478 | mov al,4 |
2476 | cmp [labels_type],4 |
2479 | cmp byte [ebx+9],4 |
2477 | jne invalid_use_of_symbol |
2480 | jne invalid_use_of_symbol |
2478 | coff_relocation: |
2481 | coff_relocation: |
2479 | mov ebx,[free_additional_memory] |
2482 | mov ebx,[free_additional_memory] |
2480 | add ebx,0Ch |
2483 | add ebx,0Ch |
2481 | cmp ebx,[structures_buffer] |
2484 | cmp ebx,[structures_buffer] |
2482 | jae out_of_memory |
2485 | jae out_of_memory |
Line 2684... | Line 2687... | ||
2684 | add esi,10h |
2687 | add esi,10h |
2685 | jmp find_relocations |
2688 | jmp find_relocations |
2686 | add_relocation: |
2689 | add_relocation: |
2687 | lea eax,[ebx+0Ah] |
2690 | lea eax,[ebx+0Ah] |
2688 | cmp eax,[display_buffer] |
2691 | cmp eax,[tagged_blocks] |
2689 | ja out_of_memory |
2692 | ja out_of_memory |
2690 | mov eax,[esi+4] |
2693 | mov eax,[esi+4] |
2691 | mov [ebx],eax |
2694 | mov [ebx],eax |
2692 | mov eax,[esi+8] |
2695 | mov eax,[esi+8] |
2693 | mov eax,[eax] |
2696 | mov eax,[eax] |
2694 | shr eax,8 |
2697 | shr eax,8 |
Line 2903... | Line 2906... | ||
2903 | jnz format_elf64 |
2906 | jnz format_elf64 |
2904 | mov edx,edi |
2907 | mov edx,edi |
2905 | mov ecx,34h shr 2 |
2908 | mov ecx,34h shr 2 |
2906 | lea eax,[edi+ecx*4] |
2909 | lea eax,[edi+ecx*4] |
2907 | cmp eax,[display_buffer] |
2910 | cmp eax,[tagged_blocks] |
2908 | jae out_of_memory |
2911 | jae out_of_memory |
2909 | xor eax,eax |
2912 | xor eax,eax |
2910 | rep stos dword [edi] |
2913 | rep stos dword [edi] |
2911 | mov dword [edx],7Fh + 'ELF' shl 8 |
2914 | mov dword [edx],7Fh + 'ELF' shl 8 |
2912 | mov al,1 |
2915 | mov al,1 |
2913 | mov [edx+4],al |
2916 | mov [edx+4],al |
Line 2938... | Line 2941... | ||
2938 | mov al,111b |
2941 | mov al,111b |
2939 | mov [ebx+14h],eax |
2942 | mov [ebx+14h],eax |
2940 | mov al,4 |
2943 | mov al,4 |
2941 | mov [ebx+10h],eax |
2944 | mov [ebx+10h],eax |
2942 | call setup_coff_section_org |
2945 | mov edx,ebx |
- | 2946 | call init_addressing_space |
|
2943 | test [format_flags],8 |
2947 | xchg edx,ebx |
- | 2948 | mov [edx+14h],ebx |
|
- | 2949 | mov byte [edx+9],2 |
|
- | 2950 | test [format_flags],8 |
|
2944 | jz format_defined |
2951 | jz format_defined |
2945 | mov byte [ebx+10h],8 |
2952 | mov byte [edx+9],4 |
- | 2953 | mov byte [ebx+10h],8 |
|
2946 | jmp format_defined |
2954 | jmp format_defined |
2947 | format_elf64: |
2955 | format_elf64: |
2948 | mov edx,edi |
2956 | mov edx,edi |
2949 | mov ecx,40h shr 2 |
2957 | mov ecx,40h shr 2 |
2950 | lea eax,[edi+ecx*4] |
2958 | lea eax,[edi+ecx*4] |
2951 | cmp eax,[display_buffer] |
2959 | cmp eax,[tagged_blocks] |
2952 | jae out_of_memory |
2960 | jae out_of_memory |
2953 | xor eax,eax |
2961 | xor eax,eax |
2954 | rep stos dword [edi] |
2962 | rep stos dword [edi] |
2955 | mov dword [edx],7Fh + 'ELF' shl 8 |
2963 | mov dword [edx],7Fh + 'ELF' shl 8 |
2956 | mov al,1 |
2964 | mov al,1 |
2957 | mov [edx+5],al |
2965 | mov [edx+5],al |
Line 2982... | Line 2990... | ||
2982 | mov [ebx+8],edi |
2990 | mov [ebx+8],edi |
2983 | mov [ebx+10h],eax |
2991 | mov [ebx+10h],eax |
2984 | mov al,10b |
2992 | mov al,10b |
2985 | mov [ebx+14h],eax |
2993 | mov [ebx+14h],eax |
2986 | call setup_coff_section_org |
2994 | mov edx,ebx |
- | 2995 | call create_addressing_space |
|
2987 | lods word [esi] |
2996 | xchg edx,ebx |
- | 2997 | mov [edx+14h],ebx |
|
- | 2998 | mov byte [edx+9],2 |
|
- | 2999 | test [format_flags],8 |
|
- | 3000 | jz elf_labels_type_ok |
|
- | 3001 | mov byte [edx+9],4 |
|
- | 3002 | elf_labels_type_ok: |
|
- | 3003 | lods word [esi] |
|
2988 | cmp ax,'(' |
3004 | cmp ax,'(' |
2989 | jne invalid_argument |
3005 | jne invalid_argument |
2990 | mov [ebx+4],esi |
3006 | mov [ebx+4],esi |
2991 | mov ecx,[esi] |
3007 | mov ecx,[esi] |
2992 | lea esi,[esi+4+ecx+1] |
3008 | lea esi,[esi+4+ecx+1] |
Line 3036... | Line 3052... | ||
3036 | jz instruction_assembled |
3052 | jz instruction_assembled |
3037 | mov byte [ebx+10h],8 |
3053 | mov byte [ebx+10h],8 |
3038 | jmp instruction_assembled |
3054 | jmp instruction_assembled |
3039 | mark_elf_relocation: |
3055 | mark_elf_relocation: |
3040 | cmp [value_type],3 |
3056 | push ebx |
- | 3057 | mov ebx,[addressing_space] |
|
- | 3058 | cmp [value_type],3 |
|
3041 | je elf_relocation_relative |
3059 | je elf_relocation_relative |
3042 | cmp [value_type],7 |
3060 | cmp [value_type],7 |
3043 | je elf_relocation_relative |
3061 | je elf_relocation_relative |
3044 | push ebx eax |
3062 | push eax |
3045 | cmp [value_type],5 |
3063 | cmp [value_type],5 |
3046 | je elf_gotoff_relocation |
3064 | je elf_gotoff_relocation |
3047 | ja invalid_use_of_symbol |
3065 | ja invalid_use_of_symbol |
3048 | mov al,1 ; R_386_32 / R_AMD64_64 |
3066 | mov al,1 ; R_386_32 / R_AMD64_64 |
3049 | test [format_flags],8 |
3067 | test [format_flags],8 |
3050 | jz coff_relocation |
3068 | jz coff_relocation |
Line 3057... | Line 3075... | ||
3057 | jnz invalid_use_of_symbol |
3075 | jnz invalid_use_of_symbol |
3058 | mov al,9 ; R_386_GOTOFF |
3076 | mov al,9 ; R_386_GOTOFF |
3059 | jmp coff_relocation |
3077 | jmp coff_relocation |
3060 | elf_relocation_relative: |
3078 | elf_relocation_relative: |
3061 | cmp [labels_type],0 |
3079 | cmp byte [ebx+9],0 |
3062 | je invalid_use_of_symbol |
3080 | je invalid_use_of_symbol |
3063 | push ebx |
3081 | mov ebx,[current_section] |
3064 | mov ebx,[current_section] |
- | |
3065 | mov ebx,[ebx+8] |
3082 | mov ebx,[ebx+8] |
3066 | sub ebx,edi |
3083 | sub ebx,edi |
3067 | sub eax,ebx |
3084 | sub eax,ebx |
3068 | push eax |
3085 | push eax |
3069 | mov al,2 ; R_386_PC32 / R_AMD64_PC32 |
3086 | mov al,2 ; R_386_PC32 / R_AMD64_PC32 |
Line 3688... | Line 3705... | ||
3688 | adc cl,0 |
3705 | adc cl,0 |
3689 | add eax,edi |
3706 | add eax,edi |
3690 | adc ebp,0 |
3707 | adc ebp,0 |
3691 | adc cl,0 |
3708 | adc cl,0 |
3692 | mov dword [org_origin],eax |
3709 | elf_exe_addressing_setup: |
3693 | mov dword [org_origin+4],edx |
3710 | push eax |
- | 3711 | call init_addressing_space |
|
3694 | mov [org_origin_sign],cl |
3712 | pop eax |
- | 3713 | mov [ebx],eax |
|
3695 | and [org_registers],0 |
3714 | mov [ebx+4],edx |
3696 | mov [org_start],edi |
3715 | mov [ebx+8],cl |
3697 | mov [symbols_stream],edi |
3716 | mov [symbols_stream],edi |
3698 | jmp format_defined |
3717 | jmp format_defined |
3699 | format_elf64_exe: |
3718 | format_elf64_exe: |
3700 | add esi,2 |
3719 | add esi,2 |
3701 | or [format_flags],1 |
3720 | or [format_flags],1 |
3702 | cmp byte [esi],'(' |
3721 | cmp byte [esi],'(' |
Line 3766... | Line 3785... | ||
3766 | adc cl,0 |
3785 | adc cl,0 |
3767 | add eax,edi |
3786 | add eax,edi |
3768 | adc edx,0 |
3787 | adc edx,0 |
3769 | adc cl,0 |
3788 | adc cl,0 |
3770 | mov dword [org_origin],eax |
3789 | jmp elf_exe_addressing_setup |
3771 | mov dword [org_origin+4],edx |
- | |
3772 | mov [org_origin_sign],cl |
- | |
3773 | and [org_registers],0 |
- | |
3774 | mov [org_start],edi |
- | |
3775 | mov [symbols_stream],edi |
- | |
3776 | jmp format_defined |
- | |
3777 | elf_entry: |
3790 | elf_entry: |
3778 | lods byte [esi] |
3791 | lods byte [esi] |
3779 | cmp al,'(' |
3792 | cmp al,'(' |
3780 | jne invalid_argument |
3793 | jne invalid_argument |
3781 | cmp byte [esi],'.' |
3794 | cmp byte [esi],'.' |
3782 | je invalid_value |
3795 | je invalid_value |
Line 3802... | Line 3815... | ||
3802 | test [format_flags],8 |
3815 | test [format_flags],8 |
3803 | jnz elf64_segment |
3816 | jnz elf64_segment |
3804 | call close_elf_segment |
3817 | call close_elf_segment |
3805 | push eax |
3818 | push eax |
3806 | mov ebx,[number_of_sections] |
3819 | call create_addressing_space |
- | 3820 | mov ebp,ebx |
|
- | 3821 | mov ebx,[number_of_sections] |
|
3807 | shl ebx,5 |
3822 | shl ebx,5 |
3808 | add ebx,[code_start] |
3823 | add ebx,[code_start] |
3809 | add ebx,34h |
3824 | add ebx,34h |
3810 | cmp ebx,[symbols_stream] |
3825 | cmp ebx,[symbols_stream] |
3811 | jb new_elf_segment |
3826 | jb new_elf_segment |
Line 3881... | Line 3896... | ||
3881 | adc cl,0 |
3896 | adc cl,0 |
3882 | add eax,edi |
3897 | add eax,edi |
3883 | adc edx,0 |
3898 | adc edx,0 |
3884 | adc cl,0 |
3899 | adc cl,0 |
3885 | mov dword [org_origin],eax |
3900 | elf_segment_addressing_setup: |
3886 | mov dword [org_origin+4],edx |
3901 | mov [ds:ebp],eax |
3887 | mov [org_origin_sign],cl |
3902 | mov [ds:ebp+4],edx |
3888 | and [org_registers],0 |
3903 | mov [ds:ebp+8],cl |
3889 | mov [org_start],edi |
- | |
3890 | inc [number_of_sections] |
3904 | inc [number_of_sections] |
3891 | jmp instruction_assembled |
3905 | jmp instruction_assembled |
3892 | close_elf_segment: |
3906 | close_elf_segment: |
3893 | cmp [number_of_sections],0 |
3907 | cmp [number_of_sections],0 |
3894 | jne finish_elf_segment |
3908 | jne finish_elf_segment |
3895 | cmp edi,[symbols_stream] |
3909 | cmp edi,[symbols_stream] |
Line 3933... | Line 3947... | ||
3933 | ret |
3947 | ret |
3934 | elf64_segment: |
3948 | elf64_segment: |
3935 | call close_elf64_segment |
3949 | call close_elf64_segment |
3936 | push eax edx |
3950 | push eax edx |
3937 | mov ebx,[number_of_sections] |
3951 | call create_addressing_space |
- | 3952 | mov ebp,ebx |
|
- | 3953 | mov ebx,[number_of_sections] |
|
3938 | imul ebx,38h |
3954 | imul ebx,38h |
3939 | add ebx,[code_start] |
3955 | add ebx,[code_start] |
3940 | add ebx,40h |
3956 | add ebx,40h |
3941 | cmp ebx,[symbols_stream] |
3957 | cmp ebx,[symbols_stream] |
3942 | jb new_elf64_segment |
3958 | jb new_elf64_segment |
Line 4013... | Line 4029... | ||
4013 | adc cl,0 |
4029 | adc cl,0 |
4014 | add eax,edi |
4030 | add eax,edi |
4015 | adc edx,0 |
4031 | adc edx,0 |
4016 | adc cl,0 |
4032 | adc cl,0 |
4017 | mov dword [org_origin],eax |
4033 | jmp elf_segment_addressing_setup |
4018 | mov dword [org_origin+4],edx |
- | |
4019 | mov [org_origin_sign],cl |
- | |
4020 | and [org_registers],0 |
- | |
4021 | mov [org_start],edi |
- | |
4022 | inc [number_of_sections] |
- | |
4023 | jmp instruction_assembled |
- | |
4024 | close_elf64_segment: |
4034 | close_elf64_segment: |
4025 | cmp [number_of_sections],0 |
4035 | cmp [number_of_sections],0 |
4026 | jne finish_elf64_segment |
4036 | jne finish_elf64_segment |
4027 | cmp edi,[symbols_stream] |
4037 | cmp edi,[symbols_stream] |
4028 | jne first_elf64_segment_ok |
4038 | jne first_elf64_segment_ok |
4029 | push edi |
4039 | push edi |