Subversion Repositories Kolibri OS

Rev

Rev 1293 | Rev 3628 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1042 vkos 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;  Copyright (C) Vasiliy Kosenko (vkos), 2009                                                    ;;
3
;;  Launch is free software: you can redistribute it and/or modify it under the terms of the GNU  ;;
1262 vkos 4
;;  General Public License as published by the Free Software Foundation, either version 3         ;;
1042 vkos 5
;;  of the License, or (at your option) any later version.                                        ;;
6
;;                                                                                                ;;
7
;;  Launch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without   ;;
8
;;  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
9
;;  General Public License for more details.                                                      ;;
10
;;                                                                                                ;;
11
;;  You should have received a copy of the GNU General Public License along with Launch.          ;;
12
;;  If not, see .                                                   ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
;;  Launch finds program in search dirictories and runs it.                                       ;;
17
;;  For more details see readme.txt                                                               ;;
18
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
 
1236 vkos 20
format binary
21
 
1042 vkos 22
APP_NAME fix 'Launch'
1293 vkos 23
APP_VERSION fix '0.1.80.1'
1042 vkos 24
 
25
use32
26
org 0x0
27
 
28
db 'MENUET01'
29
dd 0x01
30
dd START
31
dd APP_END
32
dd MEM_END
33
dd APP_STACK
34
dd args
35
dd path
36
 
1236 vkos 37
define DEBUG_NO 0
38
define DEBUG_CONSOLE 1
39
define DEBUG_BOARD 2			;; Not used now
40
 
1042 vkos 41
define PATH_MAX_LEN 1024
42
define DEBUG_MAX_LEN 8
1236 vkos 43
define DEBUG_DEFAULT 0
1042 vkos 44
define BUFF_SIZE 1024
45
 
1262 vkos 46
include 'proc32.inc'
47
include 'macros.inc'
1042 vkos 48
include 'libio.inc'
3014 dunkaist 49
include '../../../dll.inc'
1042 vkos 50
 
1262 vkos 51
purge mov
52
 
53
include 'thread.inc'
54
include 'ipc.inc'
55
include 'kobra.inc'
56
 
1236 vkos 57
;;--------------------------------------------------------------------------------------------------
58
;; Basic initialization
1042 vkos 59
START:
60
	;; Initialize process heap
61
	mcall 68,11
62
	test eax, eax
63
	jz exit
64
 
65
	;; Import modules
66
	stdcall dll.Load,importTable
67
	test eax, eax
68
	jnz exit
69
 
1236 vkos 70
;;--------------------------------------------------------------------------------------------------
71
;; Reading config
72
read_ini_path:													;; Read search path
1042 vkos 73
	;; First read config in /sys/etc
74
	invoke ini.get_str, etc_cfg, cfg_main, cfg_path, search_path, PATH_MAX_LEN, empty_str
75
 
76
	;; Next, read config from current directory
77
	;; Find end of path string
78
.find_path_eol:
79
	mov edi, path
80
	mov ecx, PATH_MAX_LEN
81
	xor al, al
82
	cld
83
	repne scasb
84
 
85
	;; Append ext to run path (NOTE: this work only when config file has name .cfg and ext size is dword)
86
	mov eax, dword [cfg_ext]
87
	dec edi
88
	mov dword [edi], eax
89
	mov byte [edi+5], 0
90
 
91
	;; Currently there is no checking for repeating pathes, so we should only concatenate two strings
92
	;; So we need to find end of current search_path string
93
.find_search_eol:
94
	mov edi, search_path
95
	mov ecx, PATH_MAX_LEN
96
	xor al, al
97
	;cld
98
	repne scasb
99
	dec edi
100
 
101
	;; Now we need to correct buffer length
102
	mov eax, path+PATH_MAX_LEN
103
	sub eax, edi
104
	;; Read ini
105
	invoke ini.get_str, path, cfg_main, cfg_path, edi, PATH_MAX_LEN, empty_str
106
 
1236 vkos 107
read_ini_debug:												;; Read debug options
1042 vkos 108
	;; Read debug options from config files
1236 vkos 109
	invoke ini.get_option_str, etc_cfg, cfg_debug, cfg_debug, debug_strings, DEBUG_MAX_LEN, DEBUG_DEFAULT
110
	invoke ini.get_option_str, path, cfg_debug, cfg_debug, debug_strings, DEBUG_MAX_LEN, eax
111
	mov [debug_option], eax
112
 
113
	test eax, eax				;; No console
1042 vkos 114
	je .ok
1236 vkos 115
 
116
	jmp .con_init
1042 vkos 117
 
1236 vkos 118
.console_err:
1262 vkos 119
	mov byte [debug_option], 0
1042 vkos 120
	jmp .ok
121
 
122
.con_init:
123
	stdcall dll.Load, consoleImport
124
	test eax, eax
1236 vkos 125
	jnz .console_err
126
	invoke con.init, -1, -1, -1, -1, window_title
1042 vkos 127
 
128
.read_level:
129
	invoke ini.get_int, etc_cfg, cfg_debug, cfg_level, 0
130
	invoke ini.get_int, path, cfg_debug, cfg_level, eax
1262 vkos 131
	mov byte [debug_level], al
1042 vkos 132
.ok:
133
 
1262 vkos 134
read_ini_kobra:
135
	invoke ini.get_bool, etc_cfg, cfg_kobra, cfg_use, 0
136
	invoke ini.get_bool, path, cfg_kobra, cfg_use, eax
1236 vkos 137
 
1262 vkos 138
	mov byte [kobra_use], al
1236 vkos 139
 
140
;;--------------------------------------------------------------------------------------------------
141
;; Parse command line options
1042 vkos 142
parse_args:
143
	;; Now parse command line arguments
144
	;; TODO: use optparse library
1236 vkos 145
	;; Currently the only argument to parse is program name with its' arguments
1042 vkos 146
 
147
.skip_spaces:
148
	mov ecx, -1
149
	mov edi, args
150
	mov al, ' '
1050 vkos 151
	xor bl, bl
1042 vkos 152
	;cld
153
	repe scasb
154
 
155
	push edi
156
 
157
	mov ecx, -1
1050 vkos 158
@@:
159
	scasb
160
	je @f
161
	xchg al, bl
162
	dec edi
163
	scasb
164
	jne @b
165
@@:
1042 vkos 166
	mov dword [prog_args], edi
167
 
168
	pop edi
169
	dec edi
170
	;; Now edi = program name
171
 
1236 vkos 172
;;--------------------------------------------------------------------------------------------------
173
;; Finding file
1042 vkos 174
search_file:
175
	push edi
176
	mov esi, search_path
177
	xchg esi, [esp]
178
.loop:
179
	or dl, dl
180
	je .prn_dbg
181
	xor dl, dl
182
	jmp .prn_end
183
.prn_dbg:
184
	push eax
185
	mov al, byte [debug_option]
1236 vkos 186
;	dec al
1042 vkos 187
	test al, al
188
	je .prn_stp
1262 vkos 189
	mov al, byte [debug_level]
190
	or al, al
1042 vkos 191
	je .prn_stp
1262 vkos 192
	dec al
193
	or al, al
1042 vkos 194
	je .prn_1
195
.prn_1:
196
	cinvoke con.printf, message_dbg_not_found, buff
197
 
198
.prn_stp:
199
	pop eax
200
.prn_end:
201
	xor eax, eax					;; When we check is proramme launched we are checking for eax
202
	xchg esi, [esp]
203
	mov edi, buff
204
.copy_path:
205
	lodsb
206
	cmp al, ';'
207
	je .copy_file
208
	or al, al
209
	je exit
210
	stosb
211
	jmp .copy_path
212
 
213
.copy_file:
214
	xchg esi, [esp]
215
	push esi
216
.cp_file_loop:
217
	lodsb
218
	or al, al
219
	je .copy_end
220
	cmp al, ' '
221
	je .copy_end
222
	stosb
223
	jmp .cp_file_loop
224
 
225
.copy_end:
226
	pop esi
227
	xor al, al
228
	stosb
229
 
230
	;; Try to launch
231
 
232
	mov dword [LaunchStruct.Function], 7
233
	push dword [prog_args]
234
	pop dword [LaunchStruct.Arguments]
235
	mov dword [LaunchStruct.Flags], 0
236
	mov dword [LaunchStruct.Zero], 0
237
	mov dword [LaunchStruct.FileNameP], buff
238
	mcall 70, LaunchStruct
239
	cmp eax, 0
240
	jl .loop
241
 
1236 vkos 242
;;--------------------------------------------------------------------------------------------------
243
;; Exit
1042 vkos 244
exit:
1262 vkos 245
	mov dword [tid], eax
1042 vkos 246
	;; If console is present we should write some info
247
	mov al, byte [debug_option]
1236 vkos 248
	cmp al, DEBUG_CONSOLE
1262 vkos 249
	jne .kobra
1042 vkos 250
 
251
.write_console:
1262 vkos 252
	mov eax, dword [tid]
1042 vkos 253
	test eax, eax
254
	jz .write_error
255
.write_launched:
256
	cinvoke con.printf, message_ok, buff, eax, eax
257
	jmp .wr_end
258
.write_error:
259
	pop edi
260
	cinvoke con.printf, message_error, edi
261
.wr_end:
262
	invoke con.exit, 0
263
 
1262 vkos 264
.kobra:
265
	mov al, byte [kobra_use]
266
	test al, al
267
	je .close
268
 
269
.register:
270
	mov dword [IPC_area], buff
271
	call IPC_init
272
; 	jnz .close
273
 
274
	mov dword [thread_find_buff], another_buff
275
 
276
	call kobra_register
277
 
278
	test eax, eax
279
	jnz .close
280
 
281
	;; Prepare message
282
	mov dword [kobra_message], KOBRA_MESSAGE_LAUNCH_STATE
283
 
284
	mov eax, dword [tid]
285
	mov dword [kobra_message+4], eax
286
 
287
.kobra_send:
288
	stdcall kobra_send_message, kobra_group_launch_reactive, kobra_message, 8
289
 
1236 vkos 290
.close:
291
	mcall -1
292
 
293
;; End of code
294
;;--------------------------------------------------------------------------------------------------
295
 
1262 vkos 296
;;--------------------------------------------------------------------------------------------------
297
;; Imports
1042 vkos 298
align 16
299
importTable:
1236 vkos 300
 
1293 vkos 301
library libini, 'libconfig.obj' ;,                      \
1042 vkos 302
;        libio, 'libio.obj',                            \
303
 
304
import	libini, \
1236 vkos 305
	ini.get_str        ,'ini_get_str', \
306
\;        ini.set_str      ,'ini_set_str', \
307
	ini.get_int        ,'ini_get_int', \
308
\;        ini.set_int      ,'ini_set_int', \
309
\;        ini.get_color    ,'ini_get_color', \
310
\;        ini.set_color    ,'ini_set_color', \
1262 vkos 311
	ini.get_option_str ,'ini_get_option_str', \
312
	ini.get_bool       ,'ini_get_bool';,\
1042 vkos 313
 
314
;import  libio, \
1236 vkos 315
;        file_find_first,'file_find_first', \
316
;        file_find_next ,'file_find_next', \
317
;        file_find_close,'file_find_close', \
318
;        file_size      ,'file_size', \
319
;        file_open      ,'file_open', \
320
;        file_read      ,'file_read', \
321
;        file_write     ,'file_write', \
322
;        file_seek      ,'file_seek', \
323
;        file_tell      ,'file_tell', \
324
;        file_eof?      ,'file_eof?', \
325
;        file_truncate  ,'file_truncate', \
326
;        file_close     ,'file_close'
1042 vkos 327
 
328
consoleImport:
329
library 						\
330
	conlib, 'console.obj'
331
 
1236 vkos 332
import conlib,\
333
	con.init,	  'con_init',\
334
	con.exit,	  'con_exit',\
335
	con.printf,	  'con_printf' ;,\
336
;        con.write_asciiz, 'con_write_asciiz'
1042 vkos 337
 
1262 vkos 338
;;--------------------------------------------------------------------------------------------------
339
;; Data
1042 vkos 340
align 16
341
APP_DATA:
342
 
1236 vkos 343
;; Window title
344
window_title:
1042 vkos 345
	db APP_NAME, ' ', APP_VERSION, 0
346
 
1236 vkos 347
;; Messages
1042 vkos 348
message_dbg_not_found:
349
	db '%s not found', 10, 0
350
 
351
message_error:
352
	db 'File (%s) not found!', 0
353
 
354
message_ok:
1262 vkos 355
	db '%s loaded succesfully. PID: %d (0x%X)', 0
1042 vkos 356
 
1236 vkos 357
;; Configuration path
1042 vkos 358
etc_cfg:
359
	db '/sys/etc/'
360
cfg_name:
361
	db 'launch'
362
cfg_ext:
363
	db '.cfg', 0
364
 
1262 vkos 365
;; Strings in config file
1042 vkos 366
cfg_main:
367
	db 'main', 0
368
cfg_path:
369
	db 'path', 0
370
cfg_debug:
371
	db 'debug', 0
372
cfg_level:
373
	db 'level', 0
1262 vkos 374
cfg_kobra:
375
	db 'kobra', 0
376
cfg_use:
377
	db 'use', 0
1042 vkos 378
 
1236 vkos 379
;; List of debug modes for parsing debug option
380
debug_strings:
1042 vkos 381
	dd debug_no
382
	dd debug_console
383
	dd 0
384
 
385
debug_no:
386
	db 'no', 0
387
debug_console:
388
	db 'console', 0
389
 
1262 vkos 390
;; Empty string
391
empty_str:
392
	db 0
1042 vkos 393
 
1262 vkos 394
kobra_group_launch_reactive:
395
	db 'launch_reactive', 0
396
 
397
;;--------------------------------------------------------------------------------------------------
398
;; Configuration options
1042 vkos 399
debug_level:
1262 vkos 400
	db 0
1042 vkos 401
 
1262 vkos 402
; debug_kobra:
403
; 	db 0
404
 
405
;; debug option (bool)
406
debug_option:
1236 vkos 407
	db 0
408
 
1262 vkos 409
kobra_use:
410
	db 0
411
 
412
;;--------------------------------------------------------------------------------------------------
413
tid:
414
	dd 0
415
 
1042 vkos 416
LaunchStruct FileInfoRun
417
 
418
args: db 0
419
APP_END:
420
rb 255
421
 
422
prog_args:
423
	rd 1
424
path:
425
	rb 1024
426
 
1236 vkos 427
;; Search path will be here
1042 vkos 428
search_path:
429
	rb PATH_MAX_LEN
430
 
1236 vkos 431
;; Buffer
1042 vkos 432
buff:
433
	rb BUFF_SIZE
434
 
1262 vkos 435
another_buff:
436
	rb 0x1000
437
 
438
kobra_message:
439
	rb 0x100
440
 
1042 vkos 441
rb 0x1000	;; 4 Kb stack
442
APP_STACK:
443
MEM_END: