Subversion Repositories Kolibri OS

Rev

Rev 6839 | 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
 
7127 dunkaist 46
include 'proc32.inc'
47
include 'macros.inc'
48
include 'libio.inc'
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
3628 fedesco 112
 
1236 vkos 113
	test eax, eax				;; No console
1042 vkos 114
	je .ok
3628 fedesco 115
 
1236 vkos 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
3628 fedesco 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
3628 fedesco 268
 
1262 vkos 269
.register:
270
	mov dword [IPC_area], buff
271
	call IPC_init
272
; 	jnz .close
3628 fedesco 273
 
1262 vkos 274
	mov dword [thread_find_buff], another_buff
3628 fedesco 275
 
1262 vkos 276
	call kobra_register
3628 fedesco 277
 
1262 vkos 278
	test eax, eax
279
	jnz .close
3628 fedesco 280
 
1262 vkos 281
	;; Prepare message
282
	mov dword [kobra_message], KOBRA_MESSAGE_LAUNCH_STATE
3628 fedesco 283
 
1262 vkos 284
	mov eax, dword [tid]
285
	mov dword [kobra_message+4], eax
3628 fedesco 286
 
1262 vkos 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
3628 fedesco 348
if lang eq it
349
	message_dbg_not_found:
350
		db '%s non trovato', 10, 0
1042 vkos 351
 
3628 fedesco 352
	message_error:
353
		db 'File (%s) non trovato!', 0
1042 vkos 354
 
3628 fedesco 355
	message_ok:
356
		db '%s caricato correttamente. PID: %d (0x%X)', 0
357
else
358
	message_dbg_not_found:
359
		db '%s not found', 10, 0
1042 vkos 360
 
3628 fedesco 361
	message_error:
362
		db 'File (%s) not found!', 0
363
 
364
	message_ok:
365
		db '%s loaded succesfully. PID: %d (0x%X)', 0
366
end if
1236 vkos 367
;; Configuration path
1042 vkos 368
etc_cfg:
369
	db '/sys/etc/'
370
cfg_name:
371
	db 'launch'
372
cfg_ext:
373
	db '.cfg', 0
374
 
1262 vkos 375
;; Strings in config file
1042 vkos 376
cfg_main:
377
	db 'main', 0
378
cfg_path:
379
	db 'path', 0
380
cfg_debug:
381
	db 'debug', 0
382
cfg_level:
383
	db 'level', 0
1262 vkos 384
cfg_kobra:
385
	db 'kobra', 0
386
cfg_use:
387
	db 'use', 0
1042 vkos 388
 
1236 vkos 389
;; List of debug modes for parsing debug option
390
debug_strings:
1042 vkos 391
	dd debug_no
392
	dd debug_console
393
	dd 0
394
 
395
debug_no:
396
	db 'no', 0
397
debug_console:
398
	db 'console', 0
399
 
1262 vkos 400
;; Empty string
401
empty_str:
402
	db 0
1042 vkos 403
 
1262 vkos 404
kobra_group_launch_reactive:
405
	db 'launch_reactive', 0
406
 
407
;;--------------------------------------------------------------------------------------------------
408
;; Configuration options
1042 vkos 409
debug_level:
1262 vkos 410
	db 0
1042 vkos 411
 
1262 vkos 412
; debug_kobra:
413
; 	db 0
414
 
415
;; debug option (bool)
416
debug_option:
1236 vkos 417
	db 0
418
 
1262 vkos 419
kobra_use:
420
	db 0
421
 
422
;;--------------------------------------------------------------------------------------------------
423
tid:
424
	dd 0
425
 
6834 dunkaist 426
struct FileInfoRun
427
  Function     dd 7
428
  Flags        dd ?
429
  Arguments    dd 0
430
  Reserved0    dd ?
431
  Reserved1    dd ?
432
  union
433
    FileName   rb 1024
434
    struct
435
      Zero       db 0
436
      FileNameP  dd ?
437
    ends
438
  ends
439
ends
440
 
1042 vkos 441
LaunchStruct FileInfoRun
442
 
443
args: db 0
444
APP_END:
445
rb 255
446
 
447
prog_args:
448
	rd 1
449
path:
450
	rb 1024
451
 
1236 vkos 452
;; Search path will be here
1042 vkos 453
search_path:
454
	rb PATH_MAX_LEN
455
 
1236 vkos 456
;; Buffer
1042 vkos 457
buff:
458
	rb BUFF_SIZE
459
 
1262 vkos 460
another_buff:
461
	rb 0x1000
462
 
463
kobra_message:
464
	rb 0x100
465
 
1042 vkos 466
rb 0x1000	;; 4 Kb stack
467
APP_STACK:
468
MEM_END: