Subversion Repositories Kolibri OS

Rev

Rev 4673 | Rev 4879 | 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 KolibriOS
  7. ;
  8. WRITE_LOG    equ 1
  9. P_LEN            equ 11
  10. include 'lang.inc'
  11.  
  12.    use32
  13.    org    0x0
  14.    db     'MENUET01'              ; 8 byte id
  15.    dd     0x01                    ; header version
  16.    dd     START                   ; start of code
  17.    dd     I_END                   ; size of image
  18.    dd     mem                   ; memory for app
  19.    dd     mem                   ; esp
  20.    dd     filename , 0x0          ; I_Param , I_Icon
  21. include '../../../macros.inc'
  22. include '../../../debug.inc'
  23. purge newline
  24. MAXSTRINGS = 16
  25. TMP = 80*(MAXSTRINGS+1)
  26. ;------------------------------------------------------------------------------
  27. START:                          ; start of execution
  28.  
  29.         call CheckUnique
  30.  
  31.         mov     edi,filename
  32.         cmp     [edi],byte 0
  33.         jnz     param
  34.         mov     esi,default_filename
  35. @@:
  36.         lodsb
  37.         stosb
  38.         test    al,al
  39.         jnz     @b
  40. param:
  41.  
  42. ; allow user to see messages written before start
  43. ;       mov     ecx,4096
  44. ;flush:
  45. ;       mcall   63,2
  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.         mcall   14
  57.         and     eax,0xffff0000
  58.         sub     eax,399 shl 16
  59.         add     eax,399
  60.         mov     [xstart],eax
  61.         mcall   48,3,sc,sizeof.system_colors
  62.  
  63.         mov     esi,filename
  64.         call    CreateFile
  65. ;------------------------------------------------------------------------------
  66. red:
  67.         call draw_window
  68. ;------------------------------------------------------------------------------
  69. still:
  70.         cmp     [buffer_length],0
  71.         je      @f
  72.         call    write_buffer
  73. @@:
  74.         mcall   23,50           ; wait here for event
  75.         cmp     eax,1                   ; redraw request ?
  76.         je      red
  77.  
  78.         cmp     eax,2                   ; key in buffer ?
  79.         je      key
  80.  
  81.         cmp     eax,3                   ; button in buffer ?
  82.         je      button
  83.  
  84.         mcall   63,2
  85.         cmp     ebx,1
  86.         jne     still
  87.  
  88. new_data:
  89.         cmp     [buffer_length],255
  90.         jne     @f
  91.         call    write_buffer
  92. @@:
  93.         movzx   ebx,byte[buffer_length]
  94.         mov     [ebx+tmp],al
  95.         inc     [buffer_length]
  96.  
  97.         mov     ebp,[targ]
  98. .no4:
  99.         cmp     al,13
  100.         jne     no13
  101.         and     [ebp-8],dword 0
  102.         jmp     new_check
  103. ;------------------------------------------
  104. write_buffer:
  105.         pusha
  106.         mov     edx,tmp
  107.         movzx   ecx,byte[buffer_length] ;1
  108.         mov     esi,filename
  109. .write_to_logfile:
  110.         call    WriteToFile
  111.         cmp     eax,5
  112.         jne     @f
  113.         mov     esi,filename
  114.         mov     [filepos],0
  115.         call    CreateFile
  116.         jnc     .write_to_logfile
  117. @@:
  118.         movzx   eax,byte[buffer_length]
  119.         add     [filepos],eax
  120.         xor     eax,eax
  121.         mov     [buffer_length],al
  122.         popa
  123.         ret
  124. ;------------------------------------------
  125. no13:
  126.         cmp     al,10
  127.         jne     no10
  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,80*(MAXSTRINGS)
  136.         cld
  137.         rep     movsb
  138.  
  139.         mov     esi,[ebp-4]
  140.         imul    esi,80
  141.         add     esi,[ebp-8]
  142.         add     esi,ebp
  143.         mov     ecx,80
  144.         xor     al,al
  145.         rep     stosb
  146. .noypos:
  147.         mov     [targ],text2
  148.         and     [krnl_cnt],0
  149.         jmp     new_check
  150. ;------------------------------------------
  151. no10:
  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. macro GetClientTop
  214. {
  215.        
  216. }
  217. ;------------------------------------------------------------------------------
  218. ;   *********************************************
  219. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  220. ;   *********************************************
  221. draw_window:
  222.         mcall   12,1    ; 1, start of draw
  223.         mcall 48, 5     ; GetClientTop
  224.     shr ebx, 16
  225.         mov     ecx,ebx
  226.         shl ecx,16
  227.         add ecx,MAXSTRINGS*10+45           ; [y start] *65536 + [y size]
  228.         xor     eax,eax              ; function 0 : define and draw window
  229. ;       mov     edx,[sc.work]              ; color of work area RRGGBB,8->color gl
  230.         mov     edx,0xffffff
  231.         or      edx,0x14000000
  232.         xor     esi,esi
  233.         mcall   ,[xstart],,,,title
  234.         mov     ebx,296 shl 16+5*6
  235.         mcall   8,,<5,12>,3,[sc.work]
  236.         mov     edx,[vmode]
  237.         lea     edx,[edx*4+duk]
  238.         mcall   4,<300,8>,,,4
  239.         call    draw_text
  240.         mcall   12,2    ; 2, end of draw
  241.         ret
  242. ;------------------------------------------------------------------------------
  243. draw_text:
  244.         mov     ebx,15*65536+30    ; draw info text with function 4
  245. ;       mov     ecx,[sc.work_text]
  246.         xor     ecx,ecx
  247.         or      ecx,0x40000000
  248. ;       mov     edi,[sc.work]
  249.         mov     edi,0xffffff
  250.         mov     edx,text1
  251.         cmp     [vmode],0
  252.         je      .kern
  253.         mov     edx,text2
  254. .kern:
  255.         push    ebx ecx edx
  256.         mcall   9,procinfo,-1
  257.         mov     eax,[ebx+42]
  258.         xor     edx,edx
  259.         mov     ebx,6
  260.         div     ebx
  261.         pop     edx ecx ebx
  262.         mov     esi,80
  263.         cmp     eax,esi
  264.         ja      @f
  265.         mov     esi,eax
  266. @@:
  267.         cmp     esi,5
  268.         ja      @f
  269.         mov     esi,5
  270. @@:
  271.         sub     esi,4
  272.         mov     eax,4
  273. newline:
  274.         mcall
  275.         add     ebx,10
  276.         add     edx,80
  277.         cmp     [edx],byte 'x'
  278.         jne     newline
  279.         ret
  280. ;------------------------------------------------------------------------------
  281. ;********************************************
  282. ;*  input:  esi = pointer to the file name  *
  283. ;********************************************
  284.  
  285. CreateFile:
  286.         pusha
  287.         mov     dword [InfoStructure],2         ; create file
  288.         mov     dword [InfoStructure+4],0       ; reserved
  289.         mov     dword [InfoStructure+8],0       ; reserved
  290.         mov     dword [InfoStructure+12],0      ; 0 bytes to write (just create)
  291.         mov     dword [InfoStructure+16],0      ; NULL data pointer (no data)
  292.         mov     dword [InfoStructure+20],0      ; reserved
  293.         mov     dword [InfoStructure+21],esi    ; pointer to the file name
  294.         mcall   70, InfoStructure
  295.         test    eax,eax
  296.         jz      .out
  297.         stc
  298. .out:
  299.         popa
  300.         ret
  301. ;------------------------------------------------
  302. ;********************************************
  303. ;*  input:  esi = pointer to the file name  *
  304. ;*          edx = pointer to data buffer    *
  305. ;*          ecx = data length               *
  306. ;********************************************
  307.  
  308. WriteToFile:
  309.         push    ebx
  310.         mov     dword [InfoStructure],3         ; write to file
  311.         mov     eax,  [filepos]
  312.         mov     dword [InfoStructure+4],eax     ; lower position addr
  313.         mov     dword [InfoStructure+8],0       ; upper position addr (0 for FAT)
  314.         mov     dword [InfoStructure+12],ecx    ; number of bytes to write
  315.         mov     dword [InfoStructure+16],edx    ; pointer to data buffer
  316.         mov     dword [InfoStructure+20],0      ; reserved
  317.         mov     dword [InfoStructure+21],esi    ; pointer to the file name
  318.         mcall   70, InfoStructure
  319.         clc
  320.         test    eax,eax
  321.         jz      .out
  322.         stc
  323. .out:
  324.         pop      ebx
  325.         ret
  326.  
  327. ;-------------------------------------------------
  328. ;********************************************
  329. ;*  input:  esi = pointer to string         *
  330. ;*          edi = pointer to string         *
  331. ;*          ecx = data length               *
  332. ;********************************************
  333. StrCmp:
  334.         repe cmpsb
  335.         ja .a_greater_b
  336.         jb .a_less_b
  337. .equal:
  338.         mov eax, 0
  339.         jmp .end
  340. .a_less_b:
  341.         mov eax, 1
  342.         jmp .end
  343. .a_greater_b:
  344.         mov eax, -1
  345. .end:
  346.         ret
  347.  
  348. ;-------------------------------------------------
  349. ;********************************************
  350. ;*  input:  edi = pointer to string         *
  351. ;*          ecx = data length                       *
  352. ;********************************************
  353. ; 'a' - 'A' = 32 -> 'A'|32 = 'a'
  354. ToLower:
  355.         xor eax, eax
  356. .cycle:
  357.         or byte[edi+eax], 32
  358.         inc eax
  359.         loop .cycle
  360. .end:
  361.         ret
  362.  
  363.  
  364. ;-------------------------------------------------
  365. CheckUnique:
  366. ;get info on current thread, save pid/tid
  367. ;look for another process with same name and different pid/tid
  368. ;if found, close self
  369. ;else continue normally
  370.  
  371. .get_thread_info:
  372.         mov ebx, procinfo
  373.         mov ecx, -1
  374.         mcall 9
  375. .get_pid:
  376. ; check_buffer
  377.         mov [process_count], eax
  378.         mov eax, [ebx+process_information.PID]
  379.         mov [pid_tid], eax
  380.         mov ecx, 2
  381.  
  382. .check_threads:
  383.         cmp ecx, [process_count]
  384.         ja .leave_check
  385.         mov eax, 9
  386.         mcall
  387.  
  388. .check_slot_free:
  389.         cmp dword [ebx+process_information.slot_state], 9
  390.         je .next_thread
  391.  
  392. .check_pid:
  393.         mov eax, [pid_tid]
  394.         cmp [ebx+process_information.PID], eax
  395.         je .next_thread
  396.  
  397. .get_proc_name:
  398.         lea edi, [ebx+process_information.process_name]
  399.         push ecx
  400.         mov ecx, my_name_size-1
  401. .lower_case:
  402.         call ToLower
  403.         lea esi, [my_name]
  404.  
  405.         mov ecx, my_name_size
  406.         call StrCmp
  407.  
  408.         pop ecx
  409.  
  410.         cmp eax, 0
  411.         je .close_program
  412.  
  413. .next_thread:
  414.         inc ecx
  415.         jmp .check_threads
  416.  
  417. .close_program:
  418.         mcall 18,3 ; restore and active window of previous thread
  419.         mov eax, -1
  420.         mcall
  421.  
  422. .leave_check:
  423.         ret
  424.  
  425.  
  426.  
  427. ;--------------------------------------------------
  428. InfoStructure:
  429.         dd 0x0  ; subfunction number
  430.         dd 0x0  ; position in the file in bytes
  431.         dd 0x0  ; upper part of the position address
  432.         dd 0x0  ; number of bytes to read
  433.         dd 0x0  ; pointer to the buffer to write data
  434.         db 0
  435.         dd 0    ; pointer to the filename
  436.  
  437. filepos dd 0
  438. default_filename db '/sys/boardlog.txt',0
  439. ;------------------------------------------------------------------------------
  440. krnl_msg db 'K : '
  441. duk db 'KernUser'
  442.  
  443. ; DATA AREA
  444.  
  445. ; 11,11 > 0,-1
  446. ; 5,11  > 0,-1
  447. if lang eq ru
  448.  title  db '„®áª  ®â« ¤ª¨ ¨ á®®¡é¥­¨©',0
  449. else if lang eq it
  450.  title  db 'Notifiche e informazioni generiche per il debug',0
  451. else if lang eq ge
  452.  title  db 'Allgemeines debug- & nachrichtenboard',0
  453. else
  454.  title  db 'General debug & message board',0
  455. end if
  456. krnl_cnt        dd 0
  457. vmode           dd 1
  458. targ            dd text2
  459.  
  460. my_name            db 'board',0
  461. my_name_size   = $-my_name
  462. process_count  dd 0x0
  463. pid_tid            dd 0x0
  464. ;------------------------------------------------------------------------------
  465. I_END:
  466. ;------------------------------------------------------------------------------
  467. offs    dd ?
  468. flag    rb 1
  469.         rd 2
  470. ;x1pos  dd ?
  471. ;y1pos  dd ?
  472. text1   rb 80*(MAXSTRINGS+1)
  473. tmp1    db ?
  474.         rd 2
  475. ;x2pos  dd ?
  476. ;y2pos  dd ?
  477. text2   rb 80*(MAXSTRINGS+1)
  478. tmp2    db ?
  479. xstart  dd ?
  480.  
  481. sc system_colors
  482.  
  483. i_end:
  484. buffer_length   rb 1
  485. ;------------------------------------------------------------------------------
  486. tmp     rb      256
  487. ;------------------------------------------------------------------------------
  488. filename        rb 256
  489. ;------------------------------------------------------------------------------
  490. align 4
  491. procinfo:
  492.         rb 1024
  493. ;------------------------------------------------------------------------------
  494. align 4
  495. stackbuf        rb 2000h
  496. ;------------------------------------------------------------------------------
  497. mem: