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

tazboot: spave 40k+ for zImage
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jun 24 16:31:09 2019 +0200 (2019-06-24)
parents 76087975885f
children d8f824013cf6
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p8086
10 group DGROUP _TEXT,_DATA
11 assume cs:DGROUP,ds:DGROUP
13 segment _DATA byte public use16 'DATA'
15 global die:near
16 enable_a20_methods:
17 dw _enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die
18 msg_a20 db "Can't use A20",0
19 overflow db "Loaded too close to 9000:0",0
21 ends _DATA
23 segment _TEXT byte public use16 'CODE'
25 global xmm_driver:near
26 global _enable_a20_xmm:near
28 ;***************************************************************
29 ;void enable_a20_kbd();
30 ;***************************************************************
31 proc _enable_a20_kbd near
33 call @@empty_8042
34 mov al,0D1h ; command write
35 out 64h,al
36 call @@empty_8042
37 mov al,0DFh ; A20 on
38 out 60h,al
40 ; This routine checks that the keyboard command queue is empty
41 ; (after emptying the output buffers)
42 ; Some machines have delusions that the keyboard buffer is always full
43 ; with no keyboard attached...
44 ; If there is no keyboard controller, we will usually get 0xff
45 ; to all the reads. With each IO taking a microsecond and
46 ; a timeout of 100,000 iterations, this can take about half a
47 ; second ("delay" == out to port 0x80). That should be ok,
48 ; and should also be plenty of time for a real keyboard controller
49 ; to empty.
51 @@empty_8042:
52 xor cx,cx ; 64K iterations
53 @@loop:
54 call @@delay ; 8042 status port
55 in al,64h
56 test al,3 ; is output or input full?
57 jz @@break ; no - break loop
58 test al,1 ;
59 jz @@no_output
60 call @@delay ; yes: read it
61 in al,60h ;
62 @@no_output:
63 loop @@loop
64 @@break:
65 ret
67 @@delay: out 80h,al
68 ret
70 endp _enable_a20_kbd
72 ;***************************************************************
73 ;void enable_a20_fast();
74 ;***************************************************************
75 proc _enable_a20_fast near
77 ; You must preserve the other bits here. Otherwise embarrasing things
78 ; like laptops powering off on boot happen. Corrected version by Kira
79 ; Brown from Linux 2.2
80 in al,92h ;
81 or al,02h ; "fast A20" version
82 out 92h,al ; some chips have only this
83 ret
85 endp _enable_a20_fast
87 ;***************************************************************
88 ;_fastcall void moverm(bx:struct himem *m);
89 ;***************************************************************
91 global @moverm$qp11image_himem:near
92 @moverm$qp11image_himem:
93 push si di
94 global sssp:dword
95 extrn _heap_top:word
96 ifdef NO386
97 extrn _topseg:near
98 call near _topseg
99 mov cl,4
100 org $-4
101 sssp dd ?
102 mov [word sssp+2],ax
103 ;extrn _initrd_desc:dword
104 ;mov [word _initrd_desc+2],ax
105 xchg ax,dx
106 mov ax,[_heap_top]
107 shr ax,cl
108 else
109 p386
110 mov ax,[_heap_top]
111 shr ax,4
112 mov dx,9000h
113 org $-4
114 sssp dd ?
115 endif
116 mov es,dx
117 mov cx,cs
118 add ax,cx
119 cmp ax,dx
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 rep
129 movsb
130 ;push ds
131 ;pop es
132 ;pop di si
133 pop di
135 ;***************************************************************
136 ;void enable_a20_or_die();
137 ;***************************************************************
138 proc _enable_a20_or_die near
140 ;push si
141 mov si,offset enable_a20_methods
142 jmp @@check
143 @@loop:
144 lodsw
145 mov bx,offset msg_a20
146 call ax
147 @@check:
148 ;call _check_a20
149 ;***************************************************************
150 ;int check_a20();
151 ;***************************************************************
152 ;proc _check_a20 near
154 ; From linux kernel setup.S:
155 ; wait until a20 really *is* enabled; it can take a fair amount of
156 ; time on certain systems; Toshiba Tecras are known to have this
157 ; problem.
159 push ds
160 xor bx,bx
161 mov ds,bx
162 mov cx,0FFFFh
163 mov es,cx
164 a20lp:
165 cli
166 mov ax,0AA55h
167 xchg al,[bx]
168 xchg ah,[es:bx+10h]
169 xchg al,[bx]
170 xchg ah,[es:bx+10h]
171 cmp al,55h
172 sti
173 a20ko:
174 loopne a20lp
175 ;xchg ax,cx
176 pop ds
177 ;ret
179 ;endp _check_a20
181 jne @@loop
182 ;push ds
183 ;pop es
184 pop si
185 ret
187 endp _enable_a20_or_die
189 ends _TEXT
191 end
193 ;###### END OF FILE ############################################