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

Add obexd & obexftp
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Apr 02 16:56:55 2017 +0200 (2017-04-02)
parents 96b6a30a3f9a
children 429d89fd5e0f
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 ;push cx bx
46 xor cx,cx ;fix to work around buggy
47 xor dx,dx ; BIOSes which dont clear/set
48 stc ; carry on pass/error of
49 mov ax,0E801h
50 int 15h
51 jc @@err
52 test cx,cx ;kludge to handle BIOSes
53 jnz @@use_cxdx ; which report their extended
54 test dx,dx ; 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 ;jmp @@end_kludge ; are more reasonable anyway...
58 db 0a8h ; test al,im opcode
59 @@use_cxdx: xchg ax,cx
60 @@end_kludge: ;now: dx=64k units above 16m
61 ; ax=1k units above 1m below 16m (max 3c00h)
62 ;pop bx cx
63 test dx,dx
64 jz tokb ;dx=0 here, ax=kbs above 1m
65 xor ax,ax ;ignore info on low 16M (assume full)
66 ;add dx,100h ;account for low 16M
67 inc dh ;account for low 16M (optimized)
68 ret
69 @@err:
70 ; xor ax,ax
71 ; cwd
72 ; ret
73 ; endp _memtop_e801
76 ;***************************************************************
77 ;u32 memtop_88()
78 ;***************************************************************
79 ; proc _memtop_88 near
81 mov ah,88h
82 int 15h ;ax=kbs above 1m
83 jnc @@ok ; error: cf=1 or ax=0
84 xor ax,ax ;
85 @@ok:
86 ; xor dx,dx
87 test ax,ax ;happens on big mem systems
88 jnz tokb
90 ;***************************************************************
91 ;u32 memtop_cmos()
92 ;***************************************************************
94 ;memtop_cmos:
95 pushf
96 cli
97 call rdcmos17
98 popf
99 tokb:
100 xor dx,dx
101 add ah,4h ;account for 1024 low kb
102 adc dx,dx ; (optimized to death)
103 ifndef NO386
104 shld dx,ax,10 ;multiply by 1024
105 shl ax,10 ; (kbytes -> bytes)
106 else
107 @@lp:
108 mov cx,10
109 shl ax,1 ;multiply by 1024
110 rcl dx,1
111 loop @@lp
112 endif
113 ; mov cx,ax
114 ; or cx,dx ;update ZF
115 ;@@fail:
116 ret
117 ; endp _memtop_88
119 ; proc _memtopz near
121 ; call _memtop_e801
122 ; jnz @@ok
123 ; call _memtop_88
124 ; jnz @@ok
125 ; jmp memtop_cmos
127 rdcmos17: mov al,18h ; read bytes 17-18 from CMOS
128 call @@rdcmos
129 mov ah,al
130 mov al,17h
131 @@rdcmos: out 70h,al
132 call @@ret
133 in al,71h
134 @@ret:
135 ret
138 ;***************************************************************
139 ;u32 memtop();
140 ;***************************************************************
141 global _memtop:near
142 _memtop:
143 call _memtopz
144 mov cx,40h ; min 4m
145 ; If reported mem is ridiculously low, presume
146 ; we had trouble detecting memory size
147 cmp dx,cx
148 jb @@set
149 mov cx,[word _topmem+2] ; max 256m ?
150 ; Kernel can have trouble with initrd at very high addr:
151 ; limit mem top to 256m
152 cmp dh,ch
153 jb @@done
154 @@set:
155 xchg ax,cx
156 cwd
157 xchg ax,dx
158 @@done:
159 ; Round down to page boundary.
160 ; Or else initrd's tail may end up in last, partial page.
161 ; Kernel will refuse to use such initrd.
162 and ax,0f000h
163 ;@@ok:
164 ret
166 endp _memtopz
168 ;***************************************************************
169 ;void hook_int15_88();
170 ;***************************************************************
171 global _hook_int15_88:near
172 proc _hook_int15_88 near
174 ifndef xmm_hook
175 mov ax,4300h
176 cwd
177 mov es,dx
178 int 2fh
179 cmp al,80h ; 80h = XMS driver installed
180 je @@skip
181 endif
182 ifndef NO386
183 ifdef xmm_hook
184 push 0
185 pop es
186 endif
187 push cs
188 push offset int15_88
189 pop eax
190 xchg eax,[es:15*4]
191 mov [saved15],eax
192 else
193 ifdef xmm_hook
194 xor ax,ax
195 mov es,ax
196 endif
197 mov ax,offset int15_88
198 xchg ax,[es:15*4]
199 mov [word saved15],ax
200 mov ax,cs
201 xchg ax,[es: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 ############################################