Subversion Repositories Kolibri OS

Rev

Rev 7859 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7836 leency 1
; flat assembler
2
; Copyright (c) 1999-2020, Tomasz Grysztar
3
; All rights reserved.
4
 
5
 
6
 
7
 
8
 
9
init_memory:
10
 
11
;        mov ecx, 16*1024*1024
12
;
13
; allocate_memory:
14
	mcall	SF_SYSTEM, SSF_GET_FREE_RAM
15
	cmp	eax, 0x38000000 shr 9
16
	jbe	@f
17
	mov	eax, 0x38000000 shr 9
18
@@:
19
	shl	eax, 9
20
	xchg	eax, ecx
21
	mov	[memory_setting],ecx
22
	mcall	SF_SYS_MISC, SSF_MEM_ALLOC
23
	or	eax,eax
24
	jz	out_of_memory
25
	mov	[memblock], eax
26
	mov	[additional_memory],eax
27
	add	eax,[memory_setting]
28
	mov	[memory_end],eax
29
	mov	eax,[memory_setting]
30
	shr	eax,2
31
	add	eax,[additional_memory]
32
	mov	[additional_memory_end],eax
33
	mov	[memory_start],eax
34
	ret
35
 
36
exit_program:
37
	cmp	[_mode],NORMAL_MODE
38
	jne	@f
39
	mcall	SF_SYS_MISC, SSF_MEM_FREE, [memblock]
40
	mov	esp,[processing_esp]
41
	jmp	still
42
@@:
43
	or	eax,-1
44
	mcall
45
 
46
make_timestamp:
47
	push	ebx
48
	mcall	SF_SYSTEM_GET,SSF_TIME_COUNT
49
	imul	eax,10
50
	pop	ebx
51
	ret
52
 
53
symbol_dump:
54
 
55
	push	edi
56
	mov	edx,[memory_end]
57
      symb_dump:
58
	cmp	edx,[labels_list]
59
	jbe	symbols_dumped
60
	sub	edx,LABEL_STRUCTURE_SIZE
61
	cmp	dword [edx+24],0
62
	je	symb_dump	; do not dump anonymous symbols
63
	test	byte [edx+8],1
64
	jz	symb_dump	; do not dump symbols that didn't get defined
65
	mov	ax,[current_pass]
66
	cmp	ax,[edx+16]
67
	jne	symb_dump
68
	test	byte [edx+8],4 or 2
69
	jnz	symb_dump	; do not dump assembly-time variables
70
				; do not dump variables defined with '='
71
	cmp	word [edx+12], 0
72
	jnz	symb_dump	; do not dump register-based variables
73
 
74
	mov	al, '0'
75
	stosb
76
	mov	al, 'x'
77
	stosb
78
	mov	eax, [edx+4]
79
	mov	ecx, 8
80
@@:
81
	rol	eax, 4
82
	test	al, 0xF
83
	loopz	@b
84
	jz	.nohigh
85
	inc	ecx
86
@@:
87
	push	eax
88
	and	al, 0xF
89
	cmp	al, 10
90
	sbb	al, 69h
91
	das
92
	stosb
93
	pop	eax
94
	rol	eax, 4
95
	loop	@b
96
	mov	eax, [edx]
97
	mov	ecx, 8
98
	jmp	.low
99
.nohigh:
100
	mov	eax, [edx]
101
	mov	ecx, 8
102
@@:
103
	rol	eax, 4
104
	test	al, 0xF
105
	loopz	@b
106
	inc	ecx
107
.low:
108
	push	eax
109
	and	al, 0xF
110
	cmp	al, 10
111
	sbb	al, 69h
112
	das
113
	stosb
114
	pop	eax
115
	rol	eax, 4
116
	loop	.low
117
 
118
	mov	al, ' '
119
	stosb
120
 
121
	mov	esi,[edx+24]
122
	movzx	ecx,byte [esi-1]
123
	rep	movsb
124
 
125
	mov	ax,0A0Dh
126
	stosw
127
 
128
	jmp	symb_dump
129
 
130
      symbols_dumped:
131
	mov	edx,dbgfilename
132
	push	esi edi
133
	mov	esi, outfile
134
	mov	edi, edx
135
@@:
136
	lodsb
137
	stosb
138
	test	al, al
139
	jnz	@b
140
	lea	ecx, [edi-1]
141
@@:
142
	dec	edi
143
	cmp	edi, edx
144
	jb	@f
145
	cmp	byte [edi], '/'
146
	jz	@f
147
	cmp	byte [edi], '.'
148
	jnz	@b
149
	mov	ecx, edi
150
@@:
151
	mov	dword [ecx], '.dbg'
152
	mov	byte [ecx+4], 0
153
	pop	edi esi
154
	call	create
155
	mov	edx,[esp]
156
	mov	ecx,edi
157
	sub	ecx,edx
158
	call	write
159
	call	close
160
	pop	edi
161
 
162
	ret
163
 
164
get_environment_variable:
165
	mov	ecx,[memory_end]
166
	sub	ecx,edi
167
	cmp	ecx,7
168
	jb	out_of_memory
169
	cmp	dword[esi],'INCL'
170
	jne	.finish
171
	mov	esi,_ramdisk
172
	mov	ecx,6
173
	cld
174
	rep	movsb
175
  .finish:
176
;       stc
177
	ret
178
 
179
alloc_handle:
180
	call	make_fullpaths
181
	mov	ebx, fileinfos+4
182
@@:
183
	cmp	dword [ebx], -1
184
	jz	.found
185
	add	ebx, 4+20+MAX_PATH
186
	cmp	ebx, fileinfos_end
187
	jb	@b
188
	stc
189
	ret
190
.found:
191
	and	dword [ebx+4], 0
192
	and	dword [ebx+8], 0
193
	push	esi edi ecx
194
	mov	esi, fullpath_open
195
	lea	edi, [ebx+20]
196
	mov	ecx, MAX_PATH
197
	rep	movsb
198
	pop	ecx edi esi
199
	ret	; CF=0
200
 
201
create:
202
	call	alloc_handle
203
	jc	.ret
204
	and	dword [ebx-4], 0
205
	mov	dword [ebx], 2
206
.ret:
207
	ret
208
 
209
 
210
open:
211
;        call    make_fullpaths
212
 
213
;;       mov     eax,fullpath_open
214
;;       DEBUGF  '"%s"\n',eax
215
 
216
;        mov     dword[file_info_open+8],-1
217
;        mcall   58,file_info_open
218
;        or      eax,eax                 ; found
219
;        jz      @f
220
;        cmp     eax,6
221
;        jne     file_error
222
;@@: mov [filesize],ebx
223
;        clc
224
;        ret
225
;file_error:
226
;        stc
227
;        ret
228
 
229
	call	alloc_handle
230
	jc	.ret
231
	mov	dword [ebx], SSF_GET_INFO
232
	and	dword [ebx+12], 0
233
	mov	dword [ebx+16], fileinfo
234
	mov	eax, SF_FILE
235
	push	ebx
236
	mcall
237
	pop	ebx
238
	test	eax, eax
239
	jnz	.fail
240
	mov	eax, dword[fileinfo.size]
241
	mov	[ebx-4], eax
242
	and	dword [ebx], 0
243
.ret:
244
	ret
245
.fail:
246
	or	dword [ebx], -1 ; close handle
247
	stc
248
	ret
249
 
250
read:
251
;          pusha
252
;          mov     edi,edx
253
;          mov     esi,[filepos]
254
;          add     esi,0x20000
255
;          cld
256
;          rep     movsb
257
;          popa
258
;;         ret
259
 
260
	mov	[ebx+12], ecx
261
	mov	[ebx+16], edx
262
	push	ebx
263
	mov	eax, SF_FILE
264
	mcall
265
	xchg	eax, [esp]
266
	add	[eax+4], ebx
267
	adc	[eax+8], dword 0
268
	mov	ebx, eax
269
	pop	eax
270
	test	eax, eax
271
	jz	.ok
272
	cmp	eax, 6
273
	jz	.ok
274
	stc
275
.ok:
276
	ret
277
 
278
close:
279
	or	dword [ebx], -1
280
	ret
281
 
282
 
283
; ebx file handle
284
; ecx count of bytes to write
285
; edx pointer to buffer
286
write:
287
;        pusha
288
;        mov     [file_info_write+8],ecx
289
;        mov     [file_info_write+12],edx
290
;        mov     [filesize],edx
291
;        mov     eax,58
292
;        mov     ebx,file_info_write
293
;        mcall
294
;        popa
295
;        ret
296
 
297
	mov	[ebx+12], ecx
298
	mov	[ebx+16], edx
299
	push	ebx
300
	mov	eax, SF_FILE
301
	mcall
302
	xchg	eax, [esp]
303
	add	[eax+4], ebx
304
	adc	[eax+8], dword 0
305
	mov	ebx, eax
306
	pop	eax
307
	mov	byte [ebx], 3
308
	cmp	eax, 1
309
	cmc
310
	ret
311
 
312
make_fullpaths:
313
	pusha
314
	push	edx
315
 
316
	mov	esi,path	      ; open
317
;       DEBUGF  "   '%s'",esi
318
	mov	edi,fullpath_open
319
	cld
320
      newc1:
321
	movsb
322
	cmp	byte[esi],0;' '
323
	jne	newc1
324
	mov	esi,[esp]
325
 
326
	cmp	byte[esi],'/'
327
	jne	@f
328
	mov	edi,fullpath_open
329
 
330
    @@:
331
	lodsb
332
	stosb
333
	cmp	al,0
334
	jne	@b
335
;       mov     ecx,12
336
;       cld
337
;       rep     movsb
338
;       mov     byte[edi],0
339
 
340
	mov	esi,path	      ; write
341
	mov	edi,fullpath_write
342
	cld
343
      newc2:
344
	movsb
345
	cmp	byte[esi],0;' '
346
	jne	newc2
347
	mov	esi,[esp]
348
 
349
	cmp	byte[esi],'/'
350
	jne	@f
351
	mov	edi,fullpath_write
352
 
353
    @@:
354
	lodsb
355
	stosb
356
	cmp	al,0
357
	jne	@b
358
;        mov     ecx,12
359
;        cld
360
;        rep     movsb
361
;        mov     byte[edi],0
362
 
363
	mov	esi,path	      ; start
364
	mov	edi,file_io_start.path
365
	cld
366
      newc3:
367
	movsb
368
	cmp  byte[esi],0;' '
369
	jne  newc3
370
;        mov  esi,[esp]
371
	pop	esi
372
 
373
	cmp	byte[esi],'/'
374
	jne	@f
375
	mov	edi,file_io_start.path
376
 
377
    @@:
378
	lodsb
379
	stosb
380
	cmp	al,0
381
	jne	@b
382
;        mov  ecx,12
383
;        cld
384
;        rep  movsb
385
;        mov  byte[edi],0
386
 
387
;        add  esp,4
388
	popa
389
	ret
390
 
391
 
392
 
393
lseek:
394
	cmp	al,0
395
	jnz	@f
396
	and	dword [ebx+4], 0
397
	and	dword [ebx+8], 0
398
    @@: cmp	al,2
399
	jnz	@f
400
	mov	eax, [ebx-4]
401
	mov	[ebx+4], eax
402
	and	dword [ebx+8], 0
403
    @@: add	dword [ebx+4], edx
404
	adc	dword [ebx+8], 0
405
	ret
406
 
407
display_character:
408
	pusha
409
	cmp	[_mode],NORMAL_MODE
410
	jne	@f
411
	cmp	dl,13
412
	jz	dc2
413
	cmp	dl,0xa
414
	jnz	dc1
415
	and	[textxy],0x0000FFFF
416
	add	[textxy], 8 shl 16 and 0xFFFF0000 + 18
417
dc2:
418
  popa
419
	ret
420
dc1:
421
  mov eax,[textxy]
422
	cmp	ax,word[bottom_right]
423
	ja	dc2
424
	shr	eax,16
425
	cmp	ax,word[bottom_right+2]
426
	ja	dc2
427
	mov	[dc],dl
428
	mcall	SF_DRAW_TEXT,[textxy],0x10000000,dc,1
429
	add	[textxy],0x00080000
430
	popa
431
	ret
432
@@:
433
  mov	eax,SF_BOARD
434
	mov	ebx,1
435
	mov	cl,dl
436
	mcall
437
	popa
438
	ret
439
 
440
 
441
display_string:
442
	pusha
443
@@:
444
  cmp	byte[esi],0
445
	je	@f
446
	mov	dl,[esi]
447
	call	display_character
448
	add	esi,1
449
	jmp	@b
450
@@:
451
  popa
452
	ret
453
 
454
display_number:
455
	push	ebx
456
	mov	ecx,1000000000
457
	xor	edx,edx
458
	xor	bl,bl
459
display_loop:
460
	div	ecx
461
	push	edx
462
	cmp	ecx,1
463
	je	display_digit
464
	or	bl,bl
465
	jnz	display_digit
466
	or	al,al
467
	jz	digit_ok
468
	not	bl
469
display_digit:
470
	mov	dl,al
471
	add	dl,30h
472
	push	ebx ecx
473
	call	display_character
474
	pop	ecx ebx
475
digit_ok:
476
	mov	eax,ecx
477
	xor	edx,edx
478
	mov	ecx,10
479
	div	ecx
480
	mov	ecx,eax
481
	pop	eax
482
	or	ecx,ecx
483
	jnz	display_loop
484
	pop	ebx
485
	ret
486
 
487
display_user_messages:
488
;    push   [skinh]
489
;    pop    [textxy]
490
;    add    [textxy], 7 shl 16 +53
491
	mov	[displayed_count],0
492
	call	show_display_buffer
493
	cmp	[displayed_count],1
494
	jb	line_break_ok
495
	je	make_line_break
496
	mov	ax,word[last_displayed]
497
	cmp	ax,0A0Dh
498
	je	line_break_ok
499
	cmp	ax,0D0Ah
500
	je	line_break_ok
501
make_line_break:
502
	mov	esi,crlf
503
	call	display_string
504
line_break_ok:
505
	ret
506
 
507
display_block:
508
	pusha
509
@@: mov dl,[esi]
510
	call	display_character
511
	inc	esi
512
	loop	@b
513
	popa
514
	ret
515
 
516
fatal_error:
517
	mov	esi,error_prefix
518
	call	display_string
519
	pop	esi
520
	call	display_string
521
	mov	esi,error_suffix
522
	call	display_string
523
	mov	esi,crlf
524
	call	display_string
525
	mov	al,0FFh
526
	jmp	exit_program
527
 
528
assembler_error:
529
	call	display_user_messages
530
	push	dword 0
531
	mov	ebx,[current_line]
532
get_error_lines:
533
	push	ebx
534
	test	byte [ebx+7],80h
535
	jz	display_error_line
536
	mov	edx,ebx
537
find_definition_origin:
538
	mov	edx,[edx+12]
539
	test	byte [edx+7],80h
540
	jnz	find_definition_origin
541
	push	edx
542
	mov	ebx,[ebx+8]
543
	jmp	get_error_lines
544
display_error_line:
545
	mov	esi,[ebx]
546
	call	display_string
547
	mov	esi,line_number_start
548
	call	display_string
549
	mov	eax,[ebx+4]
550
	and	eax,7FFFFFFFh
551
	call	display_number
552
	mov	dl,']'
553
	call	display_character
554
	pop	esi
555
	cmp	ebx,esi
556
	je	line_number_ok
557
	mov	dl,20h
558
	call	display_character
559
	push	esi
560
	mov	esi,[esi]
561
	movzx	ecx,byte [esi]
562
	inc	esi
563
	call	display_block
564
	mov	esi,line_number_start
565
	call	display_string
566
	pop	esi
567
	mov	eax,[esi+4]
568
	and	eax,7FFFFFFFh
569
	call	display_number
570
	mov	dl,']'
571
	call	display_character
572
line_number_ok:
573
	mov	esi,line_data_start
574
	call	display_string
575
	mov	esi,ebx
576
	mov	edx,[esi]
577
	call	open
578
	mov	al,2
579
	xor	edx,edx
580
	call	lseek
581
	mov	edx,[esi+8]
582
	sub	eax,edx
583
	push	eax
584
	xor	al,al
585
	call	lseek
586
	mov	ecx,[esp]
587
	mov	edx,[additional_memory]
588
	lea	eax,[edx+ecx]
589
	cmp	eax,[additional_memory_end]
590
	ja	out_of_memory
591
	call	read
592
	call	close
593
	pop	ecx
594
	mov	esi,[additional_memory]
595
get_line_data:
596
	mov	al,[esi]
597
	cmp	al,0Ah
598
	je	display_line_data
599
	cmp	al,0Dh
600
	je	display_line_data
601
	cmp	al,1Ah
602
	je	display_line_data
603
	or	al,al
604
	jz	display_line_data
605
	inc	esi
606
	loop	get_line_data
607
display_line_data:
608
	mov	ecx,esi
609
	mov	esi,[additional_memory]
610
	sub	ecx,esi
611
	call	display_block
612
	mov	esi,crlf
613
	call	display_string
614
	pop	ebx
615
	or	ebx,ebx
616
	jnz	display_error_line
617
	mov	esi,error_prefix
618
	call	display_string
619
	pop	esi
620
	call	display_string
621
	mov	esi,error_suffix
622
	call	display_string
623
	jmp	exit_program