Subversion Repositories Kolibri OS

Rev

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