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

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