wok view linld/stuff/src/CRTLX.ASM @ rev 19781

mate-control-center; update bdeps
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 22 09:33:32 2017 +0100 (2017-02-22)
parents d90896f9d59e
children
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p8086
10 group DGROUP _TEXT,_DATA,_BSS
11 assume cs:DGROUP,ds:DGROUP
13 segment _DATA byte public use16 'DATA'
15 tazboot_cmd db "tazboot.cmd",0
17 ends _DATA
19 segment _BSS byte public use16 'BSS'
21 ultoabuf db 12 dup (?)
23 ends _BSS
25 segment _TEXT byte public use16 'CODE'
27 ;***************************************************************
28 ;int strcmp(const char* a,const char* b);
29 ;***************************************************************
30 global _strcmp:near
31 proc _strcmp near
33 pop cx ;caller return address
34 pop bx ; a
35 pop ax ; b
36 push ax
37 push bx
38 push cx
39 push si
40 xchg ax,si
41 sub bx,si
42 @@lp:
43 mov al,[si]
44 sub al,[bx+si]
45 jnz @@out
46 lodsb
47 cmp al,0
48 jne @@lp
49 @@out:
50 cbw
51 pop si
52 ret
54 endp _strcmp
57 ;***************************************************************
58 ;char strstr(const char* a,const char* b);
59 ;***************************************************************
60 global _strstr:near
61 proc _strstr near
63 pop ax ;caller return address
64 pop cx ; a
65 pop dx ; b
66 push dx
67 push cx
68 push ax
69 push si
70 @@loop:
71 xor ax,ax
72 mov si,cx
73 cmp [si],al ; *a
74 jz @@end ; return ax = NULL
75 mov bx,dx
76 sub bx,si
77 @@match:
78 or ah,[bx+si] ; *b
79 jz @@found
80 lodsb
81 sub ah,al
82 jz @@match
83 inc cx
84 jmp @@loop
85 @@found:
86 xchg ax,cx
87 @@end:
88 pop si
89 ret
91 endp _strstr
94 macro cpuid
95 db 0fh,0A2h
96 endm
97 ;***************************************************************
98 ;int cpuhaslm(void)
99 ;***************************************************************
100 global _cpuhaslm:near
101 proc _cpuhaslm near
103 pushf
104 ; Check for oldies
105 mov bh, 0F0h
106 push bx ; < 286 : flags[12..15] are forced 1
107 popf ; = 286 : flags[12..15] are forced 0
108 pushf ; > 286 : only flags[15] is forced 0
109 pop dx
110 popf
111 add dh,bh ; NS=386+, NC=286
112 clc
113 js @@bad ;it is a 86/186/286, not a 386+
114 p386
115 pushfd
116 pop dx
117 pop ax
118 mov bl,al
119 xor al,20h ; toggle CPUID feature bit 21
120 push ax
121 push dx
122 popfd
123 pushfd
124 pop dx
125 pop ax
126 xor al,bl ; clear C
127 je @@bad ; CPUID feature bit changed ?
128 mov eax,80000001h ; Extended Processor Info and Feature Bits
129 cpuid
130 shr edx,1+29 ; LM feature bit ?
131 @@bad:
132 p8086
133 sbb ax,ax
134 ret
136 endp _cpuhaslm
139 ;***************************************************************
140 ;char *progname(void)
141 ;***************************************************************
142 global _progname:near
143 proc _progname near
145 push si di es
146 mov ah,30h
147 int 21h
148 cmp al,3
149 jb @@skip
150 xor di,di
151 mov es,[cs:2Ch]
152 mov cx,-1
153 mov ax,di
154 @@loop1:
155 repne
156 scasb
157 scasb
158 jne @@loop1
159 lea si,[di+2]
160 mov bx, si
161 extrn strlen:near
162 call near strlen
163 xchg ax,cx
164 inc cx
165 extrn malloc_or_die:near
166 call near malloc_or_die
167 xchg ax,di
168 push ds
169 push ds
170 push es
171 pop ds
172 pop es
173 push di
174 @@loop2:
175 lodsb
176 stosb
177 or al,al
178 jnz @@loop2
179 pop ax
180 pop ds
181 @@skip:
182 pop es di si
183 ret
185 endp _progname
188 ;***************************************************************
189 ;int chdir(char *path);
190 ;***************************************************************
191 global _chdir:near
192 proc _chdir near
194 pop ax
195 pop dx
196 push dx
197 push ax
198 chdir:
199 stc
200 mov ax,713Bh
201 int 21h
202 jnc @@end
203 mov ah,3Bh
204 int 21h
205 @@end:
206 sbb ax,ax
207 ret
209 endp _chdir
212 ;***************************************************************
213 ;int chdirname(char *path)
214 ;***************************************************************
215 global _chdirname:near
216 proc _chdirname near
218 pop ax
219 pop bx
220 push bx
221 push ax
223 cmp [byte bx+1],3Ah
224 jne @@nodisk
225 mov dl,[bx]
226 or dl,20h
227 sub dl,61h
228 mov ah,0Eh
229 push bx
230 int 21h
231 pop bx
232 inc bx
233 inc bx
234 @@nodisk:
235 mov dx,bx
236 xor cx,cx
237 @@next:
238 mov al,[bx]
239 cmp al,5Ch
240 jne @@tsteos
241 mov cx,bx
242 @@tsteos:
243 inc bx
244 or al,al
245 jnz @@next
246 cbw
247 jcxz @@end
248 mov bx,cx
249 push [word bx]
250 mov [bx],al
251 push bx
252 call chdir
253 pop bx
254 pop [word bx]
255 @@end:
256 ret
258 endp _chdirname
261 ;***************************************************************
262 ;char *ultoa(unsigned long n);
263 ;***************************************************************
264 global _ultoa:near
265 proc _ultoa near
267 pop ax
268 pop cx
269 pop dx
270 push dx
271 push cx
272 push ax ; DX:CX = n
273 push si
274 mov si,10
275 mov bx,offset ultoabuf+11
276 @@loop:
277 dec bx
278 xchg ax,dx
279 xor dx,dx
280 div si ; DX:AX = 0000:hi(n)
281 xchg ax,cx ; CX = hi(n)/10
282 div si ; DX:AX = hi(n)%10:lo(n)
283 xchg ax,cx ; CX = lo(n/10)
284 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
285 add al,'0'
286 mov [bx],al
287 mov ax,cx
288 or ax,dx
289 jnz @@loop
290 xchg ax,bx
291 pop si
292 ret
294 endp _ultoa
297 ;***************************************************************
298 ;unsigned long kver2ul(char *kernel_version);
299 ;***************************************************************
300 global _kver2ul:near
301 proc _kver2ul near
303 pop bx
304 pop ax
305 push ax
306 push bx
307 push bp si di
308 xchg ax,si
309 xor di,di
310 push di
311 push di
312 mov bp,sp
313 inc di
314 inc di
315 mov cl,4
316 @@number:
317 xor ax,ax
318 @@digit:
319 shl al,cl
320 shl ax,cl
321 lodsb
322 sub al,30h
323 cmp al,9
324 jbe @@digit
325 mov [bp+di],ah
326 dec di
327 jns @@number
328 pop ax
329 pop dx
330 pop di si bp
331 kver2ulret:
332 ret
334 endp _kver2ul
337 ;***************************************************************
338 ;void try_default_args();
339 ;***************************************************************
340 global _try_default_args:near
341 proc _try_default_args near
343 mov bx,offset tazboot_cmd
344 extrn open:near
345 call near open
346 jc kver2ulret
347 mov cx,4096
348 extrn _heap_top:word
349 mov di,[_heap_top]
350 push cx
351 extrn read_cmdline:near
352 jmp near read_cmdline ; read_cmdline(ax,di,cx)
354 endp _try_default_args
356 struc isostate ; struct isostate {
357 fd dw ? ; 0 int fd;
358 fileofs dd ? ; 2 unsigned long fileofs;
359 filesize dd ? ; 6 unsigned long filesize;
360 filemod dw ? ;10 unsigned short filemod;
361 filename dw ? ;12 char *filename;
362 dirofs dd ? ;14 unsigned long dirofs;
363 dirsize dd ? ;16 unsigned long dirsize;
364 curdirofs dd ? ;20 unsigned long curdirofs;
365 curdirsize dd ? ;24 unsigned long curdirsize;
366 curpos dd ? ;28 unsigned long curpos;
367 ends ; } isostate;
368 ;***************************************************************
369 ;unsigned long isolseek(unsigned long offset);
370 ;***************************************************************
371 global _isolseek:near
372 proc _isolseek near
374 pop ax
375 pop dx
376 pop cx
377 push cx
378 push dx
379 push ax
380 extrn _isostate:isostate
381 mov bx,[_isostate.fd]
382 extrn lseekset:near
383 jmp near lseekset ; (bx=fd, sz=cx:dx)
385 endp _isolseek
387 ends _TEXT
389 end
391 ;###### END OF FILE ############################################