Subversion Repositories Kolibri OS

Rev

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