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

linld: spare up to 30k more for zImage (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 09 17:39:43 2019 +0100 (2019-11-09)
parents 65ea21135647
children 08212b207b25
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 extrn _pm_high:byte
103 mov si,offset _pm_high
104 ifdef MOVE_SETUP
105 mov di,8000h
106 sub di,[bx-4] ; rm size
107 extrn _rm_offset:word
108 mov [_rm_offset],di
109 endif
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
117 mov cx,0fffh
118 test [byte si],cl
119 jne @bzimage
120 xchg ax,dx
121 cmp ax,cx
122 jae @sys@ok
123 xchg ax,cx
124 @sys@ok:
125 inc ax
126 extrn N_LXLSH@4:near
127 call N_LXLSH@4
128 mov [word ((image_himem bx).fallback)],ax
129 mov [word ((image_himem bx).fallback)+2],dx
130 add ax,[word ((image_himem bx).size)]
131 adc dx,[word ((image_himem bx).size)+2]
132 ifdef MOVE_SETUP
133 sub ax,di ; -rm_offset
134 sbb dx,cx
135 endif
136 mov cl,12
137 shl dx,cl
138 jc @overflow
139 @bzimage:
140 extrn _topseg:near
141 call near _topseg
142 mov [word sssp+2],ax
143 else
144 p386
145 movzx eax,[word _heap_top]
146 shr ax,4
147 mov dx,cs
148 add ax,dx
149 mov cx,0fffh
150 test [byte si],cl
151 jne @bzimage
152 cmp ax,cx
153 jae @sys@ok
154 xchg ax,cx
155 @sys@ok:
156 inc ax
157 shl eax,4
158 mov [(image_himem bx).fallback],eax
159 add eax,[(image_himem bx).size]
160 ifdef MOVE_SETUP
161 extrn _rm_offset:word
162 movzx ecx,di ; -rm_offset
163 sub eax,ecx
164 endif
165 shl eax,4
166 @bzimage:
167 xchg ax,dx
168 mov ax,9000h
169 endif
170 mov es,ax
171 cmp dx,ax
172 jb @nooverflow
173 @overflow:
174 ; Oops! We can stomp on our toes... better stop now
175 mov bx,offset overflow
176 call near die
177 @nooverflow:
178 ifdef MOVE_SETUP
179 cmp [si],al
180 je @@do_move
181 endif
182 xor di,di
183 @@do_move:
184 mov si,[bx-2] ; rm data
185 mov cx,[bx-4] ; rm size
186 @@move_clear:
187 movsb
188 mov [byte si-1],al
189 loop @@move_clear
190 ;push ds
191 ;pop es
192 ;pop di si
193 pop di
195 ;***************************************************************
196 ;void enable_a20_or_die();
197 ;***************************************************************
198 proc _enable_a20_or_die near
200 ;push si
201 mov si,offset enable_a20_methods
202 jmp @@check
203 @@loop:
204 lodsw
205 mov bx,offset msg_a20
206 call ax
207 @@check:
208 ;call _check_a20
209 ;***************************************************************
210 ;int check_a20();
211 ;***************************************************************
212 ;proc _check_a20 near
214 ; From linux kernel setup.S:
215 ; wait until a20 really *is* enabled; it can take a fair amount of
216 ; time on certain systems; Toshiba Tecras are known to have this
217 ; problem.
219 push ds
220 xor bx,bx
221 mov ds,bx
222 mov cx,0FFFFh
223 mov es,cx
224 a20lp:
225 cli
226 mov ax,0AA55h
227 xchg al,[bx]
228 xchg ah,[es:bx+10h]
229 xchg al,[bx]
230 xchg ah,[es:bx+10h]
231 cmp al,55h
232 sti
233 a20ko:
234 loopne a20lp
235 ;xchg ax,cx
236 pop ds
237 ;ret
239 ;endp _check_a20
241 jne @@loop
242 ;push ds
243 ;pop es
244 pop si
245 ret
247 endp _enable_a20_or_die
249 ends _TEXT
251 end
253 ;###### END OF FILE ############################################