36918e3217
- Update crt0 - Removed autoloader generation(use libc.def). git-svn-id: svn://kolibrios.org@9666 a494cfbc-eb01-0410-851d-a64ba20cac60
128 lines
2.9 KiB
NASM
128 lines
2.9 KiB
NASM
;
|
|
; 2021, Edited by Coldy
|
|
;
|
|
; This module same as original crt0.asm, but cut:
|
|
; 1. virtual header block (hparams change to __app_params, hpath change to __app_path)
|
|
; 2. init heap of memory - not needed because 68.18 (68.19) init heap implicitly
|
|
; (it is does dll.obj)
|
|
; 3. loader (he lives in dll.obj)
|
|
;
|
|
|
|
format ELF
|
|
section '.text' executable
|
|
public start
|
|
public start as '_start'
|
|
|
|
extrn main
|
|
|
|
include '../../../../../../proc32.inc'
|
|
include '../../../../../../macros.inc'
|
|
__DEBUG__ = 0
|
|
|
|
__app_params equ 0x1C ; Pointer to program arguments
|
|
;__app_path equ 0x20 ; Pointer to program path
|
|
|
|
start:
|
|
;DEBUGF 'Start programm\n'
|
|
|
|
mov [argc], 0
|
|
mov eax, [__app_params]
|
|
test eax, eax
|
|
jz .without_path
|
|
mov eax, path
|
|
cmp word ptr eax, 32fh ; '/#3' UTF8
|
|
jne .without_path
|
|
mov word ptr eax, 12fh ; '/#1' fix to CP866
|
|
.without_path:
|
|
mov esi, eax
|
|
call push_param
|
|
; retrieving parameters
|
|
mov esi, params
|
|
xor edx, edx ; dl - èä¸ò ïàðàìåòð(1) èëè ðàçäåëèòåëè(0)
|
|
; dh - ñèìâîë ñ êîòîðîãî íà÷àëñÿ ïàðàìåòð (1 êàâû÷êè, 0 îñòàëüíîå)
|
|
mov ecx, 1 ; cl = 1
|
|
; ch = 0 ïðîñòî íîëü
|
|
.parse:
|
|
lodsb
|
|
test al, al
|
|
jz .run
|
|
test dl, dl
|
|
jnz .findendparam
|
|
;{åñëè áûë ðàçäåëèòåëü
|
|
cmp al, ' '
|
|
jz .parse ;çàãðóæåí ïðîáåë, ãðóçèì ñëåäóþùèé ñèìâîë
|
|
mov dl, cl ;íà÷èíàåòñÿ ïàðàìåòð
|
|
cmp al, '"'
|
|
jz @f ;çàãðóæåíû êàâû÷êè
|
|
mov dh, ch ;ïàðàìåòð áåç êàâû÷åê
|
|
dec esi
|
|
call push_param
|
|
inc esi
|
|
jmp .parse
|
|
|
|
@@:
|
|
mov dh, cl ;ïàðàìåòð â êàâû÷åêàõ
|
|
call push_param ;åñëè íå ïðîáåë çíà÷èò íà÷èíàåòñÿ êàêîé òî ïàðàìåòð
|
|
jmp .parse ;åñëè áûë ðàçäåëèòåëü}
|
|
|
|
.findendparam:
|
|
test dh, dh
|
|
jz @f ; áåç êàâû÷åê
|
|
cmp al, '"'
|
|
jz .clear
|
|
jmp .parse
|
|
@@:
|
|
cmp al, ' '
|
|
jnz .parse
|
|
|
|
.clear:
|
|
lea ebx, [esi - 1]
|
|
mov [ebx], ch
|
|
mov dl, ch
|
|
jmp .parse
|
|
|
|
.run:
|
|
push argv
|
|
push [argc]
|
|
call main
|
|
.exit:
|
|
xor eax,eax
|
|
dec eax
|
|
int 0x40
|
|
dd -1
|
|
.crash:
|
|
jmp .exit
|
|
;============================
|
|
push_param:
|
|
;============================
|
|
;parameters
|
|
; esi - pointer
|
|
;description
|
|
; procedure increase argc
|
|
; and add pointer to array argv
|
|
; procedure changes ebx
|
|
mov ebx, [argc]
|
|
cmp ebx, max_parameters
|
|
jae .dont_add
|
|
mov [argv+4*ebx], esi
|
|
inc [argc]
|
|
.dont_add:
|
|
ret
|
|
|
|
|
|
;==============================
|
|
public argc as '__argc'
|
|
public params as '__argv'
|
|
public path as '__path'
|
|
|
|
section '.bss'
|
|
buf_len = 0x400
|
|
max_parameters=0x20
|
|
argc rd 1
|
|
argv rd max_parameters
|
|
path rb buf_len
|
|
params rb buf_len
|
|
|
|
;section '.data'
|
|
;include_debug_strings ; ALWAYS present in data section
|