|
|
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。- ;A200N.ASM , E$ z! W8 ^% u1 O
- ;
6 H/ w; }( I: D! G9 ^2 D - ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
$ b& ^+ {& m; V) B/ _; l! Z4 N M9 l6 z - ; ml A20ON.asm
% m5 \& v7 p3 _ - ;
3 E8 p, q6 e8 K' q$ u - .model tiny Z) F8 R( ?- V% I( ~) x. C
- .code& j5 V+ `# ~, _3 K Q
- .486; B- N4 [! s7 ~+ y3 @: \$ n I# Z7 D
- .startup
0 ^8 \9 ~2 _9 ]; ], F - ' x$ T; n% v( ^7 R# U; \( t4 [
- mov dx, offset msg_author- R" C% x* {0 n
- mov ah, 09h7 ~8 m) T6 j3 Y m
- int 21h7 C, _8 W0 {$ k- ?# b3 j
. y' y x, m/ K" u" U- mov dx, offset msg_fail * u0 c7 c* o& a6 H8 `9 a
- call A20_ENABLE
1 q: a1 W A5 B5 r, B5 X0 d, t - jz exit1
5 s/ \9 ~, `* M! I0 J. ^" f2 P* g - mov dx, offset msg_ok 4 C* A( N& l {6 @5 G! D
9 \& L% D! ~5 F: h0 o f; ?6 I6 X }- exit1: mov ah, 09h
6 u* |$ m* O( g! q- b - int 21h 3 v( B% o D' u, n/ ~7 Y( o
- mov ax, 4C00h
2 Z' P9 ]+ y9 X) D+ ] - int 21h 7 u- J" Z( _: R8 q0 z
- D7 g! V- z. R# {4 p" z
- msg_author db "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
( n; @1 l6 Z1 ~! B5 a& F! j! V - "2008-07-01",13, 10, "$" 2 Z5 `2 i$ U" e2 z% _. F
- msg_ok db "A20 Enable OK", 13, 10, "$" 1 m) [' K6 f' k8 `/ i. r, C
- msg_fail db "A20 Enable FAIL", 13, 10, "$"
8 T' x* o1 s0 H- C; k1 O
. p2 |, O( E- l; N+ `& f I- x3 }- ;------------------------ follow code maybe make to lib, if you want...-------------------------------
7 \; J8 ?4 l4 Y0 _1 M6 d - A20_ENABLE: 8 a2 ], s7 q( w! i
- call A20Write , @: R$ ]) P1 e5 b, w- Q& C0 a
- jz exit_enable( y1 J4 s. Q: q' m
- # S* s/ C6 N9 B# e" Y! R; S) y1 r
- cli ; Only need for reading value from KBC
/ _# B; r' I \9 ] - mov al, 0D0h ) }4 O8 G, j: |$ h
- out 64h, al + I2 N0 w% m$ x7 c& w
- call A20Read
' d3 P6 E1 {+ Q) w - jz enable_int
. {; ~2 b5 R0 q, o7 x - w$ s# [+ X) h4 s- X) o% ^
- in al, 60h ; Get current status , D" m% n! R, h) N+ d
- mov ah, al
* z- t5 Z% L) J% N9 j. b: C: B5 Y$ H - call A20Write
; M0 o2 h* o4 v, G' h3 o/ m8 q9 u9 _ - enable_int: sti
/ P# R6 I ~+ {3 ?3 W. W( ?, E. ? - jz exit_enable; y, z! ?2 V8 v# d3 H9 e
8 O: d$ _0 n" z+ z% Z- mov al, 0D1h ; Tell the KBC , want to write to the
( o/ p1 ^, q: t, H/ c - out 64h, al ; Out Put Port next " A# Z, |# N4 z% {% J" D. u( T
- call A20Write - m) u9 C' f2 X& \$ `( t6 T K
- jz exit_enable9 r/ Z8 Q3 J1 z( x$ K/ P$ O
3 s" Y5 t% a- G. S* V* r- mov al, ah
4 R, w5 h; b' c. j; F' t - or al, 2 ; Enable line A20
8 H% b& t2 w8 O/ E6 k: p0 h - out 60h, al
6 |8 |1 y! O+ N# s: m; u/ q! a9 R* r - call A20Write ) X1 z5 u1 p3 m- X0 b3 ?9 d
- jz exit_enable
; [% X7 @* [% _1 V( h1 ?4 Z: m - 2 r% K% B/ ?( r- u9 Y8 g( w# r
- mov al, 0FFh ; NOP
: F3 z* f. Y5 g d) _/ H0 ], m - out 64h, al 3 \8 m# i& H! l( [: z2 A
- call A20Write
) K1 }4 o; R/ _9 u4 G3 o
5 C: R, `! L$ ]* @5 x. B7 @/ X- exit_enable: ret
9 M# Y9 Z; h' O1 L
) h$ o' Y, Z3 Z2 ~/ f- A20Write: xor cx, cx ; Reasonable wait 9 t& m( {( a! I3 i2 h& l
- get_wirte: in al, 64h ; Get KBC read status
/ A9 V' q( {2 p7 {3 D9 g - test al, 02 ; See if buffer empty, bit 1 clear # C( E" m3 ~7 v1 V4 U9 h) K
- jz clear
- a6 }/ K6 Q! g. W+ I2 [ - dec cx
7 n8 i1 K) e3 C. _ - jz exit_write
- W0 D* ^# |5 {6 l8 b/ ~ - jmp short get_wirte 1 P, ~0 U! S$ i m
- clear: inc al ; Clear ZR $ J2 N/ Q( y# X1 S7 M, T9 R
- exit_write: ret
! T e8 A* L) g! ]* O! T8 u0 R% W% w - " V2 f2 r: w, o4 z5 A( T1 M5 W
' J( L w; ^/ ]4 ^' _6 V3 q- A20Read: xor cx, cx / u$ a( z, u/ M; s! m0 c
- get_read: in al, 64h
* S, }& ^1 }) g$ V6 y1 f - test al, 01 ; If the 'output buffer' is full, has
' q! R k) J, \ - jnz exit4 ; ...
. q2 Z8 Q; F, B" ?. A& I8 r; E - dec cx
" W1 g2 J# p* |6 m4 A - jnz get_read/ H B. S( [3 q+ P+ x; j7 F
- exit4: ret
& z/ D$ P0 h. o; l. o' C - ( x8 R9 I* M. x# M# \/ l, L: p. L$ Z' P
- end
复制代码- ;A200FF.ASM ; R; G6 V2 _2 R
- ;
3 ]* X9 ` [. @( k - ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
" D( I2 g; {. [2 x - ; ml A20ON.asm
1 p$ {) e9 I( i1 {$ H h* Z5 U - ;
* H( l) Z! B# F/ i( y" Z8 a$ } - .model tiny
0 Z( F4 u( F x: Y. V$ O+ o r* j - .code7 \' X% J& M; J, K$ S8 K
- .486( p( r% ^' A) V8 \# d& {
- .startup* B2 k ]4 T! h `1 Z+ X
& o4 @8 U6 D; @& e& f" x+ O' c" M8 q- mov dx, offset msg_author
* C7 p6 C! x5 w5 m% d5 j - mov ah, 09h
" {7 k$ J; j% j7 g2 e - int 21h
3 K8 m* N9 e" I - % c) n* L' I" v
- mov dx, offset msg_fail D1 F8 ?5 K1 Y9 q% J
- call A20_DISABLE
2 c; r5 V0 r. U! U - jz exit1
4 S8 X# v5 m( p" J4 p4 F - mov dx, offset msg_ok
: J5 W) h7 X0 M/ D
% d. F% S! `( c- exit1: mov ah, 09h $ j0 M) N& L& x7 q9 `
- int 21h
1 A1 a4 w& p( }0 u/ v, c - mov ax, 4C00h ( {; V) t1 J1 |" i4 E
- int 21h & H4 R$ T1 q& p U% h& c
-
4 f' ?, o$ P" v' K# F - msg_author db "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
9 d* ]$ k- t0 u- M - "2008-07-01",13, 10, "$" 0 y3 t5 V+ v3 c; Y1 l& q# {
- msg_ok db "A20 Disable OK", 13, 10, "$" + J. T' w/ U1 W5 A
- msg_fail db "A20 Disable FAIL", 13, 10, "$" ! q8 O& S4 ~: q5 ^3 \9 w( g
2 G9 L. S7 q6 m. o- ;------------------------ follow code maybe make to lib, if you want...-------------------------------* Z x' e8 n, v' B4 ]
- A20_DISABLE:
9 I) C5 g% y9 u q - call A20Write
( Q: D) c1 d/ a0 T+ Q7 V - jz exit_disable
& r X8 X s. R
. J# m' D5 t4 ?2 F+ @6 }- cli ; Only need for reading value from KBC
9 |9 b) K" t' ]) m9 I0 w - mov al, 0D0h / E- K) B2 x6 `( Q w
- out 64h, al
* D% j$ s% K. M+ a - call A20Read
) a4 Y1 b8 F; X. E1 \$ y* c - jz Disable_int $ \2 S) F9 o+ h8 z6 Z
- / ]2 z( t; q7 ~ f
- in al, 60h ; Get current status 6 w6 Y; F W8 v7 ]4 B
- mov ah, al + L, Y# T7 B+ o* y1 Q* @* M& T. w
- call A20Write
2 c6 K4 @, k; i0 Z2 s6 m - Disable_int: sti * z0 L% V4 q7 T* Y
- jz exit_disable" Q! }# u! c& @8 a2 i+ o
- 5 B" d# H/ D6 L+ s6 x c1 f
- mov al, 0D1h ; Tell the KBC , want to write to the
& E; V) d* W) v% Y - out 64h, al ; Out Put Port next
5 q- i3 _3 E5 _+ F; ` - call A20Write 2 e p- A/ ~ k# V# F1 x
- jz exit_disable7 Q7 n( w" y& m9 I/ H
- ! T8 J7 `: b# s+ W- Q0 I V
- mov al, ah
0 H2 E* p I$ i' j6 o - and al, not 2 ; Disable line A20 ! l* f" r: N) `: F1 r
- out 60h, al
3 n1 y; r3 d3 ] j( |/ [" } f - call A20Write 9 ~/ t$ t% u7 k& d; { W& l
- jz exit_disable
' B8 J% z" i( @# Z8 L1 O
o; ]4 i. P, h, x: p- mov al, 0FFh ; NOP & t: _& M2 w1 l* t. X! T" U
- out 64h, al
# H C- C: H+ ]0 P( r- ?. O - call A20Write
: @3 E6 P2 M: m - * m/ g4 Q# Q$ s9 D* U
- exit_disable: ret , `0 c$ R6 p6 S& Q$ a
# r1 G' T5 j6 L% s6 Z* X$ m4 S; Y, X- A20Write: xor cx, cx ; Reasonable wait 9 U! K. V! S6 X; Y* O1 ]& j, b& @3 Y
- get_wirte: in al, 64h ; Get KBC read status
2 J! i; t" v5 j- y8 g - test al, 02 ; See if buffer empty, bit 1 clear 2 y, E- [6 ~' J- [& n# x
- jz clear
( ^# L& c ]0 A1 S) t7 ~ - dec cx
m- ?! u0 `3 t - jz exit_write
& w: R) L' z M4 g" W3 D0 V - jmp short get_wirte
% ~$ s9 M R( f( a7 E& S - clear: inc al ; Clear ZR 5 n$ F' n" [2 Z* {
- exit_write: ret 1 M5 u6 Z+ V0 U' I8 B: Q+ Y6 {
( w: J: y. H% z) t- + D& s* d# }3 E: t* p
- A20Read: xor cx, cx
/ c; R3 g$ _3 }7 V! l' V6 J9 | - get_read: in al, 64h Y- T; M7 W! Q6 I. Y9 i' p
- test al, 01 ; If the 'output buffer' is full, has & s! Q& `% D# A" L9 r. Y5 ^0 h
- jnz exit4 ; ... ' v2 u7 Q; ^. z. S: C D
- dec cx + g2 Q+ l& L. i" C' B! R
- jnz get_read
! M. j* m, z2 C6 k - exit4: ret
5 {: `( u* k `5 \ - ( w1 e; M9 j7 Z" Q$ A
- end
复制代码- ;A20STATE.ASM 8 _- i0 ^7 U9 y5 x
- ; + Z [. E/ L# m" G
- ; Returns the status of the line A20 through the KBC * e0 d* z, e1 U& n
- ; programming by bini for debug. 2008-07-01# O4 W0 K7 l7 T% B/ X: L" Z. T: m& }
- ;
* V7 U% g, N9 k4 X: M* u2 h - .model tiny- R2 \' k/ g* l- t, K; {# R
- .code
W9 [" a8 ]& ^/ J' B$ y' c - .486
; {+ y: ~& n% ] - .startup, Z$ |' D' R6 I1 H6 j1 M% p$ V$ l' U
- mov dx, offset msg_fail 2 y/ x4 T! p# I" h8 Y; \" ]( r" z
- call _GET_A20_STATE_
" A4 ?' a9 }1 l9 z+ _ - jz exit1 ; was a problem8 d; n8 m! `. S4 z! g1 @
- push ax ; Save state, AH U; V: M" E4 C5 w4 b0 f5 u9 H! {- r
- mov dx, offset msg_ok ; There wasn't a problem
5 a ?* p3 _/ G - mov ah, 09h 3 v; t8 J7 u9 O1 o5 @& `1 B
- int 21h ; Print message
# Y0 R7 C8 ~" X, g - pop ax ; retreve state
! N* o3 H: P7 K; f9 H& \
0 a9 U1 q1 w7 |! Z6 P& c- mov dx, offset msg_dis
* ]$ `5 U& F- R" }) y) i$ ] - and ah, 00000010b ; bit 1, 2h, indicates state ) y; x/ l& C6 d6 e
- jz exit1 9 w; T7 E/ x( ^' A4 k
- mov dx, offset msg_en
$ \9 H4 r; h1 b4 r3 m: R" G! b - " A# D8 S% Q$ T! D. y. v
- exit1: mov ah, 09h , Y2 R' W! K; L
- ; DX already contains address of string
/ O$ b1 w/ x! N1 I" o2 J - int 21h 5 F% B* K0 c {* R/ A% t2 f# u5 Y+ S( z
- # w0 M; \5 b! h. K
- mov ax, 4C00h
C4 [6 |: E( ] - int 21h
% N* A; Q9 l! D8 X5 C5 m9 ` - ) L/ a. o4 B$ |5 k* z( _% \7 b
- msg_ok db "OK", 13, 10, "A20 $" ) |0 I+ F" N. [' H! F
- msg_fail db "FAIL", 13, 10, "$" 5 S( e( T; @. X, A6 i
- msg_en db "ENABLED", 13, 10, "$"
+ w O. H O8 r# T. K - msg_dis db "DISABLED", 13, 10, "$"
1 b6 O" S7 y+ Y& B - : R9 n M7 I; J: `) c
- 2 e! W, b. V$ {" V. E+ @
- _GET_A20_STATE_:
* w( E/ J$ J6 b! m/ N7 S% h - call A20Write ; Wait till the input register is empty
3 f G& q, |1 @& l6 m2 E2 E; d - jz exit2+1 ; Bypas the reset int's
' x* T; [( y, G - cli ; Disable ints so we'll get our value / |7 n g5 Y q
+ b: f! _0 Y1 R; P/ f ], W- mov al, 0D0h ; Send command to the 8042 command register
7 W. l, n- h! H/ z; G* O - out 64h, al ; to tell it we want to Read the Output Port 0 t; |3 @5 V/ Q7 O2 c% E7 l3 \' p
- call A20Read ; Wait till the 8042 output register 0 E3 V- t5 S4 Z* f; @4 f
- jz exit2 ; has something in it's buffer # E! Z) \ t; _& b4 G, B+ {5 Y
9 E& b6 O H/ Q8 f5 r/ [4 f7 s- in al, 60h ; Get it ( A( D; t( K5 G' d' Q* D2 g
- mov ah, al
: y# ^( d( B: S; [* J - call A20Write ; Make sure the input register is empty 9 f I. b/ A: g7 Y. J6 L
- jz exit2 % }- l7 Y0 h* k. M$ N
; K3 W$ h6 _6 U5 t5 b* Z0 [ x- mov al, 0FFh ; KBC NOP command, does nothing
" J! k" p. I. J5 F5 Z/ G; T2 E - out 64h, al / Y. ~7 E- }/ R. I
- call A20Write
; z! U/ B: B: D8 g% ^: g( \4 y
6 g# ?2 d5 w& E/ b5 y- exit2: sti " c8 r! W+ X& @" m- T
- ret. E" u" D9 u& }# V6 h* S5 m
- ) h! K; _! O1 U6 ?7 W* |4 m
/ r/ o [! S- r- A20Write: xor cx, cx ; Reasonable wait 2 c9 w9 U& }- k" }) h M
- get1: in al, 64h ; Get KBC read status 7 B! D/ {0 c4 q# T, ~, U+ t
- test al, 02 ; See if buffer empty, bit 1 clear
8 O; G- z& I" W+ V* m$ { z3 E7 w - jz clear 0 q& W. W$ e! p1 P
- dec cx
- S/ G0 K4 Y* Y/ | - jz exit3
% S: a# @$ H: M8 c, B$ \, t - jmp SHORT get1 , W) L+ S1 H$ F& f* R, S
- clear: inc al ; Clear ZR
. r1 s2 T% Z) s: V5 B0 V - exit3: ret * k6 C; j3 v a
1 \% x, l$ s# a$ w9 ?6 {- ( b7 C6 x" ~ ?4 C
- A20Read: xor cx, cx & ~, `4 q1 h! K
- get2: in al, 64h 9 f* k! ~; [4 A9 i2 z& {+ ~4 K
- test al, 01 ; If the 'output buffer' is full, has 0 x. b) e" {) B) c( e+ O( m
- jnz exit4 ; something for me
/ X) b4 q% f4 O6 ?* i- ] - dec cx 3 g3 L, ]& f: U9 W
- jnz get22 n8 S8 s+ T9 ?# Q Q+ f! ?# ]8 A
- exit4: ret ; k4 j7 c4 f' G, }8 X: ^
- 1 l$ y7 I8 I2 \/ n9 o
- end
复制代码 |
|