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