Rev 992 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 992 | Rev 2287 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | symbol_dump: |
- | |
Line 2... | Line -... | ||
2 | - | ||
3 | push edi |
- | |
4 | mov edx,[memory_end] |
1 | ; flat assembler core |
5 | symb_dump: |
- | |
6 | cmp edx,[labels_list] |
- | |
7 | jbe symbols_dumped |
- | |
8 | sub edx,LABEL_STRUCTURE_SIZE |
- | |
9 | cmp dword [edx+24],0 |
2 | ; Copyright (c) 1999-2011, Tomasz Grysztar. |
10 | je symb_dump ; do not dump anonymous symbols |
3 | ; All rights reserved. |
11 | test byte [edx+8],1 |
- | |
12 | jz symb_dump ; do not dump symbols that didn't get defined |
- | |
13 | mov ax,[current_pass] |
- | |
14 | cmp ax,[edx+16] |
- | |
15 | jne symb_dump |
- | |
16 | test byte [edx+8],4 or 2 |
- | |
17 | jnz symb_dump ; do not dump assembly-time variables |
- | |
18 | ; do not dump variables defined with '=' |
- | |
19 | cmp word [edx+12], 0 |
- | |
20 | jnz symb_dump ; do not dump register-based variables |
- | |
21 | - | ||
22 | mov al, '0' |
- | |
23 | stosb |
- | |
24 | mov al, 'x' |
- | |
25 | stosb |
- | |
26 | mov eax, [edx+4] |
- | |
27 | mov ecx, 8 |
- | |
28 | @@: |
- | |
29 | rol eax, 4 |
- | |
30 | test al, 0xF |
- | |
31 | loopz @b |
- | |
32 | jz .nohigh |
- | |
33 | inc ecx |
- | |
34 | @@: |
- | |
35 | push eax |
- | |
36 | and al, 0xF |
- | |
37 | cmp al, 10 |
- | |
38 | sbb al, 69h |
- | |
39 | das |
- | |
40 | stosb |
- | |
41 | pop eax |
- | |
42 | rol eax, 4 |
- | |
43 | loop @b |
- | |
44 | mov eax, [edx] |
- | |
45 | mov ecx, 8 |
- | |
46 | jmp .low |
- | |
47 | .nohigh: |
- | |
48 | mov eax, [edx] |
- | |
49 | mov ecx, 8 |
- | |
50 | @@: |
- | |
51 | rol eax, 4 |
- | |
52 | test al, 0xF |
- | |
53 | loopz @b |
- | |
54 | inc ecx |
- | |
55 | .low: |
- | |
56 | push eax |
- | |
57 | and al, 0xF |
- | |
58 | cmp al, 10 |
- | |
59 | sbb al, 69h |
- | |
60 | das |
- | |
61 | stosb |
- | |
62 | pop eax |
- | |
63 | rol eax, 4 |
- | |
Line -... | Line 4... | ||
- | 4 | ||
- | 5 | dump_symbols: |
|
- | 6 | mov edi,[code_start] |
|
- | 7 | call setup_dump_header |
|
- | 8 | mov esi,[input_file] |
|
- | 9 | call copy_asciiz |
|
- | 10 | cmp edi,[display_buffer] |
|
- | 11 | jae out_of_memory |
|
- | 12 | mov eax,edi |
|
- | 13 | sub eax,ebx |
|
- | 14 | mov [ebx-38h+0Ch],eax |
|
- | 15 | mov esi,[output_file] |
|
- | 16 | call copy_asciiz |
|
- | 17 | cmp edi,[display_buffer] |
|
- | 18 | jae out_of_memory |
|
- | 19 | mov edx,[symbols_stream] |
|
- | 20 | mov ebp,[free_additional_memory] |
|
- | 21 | mov [number_of_sections],0 |
|
- | 22 | cmp [output_format],4 |
|
- | 23 | je prepare_strings_table |
|
- | 24 | cmp [output_format],5 |
|
- | 25 | jne strings_table_ready |
|
- | 26 | bt [format_flags],0 |
|
- | 27 | jc strings_table_ready |
|
- | 28 | prepare_strings_table: |
|
- | 29 | cmp edx,ebp |
|
64 | loop .low |
30 | je strings_table_ready |
- | 31 | mov al,[edx] |
|
- | 32 | test al,al |
|
- | 33 | jz prepare_string |
|
- | 34 | cmp al,80h |
|
- | 35 | je prepare_string |
|
- | 36 | add edx,0Ch |
|
- | 37 | cmp al,0C0h |
|
- | 38 | jb prepare_strings_table |
|
- | 39 | add edx,4 |
|
- | 40 | jmp prepare_strings_table |
|
- | 41 | prepare_string: |
|
65 | 42 | mov esi,edi |
|
- | 43 | sub esi,ebx |
|
- | 44 | xchg esi,[edx+4] |
|
- | 45 | test al,al |
|
- | 46 | jz prepare_section_string |
|
- | 47 | or dword [edx+4],1 shl 31 |
|
- | 48 | add edx,0Ch |
|
- | 49 | prepare_external_string: |
|
- | 50 | mov ecx,[esi] |
|
- | 51 | add esi,4 |
|
- | 52 | rep movs byte [edi],[esi] |
|
- | 53 | mov byte [edi],0 |
|
- | 54 | inc edi |
|
- | 55 | cmp edi,[display_buffer] |
|
- | 56 | jae out_of_memory |
|
- | 57 | jmp prepare_strings_table |
|
- | 58 | prepare_section_string: |
|
- | 59 | mov ecx,[number_of_sections] |
|
66 | mov al, ' ' |
60 | mov eax,ecx |
- | 61 | inc eax |
|
- | 62 | mov [number_of_sections],eax |
|
- | 63 | xchg eax,[edx+4] |
|
- | 64 | shl ecx,2 |
|
- | 65 | add ecx,[free_additional_memory] |
|
- | 66 | mov [ecx],eax |
|
- | 67 | add edx,20h |
|
- | 68 | test esi,esi |
|
- | 69 | jz prepare_default_section_string |
|
- | 70 | cmp [output_format],5 |
|
- | 71 | jne prepare_external_string |
|
- | 72 | bt [format_flags],0 |
|
- | 73 | jc prepare_external_string |
|
- | 74 | mov esi,[esi] |
|
- | 75 | add esi,[resource_data] |
|
- | 76 | copy_elf_section_name: |
|
- | 77 | lods byte [esi] |
|
- | 78 | cmp edi,[display_buffer] |
|
- | 79 | jae out_of_memory |
|
- | 80 | stos byte [edi] |
|
- | 81 | test al,al |
|
- | 82 | jnz copy_elf_section_name |
|
- | 83 | jmp prepare_strings_table |
|
- | 84 | prepare_default_section_string: |
|
- | 85 | mov eax,'.fla' |
|
- | 86 | stos dword [edi] |
|
- | 87 | mov ax,'t' |
|
- | 88 | stos word [edi] |
|
- | 89 | cmp edi,[display_buffer] |
|
- | 90 | jae out_of_memory |
|
- | 91 | jmp prepare_strings_table |
|
- | 92 | strings_table_ready: |
|
- | 93 | mov edx,[display_buffer] |
|
- | 94 | mov ebp,[memory_end] |
|
- | 95 | sub ebp,[labels_list] |
|
- | 96 | add ebp,edx |
|
- | 97 | prepare_labels_dump: |
|
- | 98 | cmp edx,ebp |
|
67 | stosb |
99 | je labels_dump_ok |
- | 100 | mov eax,[edx+24] |
|
- | 101 | test eax,eax |
|
- | 102 | jz label_dump_name_ok |
|
- | 103 | cmp eax,[memory_start] |
|
- | 104 | jb label_name_outside_source |
|
- | 105 | cmp eax,[source_start] |
|
- | 106 | ja label_name_outside_source |
|
- | 107 | sub eax,[memory_start] |
|
- | 108 | dec eax |
|
- | 109 | mov [edx+24],eax |
|
- | 110 | jmp label_dump_name_ok |
|
- | 111 | label_name_outside_source: |
|
- | 112 | mov esi,eax |
|
- | 113 | mov eax,edi |
|
- | 114 | sub eax,ebx |
|
- | 115 | or eax,1 shl 31 |
|
68 | 116 | mov [edx+24],eax |
|
- | 117 | movzx ecx,byte [esi-1] |
|
- | 118 | lea eax,[edi+ecx+1] |
|
- | 119 | cmp edi,[display_buffer] |
|
69 | mov esi,[edx+24] |
120 | jae out_of_memory |
70 | movzx ecx,byte [esi-1] |
- | |
71 | rep movsb |
121 | rep movsb |
72 | - | ||
73 | mov ax,0A0Dh |
- | |
74 | stosw |
- | |
75 | - | ||
76 | jmp symb_dump |
- | |
77 | - | ||
78 | symbols_dumped: |
- | |
79 | mov edx,dbgfilename |
- | |
80 | push esi edi |
- | |
81 | mov esi, outfile |
- | |
82 | mov edi, edx |
- | |
83 | @@: |
122 | xor al,al |
- | 123 | stosb |
|
- | 124 | label_dump_name_ok: |
|
84 | lodsb |
125 | mov eax,[edx+28] |
- | 126 | test eax,eax |
|
- | 127 | jz label_dump_line_ok |
|
- | 128 | sub eax,[memory_start] |
|
- | 129 | mov [edx+28],eax |
|
- | 130 | label_dump_line_ok: |
|
- | 131 | mov eax,[edx+20] |
|
- | 132 | test eax,eax |
|
- | 133 | jz base_symbol_for_label_ok |
|
- | 134 | cmp eax,[symbols_stream] |
|
- | 135 | mov eax,[eax+4] |
|
- | 136 | jae base_symbol_for_label_ok |
|
- | 137 | xor eax,eax |
|
- | 138 | base_symbol_for_label_ok: |
|
- | 139 | mov [edx+20],eax |
|
- | 140 | mov ax,[current_pass] |
|
- | 141 | cmp ax,[edx+16] |
|
- | 142 | je label_defined_flag_ok |
|
- | 143 | and byte [edx+8],not 1 |
|
- | 144 | label_defined_flag_ok: |
|
- | 145 | cmp ax,[edx+18] |
|
- | 146 | je label_used_flag_ok |
|
- | 147 | and byte [edx+8],not 8 |
|
- | 148 | label_used_flag_ok: |
|
- | 149 | add edx,LABEL_STRUCTURE_SIZE |
|
- | 150 | jmp prepare_labels_dump |
|
- | 151 | labels_dump_ok: |
|
- | 152 | mov eax,edi |
|
- | 153 | sub eax,ebx |
|
- | 154 | mov [ebx-38h+14h],eax |
|
- | 155 | add eax,38h |
|
- | 156 | mov [ebx-38h+18h],eax |
|
- | 157 | mov ecx,[memory_end] |
|
- | 158 | sub ecx,[labels_list] |
|
- | 159 | mov [ebx-38h+1Ch],ecx |
|
- | 160 | add eax,ecx |
|
- | 161 | mov [ebx-38h+20h],eax |
|
- | 162 | mov ecx,[source_start] |
|
- | 163 | sub ecx,[memory_start] |
|
- | 164 | mov [ebx-38h+24h],ecx |
|
- | 165 | add eax,ecx |
|
- | 166 | mov [ebx-38h+28h],eax |
|
85 | stosb |
167 | mov eax,[number_of_sections] |
- | 168 | shl eax,2 |
|
- | 169 | mov [ebx-38h+34h],eax |
|
- | 170 | call prepare_preprocessed_source |
|
- | 171 | mov esi,[labels_list] |
|
- | 172 | mov ebp,edi |
|
- | 173 | make_lines_dump: |
|
- | 174 | cmp esi,[display_buffer] |
|
86 | test al, al |
175 | je lines_dump_ok |
87 | jnz @b |
176 | mov eax,[esi-4] |
88 | lea ecx, [edi-1] |
177 | mov ecx,[esi-8] |
89 | @@: |
178 | sub esi,8 |
90 | dec edi |
179 | sub esi,ecx |
- | 180 | cmp eax,1 |
|
- | 181 | jne make_lines_dump |
|
- | 182 | mov eax,[esi+4] |
|
- | 183 | sub eax,[code_start] |
|
91 | cmp edi, edx |
184 | add eax,[headers_size] |
- | 185 | cmp byte [esi+1Ah],0 |
|
- | 186 | je store_offset |
|
- | 187 | xor eax,eax |
|
- | 188 | store_offset: |
|
- | 189 | stos dword [edi] |
|
- | 190 | mov eax,[esi] |
|
- | 191 | sub eax,[memory_start] |
|
- | 192 | stos dword [edi] |
|
- | 193 | mov eax,[esi+4] |
|
- | 194 | xor edx,edx |
|
- | 195 | sub eax,[esi+8] |
|
- | 196 | sbb edx,[esi+8+4] |
|
- | 197 | stos dword [edi] |
|
- | 198 | mov eax,edx |
|
- | 199 | stos dword [edi] |
|
- | 200 | mov eax,[esi+10h] |
|
- | 201 | stos dword [edi] |
|
- | 202 | mov eax,[esi+14h] |
|
- | 203 | test eax,eax |
|
- | 204 | jz base_symbol_for_line_ok |
|
- | 205 | cmp eax,[symbols_stream] |
|
- | 206 | mov eax,[eax+4] |
|
92 | jb @f |
207 | jae base_symbol_for_line_ok |
- | 208 | xor eax,eax |
|
- | 209 | base_symbol_for_line_ok: |
|
- | 210 | stos dword [edi] |
|
- | 211 | mov eax,[esi+18h] |
|
- | 212 | and eax,001FFFFh |
|
- | 213 | stos dword [edi] |
|
- | 214 | cmp edi,[display_buffer] |
|
93 | cmp byte [edi], '/' |
215 | jae out_of_memory |
- | 216 | jmp make_lines_dump |
|
94 | jz @f |
217 | lines_dump_ok: |
- | 218 | mov edx,edi |
|
- | 219 | mov eax,[current_offset] |
|
- | 220 | sub eax,[code_start] |
|
- | 221 | add eax,[headers_size] |
|
95 | cmp byte [edi], '.' |
222 | stos dword [edi] |
- | 223 | mov ecx,edi |
|
- | 224 | sub ecx,ebx |
|
- | 225 | sub ecx,[ebx-38h+14h] |
|
- | 226 | mov [ebx-38h+2Ch],ecx |
|
- | 227 | add ecx,[ebx-38h+28h] |
|
- | 228 | mov [ebx-38h+30h],ecx |
|
96 | jnz @b |
229 | find_inexisting_offsets: |
- | 230 | sub edx,1Ch |
|
- | 231 | cmp edx,ebp |
|
- | 232 | jb write_symbols |
|
- | 233 | test byte [edx+1Ah],1 |
|
- | 234 | jnz find_inexisting_offsets |
|
- | 235 | cmp eax,[edx] |
|
- | 236 | jb correct_inexisting_offset |
|
- | 237 | mov eax,[edx] |
|
- | 238 | jmp find_inexisting_offsets |
|
97 | mov ecx, edi |
239 | correct_inexisting_offset: |
98 | @@: |
240 | mov dword [edx],0 |
- | 241 | or byte [edx+1Ah],2 |
|
- | 242 | jmp find_inexisting_offsets |
|
99 | mov dword [ecx], '.dbg' |
243 | write_symbols: |
100 | mov byte [ecx+4], 0 |
244 | mov edx,[symbols_file] |
- | 245 | call create |
|
- | 246 | jc write_failed |
|
- | 247 | mov edx,[code_start] |
|
- | 248 | mov ecx,[edx+14h] |
|
- | 249 | add ecx,38h |
|
- | 250 | call write |
|
- | 251 | jc write_failed |
|
- | 252 | mov edx,[display_buffer] |
|
- | 253 | mov ecx,[memory_end] |
|
- | 254 | sub ecx,[labels_list] |
|
- | 255 | call write |
|
- | 256 | jc write_failed |
|
- | 257 | mov edx,[memory_start] |
|
- | 258 | mov ecx,[source_start] |
|
- | 259 | sub ecx,edx |
|
- | 260 | call write |
|
101 | pop edi esi |
261 | jc write_failed |
102 | call create |
262 | mov edx,ebp |
103 | mov edx,[esp] |
263 | mov ecx,edi |
104 | mov ecx,edi |
264 | sub ecx,edx |
- | 265 | call write |
|
- | 266 | jc write_failed |
|
- | 267 | mov edx,[free_additional_memory] |
|
- | 268 | mov ecx,[number_of_sections] |
|
- | 269 | shl ecx,2 |
|
- | 270 | call write |
|
- | 271 | jc write_failed |
|
- | 272 | call close |
|
- | 273 | ret |
|
- | 274 | setup_dump_header: |
|
- | 275 | xor eax,eax |
|
- | 276 | mov ecx,38h shr 2 |
|
- | 277 | rep stos dword [edi] |
|
- | 278 | mov ebx,edi |
|
- | 279 | mov dword [ebx-38h],'fas'+1Ah shl 24 |
|
- | 280 | mov dword [ebx-38h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16 |
|
- | 281 | mov dword [ebx-38h+10h],38h |
|
- | 282 | ret |
|
- | 283 | prepare_preprocessed_source: |
|
- | 284 | mov esi,[memory_start] |
|
- | 285 | mov ebp,[source_start] |
|
- | 286 | test ebp,ebp |
|
- | 287 | jnz prepare_preprocessed_line |
|
- | 288 | mov ebp,[current_line] |
|
- | 289 | inc ebp |
|
- | 290 | prepare_preprocessed_line: |
|
- | 291 | cmp esi,ebp |
|
- | 292 | jae preprocessed_source_ok |
|
- | 293 | mov eax,[memory_start] |
|
- | 294 | mov edx,[input_file] |
|
- | 295 | cmp [esi],edx |
|
- | 296 | jne line_not_from_main_input |
|
- | 297 | mov [esi],eax |
|
- | 298 | line_not_from_main_input: |
|
- | 299 | sub [esi],eax |
|
- | 300 | test byte [esi+7],1 shl 7 |
|
- | 301 | jz prepare_next_preprocessed_line |
|
- | 302 | sub [esi+8],eax |
|
- | 303 | sub [esi+12],eax |
|
- | 304 | prepare_next_preprocessed_line: |
|
- | 305 | call skip_preprocessed_line |
|
- | 306 | jmp prepare_preprocessed_line |
|
- | 307 | preprocessed_source_ok: |
|
- | 308 | ret |
|
- | 309 | skip_preprocessed_line: |
|
- | 310 | add esi,16 |
|
- | 311 | skip_preprocessed_line_content: |
|
- | 312 | lods byte [esi] |
|
- | 313 | cmp al,1Ah |
|
- | 314 | je skip_preprocessed_symbol |
|
- | 315 | cmp al,3Bh |
|
- | 316 | je skip_preprocessed_symbol |
|
- | 317 | cmp al,22h |
|
- | 318 | je skip_preprocessed_string |
|
- | 319 | or al,al |
|
- | 320 | jnz skip_preprocessed_line_content |
|
- | 321 | ret |
|
- | 322 | skip_preprocessed_string: |
|
- | 323 | lods dword [esi] |
|
- | 324 | add esi,eax |
|
- | 325 | jmp skip_preprocessed_line_content |
|
- | 326 | skip_preprocessed_symbol: |
|
- | 327 | lods byte [esi] |
|
- | 328 | movzx eax,al |
|
- | 329 | add esi,eax |
|
- | 330 | jmp skip_preprocessed_line_content |
|
- | 331 | restore_preprocessed_source: |
|
- | 332 | mov esi,[memory_start] |
|
- | 333 | mov ebp,[source_start] |
|
- | 334 | test ebp,ebp |
|
- | 335 | jnz restore_preprocessed_line |
|
- | 336 | mov ebp,[current_line] |
|
- | 337 | inc ebp |
|
- | 338 | restore_preprocessed_line: |
|
- | 339 | cmp esi,ebp |
|
- | 340 | jae preprocessed_source_restored |
|
- | 341 | mov eax,[memory_start] |
|
- | 342 | add [esi],eax |
|
- | 343 | cmp [esi],eax |
|
- | 344 | jne preprocessed_line_source_restored |
|
- | 345 | mov edx,[input_file] |
|
- | 346 | mov [esi],edx |
|
- | 347 | preprocessed_line_source_restored: |
|
- | 348 | test byte [esi+7],1 shl 7 |
|
- | 349 | jz restore_next_preprocessed_line |
|
- | 350 | add [esi+8],eax |
|
- | 351 | add [esi+12],eax |
|
- | 352 | restore_next_preprocessed_line: |
|
- | 353 | call skip_preprocessed_line |
|
- | 354 | jmp restore_preprocessed_line |
|
- | 355 | preprocessed_source_restored: |
|
- | 356 | ret |
|
- | 357 | dump_preprocessed_source: |
|
- | 358 | mov edi,[free_additional_memory] |
|
- | 359 | call setup_dump_header |
|
- | 360 | mov esi,[input_file] |
|
- | 361 | call copy_asciiz |
|
- | 362 | cmp edi,[additional_memory_end] |
|
- | 363 | jae out_of_memory |
|
- | 364 | mov eax,edi |
|
- | 365 | sub eax,ebx |
|
- | 366 | dec eax |
|
- | 367 | mov [ebx-38h+0Ch],eax |
|
- | 368 | mov eax,edi |
|
- | 369 | sub eax,ebx |
|
- | 370 | mov [ebx-38h+14h],eax |
|
- | 371 | add eax,38h |
|
- | 372 | mov [ebx-38h+20h],eax |
|
- | 373 | call prepare_preprocessed_source |
|
- | 374 | sub esi,[memory_start] |
|
- | 375 | mov [ebx-38h+24h],esi |
|
- | 376 | mov edx,[symbols_file] |
|
- | 377 | call create |
|
- | 378 | jc write_failed |
|
- | 379 | mov edx,[free_additional_memory] |
|
- | 380 | mov ecx,[edx+14h] |
|
- | 381 | add ecx,38h |
|
- | 382 | call write |
|
- | 383 | jc write_failed |
|
- | 384 | mov edx,[memory_start] |
|
- | 385 | mov ecx,esi |
|
- | 386 | call write |
|
105 | sub ecx,edx |
387 | jc write_failed |
106 | call write |
- | |
107 | call close |
- | |
108 | pop edi |
388 | call close |