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

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