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

updated reiser4progs and reiser4progs-dev (2.0.0 -> 2.0.5)
author Hans-G?nter Theisgen
date Mon Jul 18 14:19:27 2022 +0100 (2022-07-18)
parents 6b6d14c9f7e9
children
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT
19 assume cs:DGROUP,ds:DGROUP
22 segment _TEXT byte public use16 'CODE'
24 ;***************************************************************
25 ;u32 memtop();
26 ;***************************************************************
27 global _memtop:near
28 proc _memtop near
29 ;***************************************************************
30 ;u32 memtop_e820()
31 ;***************************************************************
32 ; proc _memtop_e820 near
34 ifdef INT15_E820
36 struc e820 ;struct e820 {
37 base dd ?,? ; 0 u64 base;
38 length dd ?,? ; 8 u64 length;
39 type db ?,?,?,? ;16 u32 type; 1=available
40 ends e820 ;};
42 p386
43 push ds
44 pop es
45 push di
46 xor ebx,ebx
47 @@e820lp:
48 mov eax,0E820h
49 mov edx,534D4150h ; 'SMAP'
50 xor ecx,ecx
51 mov cl,size e820
52 extrn buf4k:byte
53 mov di,offset buf4k
54 int 15h
55 jc @@err_e820
56 ;cmp eax,534D4150h ; 'SMAP'
57 ;jne @@err_e820
58 cmp [(e820 di).type],1
59 jnz @@notavail
60 mov eax,[(e820 di).base]
61 add eax,[(e820 di).length]
62 push eax
63 pop ax
64 pop dx
65 or dh,dh ; > 16M
66 je @@notavail
67 pop di
68 ret
69 @@notavail:
70 or bx,bx
71 jne @@e820lp
72 @@err_e820:
73 pop di
74 endif
76 ; endp _memtop_e820
78 ;***************************************************************
79 ;u32 memtop_e801()
80 ;***************************************************************
81 ; proc _memtop_e801 near
83 xor cx,cx ;fix to work around buggy
84 xor dx,dx ; BIOSes which dont clear/set
85 mov ax,0E801h ;ax=1kbs in 1-16M bx=64kbs above 16M extended
86 int 15h ;cx=1kbs in 1-16M dx=64kbs above 16M configured
87 xchg ax,cx ;kludge to handle BIOSes
88 jcxz @@use_cxdx ; which report their extended
89 ; memory in AX/BX rather than
90 ; CX/DX. The spec I have read
91 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
92 xchg ax,cx ; are more reasonable anyway...
93 @@use_cxdx: ;now: dx=64k units above 16m
94 ; ax=1k units above 1m below 16m (max 3c00h)
95 or dx,dx
96 jz @@below16M
97 xor ax,ax ;ignore info on low 16M (assume full)
98 inc dh ;account for low 16M
99 ret
100 @@below16M:
101 or ax,ax
102 jnz tokb ;dx=0 here, ax=kbs above 1m
103 @@err:
104 ; ret
105 ; endp _memtop_e801
108 ;***************************************************************
109 ;u32 memtop_88()
110 ;***************************************************************
111 ; proc _memtop_88 near
113 mov ah,88h
114 int 15h ;ax=kbs above 1m
115 test ax,ax ; error: ax=0
116 jnz tokb ;happens on big mem systems
118 ;***************************************************************
119 ;u32 memtop_cmos()
120 ;***************************************************************
122 ;memtop_cmos:
123 pushf
124 call rdcmos17
125 popf
126 tokb:
127 mov cl,10 ;multiply by 1024
128 ifndef NO386
129 add ah,4h ;account for 1024 low kb
130 setc dl ; (optimized to death)
131 shld dx,ax,cl
132 shl ax,cl ; (kbytes -> bytes)
133 ret
134 else
135 xor dx,dx
136 add ah,4h ;account for 1024 low kb
137 adc dx,dx ; (optimized to death)
138 db 0A9h ; test ax,0C28Ch
139 global N_LXLSH@ES:near
140 N_LXLSH@ES:
141 mov dx,es
142 global N_LXLSH@:near
143 N_LXLSH@:
144 mov ch,0
145 @@lp:
146 shl ax,1
147 rcl dx,1
148 loop @@lp
149 ret
150 global N_LXLSH@4:near
151 N_LXLSH@4:
152 xor dx,dx
153 mov cl,4
154 jmp N_LXLSH@
155 endif
157 ; endp _memtop_88
159 ; proc _memtop near
161 ; call _memtop_e801
162 ; jnz @@ok
163 ; call _memtop_88
164 ; jnz @@ok
165 ; jmp memtop_cmos
167 rdcmos17: cli
168 mov al,18h ; read bytes 17-18 from CMOS
169 call @@rdcmos
170 mov ah,al
171 mov al,17h
172 @@rdcmos: out 70h,al
173 call @@ret
174 in al,71h
175 @@ret:
176 ret
179 ;***************************************************************
180 ;u32 topload();
181 ;***************************************************************
182 global _topload:near
183 _topload:
184 call _memtop
185 mov cx,40h ; min 4m
186 ; If reported mem is ridiculously low, presume
187 ; we had trouble detecting memory size
188 cmp dx,cx
189 jb @@set
190 extrn _cmdnum:dword
191 _topmem = _cmdnum+8
192 mov cx,[word _topmem+2]
193 inc cx ; jcxnz
194 loop @@topmemset
195 mov ch,10h ; default = max 256m
196 @@topmemset:
197 ; Kernel can have trouble with initrd at very high addr:
198 ; limit mem top to 256m
199 cmp dh,ch
200 jb @@done
201 @@set:
202 xchg ax,cx
203 cwd
204 xchg ax,dx
205 @@done:
206 ; Round down to page boundary.
207 ; Or else initrd's tail may end up in last, partial page.
208 ; Kernel will refuse to use such initrd.
209 and ax,0f000h
210 ;@@ok:
211 ret
213 endp _memtop
215 ;***************************************************************
216 ;void hook_int15_88();
217 ;***************************************************************
218 global _hook_int15_88:near
219 proc _hook_int15_88 near
221 ifndef xmm_hook
222 ;mov ax,4300h
223 ;int 2fh
224 ;cmp al,80h ; 80h = XMS driver installed
225 ;je @@skip
226 endif
227 saved15:
228 xor bx,bx
229 mov es,bx
230 ifndef NO386
231 push cs
232 push offset int15_88
233 pop eax
234 xchg eax,[es:bx+15*4]
235 mov [dword saved15],eax
236 else
237 mov ax,offset int15_88
238 call saved15z
239 mov ax,cs
240 inc bx
241 inc bx
242 saved15z:
243 xchg ax,[es:bx+15*4]
244 mov [word bx+saved15],ax
245 endif
246 ;push ds
247 ;pop es
248 @@skip:
249 ret
250 int15_88:
251 cmp ah,88h
252 je @@do88
253 jmp [dword saved15]
254 @@do88:
255 pushf
256 call [dword saved15]
257 or ax,ax
258 jnz @@iret
260 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
261 call rdcmos17
262 @@iret:
263 iret
265 endp _hook_int15_88
267 ends _TEXT
269 end
271 ;###### END OF FILE ############################################