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

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