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

linld: clear heap in moverm
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 08 10:47:52 2019 +0100 (2019-11-08)
parents 6e3d30b3031f
children 10fa26e4c60d
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 @@move_clear:
128 movsb
129 mov [byte si-1],0
130 loop @@move_clear
131 ;push ds
132 ;pop es
133 ;pop di si
134 pop di
136 ;***************************************************************
137 ;void enable_a20_or_die();
138 ;***************************************************************
139 proc _enable_a20_or_die near
141 ;push si
142 mov si,offset enable_a20_methods
143 jmp @@check
144 @@loop:
145 lodsw
146 mov bx,offset msg_a20
147 call ax
148 @@check:
149 ;call _check_a20
150 ;***************************************************************
151 ;int check_a20();
152 ;***************************************************************
153 ;proc _check_a20 near
155 ; From linux kernel setup.S:
156 ; wait until a20 really *is* enabled; it can take a fair amount of
157 ; time on certain systems; Toshiba Tecras are known to have this
158 ; problem.
160 push ds
161 xor bx,bx
162 mov ds,bx
163 mov cx,0FFFFh
164 mov es,cx
165 a20lp:
166 cli
167 mov ax,0AA55h
168 xchg al,[bx]
169 xchg ah,[es:bx+10h]
170 xchg al,[bx]
171 xchg ah,[es:bx+10h]
172 cmp al,55h
173 sti
174 a20ko:
175 loopne a20lp
176 ;xchg ax,cx
177 pop ds
178 ;ret
180 ;endp _check_a20
182 jne @@loop
183 ;push ds
184 ;pop es
185 pop si
186 ret
188 endp _enable_a20_or_die
190 ends _TEXT
192 end
194 ;###### END OF FILE ############################################