Subversion Repositories Kolibri OS

Rev

Rev 1571 | Rev 1741 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;   DEBUG BOARD for APPLICATIONS and KERNEL DEVELOPMENT
3
;
4
;   See f63
5
;
6
;   Compile with FASM for Menuet
7
;
1571 Asper 8
LMARGIN    equ (15+5)
9
TMARGIN    equ (35+5)
10
HSPACE	   equ 16
11
VSPACE	   equ 12
12
IPC_BUF    equ 160
13
DR_GRID    equ 0;1
14
WRITE_LOG  equ 1
31 halyavin 15
 
131 diamond 16
FL_KRNL equ 1
17
 
31 halyavin 18
include 'lang.inc'
19
 
20
   use32
1571 Asper 21
   org	  0x0
22
   db	  'MENUET01'		  ; 8 byte id
23
   dd	  0x01			  ; header version
24
   dd	  START 		  ; start of code
25
   dd	  I_END 		  ; size of image
26
   dd	  i_end+0x2000			; memory for app (4 Kb)
27
   dd	  i_end+0x2000			; esp
28
   dd	  0x0 , 0x0		  ; I_Param , I_Icon
485 heavyiron 29
include '..\..\..\MACROS.INC'
131 diamond 30
include 'debug.inc'
31
purge newline
31 halyavin 32
MAXSTRINGS = 16
131 diamond 33
TMP = 80*(MAXSTRINGS+1)
31 halyavin 34
 
1571 Asper 35
START:				; start of execution
31 halyavin 36
 
131 diamond 37
     mcall 60,1,ipcbuff,IPC_BUF+20
38
     mcall 40,1000111b
39
     mov  [ipcbuff+4],8
1355 diamond 40
; allow user to see messages written before start
41
;     mov  ecx,4096
42
;    flush:
43
;     mov  eax,63
44
;     mov  ebx,2
45
;     mcall
46
;     loop flush
31 halyavin 47
 
131 diamond 48
     mov  ecx, TMP
31 halyavin 49
     xor  eax, eax
131 diamond 50
     mov  edi, [targ]
31 halyavin 51
     rep  stosb
52
 
131 diamond 53
     mov  [tmp1],'x'
54
     mov  [tmp2],'x'
31 halyavin 55
 
56
     mov  eax,14
447 heavyiron 57
     mcall
31 halyavin 58
     and  eax,0xffff0000
131 diamond 59
     sub  eax,399 shl 16
60
     add  eax,399
31 halyavin 61
     mov  [xstart],eax
447 heavyiron 62
 
63
     mov  eax,48
64
     mov  ebx,3
65
     mov  ecx,sc
66
     mov  edx,sizeof.system_colors
67
     mcall
1571 Asper 68
  if WRITE_LOG
69
     mov  esi, filename
70
     call CreateFile
71
  end if
447 heavyiron 72
 
131 diamond 73
  red:
31 halyavin 74
     call draw_window
75
 
76
still:
77
 
1571 Asper 78
    mov  eax,23 		; wait here for event
31 halyavin 79
    mov  ebx,1
447 heavyiron 80
    mcall
31 halyavin 81
 
1571 Asper 82
    cmp  eax,1			; redraw request ?
83
    je	 red
84
    cmp  eax,2			; key in buffer ?
85
    je	 key
86
    cmp  eax,3			; button in buffer ?
87
    je	 button
131 diamond 88
    cmp  eax,7
1571 Asper 89
    je	 ipc
447 heavyiron 90
 
31 halyavin 91
    mov  eax,63
92
    mov  ebx,2
447 heavyiron 93
    mcall
31 halyavin 94
 
95
    cmp  ebx,1
96
    jne  still
1571 Asper 97
 
31 halyavin 98
  new_data:
1571 Asper 99
  if WRITE_LOG
100
     pusha
101
     mov  [tmp], al
102
     mov  edx, tmp
103
     mov  ecx, 1
104
     mov  esi, filename
105
  .write_to_logfile:
106
     call WriteToFile
107
     cmp  eax, 5
108
     jne  @f
109
     mov  esi, filename
110
     mov  [filepos], 0
111
     call CreateFile
112
     jmp  .write_to_logfile
113
  @@:
114
     inc  [filepos]
115
     popa
116
  end if
117
 
131 diamond 118
    mov  ebp,[targ]
119
  .no4:
31 halyavin 120
    cmp  al,13
121
    jne  no13
131 diamond 122
    and  dword[ebp-8],0
31 halyavin 123
    jmp  new_check
124
   no13:
125
    cmp  al,10
126
    jne  no10
131 diamond 127
    inc  dword[ebp-4]
128
    cmp  dword[ebp-4],MAXSTRINGS
129
    jbe  .noypos
130
    mov  dword[ebp-4],MAXSTRINGS
131
    lea  esi,[ebp+80]
132
    mov  edi,ebp
31 halyavin 133
    mov  ecx,80*(MAXSTRINGS)
134
    cld
135
    rep  movsb
136
 
131 diamond 137
    mov  esi,[ebp-4]
31 halyavin 138
    imul esi,80
131 diamond 139
    add  esi,[ebp-8]
140
    add  esi,ebp
31 halyavin 141
    mov  ecx,80
142
    xor  al,al
143
    rep  stosb
131 diamond 144
  .noypos:
145
    mov  [targ],text2
146
    and  [krnl_cnt],0
31 halyavin 147
    jmp  new_check
148
  no10:
131 diamond 149
    cmp  ebp,text1
1571 Asper 150
    je	 add2
151
		mov  ecx,[krnl_cnt]
131 diamond 152
		  cmp  al,[krnl_msg+ecx]
1571 Asper 153
		jne  .noknl
131 diamond 154
		  inc  [krnl_cnt]
1571 Asper 155
		cmp  [krnl_cnt],4
156
		jne  new_check
131 diamond 157
    mov  [targ],text1
1571 Asper 158
	.noknl:
131 diamond 159
    mov  ebp,[targ]
160
	   jecxz .add
161
    push eax
162
    mov  esi,krnl_msg
163
   .l1:
164
    lodsb
165
    call add_char
166
    loop .l1
167
    pop  eax
168
   .add:
169
    and  [krnl_cnt],0
170
  add2:
171
    call add_char
31 halyavin 172
 
173
  new_check:
174
 
175
    mov  eax,63
176
    mov  ebx,2
447 heavyiron 177
    mcall
31 halyavin 178
 
179
    cmp  ebx,1
1571 Asper 180
    je	 new_data
31 halyavin 181
 
131 diamond 182
    cmp  [vmode],2
1571 Asper 183
    je	 still
31 halyavin 184
    call draw_window
185
 
186
    jmp  still
187
 
131 diamond 188
  ipc:
189
    mov  [vmode],2
190
    mov  eax,ipcbuff
191
    mov  esi,[eax+8]
192
    mov  byte[eax],1
193
    push dword[eax+12]
194
    pop  [dump_len]
195
    mcall 9,work,-1
196
    mov  ecx,eax
197
   .lp:
198
    mcall 9
199
    cmp  [ebx+30],esi
1571 Asper 200
    je	 .ok
131 diamond 201
    loop .lp
202
    and  [dump_len],0
203
    jmp  red
204
  .ok:
205
    mov  [pid],esi
206
    lea  esi,[ebx+10]
207
    mov  edi,dump_title+10
208
    mov  ecx,12
209
    rep  movsb
210
    jmp  red
1571 Asper 211
  key:				; key
212
    mov  al,2		       ; just read it and ignore
447 heavyiron 213
    mcall
131 diamond 214
    cmp  ah,' '
1571 Asper 215
    je	 button.no_krnl_flt
131 diamond 216
    cmp  [vmode],2
217
    jne  still
218
    cmp  ah,176 ;left
1571 Asper 219
    jb	 still
131 diamond 220
    cmp  ah,179 ;right
1571 Asper 221
    ja	still
131 diamond 222
    mov  ecx,[offs]
223
    shr  eax,8
224
    sub  eax,176
225
    add  ecx,[arrows+eax*4]
226
    shl  ecx,12
227
    shr  cx,12
228
    jmp  button.check_sel
229
  .nol:
31 halyavin 230
    jmp  still
231
 
131 diamond 232
arrows dd -1,16,-16,1
233
 
1571 Asper 234
  button:			; button
235
    mov  al,17		       ; get id
447 heavyiron 236
    mcall
31 halyavin 237
 
1571 Asper 238
    cmp  ah,1			; button id=1 ?
131 diamond 239
    jne  .noclose
31 halyavin 240
 
1571 Asper 241
    or	 eax,-1 		; close this program
447 heavyiron 242
    mcall
131 diamond 243
  .noclose:
1571 Asper 244
	shr  eax,8
245
		cmp  eax,10
246
		jb   .nodump
131 diamond 247
		  lea  edi,[eax-10]
1571 Asper 248
		mcall 37,1
131 diamond 249
		  sub  eax,[edi*4+dump_cell_marg]
1571 Asper 250
		sub  eax,TMARGIN+VSPACE
251
		push eax
131 diamond 252
    and  eax,0xffff
253
		  xor  edx,edx
1571 Asper 254
		div  word[edi*4+dump_cell_size+2]
131 diamond 255
		  mov  ecx,eax
256
    shl  ecx,16
1571 Asper 257
		xor  edx,edx
131 diamond 258
		  pop  eax
1571 Asper 259
		shr  eax,16
260
		div  word[edi*4+dump_cell_size]
261
		mov  cx,ax
131 diamond 262
  .check_sel:
1571 Asper 263
		mov  eax,ecx
131 diamond 264
    shl  ax,12
265
    shr  eax,12
266
    inc  eax
267
    cmp  eax,[dump_len]
1571 Asper 268
    ja	 still;.nosel
131 diamond 269
    mov  dword[sel_byte],ecx
270
    dec  eax
271
    mov  [offs],eax
272
    jmp  red
31 halyavin 273
 
131 diamond 274
  .nodump:
275
    cmp  eax,2
276
    jne  .no_krnl_flt
277
    xor  [flag],FL_KRNL
31 halyavin 278
    jmp  still
131 diamond 279
  .no_krnl_flt:
280
    mov  [ipcbuff+4],8
281
    and  byte[ipcbuff],0
282
    inc  [vmode]
283
    cmp  [vmode],3
1571 Asper 284
    jb	 .vmok
131 diamond 285
    and  [vmode],0
286
  .vmok:
287
    jmp  red
31 halyavin 288
 
131 diamond 289
add_char:
290
    push esi
291
    mov  esi,[ebp-4]
292
    imul esi,80
293
    add  esi,[ebp-8]
294
    mov  [ebp+esi],al
295
    inc  dword[ebp-8]
296
    cmp  dword[ebp-8],80
1571 Asper 297
    jb	 .ok
131 diamond 298
    mov  dword[ebp-8],79
299
  .ok:
300
    pop  esi
301
    ret
31 halyavin 302
 
303
;   *********************************************
304
;   *******  WINDOW DEFINITIONS AND DRAW ********
305
;   *********************************************
306
 
307
 
308
draw_window:
309
 
1571 Asper 310
    mov  eax,12 		   ; function 12:tell os about windowdraw
311
    mov  ebx,1			   ; 1, start of draw
447 heavyiron 312
    mcall
31 halyavin 313
 
1571 Asper 314
				   ; DRAW WINDOW
315
    xor  eax,eax		     ; function 0 : define and draw window
31 halyavin 316
;   mov  ebx,50*65536+400          ; [x start] *65536 + [x size]
317
    mov  ebx,[xstart]
1571 Asper 318
    mov  ecx,MAXSTRINGS*10+45	   ; [y start] *65536 + [y size]
319
    mov  edx,[sc.work]		   ; color of work area RRGGBB,8->color gl
320
    or	 edx,0x13000000
321
    mov  edi,title		  ; WINDOW LABEL
447 heavyiron 322
    mcall
1571 Asper 323
 
131 diamond 324
    mov  ecx,4
325
    mov  esi,[sc.work]
447 heavyiron 326
    mov  ebx,296 shl 16+5*6
131 diamond 327
    mov  edx,3;+1 shl 30
328
    mcall 8,,<5,12>
329
    mov  edx,[vmode]
330
    lea  edx,[edx*4+duk]
447 heavyiron 331
    mcall 4,<300,8>,,,4
131 diamond 332
 
333
    cmp  [vmode],2
1571 Asper 334
    je	 no_mdbg
335
    mov  ebx,15*65536+33	   ; draw info text with function 4
31 halyavin 336
    mov  ecx,[sc.work_text]
131 diamond 337
    mov  edx,text1
338
    cmp  [vmode],0
1571 Asper 339
    je	 .kern
131 diamond 340
    mov  edx,text2
341
  .kern:
31 halyavin 342
    mov  esi,80
447 heavyiron 343
    mov  eax,4
31 halyavin 344
  newline:
447 heavyiron 345
    mcall
31 halyavin 346
    add  ebx,10
347
    add  edx,80
348
    cmp  [edx],byte 'x'
349
    jne  newline
131 diamond 350
    jmp  enddraw
351
  no_mdbg:
352
  if DUMP_TEST eq 1
353
    mov  esi,0
354
    mov  [dump_len],100;IPC_BUF
355
  else
356
    mov  esi,ipcbuff+16
357
  end if
358
    mov  ecx,[dump_len]
359
    call dump_btn
1571 Asper 360
		call draw_dump
131 diamond 361
		enddraw:
1571 Asper 362
    mov  eax,12 		   ; function 12:tell os about windowdraw
363
    mov  ebx,2			   ; 2, end of draw
447 heavyiron 364
    mcall
31 halyavin 365
 
366
    ret
367
 
131 diamond 368
if DR_GRID eq 1
369
draw_grid:
370
  mov  ecx,11
371
  mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE
372
 .l1:
373
  push ecx
374
  mov  ebx,LMARGIN shl 16+LMARGIN+16*HSPACE
375
  mcall 38,,edi,0
376
  add  edi,VSPACE shl 16+VSPACE
377
  pop  ecx
378
  loop .l1
379
  mov  ecx,17
380
  mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE*10
381
  mov  ebx,LMARGIN shl 16+LMARGIN
382
 .l2:
383
  push ecx
384
  mcall 38,,edi,0
385
  add  ebx,HSPACE shl 16+HSPACE
386
  pop  ecx
387
  loop .l2
388
  ret
389
end if
31 halyavin 390
 
131 diamond 391
draw_numbers:
392
  mcall 4,(LMARGIN+2) shl 16+180,0,numb,numb_len-numb
393
  mov  eax,dword[sel_byte]
394
  shl  ax,12
395
  shr  eax,12
396
  mov  edi,eax
397
if ~ DUMP_TEST eq 1
398
  add  edi,ipcbuff+16
399
end if
400
  mov  edx,(LMARGIN+2+6*6)shl 16+180
401
  mov  ebx,0x30000
402
  movzx ecx,byte[edi]
403
  mcall 47,,,,0x4e00e7
404
  add  ebx,0x20000
405
  add  edx,(6*10)shl 16
406
  movzx ecx,word[edi]
407
  mcall
408
  add  ebx,0x50000
409
  add  edx,(6*13)shl 16
410
  mov  ecx,[edi]
411
  mcall
412
  mov  ebx,0x80100
413
  add  edx,(6*19)shl 16
414
  mcall
415
.ex:
416
  ret
417
 
418
draw_dump:
419
; esi - data ptr, ecx - length
420
  jecxz draw_numbers.ex
421
  pusha
422
  call draw_numbers
423
  mcall 4,(LMARGIN+2) shl 16+27,0,dump_title,dump_t_len-dump_title
424
  mcall 47,0x30101,ipcbuff+8,(LMARGIN+2+6*29)shl 16+27
1571 Asper 425
  add	edx,(6*27) shl 16
426
  mov	ecx,offs
131 diamond 427
  mcall
1571 Asper 428
  sub	edx,(5*6)shl 16
131 diamond 429
  mcall ,0x30001
430
  mov  ecx,16
431
  mov  edi,HSPACE shl 16
432
  mov  ebx,(LMARGIN+5)shl 16+42
433
  call draw_marks
434
  mov  ecx,[esp+24]
435
  dec  ecx
436
  shr  ecx,4
437
  inc  ecx
438
  mov  ebx,(LMARGIN-10)shl 16+TMARGIN+2+VSPACE
439
  mov  edi,VSPACE
440
  call draw_marks
441
  popa
442
		mov  edx,TMARGIN+2
443
		mov  edi,ecx
1571 Asper 444
	.lp:
131 diamond 445
		add  edx,(LMARGIN+2) shl 16+VSPACE
446
		mov  ecx,16
447
		cmp  edi,ecx
448
		jae  .less
449
		mov  ecx,edi
1571 Asper 450
	.less:
131 diamond 451
		sub  edi,ecx
452
		push esi ecx
453
		mov  ebx,0x20100
1571 Asper 454
	.lp1:
131 diamond 455
		push ecx esi
456
		movzx ecx,byte[esi]
457
		mcall 47,,,,0
458
		add  edx,HSPACE shl 16
459
		pop  esi ecx
460
		inc  esi
461
		loop .lp1
462
		pusha
463
		mov  ebx,edx
464
		and  ebx,0xffff
465
		add  ebx,(LMARGIN+16*HSPACE+15)shl 16
466
		mov  edx,[esp+36]
467
		mov  esi,[esp+32]
468
		mcall 4,,0
469
		popa
470
		add  esp,8
471
		and  edx,0xffff
472
		test edi,edi
473
		jnz  .lp
474
.ex:
475
		ret
476
 
477
draw_marks:
478
; ebx -xy, edi-addition, ecx -cycles
479
		pusha
480
  mov  edx,__hexdigits
481
  mov  eax,4
482
  mov  esi,1
483
.tt:
484
  push ecx
485
  mcall ,,0xffffff
486
  add  ebx,edi
487
  inc  edx
488
  pop  ecx
489
  loop .tt
490
  popa
491
  ret
492
 
493
dump_btn: ; ecx-length
494
  jecxz draw_dump.ex
495
		pusha
496
		test ecx,0xffff
497
		je   .even
498
		add  ecx,16
1571 Asper 499
	.even:
131 diamond 500
		shr  ecx,4
501
		imul ecx,VSPACE
502
		add  ecx,(TMARGIN+VSPACE)shl 16-5
503
		mcall 8,LMARGIN shl 16+16*HSPACE-5,,10+3 shl 29,[sc.work]
504
		inc  edx
505
		mcall ,(LMARGIN+16*HSPACE+15)shl 16+6*16
506
		mov  edx,0xff0000
507
		mov  esi,dump_cell_size
508
		xor  eax,eax
509
		movzx ebx,[sel_byte]
510
		lodsw
511
		imul bx,ax
512
		shl  ebx,16
513
		lea  ebx,[ebx+eax+LMARGIN shl 16]
514
		movzx ecx,[sel_byte+2]
515
		lodsw
516
		imul cx,ax
517
		shl  ecx,16
518
		lea  ecx,[ecx+eax+(TMARGIN+VSPACE) shl 16]
519
		mcall 13
520
		movzx ebx,[sel_byte]
521
		lodsw
522
		imul bx,ax
523
		shl  ebx,16
524
		lea  ebx,[ebx+eax+(LMARGIN+16*HSPACE+15)shl 16]
525
  mcall 13
526
		popa
527
.ex:
1571 Asper 528
		ret
131 diamond 529
 
1571 Asper 530
 
531
if WRITE_LOG
532
;********************************************
533
;*  input:  esi = pointer to the file name  *
534
;********************************************
535
 
536
CreateFile:
537
    pusha
538
    mov      dword [InfoStructure],    2   ; create file
539
    mov      dword [InfoStructure+4],  0   ; reserved
540
    mov      dword [InfoStructure+8],  0   ; reserved
541
    mov      dword [InfoStructure+12], 0   ; 0 bytes to write (just create)
542
    mov      dword [InfoStructure+16], 0   ; NULL data pointer (no data)
543
    mov      dword [InfoStructure+20], 0   ; reserved
544
    mov      dword [InfoStructure+21], esi ; pointer to the file name
545
    mcall    70, InfoStructure
546
    clc
547
    test     eax, eax
548
    jz	     .out
549
    stc
550
  .out:
551
    popa
552
    ret
553
 
554
;********************************************
555
;*  input:  esi = pointer to the file name  *
556
;*          edx = pointer to data buffer    *
557
;*          ecx = data length               *
558
;********************************************
559
 
560
WriteToFile:
561
    push     ebx
562
    mov      dword [InfoStructure],    3   ; write to file
563
    mov      eax,  [filepos]
564
    mov      dword [InfoStructure+4],  eax ; lower position addr
565
    mov      dword [InfoStructure+8],  0   ; upper position addr (0 for FAT)
566
    mov      dword [InfoStructure+12], ecx ; number of bytes to write
567
    mov      dword [InfoStructure+16], edx ; pointer to data buffer
568
    mov      dword [InfoStructure+20], 0   ; reserved
569
    mov      dword [InfoStructure+21], esi ; pointer to the file name
570
    mcall    70, InfoStructure
571
    clc
572
    test     eax, eax
573
    jz	     .out
574
    stc
575
  .out:
576
    pop      ebx
577
    ret
578
 
579
 
580
InfoStructure:
581
		     dd      0x0     ; subfunction number
582
		     dd      0x0     ; position in the file in bytes
583
		     dd      0x0     ; upper part of the position address
584
		     dd      0x0     ; number of     bytes to read
585
		     dd      0x0     ; pointer to the buffer to write data
586
		     db      0
587
		     dd      0	     ; pointer to the filename
588
 
589
filepos  dd 0
590
filename db '/sys/boardlog.txt',0
591
tmp	 db 0
592
end if
593
 
594
 
595
 
596
 
131 diamond 597
krnl_msg db 'K : '
598
duk db 'KernUserDump'
599
numb db 'Byte:     Word:       Dword:               Hex:'
600
numb_len:
601
dump_title db 'Dump from              (pid=    h)         Offset:     (   h)'
602
dump_t_len:
603
 
31 halyavin 604
; DATA AREA
605
 
131 diamond 606
dump_cell_marg dd LMARGIN shl 16,(LMARGIN+16*HSPACE+15)shl 16
607
dump_cell_size dw HSPACE,VSPACE,6,VSPACE
608
; 11,11 > 0,-1
609
; 5,11  > 0,-1
31 halyavin 610
if lang eq ru
1571 Asper 611
   title    db	 'Доска отладки и сообщений',0
135 diamond 612
else if lang eq en
1571 Asper 613
   title    db	 'General debug & message board',0
135 diamond 614
else
1571 Asper 615
   title    db	 'Allgemeines debug- & nachrichtenboard',0
31 halyavin 616
end if
205 heavyiron 617
   krnl_cnt dd 0
1571 Asper 618
   vmode dd 1
131 diamond 619
   targ  dd text2
31 halyavin 620
I_END:
131 diamond 621
     offs dd ?
622
     flag rb 1
623
     ipcbuff rb IPC_BUF+20
624
     rd 2
625
;     x1pos  dd ?
626
;     y1pos  dd ?
627
     text1 rb 80*(MAXSTRINGS+1)
628
     tmp1  db ?
629
     rd 2
630
;     x2pos  dd ?
631
;     y2pos  dd ?
632
     text2 rb 80*(MAXSTRINGS+1)
633
     tmp2  db ?
634
     work rb 4096
635
     sel_byte  dw ?,?
636
     pid  dd ?
31 halyavin 637
     xstart dd ?
131 diamond 638
     dump_len dd ?
639
     sc system_colors
640
i_end: