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

linld/iso2exe: remove non slitaz dos boot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 10 18:47:30 2019 +0200 (2019-08-10)
parents 2373992ff751
children 6e3d30b3031f
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 or 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 mov cl,10 ;multiply by 1024
86 ifndef NO386
87 add ah,4h ;account for 1024 low kb
88 setc dl ; (optimized to death)
89 shld dx,ax,cl
90 shl ax,cl ; (kbytes -> bytes)
91 ret
92 else
93 xor dx,dx
94 add ah,4h ;account for 1024 low kb
95 adc dx,dx ; (optimized to death)
96 db 0A9h ; test ax,0C28Ch
97 global N_LXLSH@ES:near
98 N_LXLSH@ES:
99 mov dx,es
100 global N_LXLSH@:near
101 N_LXLSH@:
102 mov ch,0
103 @@lp:
104 shl ax,1
105 rcl dx,1
106 loop @@lp
107 ret
108 global N_LXLSH@4:near
109 N_LXLSH@4:
110 xor dx,dx
111 mov cl,4
112 jmp N_LXLSH@
113 endif
115 ; endp _memtop_88
117 ; proc _memtopz near
119 ; call _memtop_e801
120 ; jnz @@ok
121 ; call _memtop_88
122 ; jnz @@ok
123 ; jmp memtop_cmos
125 rdcmos17: cli
126 mov al,18h ; read bytes 17-18 from CMOS
127 call @@rdcmos
128 mov ah,al
129 mov al,17h
130 @@rdcmos: out 70h,al
131 call @@ret
132 in al,71h
133 @@ret:
134 ret
137 ;***************************************************************
138 ;u32 memtop();
139 ;***************************************************************
140 global _memtop:near
141 _memtop:
142 call _memtopz
143 mov cx,40h ; min 4m
144 ; If reported mem is ridiculously low, presume
145 ; we had trouble detecting memory size
146 cmp dx,cx
147 jb @@set
148 extrn _topmem:dword
149 mov cx,[word _topmem+2]
150 inc cx ; jcxnz
151 loop @@topmemset
152 mov ch,10h ; default = max 256m
153 @@topmemset:
154 ; Kernel can have trouble with initrd at very high addr:
155 ; limit mem top to 256m
156 cmp dh,ch
157 jb @@done
158 @@set:
159 xchg ax,cx
160 cwd
161 xchg ax,dx
162 @@done:
163 ; Round down to page boundary.
164 ; Or else initrd's tail may end up in last, partial page.
165 ; Kernel will refuse to use such initrd.
166 and ax,0f000h
167 ;@@ok:
168 ret
170 endp _memtopz
172 ;***************************************************************
173 ;void hook_int15_88();
174 ;***************************************************************
175 global _hook_int15_88:near
176 proc _hook_int15_88 near
178 ifndef xmm_hook
179 mov ax,4300h
180 int 2fh
181 cmp al,80h ; 80h = XMS driver installed
182 je @@skip
183 endif
184 xor bx,bx
185 mov es,bx
186 ifndef NO386
187 push cs
188 push offset int15_88
189 pop eax
190 xchg eax,[es:bx+15*4]
191 mov [saved15],eax
192 else
193 mov ax,offset int15_88
194 xchg ax,[es:bx+15*4]
195 mov [word saved15],ax
196 mov ax,cs
197 xchg ax,[es:bx+15*4+2]
198 mov [word saved15+2],ax
199 endif
200 ;push ds
201 ;pop es
202 @@skip:
203 ret
204 int15_88:
205 cmp ah,88h
206 je @@do88
207 jmp [saved15]
208 @@do88:
209 pushf
210 call [saved15]
211 or ax,ax
212 jnz @@iret
214 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
215 call rdcmos17
216 @@iret:
217 iret
219 endp _hook_int15_88
221 ends _TEXT
223 end
225 ;###### END OF FILE ############################################