wok-6.x view linld/stuff/src/MEMTOP.ASM @ rev 24015
Up tazinst (112)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Feb 25 10:56:54 2021 +0000 (2021-02-25) |
parents | bc4b94310a29 |
children | 61df94a0fa43 |
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_e820()
27 ;***************************************************************
28 ; proc _memtop_e820 near
30 ifdef INT15_E820
32 struc e820 ;struct e820 {
33 base dd ?,? ; 0 u64 base;
34 length dd ?,? ; 8 u64 length;
35 type db ?,?,?,? ;16 u32 type; 1=available
36 ends e820 ;};
38 p386
39 push ds
40 pop es
41 push di
42 xor ebx,ebx
43 @@e820lp:
44 mov eax,0E820h
45 mov edx,534D4150h ; 'SMAP'
46 xor ecx,ecx
47 mov cl,size e820
48 extrn buf4k:byte
49 mov di,offset buf4k
50 int 15h
51 jc @@err_e820
52 ;cmp eax,534D4150h ; 'SMAP'
53 ;jne @@err_e820
54 cmp [(e820 di).type],1
55 jnz @@notavail
56 mov eax,[(e820 di).base]
57 add eax,[(e820 di).length]
58 push eax
59 pop ax
60 pop dx
61 or dh,dh ; > 16M
62 je @@notavail
63 pop di
64 ret
65 @@notavail:
66 or bx,bx
67 jne @@e820lp
68 @@err_e820:
69 pop di
70 endif
72 ; endp _memtop_e820
74 ;***************************************************************
75 ;u32 memtop_e801()
76 ;***************************************************************
77 ; proc _memtop_e801 near
79 xor cx,cx ;fix to work around buggy
80 xor dx,dx ; BIOSes which dont clear/set
81 mov ax,0E801h ;ax=1kbs in 1-16M bx=64kbs above 16M extended
82 int 15h ;cx=1kbs in 1-16M dx=64kbs above 16M configured
83 xchg ax,cx ;kludge to handle BIOSes
84 jcxz @@use_cxdx ; which report their extended
85 ; memory in AX/BX rather than
86 ; CX/DX. The spec I have read
87 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
88 xchg ax,cx ; are more reasonable anyway...
89 @@use_cxdx: ;now: dx=64k units above 16m
90 ; ax=1k units above 1m below 16m (max 3c00h)
91 or dx,dx
92 jz @@below16M
93 xor ax,ax ;ignore info on low 16M (assume full)
94 inc dh ;account for low 16M
95 ret
96 @@below16M:
97 or ax,ax
98 jnz tokb ;dx=0 here, ax=kbs above 1m
99 @@err:
100 ; ret
101 ; endp _memtop_e801
104 ;***************************************************************
105 ;u32 memtop_88()
106 ;***************************************************************
107 ; proc _memtop_88 near
109 mov ah,88h
110 int 15h ;ax=kbs above 1m
111 test ax,ax ; error: ax=0
112 jnz tokb ;happens on big mem systems
114 ;***************************************************************
115 ;u32 memtop_cmos()
116 ;***************************************************************
118 ;memtop_cmos:
119 pushf
120 call rdcmos17
121 popf
122 tokb:
123 mov cl,10 ;multiply by 1024
124 ifndef NO386
125 add ah,4h ;account for 1024 low kb
126 setc dl ; (optimized to death)
127 shld dx,ax,cl
128 shl ax,cl ; (kbytes -> bytes)
129 ret
130 else
131 xor dx,dx
132 add ah,4h ;account for 1024 low kb
133 adc dx,dx ; (optimized to death)
134 db 0A9h ; test ax,0C28Ch
135 global N_LXLSH@ES:near
136 N_LXLSH@ES:
137 mov dx,es
138 global N_LXLSH@:near
139 N_LXLSH@:
140 mov ch,0
141 @@lp:
142 shl ax,1
143 rcl dx,1
144 loop @@lp
145 ret
146 global N_LXLSH@4:near
147 N_LXLSH@4:
148 xor dx,dx
149 mov cl,4
150 jmp N_LXLSH@
151 endif
153 ; endp _memtop_88
155 ; proc _memtopz near
157 ; call _memtop_e801
158 ; jnz @@ok
159 ; call _memtop_88
160 ; jnz @@ok
161 ; jmp memtop_cmos
163 rdcmos17: cli
164 mov al,18h ; read bytes 17-18 from CMOS
165 call @@rdcmos
166 mov ah,al
167 mov al,17h
168 @@rdcmos: out 70h,al
169 call @@ret
170 in al,71h
171 @@ret:
172 ret
175 ;***************************************************************
176 ;u32 memtop();
177 ;***************************************************************
178 global _memtop:near
179 _memtop:
180 call _memtopz
181 mov cx,40h ; min 4m
182 ; If reported mem is ridiculously low, presume
183 ; we had trouble detecting memory size
184 cmp dx,cx
185 jb @@set
186 extrn _cmdnum:dword
187 _topmem = _cmdnum+8
188 mov cx,[word _topmem+2]
189 inc cx ; jcxnz
190 loop @@topmemset
191 mov ch,10h ; default = max 256m
192 @@topmemset:
193 ; Kernel can have trouble with initrd at very high addr:
194 ; limit mem top to 256m
195 cmp dh,ch
196 jb @@done
197 @@set:
198 xchg ax,cx
199 cwd
200 xchg ax,dx
201 @@done:
202 ; Round down to page boundary.
203 ; Or else initrd's tail may end up in last, partial page.
204 ; Kernel will refuse to use such initrd.
205 and ax,0f000h
206 ;@@ok:
207 ret
209 endp _memtopz
211 ;***************************************************************
212 ;void hook_int15_88();
213 ;***************************************************************
214 global _hook_int15_88:near
215 proc _hook_int15_88 near
217 ifndef xmm_hook
218 ;mov ax,4300h
219 ;int 2fh
220 ;cmp al,80h ; 80h = XMS driver installed
221 ;je @@skip
222 endif
223 saved15:
224 xor bx,bx
225 mov es,bx
226 ifndef NO386
227 push cs
228 push offset int15_88
229 pop eax
230 xchg eax,[es:bx+15*4]
231 mov [dword saved15],eax
232 else
233 mov ax,offset int15_88
234 call saved15z
235 mov ax,cs
236 inc bx
237 inc bx
238 saved15z:
239 xchg ax,[es:bx+15*4]
240 mov [word bx+saved15],ax
241 endif
242 ;push ds
243 ;pop es
244 @@skip:
245 ret
246 int15_88:
247 cmp ah,88h
248 je @@do88
249 jmp [dword saved15]
250 @@do88:
251 pushf
252 call [dword saved15]
253 or ax,ax
254 jnz @@iret
256 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
257 call rdcmos17
258 @@iret:
259 iret
261 endp _hook_int15_88
263 ends _TEXT
265 end
267 ;###### END OF FILE ############################################