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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    7 H3 K/ Y3 n) W  e( `0 x2 c
  2. ;
    1 G, ^8 C  v7 ^% E, C( q  V  B, e
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " K& Y% P+ t9 H) f% n7 o
  4. ;       ml A20ON.asm 1 m7 i; S" @( ~$ t+ M
  5. ; : P6 c( {. X; c; V* D& @/ \
  6. .model tiny
    / @- ?) I+ w0 U9 @( T6 W2 L) c
  7. .code
    ; D  x# E- [) a& `7 U7 N
  8. .486
    6 i( ]) U2 p( j! @9 W# n0 J5 O) D
  9. .startup
    ' K% f! s) S: g% B% o9 P5 s' B

  10. 0 C% V" U6 R, L
  11.                 mov     dx, offset msg_author1 b0 C( y- l3 x( e8 J* C4 ]
  12.                 mov     ah, 09h
    / O, ~2 ~' P' s
  13.                 int     21h
    2 N6 B$ E4 a4 @
  14. ' R: V0 K3 v' L
  15.                 mov     dx, offset msg_fail $ {, p3 B. a7 z( q7 `
  16.                 call    A20_ENABLE
    5 f7 Z+ F$ ?; ~( T  M8 d$ }
  17.                 jz      exit1
    . u; J) l, t! ]+ Z; m! F
  18.                 mov     dx, offset msg_ok ; c& u9 F" X( G% ^
  19. ' J/ Z7 V- l% T* }6 t9 t
  20. exit1:          mov     ah, 09h
    0 E/ `% h& x1 {6 M
  21.                 int     21h
    0 o4 a8 z0 k1 J$ h( S* b4 U
  22.                 mov     ax, 4C00h
    ) S5 ]6 L+ R4 k, m# c- w6 N# {
  23.                 int     21h 8 L0 W  W: }/ G' e' D2 [# }
  24.                 1 k2 j) t# s- I( Y
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    0 ?) z% x% \" n# [! ]& Y8 G& `1 |; J
  26.                         "2008-07-01",13, 10, "$" 1 X7 s) ~% E9 r# y0 q* r8 Y3 y
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 9 X# C9 W5 S- e9 P" [7 }
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    * {" u3 `: @+ z6 x
  29. ( j# b0 h& o' {, s" u  O+ N
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    1 u! j  Z9 M' Z% D9 w$ X" s
  31. A20_ENABLE:
    1 b% m! P1 u" A+ N
  32.                 call    A20Write
    # }( t" X& s9 ~" n
  33.                 jz      exit_enable
    ; F4 T: u6 X' f
  34. 2 u' Y  q# ~# n# w; Z
  35.                 cli                             ; Only need for reading value from KBC
    1 V# u8 v" Z( n7 i- O4 J. `+ d
  36.                 mov     al, 0D0h
    " e! V) C( g- V2 Q! L
  37.                 out     64h, al
    $ T# |: v6 F0 T1 U$ ~0 M$ E
  38.                 call    A20Read ; A" L( d0 o6 ]0 S2 }' q5 }
  39.                 jz      enable_int
    & [4 v" z( L6 G" e: x1 e5 t! P& @
  40. ( ~3 J) U1 M) p
  41.                 in      al, 60h                 ; Get current status
    / B. b1 ^4 B0 N' r' p
  42.                 mov     ah, al $ u$ b" c& n& D! f: @6 F
  43.                 call    A20Write " @# W5 q3 B- c( n
  44. enable_int:    sti 5 O4 \" A, d5 Q$ p1 J4 Z6 {5 s! N
  45.                 jz      exit_enable  o5 F6 T: n* m5 g. A
  46. 6 _. n# f$ L! Z+ |8 k5 p
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the " G7 H, v3 f0 ^8 p
  48.                 out     64h, al                 ; Out Put Port next 7 c9 h2 {5 E  y  V
  49.                 call    A20Write - y! v; l" F8 W; _  {! ?
  50.                 jz      exit_enable
    : X& x5 d9 X% v5 X, v: E. ~

  51. 9 y/ ^5 V8 p; D# \
  52.                 mov     al, ah 7 r* k- Z9 g9 l% ~
  53.                 or      al, 2                   ; Enable line A20
    ) Y0 O7 k. o5 l' ?+ j( U) n% q) J0 n
  54.                 out     60h, al 3 N- J. M* a, {
  55.                 call    A20Write 4 F* i- T% _: W( {4 X) b4 F' i% D
  56.                 jz      exit_enable
    & \2 r4 |* e6 [/ c3 ?1 @1 m% j

  57. " t% e7 A/ X: ^) K0 F4 _# Y
  58.                 mov     al, 0FFh                ; NOP * P$ n; V3 w+ F5 R5 H' B  u
  59.                 out     64h, al
    # ?" h9 H* c0 [, x% z
  60.                 call    A20Write ' i) S+ }/ |9 ?+ y; Y
  61. * W) J# }6 j  L/ m9 _+ c8 z# I
  62. exit_enable:          ret 3 ~6 _5 y& O. h$ ^* N# s8 b& @

  63. ; S! _6 Z& o! a- T# J4 s
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - k" K3 Z& B) X8 }, r+ `' `
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    & [" d, ^3 I- j! [* U( q- m
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear & p& Q9 n" x6 C3 G7 B7 v
  67.                 jz      clear
    ! i4 Z6 y6 s( y- n& @7 _
  68.                 dec     cx 5 C. T6 p& M! u% a! c/ M) G+ B) D. G
  69.                 jz      exit_write + f9 w6 E+ @) \7 \& @. ?% S0 G
  70.                 jmp     short get_wirte 8 [" t7 e5 b- u3 D/ R9 Z8 i2 f& R
  71. clear:          inc     al                      ; Clear ZR
    # I) u1 V! u* k2 |& N
  72. exit_write:     ret 8 y1 t0 X2 {7 @1 w
  73. / u7 q9 n8 D/ J" `2 }! ]
  74. % O- B! }2 K7 {9 f7 z0 z
  75. A20Read:        xor     cx, cx 3 y3 p0 e6 ^& h. S
  76. get_read:       in      al, 64h 7 a. L- M5 V1 p) p
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 6 k; F3 L" K+ x; k
  78.                 jnz     exit4                   ; ...
    ( ]; O% k& Q% p' Q6 U( A
  79.                 dec     cx 9 W* @- p3 m2 h2 \4 [  s9 I
  80.                 jnz     get_read) s% R, U! i9 |+ s" U
  81. exit4:          ret     
    * R+ n; M2 C! j; F
  82.                   ^# w: Y: N, b& D! q9 d6 {: }* X
  83. end
复制代码
  1. ;A200FF.ASM
    0 `4 Z6 A  }! c2 E! J: r4 r
  2. ; * x3 V3 \0 X4 `" T. M, A/ d6 y0 Y
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-011 y# D2 H) F# r7 l2 s1 V7 q: }
  4. ;       ml A20ON.asm 0 X( F  ]: w% Y; Q9 U  o1 d' `# o
  5. ; ! y. h3 c4 V; L( Q6 }7 ]
  6. .model tiny
    5 `( `1 \6 a* [' I
  7. .code+ Z1 y9 }8 W5 e( }2 O5 a
  8. .486  i2 x+ I. ]1 O. X( x
  9. .startup& }0 M" a7 ?' [4 x- F

  10. 6 }& ~6 |# ^& _
  11.                 mov     dx, offset msg_author8 X% z. T* |* c$ n, p
  12.                 mov     ah, 09h
    ; R) v+ O# X  L4 l# n' V
  13.                 int     21h1 r2 [9 r; r9 f1 W0 J- i3 n% \

  14. * w6 j1 ~! A  J, f5 ]6 ~7 h0 v1 U
  15.                 mov     dx, offset msg_fail ( L9 M/ z' F+ _. p% T8 z8 Z1 K, \
  16.                 call    A20_DISABLE
    + ^# }3 z1 ^3 y6 o4 @2 k8 K$ G
  17.                 jz      exit1
    8 J- d0 p, W1 F4 s  M+ i8 T3 A' Q
  18.                 mov     dx, offset msg_ok
    " w, e6 ^9 J6 @2 h
  19. ! l( D" B# o8 W5 e
  20. exit1:          mov     ah, 09h
    2 s5 J' c' y- y- X: X: y4 G
  21.                 int     21h
    ; T) k2 f( z; }+ L
  22.                 mov     ax, 4C00h
    3 ~4 W- S, o: m8 _, E
  23.                 int     21h $ ^2 |) O% b2 I/ ]1 a+ }+ X
  24.                 , Y* c8 [* q+ F+ A3 R) q$ C- h4 m
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    , {- u# z/ L% ^2 I
  26.                         "2008-07-01",13, 10, "$"
    ( C/ u& }2 ?- N4 Q: x
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" 6 }7 Z4 ^  Q& ^  t; `8 g
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    - b2 T% c6 L3 V

  29. , @( o6 X" Y0 R6 X- Q# O; O
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------  Z8 j( U% U3 J6 _$ r4 Q
  31. A20_DISABLE: 4 r5 E$ w2 V: V3 x
  32.                 call    A20Write 4 r1 k. x( Y( n  n4 @
  33.                 jz      exit_disable
    ) v4 U# Q1 g) I( p& O
  34. & a, x( J5 w6 T. }
  35.                 cli                             ; Only need for reading value from KBC
    3 s! `# g$ W1 A5 C' \( M
  36.                 mov     al, 0D0h
    . `. j  O3 Q+ P5 h7 b  t3 d/ F
  37.                 out     64h, al & E/ l, T0 h) Z4 V
  38.                 call    A20Read
    8 F9 l$ G# }. q( M8 p
  39.                 jz      Disable_int 0 s: K% b0 L6 s" w- b- m2 ]* E

  40. " c5 a: _0 {4 P0 Y
  41.                 in      al, 60h                 ; Get current status
    2 d& l& `7 R( z# [. x  H3 k- K$ o
  42.                 mov     ah, al
    % Y- w5 K& S5 a+ J# C8 i* X
  43.                 call    A20Write ' z/ o2 c0 K" }3 k
  44. Disable_int:    sti
    + }! n' G  e* n/ |2 i; f/ j' P
  45.                 jz      exit_disable
    - V, x/ n( k9 k* D9 Y

  46.   ~; M0 O9 S: z1 o
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    - R4 Q. ?+ c1 p+ y+ ]7 G8 K
  48.                 out     64h, al                 ; Out Put Port next " R+ p  ]% J* r) ~
  49.                 call    A20Write
    ; ^4 g7 d& [; t. C) y# l
  50.                 jz      exit_disable
    3 l& P7 B: h; ~8 U7 N1 d
  51. ! q- }3 |8 a2 y# y- ?4 H/ m* n
  52.                 mov     al, ah ! B; K8 ^& S6 {# ^, C# \
  53.                 and     al, not 2               ; Disable line A20
    % k/ y, a' W7 g4 P* U
  54.                 out     60h, al # n& B9 \+ R# D7 d9 e
  55.                 call    A20Write $ }' K" ^: H+ v* g, C/ R
  56.                 jz      exit_disable
    ) g1 x" `  u- Y
  57. " S/ C5 E1 A; i( \
  58.                 mov     al, 0FFh                ; NOP
    ( V+ ^+ m9 z, Z6 k/ y6 [( Y
  59.                 out     64h, al
      q2 `& h9 M% E/ ^) A* O
  60.                 call    A20Write
    + Z# \% `# m2 E3 n. j' d& z

  61. % V2 W& X) g; @& o! N
  62. exit_disable:          ret + ~/ V. \0 D" Z$ B7 o6 j7 F

  63. , J( F# t3 |; S
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ( i  ?/ i$ t) u4 l9 Y( E9 l
  65. get_wirte:      in      al, 64h                 ; Get KBC read status / o9 A# J$ H9 T/ j9 {/ X% f- p/ [( q
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ; o0 U7 g* x% |* h
  67.                 jz      clear 6 _4 ?8 g! o1 e2 z2 r  h
  68.                 dec     cx 3 G5 f) d1 ~1 y
  69.                 jz      exit_write & e. n! U5 K, S' B, N6 n
  70.                 jmp     short get_wirte
      }5 A# p. ?# y/ s% [$ d$ G
  71. clear:          inc     al                      ; Clear ZR
    6 ^& X( [* v; y% x
  72. exit_write:     ret " ^. D- c& J+ q( `6 O+ K$ e/ O: M

  73. - m' W+ ~; w* {4 I+ W  ^+ Y) N
  74. 1 y* ?# J3 g/ o, T% w# q8 z
  75. A20Read:        xor     cx, cx 4 c8 ]  J. ^( D6 g
  76. get_read:       in      al, 64h : j* r2 q4 v. }2 i% \+ M" s
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ( Z3 G' T8 b/ d. V* n1 I9 `  q
  78.                 jnz     exit4                   ; ... 7 [/ V% W' u' _
  79.                 dec     cx
    ' ~! c  P5 G: c  Q
  80.                 jnz     get_read" ~2 T  @% W+ x
  81. exit4:          ret     
    ; c) \6 T; ]  O' i
  82.                 ( e3 X. I6 Z7 e7 ~
  83. end
复制代码
  1. ;A20STATE.ASM
    , O6 w9 c7 s5 r4 _# R1 S
  2. ;
    ' j3 x: }( q9 ]% l4 t& s( i$ s5 B
  3. ; Returns the status of the line A20 through the KBC ' V' f2 Z' h( S- Z. J. g
  4. ;       programming by bini for debug. 2008-07-01
    : {+ B* ^5 p7 H
  5. ;
    $ D! T9 }2 N  ^% k" a: ]
  6. .model tiny
    % Z6 r/ L' _) @3 x) U( ?
  7. .code
    2 o/ K8 R4 W  @9 d  h5 ?" i+ @% t
  8. .486
    7 a5 m/ E9 ]9 ^2 B
  9. .startup
    5 L3 u7 M5 e8 g" x8 s
  10.                 mov     dx, offset msg_fail
    ! `  O. V1 Y+ Q% W% m
  11.                 call    _GET_A20_STATE_
    # u* O. W9 H' [# n! W
  12.                 jz      exit1                           ;  was a problem
    ' ?& o) R% r3 x. u% e. y
  13.                 push    ax                              ; Save state, AH $ Y& D- m' w+ g" N3 @0 n
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem + V, o/ z0 B( V: ?$ {5 c; {) S- |
  15.                 mov     ah, 09h , x: Z6 K4 t/ F  W. V4 {
  16.                 int     21h                             ; Print message 9 `4 R4 d7 o$ v1 C1 Y
  17.                 pop     ax                              ; retreve state
    6 x: V; F  x8 W8 [( L

  18. . n7 S- z- _0 D4 _0 b* a( g
  19.                 mov     dx, offset msg_dis 3 ]$ ]1 Q* d  {5 t
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state , b# _" i- P- K0 H
  21.                 jz      exit1
    ' [- b) b$ l4 D0 r
  22.                 mov     dx, offset msg_en - V& _" m' D) ?' T) r! ~

  23.   a& H6 ^& O: c/ g
  24. exit1:          mov     ah, 09h 6 d/ L% f5 y* T& H+ B
  25.                 ; DX already contains address of string , K6 X+ ]2 h( W8 S0 B2 F$ S6 v
  26.                 int     21h 5 D: J: i8 E6 o1 N% m
  27. + E" c# D& r( b8 K+ i4 k# _6 ~
  28.                 mov     ax, 4C00h * A0 q( A- C8 M
  29.                 int     21h % s" _" @: H$ ^  v$ l- k

  30. , g. |6 w3 S8 D* W, g3 N9 a4 A6 D
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    , {* |, t& \1 O8 ]
  32. msg_fail       db      "FAIL", 13, 10, "$"
      V7 _+ q3 ?% `& q9 s0 z7 L
  33. msg_en         db      "ENABLED", 13, 10, "$"
    # c! ^0 n; ?( W8 D7 E7 D7 _* a
  34. msg_dis        db      "DISABLED", 13, 10, "$"% V6 T$ [" Y: Q0 ~8 P# Z

  35. 3 _! n# R2 e! O0 j+ p/ K
  36. ' \/ e+ r2 I; u, Y/ Y" j, n
  37. _GET_A20_STATE_: ( q, _* _% N  I! H  U9 r: X0 N
  38.                 call    A20Write                ; Wait till the input register is empty ' i. Q0 x' B. O. X- e2 t
  39.                 jz      exit2+1                 ; Bypas the reset int's
    4 l: y- q9 l( b; p$ w2 j
  40.                 cli                             ; Disable ints so we'll get our value
    - Y! r* y% u" l; Z6 `( a
  41. % P' B9 k" ^3 q3 h* X1 i$ H
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register ' j' c9 _! Q/ X, v# \* x: I9 @+ Q9 d
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 4 t; c; z8 b8 g' _7 `) S! F& O
  44.                 call    A20Read                 ; Wait till the 8042 output register % b( P8 r! q9 z8 l! ^
  45.                 jz      exit2                   ; has something in it's buffer ; _& G" e$ }  s: i3 d
  46. 2 u% K1 \) D8 H( M; u# X
  47.                 in      al, 60h                 ; Get it , G7 V( Q. I. J
  48.                 mov     ah, al : T% Y; x4 E' t/ C/ Q6 Q6 ]
  49.                 call    A20Write                ; Make sure the input register is empty
    9 k$ S3 Z8 s) ]" [! @/ d
  50.                 jz      exit2
    & e4 S* a5 C3 c, n6 ^
  51. - R( ]# s2 w& X! S& l& Y
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ! s9 K! x" Y1 B) r0 H% J
  53.                 out     64h, al
    8 [1 G( c- V+ U- @& M1 m# ^$ O
  54.                 call    A20Write
    4 Z' E8 ~# s& E6 r9 S, J+ {
  55. + F2 S! s% \- G( @5 K6 ?
  56. exit2:          sti 4 r5 H4 y% c: s, A, S' A! u
  57.                 ret
    7 t/ z  M& T: r6 Q0 E
  58. , E% U! @/ l5 W7 k

  59.   T: S" L: |& ?  J6 u1 K$ u
  60. A20Write:       xor     cx, cx                  ; Reasonable wait . }7 K9 |; v5 @( o( x) }! K. s
  61. get1:           in      al, 64h                 ; Get KBC read status 2 P! m  ?( o/ o
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : d, [+ J9 U  D. ?$ t- ?" \. \
  63.                 jz      clear / G8 u, g* k, |4 v1 A) J  D6 ^8 s8 Q
  64.                 dec     cx
    - b& v3 E& P( F9 J( N0 `. r0 O
  65.                 jz      exit3   E" I+ s9 s* h3 o2 ?" p+ V0 {4 J
  66.                 jmp     SHORT get1
    ' U1 {$ J- F* x3 U& \$ y* x  S
  67. clear:          inc     al                      ; Clear ZR , H6 s2 `$ K+ D. ]" M! P7 N
  68. exit3:          ret ) Y+ [, d/ W8 v$ J  Z* y

  69. 6 E6 O* l' {$ T
  70. & \; Y1 P* P4 H4 i2 `; P' o
  71. A20Read:        xor     cx, cx 6 U, A/ d6 m' l$ n" P/ Q
  72. get2:           in      al, 64h 0 |4 \0 ?( Z1 O  B* E1 o
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ! |3 g- {1 I! m5 l
  74.                 jnz     exit4                   ; something for me 2 g/ ~- [; B0 I/ z: j
  75.                 dec     cx
      k% E8 _7 w9 q0 @2 m
  76.                 jnz     get2
    " G" k6 q5 c& t: I
  77. exit4:          ret     7 M9 y0 G. q( i0 p, l& G1 T
  78.                
    2 b& O  h6 h" C. j2 H
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
- B  w* a2 h+ r! [{        while(inp(0x64) & 2);        outp(0x64,0xd1);
) W- v+ W2 |# w        while(inp(0x64) & 2);        outp(0x60,0xdf);6 G  h1 f3 R$ H: \4 T
        while(inp(0x64) & 2);        outp(0x64,0xff);
, X! t" V1 x4 b5 |; D! {}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-4 00:33 , Processed in 0.204843 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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