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

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