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

linld: x86 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Oct 14 11:20:06 2019 +0200 (2019-10-14)
parents d8f824013cf6
children a0dccc5d133d
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 extrn _topseg:near
103 call near _topseg
104 mov cl,4
105 mov [word sssp+2],ax
106 xchg ax,dx
107 mov ax,[_heap_top]
108 shr ax,cl
109 else
110 p386
111 mov ax,[_heap_top]
112 shr ax,4
113 mov dx,9000h
114 endif
115 mov es,dx
116 mov cx,cs
117 add ax,cx
118 cmp ax,dx
119 jb @@nooverflow
120 ; Oops! We can stomp on our toes... better stop now
121 mov bx,offset overflow
122 call near die
123 @@nooverflow:
124 mov cx,[bx-5] ; size
125 mov si,[bx-2] ; data
126 xor di,di
127 rep
128 movsb
129 ;push ds
130 ;pop es
131 ;pop di si
132 pop di
134 ;***************************************************************
135 ;void enable_a20_or_die();
136 ;***************************************************************
137 proc _enable_a20_or_die near
139 ;push si
140 mov si,offset enable_a20_methods
141 jmp @@check
142 @@loop:
143 lodsw
144 mov bx,offset msg_a20
145 call ax
146 @@check:
147 ;call _check_a20
148 ;***************************************************************
149 ;int check_a20();
150 ;***************************************************************
151 ;proc _check_a20 near
153 ; From linux kernel setup.S:
154 ; wait until a20 really *is* enabled; it can take a fair amount of
155 ; time on certain systems; Toshiba Tecras are known to have this
156 ; problem.
158 push ds
159 xor bx,bx
160 mov ds,bx
161 mov cx,0FFFFh
162 mov es,cx
163 a20lp:
164 cli
165 mov ax,0AA55h
166 xchg al,[bx]
167 xchg ah,[es:bx+10h]
168 xchg al,[bx]
169 xchg ah,[es:bx+10h]
170 cmp al,55h
171 sti
172 a20ko:
173 loopne a20lp
174 ;xchg ax,cx
175 pop ds
176 ;ret
178 ;endp _check_a20
180 jne @@loop
181 ;push ds
182 ;pop es
183 pop si
184 ret
186 endp _enable_a20_or_die
188 ends _TEXT
190 end
192 ;###### END OF FILE ############################################