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@19515
|
117 ; proc _memtopz near
|
pascal@19515
|
118
|
pascal@19515
|
119 ; call _memtop_e801
|
pascal@19515
|
120 ; jnz @@ok
|
pascal@19515
|
121 ; call _memtop_88
|
pascal@19515
|
122 ; jnz @@ok
|
pascal@19879
|
123 ; jmp memtop_cmos
|
pascal@19515
|
124
|
pascal@19515
|
125 rdcmos17: mov al,18h ; read bytes 17-18 from CMOS
|
pascal@19515
|
126 call @@rdcmos
|
pascal@19515
|
127 mov ah,al
|
pascal@19515
|
128 mov al,17h
|
pascal@19515
|
129 @@rdcmos: out 70h,al
|
pascal@19515
|
130 call @@ret
|
pascal@19515
|
131 in al,71h
|
pascal@19515
|
132 @@ret:
|
pascal@19515
|
133 ret
|
pascal@19515
|
134
|
pascal@19515
|
135
|
pascal@19515
|
136 ;***************************************************************
|
pascal@19515
|
137 ;u32 memtop();
|
pascal@19515
|
138 ;***************************************************************
|
pascal@19515
|
139 global _memtop:near
|
pascal@19515
|
140 _memtop:
|
pascal@19515
|
141 call _memtopz
|
pascal@19515
|
142 mov cx,40h ; min 4m
|
pascal@19515
|
143 ; If reported mem is ridiculously low, presume
|
pascal@19515
|
144 ; we had trouble detecting memory size
|
pascal@19515
|
145 cmp dx,cx
|
pascal@19515
|
146 jb @@set
|
pascal@19515
|
147 mov cx,[word _topmem+2] ; max 256m ?
|
pascal@19515
|
148 ; Kernel can have trouble with initrd at very high addr:
|
pascal@19515
|
149 ; limit mem top to 256m
|
pascal@19515
|
150 cmp dh,ch
|
pascal@19515
|
151 jb @@done
|
pascal@19515
|
152 @@set:
|
pascal@19515
|
153 xchg ax,cx
|
pascal@19515
|
154 cwd
|
pascal@19515
|
155 xchg ax,dx
|
pascal@19515
|
156 @@done:
|
pascal@19515
|
157 ; Round down to page boundary.
|
pascal@19515
|
158 ; Or else initrd's tail may end up in last, partial page.
|
pascal@19515
|
159 ; Kernel will refuse to use such initrd.
|
pascal@19515
|
160 and ax,0f000h
|
pascal@19515
|
161 ;@@ok:
|
pascal@19515
|
162 ret
|
pascal@19515
|
163
|
pascal@19515
|
164 endp _memtopz
|
pascal@19515
|
165
|
pascal@19515
|
166 ;***************************************************************
|
pascal@19515
|
167 ;void hook_int15_88();
|
pascal@19515
|
168 ;***************************************************************
|
pascal@19515
|
169 global _hook_int15_88:near
|
pascal@19515
|
170 proc _hook_int15_88 near
|
pascal@19515
|
171
|
pascal@19515
|
172 ifndef xmm_hook
|
pascal@19515
|
173 mov ax,4300h
|
pascal@19515
|
174 int 2fh
|
pascal@19571
|
175 cmp al,80h ; 80h = XMS driver installed
|
pascal@19515
|
176 je @@skip
|
pascal@19515
|
177 endif
|
pascal@19883
|
178 xor bx,bx
|
pascal@19883
|
179 mov es,bx
|
pascal@19571
|
180 ifndef NO386
|
pascal@19876
|
181 push cs
|
pascal@19876
|
182 push offset int15_88
|
pascal@19876
|
183 pop eax
|
pascal@19883
|
184 xchg eax,[es:bx+15*4]
|
pascal@19515
|
185 mov [saved15],eax
|
pascal@19515
|
186 else
|
pascal@19876
|
187 mov ax,offset int15_88
|
pascal@19883
|
188 xchg ax,[es:bx+15*4]
|
pascal@19515
|
189 mov [word saved15],ax
|
pascal@19876
|
190 mov ax,cs
|
pascal@19883
|
191 xchg ax,[es:bx+15*4+2]
|
pascal@19515
|
192 mov [word saved15+2],ax
|
pascal@19515
|
193 endif
|
pascal@19515
|
194 @@skip:
|
pascal@19515
|
195 ret
|
pascal@19515
|
196 int15_88:
|
pascal@19515
|
197 cmp ah,88h
|
pascal@19515
|
198 je @@do88
|
pascal@19876
|
199 @@jmp_saved15:
|
pascal@19515
|
200 jmp [saved15]
|
pascal@19515
|
201 @@do88:
|
pascal@19515
|
202 pushf
|
pascal@19876
|
203 call @@jmp_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 ############################################
|