wok view linld/stuff/src/_BEG.ASM @ rev 19538

linld: add 'linld <kernel> <cmdline>' syntax
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 02 12:37:59 2016 +0100 (2016-12-02)
parents bb42796dcd3b
children 31c5cbbd9380
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p386
10 group DGROUP _TEXT,_DATA,_BSS
11 assume cs:DGROUP,ds:DGROUP
13 segment _TEXT byte public use16 'CODE'
15 org 100h
16 global _text_start:byte
17 label _text_start byte
18 extrn _bss_end
19 ;***************************************************************
20 ; clear bss
21 ;***************************************************************
22 xor ax,ax
23 mov di,offset _bss_start
24 clearbss:
25 mov [di],al
26 inc di
27 cmp di,sp ; clear bss + heap
28 jbe clearbss
29 mov di,offset _bss_end
30 ;***************************************************************
31 ; build argv & argc
32 ;***************************************************************
33 ; push ax ; envp (int 20h do it for us)
34 ;mov [word di],ax ; argv[0] = 0
35 mov si,80h
36 cld
37 lodsb
38 cmp al,7Eh
39 jbe alok
40 mov al,7Eh
41 alok:
42 xchg ax,bx
43 mov [bx+si],bh ; set eos
44 argbuild:
45 mov bx,2 ; argc * 2
46 argeos:
47 mov dl,1 ; look for a start of string
48 mov [byte si-1],bh ; mark eos
49 mov ah,20h ; space will be eos
50 arglp:
51 lodsb
52 cmp al,0h
53 je argdone
54 cmp al,20h
55 jb argeos
56 cmp al,ah
57 je argeos
58 cmp al,27h
59 je isargstr
60 cmp al,22h
61 je isargstr
62 or dl,dl
63 je arglp ; not start of string
64 dec si
65 jmp newarg
66 isargstr:
67 mov ah,al ; expected eos
68 newarg:
69 mov [word bx+di],si ; argv[argc++] = si
70 inc bx
71 inc bx
72 dec dx
73 jmp arglp
74 argdone:
75 ;mov [word bx+di],0 ; argv[argc] = 0
76 lea si,[bx+di+2]
77 extrn _heap_top:word
78 mov [_heap_top],si
79 push di ; argv
80 shr bx,1
81 push bx ; argc
82 ifndef filearg
83 mov bx,[di+2] ; argv[1]
84 cmp [byte bx],'@'
85 jne argend
86 inc bx ; al=0 RDONLY
87 extrn open:near
88 call near open
89 jc argend
90 pop bx ; trash argc, argv >> 1Kb !
91 push di
92 push ax
93 extrn _read:near
94 call near _read
95 pop bx ; fd for close
96 pop si ; si=buffer=argv
97 add di,ax
98 pop ax ; trash sizemax=argv
99 extrn close:near
100 call near close
101 jmp argbuild
102 argend:
103 endif
105 ;***************************************************************
106 extrn _is_vm86:near
107 call _is_vm86 ; load_image needs that
109 ;***************************************************************
110 extrn _main:near
111 call _main
113 ;***************************************************************
114 global exit:near
115 exit:
116 mov ah,4Ch
117 int 21h
118 ends _TEXT
120 segment _DATA byte public use16 'DATA'
121 global _data_start:byte
122 label _data_start byte
123 ends _DATA
125 segment _BSS byte public use16 'BSS'
126 global _bss_start:byte
127 label _bss_start byte
128 ends _BSS
130 end _text_start
132 ;###### END OF FILE ############################################