wok-current view linld/stuff/src/A20.ASM @ rev 22181
linld: check memory size for vcpi
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Nov 10 11:45:54 2019 +0100 (2019-11-10) |
parents | ee7d4644eb13 |
children | f25cb816bdd9 |
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 p8086
11 group DGROUP _TEXT,_DATA
12 assume cs:DGROUP,ds:DGROUP
14 segment _DATA byte public use16 'DATA'
16 global die:near
17 enable_a20_methods:
18 dw _enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die
19 msg_a20 db "Can't use A20",0
20 overflow db "Out of memory",0
21 global sssp:dword
22 global _initrd_desc:dword
23 _initrd_desc dd 90000218h
24 org $-4
25 sssp dd ?
27 ends _DATA
29 segment _TEXT byte public use16 'CODE'
31 global xmm_driver:near
32 global _enable_a20_xmm:near
34 ;***************************************************************
35 ;void enable_a20_kbd();
36 ;***************************************************************
37 proc _enable_a20_kbd near
39 call @@empty_8042
40 mov al,0D1h ; command write
41 out 64h,al
42 call @@empty_8042
43 mov al,0DFh ; A20 on
44 out 60h,al
46 ; This routine checks that the keyboard command queue is empty
47 ; (after emptying the output buffers)
48 ; Some machines have delusions that the keyboard buffer is always full
49 ; with no keyboard attached...
50 ; If there is no keyboard controller, we will usually get 0xff
51 ; to all the reads. With each IO taking a microsecond and
52 ; a timeout of 100,000 iterations, this can take about half a
53 ; second ("delay" == out to port 0x80). That should be ok,
54 ; and should also be plenty of time for a real keyboard controller
55 ; to empty.
57 @@empty_8042:
58 xor cx,cx ; 64K iterations
59 @@loop:
60 call @@delay ; 8042 status port
61 in al,64h
62 test al,3 ; is output or input full?
63 jz @@break ; no - break loop
64 test al,1 ;
65 jz @@no_output
66 call @@delay ; yes: read it
67 in al,60h ;
68 @@no_output:
69 loop @@loop
70 @@break:
71 ret
73 @@delay: out 80h,al
74 ret
76 endp _enable_a20_kbd
78 ;***************************************************************
79 ;void enable_a20_fast();
80 ;***************************************************************
81 proc _enable_a20_fast near
83 ; You must preserve the other bits here. Otherwise embarrasing things
84 ; like laptops powering off on boot happen. Corrected version by Kira
85 ; Brown from Linux 2.2
86 in al,92h ;
87 or al,02h ; "fast A20" version
88 out 92h,al ; some chips have only this
89 ret
91 endp _enable_a20_fast
93 include "himem.inc"
95 ;***************************************************************
96 ;_fastcall void moverm(bx:struct himem *m);
97 ;***************************************************************
99 global @moverm$qp11image_himem:near
100 @moverm$qp11image_himem:
101 push si di
102 xor di,di
103 extrn _heap_top:word
104 ifdef NO386
105 mov ax,[_heap_top]
106 mov cl,4
107 shr ax,cl
108 mov dx,cs
109 add dx,ax
110 mov cx,0fffh
111 extrn _pm_high:byte
112 test [_pm_high],cl
113 jne @bzimage
114 xchg ax,dx
115 cmp ax,cx
116 jae @sys@ok
117 xchg ax,cx
118 @sys@ok:
119 inc ax
120 extrn N_LXLSH@4:near
121 call N_LXLSH@4
122 mov [word ((image_himem bx).fallback)],ax
123 mov [word ((image_himem bx).fallback)+2],dx
124 add ax,[word ((image_himem bx).size)]
125 adc dx,[word ((image_himem bx).size)+2]
126 ifdef MOVE_SETUP
127 mov di,8000h
128 sub di,[bx-4] ; rm size
129 extrn _rm_offset:word
130 mov [_rm_offset],di
131 sub ax,di ; -rm_offset
132 sbb dx,cx
133 endif
134 mov cl,12
135 shl dx,cl
136 jc @overflow
137 @bzimage:
138 extrn _topseg:near
139 call near _topseg
140 mov [word sssp+2],ax
141 else
142 p386
143 movzx eax,[word _heap_top]
144 shr ax,4
145 mov dx,cs
146 add ax,dx
147 mov cx,0fffh
148 extrn _pm_high:byte
149 test [_pm_high],cl
150 jne @bzimage
151 cmp ax,cx
152 jae @sys@ok
153 xchg ax,cx
154 @sys@ok:
155 inc ax
156 shl eax,4
157 mov [(image_himem bx).fallback],eax
158 add eax,[(image_himem bx).size]
159 ifdef MOVE_SETUP
160 mov di,8000h
161 sub di,[bx-4] ; rm size
162 extrn _rm_offset:word
163 mov [_rm_offset],di
164 movzx ecx,di ; -rm_offset
165 sub eax,ecx
166 endif
167 shl eax,4
168 mov ch,0
169 @bzimage:
170 xchg ax,dx
171 mov ax,9000h
172 endif
173 add dh,ch ; room for malloc_bufv_or_die
174 cmp dx,ax
175 jb @nooverflow
176 @overflow:
177 ; Oops! We can stomp on our toes... better stop now
178 mov bx,offset overflow
179 call near die
180 @nooverflow:
181 les cx,[bx-4] ; rm size
182 mov si,es ; rm data
183 mov es,ax
184 @@move_clear:
185 movsb
186 mov [byte si-1],al
187 loop @@move_clear
188 ;push ds
189 ;pop es
190 ;pop di si
191 pop di
193 ;***************************************************************
194 ;void enable_a20_or_die();
195 ;***************************************************************
196 proc _enable_a20_or_die near
198 ;push si
199 mov si,offset enable_a20_methods
200 jmp @@check
201 @@loop:
202 lodsw
203 mov bx,offset msg_a20
204 call ax
205 @@check:
206 ;call _check_a20
207 ;***************************************************************
208 ;int check_a20();
209 ;***************************************************************
210 ;proc _check_a20 near
212 ; From linux kernel setup.S:
213 ; wait until a20 really *is* enabled; it can take a fair amount of
214 ; time on certain systems; Toshiba Tecras are known to have this
215 ; problem.
217 push ds
218 xor bx,bx
219 mov ds,bx
220 mov cx,0FFFFh
221 mov es,cx
222 a20lp:
223 cli
224 mov ax,0AA55h
225 xchg al,[bx]
226 xchg ah,[es:bx+10h]
227 xchg al,[bx]
228 xchg ah,[es:bx+10h]
229 cmp al,55h
230 sti
231 a20ko:
232 loopne a20lp
233 ;xchg ax,cx
234 pop ds
235 ;ret
237 ;endp _check_a20
239 jne @@loop
240 ;push ds
241 ;pop es
242 pop si
243 ret
245 endp _enable_a20_or_die
247 ends _TEXT
249 end
251 ;###### END OF FILE ############################################