Subversion Repositories Kolibri OS

Rev

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