wok-6.x view linld/stuff/src/MEMTOP.ASM @ rev 20528

linld: pascal convention calls
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 09 16:37:55 2018 +0100 (2018-11-09)
parents a5b6457fb890
children be1594cae466
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 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 db 0A9h ; test ax,04B1h
94 global N_LXLSH@4:near
95 N_LXLSH@4:
96 mov cl,4
97 global N_LXLSH@:near
98 N_LXLSH@:
99 mov ch,0
100 @@lp:
101 shl ax,1
102 rcl dx,1
103 loop @@lp
104 endif
105 ret
107 ; endp _memtop_88
109 ifdef NO386
110 global N_LXURSH@:near
111 global N_LXURSH@4:near
112 ; proc N_LXURSH@4 near
113 N_LXURSH@4:
114 mov cl,4
115 N_LXURSH@:
116 mov ch,0
117 @@loop:
118 shr dx,1
119 rcr ax,1
120 loop @@loop
121 ret
123 ; endp N_LXURSH@4
125 endif
128 ; proc _memtopz near
130 ; call _memtop_e801
131 ; jnz @@ok
132 ; call _memtop_88
133 ; jnz @@ok
134 ; jmp memtop_cmos
136 rdcmos17: cli
137 mov al,18h ; read bytes 17-18 from CMOS
138 call @@rdcmos
139 mov ah,al
140 mov al,17h
141 @@rdcmos: out 70h,al
142 call @@ret
143 in al,71h
144 @@ret:
145 ret
148 ;***************************************************************
149 ;u32 memtop();
150 ;***************************************************************
151 global _memtop:near
152 _memtop:
153 call _memtopz
154 mov cx,40h ; min 4m
155 ; If reported mem is ridiculously low, presume
156 ; we had trouble detecting memory size
157 cmp dx,cx
158 jb @@set
159 extrn _topmem:dword
160 mov cx,[word _topmem+2]
161 inc cx ; jcxnz
162 loop @@topmemset
163 mov ch,10h ; default = max 256m
164 @@topmemset:
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 or 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 ############################################