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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    5 c  i+ |( A4 l# m: a* H
  2. ; $ i$ o- T7 Y* A; X/ u8 d$ v
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    9 ~+ c& U' R+ G: Z3 N2 `& {
  4. ;       ml A20ON.asm
    7 H$ [3 }& {$ k! [8 U1 }, }. E
  5. ;
    0 E4 i0 w/ C5 Q
  6. .model tiny: ]# O$ f* j7 J
  7. .code
    7 q" |7 g9 n0 a' k/ W+ F3 E, }9 ]
  8. .486
    * z2 K, c. _! X/ M: d+ t) Q. W2 {
  9. .startup
    1 e: h0 s0 y+ ~
  10. % q( d: u3 E. M- c2 V( J1 k' \
  11.                 mov     dx, offset msg_author
    $ n0 N% y9 E. P' f
  12.                 mov     ah, 09h
    & f7 v& j0 ~& H% W) t, a0 T& S
  13.                 int     21h
    + C7 _$ Y: `( m# }. r% v

  14. , g! Y" Z% t) M8 _: C+ j4 y
  15.                 mov     dx, offset msg_fail ) \/ j, V8 k# K' }
  16.                 call    A20_ENABLE( Q  L1 G3 X2 u; x
  17.                 jz      exit1
    % c& T$ X+ d0 j0 ~  D2 s  h3 N
  18.                 mov     dx, offset msg_ok
    + D) ^7 @0 D) F" l

  19. 5 E4 u+ Q0 y% q# L( L
  20. exit1:          mov     ah, 09h , ~* h" U; Z$ d/ A/ k5 W' q
  21.                 int     21h
    3 u$ B) Q& j; Z! N( `- p! G2 o! |) }
  22.                 mov     ax, 4C00h
    7 \/ [9 d- K% n" I0 U! D! }
  23.                 int     21h ; ^' M! ?6 z  m0 \9 O. c
  24.                 * T! A$ l; ]) X4 O# w8 }
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,, q$ h2 F7 U# c' U, Z9 S7 R
  26.                         "2008-07-01",13, 10, "$"   [2 f+ ?  J9 G  u+ h: Q
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 0 T. C) s* f% B/ j
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" % e- Z( _& ~9 q) l

  29. . H  ]+ _* l& W8 |) W% N6 g
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------. x$ R% O: @% @) p! u% ^- `
  31. A20_ENABLE: ) o! }6 |$ k9 o. P! @0 K
  32.                 call    A20Write , e$ p& d2 w) f7 b9 U
  33.                 jz      exit_enable8 X& G5 z' d' a0 V% m# Q# q$ ?7 y6 V, f$ c

  34. " a/ u: L5 V! C2 _9 B! J
  35.                 cli                             ; Only need for reading value from KBC
    7 N& ?5 E, o7 \1 M
  36.                 mov     al, 0D0h $ v8 M" J; t0 ~: a7 r4 i5 [$ r
  37.                 out     64h, al
    2 R& M4 I1 U8 o" b
  38.                 call    A20Read 5 g5 \6 o9 _% |. w- Q2 e
  39.                 jz      enable_int . R9 x% H& ]+ K& U& \1 Z

  40. 3 C) [- }- ^4 v) a0 `
  41.                 in      al, 60h                 ; Get current status
    , z6 x* R- C1 E% u5 C
  42.                 mov     ah, al : i0 |1 q6 O/ A9 |& F2 Z0 K
  43.                 call    A20Write ) K  \- d7 U5 ^6 C' ^$ z" @( V
  44. enable_int:    sti 1 I: ^! n) R3 U. c1 k
  45.                 jz      exit_enable% f' x! }. I# |; W& i$ A% p4 @
  46. ' o) P1 f& h$ F9 E2 P5 |
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the . a6 y& V1 ?/ R6 ]2 L
  48.                 out     64h, al                 ; Out Put Port next
    " E6 w. E, c7 H+ \+ ~  R; _
  49.                 call    A20Write
    3 R( Y4 p5 I. V- B' U( e% y+ [
  50.                 jz      exit_enable
    ' `) g3 s4 U+ D% U

  51. + a- J. @! U0 \8 k* k
  52.                 mov     al, ah ( E# o: v$ _7 S$ x) X) B
  53.                 or      al, 2                   ; Enable line A20 9 T$ b  o, X* r$ t( L
  54.                 out     60h, al
    : m5 N6 [$ Y' R4 D
  55.                 call    A20Write
    4 Q% c% j+ e1 G! |
  56.                 jz      exit_enable
      \5 \7 M3 ?: a# r

  57. , e; @( \3 K5 B. }
  58.                 mov     al, 0FFh                ; NOP 5 S7 _. g) V$ |6 L) ?! z
  59.                 out     64h, al . z1 p4 u1 I6 {6 `5 s' {
  60.                 call    A20Write ) h5 D+ L0 D' [  K7 y6 P7 L  o- Z
  61. + F8 s8 i& L5 M
  62. exit_enable:          ret
    , ~; _, K4 |1 b
  63. ! W4 j  [4 J: f2 A$ w3 N
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    & |# p: }' \  M6 {
  65. get_wirte:      in      al, 64h                 ; Get KBC read status % r. \0 Z  b. V- v8 J% R
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    1 u, C6 Y6 R  x) J
  67.                 jz      clear 0 A( J) S3 a3 l
  68.                 dec     cx / F5 C& x! v% k1 h& c8 _
  69.                 jz      exit_write & v( G* O( g( w
  70.                 jmp     short get_wirte
    6 _# W+ D3 G! I6 d
  71. clear:          inc     al                      ; Clear ZR
    % i/ H( Q. z( g& ^' R6 |
  72. exit_write:     ret
      n' D! s/ k( k6 o  x" _
  73. & o1 u; w. b; I1 M) }2 K

  74. . C# [  M- X. j- u: I( C0 E
  75. A20Read:        xor     cx, cx
    ! s" w& `' w! \7 K& w& r& x
  76. get_read:       in      al, 64h & I2 m9 q; P, j- p
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 4 p) b: n% V6 j! {
  78.                 jnz     exit4                   ; ... ) G6 ]: L, p$ H7 X# h
  79.                 dec     cx
    + }4 n7 F8 W' k) N7 S5 N; b
  80.                 jnz     get_read
    0 i3 E( g0 V8 U& V! Q, S9 T
  81. exit4:          ret     7 M  Q0 F" W1 B6 B+ T. ?3 a+ u# y6 q
  82.                
    * r( }; f3 \$ E) Z
  83. end
复制代码
  1. ;A200FF.ASM 6 Y4 l9 ]1 g: H- J; b
  2. ;
    8 O7 \6 n4 u1 K
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    * q) u+ r* f. Y- T
  4. ;       ml A20ON.asm ) h/ E, X* {. A( S
  5. ;
    8 r# T% y- u, N+ w/ u" S" l) x. ~
  6. .model tiny
    4 _# |$ W9 e* e2 j- n* s
  7. .code
    0 x8 {" G( y* S8 e
  8. .486! D6 K2 ]8 h  \4 j2 ?, l7 T
  9. .startup
    / t3 G4 f) P# O7 ]% c* v1 ^
  10. , c" r, F- v0 A- t# I
  11.                 mov     dx, offset msg_author, |" W" ]( h* q' g
  12.                 mov     ah, 09h+ s. `6 _- ~2 e+ {3 T+ y
  13.                 int     21h9 i8 J) ^0 K1 @% A3 i! O

  14. / v) F2 x5 ?/ H1 z! v
  15.                 mov     dx, offset msg_fail
    2 e# s( w- j  `2 `! z" M
  16.                 call    A20_DISABLE0 X! U9 U# Y( S# f8 J) g3 b! q( l
  17.                 jz      exit1* U7 Q! i8 y1 L+ C+ i+ j
  18.                 mov     dx, offset msg_ok ; T& Y- G) x+ L& s, s6 J9 |

  19. 2 o- K4 Z$ h! {! y. I# w
  20. exit1:          mov     ah, 09h
    , h7 z3 d( [0 \. C. L" _
  21.                 int     21h 6 @! L9 {8 [6 u: {4 R
  22.                 mov     ax, 4C00h * A5 A- o. k+ z0 k: k, T! \+ B
  23.                 int     21h / [% R" t0 [5 U
  24.                 7 a* D* ]3 q7 {
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    , K) ?& _7 Y, f) ^: G
  26.                         "2008-07-01",13, 10, "$"
    6 s$ m# H# l0 i5 C% L" [+ R4 [! X
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" / K6 N, ~* ]9 r5 G
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" - A; ^; m" r4 T" V' ]( r8 C8 Z

  29. " y9 I; Q% o3 W5 ~/ k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------( ]' p' ~6 o3 q5 d  ^6 p
  31. A20_DISABLE: . X( d( t# e; C2 g& ^. K  k0 `! C
  32.                 call    A20Write 6 u4 l8 M$ v0 y0 U$ s
  33.                 jz      exit_disable8 J- v" @2 L$ Y4 G
  34. : J1 v$ v) Y5 q5 U% G9 v$ h% ?
  35.                 cli                             ; Only need for reading value from KBC 1 c& c8 W9 q$ ]# T
  36.                 mov     al, 0D0h
    ) J) n% b7 u+ o1 P
  37.                 out     64h, al
    & v) @  U$ {; x
  38.                 call    A20Read + s% ~* _, z3 y: e. r. a( e  {6 W
  39.                 jz      Disable_int 7 x! \# f0 u9 y% |6 t" R3 r

  40. " a+ z2 X" ]3 G& ]
  41.                 in      al, 60h                 ; Get current status $ u* X2 K. v2 |/ {2 b
  42.                 mov     ah, al , p' T0 k+ G% I+ ^2 ]; c2 `7 _3 F
  43.                 call    A20Write
    / z3 \7 p: Y0 E2 S
  44. Disable_int:    sti
    ' P. q. Z6 ^% P9 r, a7 d' k. ^
  45.                 jz      exit_disable
    & q' p7 G- Q' @7 j- _: S) u

  46. $ l7 T" {" V9 ]! s5 B& M* E
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    / r0 c& U! L/ l* [( u5 R0 f% E
  48.                 out     64h, al                 ; Out Put Port next
    ' k9 M8 u( h& a+ A- ?& M; n
  49.                 call    A20Write ! u" K( x, ?* F( P. y
  50.                 jz      exit_disable; \4 z: K% Z. B" S2 g% I6 a3 m/ d

  51. # }' }( n2 d7 ^' m; P" m. @; F
  52.                 mov     al, ah
    4 A2 T: m- y8 D: {+ N1 D# W+ ]8 T
  53.                 and     al, not 2               ; Disable line A20 2 `4 }: \' o( [' s# R8 Z' P
  54.                 out     60h, al " T5 F, j$ V: a; |+ r1 d, X: O# A7 ~5 F
  55.                 call    A20Write ' w! g- Q. L2 o( |2 q
  56.                 jz      exit_disable
    9 ^  P. t7 N) H6 g# V
  57. 3 g* ]1 C) e4 B: p+ |' ~4 b
  58.                 mov     al, 0FFh                ; NOP
    ' A. K) I' ]( n7 Y* c
  59.                 out     64h, al ; i( G3 A  M: d7 P* J5 i
  60.                 call    A20Write 4 p* P) r% `* c7 n( K2 W9 z+ z" }
  61. 2 g; ]! I/ O" g! H
  62. exit_disable:          ret 6 d3 j' V( r' E1 B! W7 C

  63. ! E; h2 m2 W8 [3 d
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    # n0 m/ y, ^: ~; n/ |
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    , `! V2 R" Z" w' ?% G
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    . x. g$ T% p* ]
  67.                 jz      clear ; m; N+ a3 U) K! D$ D/ X2 R
  68.                 dec     cx % b0 i& L/ v1 z& y
  69.                 jz      exit_write
    : l2 Y6 u/ N& n; M* G
  70.                 jmp     short get_wirte
    5 V$ ^, e! v- `$ z
  71. clear:          inc     al                      ; Clear ZR
    9 B& l! A( F, s8 q3 v. @/ a: N
  72. exit_write:     ret ; E& j) K: k4 v* w( T

  73. $ e( e$ l: P' [' Z

  74. 4 x, w* Y- m  Z
  75. A20Read:        xor     cx, cx
    5 v2 U* `& A( d
  76. get_read:       in      al, 64h 0 ?# O0 c) }7 ^& b# x
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    7 C( k2 [% E5 Z  \
  78.                 jnz     exit4                   ; ...
    2 f  h: o. G+ ~9 }. z
  79.                 dec     cx
    0 \# \  c) U, c* f9 R# l  B% B/ `
  80.                 jnz     get_read
    2 i( i$ i& o3 C$ [+ t
  81. exit4:          ret     : n) F" ]$ H  @# r, D4 C
  82.                 , |) `: [/ G5 f7 ]. J; R
  83. end
复制代码
  1. ;A20STATE.ASM - V/ p4 _: {# e, a3 X' n& n( T* y
  2. ; ! x6 N4 e* g. J% X6 n
  3. ; Returns the status of the line A20 through the KBC
    4 s3 q1 P! R( t- J2 ]
  4. ;       programming by bini for debug. 2008-07-01
    , T" @) j4 }& p; I8 X  ]' A- h9 e
  5. ; + b! d+ N; F2 r6 @6 c9 \" x
  6. .model tiny" r% R5 h/ F' L- E
  7. .code, f8 {; R3 V0 r4 G+ X
  8. .486
    8 w7 {: }) Z0 O
  9. .startup
    3 w' m. s3 A4 i+ _. b9 e
  10.                 mov     dx, offset msg_fail
    " s- e" Y* S* a0 _& f/ G5 D5 E
  11.                 call    _GET_A20_STATE_8 z" `3 g$ q+ c8 b" f4 _( z' ]
  12.                 jz      exit1                           ;  was a problem
    & Z& f) R9 p* [
  13.                 push    ax                              ; Save state, AH
    , ^( L9 k% s  d0 Y7 }: w2 _
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem & ^* m. y2 i( Q% O3 T1 m$ F
  15.                 mov     ah, 09h
    + m. y0 c  Z/ H& K  a% Y! C
  16.                 int     21h                             ; Print message : p5 S: r1 I( {, g
  17.                 pop     ax                              ; retreve state : f( W* s" {, f. h

  18. * P! ~6 @2 x( v. G
  19.                 mov     dx, offset msg_dis ) C  A/ t  x( N6 I) l* @. W
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state # y/ X) w' Q: X, k
  21.                 jz      exit1 . M# i5 T) h" d. A: i: {/ v$ p+ W
  22.                 mov     dx, offset msg_en
    & [! e5 U1 ?  U( k+ L2 q
  23. / b- r0 ~5 G1 |  P9 p
  24. exit1:          mov     ah, 09h ' y3 e2 W, l) d) p2 Y: P
  25.                 ; DX already contains address of string
    . I! ]9 M9 v) H2 _
  26.                 int     21h
    # z: T' [4 K4 _3 U  z
  27. 0 R% w' _. [0 @  B
  28.                 mov     ax, 4C00h 9 a) ^0 l; M8 E
  29.                 int     21h + K8 j8 T- c0 a2 u# [+ S! Y

  30. . S% Y: ]4 x( ~8 u& W& e
  31. msg_ok         db      "OK", 13, 10, "A20 $" " V5 N. Z) \8 ~; n
  32. msg_fail       db      "FAIL", 13, 10, "$"
    6 w3 N! [3 T: @+ o, j
  33. msg_en         db      "ENABLED", 13, 10, "$" ( i# N4 c) C+ k7 v" m1 e( y
  34. msg_dis        db      "DISABLED", 13, 10, "$"% [6 b, h1 e" F/ l3 \% s/ U3 q/ D
  35. 2 o8 B7 _3 M) w2 H2 `2 c! @
  36. 0 K/ O4 z& R! O& l$ K  Z9 I6 i
  37. _GET_A20_STATE_: $ V9 n; c  l9 `% k
  38.                 call    A20Write                ; Wait till the input register is empty $ T2 H: ]: `# u) |* M8 s
  39.                 jz      exit2+1                 ; Bypas the reset int's
    & n2 A, X7 @  a0 X+ a
  40.                 cli                             ; Disable ints so we'll get our value
    ! H( h5 ~! {4 ]3 k0 _! W1 K* B
  41. # j9 ?( z" z5 O& o. U/ ~- B+ g
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register # k, ?  J1 |+ ]; z; [) n
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
      b4 |4 M6 f4 Z2 \
  44.                 call    A20Read                 ; Wait till the 8042 output register 3 v/ e) K* O8 b
  45.                 jz      exit2                   ; has something in it's buffer 5 n& u* p' G" F  t, M! I
  46. * h! U- A1 y7 }1 Q/ h
  47.                 in      al, 60h                 ; Get it : h& [& r1 q% }2 K* j& Z
  48.                 mov     ah, al 2 X) N% J( R$ z5 E) H7 ?6 G1 }' F
  49.                 call    A20Write                ; Make sure the input register is empty
    + F& c+ W" i: B6 e2 [! y& P
  50.                 jz      exit2 - q1 N# [  J$ B# _4 ~

  51. ) _0 A/ |% q2 m& [/ n* o* h+ H2 C
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ; Y# }! j# J& A, v
  53.                 out     64h, al
    2 I2 w* k) Y6 ]! C) \1 w
  54.                 call    A20Write   |2 u( X) F2 c& k
  55. 8 c0 V% `1 b0 Z3 Q* ~
  56. exit2:          sti ! C  y2 L+ P8 h8 c) x- m  h8 w
  57.                 ret5 ]+ c! f6 o" o; s7 m
  58. / z8 @% r2 i" j2 }$ E

  59. ' N3 w* e0 `$ p: {7 `
  60. A20Write:       xor     cx, cx                  ; Reasonable wait % ^4 q# w: R5 @3 j# I
  61. get1:           in      al, 64h                 ; Get KBC read status
    8 f! X$ f: d% A$ f) {3 H7 k- A
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    8 v/ U/ T" d' B1 C7 K- ]" @
  63.                 jz      clear
    1 C+ [) q1 t. z3 o1 f$ D
  64.                 dec     cx ' G2 _7 N' B' e( Z/ Z* U( _
  65.                 jz      exit3
    / l- x6 ?7 s: {8 P# V% K+ J
  66.                 jmp     SHORT get1
    ; B9 P' ]# q6 {1 G3 u1 g
  67. clear:          inc     al                      ; Clear ZR 3 P2 r8 R% M7 u! h, U
  68. exit3:          ret 1 Z/ U& w* T# S! L5 W4 n
  69. 7 V2 c: z( f, F3 c3 G$ p" V! b1 N
  70. 6 D+ A) \' N* u5 G6 Z9 u
  71. A20Read:        xor     cx, cx
    9 \' [, r" i3 W9 m! \' @
  72. get2:           in      al, 64h
    8 b$ w) n) c4 \4 g  ?! e
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    / d4 t$ _+ R  M! S4 P$ N
  74.                 jnz     exit4                   ; something for me   l/ t8 J& z8 r" c; y% K) [
  75.                 dec     cx 1 ^8 y9 N0 A% O) u7 v
  76.                 jnz     get20 _" A' y0 R" v( A# D% A' D4 p5 r2 `
  77. exit4:          ret     
    4 I/ b+ Y6 k& G2 T6 u: s! \) Q: g
  78.                 8 o1 w- B; A& Y; u% w+ w  L9 u
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
2 \/ \8 s% ]2 h{        while(inp(0x64) & 2);        outp(0x64,0xd1);3 b, U' D% i/ H; f  s. L# s
        while(inp(0x64) & 2);        outp(0x60,0xdf);7 @' V, I% n2 ]$ c$ E( M
        while(inp(0x64) & 2);        outp(0x64,0xff);& Q' F+ i# x* T- K/ U2 c* p- y
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-19 06:56 , Processed in 0.025829 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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