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

linld: add iso support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 08 20:15:35 2021 +0000 (2021-01-08)
parents fc88d0826de4
children bc4b94310a29
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
16 assume cs:DGROUP,ds:DGROUP
19 segment _TEXT byte public use16 'CODE'
21 ;***************************************************************
22 ;u32 memtopz();
23 ;***************************************************************
24 proc _memtopz near
25 ;***************************************************************
26 ;u32 memtop_e801()
27 ;***************************************************************
28 ; proc _memtop_e801 near
30 xor cx,cx ;fix to work around buggy
31 xor dx,dx ; BIOSes which dont clear/set
32 stc ; carry on pass/error of
33 mov ax,0E801h
34 int 15h
35 jc @@err
37 xchg ax,cx ;kludge to handle BIOSes
38 jcxz @@use_cxdx ; which report their extended
39 ; memory in AX/BX rather than
40 ; CX/DX. The spec I have read
41 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
42 xchg ax,cx ; are more reasonable anyway...
43 @@use_cxdx: ;now: dx=64k units above 16m
44 ; ax=1k units above 1m below 16m (max 3c00h)
45 or dx,dx
46 jz tokb ;dx=0 here, ax=kbs above 1m
47 xor ax,ax ;ignore info on low 16M (assume full)
48 ;add dx,100h ;account for low 16M
49 inc dh ;account for low 16M (optimized)
50 ret
51 @@err:
52 ; xor ax,ax
53 ; cwd
54 ; ret
55 ; endp _memtop_e801
58 ;***************************************************************
59 ;u32 memtop_88()
60 ;***************************************************************
61 ; proc _memtop_88 near
63 mov ah,88h
64 int 15h ;ax=kbs above 1m
65 cmc ; error: cf=1 or ax=0
66 sbb dx,dx
67 and ax,dx ;
68 jnz tokb ;happens on big mem systems
70 ;***************************************************************
71 ;u32 memtop_cmos()
72 ;***************************************************************
74 ;memtop_cmos:
75 pushf
76 call rdcmos17
77 popf
78 tokb:
79 mov cl,10 ;multiply by 1024
80 ifndef NO386
81 add ah,4h ;account for 1024 low kb
82 setc dl ; (optimized to death)
83 shld dx,ax,cl
84 shl ax,cl ; (kbytes -> bytes)
85 ret
86 else
87 xor dx,dx
88 add ah,4h ;account for 1024 low kb
89 adc dx,dx ; (optimized to death)
90 db 0A9h ; test ax,0C28Ch
91 global N_LXLSH@ES:near
92 N_LXLSH@ES:
93 mov dx,es
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 ret
102 global N_LXLSH@4:near
103 N_LXLSH@4:
104 xor dx,dx
105 mov cl,4
106 jmp N_LXLSH@
107 endif
109 ; endp _memtop_88
111 ; proc _memtopz near
113 ; call _memtop_e801
114 ; jnz @@ok
115 ; call _memtop_88
116 ; jnz @@ok
117 ; jmp memtop_cmos
119 rdcmos17: cli
120 mov al,18h ; read bytes 17-18 from CMOS
121 call @@rdcmos
122 mov ah,al
123 mov al,17h
124 @@rdcmos: out 70h,al
125 call @@ret
126 in al,71h
127 @@ret:
128 ret
131 ;***************************************************************
132 ;u32 memtop();
133 ;***************************************************************
134 global _memtop:near
135 _memtop:
136 call _memtopz
137 mov cx,40h ; min 4m
138 ; If reported mem is ridiculously low, presume
139 ; we had trouble detecting memory size
140 cmp dx,cx
141 jb @@set
142 extrn _cmdnum:dword
143 _topmem = _cmdnum+8
144 mov cx,[word _topmem+2]
145 inc cx ; jcxnz
146 loop @@topmemset
147 mov ch,10h ; default = max 256m
148 @@topmemset:
149 ; Kernel can have trouble with initrd at very high addr:
150 ; limit mem top to 256m
151 cmp dh,ch
152 jb @@done
153 @@set:
154 xchg ax,cx
155 cwd
156 xchg ax,dx
157 @@done:
158 ; Round down to page boundary.
159 ; Or else initrd's tail may end up in last, partial page.
160 ; Kernel will refuse to use such initrd.
161 and ax,0f000h
162 ;@@ok:
163 ret
165 endp _memtopz
167 ;***************************************************************
168 ;void hook_int15_88();
169 ;***************************************************************
170 global _hook_int15_88:near
171 proc _hook_int15_88 near
173 ifndef xmm_hook
174 mov ax,4300h
175 int 2fh
176 cmp al,80h ; 80h = XMS driver installed
177 je @@skip
178 endif
179 saved15:
180 xor bx,bx
181 mov es,bx
182 ifndef NO386
183 push cs
184 push offset int15_88
185 pop eax
186 xchg eax,[es:bx+15*4]
187 mov [dword saved15],eax
188 else
189 mov ax,offset int15_88
190 call saved15z
191 mov ax,cs
192 inc bx
193 inc bx
194 saved15z:
195 xchg ax,[es:bx+15*4]
196 mov [word bx+saved15],ax
197 endif
198 ;push ds
199 ;pop es
200 @@skip:
201 ret
202 int15_88:
203 cmp ah,88h
204 je @@do88
205 jmp [dword saved15]
206 @@do88:
207 pushf
208 call [dword saved15]
209 or ax,ax
210 jnz @@iret
212 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
213 call rdcmos17
214 @@iret:
215 iret
217 endp _hook_int15_88
219 ends _TEXT
221 end
223 ;###### END OF FILE ############################################