Subversion Repositories Kolibri OS

Rev

Rev 4095 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ;   LAUNCHER - startup of programs
  4. ;
  5. ;   Compile with FASM 1.52 or newer
  6. ;
  7. ;-----------------------------------------------------------------------------
  8. ; last update:  02/03/2014
  9. ; changed by:   Marat Zakiyanov aka Mario79, aka Mario
  10. ; changes:      Reducing the consumption of RAM, 4 KB instead of 32 KB.
  11. ;               Output to BOARD information about running applications.
  12. ;               Cleaning of the source code.
  13. ; notice:       Only 2 KB of memory for AUTORUN.DAT - be careful!
  14. ;-----------------------------------------------------------------------------
  15.         use32
  16.         org 0x0
  17.         db 'MENUET01'   ; 8 byte id
  18.         dd 0x01         ; header version
  19.         dd START        ; start of code
  20.         dd IM_END       ; size of image
  21.         dd I_END        ; memory for app
  22.         dd stack_top    ; esp
  23.         dd 0x0          ; I_Param
  24.         dd 0x0          ; I_Icon
  25. ;-----------------------------------------------------------------------------
  26. include "../../../macros.inc"
  27.  
  28. define __DEBUG__ 1
  29. define __DEBUG_LEVEL__ 1
  30. include "../../../debug-fdo.inc"
  31. ;-----------------------------------------------------------------------------
  32. START:                           ; start of execution
  33.         mcall   70,autorun_dat_info     ; load AUTORUN.DAT
  34.         add     ebx,file_data
  35.         mov     [fileend],ebx
  36. ;-----------------------------------------------------------------------------
  37. ; this cycle does not contain an obvious exit condition,
  38. ; but auxiliary procedures (like "get_string") will exit
  39. ; at EOF
  40. start_program:
  41.         call    skip_spaces
  42.         cmp     al,byte '#'
  43.         jz      skip_this_string
  44.         call    clear_strings
  45.         mov     edi,program
  46.         call    get_string
  47.         mov     edi,parameters
  48.         call    get_string
  49.         call    get_number
  50.         call    run_program
  51. ;--------------------------------------
  52. skip_this_string:
  53.         call    next_line
  54.         jmp     start_program
  55. ;-----------------------------------------------------------------------------
  56. exit:
  57.         or      eax,-1
  58.         mcall
  59. ;-----------------------------------------------------------------------------
  60. run_program:     ; time to delay in eax
  61.         DEBUGF 1, "Launch: %s Parameter: %s\n",program,parameters
  62.         push    eax
  63.         mcall   70,start_info
  64.         pop     ebx
  65. ; if delay is negative, wait for termination
  66. ;   of the spawned process
  67.         test    ebx,ebx
  68.         js      must_wait_for_termination
  69. ; otherwise, simply wait
  70.         mcall   5
  71.         ret
  72. ;-----------------------------------------------------------------------------
  73. must_wait_for_termination:
  74.         mov     esi,eax  ; save slot for the future
  75. ; get process slot
  76.         mov     ecx,eax
  77.         mcall   18,21
  78. ; if an error has occured, exit
  79.         test    eax,eax
  80.         jz      child_exited
  81.  
  82.         mov     ecx,eax
  83. ;--------------------------------------
  84. wait_for_termination:
  85.         mcall   5,1
  86.         mov     ebx, processinfo
  87.         mcall   9
  88.         cmp     [ebx+50],word 9 ; the slot was freed?
  89.         jz      child_exited
  90.  
  91.         cmp     [ebx+30],dword esi ; the slot is still occupied by our child?
  92.         jz      wait_for_termination
  93. ;--------------------------------------
  94. child_exited:
  95.         ret
  96. ;-----------------------------------------------------------------------------
  97. clear_strings:   ; clears buffers
  98.         pushad
  99.         mov     ecx,60+1
  100.         mov     edi,program
  101.         xor     al,al
  102.         rep     stosb
  103.         mov     ecx,60+1
  104.         mov     edi,parameters
  105.         rep     stosb
  106.         popad
  107.         ret
  108. ;-----------------------------------------------------------------------------
  109. get_string: ; pointer to destination buffer in edi
  110.         pushad
  111.         call    skip_spaces
  112.         mov     esi,[position]
  113.         add     esi,file_data
  114.         cmp     [esi],byte '"'
  115.         jz      .quoted
  116. ;--------------------------------------
  117. .start:
  118.         cmp     esi,[fileend]
  119.         jae     exit
  120.  
  121.         lodsb
  122.         cmp     al,byte ' '
  123.         jbe     .finish
  124.  
  125.         stosb
  126.         inc     dword [position]
  127.         jmp     .start
  128. ;--------------------------------------
  129. .finish:
  130.         popad
  131.         ret
  132. ;--------------------------------------
  133. .quoted:
  134.         inc     esi
  135.         inc     dword [position]
  136. ;--------------------------------------
  137. .quoted.start:
  138.         cmp     esi,[fileend]
  139.         jae     exit
  140.  
  141.         lodsb
  142.         inc     dword [position]
  143.         cmp     al,byte '"'
  144.         je      .finish
  145.  
  146.         stosb
  147.         jmp     .quoted.start
  148. ;-----------------------------------------------------------------------------
  149. get_number:
  150.         push    ebx esi
  151.         call    skip_spaces
  152.         mov     esi,[position]
  153.         add     esi,file_data
  154.         xor     eax,eax
  155.         cmp     [esi],byte '-'
  156.         jnz     @f
  157.  
  158.         inc     eax
  159.         inc     esi
  160.         inc     dword [position]
  161. ;--------------------------------------
  162. @@:
  163.         push    eax
  164.         xor     eax,eax
  165.         xor     ebx,ebx
  166. ;--------------------------------------
  167. .start:
  168.         cmp     esi,[fileend]
  169.         jae     .finish
  170.  
  171.         lodsb
  172.         sub     al,byte '0'
  173.         cmp     al,9
  174.         ja      .finish
  175.  
  176.         lea     ebx,[ebx*4+ebx]
  177.         lea     ebx,[ebx*2+eax]
  178.         inc     dword [position]
  179.         jmp     .start
  180. ;--------------------------------------
  181. .finish:
  182.         pop     eax
  183.         dec     eax
  184.         jnz     @f
  185.  
  186.         neg     ebx
  187. ;--------------------------------------
  188. @@:
  189.         mov     eax,ebx
  190.         pop     esi ebx
  191.         ret
  192. ;-----------------------------------------------------------------------------
  193. skip_spaces:
  194.         push    esi
  195.         xor     eax,eax
  196.         mov     esi,[position]
  197.         add     esi,file_data
  198. ;--------------------------------------
  199. .start:
  200.         cmp     esi,[fileend]
  201.         jae     .finish
  202.  
  203.         lodsb
  204.         cmp     al,byte ' '
  205.         ja      .finish
  206.  
  207.         inc     dword [position]
  208.         jmp     .start
  209. ;--------------------------------------
  210. .finish:
  211.         pop     esi
  212.         ret
  213. ;-----------------------------------------------------------------------------
  214. next_line:
  215.         mov     esi,[position]
  216.         add     esi,file_data
  217. ;--------------------------------------
  218. .start:
  219.         cmp     esi,[fileend]
  220.         jae     exit
  221.  
  222.         lodsb
  223.         cmp     al,13
  224.         je      .finish
  225.  
  226.         cmp     al,10
  227.         je      .finish
  228.  
  229.         inc     dword [position]
  230.         jmp     .start
  231. ;--------------------------------------
  232. .finish:
  233.         inc     dword [position]
  234.         cmp     esi,[fileend]
  235.         jae     exit
  236.  
  237.         lodsb
  238.         cmp     al,13
  239.         je      .finish
  240.  
  241.         cmp     al,10
  242.         je      .finish
  243.  
  244.         ret
  245. ;-----------------------------------------------------------------------------
  246. ; DATA:
  247. ;-----------------------------------------------------------------------------
  248. include_debug_strings
  249. ;-----------------------------------------------------------------------------
  250. autorun_dat_info:       ; AUTORUN.DAT
  251.         .mode           dd 0            ; read file
  252.         .start_block    dd 0            ; block to read
  253.                         dd 0
  254.         .blocks         dd 4*512       ; 2 Kb max for AUTORUN.DAT
  255.         .address        dd file_data
  256.         db "/SYS/SETTINGS/AUTORUN.DAT",0
  257. ;-----------------------------------------------------------------------------
  258. start_info:
  259.         .mode   dd 7
  260.                 dd 0
  261.         .params dd parameters
  262.                 dd 0
  263.                 dd 0
  264.         .path:
  265. ;-----------------------------------------------------------------------------
  266. IM_END:
  267. ;-----------------------------------------------------------------------------
  268. align 4
  269. processinfo:
  270. ;-----------------------------------------------------------------------------
  271. program:
  272.         rb 61   ; 60 + [0] char
  273. ;-----------------------------------------------------------------------------
  274. parameters:
  275.         rb 61
  276. ;-----------------------------------------------------------------------------
  277.         rb 1024-61*2
  278. ;-----------------------------------------------------------------------------
  279. position:
  280.         rd 1    ; position in file
  281. ;-----------------------------------------------------------------------------
  282. fileend:
  283.         rd 1
  284. ;-----------------------------------------------------------------------------
  285. align 4
  286. file_data:
  287.         rb 4*512 ; 2 Kb for AUTORUN.DAT
  288. ;-----------------------------------------------------------------------------
  289. align 4
  290.         rb 256
  291. stack_top:
  292. ;-----------------------------------------------------------------------------
  293. I_END:
  294. ;-----------------------------------------------------------------------------
  295.