Subversion Repositories Kolibri OS

Rev

Rev 485 | Rev 1571 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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