Subversion Repositories Kolibri OS

Rev

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