flat assembler, the next generation

Check-in [d7f8ec884e]
Login
Overview
Comment:minor rearrangements and corrections
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d7f8ec884ec240cde25d1b21bd2d64fd903be0b4
User & Date: Tomasz on 2017-09-19 08:37:30
Other Links: manifest | tags
Context
2017-09-24
18:35
new option in ELF executable formatter check-in: 46e75568bf user: Tomasz tags: trunk
2017-09-22
20:08
Reduced memory usage of LOCAL-less macros check-in: 405f908cac user: Tomasz tags: lowmem
2017-09-19
08:37
minor rearrangements and corrections check-in: d7f8ec884e user: Tomasz tags: trunk
2017-09-18
20:08
minor correction check-in: 94b111b3c6 user: Tomasz tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified examples/x86/include/format/format.inc from [9376dc026f] to [82747dd717].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
66
67
68
69
70
71
72





73
74
75
76
77
78
79
80
81
82
83
84
...
136
137
138
139
140
141
142





143
144
145
146
147
148
149

macro format? clause
	match =MZ?, clause
		format binary as 'exe'
		include 'p6.inc'
		include 'format/mz.inc'
	else match =PE? settings, clause:
		format binary as 'exe'
		PE.Settings.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_32BIT_MACHINE or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED
		PE.Settings.DllCharacteristics = 0
		local seq
		define seq settings
		while 1
			match :, seq
				break
................................................................................
				match V.v more, seq
					PE.Settings.MajorSubsystemVersion = V
					PE.Settings.MinorSubsystemVersion = v
					redefine seq more
				end match
			end match
		end while





		include 'format/pe.inc'
		include 'p6.inc'
		use32
	else match =PE64? settings, clause:
		format binary as 'exe'
		PE.Settings.Magic = 0x20B
		PE.Settings.Machine = IMAGE_FILE_MACHINE_AMD64
		PE.Settings.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_32BIT_MACHINE or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED
		PE.Settings.DllCharacteristics = 0
		PE.Settings.MajorSubsystemVersion = 5
		PE.Settings.MinorSubsystemVersion = 0
		local seq
................................................................................
				match V.v more, seq
					PE.Settings.MajorSubsystemVersion = V
					PE.Settings.MinorSubsystemVersion = v
					redefine seq more
				end match
			end match
		end while





		include 'format/pe.inc'
		include 'x64.inc'
		use64
	else match =ELF? =executable? settings, clause:
		match brand =at? base:, settings
			ELF.Settings.ABI = brand
			ELF.Settings.BaseAddress = base







<







 







>
>
>
>
>




<







 







>
>
>
>
>







1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

macro format? clause
	match =MZ?, clause
		format binary as 'exe'
		include 'p6.inc'
		include 'format/mz.inc'
	else match =PE? settings, clause:

		PE.Settings.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_32BIT_MACHINE or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED
		PE.Settings.DllCharacteristics = 0
		local seq
		define seq settings
		while 1
			match :, seq
				break
................................................................................
				match V.v more, seq
					PE.Settings.MajorSubsystemVersion = V
					PE.Settings.MinorSubsystemVersion = v
					redefine seq more
				end match
			end match
		end while
		if PE.Settings.Characteristics and IMAGE_FILE_DLL
			format binary as 'dll'
		else
			format binary as 'exe'
		end if
		include 'format/pe.inc'
		include 'p6.inc'
		use32
	else match =PE64? settings, clause:

		PE.Settings.Magic = 0x20B
		PE.Settings.Machine = IMAGE_FILE_MACHINE_AMD64
		PE.Settings.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_32BIT_MACHINE or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED
		PE.Settings.DllCharacteristics = 0
		PE.Settings.MajorSubsystemVersion = 5
		PE.Settings.MinorSubsystemVersion = 0
		local seq
................................................................................
				match V.v more, seq
					PE.Settings.MajorSubsystemVersion = V
					PE.Settings.MinorSubsystemVersion = v
					redefine seq more
				end match
			end match
		end while
		if PE.Settings.Characteristics and IMAGE_FILE_DLL
			format binary as 'dll'
		else
			format binary as 'exe'
		end if
		include 'format/pe.inc'
		include 'x64.inc'
		use64
	else match =ELF? =executable? settings, clause:
		match brand =at? base:, settings
			ELF.Settings.ABI = brand
			ELF.Settings.BaseAddress = base

Modified source/assembler.inc from [a103fabea3] to [ef7d32dc8f].

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
142
143
144
145
146
147
148




149
150
151
152
153
154
155
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
508
509
510
511
512
513
514









515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
...
601
602
603
604
605
606
607



608
609
610
611
612
613
614
	xor	eax,eax
	mov	[current_pass],eax
	mov	[first_error],eax

	mov	[file_source_cache],eax
	mov	[memory_source_cache],eax
	mov	[file_data_cache],eax
	mov	[auxiliary_output_areas],eax

	mov	[tree_stack_base],eax
	mov	[source_context],eax
	mov	[line_embeddings],eax
	mov	[directives_stack_base],eax
	mov	[counters_stack_base],eax
	mov	[operator_stack_base],eax
................................................................................
	call	create_string_map
	mov	[memory_source_cache],ebx

	mov	cl,10
	call	create_string_map
	mov	[file_data_cache],ebx





	mov	ecx,sizeof.SymbolTree_Root + sizeof.SymbolTree_Node
	call	create_tree_element
	mov	[root_namespace],eax

	call	create_parameter_namespace
	mov	[global_parameter_namespace],eax

................................................................................

assembly_shutdown:

	call	discard_errors

	mov	ebx,[auxiliary_output_areas]
	test	ebx,ebx
	jz	auxiliary_output_released
	call	destroy_string_map
    auxiliary_output_released:

	mov	ebx,[value_definition_chain]
    release_values_from_chain:
	test	ebx,ebx
	jz	values_released
	cmp	[ebx+ValueDefinition.block_length],0
	je	release_next_value
................................................................................
	test	eax,eax
	jz	file_data_released
	mov	ebx,[ebx+FileCache.next]
	call	mfree
	jmp	release_file_cache
      file_data_released:
	retn










assembly_pass:
; in:
;  esi - ASCIIZ string containing source text
;  edx - path to source file
; out:
;  cf clear if another pass is needed
; note:
;  if both string and file sources are present, they are assembled as combined text
	mov	[source_file],edx
	inc	[current_pass]
	call	discard_errors
	mov	ebx,[auxiliary_output_areas]
	test	ebx,ebx
	jz	auxiliary_output_clear
	mov	edi,dereference_auxiliary_output
	call	iterate_through_map
	xor	ebx,ebx
	xchg	ebx,[auxiliary_output_areas]
	call	destroy_string_map
	jmp	auxiliary_output_clear
      dereference_auxiliary_output:
	dec	[eax+ValueDefinition.reference_count]
	retn
      auxiliary_output_clear:
	mov	eax,[directives_stack_base]
	mov	[directives_stack],eax
	mov	eax,[root_namespace]
	mov	[current_namespace],eax
	mov	edx,[counters_stack_base]
	mov	[current_counter],edx
	xor	eax,eax
................................................................................
	mov	ebx,[source_context]
	inc	[ebx+SourceContext.number_of_entries]
	mov	esi,zero_value
	mov	ecx,4+4
	call	create_output_area
	mov	[current_area],edx
	inc	[edx+ValueDefinition.reference_count]



    assembly_line:
	xor	eax,eax
	mov	[value_position],eax
	mov	[current_constituent],al
	call	clear_line_embeddings
	call	get_line
	jc	pass_done







<







 







>
>
>
>







 







|

|







 







>
>
>
>
>
>
>
>
>












<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>







63
64
65
66
67
68
69

70
71
72
73
74
75
76
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
...
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538













539
540
541
542
543
544
545
...
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
	xor	eax,eax
	mov	[current_pass],eax
	mov	[first_error],eax

	mov	[file_source_cache],eax
	mov	[memory_source_cache],eax
	mov	[file_data_cache],eax


	mov	[tree_stack_base],eax
	mov	[source_context],eax
	mov	[line_embeddings],eax
	mov	[directives_stack_base],eax
	mov	[counters_stack_base],eax
	mov	[operator_stack_base],eax
................................................................................
	call	create_string_map
	mov	[memory_source_cache],ebx

	mov	cl,10
	call	create_string_map
	mov	[file_data_cache],ebx

	mov	cl,7
	call	create_string_map
	mov	[auxiliary_output_areas],ebx

	mov	ecx,sizeof.SymbolTree_Root + sizeof.SymbolTree_Node
	call	create_tree_element
	mov	[root_namespace],eax

	call	create_parameter_namespace
	mov	[global_parameter_namespace],eax

................................................................................

assembly_shutdown:

	call	discard_errors

	mov	ebx,[auxiliary_output_areas]
	test	ebx,ebx
	jz	auxiliary_output_areas_released
	call	destroy_string_map
    auxiliary_output_areas_released:

	mov	ebx,[value_definition_chain]
    release_values_from_chain:
	test	ebx,ebx
	jz	values_released
	cmp	[ebx+ValueDefinition.block_length],0
	je	release_next_value
................................................................................
	test	eax,eax
	jz	file_data_released
	mov	ebx,[ebx+FileCache.next]
	call	mfree
	jmp	release_file_cache
      file_data_released:
	retn

    release_auxiliary_output:
	test	eax,eax
	jz	auxiliary_output_released
	dec	[eax+ValueDefinition.reference_count]
	xor	eax,eax
	mov	[edx+MapEntry.value],eax
      auxiliary_output_released:
	retn

assembly_pass:
; in:
;  esi - ASCIIZ string containing source text
;  edx - path to source file
; out:
;  cf clear if another pass is needed
; note:
;  if both string and file sources are present, they are assembled as combined text
	mov	[source_file],edx
	inc	[current_pass]
	call	discard_errors













	mov	eax,[directives_stack_base]
	mov	[directives_stack],eax
	mov	eax,[root_namespace]
	mov	[current_namespace],eax
	mov	edx,[counters_stack_base]
	mov	[current_counter],edx
	xor	eax,eax
................................................................................
	mov	ebx,[source_context]
	inc	[ebx+SourceContext.number_of_entries]
	mov	esi,zero_value
	mov	ecx,4+4
	call	create_output_area
	mov	[current_area],edx
	inc	[edx+ValueDefinition.reference_count]
	mov	ebx,[auxiliary_output_areas]
	mov	edi,release_auxiliary_output
	call	iterate_through_map
    assembly_line:
	xor	eax,eax
	mov	[value_position],eax
	mov	[current_constituent],al
	call	clear_line_embeddings
	call	get_line
	jc	pass_done

Modified source/directives.inc from [9a2c1a1edf] to [cb66b11b44].

943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
....
4615
4616
4617
4618
4619
4620
4621
4622
4623




4624



4625
4626
4627
4628
4629
4630
4631
	jne	invalid_argument
	cmp	[edx+ValueDefinition.value],PREPOSITION_AS
	jne	invalid_argument
	call	get_constant_value
	cmp	al,22h
	jne	invalid_argument
	mov	ebx,[auxiliary_output_areas]
	test	ebx,ebx
	jnz	register_auxiliary_output
	mov	cl,7
	push	edx esi
	call	create_string_map
	pop	esi edx
	mov	[auxiliary_output_areas],ebx
      register_auxiliary_output:
	mov	edi,esi
	mov	ecx,[edx]
	lea	esi,[edx+4]
	mov	eax,[current_area]
	inc	[eax+ValueDefinition.reference_count]
	push	ecx
	call	put_into_map
................................................................................
	jne	repeated_declaration
	call	get_constant_value
	cmp	al,22h
	jne	invalid_argument
	mov	edi,esi
	mov	ecx,[edx]
	lea	esi,[edx+4]
	call	store_string
	mov	[output_extension],esi




	mov	[output_extension_length],ecx



    validate_extension:
	mov	ebx,characters
    scan_extension:
	test	ecx,ecx
	jz	extension_valid
	lodsb
	xlatb







<
<
<
<
<
<
<
<







 







<
|
>
>
>
>
|
>
>
>







943
944
945
946
947
948
949








950
951
952
953
954
955
956
....
4607
4608
4609
4610
4611
4612
4613

4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
	jne	invalid_argument
	cmp	[edx+ValueDefinition.value],PREPOSITION_AS
	jne	invalid_argument
	call	get_constant_value
	cmp	al,22h
	jne	invalid_argument
	mov	ebx,[auxiliary_output_areas]








	mov	edi,esi
	mov	ecx,[edx]
	lea	esi,[edx+4]
	mov	eax,[current_area]
	inc	[eax+ValueDefinition.reference_count]
	push	ecx
	call	put_into_map
................................................................................
	jne	repeated_declaration
	call	get_constant_value
	cmp	al,22h
	jne	invalid_argument
	mov	edi,esi
	mov	ecx,[edx]
	lea	esi,[edx+4]

	mov	[output_extension_length],ecx
	mov	ebx,[auxiliary_output_areas]
	call	get_from_map
	jnc	extension_stored
	xor	eax,eax
	mov	ecx,[output_extension_length]
	call	put_into_map
    extension_stored:
	mov	[output_extension],esi
    validate_extension:
	mov	ebx,characters
    scan_extension:
	test	ecx,ecx
	jz	extension_valid
	lodsb
	xlatb

Modified source/map.inc from [1e47d14a1c] to [6a9b2e93f5].

184
185
186
187
188
189
190

191
192
193
194
195
196
197
; in:
;  ebx - map
;  edi - callback function
; callback:
;  eax = value
;  esi - string
;  ecx = string length

	mov	ecx,[ebx+Map.hash_mask]
	inc	ecx
	add	ebx,sizeof.Map
    iterate_through_hash_table:
	mov	edx,[ebx]
    iterate_through_bucket:
	test	edx,edx







>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
; in:
;  ebx - map
;  edi - callback function
; callback:
;  eax = value
;  esi - string
;  ecx = string length
;  edx - MapEntry
	mov	ecx,[ebx+Map.hash_mask]
	inc	ecx
	add	ebx,sizeof.Map
    iterate_through_hash_table:
	mov	edx,[ebx]
    iterate_through_bucket:
	test	edx,edx

Modified source/output.inc from [ae60a80778] to [2e3e100e3f].

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462


463
464
465
466
467
468
469
	cmp	esi,[current_output_area_entry]
	je	close_output_file
	mov	esi,[esi+AreaEntry.next]
	jmp	write_area
    close_output_file:
	call	close
	mov	ebx,[auxiliary_output_areas]
	test	ebx,ebx
	jz	output_done
	mov	edi,write_auxiliary_output_area
	call	iterate_through_map
	cmp	[output_failures],0
	jne	output_write_failed
    output_done:
	clc
	retn
    file_write_failed:
	call	close
    output_write_failed:
	stc
	retn

write_auxiliary_output_area:
; in:
;  eax = ValueDefinition
;  esi - file extension
;  ecx = length of the extension


	mov	ebx,[base_path]
	test	ebx,ebx
	jz	auxiliary_output_processed
	push	eax
	call	create_output_path
	call	create
	pop	edx







<
<




<










|


>
>







436
437
438
439
440
441
442


443
444
445
446

447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
	cmp	esi,[current_output_area_entry]
	je	close_output_file
	mov	esi,[esi+AreaEntry.next]
	jmp	write_area
    close_output_file:
	call	close
	mov	ebx,[auxiliary_output_areas]


	mov	edi,write_auxiliary_output_area
	call	iterate_through_map
	cmp	[output_failures],0
	jne	output_write_failed

	clc
	retn
    file_write_failed:
	call	close
    output_write_failed:
	stc
	retn

write_auxiliary_output_area:
; in:
;  eax = ValueDefinition, null for cached extension not used for auxiliary output
;  esi - file extension
;  ecx = length of the extension
	test	eax,eax
	jz	auxiliary_output_processed
	mov	ebx,[base_path]
	test	ebx,ebx
	jz	auxiliary_output_processed
	push	eax
	call	create_output_path
	call	create
	pop	edx

Modified source/version.inc from [425cf6b7ce] to [fcb207ffad].

1
VERSION equ "hxh48"
|
1
VERSION equ "hxhsr"