找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 13851|回复: 1

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM ' ?6 @8 H& B/ M1 \
  2. ; ' `+ p; @5 ~" s( s" P2 v
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    . A" C: ~. o$ U2 V5 \/ n
  4. ;       ml A20ON.asm & I- [8 P& w. Q! L( l0 u- D" I
  5. ;
    # o3 k) |1 U& f) e% h* E4 S: B! b7 n
  6. .model tiny
    , N& k. p. E- c
  7. .code
    6 v' q$ s/ f3 V! I
  8. .486# X! W! E2 }+ g4 Y/ R
  9. .startup
    ; ]7 \/ j  l4 ^: D

  10. 3 M# L- z& P9 \& w9 z6 ]* K
  11.                 mov     dx, offset msg_author0 i3 O2 G0 h) }. W
  12.                 mov     ah, 09h
    4 D$ F. H1 O4 m. K9 p5 J
  13.                 int     21h
    : a" @* f& Q3 d7 |6 o. ?' K7 Y9 ^
  14. , [/ Z4 k& c" ?$ O3 {0 m9 ?
  15.                 mov     dx, offset msg_fail
    4 \6 @% h- p0 w3 W6 _3 J, X$ `
  16.                 call    A20_ENABLE
    - n& m& d! W% Y4 ^- M$ Q  c# b
  17.                 jz      exit1: j) d7 B% ?' P% W( n. s
  18.                 mov     dx, offset msg_ok # q5 B3 c& ]0 r/ G  u8 S' q- a9 U

  19. 1 T' e5 z4 k/ F# t# N$ a
  20. exit1:          mov     ah, 09h 1 I/ L3 B( T: k  }" F
  21.                 int     21h ! d; \0 [, h$ {% x. e; X8 k) ^% g7 N
  22.                 mov     ax, 4C00h
    * U* {- `; D8 q5 I
  23.                 int     21h % j3 U+ ]/ D( ?( @' F
  24.                 ; \0 t, G4 |- M
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    5 f3 n1 V: Z' j; q) ?8 O
  26.                         "2008-07-01",13, 10, "$" & q9 x& \& g0 ^1 k. W: F$ E0 G
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ( Z& B* ~( m+ ^. E3 @! L, `) O
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    5 o# S1 Q7 |( n: T" v

  29. 1 [8 a+ K% H+ }
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------/ `) H1 Q6 B) N  z1 R  Z" Y0 }: n' x- U
  31. A20_ENABLE: 6 S" T* a* O7 f- j
  32.                 call    A20Write
    4 ]0 V" o5 l6 @
  33.                 jz      exit_enable
    - n* u+ T& x1 Z& @7 _1 ]

  34. 0 b' U' Y" M& b: a- H+ I
  35.                 cli                             ; Only need for reading value from KBC 1 e) O* B$ ?+ H' l* w% t& ^
  36.                 mov     al, 0D0h % T& D& M- Q# L: u6 R+ T
  37.                 out     64h, al
    ; `; M* g" ^  s5 j+ Q5 d/ V
  38.                 call    A20Read - r7 n) }$ T8 Q. q
  39.                 jz      enable_int . g4 h; D! r+ p7 \3 t: g1 l
  40. . g0 u) I0 Z. b( e. [
  41.                 in      al, 60h                 ; Get current status " a  E0 g6 J, T; X; U
  42.                 mov     ah, al
    8 h) r+ s$ Z; t+ m. \
  43.                 call    A20Write
    3 \" n# Y# B4 P6 Z4 o) J! B2 W
  44. enable_int:    sti / e2 @( T! _( Y, Q
  45.                 jz      exit_enable; e& t* b: k4 G
  46. , j8 T0 e- z+ H
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    + A# f+ y( z, i& X
  48.                 out     64h, al                 ; Out Put Port next
    3 h$ E7 v9 a0 R, |5 s9 H
  49.                 call    A20Write 5 \/ j) u# v. C! i, j: c' K
  50.                 jz      exit_enable4 p. j0 ^+ x& G

  51. ! ?! s0 H. i2 u
  52.                 mov     al, ah
    $ R8 L5 h! L! l- r8 i" n
  53.                 or      al, 2                   ; Enable line A20 / w7 t. ]. I! I5 l" `, ?
  54.                 out     60h, al
    : p' B7 }5 `! G! M4 L6 v' T
  55.                 call    A20Write 4 m/ |: F5 B! W
  56.                 jz      exit_enable8 R! o3 E. [  d. g: L! t

  57. 4 D- c3 L4 I# {! V  ~' {- I
  58.                 mov     al, 0FFh                ; NOP 9 I! G5 q: G& v$ _) v3 h
  59.                 out     64h, al
    + T% W. U8 W8 O! T3 S6 D! c
  60.                 call    A20Write
    # M# k! B7 R; U8 Z) D, ~/ |4 V

  61. ) j& V  w: a2 R# g7 w, B7 |
  62. exit_enable:          ret
    ' N' {1 P+ V- N, t" o

  63. - T4 W# C: w! w, K
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 ]. Y' L% `  M
  65. get_wirte:      in      al, 64h                 ; Get KBC read status , I% L. c' R' z5 [- H) [
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear # s$ _! j  O1 ~
  67.                 jz      clear 3 j9 l: R8 @, f, L% P; Q" R
  68.                 dec     cx / K& U, {$ F' h" z. b" h- G
  69.                 jz      exit_write
    : U* l1 Q: E! K  S
  70.                 jmp     short get_wirte
    : B4 E- k  r) E1 ]
  71. clear:          inc     al                      ; Clear ZR
    * o# e+ k5 v5 m% O- v  j
  72. exit_write:     ret   ?: u3 g2 T$ ?9 |0 Z  n

  73. " u0 n1 Y% @# t" N+ v7 A) f
  74. 4 w1 I3 l" m% c2 p' g
  75. A20Read:        xor     cx, cx ( t* D1 U- n" s9 P
  76. get_read:       in      al, 64h ) D! T) ?' h# B: C: C7 N! k
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( w6 S2 A2 g) T4 D; e/ [
  78.                 jnz     exit4                   ; ...
    / ]# d# V6 a/ M" S% B
  79.                 dec     cx
    6 q3 R1 Y3 f! V. B- M+ ^/ B
  80.                 jnz     get_read
    4 |7 y; w! I' q% F* [
  81. exit4:          ret     6 B/ p; [1 B3 H# {$ F8 x4 l
  82.                 " @+ j. ~- h7 _
  83. end
复制代码
  1. ;A200FF.ASM 7 S7 B" n2 l1 c0 p; x1 {
  2. ;
    / r' D4 v" c6 n$ O4 w5 L- U) m
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01# e0 c* r2 O" n7 H( M/ B
  4. ;       ml A20ON.asm ' E" a3 I% u# t( k+ _7 g3 K, e) k
  5. ;
    3 w3 S) l+ I' ^9 B
  6. .model tiny
    # P' e' o7 k* q% s
  7. .code9 X  I0 W. |9 B& H0 _
  8. .4861 p+ i" f9 \5 g3 x! I
  9. .startup) I4 m+ H4 x, G$ w4 \! f- I

  10. ; O1 d: }! V6 m; E3 H& J# K
  11.                 mov     dx, offset msg_author
    * L- \2 x- m/ C6 g; P. h
  12.                 mov     ah, 09h
      |0 p" T/ q" l$ U0 F+ d, s2 R
  13.                 int     21h
    + Q' v  i8 J3 N' m' _2 P- P

  14. ( O5 E1 t) e1 X% q
  15.                 mov     dx, offset msg_fail
    ! V8 m3 z. O" l# K, D* E9 y" m
  16.                 call    A20_DISABLE& `$ v) P9 n6 w3 u1 Q0 @
  17.                 jz      exit1. O% ^3 a2 K$ Z
  18.                 mov     dx, offset msg_ok 9 _# X1 p1 K  G6 u

  19. $ B1 \. g! M( Q7 T& T' J( U2 X+ U
  20. exit1:          mov     ah, 09h ! h2 x3 z1 P8 _2 ?) D
  21.                 int     21h
    " r4 q3 _0 U! Z2 ?" ]6 Q6 }
  22.                 mov     ax, 4C00h
    5 C# \0 @  p( S1 |
  23.                 int     21h
    " J/ @; I0 f5 u8 Z  X* A
  24.                 9 r" S3 w& U8 U4 A1 J3 k7 ~2 p
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    4 \0 u/ \  g1 y2 B
  26.                         "2008-07-01",13, 10, "$" # z8 O) S/ c& v/ D
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    2 ]- ~+ w/ \5 R( U: U) l- S3 n
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"   |1 Z& k* X" R5 y: {
  29. + u8 M7 W, T& r0 D
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    , S6 ]' Z1 d: s5 _2 K. h) k
  31. A20_DISABLE:
    % a$ U1 e( [8 M  ^- O
  32.                 call    A20Write
    - D8 K) x/ P' B$ m
  33.                 jz      exit_disable+ m! V* Y1 q; Z9 D: x$ E

  34. 7 X! x6 b  c( [6 Y
  35.                 cli                             ; Only need for reading value from KBC
    / i/ `8 O( r" l; s
  36.                 mov     al, 0D0h
    ( x5 p! b9 O; O  o) e
  37.                 out     64h, al
    : l* A! ~: K& h2 F: p. u2 G& _
  38.                 call    A20Read / _  x$ d+ L, v3 v5 q
  39.                 jz      Disable_int 6 q8 M2 h  k( `* H; i$ U

  40. ' b. o: Z" l% e' {; j6 @  N
  41.                 in      al, 60h                 ; Get current status
    : {- {1 b' V* k0 T; Y9 y* n1 _% t
  42.                 mov     ah, al
    ! B% R1 H0 _" a9 P6 L& O: w! d( A
  43.                 call    A20Write
    5 m1 i- j+ T$ ]- |; I
  44. Disable_int:    sti
    / l* w3 _6 \! `, S
  45.                 jz      exit_disable+ W+ K( [' \% K. p+ p
  46. # d! m4 C9 C9 f
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    # ~& Y) S  _6 `1 I. g
  48.                 out     64h, al                 ; Out Put Port next 1 X! @' f6 t8 c3 X: q6 [8 g
  49.                 call    A20Write ' g" E$ I! g( _
  50.                 jz      exit_disable; |3 D) [7 X( M
  51. 3 e0 E# W4 Y* I& a9 C3 I
  52.                 mov     al, ah 8 X, D+ M: T) T. w; h! m9 T
  53.                 and     al, not 2               ; Disable line A20
    0 |7 }  T( X  {6 b: S6 b1 p
  54.                 out     60h, al
    4 N2 D* t( h, t
  55.                 call    A20Write 4 f" S5 E' n0 ^  L( g) `8 m
  56.                 jz      exit_disable
    7 i. m! F- A% Z

  57. 8 \: z! L  H+ p/ A
  58.                 mov     al, 0FFh                ; NOP
    % `/ ~# y/ u- g, s
  59.                 out     64h, al - |- |; N. t% R% d0 T
  60.                 call    A20Write 7 @1 \* U' a* y2 Q) _% J: ]" O* l1 ?5 H

  61. + K  M- K4 y0 Z! N9 @$ y8 y( T- q
  62. exit_disable:          ret
    : a3 n1 X5 _* M9 U
  63. . k( v+ q8 e" x
  64. A20Write:       xor     cx, cx                  ; Reasonable wait : u  l0 r& W3 m( M
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ! l% I; Z9 g) t( t, ?2 }' k
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear - N# W6 E& o; n# v& M2 b4 M( V
  67.                 jz      clear
      _7 t; w4 k5 D3 o- P2 x! o' P7 O% y
  68.                 dec     cx
    & A2 v7 Q+ A# L4 B1 d7 d9 U. g- Q8 ?
  69.                 jz      exit_write
    6 \. h; z: p1 y- f
  70.                 jmp     short get_wirte
    % K+ B0 W+ N! s9 U1 b7 c, B
  71. clear:          inc     al                      ; Clear ZR
    0 q) r1 _4 R! F3 W7 Z
  72. exit_write:     ret
    & J1 D' i4 F: j+ y! y

  73. : n% j: v3 J3 E6 A5 O$ @! k( p

  74. - D0 Z/ b, _# F3 G9 r3 K
  75. A20Read:        xor     cx, cx
    % U* |: s/ D4 {
  76. get_read:       in      al, 64h 9 K2 v: h1 }! j- J0 W% u( I9 ?+ ?4 {
  77.                 test    al, 01                  ; If the 'output buffer' is full, has " J4 T" ^& X) Z  l
  78.                 jnz     exit4                   ; ...
    + P) u4 v+ r; e+ `
  79.                 dec     cx
    : i- s& E6 k/ h! Y+ H+ w8 a" e) D- T
  80.                 jnz     get_read+ ~# ^1 K2 r" ]3 I4 [- g
  81. exit4:          ret     
    6 u) L. v$ P" z: x$ n) l% ?7 [: d
  82.                
    7 s- V) q" l& I: [- p' O
  83. end
复制代码
  1. ;A20STATE.ASM
    : t0 f2 ?" Y: O0 f
  2. ; ! N5 J8 v9 U: y( z
  3. ; Returns the status of the line A20 through the KBC - f  }1 v1 @1 l/ V7 h: G( }
  4. ;       programming by bini for debug. 2008-07-01+ J* s" c8 g( U
  5. ; 5 e" r$ u% K$ t) f# d
  6. .model tiny% m, o# Q" n% V' V6 S: D1 p
  7. .code9 Z4 ^5 @0 _2 H* z: I
  8. .486
    0 J( r4 ?& n; w! q  M* I- _2 s9 S8 n
  9. .startup
    5 b: Z5 ~3 E: G3 K! c
  10.                 mov     dx, offset msg_fail 9 \0 M* F( S7 t8 A: c0 K
  11.                 call    _GET_A20_STATE_* I% L( M  D  n3 N) j3 g
  12.                 jz      exit1                           ;  was a problem
    , o9 w. ~$ Z' j' Y9 w4 G8 c) w% y
  13.                 push    ax                              ; Save state, AH 1 n/ s2 i3 |5 J- u" M, x
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    - X* A& d$ k  r9 ^/ G, q* T
  15.                 mov     ah, 09h % v) d3 y' w* ?3 r) J
  16.                 int     21h                             ; Print message
    $ z. t4 y# w  U& L
  17.                 pop     ax                              ; retreve state
    " d% N( o- K' F- R! w

  18. 3 i+ ]. t8 a- Y) B( y/ s
  19.                 mov     dx, offset msg_dis + P( P8 v0 j, N- b0 _4 z  I$ p
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    : f, f) G  N) T* H+ y+ v4 o" |
  21.                 jz      exit1
    8 Q; f& B! i1 w8 I$ j
  22.                 mov     dx, offset msg_en 2 J0 v. d4 E. w; `6 ?' ^: N. [
  23. 1 f) c' o# z! w1 D5 L
  24. exit1:          mov     ah, 09h
    2 I5 B) a. {/ J$ N) e! c' ]1 B
  25.                 ; DX already contains address of string
    / Q$ M  f+ b- H  d
  26.                 int     21h
    $ V5 `! Z0 q1 J6 I

  27. 7 E" z# s4 n% x6 Y( e" L) q0 s
  28.                 mov     ax, 4C00h . N' Z$ |8 ~4 l. S
  29.                 int     21h
    $ h- n1 V) Y6 R4 V% V9 T# ?9 l" `6 Q

  30. 8 A& P  J/ ~7 q! U
  31. msg_ok         db      "OK", 13, 10, "A20 $" # r3 D6 u! ?7 `7 q3 n
  32. msg_fail       db      "FAIL", 13, 10, "$" + ?+ A1 {3 l% i. u9 `
  33. msg_en         db      "ENABLED", 13, 10, "$" ; T! L; O* n% O$ K( a
  34. msg_dis        db      "DISABLED", 13, 10, "$"' L/ y+ y' ^6 R% p* Q

  35. & e  w9 l& t* O) [; \$ Q7 H

  36. 3 X: K' a$ z+ x5 k
  37. _GET_A20_STATE_: 1 s3 {* M) n' t5 u1 G7 L
  38.                 call    A20Write                ; Wait till the input register is empty ( X2 Y. ~8 B( i% L2 [3 ?4 O2 x. f
  39.                 jz      exit2+1                 ; Bypas the reset int's
    9 e! @' l, h2 o+ H( A! g
  40.                 cli                             ; Disable ints so we'll get our value 6 V7 y, N" ]8 U' p! U

  41. ; v6 ?" J8 {, K, k$ A
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    . v4 Q, V- u# g" b. E
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port ; I! J; E  t$ l/ H4 Q, S
  44.                 call    A20Read                 ; Wait till the 8042 output register ( R" X$ j3 ^8 e# T+ e
  45.                 jz      exit2                   ; has something in it's buffer
    ! a* L$ J" N9 o# z/ B/ n$ Z
  46. ) ~# C. T& F. N/ p2 D8 d
  47.                 in      al, 60h                 ; Get it
    8 m0 g3 c+ v9 H& H. B5 i" x8 `
  48.                 mov     ah, al
    1 V2 G) Y2 B/ T
  49.                 call    A20Write                ; Make sure the input register is empty
    ' [( j& X$ F; M. E. V7 N) `
  50.                 jz      exit2 1 e; ]8 @3 Y! R: ~

  51. . l6 c- k" v( x: H& O1 b. {
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing - o! Z; n2 w9 T& ^' c: o7 r
  53.                 out     64h, al
    9 e' g% j$ f: E6 q! {: Q
  54.                 call    A20Write
    7 I0 R: I; N- p/ X) _# X% y/ }; V% G0 z
  55. , Y: i# Z# K. v7 n% L2 a
  56. exit2:          sti ' ^8 Y3 `/ `  f" O  Y$ [
  57.                 ret
    8 V9 [% M( ?( ^3 U
  58. # h! d+ F5 L" M# \$ [7 |1 s

  59. + C, l' l+ H* i
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    6 h* a8 J1 M: R+ K5 K) X
  61. get1:           in      al, 64h                 ; Get KBC read status
    # T) L1 X8 w9 H
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear 3 x; d( ^& }- j% k) ^4 b; R5 h% q# C
  63.                 jz      clear
    1 I/ Y$ W, ~& S' G+ x% e
  64.                 dec     cx
    / z- r+ p) K9 P' @6 x
  65.                 jz      exit3
    * v4 W1 J! H: L% K0 ]
  66.                 jmp     SHORT get1 / r$ H! F. R  U7 ?  T0 n
  67. clear:          inc     al                      ; Clear ZR . c* `( a) k( j) n& S: [1 d
  68. exit3:          ret
    ; g/ D( J1 Y9 _+ H; s( ^" R/ m
  69. $ R3 E$ T& T1 L5 R" |- ?# N. E

  70. . x/ i1 ^# D7 _8 l' i$ C
  71. A20Read:        xor     cx, cx ( {$ L, l9 s4 b5 ^
  72. get2:           in      al, 64h
    . r- t/ q( ?$ a/ C6 ~2 I3 L3 B
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    # B: W% B4 X* F& d
  74.                 jnz     exit4                   ; something for me * o& ^1 H2 j  m. j6 ^
  75.                 dec     cx
    ' ^) u3 x7 O* O% S& W: M% l- w8 V  k, r9 u
  76.                 jnz     get2
    - F4 `6 m9 |5 ^2 C
  77. exit4:          ret     + ~6 I( v6 [  N1 \
  78.                 4 d1 }% ?; Q; A: o+ h' H! i
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
3 |4 g3 Z+ R5 e3 b: P) P4 s{        while(inp(0x64) & 2);        outp(0x64,0xd1);
  d# @/ B, V" |: z4 \$ a8 y/ L        while(inp(0x64) & 2);        outp(0x60,0xdf);
* y3 ^% q6 X+ u2 r. Q7 Z        while(inp(0x64) & 2);        outp(0x64,0xff);1 t  r, _+ V5 W  t) z, x, W
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2026-2-1 13:58 , Processed in 0.060216 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表