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