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

bluez: add /usr/bin/bluepin
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 03 17:30:48 2017 +0200 (2017-04-03)
parents a7fbb1c5c71a
children 04feaffdc0d9
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 jnc @@ok ; error: cf=1 or ax=0
81 xor ax,ax ;
82 @@ok:
83 ; xor dx,dx
84 test ax,ax ;happens on big mem systems
85 jnz tokb
87 ;***************************************************************
88 ;u32 memtop_cmos()
89 ;***************************************************************
91 ;memtop_cmos:
92 pushf
93 cli
94 call rdcmos17
95 popf
96 tokb:
97 xor dx,dx
98 add ah,4h ;account for 1024 low kb
99 adc dx,dx ; (optimized to death)
100 mov cl,10 ;multiply by 1024
101 global N_LXLSH@:near
102 N_LXLSH@:
103 ifndef NO386
104 shld dx,ax,cl
105 shl ax,cl ; (kbytes -> bytes)
106 else
107 mov ch,0
108 @@lp:
109 shl ax,1
110 rcl dx,1
111 loop @@lp
112 endif
113 ret
115 ; endp _memtop_88
117 ifdef NO386
118 global N_LXURSH@:near
119 global N_LXURSH@4:near
120 ; proc N_LXURSH@4 near
121 N_LXURSH@4:
122 mov cl,4
123 N_LXURSH@:
124 mov ch,0
125 @@loop:
126 shr dx,1
127 rcr ax,1
128 loop @@loop
129 ret
131 ; endp N_LXURSH@4
133 endif
136 ; proc _memtopz near
138 ; call _memtop_e801
139 ; jnz @@ok
140 ; call _memtop_88
141 ; jnz @@ok
142 ; jmp memtop_cmos
144 rdcmos17: mov al,18h ; read bytes 17-18 from CMOS
145 call @@rdcmos
146 mov ah,al
147 mov al,17h
148 @@rdcmos: out 70h,al
149 call @@ret
150 in al,71h
151 @@ret:
152 ret
155 ;***************************************************************
156 ;u32 memtop();
157 ;***************************************************************
158 global _memtop:near
159 _memtop:
160 call _memtopz
161 mov cx,40h ; min 4m
162 ; If reported mem is ridiculously low, presume
163 ; we had trouble detecting memory size
164 cmp dx,cx
165 jb @@set
166 mov cx,[word _topmem+2] ; max 256m ?
167 ; Kernel can have trouble with initrd at very high addr:
168 ; limit mem top to 256m
169 cmp dh,ch
170 jb @@done
171 @@set:
172 xchg ax,cx
173 cwd
174 xchg ax,dx
175 @@done:
176 ; Round down to page boundary.
177 ; Or else initrd's tail may end up in last, partial page.
178 ; Kernel will refuse to use such initrd.
179 and ax,0f000h
180 ;@@ok:
181 ret
183 endp _memtopz
185 ;***************************************************************
186 ;void hook_int15_88();
187 ;***************************************************************
188 global _hook_int15_88:near
189 proc _hook_int15_88 near
191 ifndef xmm_hook
192 mov ax,4300h
193 int 2fh
194 cmp al,80h ; 80h = XMS driver installed
195 je @@skip
196 endif
197 xor bx,bx
198 mov es,bx
199 ifndef NO386
200 push cs
201 push offset int15_88
202 pop eax
203 xchg eax,[es:bx+15*4]
204 mov [saved15],eax
205 else
206 mov ax,offset int15_88
207 xchg ax,[es:bx+15*4]
208 mov [word saved15],ax
209 mov ax,cs
210 xchg ax,[es:bx+15*4+2]
211 mov [word saved15+2],ax
212 endif
213 @@skip:
214 ret
215 int15_88:
216 cmp ah,88h
217 je @@do88
218 @@jmp_saved15:
219 jmp [saved15]
220 @@do88:
221 pushf
222 call @@jmp_saved15
223 test ax,ax
224 jnz @@iret
226 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
227 call rdcmos17
228 @@iret:
229 iret
231 endp _hook_int15_88
233 ends _TEXT
235 end
237 ;###### END OF FILE ############################################