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

linld: spare up to 30k more for zImage
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 08 20:55:40 2019 +0100 (5 weeks ago)
parents a0dccc5d133d
children 65ea21135647
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 "Loaded too close to 9000:0",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 ;***************************************************************
94 ;_fastcall void moverm(bx:struct himem *m);
95 ;***************************************************************
97 global @moverm$qp11image_himem:near
98 @moverm$qp11image_himem:
99 push si di
100 extrn _heap_top:word
101 ifdef NO386
102 mov ax,[_heap_top]
103 mov cl,4
104 shr ax,cl
105 mov dx,cs
106 add dx,ax
107 extrn _topseg:near
108 call near _topseg
109 mov [word sssp+2],ax
110 else
111 p386
112 mov ax,[_heap_top]
113 shr ax,4
114 mov dx,cs
115 add dx,ax
116 mov ax,9000h
117 endif
118 mov es,ax
119 cmp dx,ax
120 jb @@nooverflow
121 ; Oops! We can stomp on our toes... better stop now
122 mov bx,offset overflow
123 call near die
124 @@nooverflow:
125 mov cx,[bx-5] ; size
126 mov si,[bx-2] ; data
127 xor di,di
128 ifdef MOVE_SETUP
129 extrn _pm_high:byte
130 cmp [_pm_high],al
131 jne @@move_clear
132 mov di,8000h
133 sub di,cx
134 extrn _rm_offset:word
135 mov [_rm_offset],di
136 endif
137 @@move_clear:
138 movsb
139 mov [byte si-1],al
140 loop @@move_clear
141 ;push ds
142 ;pop es
143 ;pop di si
144 pop di
146 ;***************************************************************
147 ;void enable_a20_or_die();
148 ;***************************************************************
149 proc _enable_a20_or_die near
151 ;push si
152 mov si,offset enable_a20_methods
153 jmp @@check
154 @@loop:
155 lodsw
156 mov bx,offset msg_a20
157 call ax
158 @@check:
159 ;call _check_a20
160 ;***************************************************************
161 ;int check_a20();
162 ;***************************************************************
163 ;proc _check_a20 near
165 ; From linux kernel setup.S:
166 ; wait until a20 really *is* enabled; it can take a fair amount of
167 ; time on certain systems; Toshiba Tecras are known to have this
168 ; problem.
170 push ds
171 xor bx,bx
172 mov ds,bx
173 mov cx,0FFFFh
174 mov es,cx
175 a20lp:
176 cli
177 mov ax,0AA55h
178 xchg al,[bx]
179 xchg ah,[es:bx+10h]
180 xchg al,[bx]
181 xchg ah,[es:bx+10h]
182 cmp al,55h
183 sti
184 a20ko:
185 loopne a20lp
186 ;xchg ax,cx
187 pop ds
188 ;ret
190 ;endp _check_a20
192 jne @@loop
193 ;push ds
194 ;pop es
195 pop si
196 ret
198 endp _enable_a20_or_die
200 ends _TEXT
202 end
204 ;###### END OF FILE ############################################