wok view linld/stuff/src/MEMTOP.ASM @ rev 23983

linld: fix strtol
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 24 08:47:45 2020 +0000 (2020-11-24)
parents 6e3d30b3031f
children a946c1651082
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT
16 assume cs:DGROUP,ds:DGROUP
19 segment _TEXT byte public use16 'CODE'
21 ;***************************************************************
22 ;u32 memtopz();
23 ;***************************************************************
24 proc _memtopz near
25 ;***************************************************************
26 ;u32 memtop_e801()
27 ;***************************************************************
28 ; proc _memtop_e801 near
30 xor cx,cx ;fix to work around buggy
31 xor dx,dx ; BIOSes which dont clear/set
32 stc ; carry on pass/error of
33 mov ax,0E801h
34 int 15h
35 jc @@err
37 xchg ax,cx ;kludge to handle BIOSes
38 jcxz @@use_cxdx ; which report their extended
39 ; memory in AX/BX rather than
40 ; CX/DX. The spec I have read
41 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
42 xchg ax,cx ; are more reasonable anyway...
43 @@use_cxdx: ;now: dx=64k units above 16m
44 ; ax=1k units above 1m below 16m (max 3c00h)
45 or dx,dx
46 jz tokb ;dx=0 here, ax=kbs above 1m
47 xor ax,ax ;ignore info on low 16M (assume full)
48 ;add dx,100h ;account for low 16M
49 inc dh ;account for low 16M (optimized)
50 ret
51 @@err:
52 ; xor ax,ax
53 ; cwd
54 ; ret
55 ; endp _memtop_e801
58 ;***************************************************************
59 ;u32 memtop_88()
60 ;***************************************************************
61 ; proc _memtop_88 near
63 mov ah,88h
64 int 15h ;ax=kbs above 1m
65 cmc ; error: cf=1 or ax=0
66 sbb dx,dx
67 and ax,dx ;
68 jnz tokb ;happens on big mem systems
70 ;***************************************************************
71 ;u32 memtop_cmos()
72 ;***************************************************************
74 ;memtop_cmos:
75 pushf
76 call rdcmos17
77 popf
78 tokb:
79 mov cl,10 ;multiply by 1024
80 ifndef NO386
81 add ah,4h ;account for 1024 low kb
82 setc dl ; (optimized to death)
83 shld dx,ax,cl
84 shl ax,cl ; (kbytes -> bytes)
85 ret
86 else
87 xor dx,dx
88 add ah,4h ;account for 1024 low kb
89 adc dx,dx ; (optimized to death)
90 db 0A9h ; test ax,0C28Ch
91 global N_LXLSH@ES:near
92 N_LXLSH@ES:
93 mov dx,es
94 global N_LXLSH@:near
95 N_LXLSH@:
96 mov ch,0
97 @@lp:
98 shl ax,1
99 rcl dx,1
100 loop @@lp
101 ret
102 global N_LXLSH@4:near
103 N_LXLSH@4:
104 xor dx,dx
105 mov cl,4
106 jmp N_LXLSH@
107 endif
109 ; endp _memtop_88
111 ; proc _memtopz near
113 ; call _memtop_e801
114 ; jnz @@ok
115 ; call _memtop_88
116 ; jnz @@ok
117 ; jmp memtop_cmos
119 rdcmos17: cli
120 mov al,18h ; read bytes 17-18 from CMOS
121 call @@rdcmos
122 mov ah,al
123 mov al,17h
124 @@rdcmos: out 70h,al
125 call @@ret
126 in al,71h
127 @@ret:
128 ret
131 ;***************************************************************
132 ;u32 memtop();
133 ;***************************************************************
134 global _memtop:near
135 _memtop:
136 call _memtopz
137 mov cx,40h ; min 4m
138 ; If reported mem is ridiculously low, presume
139 ; we had trouble detecting memory size
140 cmp dx,cx
141 jb @@set
142 extrn _topmem:dword
143 mov cx,[word _topmem+2]
144 inc cx ; jcxnz
145 loop @@topmemset
146 mov ch,10h ; default = max 256m
147 @@topmemset:
148 ; Kernel can have trouble with initrd at very high addr:
149 ; limit mem top to 256m
150 cmp dh,ch
151 jb @@done
152 @@set:
153 xchg ax,cx
154 cwd
155 xchg ax,dx
156 @@done:
157 ; Round down to page boundary.
158 ; Or else initrd's tail may end up in last, partial page.
159 ; Kernel will refuse to use such initrd.
160 and ax,0f000h
161 ;@@ok:
162 ret
164 endp _memtopz
166 ;***************************************************************
167 ;void hook_int15_88();
168 ;***************************************************************
169 global _hook_int15_88:near
170 proc _hook_int15_88 near
172 ifndef xmm_hook
173 mov ax,4300h
174 int 2fh
175 cmp al,80h ; 80h = XMS driver installed
176 je @@skip
177 endif
178 saved15:
179 xor bx,bx
180 mov es,bx
181 ifndef NO386
182 push cs
183 push offset int15_88
184 pop eax
185 xchg eax,[es:bx+15*4]
186 mov [dword saved15],eax
187 else
188 mov ax,offset int15_88
189 xchg ax,[es:bx+15*4]
190 mov [word saved15],ax
191 mov ax,cs
192 xchg ax,[es:bx+15*4+2]
193 mov [word saved15+2],ax
194 endif
195 ;push ds
196 ;pop es
197 @@skip:
198 ret
199 int15_88:
200 cmp ah,88h
201 je @@do88
202 jmp [dword saved15]
203 @@do88:
204 pushf
205 call [dword saved15]
206 or ax,ax
207 jnz @@iret
209 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
210 call rdcmos17
211 @@iret:
212 iret
214 endp _hook_int15_88
216 ends _TEXT
218 end
220 ;###### END OF FILE ############################################