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