Subversion Repositories Kolibri OS

Rev

Rev 4879 | Rev 5837 | 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  = 16
  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.         xor     al , 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.         mcall   4,<300,7>,,,4
  222.         call    draw_text
  223.         mcall   12, 2                     ; 2, end of draw
  224.         ret
  225. ;------------------------------------------------------------------------------
  226. draw_text:
  227.         mov     ebx, 15*65536+30          ; draw info text with function 4
  228.         xor     ecx, ecx
  229.         or      ecx, 0x40000000
  230.         mov     edi, 0xffffff
  231.         mov     edx, text1
  232.         cmp     [vmode], 0
  233.         je      .kern
  234.         mov     edx, text2
  235.     .kern:
  236.         push    ebx ecx edx
  237.         mcall   9, procinfo,-1
  238.         mov     eax, [ebx+42]
  239.         xor     edx, edx
  240.         mov     ebx, 6
  241.         div     ebx
  242.         pop     edx ecx ebx
  243.         mov     esi, 80
  244.         cmp     eax, esi
  245.         ja      @f
  246.         mov     esi, eax
  247. @@:
  248.         cmp     esi, 5
  249.         ja      @f
  250.         mov     esi, 5
  251. @@:
  252.         sub     esi, 4
  253.         mov     eax, 4
  254. newline:
  255.         mcall
  256.         add     ebx, 10
  257.         add     edx, 80
  258.         cmp     [edx], byte 'x'
  259.         jne     newline
  260.         ret
  261.  
  262. ;------------------------------------------------------------------------------
  263. ;*  input:  esi = pointer to the file name  *
  264. ;------------------------------------------------------------------------------
  265. CreateFile:
  266.         pusha
  267.         mov     dword [InfoStructure+00], 2   ; create file
  268.         mov     dword [InfoStructure+04], 0   ; reserved
  269.         mov     dword [InfoStructure+08], 0   ; reserved
  270.         mov     dword [InfoStructure+12], 0   ; 0 bytes to write (just create)
  271.         mov     dword [InfoStructure+16], 0   ; NULL data pointer (no data)
  272.         mov     dword [InfoStructure+20], 0   ; reserved
  273.         mov     dword [InfoStructure+21], esi ; pointer to the file name
  274.         mcall   70, InfoStructure
  275.         test    eax, eax
  276.         jz      .out
  277.         stc
  278.     .out:
  279.         popa
  280.         ret
  281. ;------------------------------------------------------------------------------
  282. ;*  input:  esi = pointer to the file name  *
  283. ;*          edx = pointer to data buffer    *
  284. ;*          ecx = data length               *
  285. ;------------------------------------------------------------------------------
  286. WriteToFile:
  287.         push    ebx
  288.         mov     dword [InfoStructure+00], 3   ; write to file
  289.         mov     eax,  [filepos]
  290.         mov     dword [InfoStructure+04], eax ; lower position addr
  291.         mov     dword [InfoStructure+08], 0   ; upper position addr (0 for FAT)
  292.         mov     dword [InfoStructure+12], ecx ; number of bytes to write
  293.         mov     dword [InfoStructure+16], edx ; pointer to data buffer
  294.         mov     dword [InfoStructure+20], 0   ; reserved
  295.         mov     dword [InfoStructure+21], esi ; pointer to the file name
  296.         mcall   70, InfoStructure
  297.         clc
  298.         test    eax, eax
  299.         jz      .out
  300.         stc
  301.     .out:
  302.         pop      ebx
  303.         ret
  304.  
  305. ;------------------------------------------------------------------------------
  306. ;*  input:  esi = pointer to string         *
  307. ;*          edi = pointer to string         *
  308. ;*          ecx = data length               *
  309. ;------------------------------------------------------------------------------
  310. StrCmp:
  311.         repe    cmpsb
  312.         ja      .a_greater_b
  313.         jb      .a_less_b
  314.     .equal:
  315.         mov     eax, 0
  316.         jmp     .end
  317.     .a_less_b:
  318.         mov     eax, 1
  319.         jmp     .end
  320.     .a_greater_b:
  321.         mov     eax, -1
  322.     .end:
  323.         ret
  324.  
  325. ;------------------------------------------------------------------------------
  326. ;*  input:  edi = pointer to string          *
  327. ;*          ecx = data length                *
  328. ;------------------------------------------------------------------------------
  329. ; 'a' - 'A' = 32 -> 'A'|32 = 'a'
  330. ToLower:
  331.         xor     eax, eax
  332. .cycle:
  333.         or      byte[edi+eax], 32
  334.         inc     eax
  335.         loop    .cycle
  336. .end:
  337.         ret
  338.  
  339. ;------------------------------------------------------------------------------
  340. ;* get info on current thread, save pid/tid
  341. ;* look for another process with same name and different pid/tid
  342. ;* if found, close self
  343. ;* else continue normally
  344. ;------------------------------------------------------------------------------
  345. CheckUnique:
  346.     .get_thread_info:
  347.         mov     ebx, procinfo
  348.         mov     ecx, -1
  349.         mcall   9
  350.  
  351.     .get_pid:                             ; check_buffer
  352.         mov     [process_count], eax
  353.         mov     eax, [ebx+process_information.PID]
  354.         mov     [pid_tid], eax
  355.         mov     ecx, 2
  356.  
  357.     .check_threads:
  358.         cmp     ecx, [process_count]
  359.         ja      .leave_check
  360.         mov     eax, 9
  361.         mcall
  362.  
  363.     .check_slot_free:
  364.         cmp     dword [ebx+process_information.slot_state], 9
  365.         je      .next_thread
  366.  
  367.     .check_pid:
  368.         mov     eax, [pid_tid]
  369.         cmp     [ebx+process_information.PID], eax
  370.         je      .next_thread
  371.  
  372.     .get_proc_name:
  373.         lea     edi, [ebx+process_information.process_name]
  374.         push    ecx
  375.         mov     ecx, my_name_size-1
  376.  
  377.     .lower_case:
  378.         call    ToLower
  379.         lea     esi, [my_name]
  380.         mov     ecx, my_name_size
  381.         call    StrCmp
  382.         pop     ecx
  383.         cmp     eax, 0
  384.         je      .close_program
  385.  
  386.     .next_thread:
  387.         inc     ecx
  388.         jmp     .check_threads
  389.  
  390.     .close_program:
  391.         ; restore and active window of previous thread
  392.         mcall    18, 3
  393.         mov      eax, -1
  394.         mcall
  395.  
  396.     .leave_check:
  397.         ret
  398.  
  399.  
  400. ;------------------------------------------------------------------------------
  401. ;***********************************  DATA ************************************
  402. ;------------------------------------------------------------------------------
  403. align 4
  404. InfoStructure:
  405.         dd      0x0                       ; subfunction number
  406.         dd      0x0                       ; position in the file in bytes
  407.         dd      0x0                       ; upper part of the position address
  408.         dd      0x0                       ; number of bytes to read
  409.         dd      0x0                       ; pointer to the buffer to write data
  410.         db      0x0
  411.         dd      0x0                       ; pointer to the filename
  412. filepos dd      0x0
  413. default_filename db '/sys/boardlog.txt',0
  414. ;------------------------------------------------------------------------------
  415. if lang eq ru
  416.  title  db '„®áª  ®â« ¤ª¨ ¨ á®®¡é¥­¨©',0
  417. else if lang eq it
  418.  title  db 'Notifiche e informazioni generiche per il debug',0
  419. else if lang eq ge
  420.  title  db 'Allgemeines debug- & nachrichtenboard',0
  421. else
  422.  title  db 'General debug & message board',0
  423. end if
  424. ;------------------------------------------------------------------------------
  425. krnl_msg        db  'K : '
  426. duk             db  'KernUser'
  427. krnl_cnt        dd  0
  428. vmode           dd  1
  429. targ            dd  text2
  430. my_name         db  'board',0
  431. my_name_size    = $-my_name
  432. process_count   dd  0x0
  433. pid_tid         dd  0x0
  434. ;------------------------------------------------------------------------------
  435. I_END:
  436. ;------------------------------------------------------------------------------
  437. offs            dd  ?
  438. flag            rb  1
  439.                 rd  2
  440. text1           rb  80*(MAXSTRINGS+1)
  441. tmp1            db  ?
  442.                 rd  2
  443. text2           rb  80*(MAXSTRINGS+1)
  444. tmp2            db  ?
  445. xstart          dd  ?
  446. sc              sys_colors_new
  447. i_end:
  448. buffer_length   rb  1
  449. ;------------------------------------------------------------------------------
  450. tmp             rb  256
  451. filename        rb  256
  452. ;------------------------------------------------------------------------------
  453. align 4
  454. procinfo:
  455.         rb 1024
  456. ;------------------------------------------------------------------------------
  457. align 4
  458. stackbuf        rb  2000h
  459. ;------------------------------------------------------------------------------
  460. mem: