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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    ) R/ j+ ~+ g, @1 r4 h
  2. ;
    2 ~# G! z! s9 F. Z0 e
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    4 \+ J4 ^2 h3 T2 c- z/ i" ~
  4. ;       ml A20ON.asm ! \8 W! c- \' u
  5. ;
    * j- b0 f3 x( e$ N  s" F- `/ \  `
  6. .model tiny
    ! y4 m, E6 }% M- B% H7 Y
  7. .code! g1 M2 V( u; r
  8. .486; S8 Y1 q+ p; i; c% G+ i
  9. .startup- F, o+ u" W9 F* A$ O3 s$ A6 H
  10. - e! s/ M4 [  A; J, e
  11.                 mov     dx, offset msg_author
    9 L1 i6 p. }3 i( K. M3 s
  12.                 mov     ah, 09h5 T8 q* V- @% `7 F" m7 l
  13.                 int     21h$ {  f9 T- D8 g9 s, x
  14. * {$ E4 g  S- N+ \4 s8 L
  15.                 mov     dx, offset msg_fail 4 t( `( [4 v1 N3 r- ?. @
  16.                 call    A20_ENABLE3 u5 w$ m7 L2 }/ r, L
  17.                 jz      exit1
    , K9 k  [2 e2 f/ T+ T
  18.                 mov     dx, offset msg_ok ' d- w' e+ t# d- H& W5 ~# u) i$ z
  19. % ~; Q1 y9 r: f+ p# U8 t# P
  20. exit1:          mov     ah, 09h
    ' t+ G  H+ F$ Z. L$ x6 C& Z
  21.                 int     21h ' Y& G/ j5 R0 ?, a" x8 F
  22.                 mov     ax, 4C00h % Z( P% E, A! g& g3 r
  23.                 int     21h - T: I: O' _$ p0 h- x9 y" E$ r  e
  24.                 . v( o! ]# j+ H: S2 ?6 b5 Z6 ]  w$ g
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    / [  P3 g3 c+ P  P
  26.                         "2008-07-01",13, 10, "$" 4 W' ^4 f* I  \) o5 w! r9 i
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    * G' n9 E2 W2 Y! S* N0 }1 @
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    + S  h- z" t  T( M/ W/ O' \# u

  29. 2 U& d9 m; F. J( K% X9 z" W
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    : g, h9 P" U* `' d
  31. A20_ENABLE:
    " a$ i3 o2 i8 t& }) ~
  32.                 call    A20Write
    2 s1 I( W7 {3 R
  33.                 jz      exit_enable8 k3 _  }" ]% n& P, N. @$ [" c5 Q

  34.   L( r1 u- h3 ~% a; U
  35.                 cli                             ; Only need for reading value from KBC
    8 h% X; J. t$ c
  36.                 mov     al, 0D0h 9 V  A* m6 J5 |7 R1 P
  37.                 out     64h, al 8 _. O% z) D! _) T8 R  u$ {$ e9 q& @
  38.                 call    A20Read
    $ g' U# _- G+ a- k) Y4 F2 e
  39.                 jz      enable_int
    , ~& l# j! U3 b  H5 _

  40. & s% h. |- I, K$ G: ~/ u; ~
  41.                 in      al, 60h                 ; Get current status
    $ Z  t; c  Y* `5 A
  42.                 mov     ah, al " ^& N! Z5 f! x. k
  43.                 call    A20Write 7 ^5 N5 T$ h3 g; w* u
  44. enable_int:    sti
    , S$ y" d0 u0 ?4 ?$ [2 M& B
  45.                 jz      exit_enable4 u* w) w# F% V' h
  46. ! e9 Z! v( W4 B4 i/ U& T2 I
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ) Y  s4 f: M3 \& k0 @
  48.                 out     64h, al                 ; Out Put Port next
    2 F" t( ?/ G" ?' H+ L7 a- U
  49.                 call    A20Write + Q- H; A$ D& p( C" l0 P
  50.                 jz      exit_enable
    1 B( J  o, A- W% X# Z% g0 q* |3 K

  51. 8 b9 v* Z* o& q" }
  52.                 mov     al, ah
    1 `6 u' m2 Z7 X
  53.                 or      al, 2                   ; Enable line A20
    1 J. z: Q' z2 \3 b( n5 v) _
  54.                 out     60h, al
    / ~: O8 \  M4 g2 K" M6 [( F. F( Z
  55.                 call    A20Write ; w( F. j1 g3 C$ a: O: v. w
  56.                 jz      exit_enable
    ; S/ \( @& c0 |/ e6 p0 P+ D) }$ [! Q
  57. & T1 t9 T7 t, i, Y; V  r
  58.                 mov     al, 0FFh                ; NOP
    5 w3 F& |% ^7 l( `7 p6 G' n* T
  59.                 out     64h, al / j( x  i/ F: J
  60.                 call    A20Write & X* j* _$ |" U, ~

  61. ( w, |/ K; O, k1 ?/ A
  62. exit_enable:          ret   V8 ]; \2 x; _, f; r

  63. + `' W/ R8 b6 r( t) i6 S9 t
  64. A20Write:       xor     cx, cx                  ; Reasonable wait + j' J# a. S" S) U
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ! f+ D- {6 u9 u/ b. q5 i) U* S
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ' C$ E% I* |1 r' h! k, \
  67.                 jz      clear . D6 s( |. n. h( s5 Z% D& B" r3 j
  68.                 dec     cx
    ( v; B# ]- s) g" Y  P  j% z: s
  69.                 jz      exit_write ; |1 Y8 Y0 W, i
  70.                 jmp     short get_wirte
    3 D- ]7 _5 ~8 y% T) J: L1 X# d- ?
  71. clear:          inc     al                      ; Clear ZR # k* L0 C2 {3 p9 {5 \
  72. exit_write:     ret : i* d2 B- ?, N! m- ~

  73. 1 F5 T3 A  V8 W' f

  74. $ i" m, x% w/ r6 e
  75. A20Read:        xor     cx, cx
    ' Z7 a' N5 J; h; _4 Q2 W
  76. get_read:       in      al, 64h / u2 r( b' k" a" w
  77.                 test    al, 01                  ; If the 'output buffer' is full, has + c9 E9 U2 V7 G+ ^; a
  78.                 jnz     exit4                   ; ...
    ; a- n& e5 `+ i% I1 a1 Y
  79.                 dec     cx 5 [+ I3 |" T. r  {$ K
  80.                 jnz     get_read" r2 H8 ]5 Q; _8 E, g3 D; ~. X
  81. exit4:          ret     
    ( d- f$ \9 G: X% V, Q8 O
  82.                
    ) e. Q! C/ c/ a1 c; |/ G7 R4 Q  n
  83. end
复制代码
  1. ;A200FF.ASM 2 ~( [1 N  s" S7 D( ^, _3 N
  2. ;
    4 w, p2 S6 Z! }' T
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " j; H+ A9 q( @( @2 T1 [- I
  4. ;       ml A20ON.asm ) y% b5 z9 r. H/ _% q
  5. ;
    1 u! l* I% s# k: W8 u# n
  6. .model tiny
    6 w3 W" ^( B  G( e7 a3 d$ `- j- j
  7. .code0 v2 v- a6 W( w- v8 a
  8. .486
    ( E& e7 u5 N' T( ~" X2 w, b& K, Y
  9. .startup; L2 }3 ~/ {) a2 y$ x8 @% J# ?

  10. & v7 b# O0 c' d. J2 I& j; s3 ]: c
  11.                 mov     dx, offset msg_author
    ' ^5 [. B0 ~8 i- j* D" O' B* q" V  i! a
  12.                 mov     ah, 09h! u, }6 o' t+ H* s% `
  13.                 int     21h; M6 |  x3 x+ @' E

  14. + [$ N) }, e2 S2 N6 Y
  15.                 mov     dx, offset msg_fail
    * i" }: v, ^5 v  d+ l
  16.                 call    A20_DISABLE
    ! [1 D- O: R9 R2 {. ]" a
  17.                 jz      exit1
    ) }' L5 w+ l: y* |+ B0 U8 h' p
  18.                 mov     dx, offset msg_ok
    0 O$ r& k+ }8 k7 P$ P

  19.   m' z8 V/ [% r
  20. exit1:          mov     ah, 09h
    9 l% H9 k' e3 I9 }) C
  21.                 int     21h 7 p8 N+ H4 x+ Z7 l% [9 _
  22.                 mov     ax, 4C00h $ E- Q4 c9 _. u* D0 j2 K) g
  23.                 int     21h
    8 v3 h; {- p) ]% Y$ S
  24.                
    1 X0 I" b  t8 R9 D, f: X  E: ?6 u" \1 q
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    ) Q/ Y8 Z8 V: g  g7 e
  26.                         "2008-07-01",13, 10, "$" * I+ C# E9 U$ W1 r; G
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    " X! C  \; r1 d( S; F
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" - S4 d/ m5 r: [' F, d$ u; Z7 C' C6 Q

  29. / P" g1 R. u2 |% O/ q' {
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ' Q7 E! E" `+ g- h; E
  31. A20_DISABLE:
    5 O: [- \7 H1 I  r3 U0 I
  32.                 call    A20Write 4 ]; q9 u. ^4 m9 S( y) W9 R* q* |
  33.                 jz      exit_disable- G# Q" o. n3 B  e

  34. ( l; K, d! b1 T4 W- Y2 O
  35.                 cli                             ; Only need for reading value from KBC # ?# j# U5 E# q1 Q0 O1 S
  36.                 mov     al, 0D0h
    & z$ b7 b# A9 a1 F* z
  37.                 out     64h, al
    1 q: j4 a4 D+ T+ P* p+ x
  38.                 call    A20Read
    + Z& K3 S/ e  \! n
  39.                 jz      Disable_int
    6 c/ Q% H  c, ]% Q

  40. # C! v6 D1 o$ z1 w7 Q
  41.                 in      al, 60h                 ; Get current status 6 ^4 _$ a; |9 U2 g4 }* G% s' I
  42.                 mov     ah, al
    0 L! Y. J! u! {7 s3 b: z/ k
  43.                 call    A20Write - [( u6 H4 G/ o
  44. Disable_int:    sti ) z7 F, h" E* E9 J. i# d9 `* X
  45.                 jz      exit_disable
    ; E# C+ Q. X6 b! c: R
  46. 1 @: Z( J0 z5 k
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 0 ?/ E( f  u4 Z# j
  48.                 out     64h, al                 ; Out Put Port next
    & z: i1 |/ o+ N. E2 ]$ G
  49.                 call    A20Write 4 W- C" ^4 {) y1 N8 I3 e. K
  50.                 jz      exit_disable3 w8 I% `# i+ _  y: I3 a! B
  51. & N- u* K2 n( A- D1 z* F! g+ I; t
  52.                 mov     al, ah 5 H4 x8 }& w/ V9 |' \
  53.                 and     al, not 2               ; Disable line A20 # N3 `( s" {8 m( F5 E( u
  54.                 out     60h, al
    # V8 K6 D. \/ I& [* L5 M
  55.                 call    A20Write
    & [  Q4 |% X6 ~) G
  56.                 jz      exit_disable
    # w$ n* U9 w( a7 G, }" a) M% b
  57. 6 |$ M: b! N$ p  U
  58.                 mov     al, 0FFh                ; NOP ) o+ K3 K" P+ ]" }* o. d- d. w
  59.                 out     64h, al   W: q: n+ U4 j  S5 Z8 m
  60.                 call    A20Write
    ) |$ x5 e" A8 z; d
  61. ( M, z: H' G0 \, w' v+ G& Z
  62. exit_disable:          ret 2 |: x4 |! i7 c

  63. 7 c% F+ S* ?* {7 z2 M
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ' V" _7 h4 h2 Z) ^8 a5 K9 E
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 7 p3 A! y8 |6 @2 r* @1 |9 S
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear * V1 ]9 b, c% l- O+ }
  67.                 jz      clear , v* {  {: E! e' Y
  68.                 dec     cx # }4 ?+ a9 P" J1 |& i2 @/ Q6 y, Y
  69.                 jz      exit_write 4 M6 K* ]$ D+ G9 z  o2 I
  70.                 jmp     short get_wirte , ^( X% V5 {1 X$ q( |! j  j
  71. clear:          inc     al                      ; Clear ZR 4 b: x3 r9 m9 ?6 R& u; |; E
  72. exit_write:     ret
    0 O6 t4 e! q9 Y; O2 Q0 _4 c

  73. 7 H3 W- \( i6 S5 X

  74. 0 c, q+ I. g- z1 ]1 k
  75. A20Read:        xor     cx, cx
    " M8 H# Q" K' U9 [
  76. get_read:       in      al, 64h   k8 _$ ]5 I2 `3 ~" P; `1 m
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    * }! W& k  N) R# S. Y* l4 ?; q
  78.                 jnz     exit4                   ; ...
    : A1 x  b. Z" u
  79.                 dec     cx % C' J" D1 D; O9 h' d
  80.                 jnz     get_read' R$ k3 B2 u. y
  81. exit4:          ret     
    - v) ^- z& p' r* @3 D0 N
  82.                 ' L, m, I: F: Q- c7 E$ e  \
  83. end
复制代码
  1. ;A20STATE.ASM
    7 _+ B$ B# ]6 K
  2. ;
    0 n* X$ d$ S' Q* K: {. V0 D
  3. ; Returns the status of the line A20 through the KBC - V. a8 A6 J4 Z2 W
  4. ;       programming by bini for debug. 2008-07-01. q7 `  q4 q" O) d, @
  5. ; 5 e7 Z. x$ O8 q+ y1 t$ K
  6. .model tiny* U7 u8 Q" x- G, m$ ?* J
  7. .code2 Z. N% {5 o4 R7 ^- D
  8. .486
    6 z. ^/ R# ]& M" h6 `- ?* {3 ]# }/ @
  9. .startup
    ) C1 ?7 I7 r. u  a- s* S/ J4 j# _6 z
  10.                 mov     dx, offset msg_fail
    # C( u0 T/ [/ m! v9 X! ]: ~' \
  11.                 call    _GET_A20_STATE_
    $ k) o1 v  `/ L8 q& F
  12.                 jz      exit1                           ;  was a problem
    4 h; D% S, K4 [5 ^
  13.                 push    ax                              ; Save state, AH 3 X! l$ e3 w5 o
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    ; d, F  w' \4 A) F5 x
  15.                 mov     ah, 09h   j* M, K& c3 g
  16.                 int     21h                             ; Print message
    , o( e3 y. ]+ [" _
  17.                 pop     ax                              ; retreve state ; o5 \1 l/ X6 }" @' z
  18. & ~- J  V8 H5 n. P0 H/ E( ?
  19.                 mov     dx, offset msg_dis 3 {1 Q8 b& Y3 A7 J" W
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state ' ?) ^( e6 F) b; i- ~% v: S
  21.                 jz      exit1
    : c3 ]- E2 V5 x- g* M# v
  22.                 mov     dx, offset msg_en
    & f  }; a* y3 R& t9 x! N9 Y

  23. $ n' U% f. S4 Y, k) K5 ]
  24. exit1:          mov     ah, 09h ; O8 A$ a9 L) ~+ f1 K8 l5 d
  25.                 ; DX already contains address of string
    ' g. b7 S$ J6 q4 |8 {
  26.                 int     21h : ^/ z) l. Q, `

  27. ' M6 @, v$ M; p5 }/ a( v+ ]
  28.                 mov     ax, 4C00h
    $ E+ X, O) n  N  i+ c  u
  29.                 int     21h 6 X; Y- u+ X1 o! f5 m" Q2 c" ]
  30. 1 `' h8 R) ]0 Q5 k( V3 s& a9 E
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    & ~$ k6 |& G2 ]4 |$ y& [
  32. msg_fail       db      "FAIL", 13, 10, "$" , H0 [, @2 J' o0 }9 \
  33. msg_en         db      "ENABLED", 13, 10, "$"
    1 k" g! U5 T  b9 D
  34. msg_dis        db      "DISABLED", 13, 10, "$"/ ?7 _, ^$ d0 f2 Q$ C2 D
  35. $ ~( @* U$ v( b2 Z' ?! ^! `: N5 ]

  36. ( l0 D6 R  @( O
  37. _GET_A20_STATE_:
    5 A+ c1 P8 L' w; j. {
  38.                 call    A20Write                ; Wait till the input register is empty 6 B# F$ C7 K% |! \, D
  39.                 jz      exit2+1                 ; Bypas the reset int's 2 \- @; f1 @8 G/ M' A
  40.                 cli                             ; Disable ints so we'll get our value
    7 Z8 C/ W, @- A, Q+ B1 m% e
  41. 4 E/ Y5 z$ j8 t+ H5 A
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 3 S$ \0 O8 m" y3 X6 o
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
      m( p6 I& Y( U& {. y5 _0 s5 \
  44.                 call    A20Read                 ; Wait till the 8042 output register
    4 {1 k, i0 i- E4 [$ M2 X
  45.                 jz      exit2                   ; has something in it's buffer
    4 t6 u6 u, d/ ~
  46. & R; y" T. b5 e' m3 S, h6 f1 b  l
  47.                 in      al, 60h                 ; Get it & w( o- Z# w1 f8 ?' u1 C% ?
  48.                 mov     ah, al ) e. D8 R+ ^, ?. ]+ a9 }9 W; C
  49.                 call    A20Write                ; Make sure the input register is empty
    # c: R/ d* d- u# a" }' s; f
  50.                 jz      exit2
    % @: N2 k7 w& v9 E: y  `& S( G8 B

  51. , M/ K/ V8 Q# H' ]: f
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 9 ~5 c9 y3 `1 I/ u+ y
  53.                 out     64h, al * h* Y9 M3 W4 _# K1 U$ g; E- H
  54.                 call    A20Write
    8 v6 A1 D  ?: y( r' h

  55. 3 F+ m$ Y* N4 z( @) Y! @$ `% Q- c. ~
  56. exit2:          sti
    6 i0 @4 }3 B7 l& o0 b
  57.                 ret
    4 l* g1 y; N+ s+ N- [! x0 ?

  58. ) I1 h1 B* c3 f9 |

  59. ) V2 x( z2 D; R: U
  60. A20Write:       xor     cx, cx                  ; Reasonable wait . Y- e! R/ v* e7 T
  61. get1:           in      al, 64h                 ; Get KBC read status ) H6 B2 Q0 G# c  N' j
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ( u- u( {- l3 Q; @0 ]
  63.                 jz      clear + ~6 l* q* t$ T8 r3 y9 u& R
  64.                 dec     cx
    , Q( p! w" T3 }- q
  65.                 jz      exit3 8 {+ g& G7 O3 ]
  66.                 jmp     SHORT get1 : E( {- [( y1 |9 h2 w) @. |
  67. clear:          inc     al                      ; Clear ZR / P. A/ e" M$ q& @9 L* k
  68. exit3:          ret
    3 `% s% }& D5 C/ ?9 r: W3 ~
  69. 2 O: D* I5 [. Z- n. u8 [& j

  70. ' u' }+ i& |, S& y: H1 P* q7 {
  71. A20Read:        xor     cx, cx . @  Q0 X7 ^& C" F' w
  72. get2:           in      al, 64h ( D' R* M$ B. @0 ^
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' _  b0 T) l6 y* d8 W4 ^
  74.                 jnz     exit4                   ; something for me
    , W0 `' \8 B5 r! A2 j8 X
  75.                 dec     cx 0 ?: i1 g2 s) d2 l
  76.                 jnz     get2; o* ?* y! Y7 A, Y2 h8 j
  77. exit4:          ret     0 x4 }# u5 t% B$ N% g
  78.                
    1 ~* Q+ V5 b( Z! E& T- T
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
5 b. N2 M' R  D{        while(inp(0x64) & 2);        outp(0x64,0xd1);
4 e4 T/ w  y- F# S' z9 O# ~        while(inp(0x64) & 2);        outp(0x60,0xdf);
4 `' E/ u$ ~1 L1 f' i: N* k        while(inp(0x64) & 2);        outp(0x64,0xff);
" w1 |6 ^) D4 R) Z( b+ A9 {}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-1 09:11 , Processed in 0.686842 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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