wok view linld/stuff/src/A20.ASM @ rev 25037

Up glza (0.11.4)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 21 21:38:29 2022 +0000 (2022-05-21)
parents 61df94a0fa43
children
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
9 p8086
11 include "common.inc"
13 group DGROUP _TEXT,_DATA
14 assume cs:DGROUP,ds:DGROUP
16 segment _DATA byte public use16 'DATA'
18 global die:near
19 enable_a20_methods:
20 dw _enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die
21 msg_a20 db "A20 broken",0
22 extrn overflow:byte
23 ifdef NO386
24 bzimage86 db "8086 "
25 endif
26 global _bzimagestr:byte
27 _bzimagestr db "bzImage",0
28 global sssp:dword
29 global _initrd_desc:dword
30 _initrd_desc dd 90000218h
31 org $-4
32 sssp dd ?
34 ends _DATA
36 segment _TEXT byte public use16 'CODE'
38 global xmm_driver:near
39 global _enable_a20_xmm:near
41 ;***************************************************************
42 ;void enable_a20_kbd();
43 ;***************************************************************
44 proc _enable_a20_kbd near
46 call @@empty_8042
47 mov al,0D1h ; command write
48 out 64h,al
49 call @@empty_8042
50 mov al,0DFh ; A20 on
51 out 60h,al
53 ; This routine checks that the keyboard command queue is empty
54 ; (after emptying the output buffers)
55 ; Some machines have delusions that the keyboard buffer is always full
56 ; with no keyboard attached...
57 ; If there is no keyboard controller, we will usually get 0xff
58 ; to all the reads. With each IO taking a microsecond and
59 ; a timeout of 100,000 iterations, this can take about half a
60 ; second ("delay" == out to port 0x80). That should be ok,
61 ; and should also be plenty of time for a real keyboard controller
62 ; to empty.
64 @@empty_8042:
65 xor cx,cx ; 64K iterations
66 @@loop:
67 call @@delay ; 8042 status port
68 in al,64h
69 test al,3 ; is output or input full?
70 jz @@break ; no - break loop
71 test al,1 ;
72 jz @@no_output
73 call @@delay ; yes: read it
74 in al,60h ;
75 @@no_output:
76 loop @@loop
77 @@break:
78 ret
80 @@delay: out 80h,al
81 ret
83 endp _enable_a20_kbd
85 ;***************************************************************
86 ;void enable_a20_fast();
87 ;***************************************************************
88 proc _enable_a20_fast near
90 ; You must preserve the other bits here. Otherwise embarrasing things
91 ; like laptops powering off on boot happen. Corrected version by Kira
92 ; Brown from Linux 2.2
93 in al,92h ;
94 or al,02h ; "fast A20" version
95 out 92h,al ; some chips have only this
96 ret
98 endp _enable_a20_fast
100 include "himem.inc"
102 ;***************************************************************
103 ;_fastcall void moverm(bx:u16 *p);
104 ;***************************************************************
106 global @moverm$qpus:near
107 @moverm$qpus:
108 push si di
109 xor di,di ; default setup 9000:0000
110 extrn _heap_top:word
111 ifdef NO386
112 mov ax,[_heap_top]
113 mov cl,4
114 shr ax,cl
115 mov dx,cs
116 add dx,ax ; last used segment
117 mov cx,0fffh
118 extrn _pm_low:byte
119 test [_pm_low],cl
120 jne @zimage
121 extrn _cpu386:byte
122 test [_cpu386],cl
123 jne @bzimage
124 mov bx,offset bzimage86 ; no himem with 8086 !
125 @godie:
126 call near die
127 @zimage:
128 xchg ax,dx
129 cmp ax,cx
130 jae @sys@ok
131 xchg ax,cx ; segment min 1000h
132 @sys@ok:
133 inc ax ; first free segment
134 extrn N_LXLSH@4:near
135 call N_LXLSH@4
136 mov [word ((image_himem bx+4).fallback)],ax
137 mov [word ((image_himem bx+4).fallback)+2],dx
138 add ax,[word ((image_himem bx+4).size)]
139 adc dx,[word ((image_himem bx+4).size)+2]
140 ifdef MOVE_SETUP
141 mov di,8000h
142 sub di,[bx] ; rm_size
143 extrn _rm_offset:word
144 mov [_rm_offset],di
145 sub ax,di ; -rm_offset
146 sbb dx,cx
147 endif
148 mov cl,12
149 shl dx,cl ; last sys segment
150 ifndef LARGE_ZIMAGE
151 ;jc @jbe_overflow ; >= 1Mb ???
152 else
153 ;jnc @bzimage ; < 1Mb
154 ;mov dh,-1
155 endif
156 @bzimage:
157 extrn _topseg:near
158 call near _topseg
159 mov [word sssp+2],ax
160 ifdef VCPI
161 and ch,0 ; vcpi flag
162 org $-1
163 global _vcpi:byte
164 _vcpi db ?
165 endif
166 else
167 p386
168 movzx eax,[word _heap_top]
169 shr ax,4
170 mov dx,cs
171 add ax,dx ; last used segment
172 mov cx,0fffh
173 extrn _pm_low:byte
174 test [_pm_low],cl
175 je @bzimage
176 cmp ax,cx
177 jae @sys@ok
178 xchg ax,cx ; segment min 1000h
179 @sys@ok:
180 inc ax ; first free segment
181 shl eax,4
182 mov [(image_himem bx+4).fallback],eax
183 add eax,[(image_himem bx+4).size]
184 ifdef MOVE_SETUP
185 mov di,8000h
186 sub di,[bx] ; rm_size
187 extrn _rm_offset:word
188 mov [_rm_offset],di
189 movzx ecx,di ; -rm_offset
190 sub eax,ecx
191 endif
192 shr eax,4
193 ifdef VCPI
194 mov ch,0
195 endif
196 @bzimage:
197 xchg ax,dx
198 mov ax,9000h
199 ifdef VCPI
200 extrn _vcpi:byte
201 and ch,[_vcpi]
202 endif
203 endif
204 ifdef VCPI
205 add dh,ch ; 60k room for malloc_bufv_or_die
206 endif
207 cmp ax,dx
208 ifdef LARGE_ZIMAGE
209 ja @nooverflow0
210 extrn _cmdnum:dword
211 base_himem = (dword _cmdnum+12)
212 ifdef NO386
213 les cx,[base_himem]
214 mov [word ((image_himem bx+4).fallback)],cx
215 mov [word ((image_himem bx+4).fallback)+2],es
216 else
217 mov ecx,[base_himem]
218 mov [(image_himem bx+4).fallback],ecx
219 endif
220 @nooverflow0:
221 endif
222 les cx,[bx] ; rm_size
223 mov si,es ; rm_buf
224 ifndef LARGE_ZIMAGE
225 @jbe_overflow:
226 ; Oops! We can stomp on our toes... better stop now
227 mov bx,offset overflow
228 ifdef NO386
229 jbe @godie
230 else
231 ja @nooverflow
232 call near die
233 @nooverflow:
234 endif
235 endif
236 mov es,ax
237 @@move_clear:
238 movsb
239 mov [byte si-1],al
240 loop @@move_clear
241 ;push ds
242 ;pop es
243 ;pop di si
244 pop di
246 ;***************************************************************
247 ;void enable_a20_or_die();
248 ;***************************************************************
249 proc _enable_a20_or_die near
251 ;push si
252 mov si,offset enable_a20_methods
253 jmp @@check
254 @@loop:
255 lodsw
256 mov bx,offset msg_a20
257 call ax
258 @@check:
259 ;call _check_a20
260 ;***************************************************************
261 ;int check_a20();
262 ;***************************************************************
263 ;proc _check_a20 near
265 ; From linux kernel setup.S:
266 ; wait until a20 really *is* enabled; it can take a fair amount of
267 ; time on certain systems; Toshiba Tecras are known to have this
268 ; problem.
270 push ds
271 xor bx,bx
272 mov ds,bx
273 mov cx,0FFFFh
274 mov es,cx
275 a20lp:
276 cli ; A20 off A20 on
277 mov ax,0AA55h ; al ah [bx] al ah [bx] es:[bx+10h]
278 xchg al,[bx] ; ?? AA 55 ?1 AA 55 ?2
279 xchg ah,[es:bx+10h] ; ?? 55 AA ?1 ?2 55 AA
280 xchg al,[bx] ; AA 55 ?? 55 ?2 ?1 AA
281 cmp al,55h
282 sti
283 loopne a20lp
284 jne a20ko
285 xchg ah,[es:bx+10h] ; AA ?? 55 55 AA ?1 ?2
286 a20ko:
287 ;xchg ax,cx
288 pop ds
289 ;ret
291 ;endp _check_a20
293 jne @@loop
294 ;push ds
295 ;pop es
296 pop si
297 ret
299 endp _enable_a20_or_die
301 ends _TEXT
303 end
305 ;###### END OF FILE ############################################