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

linld: some fixes for strtoul
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 16 10:15:15 2017 +0100 (2017-01-16)
parents e428345df29a
children 76087975885f
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 _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 ;***************************************************************
95 ;int cpuhaslm(void)
96 ;***************************************************************
97 global _cpuhaslm:near
98 proc _cpuhaslm near
100 pushf
101 ; Check for oldies
102 mov bh, 0F0h
103 push bx ; < 286 : flags[12..15] are forced 1
104 popf ; = 286 : flags[12..15] are forced 0
105 pushf ; > 286 : only flags[15] is forced 0
106 pop dx
107 popf
108 add dh,bh ; NS=386+, NC=286
109 clc
110 js @@bad ;it is a 86/186/286, not a 386+
111 pushfd
112 pushfd
113 pop ebx
114 mov ecx,ebx
115 xor ebx,00100000h ; toggle CPUID feature bit 21
116 push ebx
117 popfd
118 pushfd
119 pop ebx
120 popfd
121 xor ebx,ecx
122 shr ebx,1+21 ; CPUID feature bit ?
123 jnc @@bad
124 mov eax,80000001h ; Extended Processor Info and Feature Bits
125 db 0Fh,0A2h ; cpuid
126 shr edx,1+29 ; LM feature bit ?
127 @@bad:
128 sbb ax,ax
129 ret
131 endp _cpuhaslm
134 ;***************************************************************
135 ;char *progname(void)
136 ;***************************************************************
137 global _progname:near
138 proc _progname near
140 push si di es
141 mov ah,30h
142 int 21h
143 cmp al,3
144 jb @@skip
145 xor di,di
146 mov es,[cs:2Ch]
147 mov cx,-1
148 mov ax,di
149 @@loop1:
150 repne
151 scasb
152 scasb
153 jne @@loop1
154 lea si,[di+2]
155 mov bx, si
156 extrn strlen:near
157 call near strlen
158 xchg ax,cx
159 inc cx
160 extrn malloc_or_die:near
161 call near malloc_or_die
162 xchg ax,di
163 push ds
164 push ds
165 push es
166 pop ds
167 pop es
168 push di
169 @@loop2:
170 lodsb
171 stosb
172 or al,al
173 jnz @@loop2
174 pop ax
175 pop ds
176 @@skip:
177 pop es di si
178 ret
180 endp _progname
183 ;***************************************************************
184 ;int chdir(char *path);
185 ;***************************************************************
186 global _chdir:near
187 proc _chdir near
189 pop ax
190 pop dx
191 push dx
192 push ax
193 chdir:
194 stc
195 mov ax,713Bh
196 int 21h
197 jnc @@end
198 mov ah,3Bh
199 int 21h
200 @@end:
201 sbb ax,ax
202 ret
204 endp _chdir
207 ;***************************************************************
208 ;int chdirname(char *path)
209 ;***************************************************************
210 global _chdirname:near
211 proc _chdirname near
213 pop ax
214 pop bx
215 push bx
216 push ax
218 cmp [byte bx+1],3Ah
219 jne @@nodisk
220 mov dl,[bx]
221 or dl,20h
222 sub dl,61h
223 mov ah,0Eh
224 push bx
225 int 21h
226 pop bx
227 inc bx
228 inc bx
229 @@nodisk:
230 mov dx,bx
231 xor cx,cx
232 @@next:
233 mov al,[bx]
234 cmp al,5Ch
235 jne @@tsteos
236 mov cx,bx
237 @@tsteos:
238 inc bx
239 or al,al
240 jnz @@next
241 cbw
242 jcxz @@end
243 mov bx,cx
244 push [word bx]
245 mov [bx],al
246 push bx
247 call chdir
248 pop bx
249 pop [word bx]
250 @@end:
251 ret
253 endp _chdirname
256 ;***************************************************************
257 ;char *ultoa(unsigned long n);
258 ;***************************************************************
259 global _ultoa:near
260 proc _ultoa near
262 pop ax
263 pop cx
264 pop dx
265 push dx
266 push cx
267 push ax ; DX:CX = n
268 push si
269 mov si,10
270 mov bx,offset ultoabuf+11
271 @@loop:
272 dec bx
273 xchg ax,dx
274 xor dx,dx
275 div si ; DX:AX = 0000:hi(n)
276 xchg ax,cx ; CX = hi(n)/10
277 div si ; DX:AX = hi(n)%10:lo(n)
278 xchg ax,cx ; CX = lo(n/10)
279 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
280 add al,'0'
281 mov [bx],al
282 mov ax,cx
283 or ax,dx
284 jnz @@loop
285 xchg ax,bx
286 pop si
287 ret
289 endp _ultoa
292 ;***************************************************************
293 ;unsigned long kver2ul(char *kernel_version);
294 ;***************************************************************
295 global _kver2ul:near
296 proc _kver2ul near
298 pop bx
299 pop ax
300 push ax
301 push bx
302 push bp si di
303 xchg ax,si
304 xor di,di
305 push di
306 push di
307 mov bp,sp
308 inc di
309 inc di
310 mov cl,4
311 @@number:
312 xor ax,ax
313 @@digit:
314 shl al,cl
315 shl ax,cl
316 lodsb
317 sub al,30h
318 cmp al,9
319 jbe @@digit
320 mov [bp+di],ah
321 dec di
322 jns @@number
323 pop ax
324 pop dx
325 pop di si bp
326 kver2ulret:
327 ret
329 endp _kver2ul
332 ;***************************************************************
333 ;void try_default_args();
334 ;***************************************************************
335 global _try_default_args:near
336 proc _try_default_args near
338 mov bx,offset tazboot_cmd
339 extrn open:near
340 call near open
341 jc kver2ulret
342 mov cx,4096
343 extrn _heap_top:word
344 mov di,[_heap_top]
345 push cx
346 extrn read_cmdline:near
347 jmp near read_cmdline ; read_cmdline(ax,di,cx)
349 endp _try_default_args
351 struc isostate ; struct isostate {
352 fd dw ? ; 0 int fd;
353 fileofs dd ? ; 2 unsigned long fileofs;
354 filesize dd ? ; 6 unsigned long filesize;
355 filemod dw ? ;10 unsigned short filemod;
356 filename dw ? ;12 char *filename;
357 dirofs dd ? ;14 unsigned long dirofs;
358 dirsize dd ? ;16 unsigned long dirsize;
359 curdirofs dd ? ;20 unsigned long curdirofs;
360 curdirsize dd ? ;24 unsigned long curdirsize;
361 curpos dd ? ;28 unsigned long curpos;
362 ends ; } isostate;
363 ;***************************************************************
364 ;unsigned long isolseek(unsigned long offset);
365 ;***************************************************************
366 global _isolseek:near
367 proc _isolseek near
369 pop ax
370 pop dx
371 pop cx
372 push cx
373 push dx
374 push ax
375 extrn _isostate:isostate
376 mov bx,[_isostate.fd]
377 extrn lseekset:near
378 jmp near lseekset ; (bx=fd, sz=cx:dx)
380 endp _isolseek
382 ends _TEXT
384 end
386 ;###### END OF FILE ############################################