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

bluez: fix bluez-simple-agent
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 03 10:27:24 2017 +0200 (2017-04-03)
parents b06deec67841
children 2717d404353b
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 push cx ;kludge to handle BIOSes
52 or cx,dx ; which report their extended
53 pop cx ; memory in AX/BX rather than
54 jnz @@use_cxdx ; CX/DX. The spec I have read
55 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
56 ;jmp @@end_kludge ; are more reasonable anyway...
57 db 0a8h ; test al,im opcode
58 @@use_cxdx: xchg ax,cx
59 @@end_kludge: ;now: dx=64k units above 16m
60 ; ax=1k units above 1m below 16m (max 3c00h)
61 test dx,dx
62 jz tokb ;dx=0 here, ax=kbs above 1m
63 xor ax,ax ;ignore info on low 16M (assume full)
64 ;add dx,100h ;account for low 16M
65 inc dh ;account for low 16M (optimized)
66 ret
67 @@err:
68 ; xor ax,ax
69 ; cwd
70 ; ret
71 ; endp _memtop_e801
74 ;***************************************************************
75 ;u32 memtop_88()
76 ;***************************************************************
77 ; proc _memtop_88 near
79 mov ah,88h
80 int 15h ;ax=kbs above 1m
81 jnc @@ok ; error: cf=1 or ax=0
82 xor ax,ax ;
83 @@ok:
84 ; xor dx,dx
85 test ax,ax ;happens on big mem systems
86 jnz tokb
88 ;***************************************************************
89 ;u32 memtop_cmos()
90 ;***************************************************************
92 ;memtop_cmos:
93 pushf
94 cli
95 call rdcmos17
96 popf
97 tokb:
98 xor dx,dx
99 add ah,4h ;account for 1024 low kb
100 adc dx,dx ; (optimized to death)
101 ifndef NO386
102 shld dx,ax,10 ;multiply by 1024
103 shl ax,10 ; (kbytes -> bytes)
104 else
105 @@lp:
106 mov cx,10
107 shl ax,1 ;multiply by 1024
108 rcl dx,1
109 loop @@lp
110 endif
111 ; mov cx,ax
112 ; or cx,dx ;update ZF
113 ;@@fail:
114 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 cwd
175 mov es,dx
176 int 2fh
177 cmp al,80h ; 80h = XMS driver installed
178 je @@skip
179 endif
180 ifndef NO386
181 ifdef xmm_hook
182 push 0
183 pop es
184 endif
185 push cs
186 push offset int15_88
187 pop eax
188 xchg eax,[es:15*4]
189 mov [saved15],eax
190 else
191 ifdef xmm_hook
192 xor ax,ax
193 mov es,ax
194 endif
195 mov ax,offset int15_88
196 xchg ax,[es:15*4]
197 mov [word saved15],ax
198 mov ax,cs
199 xchg ax,[es:15*4+2]
200 mov [word saved15+2],ax
201 endif
202 @@skip:
203 ret
204 int15_88:
205 cmp ah,88h
206 je @@do88
207 @@jmp_saved15:
208 jmp [saved15]
209 @@do88:
210 pushf
211 call @@jmp_saved15
212 test 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 ############################################