4 include 'macro/struct.inc'
14 include '../version.inc'
21 stack
stack_segment:stack_top
-stack_bottom
30 or ax,ax ; DPMI installed?
32 test bl,1 ; 32-bit programs supported?
34 mov word [cs:mode_switch
],di
35 mov word [cs:mode_switch
+2],es
36 mov bx,si ; allocate memory for DPMI data
39 jnc switch_to_protected_mode
42 db 'DPMI initialization failed.',0Dh,0Ah,0
45 db '32-bit DPMI services are not available.',0Dh,0Ah,0
61 switch_to_protected_mode:
65 call far [cs:mode_switch
] ; switch to protected mode
69 int 31h ; allocate descriptor for code
73 int 31h ; allocate descriptor for data
82 int 31h ; set code descriptor access rights
89 int 31h ; set data descriptor access rights
96 int 31h ; set data descriptor base address
99 int 31h ; set code descriptor base address
103 mov ax,8 ; set segment limit to 4 GB
111 mov [main_selector
],di
112 mov [psp_selector
],es
113 mov gs,ax ; environment selector in GS
121 int 31h ; allocate descriptor for BIOS data segment
128 int 31h ; set descriptor access rights
133 int 31h ; set base address of BIOS data segment
138 int 31h ; set limit of BIOS data segment
140 mov fs,bx ; BIOS data selector in FS
162 jnz display_usage_information
165 mov ecx,[verbosity_level
]
167 or al,TRACE_ERROR_STACK
179 mov esi,[initial_commands
]
180 mov edx,[source_path
]
184 mov eax,[current_pass
]
185 cmp eax,[maximum_number_of_passes
]
188 call show_display_data
190 mov esi,_error_prefix
192 call display_error_string
193 mov esi,_code_cannot_be_generated
195 call display_error_string
196 mov esi,_message_suffix
198 call display_error_string
204 call show_display_data
211 mov eax,[current_pass
]
217 jne display_passes_suffix
219 display_passes_suffix:
232 jz display_output_length
236 mov esi,_message_suffix
246 display_output_length:
247 call get_output_length
254 jne display_bytes_suffix
256 jnz display_bytes_suffix
258 display_bytes_suffix:
266 mov ebx,[source_path
]
267 mov edi,[output_path
]
268 call write_output_file
271 call assembly_shutdown
281 call assembly_shutdown
288 mov ebx,_write_failed
292 mov ebx,_out_of_memory
297 mov esi,_error_prefix
299 call display_error_string
302 call display_error_string
303 mov esi,_message_suffix
305 call display_error_string
307 call assembly_shutdown
313 display_usage_information:
326 mov ds,[psp_selector
]
333 je command_line_moved
335 loop move_command_line
340 mov [initial_commands
],eax
341 mov [source_path
],eax
342 mov [output_path
],eax
344 mov [verbosity_level
],eax
345 mov [maximum_number_of_passes
],100
346 mov [maximum_number_of_errors
],1
347 mov [maximum_depth_of_stack
],10000
348 mov [maximum_depth_of_stack
],10000
371 jne next_argument_found
373 jmp find_next_argument
390 mov [source_path
],edi
393 mov [output_path
],edi
397 je error_in_arguments
409 je insert_initial_command
411 je insert_initial_command
417 je set_recursion_limit
419 je set_recursion_limit
427 jne error_in_arguments
432 je find_next_argument
434 jnz error_in_arguments
435 jmp find_next_argument
437 call get_option_value
438 jc error_in_arguments
440 ja error_in_arguments
441 mov [verbosity_level
],edx
442 jmp find_next_argument
444 call get_option_value
445 jc error_in_arguments
447 jz error_in_arguments
448 mov [maximum_number_of_errors
],edx
449 jmp find_next_argument
451 call get_option_value
452 jc error_in_arguments
454 jz error_in_arguments
455 mov [maximum_depth_of_stack
],edx
456 jmp find_next_argument
458 call get_option_value
459 jc error_in_arguments
461 jz error_in_arguments
462 mov [maximum_number_of_passes
],edx
463 jmp find_next_argument
471 jmp find_option_value
479 jc invalid_option_value
481 ja invalid_option_value
483 jo invalid_option_value
485 jc invalid_option_value
491 invalid_option_value:
494 insert_initial_command:
496 find_command_segment:
498 jne command_segment_found
500 jmp find_command_segment
501 command_segment_found:
504 jne measure_command_segment
507 measure_command_segment:
509 scan_command_segment:
513 jz command_segment_measured
515 je command_segment_measured
517 je command_segment_measured
520 jne scan_command_segment
521 command_segment_measured:
523 mov edi,[initial_commands
]
526 jz allocate_initial_commands_buffer
527 mov edx,[initial_commands_length
]
530 cmp eax,[initial_commands_maximum_length
]
531 ja grow_initial_commands_buffer
532 copy_initial_command:
536 sub edi,[initial_commands
]
537 mov [initial_commands_length
],edi
540 jz initial_command_ready
542 jne command_segment_found
543 initial_command_ready:
544 mov edi,[initial_commands
]
545 add edi,[initial_commands_length
]
548 inc [initial_commands_length
]
550 jmp find_next_argument
551 allocate_initial_commands_buffer:
555 mov [initial_commands
],eax
556 mov [initial_commands_maximum_length
],ecx
559 jmp copy_initial_command
560 grow_initial_commands_buffer:
563 mov eax,[initial_commands
]
565 mov [initial_commands
],eax
566 mov [initial_commands_maximum_length
],ecx
568 add edi,[initial_commands_length
]
570 jmp copy_initial_command
574 include '../assembler.inc'
575 include '../symbols.inc'
576 include '../expressions.inc'
577 include '../conditions.inc'
578 include '../floats.inc'
579 include '../directives.inc'
580 include '../calm.inc'
581 include '../errors.inc'
583 include '../reader.inc'
584 include '../output.inc'
585 include '../console.inc'
587 _logo
db 'flat assembler version g.',VERSION
,13,10,0
589 _usage
db 'Usage: fasmg source [output]',13,10
590 db 'Optional settings:',13,10
591 db ' -e limit Set the maximum number of displayed errors (default 1)',13,10
592 db ' -p limit Set the maximum allowed number of passes (default 100)',13,10
593 db ' -r limit Set the maximum depth of the stack (default 10000)',13,10
594 db ' -v flag Enable or disable showing all lines from the stack (default 0)',13,10
595 db ' -i command Insert instruction at the beginning of source',13,10
596 db ' -n Do not show logo nor summary',13,10
600 _passes
db ' passes, ',0
602 _seconds
db ' seconds, ',0
604 _bytes
db ' bytes.',0
606 _write_failed
db 'failed to write the output file',0
607 _out_of_memory
db 'not enough memory to complete the assembly',0
608 _code_cannot_be_generated
db 'could not generate code within the allowed number of passes',0
610 include '../tables.inc'
611 include '../messages.inc'
615 include '../variables.inc'
624 maximum_number_of_passes
dd ?
626 initial_commands
dd ?
627 initial_commands_length
dd ?
628 initial_commands_maximum_length
dd ?
636 command_line
db 80h dup
?
637 parameters
db 80h dup
?
639 segment buffer_segment
641 buffer
= (buffer_segment
-main
) shl 4
645 segment stack_segment
647 stack_bottom
= (stack_segment
-main
) shl 4
651 stack_top
= stack_bottom
+ $