Subversion Repositories Kolibri OS

Rev

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