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

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