Subversion Repositories Kolibri OS

Rev

Rev 1355 | Rev 1725 | 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     0x0 , 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.  
  37.      mcall 60,1,ipcbuff,IPC_BUF+20
  38.      mcall 40,1000111b
  39.      mov  [ipcbuff+4],8
  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
  47.  
  48.      mov  ecx, TMP
  49.      xor  eax, eax
  50.      mov  edi, [targ]
  51.      rep  stosb
  52.  
  53.      mov  [tmp1],'x'
  54.      mov  [tmp2],'x'
  55.  
  56.      mov  eax,14
  57.      mcall
  58.      and  eax,0xffff0000
  59.      sub  eax,399 shl 16
  60.      add  eax,399
  61.      mov  [xstart],eax
  62.  
  63.      mov  eax,48
  64.      mov  ebx,3
  65.      mov  ecx,sc
  66.      mov  edx,sizeof.system_colors
  67.      mcall
  68.   if WRITE_LOG
  69.      mov  esi, filename
  70.      call CreateFile
  71.   end if
  72.  
  73.   red:
  74.      call draw_window
  75.  
  76. still:
  77.  
  78.     mov  eax,23                 ; wait here for event
  79.     mov  ebx,1
  80.     mcall
  81.  
  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
  88.     cmp  eax,7
  89.     je   ipc
  90.  
  91.     mov  eax,63
  92.     mov  ebx,2
  93.     mcall
  94.  
  95.     cmp  ebx,1
  96.     jne  still
  97.  
  98.   new_data:
  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.  
  118.     mov  ebp,[targ]
  119.   .no4:
  120.     cmp  al,13
  121.     jne  no13
  122.     and  dword[ebp-8],0
  123.     jmp  new_check
  124.    no13:
  125.     cmp  al,10
  126.     jne  no10
  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
  133.     mov  ecx,80*(MAXSTRINGS)
  134.     cld
  135.     rep  movsb
  136.  
  137.     mov  esi,[ebp-4]
  138.     imul esi,80
  139.     add  esi,[ebp-8]
  140.     add  esi,ebp
  141.     mov  ecx,80
  142.     xor  al,al
  143.     rep  stosb
  144.   .noypos:
  145.     mov  [targ],text2
  146.     and  [krnl_cnt],0
  147.     jmp  new_check
  148.   no10:
  149.     cmp  ebp,text1
  150.     je   add2
  151.                 mov  ecx,[krnl_cnt]
  152.                   cmp  al,[krnl_msg+ecx]
  153.                 jne  .noknl
  154.                   inc  [krnl_cnt]
  155.                 cmp  [krnl_cnt],4
  156.                 jne  new_check
  157.     mov  [targ],text1
  158.         .noknl:
  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
  172.  
  173.   new_check:
  174.  
  175.     mov  eax,63
  176.     mov  ebx,2
  177.     mcall
  178.  
  179.     cmp  ebx,1
  180.     je   new_data
  181.  
  182.     cmp  [vmode],2
  183.     je   still
  184.     call draw_window
  185.  
  186.     jmp  still
  187.  
  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
  200.     je   .ok
  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
  211.   key:                          ; key
  212.     mov  al,2                  ; just read it and ignore
  213.     mcall
  214.     cmp  ah,' '
  215.     je   button.no_krnl_flt
  216.     cmp  [vmode],2
  217.     jne  still
  218.     cmp  ah,176 ;left
  219.     jb   still
  220.     cmp  ah,179 ;right
  221.     ja  still
  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:
  230.     jmp  still
  231.  
  232. arrows dd -1,16,-16,1
  233.  
  234.   button:                       ; button
  235.     mov  al,17                 ; get id
  236.     mcall
  237.  
  238.     cmp  ah,1                   ; button id=1 ?
  239.     jne  .noclose
  240.  
  241.     or   eax,-1                 ; close this program
  242.     mcall
  243.   .noclose:
  244.         shr  eax,8
  245.                 cmp  eax,10
  246.                 jb   .nodump
  247.                   lea  edi,[eax-10]
  248.                 mcall 37,1
  249.                   sub  eax,[edi*4+dump_cell_marg]
  250.                 sub  eax,TMARGIN+VSPACE
  251.                 push eax
  252.     and  eax,0xffff
  253.                   xor  edx,edx
  254.                 div  word[edi*4+dump_cell_size+2]
  255.                   mov  ecx,eax
  256.     shl  ecx,16
  257.                 xor  edx,edx
  258.                   pop  eax
  259.                 shr  eax,16
  260.                 div  word[edi*4+dump_cell_size]
  261.                 mov  cx,ax
  262.   .check_sel:
  263.                 mov  eax,ecx
  264.     shl  ax,12
  265.     shr  eax,12
  266.     inc  eax
  267.     cmp  eax,[dump_len]
  268.     ja   still;.nosel
  269.     mov  dword[sel_byte],ecx
  270.     dec  eax
  271.     mov  [offs],eax
  272.     jmp  red
  273.  
  274.   .nodump:
  275.     cmp  eax,2
  276.     jne  .no_krnl_flt
  277.     xor  [flag],FL_KRNL
  278.     jmp  still
  279.   .no_krnl_flt:
  280.     mov  [ipcbuff+4],8
  281.     and  byte[ipcbuff],0
  282.     inc  [vmode]
  283.     cmp  [vmode],3
  284.     jb   .vmok
  285.     and  [vmode],0
  286.   .vmok:
  287.     jmp  red
  288.  
  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
  297.     jb   .ok
  298.     mov  dword[ebp-8],79
  299.   .ok:
  300.     pop  esi
  301.     ret
  302.  
  303. ;   *********************************************
  304. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  305. ;   *********************************************
  306.  
  307.  
  308. draw_window:
  309.  
  310.     mov  eax,12                    ; function 12:tell os about windowdraw
  311.     mov  ebx,1                     ; 1, start of draw
  312.     mcall
  313.  
  314.                                    ; DRAW WINDOW
  315.     xor  eax,eax                     ; function 0 : define and draw window
  316. ;   mov  ebx,50*65536+400          ; [x start] *65536 + [x size]
  317.     mov  ebx,[xstart]
  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
  322.     mcall
  323.  
  324.     mov  ecx,4
  325.     mov  esi,[sc.work]
  326.     mov  ebx,296 shl 16+5*6
  327.     mov  edx,3;+1 shl 30
  328.     mcall 8,,<5,12>
  329.     mov  edx,[vmode]
  330.     lea  edx,[edx*4+duk]
  331.     mcall 4,<300,8>,,,4
  332.  
  333.     cmp  [vmode],2
  334.     je   no_mdbg
  335.     mov  ebx,15*65536+33           ; draw info text with function 4
  336.     mov  ecx,[sc.work_text]
  337.     mov  edx,text1
  338.     cmp  [vmode],0
  339.     je   .kern
  340.     mov  edx,text2
  341.   .kern:
  342.     mov  esi,80
  343.     mov  eax,4
  344.   newline:
  345.     mcall
  346.     add  ebx,10
  347.     add  edx,80
  348.     cmp  [edx],byte 'x'
  349.     jne  newline
  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
  360.                 call draw_dump
  361.                 enddraw:
  362.     mov  eax,12                    ; function 12:tell os about windowdraw
  363.     mov  ebx,2                     ; 2, end of draw
  364.     mcall
  365.  
  366.     ret
  367.  
  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
  390.  
  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
  425.   add   edx,(6*27) shl 16
  426.   mov   ecx,offs
  427.   mcall
  428.   sub   edx,(5*6)shl 16
  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
  444.         .lp:
  445.                 add  edx,(LMARGIN+2) shl 16+VSPACE
  446.                 mov  ecx,16
  447.                 cmp  edi,ecx
  448.                 jae  .less
  449.                 mov  ecx,edi
  450.         .less:
  451.                 sub  edi,ecx
  452.                 push esi ecx
  453.                 mov  ebx,0x20100
  454.         .lp1:
  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
  499.         .even:
  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:
  528.                 ret
  529.  
  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.  
  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.  
  604. ; DATA AREA
  605.  
  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
  610. if lang eq ru
  611.    title    db   '„®áª  ®â« ¤ª¨ ¨ á®®¡é¥­¨©',0
  612. else if lang eq en
  613.    title    db   'General debug & message board',0
  614. else
  615.    title    db   'Allgemeines debug- & nachrichtenboard',0
  616. end if
  617.    krnl_cnt dd 0
  618.    vmode dd 1
  619.    targ  dd text2
  620. I_END:
  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 ?
  637.      xstart dd ?
  638.      dump_len dd ?
  639.      sc system_colors
  640. i_end:
  641.