wok-6.x view linld/stuff/src/CRTLX.ASM @ rev 19642

linld: fix cpuhaslm
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 21 09:21:18 2017 +0100 (2017-01-21)
parents 76087975885f
children d0b4145ad77c
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 ebx
117 mov ecx,ebx
118 btc ebx,21 ; toggle CPUID feature bit 21
119 push ebx
120 popfd
121 pushfd
122 pop ebx
123 xor ebx,ecx
124 shr ebx,1+21 ; CPUID feature bit changed ?
125 jnc @@bad
126 mov eax,80000001h ; Extended Processor Info and Feature Bits
127 cpuid
128 shr edx,1+29 ; LM feature bit ?
129 @@bad:
130 p8086
131 sbb ax,ax
132 ret
134 endp _cpuhaslm
137 ;***************************************************************
138 ;char *progname(void)
139 ;***************************************************************
140 global _progname:near
141 proc _progname near
143 push si di es
144 mov ah,30h
145 int 21h
146 cmp al,3
147 jb @@skip
148 xor di,di
149 mov es,[cs:2Ch]
150 mov cx,-1
151 mov ax,di
152 @@loop1:
153 repne
154 scasb
155 scasb
156 jne @@loop1
157 lea si,[di+2]
158 mov bx, si
159 extrn strlen:near
160 call near strlen
161 xchg ax,cx
162 inc cx
163 extrn malloc_or_die:near
164 call near malloc_or_die
165 xchg ax,di
166 push ds
167 push ds
168 push es
169 pop ds
170 pop es
171 push di
172 @@loop2:
173 lodsb
174 stosb
175 or al,al
176 jnz @@loop2
177 pop ax
178 pop ds
179 @@skip:
180 pop es di si
181 ret
183 endp _progname
186 ;***************************************************************
187 ;int chdir(char *path);
188 ;***************************************************************
189 global _chdir:near
190 proc _chdir near
192 pop ax
193 pop dx
194 push dx
195 push ax
196 chdir:
197 stc
198 mov ax,713Bh
199 int 21h
200 jnc @@end
201 mov ah,3Bh
202 int 21h
203 @@end:
204 sbb ax,ax
205 ret
207 endp _chdir
210 ;***************************************************************
211 ;int chdirname(char *path)
212 ;***************************************************************
213 global _chdirname:near
214 proc _chdirname near
216 pop ax
217 pop bx
218 push bx
219 push ax
221 cmp [byte bx+1],3Ah
222 jne @@nodisk
223 mov dl,[bx]
224 or dl,20h
225 sub dl,61h
226 mov ah,0Eh
227 push bx
228 int 21h
229 pop bx
230 inc bx
231 inc bx
232 @@nodisk:
233 mov dx,bx
234 xor cx,cx
235 @@next:
236 mov al,[bx]
237 cmp al,5Ch
238 jne @@tsteos
239 mov cx,bx
240 @@tsteos:
241 inc bx
242 or al,al
243 jnz @@next
244 cbw
245 jcxz @@end
246 mov bx,cx
247 push [word bx]
248 mov [bx],al
249 push bx
250 call chdir
251 pop bx
252 pop [word bx]
253 @@end:
254 ret
256 endp _chdirname
259 ;***************************************************************
260 ;char *ultoa(unsigned long n);
261 ;***************************************************************
262 global _ultoa:near
263 proc _ultoa near
265 pop ax
266 pop cx
267 pop dx
268 push dx
269 push cx
270 push ax ; DX:CX = n
271 push si
272 mov si,10
273 mov bx,offset ultoabuf+11
274 @@loop:
275 dec bx
276 xchg ax,dx
277 xor dx,dx
278 div si ; DX:AX = 0000:hi(n)
279 xchg ax,cx ; CX = hi(n)/10
280 div si ; DX:AX = hi(n)%10:lo(n)
281 xchg ax,cx ; CX = lo(n/10)
282 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
283 add al,'0'
284 mov [bx],al
285 mov ax,cx
286 or ax,dx
287 jnz @@loop
288 xchg ax,bx
289 pop si
290 ret
292 endp _ultoa
295 ;***************************************************************
296 ;unsigned long kver2ul(char *kernel_version);
297 ;***************************************************************
298 global _kver2ul:near
299 proc _kver2ul near
301 pop bx
302 pop ax
303 push ax
304 push bx
305 push bp si di
306 xchg ax,si
307 xor di,di
308 push di
309 push di
310 mov bp,sp
311 inc di
312 inc di
313 mov cl,4
314 @@number:
315 xor ax,ax
316 @@digit:
317 shl al,cl
318 shl ax,cl
319 lodsb
320 sub al,30h
321 cmp al,9
322 jbe @@digit
323 mov [bp+di],ah
324 dec di
325 jns @@number
326 pop ax
327 pop dx
328 pop di si bp
329 kver2ulret:
330 ret
332 endp _kver2ul
335 ;***************************************************************
336 ;void try_default_args();
337 ;***************************************************************
338 global _try_default_args:near
339 proc _try_default_args near
341 mov bx,offset tazboot_cmd
342 extrn open:near
343 call near open
344 jc kver2ulret
345 mov cx,4096
346 extrn _heap_top:word
347 mov di,[_heap_top]
348 push cx
349 extrn read_cmdline:near
350 jmp near read_cmdline ; read_cmdline(ax,di,cx)
352 endp _try_default_args
354 struc isostate ; struct isostate {
355 fd dw ? ; 0 int fd;
356 fileofs dd ? ; 2 unsigned long fileofs;
357 filesize dd ? ; 6 unsigned long filesize;
358 filemod dw ? ;10 unsigned short filemod;
359 filename dw ? ;12 char *filename;
360 dirofs dd ? ;14 unsigned long dirofs;
361 dirsize dd ? ;16 unsigned long dirsize;
362 curdirofs dd ? ;20 unsigned long curdirofs;
363 curdirsize dd ? ;24 unsigned long curdirsize;
364 curpos dd ? ;28 unsigned long curpos;
365 ends ; } isostate;
366 ;***************************************************************
367 ;unsigned long isolseek(unsigned long offset);
368 ;***************************************************************
369 global _isolseek:near
370 proc _isolseek near
372 pop ax
373 pop dx
374 pop cx
375 push cx
376 push dx
377 push ax
378 extrn _isostate:isostate
379 mov bx,[_isostate.fd]
380 extrn lseekset:near
381 jmp near lseekset ; (bx=fd, sz=cx:dx)
383 endp _isolseek
385 ends _TEXT
387 end
389 ;###### END OF FILE ############################################