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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    5 l1 d6 u- P) r
  2. ;
    ( F; |$ C9 r& ]3 p9 F# `
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    4 ?" v; r# N1 D! O1 ]! Q# l7 [+ F3 T
  4. ;       ml A20ON.asm
    8 z. o  N7 i  X+ A; T" F
  5. ;
    ) Z4 n; v" |2 i! q
  6. .model tiny
    " A) Y  l& p9 }6 x! N4 R* W+ d
  7. .code8 ~: B& g( P' X  O0 p' s
  8. .486
    ' Z- a6 y* d4 V, m7 O* g' W
  9. .startup
    3 {+ U) q9 e2 q
  10. : V& I" G2 k- f6 p4 j/ S
  11.                 mov     dx, offset msg_author
    8 h2 j7 V' z4 ~
  12.                 mov     ah, 09h
    ! h# i% N7 O4 s# `7 [: M! Y! V
  13.                 int     21h/ K( i- ?5 f4 f- q4 u. X, z

  14. 4 ?: ?' V5 }& a4 `- S
  15.                 mov     dx, offset msg_fail 5 m9 I" n4 k3 v8 {; o  k9 a- _
  16.                 call    A20_ENABLE
    8 O2 b8 Z* W! V; W9 P
  17.                 jz      exit1
    4 d* }2 k; u9 W$ A
  18.                 mov     dx, offset msg_ok
    ! L1 n! }% f3 v  V
  19. $ |5 g9 v1 e3 G9 S: `
  20. exit1:          mov     ah, 09h
    4 T5 _) q3 ]; \
  21.                 int     21h ' ^# W. r: ]* D; q
  22.                 mov     ax, 4C00h & o: P0 {. P% w
  23.                 int     21h / l9 _0 f# p9 w. q
  24.                 % @0 c" I& C) [5 I
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    * b* B/ t+ q9 C% b' O2 K$ E
  26.                         "2008-07-01",13, 10, "$"
    " n" ^5 f+ x3 i! ?9 T9 R) n% N
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    8 }' q; M% i* P, X) ]2 L- Y
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 1 B% I# t/ o+ \2 z: K

  29. * f1 ?9 B, z; t6 S) U  N0 p
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------* c3 q" Q; j2 K0 R. ^1 O1 P
  31. A20_ENABLE: & k- U: }7 E# X3 e
  32.                 call    A20Write
    , `8 l- P! d, z; G, E5 A# Q) c
  33.                 jz      exit_enable
    * b) `" }# \- P

  34. ; d/ X% v- w  y8 L  D* z
  35.                 cli                             ; Only need for reading value from KBC 2 e0 d" Q" d2 V) ^8 Y/ Q$ `  r. w
  36.                 mov     al, 0D0h
    $ X) O! H. j1 s6 k( W0 i  D3 @( v2 E
  37.                 out     64h, al
    & o# r+ a* o3 D+ o! C
  38.                 call    A20Read   f! W( d/ j3 K
  39.                 jz      enable_int
    & |8 q. b+ q* G$ U/ u6 A9 V1 u  J/ {' `
  40. 1 w6 D3 `. N+ J, ]9 g9 H( s5 k4 q
  41.                 in      al, 60h                 ; Get current status - K& E- j6 I9 ?9 y: M
  42.                 mov     ah, al
    2 k! z  ]$ }/ ~( w
  43.                 call    A20Write
    7 A) i  t, w* v/ M
  44. enable_int:    sti 5 X- w) m5 }* }/ S
  45.                 jz      exit_enable
    ( A5 Y4 ]+ V. L2 q$ p
  46. * v' p$ p; x9 A3 y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    0 h  n# D5 O- j6 L
  48.                 out     64h, al                 ; Out Put Port next % n9 E0 k; I2 \' N. ~
  49.                 call    A20Write 0 ^! b4 a# P7 W
  50.                 jz      exit_enable, D; k. y7 D0 k3 ]# r/ g
  51. 0 @1 R  _. p$ m3 B, j
  52.                 mov     al, ah
    . m5 Q& A! ]$ h
  53.                 or      al, 2                   ; Enable line A20
    + ?5 x8 y2 v& B9 N' \8 M: f+ N. Y
  54.                 out     60h, al : D: n& G5 m, q  c- [5 W5 j
  55.                 call    A20Write
    ( v$ i* G* L9 z3 k' h% i4 l
  56.                 jz      exit_enable
    " f% l, s5 \9 s% R* H1 T8 T! I
  57. 5 k  A! X' Z% t2 r( k2 {5 D
  58.                 mov     al, 0FFh                ; NOP ( `3 M, u/ o2 f  I3 C$ h. W- J5 j
  59.                 out     64h, al
    & N  T3 v. r, c. t( L  \
  60.                 call    A20Write 2 S9 r5 f8 a( \8 k6 g1 D
  61. 5 j- [0 S2 d; A5 z
  62. exit_enable:          ret 3 D; S8 c# T- O3 q7 s1 x/ x

  63. ; l+ X3 {: ?: u' z6 [
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    3 x: k, t; _: ]# t$ O
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    . c) Y, c: u$ u. x
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear . j( H: q; Z9 I" z
  67.                 jz      clear 0 G5 C1 A7 ~6 ?' g5 Q( [
  68.                 dec     cx . @2 A( Y' e" d+ y8 ~, v; Y
  69.                 jz      exit_write 9 }1 l# c& l' }
  70.                 jmp     short get_wirte / H5 O7 r* B  E. \0 M
  71. clear:          inc     al                      ; Clear ZR & H! r# v( c% |1 i' h! V+ ?9 \
  72. exit_write:     ret ( |  R) V. c# z: I" Q
  73. ; G" [  L! x  O

  74. & L/ c3 Z7 k% C5 d( E7 t
  75. A20Read:        xor     cx, cx
    + ?8 t* N; `0 l
  76. get_read:       in      al, 64h ; Z) |2 m  w! y2 f3 F% U
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    8 W: ?" i& K% @* m# z
  78.                 jnz     exit4                   ; ...
    + _2 s: n8 K( n& F  E. S
  79.                 dec     cx
    9 P# S5 a% |; H7 |, N
  80.                 jnz     get_read
    " {, X) v" k% ?* P4 h
  81. exit4:          ret     
    & g5 j) M* W6 ~
  82.                 # a! r. `% K% Y2 d% B
  83. end
复制代码
  1. ;A200FF.ASM   g6 q2 k8 {2 V4 U! `) I5 k
  2. ;
    ( D. [) g2 n, u5 F
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01+ \( t8 F0 I2 {- [# [7 b* f: Y
  4. ;       ml A20ON.asm
    8 y1 U$ b; Y6 B* |" x3 z2 R; J1 {
  5. ; 8 X9 o3 [: `8 P& ?5 \$ L2 V/ v/ h; d
  6. .model tiny. V. H) b2 n4 Q7 P
  7. .code+ |! Y" a% i5 l$ e+ l2 H3 U# x0 H
  8. .486
    8 p5 c0 D: p" g. J" \
  9. .startup4 o8 G  v: V. l9 _9 E3 N2 t2 l0 j

  10. - r- b- d8 K/ \
  11.                 mov     dx, offset msg_author6 J* D4 d6 g! J2 r3 w' o# C7 x! S
  12.                 mov     ah, 09h  o  ~/ O) U: o- a# X/ ?) F( E
  13.                 int     21h
    ; A5 i+ J& m+ \7 t
  14. $ v: P/ C! N) X! k& c
  15.                 mov     dx, offset msg_fail
    $ R7 G1 ?0 R& Z5 U" z8 s2 T" R6 D
  16.                 call    A20_DISABLE
    , d) I  f, Y; n+ S- S! T) U* s
  17.                 jz      exit1$ g  ~. V; [% j. I! _& u
  18.                 mov     dx, offset msg_ok
    ! m1 j. H$ c6 J

  19. 5 }5 l( k" E0 ]8 C% T2 m  X
  20. exit1:          mov     ah, 09h
    . T6 \" j# ]/ Y  G' r
  21.                 int     21h
    1 z% \; s1 k, d) _+ M! y. y( Y8 R' {
  22.                 mov     ax, 4C00h
    % W; }7 C9 s* F% _5 f8 @5 k( A! a
  23.                 int     21h 8 y" |6 j2 {. h3 p) ?3 \
  24.                 $ }3 R* L' `0 ^4 j3 X/ _
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    , |2 C3 _) o* A% T  V3 U! f% B
  26.                         "2008-07-01",13, 10, "$" / `  N% |7 v6 y9 H0 n
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    0 J: T- g9 e: V' m6 k& J, D7 I
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" 5 [1 ^5 f* l: u8 k3 t# a( ?& A

  29. , H8 j  _! Y8 y% n2 _
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------, f# A# Y% N+ t6 J- C, r
  31. A20_DISABLE:
      K5 `  Y! T9 Z, V3 ?
  32.                 call    A20Write
    9 ~5 H" w$ M* Z% A9 H9 o
  33.                 jz      exit_disable
    ( Z9 z$ V; O- Q& [
  34. * F- F1 b# e6 p! `; G, x
  35.                 cli                             ; Only need for reading value from KBC
      ~. p; ?2 C2 O, V' u  L+ ^5 Y
  36.                 mov     al, 0D0h
    9 T) `$ Z- L, C7 \; }4 c4 x* S6 `
  37.                 out     64h, al
    8 e' }8 Y& j# g9 W: a. `  l- @
  38.                 call    A20Read
    : V- z% H9 N+ l% u
  39.                 jz      Disable_int
    7 O# A1 z, o- d( e7 R

  40. ) R+ D6 S' D' E! l/ n# L- H1 i
  41.                 in      al, 60h                 ; Get current status
    1 @9 t- O5 e" B8 [$ z: y8 B( f: A1 A
  42.                 mov     ah, al 8 r0 }  Y( w, [7 \
  43.                 call    A20Write
    + o7 ^; t8 n* a' x# W* {# h
  44. Disable_int:    sti
    ) T& s" p( e( u9 x
  45.                 jz      exit_disable' H4 F+ {; k0 B5 w( q
  46. 6 K5 E; V" ?& k# }" ?8 O6 Z
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 6 N/ o; N) a& e7 B+ K. b0 G, ^# m
  48.                 out     64h, al                 ; Out Put Port next
    : C1 `/ G, t, u! ?' ^0 x
  49.                 call    A20Write
    7 Z6 i  P+ x; D$ Z  F7 c
  50.                 jz      exit_disable
    " I  e, r- H0 L, R

  51. - c0 a9 N' m" y, |5 U$ ?6 D. B
  52.                 mov     al, ah
    5 V: y0 h$ U! D( S9 J
  53.                 and     al, not 2               ; Disable line A20 6 e7 Q- s7 z' D! \6 s
  54.                 out     60h, al
      T8 a2 k7 F3 F# n$ B4 V9 A
  55.                 call    A20Write , X. E5 D8 w0 E. M' t! T7 z
  56.                 jz      exit_disable
    " t# `: a. ?5 W0 V+ s
  57. # V* d; ~6 V! ~+ m  Z, w! `- O
  58.                 mov     al, 0FFh                ; NOP
    / @$ b& w/ u3 F1 V3 Y, y
  59.                 out     64h, al
    - h# [- I4 D9 o* ]2 e
  60.                 call    A20Write
    4 V" G/ i5 k: L, @+ l. f/ V5 T6 v* ?! J

  61. + F6 ?8 c0 g& n* w
  62. exit_disable:          ret / S3 ~1 D, t9 P
  63. 3 Z1 d5 s4 `! L' G+ d1 r9 V! _1 D# o
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - \9 w" h; G6 O9 y6 ^
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    . t( h1 m& m2 X  s# ]
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    5 g8 [  f8 T( ]  \8 n- g/ h
  67.                 jz      clear ( h+ k6 O. J( s' S
  68.                 dec     cx # J/ X, c/ X8 T. G5 @8 j9 {
  69.                 jz      exit_write
    , I' B, e$ b- Z7 [+ K3 [% k
  70.                 jmp     short get_wirte / v9 J0 {8 o, c2 N" C4 L
  71. clear:          inc     al                      ; Clear ZR
    9 K4 k+ v- {7 C8 B8 H
  72. exit_write:     ret
    - h) A8 `) d2 ^* K. J. K

  73. * ?9 D; j. D- R. u
  74. ( t6 T' I- y0 d: h1 l
  75. A20Read:        xor     cx, cx
    7 R1 D& v: c/ Q7 B3 X" o; S
  76. get_read:       in      al, 64h : C9 ~, B; U% t+ B
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 3 U. G, h& m+ B0 Q! F
  78.                 jnz     exit4                   ; ...
    2 ~. S+ ]& N9 l' R/ ]" ~' R
  79.                 dec     cx
    0 Y% ]4 G2 u* `. Q9 u1 e, w  n
  80.                 jnz     get_read! R+ s8 I! E0 |) R# _) U
  81. exit4:          ret     % o7 p5 Z  V* c2 K" P! n  x5 f
  82.                
    3 E5 Q4 ~' o5 }/ n  ~' u3 _
  83. end
复制代码
  1. ;A20STATE.ASM ! D# A  l5 w: U
  2. ; . M& C0 e" H/ @2 \+ b# k
  3. ; Returns the status of the line A20 through the KBC
    - e/ D# K& a, B' b. G
  4. ;       programming by bini for debug. 2008-07-01  P1 J' T& c: M
  5. ;
    / ^& }/ h5 P! U% h5 R
  6. .model tiny
    " R- K! a  E5 x0 T9 |6 E' a, p
  7. .code) k+ P' Y3 y4 k7 R8 V6 z" q
  8. .486* y$ s9 D% [6 P" C4 ?5 j; C
  9. .startup9 u- l, R' a7 F% p* l. Q( l2 `
  10.                 mov     dx, offset msg_fail
    ' N! f5 h! S: }1 Z7 l/ m6 p
  11.                 call    _GET_A20_STATE_! l$ z$ C8 R$ b! ^6 D
  12.                 jz      exit1                           ;  was a problem) \* L5 ~( c* ^* a
  13.                 push    ax                              ; Save state, AH
    2 Y  M: f) I3 N! F1 U0 K
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem 8 |, Z0 [% J4 B+ H0 A% N' H$ {
  15.                 mov     ah, 09h
    : D0 j4 @+ y5 n9 k0 Z. e4 A, @
  16.                 int     21h                             ; Print message
    3 M1 d, R. X: l& T
  17.                 pop     ax                              ; retreve state - z: A! e% O6 S6 ?2 C' ]+ P3 i

  18. 7 b% ]) C1 L4 T" C+ R
  19.                 mov     dx, offset msg_dis % h8 ?8 B& Q: Z) U  f
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state . _( p. ?0 p, y! M0 W
  21.                 jz      exit1
    # c5 Q6 [! R, ]
  22.                 mov     dx, offset msg_en
    6 [# Y. A+ @$ T8 f/ Q

  23. ; ]. |* ^. p- a+ }( f3 y
  24. exit1:          mov     ah, 09h
    * M1 P/ k. A5 Z5 s. \( w
  25.                 ; DX already contains address of string # ~: E. |, b" ?% B4 P( i$ u
  26.                 int     21h
    : \5 k; V, @3 s, W5 V: I$ W* k4 w* x
  27. 8 J" i3 c4 |$ |# ]
  28.                 mov     ax, 4C00h
    0 V. a, z! n3 t( H
  29.                 int     21h
    , n: `8 V* F7 y7 V& g
  30.   Y* C$ Q* n* ]# f, I5 s. D+ p
  31. msg_ok         db      "OK", 13, 10, "A20 $" ! E( v; C/ g9 r# h/ X
  32. msg_fail       db      "FAIL", 13, 10, "$"
    4 \5 B" V; I( u, H
  33. msg_en         db      "ENABLED", 13, 10, "$" # q$ {) t. g8 H. @  V, f: [+ \
  34. msg_dis        db      "DISABLED", 13, 10, "$"9 d3 ^) f7 u7 M& X; k# y( k

  35. : U9 [9 X9 g4 b% A) c# n0 c; C% X

  36. % k+ y8 r% U5 {* u  D4 w) B
  37. _GET_A20_STATE_:
    0 O$ P2 j5 J- ?% n
  38.                 call    A20Write                ; Wait till the input register is empty 7 n0 l" y/ C5 }6 q7 B
  39.                 jz      exit2+1                 ; Bypas the reset int's 1 O, R0 `8 a2 s+ `
  40.                 cli                             ; Disable ints so we'll get our value ) `" P# }) S" b0 f& Q! q2 v& r
  41. " D$ P0 I* Z9 y2 `* h
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    / t( V% J& Q. v8 \4 B
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    5 m. T- w8 k1 u9 W, g+ f) ]
  44.                 call    A20Read                 ; Wait till the 8042 output register $ h1 h: B$ U, ?8 S- H! G* J
  45.                 jz      exit2                   ; has something in it's buffer ) M& ?! c+ x  s, S: D

  46. 5 o# }9 J+ u: p
  47.                 in      al, 60h                 ; Get it
    5 N  e: r0 R  W* L
  48.                 mov     ah, al
    / A' ]# i/ s4 y! x
  49.                 call    A20Write                ; Make sure the input register is empty
    * J* H3 M+ J$ `) P6 k4 h
  50.                 jz      exit2
    6 a2 @, ?* S+ ^8 c7 y: G# d  f

  51. 6 a2 i. R1 u- H/ H! ]- a
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing - |. p- c8 e- \' F
  53.                 out     64h, al   `2 X3 K( B# ~
  54.                 call    A20Write
    9 E! C# l# f& R" z

  55. $ y, Q3 i% F. d1 M+ ^, o& d8 y
  56. exit2:          sti
    % H; @/ W" |# C- b( W
  57.                 ret0 n, k6 t, z% E$ X, ^
  58. 4 x7 q& Q) _" b
  59. ) M  Y" e/ m3 h/ k
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 2 K3 Z5 A/ j2 D. h, f  [. M" j
  61. get1:           in      al, 64h                 ; Get KBC read status . H. P! N: X9 l* I7 J
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    4 q" {1 O& @. k+ V9 G
  63.                 jz      clear
    1 T: b( B/ R- G! T( l9 Q5 q
  64.                 dec     cx ; N; a1 J' T9 k; I4 u  ^( ]
  65.                 jz      exit3
    $ W2 P; [$ u) R9 A' M. p0 o% R6 a
  66.                 jmp     SHORT get1 1 g6 _: b1 q0 {5 c8 d2 w) v% \, e
  67. clear:          inc     al                      ; Clear ZR
    + B# f6 s* X$ ?! O$ a# E
  68. exit3:          ret
    2 v4 Q" k7 T8 N. X& K/ u. _

  69. ( @% G$ Q) G. {# g

  70. # G/ b" ~$ l% T. ]' h6 p
  71. A20Read:        xor     cx, cx
    7 O& ~4 D' T7 H* d& A
  72. get2:           in      al, 64h ( }0 |' S7 E. V, }+ s3 P* ~
  73.                 test    al, 01                  ; If the 'output buffer' is full, has & c9 m, T4 a: k+ D& ?# m
  74.                 jnz     exit4                   ; something for me
    4 u; z6 M2 V4 X
  75.                 dec     cx 8 y7 x' w* }4 B/ X/ @5 _2 c# Z1 L( ~
  76.                 jnz     get29 `3 `1 w% Y. @  R9 a2 M
  77. exit4:          ret     
    + q6 c  O' `0 a6 \: n8 O
  78.                   ~9 w+ T2 R% G9 e
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
# k. u. k' V8 t. X5 G0 e2 K{        while(inp(0x64) & 2);        outp(0x64,0xd1);* a  ?, M3 r3 r% w2 Y
        while(inp(0x64) & 2);        outp(0x60,0xdf);
4 Y# h; T! W2 R) k        while(inp(0x64) & 2);        outp(0x64,0xff);
! G4 U+ F* i) m! H4 z  w: ]}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-1 05:34 , Processed in 0.134755 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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