wok view linld/stuff/src/MEMTOP.ASM @ rev 19882
bluez: add SIM access profile support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Apr 03 10:59:15 2017 +0200 (2017-04-03) |
parents | 429d89fd5e0f |
children | a7fbb1c5c71a |
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 ifndef NO386
101 shld dx,ax,10 ;multiply by 1024
102 shl ax,10 ; (kbytes -> bytes)
103 else
104 @@lp:
105 mov cx,10
106 shl ax,1 ;multiply by 1024
107 rcl dx,1
108 loop @@lp
109 endif
110 ; mov cx,ax
111 ; or cx,dx ;update ZF
112 ;@@fail:
113 ret
114 ; endp _memtop_88
116 ; proc _memtopz near
118 ; call _memtop_e801
119 ; jnz @@ok
120 ; call _memtop_88
121 ; jnz @@ok
122 ; jmp memtop_cmos
124 rdcmos17: mov al,18h ; read bytes 17-18 from CMOS
125 call @@rdcmos
126 mov ah,al
127 mov al,17h
128 @@rdcmos: out 70h,al
129 call @@ret
130 in al,71h
131 @@ret:
132 ret
135 ;***************************************************************
136 ;u32 memtop();
137 ;***************************************************************
138 global _memtop:near
139 _memtop:
140 call _memtopz
141 mov cx,40h ; min 4m
142 ; If reported mem is ridiculously low, presume
143 ; we had trouble detecting memory size
144 cmp dx,cx
145 jb @@set
146 mov cx,[word _topmem+2] ; max 256m ?
147 ; Kernel can have trouble with initrd at very high addr:
148 ; limit mem top to 256m
149 cmp dh,ch
150 jb @@done
151 @@set:
152 xchg ax,cx
153 cwd
154 xchg ax,dx
155 @@done:
156 ; Round down to page boundary.
157 ; Or else initrd's tail may end up in last, partial page.
158 ; Kernel will refuse to use such initrd.
159 and ax,0f000h
160 ;@@ok:
161 ret
163 endp _memtopz
165 ;***************************************************************
166 ;void hook_int15_88();
167 ;***************************************************************
168 global _hook_int15_88:near
169 proc _hook_int15_88 near
171 ifndef xmm_hook
172 mov ax,4300h
173 cwd
174 mov es,dx
175 int 2fh
176 cmp al,80h ; 80h = XMS driver installed
177 je @@skip
178 endif
179 ifndef NO386
180 ifdef xmm_hook
181 push 0
182 pop es
183 endif
184 push cs
185 push offset int15_88
186 pop eax
187 xchg eax,[es:15*4]
188 mov [saved15],eax
189 else
190 ifdef xmm_hook
191 xor ax,ax
192 mov es,ax
193 endif
194 mov ax,offset int15_88
195 xchg ax,[es:15*4]
196 mov [word saved15],ax
197 mov ax,cs
198 xchg ax,[es:15*4+2]
199 mov [word saved15+2],ax
200 endif
201 @@skip:
202 ret
203 int15_88:
204 cmp ah,88h
205 je @@do88
206 @@jmp_saved15:
207 jmp [saved15]
208 @@do88:
209 pushf
210 call @@jmp_saved15
211 test ax,ax
212 jnz @@iret
214 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
215 call rdcmos17
216 @@iret:
217 iret
219 endp _hook_int15_88
221 ends _TEXT
223 end
225 ;###### END OF FILE ############################################