Subversion Repositories Kolibri OS

Rev

Rev 31 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 109
Line 1... Line 1...
1
; flat assembler core
1
; flat assembler core
2
; Copyright (c) 1999-2005, Tomasz Grysztar.
2
; Copyright (c) 1999-2006, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
Line 4... Line 4...
4
 
4
 
5
assembler:
-
 
6
	mov	ecx,[memory_end]
-
 
7
	mov	edi,[labels_list]
-
 
8
	sub	ecx,edi
-
 
9
	cmp	edi,[code_start]
-
 
10
	jbe	out_of_memory
-
 
11
	shr	ecx,2
5
assembler:
12
	xor	eax,eax
-
 
13
	rep	stos dword [edi]
6
        xor     eax,eax
14
	mov	[stub_size],eax
7
        mov     [stub_size],eax
15
	mov	[number_of_sections],eax
8
        mov     [number_of_sections],eax
-
 
9
        mov     [current_pass],ax
16
	mov	[current_pass],ax
10
        mov     [resolver_flags],eax
17
      assembler_loop:
11
      assembler_loop:
18
	mov	eax,[labels_list]
12
        mov     eax,[labels_list]
19
	mov	[display_buffer],eax
13
        mov     [display_buffer],eax
20
	mov	eax,[additional_memory]
14
        mov     eax,[additional_memory]
Line 109... Line 103...
109
	je	check_next_symbol
103
        je      check_next_symbol
110
      define_misprediction:
104
      define_misprediction:
111
	or	[next_pass_needed],-1
105
        or      [next_pass_needed],-1
112
      check_next_symbol:
106
      check_next_symbol:
113
	add	eax,24
107
        add     eax,LABEL_STRUCTURE_SIZE
114
	jmp	check_symbols
108
        jmp     check_symbols
115
      symbols_checked:
109
      symbols_checked:
116
	cmp	[next_pass_needed],0
110
        cmp     [next_pass_needed],0
117
	jne	next_pass
111
        jne     next_pass
118
	mov	eax,[error_line]
112
        mov     eax,[error_line]
119
	or	eax,eax
113
        or      eax,eax
Line 218... Line 212...
218
	or	ah,al
212
        or      ah,al
219
      label_symbol_ok:
213
      label_symbol_ok:
220
	mov	cx,[current_pass]
214
        mov     cx,[current_pass]
221
	xchg	[ebx+16],cx
215
        xchg    [ebx+16],cx
222
	and	byte [ebx+8],not 2
216
        mov     edx,[current_line]
-
 
217
        mov     [ebx+28],edx
-
 
218
        and     byte [ebx+8],not 2
223
	test	byte [ebx+8],1
219
        test    byte [ebx+8],1
224
	jz	new_label
220
        jz      new_label
225
	cmp	cx,[ebx+16]
221
        cmp     cx,[ebx+16]
226
	je	symbol_already_defined
222
        je      symbol_already_defined
227
	inc	cx
223
        inc     cx
Line 303... Line 299...
303
	or	ah,al
299
        or      ah,al
304
      constant_symbol_ok:
300
      constant_symbol_ok:
305
	mov	cx,[current_pass]
301
        mov     cx,[current_pass]
306
	xchg	[ebx+16],cx
302
        xchg    [ebx+16],cx
307
	test	byte [ebx+8],1
303
        mov     edx,[current_line]
-
 
304
        mov     [ebx+28],edx
-
 
305
        test    byte [ebx+8],1
308
	jz	new_constant
306
        jz      new_constant
309
	cmp	cx,[ebx+16]
307
        cmp     cx,[ebx+16]
310
	jne	redeclare_constant
308
        jne     redeclare_constant
311
	test	byte [ebx+8],2
309
        test    byte [ebx+8],2
312
	jz	symbol_already_defined
310
        jz      symbol_already_defined
Line 404... Line 402...
404
	cmp	al,')'
402
        cmp     al,')'
405
	je	skip_done
403
        je      skip_done
406
	cmp	al,']'
404
        cmp     al,']'
407
	je	skip_done
405
        je      skip_done
408
	cmp	al,0Fh
406
        cmp     al,'!'
-
 
407
        je      skip_expression
-
 
408
        cmp     al,0Fh
409
	je	skip_expression
409
        je      skip_expression
410
	cmp	al,10h
410
        cmp     al,10h
411
	je	skip_register
411
        je      skip_register
412
	cmp	al,11h
412
        cmp     al,11h
413
	je	skip_label_value
413
        je      skip_label_value
Line 446... Line 446...
446
	jnz	invalid_use_of_symbol
446
        jnz     invalid_use_of_symbol
447
	mov	[labels_type],cl
447
        mov     [labels_type],cl
448
	mov	ecx,edi
448
        mov     ecx,edi
449
	sub	ecx,eax
449
        sub     ecx,eax
450
	sbb	edx,0
450
        adc     edx,0
451
	mov	dword [org_origin],ecx
451
        neg     edx
-
 
452
        mov     dword [org_origin],ecx
452
	mov	dword [org_origin+4],edx
453
        mov     dword [org_origin+4],edx
453
	mov	[org_registers],0
454
        mov     [org_registers],0
454
	mov	[org_start],edi
455
        mov     [org_start],edi
455
	mov	edx,[symbol_identifier]
456
        mov     edx,[symbol_identifier]
456
	mov	[org_symbol],edx
457
        mov     [org_symbol],edx
Line 529... Line 530...
529
	pop	dword [ebx+8]
530
        pop     dword [ebx+8]
530
	mov	ch,[value_type]
531
        mov     ch,[value_type]
531
	or	ch,ch
532
        or      ch,ch
532
	jz	make_free_label
533
        jz      make_free_label
533
	cmp	ch,2
534
        cmp     ch,4
-
 
535
        je      make_free_label
-
 
536
        cmp     ch,2
534
	jne	invalid_use_of_symbol
537
        jne     invalid_use_of_symbol
535
      make_free_label:
538
      make_free_label:
536
	and	byte [ebx+9],not 1
539
        and     byte [ebx+9],not 1
537
	cmp	eax,[ebx]
540
        cmp     eax,[ebx]
538
	mov	[ebx],eax
541
        mov     [ebx],eax
Line 564... Line 567...
564
	or	ah,al
567
        or      ah,al
565
      free_label_symbol_ok:
568
      free_label_symbol_ok:
566
	mov	cx,[current_pass]
569
        mov     cx,[current_pass]
567
	xchg	[ebx+16],cx
570
        xchg    [ebx+16],cx
568
	and	byte [ebx+8],not 2
571
        mov     edx,[current_line]
-
 
572
        mov     [ebx+28],edx
-
 
573
        and     byte [ebx+8],not 2
569
	test	byte [ebx+8],1
574
        test    byte [ebx+8],1
570
	jz	new_free_label
575
        jz      new_free_label
571
	cmp	cx,[ebx+16]
576
        cmp     cx,[ebx+16]
572
	je	symbol_already_defined
577
        je      symbol_already_defined
573
	inc	cx
578
        inc     cx
Line 835... Line 840...
835
	mov	eax,edi
840
        mov     eax,edi
836
	xor	edx,edx
841
        xor     edx,edx
837
	sub	eax,dword [org_origin]
842
        sub     eax,dword [org_origin]
838
	sbb	edx,dword [org_origin+4]
843
        sbb     edx,dword [org_origin+4]
839
	xor	bx,bx
844
        mov     bx,word [org_registers]
-
 
845
        mov     cx,word [org_registers+2]
-
 
846
        xchg    bh,bl
840
	xor	cx,cx
847
        xchg    ch,cl
841
      set_virtual:
848
      set_virtual:
842
	push	[org_registers]
849
        push    [org_registers]
843
	mov	byte [org_registers],bh
850
        mov     byte [org_registers],bh
844
	mov	byte [org_registers+1],bl
851
        mov     byte [org_registers+1],bl
845
	mov	byte [org_registers+2],ch
852
        mov     byte [org_registers+2],ch
846
	mov	byte [org_registers+3],cl
853
        mov     byte [org_registers+3],cl
Line 888... Line 895...
888
      scan_structures:
895
      scan_structures:
889
	cmp	ebx,[additional_memory_end]
896
        cmp     ebx,[additional_memory_end]
890
	je	no_such_structure
897
        je      no_such_structure
891
	cmp	ax,[ebx]
898
        cmp     ax,[ebx]
892
	jne	next_structure
899
        je      structure_data_found
893
	clc
-
 
894
	ret
-
 
895
      next_structure:
-
 
896
	cmp	ax,if_directive-assembler
-
 
897
	je	check_structure_overlapping
-
 
898
	cmp	ax,repeat_directive-assembler
-
 
899
	je	check_structure_overlapping
-
 
900
	cmp	ax,while_directive-assembler
-
 
901
	je	check_structure_overlapping
-
 
902
	add	ebx,20h
-
 
903
	jmp	scan_structures
-
 
904
      check_structure_overlapping:
-
 
905
	cmp	word [ebx],if_directive-assembler
900
        add     ebx,20h
906
	je	no_such_structure
-
 
907
	cmp	word [ebx],repeat_directive-assembler
-
 
908
	je	no_such_structure
-
 
909
	cmp	word [ebx],while_directive-assembler
-
 
910
	je	no_such_structure
-
 
911
	add	ebx,20h
-
 
912
	jmp	scan_structures
901
        jmp     scan_structures
913
      no_such_structure:
902
      structure_data_found:
-
 
903
        ret
-
 
904
      no_such_structure:
914
	stc
905
        stc
915
	ret
906
        ret
916
      end_virtual:
907
      end_virtual:
917
	call	find_structure_data
908
        call    find_structure_data
918
	jc	unexpected_instruction
909
        jc      unexpected_instruction
Line 1905... Line 1896...
1905
	jne	invalid_use_of_symbol
1896
        jne     invalid_use_of_symbol
1906
	mov	edx,eax
1897
        mov     edx,eax
1907
	dec	edx
1898
        dec     edx
1908
	test	eax,edx
1899
        test    eax,edx
1909
	jnz	invalid_value
1900
        jnz     negative_times
1910
	or	eax,eax
1901
        or      eax,eax
1911
	jz	invalid_value
1902
        jz      negative_times
1912
	cmp	eax,1
1903
        cmp     eax,1
1913
	je	instruction_assembled
1904
        je      instruction_assembled
1914
	mov	ecx,edi
1905
        mov     ecx,edi
1915
	sub	ecx,dword [org_origin]
1906
        sub     ecx,dword [org_origin]
1916
	cmp	[org_registers],0
1907
        cmp     [org_registers],0
1917
	jne	section_not_aligned_enough
1908
        jne     section_not_aligned_enough