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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM * O3 T  @+ f6 h
  2. ; : F% r% P# H+ q6 c4 v; |# |
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    2 y/ Z  V  x' ?- k" b: i" l
  4. ;       ml A20ON.asm
    4 m8 `7 R4 `  L7 i% h0 J
  5. ;
    * V5 {( K$ a& c
  6. .model tiny
    + W% j; \1 t) {/ T/ t7 |# L& P
  7. .code) R! w$ T5 T1 g7 D" s6 ~
  8. .486
    $ k0 `' F  O2 J
  9. .startup
    ' I% U5 U$ Y. a+ X* x
  10. % b% I- m9 K/ a% R, Q
  11.                 mov     dx, offset msg_author; Y) c! {7 B. m% V# e- C
  12.                 mov     ah, 09h
      {. S2 z9 Y5 @* Y" ~6 I$ c
  13.                 int     21h2 T; G& @* S3 ^3 k* K( |4 k+ ?
  14. ! u. [- o6 d4 S
  15.                 mov     dx, offset msg_fail 1 P. C% V' R# c4 h
  16.                 call    A20_ENABLE
    ! u4 e2 t, V; C1 }7 M% G
  17.                 jz      exit1* n2 ?5 E, k1 ^0 i4 `; F( i
  18.                 mov     dx, offset msg_ok 3 J3 {9 H6 Y: v- N5 J
  19.   ]1 d/ Q9 @  \  r3 ]
  20. exit1:          mov     ah, 09h
    ( k  F3 i0 F' {. N3 K
  21.                 int     21h ! y2 P, j) B5 d: N* i+ [
  22.                 mov     ax, 4C00h
    % {( `' p4 u; _6 ~6 l, d
  23.                 int     21h
    6 U. \  I  E+ o' ?( s  o
  24.                
    , N0 p7 ]5 N# C& ]4 R
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    ( o1 n  @  U/ q7 V8 c9 ^
  26.                         "2008-07-01",13, 10, "$"   q2 ^7 T- a) B+ R
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    . J$ f& l! y0 H8 J) S
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 1 S0 D  Y# s: g. u, z" G

  29. 7 u  h3 ]" Y; U' L, V
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    & D# m9 o: U+ F) S
  31. A20_ENABLE:
    % R: W# f* V0 y% J
  32.                 call    A20Write 2 T, j. S6 [+ m8 o$ ]
  33.                 jz      exit_enable
    ( z4 n( N  e$ g- \6 C% w+ |

  34. 6 l6 x  \" E: ~$ H% _
  35.                 cli                             ; Only need for reading value from KBC
    : P6 J6 d, y1 K2 [4 G
  36.                 mov     al, 0D0h + t, p4 y, {  f1 B' [; g
  37.                 out     64h, al ( e, A; a- z% m" w8 ?; S3 l" l; @5 ?
  38.                 call    A20Read $ j+ O& ]. }5 x% g1 ?: D
  39.                 jz      enable_int ) [: R$ |$ u3 z1 X$ t1 }+ D1 O' U1 ~/ S

  40. 7 T. D$ p2 o- X
  41.                 in      al, 60h                 ; Get current status
    # u( E. m# l* d- A/ D; w
  42.                 mov     ah, al
    $ ]" ?7 u: `$ R& T  U
  43.                 call    A20Write
    $ P( X% V1 i* r; B. F# Z
  44. enable_int:    sti & S# K* z) u- K$ K9 B! I
  45.                 jz      exit_enable% q; o1 F# p, s0 c

  46. 0 J& ^& t  O  M1 U$ ^4 U( r' ?
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    9 I+ L" e" m9 B3 G/ q
  48.                 out     64h, al                 ; Out Put Port next ! e7 x% V* a5 G# e) `, n! n
  49.                 call    A20Write
      T0 Q$ u5 k, e8 m
  50.                 jz      exit_enable# D! o9 _; G2 [
  51. 7 F9 y7 S* m; ~' S4 x9 c
  52.                 mov     al, ah 4 x5 n; x. N* @* z0 H* }/ {2 S
  53.                 or      al, 2                   ; Enable line A20
    ; o/ l0 \3 ?) R& O7 I
  54.                 out     60h, al
    8 N: N4 D# e& ]! R4 l! J4 c
  55.                 call    A20Write 2 a2 ^! P1 d) U2 _7 ~& A# O
  56.                 jz      exit_enable
    + A4 D9 D9 I; p( ?1 B$ ~7 \

  57. ) ?' j$ p  q4 d( h$ i) a( d8 T
  58.                 mov     al, 0FFh                ; NOP
    % N) ]4 V" ]! m1 p
  59.                 out     64h, al ( [8 p* d5 c4 a9 _4 g3 Q. {
  60.                 call    A20Write 3 A0 C) }) R. r- h
  61. 7 i. K; [" @- b+ M, g* P& F
  62. exit_enable:          ret / L: c% P+ @4 B( P2 j

  63. 3 [& a' W7 N5 C+ N. w$ Y
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    # W2 L: @. n; O1 V: `' O2 [1 m
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    , |0 D2 Y8 Z& v- K0 k/ p
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    # u8 ~- H% M/ h
  67.                 jz      clear 5 H3 B6 Z# Q; ^, M8 V* E
  68.                 dec     cx
    + ~% b8 n8 `' ?1 E
  69.                 jz      exit_write / s/ S  t1 `. v& Q( D7 V( y9 T3 i. D
  70.                 jmp     short get_wirte ' ^# s- Z8 U! e4 O& `( y: {
  71. clear:          inc     al                      ; Clear ZR
    * H/ a9 K( i5 Q! p2 {) s# Y' Q! A
  72. exit_write:     ret
    $ ?! @$ a9 j' y

  73. + D+ f6 a; |- F$ o: m; M

  74. 6 ~/ S3 [4 O0 T; f
  75. A20Read:        xor     cx, cx + G7 `5 U6 f. D! ?3 J8 Y% w: |
  76. get_read:       in      al, 64h
    1 s8 |( L4 O& n+ E4 P7 Z5 ]- S8 g
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ) t( y( g4 d. l2 N+ n# c( h
  78.                 jnz     exit4                   ; ... 9 g7 o6 U+ q3 I0 P7 ]3 |) e
  79.                 dec     cx
    + ?  {+ y! c1 j) I. P! c/ Y
  80.                 jnz     get_read, S. z) o' @% o5 X  N  K2 f( e
  81. exit4:          ret     
    / \' p* [7 u2 l* f$ R5 y$ D
  82.                 + F. W. E# \6 q9 [2 v& B
  83. end
复制代码
  1. ;A200FF.ASM ; `; X# [5 m/ Q2 C8 \
  2. ;
    8 [0 |! c: @" H1 M9 x
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    6 z6 c( @% n" K
  4. ;       ml A20ON.asm
    - ^, W* d, C8 W% @8 t0 c% ]
  5. ; 0 j7 I) n) O( p
  6. .model tiny( O  ]9 r4 B) H, I5 _0 ?% E
  7. .code% [" t  N+ c1 \3 i! ^; `
  8. .486
    7 c1 f/ s0 k3 \- a
  9. .startup
    " k. l3 j2 ]* C

  10. 3 A4 q4 z" F, S- u$ p7 w: {- Y
  11.                 mov     dx, offset msg_author: z& R" ]' N2 D
  12.                 mov     ah, 09h( }5 {& K- r. r$ H# \) Y/ q; G
  13.                 int     21h  K* p% _" X5 F6 ^
  14. 2 [8 F9 M0 d+ E
  15.                 mov     dx, offset msg_fail
    / W" ?. e9 T2 ?
  16.                 call    A20_DISABLE1 P  Z2 S% Q6 f/ v, C
  17.                 jz      exit1# G: e% I% f+ U. Q/ k
  18.                 mov     dx, offset msg_ok , X2 g+ ]9 W9 }2 X4 d# b

  19. & k& G! G" P5 H6 ]7 i
  20. exit1:          mov     ah, 09h
    4 h$ W. y9 @8 ^
  21.                 int     21h 2 |2 M% G5 k9 A# z
  22.                 mov     ax, 4C00h
    ! }/ z9 }  s; J  t
  23.                 int     21h : ~1 d! N) K3 s$ Q2 J
  24.                
    ' p& t& W, a- i+ v# ?( h+ o3 H6 d9 \
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    1 o1 h' y( K0 L& \7 S5 [9 k' `0 A
  26.                         "2008-07-01",13, 10, "$" 6 D6 i! o7 O* x! i( K7 A
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" , d! x- `. ?$ O" {, F8 J) h
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" * s7 N/ O) j% W' s% m. e
  29. 7 N' q" K! y, |+ ^6 K
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------' Z+ d' O& H/ {% c% t! ]
  31. A20_DISABLE:
    : ^! I0 @5 j) f, r8 Z1 `& v; r4 X
  32.                 call    A20Write
    , t# q/ K  v4 V+ N: |& C1 P, i
  33.                 jz      exit_disable0 f7 N; ?  j/ G1 F. H8 Z  O

  34. . g( Y: ^" {3 t
  35.                 cli                             ; Only need for reading value from KBC " A3 O8 q" d2 S: g# ?) r2 k
  36.                 mov     al, 0D0h 6 k% l- D1 _8 V, [" h
  37.                 out     64h, al 6 _6 t0 s4 \6 Z+ P1 p
  38.                 call    A20Read ! c& d2 u. j3 b$ R7 p$ F+ k8 ~
  39.                 jz      Disable_int 9 C  i9 c% U# ?2 P
  40. 5 F$ t0 \+ Y. S# E
  41.                 in      al, 60h                 ; Get current status
    ' q7 l) _) O( p( W5 O9 ^+ d/ i
  42.                 mov     ah, al 4 m! D, `0 D) y9 R4 Y9 Y8 {
  43.                 call    A20Write
    2 A% |/ K# k) ~4 N/ e
  44. Disable_int:    sti
    / @5 L: Y2 \5 W( ~* p" ~7 j
  45.                 jz      exit_disable- }7 ^8 ~) ^% a* p- F5 q* d

  46. 1 W, M5 |- S1 Z+ E/ `
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    3 |4 I0 n5 R4 Z9 w" Y
  48.                 out     64h, al                 ; Out Put Port next
    7 |. D1 V5 q  s2 D/ m5 w* d& A
  49.                 call    A20Write
    4 h& l( I/ F5 D) Q# ~
  50.                 jz      exit_disable! I( y4 |7 T9 x

  51. , L/ f& I' Q1 H
  52.                 mov     al, ah
    & Q* x5 T' T7 a5 O/ q0 A; B
  53.                 and     al, not 2               ; Disable line A20 7 x/ y( M) U$ ~  W6 n
  54.                 out     60h, al : M8 f* |& Z9 D0 z* o. n: C2 Y
  55.                 call    A20Write
    : q2 c8 R/ _4 {3 ~2 R" X
  56.                 jz      exit_disable
    . ?5 |/ }  W# ]

  57. : y& A  ]7 i. p
  58.                 mov     al, 0FFh                ; NOP
    ! L7 c9 f% O$ G! L
  59.                 out     64h, al . f4 w5 M" h; ~' M1 ~- \. T3 a4 X* i
  60.                 call    A20Write
    ) ]5 U' i, |+ j5 n5 X& \& |

  61. & i( c5 ~& ^1 f2 p" p7 c
  62. exit_disable:          ret ) ~/ v* K. @$ H& y+ J
  63. 0 @7 K0 x+ A) ~" \2 _
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    8 Y" I: d. \" A9 g
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
      d# m; W- T! l: h& e& [
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    + F1 N0 R8 ^: h' N* {% k8 O9 A
  67.                 jz      clear 3 P8 j9 V' F  D. R
  68.                 dec     cx 5 S! f0 O) X, ]3 N
  69.                 jz      exit_write & ^0 v0 h$ o$ K7 T8 t
  70.                 jmp     short get_wirte
    - J4 k' E: e. S" J  M: i3 o
  71. clear:          inc     al                      ; Clear ZR 5 b3 n5 E. ~" f- m
  72. exit_write:     ret
    , y2 ~( Z6 B$ l" q5 m9 P( Y6 Q9 b7 H
  73. . w0 l4 i) O" J) s# B
  74. + T. J1 v9 q$ F& e5 X$ H, }) I
  75. A20Read:        xor     cx, cx 2 Z  O* k$ X7 d3 W: P( B, S6 T+ x
  76. get_read:       in      al, 64h , V$ g% x; F) N* J& U+ I
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    4 C% X2 p/ ?# k5 w
  78.                 jnz     exit4                   ; ... , X# e2 [& T0 ?2 J9 s
  79.                 dec     cx 7 x: ?3 n- k8 j5 n
  80.                 jnz     get_read
    4 q& B* m( {; @; p3 l
  81. exit4:          ret     
    . c  i' n6 X; a9 k  n
  82.                 ( c# p, k  O8 w! o
  83. end
复制代码
  1. ;A20STATE.ASM 0 Q  Z! s, B: Z6 m
  2. ; + l; a7 I* D. K$ @4 m0 M
  3. ; Returns the status of the line A20 through the KBC
    1 r) i% R* M% I0 s3 N( X$ R! R
  4. ;       programming by bini for debug. 2008-07-01
    ) B  R5 S' g) S: t/ R; Q
  5. ; # r2 |0 j# s/ ^3 S, ^4 g, Z
  6. .model tiny) \- [+ F$ u6 K5 Z
  7. .code
    . v0 e" [7 }& Y/ m
  8. .486
    8 c& R9 n* F' j6 {5 ^
  9. .startup
    $ [( W4 `& s4 K+ s4 X! A9 H0 I
  10.                 mov     dx, offset msg_fail
    , i7 q2 O+ Y3 d; u0 E
  11.                 call    _GET_A20_STATE_
    " \8 G* g  G, ?3 [: N4 v: J: A, a, N
  12.                 jz      exit1                           ;  was a problem
    7 ^6 `4 x8 {9 j
  13.                 push    ax                              ; Save state, AH 8 y, A! `  T+ ]& R0 N
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    5 C8 B$ F5 @' i8 O) `
  15.                 mov     ah, 09h
    8 W! {5 j8 b- e; T; U5 h2 z
  16.                 int     21h                             ; Print message
    # A0 k( ^6 t4 X, O7 K; {% ?
  17.                 pop     ax                              ; retreve state
    8 @% {' f+ B! \% b3 |
  18. ) ?0 T; F) D" Q& i6 l7 k
  19.                 mov     dx, offset msg_dis
    ! H! l- A- j, b  v  E' U
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state ; }% Y, ]2 h! K! _  i5 k6 Y
  21.                 jz      exit1 + R! e0 G6 V* w
  22.                 mov     dx, offset msg_en
    9 G  e- P/ g8 [

  23. / y" Y8 y' i! t- J2 y! ]
  24. exit1:          mov     ah, 09h / S) \  K/ C3 }: G; ]6 C
  25.                 ; DX already contains address of string 2 e5 I1 O' ~* t6 d) b5 \# u
  26.                 int     21h . W2 y; v2 e( z: c

  27. 9 n6 z& `' i! ^8 U
  28.                 mov     ax, 4C00h
    + ~; V, x7 b1 {" N& {7 Z* L
  29.                 int     21h
    + t% x0 r9 ^$ x8 v; P8 [5 ?# \

  30. 8 Z4 g; b$ U0 Q0 J7 @- z) O0 C+ ~
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ' j0 c# B* i& g& i' I0 U1 ~% G
  32. msg_fail       db      "FAIL", 13, 10, "$"
    6 H6 }6 j" n. E  @& J) C
  33. msg_en         db      "ENABLED", 13, 10, "$" " A& G& W" W% N' ?9 A& {2 I  c; U
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    ' s* x" A- `4 P

  35. 1 p- h& J  d. Z+ d4 \  Q

  36. 9 b+ S) G0 |2 q
  37. _GET_A20_STATE_:
    : J& }* ]+ U" H" u7 a  F0 Z
  38.                 call    A20Write                ; Wait till the input register is empty 1 u9 l% u3 x. A# H/ ]  h* H; w
  39.                 jz      exit2+1                 ; Bypas the reset int's ; P2 }, J0 x/ H4 E
  40.                 cli                             ; Disable ints so we'll get our value + t( ]' y1 f& F7 ?, `1 M/ `' M

  41. : c3 b. z7 f: _7 K) Z3 J
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 2 P8 l0 v& I4 z% X
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port % K3 W- G( q' ^3 T
  44.                 call    A20Read                 ; Wait till the 8042 output register $ b  J2 ]% E* \$ b/ Z3 L
  45.                 jz      exit2                   ; has something in it's buffer * [9 }# f4 i+ \6 O9 r  k/ N" `* n) v1 i

  46.   R: u5 P* f% J- @+ W# R: N
  47.                 in      al, 60h                 ; Get it . b# j4 M. I) W. A0 }
  48.                 mov     ah, al
    2 P) \+ S2 A* \
  49.                 call    A20Write                ; Make sure the input register is empty # i) y$ c' x# d
  50.                 jz      exit2
    ; u' u( v4 S' I" i

  51. 8 ~, S* i+ \  ?8 G3 N% k( S* D
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ( {# G& W; o: H/ s8 d: h
  53.                 out     64h, al
    + c; w- ^) {- h4 w6 E; J
  54.                 call    A20Write
    ( O2 W/ G% ^7 o" b. ]5 ]0 }
  55. 7 c7 U) d! `8 |
  56. exit2:          sti
    : o5 C' X) c! v5 R
  57.                 ret( h# j1 ]9 k4 ?3 K1 U

  58. $ B2 ~* j/ B; l: W
  59. 6 G' V5 f' M0 D- Y3 X% Y( {
  60. A20Write:       xor     cx, cx                  ; Reasonable wait ' ]$ j: {! ~3 N- n) j4 {
  61. get1:           in      al, 64h                 ; Get KBC read status " N6 F5 i+ ]( n/ H7 @, o' m- j& d3 o' m2 W
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    % |. l7 p* J# o
  63.                 jz      clear   D* S: g2 m4 e; z' P0 S0 C8 k- T  r
  64.                 dec     cx 2 {* |2 Z5 _$ @: {6 H/ z
  65.                 jz      exit3 / k/ ?: J2 j1 v
  66.                 jmp     SHORT get1 ' O+ r9 I+ y! g4 c6 \
  67. clear:          inc     al                      ; Clear ZR / b6 r; @$ Q& t8 V: V- Z
  68. exit3:          ret 6 N* b$ L; M/ r5 L# l- _% X3 s! L

  69. $ y- ^; t' Y( \) f* D( Y2 `2 y
  70. - H( t/ L/ w% c. t. ?* y
  71. A20Read:        xor     cx, cx ( t( c. t  `8 S4 u
  72. get2:           in      al, 64h
    3 Y9 |: Q  }3 c: `$ B9 t
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 1 x' V: o1 k2 O
  74.                 jnz     exit4                   ; something for me 6 h8 |$ v& t  @4 ]5 X  z
  75.                 dec     cx
    " r" @$ U9 d/ @$ [1 |- ^! i+ H
  76.                 jnz     get2
    0 l2 L0 J7 U0 @1 j% Y, q" B# H) u/ O
  77. exit4:          ret     5 [6 D3 `. {2 [& C4 ^* @. [+ W
  78.                 2 P% y0 Y3 ^5 ?; a4 m  e- y
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()) t- @; [6 b/ n# \0 q( N
{        while(inp(0x64) & 2);        outp(0x64,0xd1);! X4 o! t) ?: x2 D  g% |& G+ Y
        while(inp(0x64) & 2);        outp(0x60,0xdf);
* V7 E: v4 b* }9 Q( l( g        while(inp(0x64) & 2);        outp(0x64,0xff);
* {# t4 V2 \! s}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-8 10:54 , Processed in 0.364566 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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