Subversion Repositories Kolibri OS

Rev

Rev 5837 | Rev 6162 | 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. ; See f63
  4. ; Compile with FASM for KolibriOS
  5. ;------------------------------------------------------------------------------
  6. use32
  7. org 0
  8.         db      'MENUET01'
  9.         dd      1
  10.         dd      START
  11.         dd      I_END
  12.         dd      mem
  13.         dd      mem
  14.         dd      filename
  15.         dd      0
  16. ;------------------------------------------------------------------------------
  17. include 'lang.inc'
  18. include '../../../macros.inc'
  19. include '../../../debug.inc'
  20. purge   newline
  21. MAXSTRINGS = 45
  22. ;------------------------------------------------------------------------------
  23. START:
  24.         call    CheckUnique
  25.         mov     edi, filename
  26.         cmp     [edi], byte 0
  27.         jnz     param
  28.         mov     esi, default_filename
  29. @@:
  30.         lodsb
  31.         stosb
  32.         test    al,al
  33.         jnz     @b
  34. param:
  35.         mov     ecx, (MAXSTRINGS+1)*20
  36.         mov     edi, text1
  37.         mov     eax, '    '
  38.         rep     stosd
  39.  
  40.         mov     ecx, (MAXSTRINGS+1)*20
  41.         mov     edi, text2
  42.         rep     stosd
  43.  
  44.         mov     byte [tmp1], 'x'
  45.         mov     byte [tmp2], 'x'
  46.  
  47.         mcall   14
  48.         and     eax, 0xffff0000
  49.         sub     eax, 399 shl 16
  50.         add     eax, 399
  51.         mov     [xstart], eax
  52.         mcall   48, 3, sc, sizeof.sys_colors_new
  53.  
  54.         mov     esi, filename
  55.         call    CreateFile
  56. ;------------------------------------------------------------------------------
  57. red:
  58.         call    draw_window
  59. ;------------------------------------------------------------------------------
  60. still:
  61.         cmp     [buffer_length], 0
  62.         je      @f
  63.         call    write_buffer
  64. @@:
  65.         mcall   23, 50                    ; wait here for event
  66.         cmp     eax, 1                    ; redraw request ?
  67.         je      red
  68.  
  69.         cmp     eax, 2                    ; key in buffer ?
  70.         je      key
  71.  
  72.         cmp     eax, 3                    ; button in buffer ?
  73.         je      button
  74.  
  75.         mcall   63, 2
  76.         cmp     ebx, 1
  77.         jne     still
  78.  
  79. new_data:
  80.         cmp     [buffer_length], 255
  81.         jne     @f
  82.         call    write_buffer
  83. @@:
  84.         movzx   ebx, byte[buffer_length]
  85.         mov     [ebx+tmp], al
  86.         inc     [buffer_length]
  87.         mov     ebp, [targ]
  88.         cmp     al, 10
  89.         jz      new_line
  90.         cmp     al, 13
  91.         jz      new_check
  92.         jmp     char
  93. ;------------------------------------------
  94. write_buffer:
  95.         pusha
  96.         mov     edx, tmp
  97.         movzx   ecx, byte[buffer_length]
  98.         mov     esi, filename
  99. .write_to_logfile:
  100.         call    WriteToFile
  101.         cmp     eax, 5
  102.         jne     @f
  103.         mov     esi, filename
  104.         mov     [filepos], 0
  105.         call    CreateFile
  106.         jnc     .write_to_logfile
  107. @@:
  108.         movzx   eax,byte[buffer_length]
  109.         add     [filepos],eax
  110.         xor     eax,eax
  111.         mov     [buffer_length],al
  112.         popa
  113.         ret
  114. ;------------------------------------------
  115. new_line:
  116.         and     [ebp-8], dword 0
  117.         inc     dword [ebp-4]
  118.         cmp     [ebp-4], dword MAXSTRINGS
  119.         jbe     .noypos
  120.         mov     [ebp-4], dword MAXSTRINGS
  121.         lea     esi, [ebp+80]
  122.         mov     edi, ebp
  123.         mov     ecx, 20*(MAXSTRINGS)
  124.         cld
  125.         rep     movsd
  126.  
  127.         mov     esi, [ebp-4]
  128.         imul    esi, 80
  129.         add     esi, [ebp-8]
  130.         add     esi, ebp
  131.         mov     ecx, 20
  132.         mov     eax, '    '
  133.         rep     stosd
  134. .noypos:
  135.         mov     [targ],text2
  136.         and     [krnl_cnt],0
  137.         jmp     new_check
  138. ;------------------------------------------
  139. char:
  140.         cmp     ebp, text1
  141.         je      add2
  142.         mov     ecx, [krnl_cnt]
  143.         cmp     al, [krnl_msg+ecx]
  144.         jne     .noknl
  145.         inc     [krnl_cnt]
  146.         cmp     [krnl_cnt], 4
  147.         jne     new_check
  148.         mov     [targ], text1
  149. .noknl:
  150.         mov     ebp, [targ]
  151.         jecxz   .add
  152.         push    eax
  153.         mov     esi, krnl_msg
  154. .l1:
  155.         lodsb
  156.         call    add_char
  157.         loop    .l1
  158.         pop     eax
  159. .add:
  160.         and     [krnl_cnt], 0
  161. add2:
  162.         call    add_char
  163.  
  164. new_check:
  165.         mcall   63, 2
  166.         cmp     ebx, 1
  167.         je      new_data
  168.         call    draw_text
  169.         jmp     still
  170. ;------------------------------------------------------------------------------
  171. key:
  172.         mcall   2
  173.         cmp     ah, ' '
  174.         je      button.noclose
  175.         jmp     still
  176. ;------------------------------------------------------------------------------
  177. button:
  178.         mcall   17                        ; get id
  179.         cmp     ah, 1                     ; button id=1 ?
  180.         jne     .noclose
  181.         or      eax, -1                   ; close this program
  182.         mcall
  183. .noclose:
  184.         xor     [vmode], 1
  185.         jmp     red
  186. ;------------------------------------------------------------------------------
  187. add_char:
  188.         push    esi
  189.         mov     esi, [ebp-4]
  190.         imul    esi, 80
  191.         add     esi, [ebp-8]
  192.         mov     [ebp+esi], al
  193.         inc     dword[ebp-8]
  194.         cmp     dword[ebp-8], 80
  195.         jb      .ok
  196.         mov     dword[ebp-8], 79
  197. .ok:
  198.         pop     esi
  199.         ret
  200.  
  201. ;------------------------------------------------------------------------------
  202. ;************************  WINDOW DEFINITIONS AND DRAW ************************
  203. ;------------------------------------------------------------------------------
  204. draw_window:
  205.         mcall   12, 1                     ; 1, start of draw
  206.         mcall   48, 5                     ; GetClientTop
  207.         shr     ebx, 16
  208.         mov     ecx, ebx
  209.         shl     ecx, 16
  210.         add     ecx, MAXSTRINGS*10+45     ; [y start] *65536 + [y size]
  211.         xor     eax, eax                  ; function 0 : define and draw window
  212.         mov     edx, 0xffffff
  213.         or      edx, 0x14000000
  214.         xor     esi, esi
  215.         mcall   ,[xstart],,,,title
  216.         mov     ebx, 296 shl 16+31
  217.         mcall   8,,<4,13>,3,[sc.btn_face]
  218.         mov     edx, [vmode]
  219.         lea     edx, [edx*4+duk]
  220.         mov     ecx, 0x80
  221.         shr     ecx, 24
  222.         add     ecx, [sc.btn_text]
  223.         mcall   4,<300,7>,,,4
  224.         call    draw_text
  225.         mcall   12, 2                     ; 2, end of draw
  226.         ret
  227. ;------------------------------------------------------------------------------
  228. draw_text:
  229.         mov     ebx, 15*65536+30          ; draw info text with function 4
  230.         xor     ecx, ecx
  231.         or      ecx, 0x40000000
  232.         mov     edi, 0xffffff
  233.         mov     edx, text1
  234.         cmp     [vmode], 0
  235.         je      .kern
  236.         mov     edx, text2
  237. .kern:
  238.         push    ebx ecx edx
  239.         mcall   9, procinfo,-1
  240.         mov     eax, [ebx+42]
  241.         xor     edx, edx
  242.         mov     ebx, 6
  243.         div     ebx
  244.         pop     edx ecx ebx
  245.         mov     esi, 80
  246.         cmp     eax, esi
  247.         ja      @f
  248.         mov     esi, eax
  249. @@:
  250.         cmp     esi, 5
  251.         ja      @f
  252.         mov     esi, 5
  253. @@:
  254.         sub     esi, 4
  255.         mov     eax, 4
  256. newline:
  257.         mcall
  258.         add     ebx, 10
  259.         add     edx, 80
  260.         cmp     [edx], byte 'x'
  261.         jne     newline
  262.         ret
  263.  
  264. ;------------------------------------------------------------------------------
  265. ;*  input:  esi = pointer to the file name  *
  266. ;------------------------------------------------------------------------------
  267. CreateFile:
  268.         pusha
  269.         mov     dword [InfoStructure+00], 2   ; create file
  270.         mov     dword [InfoStructure+04], 0   ; reserved
  271.         mov     dword [InfoStructure+08], 0   ; reserved
  272.         mov     dword [InfoStructure+12], 0   ; 0 bytes to write (just create)
  273.         mov     dword [InfoStructure+16], 0   ; NULL data pointer (no data)
  274.         mov     dword [InfoStructure+20], 0   ; reserved
  275.         mov     dword [InfoStructure+21], esi ; pointer to the file name
  276.         mcall   70, InfoStructure
  277.         test    eax, eax
  278.         jz      .out
  279.         stc
  280. .out:
  281.         popa
  282.         ret
  283. ;------------------------------------------------------------------------------
  284. ;*  input:  esi = pointer to the file name  *
  285. ;*          edx = pointer to data buffer    *
  286. ;*          ecx = data length               *
  287. ;------------------------------------------------------------------------------
  288. WriteToFile:
  289.         push    ebx
  290.         mov     dword [InfoStructure+00], 3   ; write to file
  291.         mov     eax,  [filepos]
  292.         mov     dword [InfoStructure+04], eax ; lower position addr
  293.         mov     dword [InfoStructure+08], 0   ; upper position addr (0 for FAT)
  294.         mov     dword [InfoStructure+12], ecx ; number of bytes to write
  295.         mov     dword [InfoStructure+16], edx ; pointer to data buffer
  296.         mov     dword [InfoStructure+20], 0   ; reserved
  297.         mov     dword [InfoStructure+21], esi ; pointer to the file name
  298.         mcall   70, InfoStructure
  299.         clc
  300.         test    eax, eax
  301.         jz      .out
  302.         stc
  303. .out:
  304.         pop     ebx
  305.         ret
  306.  
  307. ;------------------------------------------------------------------------------
  308. ;*  input:  esi = pointer to string         *
  309. ;*          edi = pointer to string         *
  310. ;*          ecx = data length               *
  311. ;------------------------------------------------------------------------------
  312. StrCmp:
  313.         repe    cmpsb
  314.         ja      .a_greater_b
  315.         jb      .a_less_b
  316. .equal:
  317.         mov     eax, 0
  318.         jmp     .end
  319. .a_less_b:
  320.         mov     eax, 1
  321.         jmp     .end
  322. .a_greater_b:
  323.         mov     eax, -1
  324. .end:
  325.         ret
  326.  
  327. ;------------------------------------------------------------------------------
  328. ;*  input:  edi = pointer to string          *
  329. ;*          ecx = data length                *
  330. ;------------------------------------------------------------------------------
  331. ; 'a' - 'A' = 32 -> 'A'|32 = 'a'
  332. ToLower:
  333.         xor     eax, eax
  334. .cycle:
  335.         or      byte[edi+eax], 32
  336.         inc     eax
  337.         loop    .cycle
  338. .end:
  339.         ret
  340.  
  341. ;------------------------------------------------------------------------------
  342. ;* get info on current thread, save pid/tid
  343. ;* look for another process with same name and different pid/tid
  344. ;* if found, close self
  345. ;* else continue normally
  346. ;------------------------------------------------------------------------------
  347. CheckUnique:
  348. .get_thread_info:
  349.         mov     ebx, procinfo
  350.         mov     ecx, -1
  351.         mcall   9
  352.  
  353. .get_pid:                             ; check_buffer
  354.         mov     [process_count], eax
  355.         mov     eax, [ebx+process_information.PID]
  356.         mov     [pid_tid], eax
  357.         mov     ecx, 2
  358.  
  359. .check_threads:
  360.         cmp     ecx, [process_count]
  361.         ja      .leave_check
  362.         mov     eax, 9
  363.         mcall
  364.  
  365. .check_slot_free:
  366.         cmp     dword [ebx+process_information.slot_state], 9
  367.         je      .next_thread
  368.  
  369. .check_pid:
  370.         mov     eax, [pid_tid]
  371.         cmp     [ebx+process_information.PID], eax
  372.         je      .next_thread
  373.  
  374. .get_proc_name:
  375.         lea     edi, [ebx+process_information.process_name]
  376.         push    ecx
  377.         mov     ecx, my_name_size-1
  378.  
  379. .lower_case:
  380.         call    ToLower
  381.         lea     esi, [my_name]
  382.         mov     ecx, my_name_size
  383.         call    StrCmp
  384.         pop     ecx
  385.         cmp     eax, 0
  386.         je      .close_program
  387.  
  388. .next_thread:
  389.         inc     ecx
  390.         jmp     .check_threads
  391.  
  392. .close_program:
  393.         ; restore and active window of previous thread
  394.         mcall   18, 3
  395.         mov     eax, -1
  396.         mcall
  397.  
  398. .leave_check:
  399.         ret
  400.  
  401. ;------------------------------------------------------------------------------
  402. ; DATA
  403.  
  404. if lang eq ru
  405.  title  db '„®áª  ®â« ¤ª¨ ¨ á®®¡é¥­¨©',0
  406. else if lang eq it
  407.  title  db 'Notifiche e informazioni generiche per il debug',0
  408. else if lang eq ge
  409.  title  db 'Allgemeines debug- & nachrichtenboard',0
  410. else
  411.  title  db 'General debug & message board',0
  412. end if
  413.  
  414. default_filename db '/sys/boardlog.txt',0
  415. krnl_msg        db  'K : '
  416. duk             db  'KernUser'
  417. my_name         db  'board',0
  418. my_name_size = $-my_name
  419.  
  420. align 4
  421. vmode   dd  1
  422. targ    dd  text2
  423.  
  424. I_END:
  425.  
  426. InfoStructure:
  427.         dd      ?       ; subfunction number
  428.         dd      ?       ; position in the file in bytes
  429.         dd      ?       ; upper part of the position address
  430.         dd      ?       ; number of bytes to read
  431.         dd      ?       ; pointer to the buffer to write data
  432.         db      ?
  433.         dd      ?       ; pointer to the filename
  434.  
  435. buffer_length   rb  3
  436. process_count   dd  ?
  437. krnl_cnt        dd  ?
  438. pid_tid         dd  ?
  439. filepos         dd  ?
  440. xstart          dd  ?
  441. sc      sys_colors_new
  442.  
  443.         rd  2
  444. text1   rb  80*(MAXSTRINGS+1)
  445. tmp1    dd  ?
  446.  
  447.         rd  2
  448. text2   rb  80*(MAXSTRINGS+1)
  449. tmp2    dd  ?
  450.  
  451. tmp             rb  256
  452. filename        rb  256
  453. procinfo        rb  1024
  454. stackbuf        rb  2000h
  455. mem:
  456.