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

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