Subversion Repositories Kolibri OS

Rev

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