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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    : }$ z: E- c- _6 R8 q) ^
  2. ;
    + D( b& m: m) Z* l+ d
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01  [$ K, t& o9 w( W+ r# e
  4. ;       ml A20ON.asm
    ; X# n' w, ~3 T, i
  5. ; % w6 ^. F9 P2 Z- s0 ~
  6. .model tiny
    0 R2 [5 y" D! t! w" }. y
  7. .code
    * l5 q2 L- G1 \7 `0 K# i
  8. .486
    : u6 L9 E, S& K: F' K3 T  J
  9. .startup
    - ^( x, i' P' @' P! e
  10. 8 U! f0 H& {$ Y4 A9 n, ~! Q. I, X
  11.                 mov     dx, offset msg_author+ @/ R/ _4 u5 k7 e4 F- _2 a
  12.                 mov     ah, 09h+ [' y9 l- V+ q( ^( u
  13.                 int     21h& v9 Z6 b  j7 D( ~2 e

  14. 8 \! Y* @( `3 m  Z$ w
  15.                 mov     dx, offset msg_fail ! ^, X+ N7 `$ f# F* u
  16.                 call    A20_ENABLE' M' y- X' l2 N2 U6 M7 j$ Y3 Z
  17.                 jz      exit1- l+ ]  R- j& [$ j( l
  18.                 mov     dx, offset msg_ok
    7 f' E4 G& X$ n% ]0 X

  19. : ~4 i) c* {& h; J$ |# H5 y
  20. exit1:          mov     ah, 09h
    9 x" Y1 j, Q! S6 \8 f* _
  21.                 int     21h + }+ e' ?' p( N+ _' J
  22.                 mov     ax, 4C00h & V, e( N9 O+ Y* B9 k2 j) }5 M$ V
  23.                 int     21h
    ' @5 e( J( ?# D9 ?9 z$ t0 O
  24.                
    4 e+ I; t1 H# w
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,( p! c& l% p/ W% d
  26.                         "2008-07-01",13, 10, "$"
    2 r! \& {4 |1 a$ _  p) \8 ~
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    + ], }3 N2 U% O3 I" |
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    1 V4 W* g% \; Q5 @( x( F: Q+ \! E

  29. ) O. p' Y1 B: R7 k$ r9 W. s
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    8 v2 Y: V4 |# B# |$ b" ~
  31. A20_ENABLE: 2 f4 G: j. B+ q' x- P, k+ I
  32.                 call    A20Write 2 @# g0 U0 |! n' F+ Y% E2 M
  33.                 jz      exit_enable
    8 c% J7 ]: Y  e6 Z6 O9 _

  34. , Z9 Z. z& a; F5 L7 C
  35.                 cli                             ; Only need for reading value from KBC
    , v8 @" n- h  n; ?- Y7 d
  36.                 mov     al, 0D0h ' J0 g6 P8 |* `/ @
  37.                 out     64h, al
    / b# Z0 B) t" d1 o) J/ ^
  38.                 call    A20Read 2 W8 I8 q9 ?/ @. V
  39.                 jz      enable_int   P# h& W9 h% L0 v6 \

  40. - s2 m# j5 T! M& h
  41.                 in      al, 60h                 ; Get current status 2 t  o& i- k) Z
  42.                 mov     ah, al 8 o+ ^6 g, h3 `1 e
  43.                 call    A20Write # ]1 c  C' p" s- P3 W: D- ~: N3 `
  44. enable_int:    sti
    8 `$ ]3 e1 z+ [; e
  45.                 jz      exit_enable8 p, k, T+ s% d

  46. $ V, n7 t3 }( g- L0 d, O
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 1 \5 ?5 ~' U% `/ Q- U8 ]" H5 \
  48.                 out     64h, al                 ; Out Put Port next ' D: p3 V1 ^4 i7 o: m7 F* V
  49.                 call    A20Write
    $ i9 `2 w& ]- I9 c* _0 s+ {, G
  50.                 jz      exit_enable* k5 }" w5 y& p; q# |

  51.   d# m' f# t/ r8 g, [: `! x: e# h- U
  52.                 mov     al, ah
    + v) Z! `0 u5 d# o
  53.                 or      al, 2                   ; Enable line A20 8 K8 T+ A6 h1 B1 G: e+ i, k- d8 f0 K
  54.                 out     60h, al ( }5 x. W) L3 a* ^  V0 m
  55.                 call    A20Write
    ) A# t- j; M9 r
  56.                 jz      exit_enable
    0 _3 d  v) O/ F: y% u; W5 W

  57. 9 h% b( u. f  c) k- h6 r9 i5 d
  58.                 mov     al, 0FFh                ; NOP
    6 p2 q3 Q7 y5 _  T, Y; H4 {' b
  59.                 out     64h, al
    / L/ r  ?1 D3 A6 g9 z0 _1 W
  60.                 call    A20Write 5 j3 ]* K* y7 G/ l! @4 o

  61. 3 X$ e3 n4 W- \- w% |
  62. exit_enable:          ret 2 N; o* E! W' T8 }0 S4 U' m+ T% _

  63. 1 e& \& ~$ C+ @) i0 e
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    3 }" f' p, P' |2 C: q. J" X
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ; J1 ~4 j7 ?3 S; h
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear , |& D5 A, J* I( [! L3 ?
  67.                 jz      clear ( Z0 D2 I0 Z& w
  68.                 dec     cx 9 ?& v6 L- y/ x6 _( ~
  69.                 jz      exit_write 1 r/ u1 r2 K% |+ y1 F- [
  70.                 jmp     short get_wirte
    / x5 [& v$ Q$ J( n" W) H# t
  71. clear:          inc     al                      ; Clear ZR
    * {% T: l3 h$ e1 m: I: ^8 F  h
  72. exit_write:     ret
    ; V% M. a6 y  F, T  M4 T

  73. 9 v" N/ ^" j8 l; T4 _# D
  74. . g+ e! h& T& M0 F$ n! H  t
  75. A20Read:        xor     cx, cx
    9 W8 J1 O+ F2 \" b
  76. get_read:       in      al, 64h 9 m& B1 g$ ]" [! b2 O$ `
  77.                 test    al, 01                  ; If the 'output buffer' is full, has . {1 M$ ~- g, M' d) Y5 E2 e
  78.                 jnz     exit4                   ; ... ; y) L; `5 Q1 H3 y
  79.                 dec     cx ' D7 M7 S& M% F$ O5 ^
  80.                 jnz     get_read+ O% _( U, |. O& L$ M2 |+ N
  81. exit4:          ret     ! B# n: S6 w9 l$ F0 o
  82.                
    4 k. {  W/ `! t' f  k: c
  83. end
复制代码
  1. ;A200FF.ASM
    & ?! n. E& F' `2 b* p4 a( i$ X
  2. ; ( c* e, x7 o; r0 H: V7 M/ g
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    & e  j5 _# t/ P' Y# E  m
  4. ;       ml A20ON.asm
    / S3 N3 E+ W' |" s, Q1 E
  5. ; 4 d7 |$ w# |* N6 R8 Y
  6. .model tiny
    2 l9 }5 a7 _9 g; `2 ~" `
  7. .code
    " B+ y3 p  x* O$ ^  G; u, L0 i
  8. .486
    % U* \: Y7 s. C, d& M
  9. .startup6 W- v* r" E( ?. M: W" U" Q

  10. $ ?5 W7 v3 ~5 U! B
  11.                 mov     dx, offset msg_author
    ( L2 W. m& p9 e4 E) X' i" `0 M
  12.                 mov     ah, 09h3 t" L! F1 [7 H# |+ J, h+ j! @6 ?
  13.                 int     21h% |$ C/ x: H. b- |7 t9 I
  14. 4 }5 h% y! S3 b9 B# o" C
  15.                 mov     dx, offset msg_fail
    4 z# {/ B, s- Q6 M+ X" f4 w
  16.                 call    A20_DISABLE
    ) n+ S3 W) L1 F, |! i0 ^
  17.                 jz      exit1
    * r8 f9 `6 |* c  B1 H( r& p8 j
  18.                 mov     dx, offset msg_ok % P8 T: E* X7 s- f7 w2 T$ G

  19. $ I5 ~2 Q. }: J
  20. exit1:          mov     ah, 09h / L* A; `+ e# s2 q. e1 ]- W
  21.                 int     21h : u- b1 ^8 X- |. J# e
  22.                 mov     ax, 4C00h
    6 D; x! X) G  H  X
  23.                 int     21h 3 U. p" ^/ V' Y
  24.                
    ) {* f! [1 B% x0 D) O6 o
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,; S6 T+ P! J9 Y8 J- V
  26.                         "2008-07-01",13, 10, "$" * o1 q. L% {6 L. Q3 G0 d
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"   W% g, g$ g% H9 I/ q
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    4 d3 A' F1 S" ]
  29. ! d5 c1 Y; M# W( L4 }( K" T2 Z
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    3 O+ d& N. H+ k$ r4 I% `, k
  31. A20_DISABLE: 3 L1 ?8 J, h) p5 q) E0 A' y' N- z: ?
  32.                 call    A20Write 4 N  ?/ W, @  `% }  U
  33.                 jz      exit_disable8 c8 N% W. b6 n/ u. J7 b( _  G
  34. 1 \5 R8 C, p. L7 W- k! L* y
  35.                 cli                             ; Only need for reading value from KBC 7 j9 Y& f8 ]5 ~9 F) V9 p" I4 Z
  36.                 mov     al, 0D0h
    $ r; K9 N9 T& C8 i2 b2 G9 S, J% J
  37.                 out     64h, al 7 p9 O. p9 d" y. Y
  38.                 call    A20Read
    2 s  g! ?& a% c& J$ X% W+ O
  39.                 jz      Disable_int   s) H  L5 W. F; S; V" y

  40. , C! L& s9 |" ?8 A2 r& c
  41.                 in      al, 60h                 ; Get current status
    8 d5 F3 ~1 O& F
  42.                 mov     ah, al
    5 H. H" Q! r! H5 i& S5 W. c9 ?
  43.                 call    A20Write
    0 A/ p& ^- d# e% h
  44. Disable_int:    sti ) m+ {: `/ X0 E& x+ R
  45.                 jz      exit_disable6 A' X" [% M! [1 R2 Z3 S3 A% Z

  46. 8 c. A8 G2 }1 I9 e
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    ( E6 @4 D* Y2 V4 t: [
  48.                 out     64h, al                 ; Out Put Port next
    3 h- Q! h3 o8 {  [& k6 y
  49.                 call    A20Write ' [+ Z. E% b( U# g
  50.                 jz      exit_disable( D* _& X' K4 |8 F" k" X

  51. 2 o  [' y. Q. t) S/ s( O0 c9 p
  52.                 mov     al, ah % X1 @" M: Z8 O. y8 ^* z
  53.                 and     al, not 2               ; Disable line A20 7 J' B! ]( P  s; [9 @- y
  54.                 out     60h, al - H9 g; l. q( k1 c, q; D2 L) d& G
  55.                 call    A20Write 1 B* {3 l  F4 F5 y
  56.                 jz      exit_disable
    . q6 q+ Q/ v8 i$ w9 n

  57. 5 k: p. E% X, R% \8 n9 E
  58.                 mov     al, 0FFh                ; NOP
    4 a) \2 c; D6 m0 |) @8 C
  59.                 out     64h, al
    , P/ _, z. L% C8 g+ R2 S2 m* w0 r
  60.                 call    A20Write 1 x( ]$ n  n$ W3 a% m

  61. . x/ [/ N  T7 T, H3 Y  L
  62. exit_disable:          ret
    ; h- K. h7 l) \& w: f

  63. / @  Y- \1 B; q& {" {
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    / c% v, w$ c6 Y: G9 ~
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ( P& ~! X; h. J( I  M) `% s
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 4 ?# b; K, L3 r7 I0 O' T) Q7 G- U' g
  67.                 jz      clear & B, u( I% O8 |/ W( w; S
  68.                 dec     cx
    * U0 B: a& c2 s2 A2 i5 u6 w& z
  69.                 jz      exit_write
    ) A: T% f2 @6 \( R9 ~
  70.                 jmp     short get_wirte 8 s: ]! d$ Q: `8 J
  71. clear:          inc     al                      ; Clear ZR
    3 B- H- u0 _4 o2 H8 F, p8 }
  72. exit_write:     ret   P; [& T+ t5 k5 h* Y
  73. 5 W8 s, _, J' G, Z  h3 ?% ~
  74. 8 m3 U* v7 o3 J: \
  75. A20Read:        xor     cx, cx
    7 x: `4 ]$ _- `% o$ ^% F% X' Y& H
  76. get_read:       in      al, 64h
    - K. i, X" S: B! N. T9 T
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    , g; b. Y8 a) ~8 L$ s
  78.                 jnz     exit4                   ; ... ! ~+ F) v7 B% J
  79.                 dec     cx , B0 \. e2 I8 f  j! G; k( Y- j; Y' G
  80.                 jnz     get_read; V' H1 I, T* C4 v
  81. exit4:          ret     
    8 h* W; G9 m, L# r# I& w
  82.                
    9 a( D/ N* F  U& U% W7 b/ F
  83. end
复制代码
  1. ;A20STATE.ASM
    ; T- w: W" j2 L* r
  2. ;
    / k. c  @, K' ]" m
  3. ; Returns the status of the line A20 through the KBC
    * f" j$ `5 l9 O
  4. ;       programming by bini for debug. 2008-07-01/ x$ X$ {/ H5 N2 G% |8 I3 [# x' @1 y% y
  5. ; ) v" _8 E# `. |/ _0 e* h
  6. .model tiny' ?: g7 n3 H( v# n! K* l2 N) n8 d6 q9 y$ R
  7. .code
    7 r: H2 U% c2 o
  8. .486
    : f0 P3 l5 s+ K, o+ O
  9. .startup
    8 A( H# r7 _5 p1 q+ E/ j
  10.                 mov     dx, offset msg_fail
    8 b/ y3 C# N$ ^3 p) W
  11.                 call    _GET_A20_STATE_( p# K8 G0 r( g$ _7 ^. y
  12.                 jz      exit1                           ;  was a problem
    2 l3 C' x: l! k1 W0 B$ F3 o6 l
  13.                 push    ax                              ; Save state, AH ! G" K+ }% E6 J" A* s7 l! V
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    $ n% r& m- u' S/ i$ [
  15.                 mov     ah, 09h 2 K& r/ Z9 t" K: x
  16.                 int     21h                             ; Print message ! t/ G1 ^+ a  o
  17.                 pop     ax                              ; retreve state 4 D  g" s5 e9 o2 Z8 d

  18. 8 s9 p' R# \8 U! f- L. _" P7 x' T# d
  19.                 mov     dx, offset msg_dis $ T- S6 Y8 v2 l& n4 T$ P8 Z. M9 O
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    6 n) L9 O. b% A" M7 n
  21.                 jz      exit1 2 r; b9 `# A: _4 p! X  a
  22.                 mov     dx, offset msg_en
    ' c1 ]) U: H7 G* R: E$ n% B

  23. 1 d1 j! j6 _5 C' K
  24. exit1:          mov     ah, 09h
    : e! C9 [+ j7 a5 H
  25.                 ; DX already contains address of string
    6 w# k) A* W; c5 g2 O
  26.                 int     21h
    ' S: `; l  U% g2 \0 \. l

  27. 3 L- K3 `5 {1 O
  28.                 mov     ax, 4C00h 2 n  h$ ^8 V* B* e
  29.                 int     21h
    9 d3 H& @, s( e+ X
  30. & `+ H' H0 h$ O( h6 |" V
  31. msg_ok         db      "OK", 13, 10, "A20 $" 3 T( v) v1 `* n
  32. msg_fail       db      "FAIL", 13, 10, "$" 5 u0 p& C+ r; Y! A5 ?- t
  33. msg_en         db      "ENABLED", 13, 10, "$"
    # b3 m4 S% i. g  l, [9 g2 ~
  34. msg_dis        db      "DISABLED", 13, 10, "$"9 i9 n2 f4 R# d  R

  35. # x/ I7 g, {% k- _3 B

  36. 5 q. \; W% _" Y1 S
  37. _GET_A20_STATE_: * H6 _7 D/ V0 L: s) A" a' ~% J
  38.                 call    A20Write                ; Wait till the input register is empty : v0 a8 m6 m% {1 [' W% D
  39.                 jz      exit2+1                 ; Bypas the reset int's
    # |8 ~& _, X9 S# `  h
  40.                 cli                             ; Disable ints so we'll get our value
    2 H$ H9 B8 ]' S* B
  41. * z! w% h" M; q6 y" n8 c2 X
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 1 ^7 x8 G7 Y: `+ S5 e
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
      H! Q4 W/ x3 m0 E- u3 c2 R
  44.                 call    A20Read                 ; Wait till the 8042 output register
    / n& T0 _$ I& \5 w; m6 ]+ a0 S
  45.                 jz      exit2                   ; has something in it's buffer
    % y  P+ N6 K* N1 p5 n

  46.   t- U% V4 V3 i! K2 @4 H
  47.                 in      al, 60h                 ; Get it ( ?( f" ]4 [- s* C$ Y* w6 c$ T9 f
  48.                 mov     ah, al
    . D( X8 {, \) J( E" `% w1 O5 f
  49.                 call    A20Write                ; Make sure the input register is empty ' F0 X* W8 y, ?* S2 |9 k" Z
  50.                 jz      exit2
    ! O& A- C. ^" n9 [6 o, ?
  51. : J8 _. o8 |' X& V7 M; \. V/ ^
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    + z# w7 p4 _7 V3 n6 _
  53.                 out     64h, al ; z- [+ }) k2 f9 u! ^
  54.                 call    A20Write
    + h# K2 E/ a1 U9 Q6 s5 r& W/ w* z- @

  55. - d2 E" j2 U7 R' M
  56. exit2:          sti & B# {, ^, P7 H* B9 |8 @) }7 m* l
  57.                 ret
    " _! J4 ]3 ], i  _. j0 v

  58. % [9 M3 h- A0 I2 O, y
  59. 8 S5 N( A. E6 A! e4 p6 H
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    & y% O  q* r' O# U3 Q7 h; F
  61. get1:           in      al, 64h                 ; Get KBC read status
    9 K. O; ?5 V) V( T1 h  |7 ?9 z1 p
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : s5 C% K6 P  R9 Y
  63.                 jz      clear
    + B8 y. F3 q1 L7 l6 O5 h3 c
  64.                 dec     cx $ c) w! `* t$ @* s2 I0 s( Q. v1 s& l
  65.                 jz      exit3
    4 i- T* F6 k4 T  B) a% ?! I
  66.                 jmp     SHORT get1 4 z) _  E$ D# d9 G7 g7 S$ q
  67. clear:          inc     al                      ; Clear ZR $ n1 J, R7 r. ^) j* M# _: i( [
  68. exit3:          ret
    3 J+ }4 T) Y1 y
  69. 1 t$ n% l, f, ]+ U( b
  70. 0 O# r4 w* S& s6 n" g9 l# a: w
  71. A20Read:        xor     cx, cx   `0 y- D  T. g7 [) _4 i. _
  72. get2:           in      al, 64h ! |8 y+ [; ~7 ]( ~
  73.                 test    al, 01                  ; If the 'output buffer' is full, has : O$ L4 X4 A7 A+ V
  74.                 jnz     exit4                   ; something for me
    " L0 L0 K' D3 x" ]. d$ v
  75.                 dec     cx
    9 @* S2 j& q$ T" m! A; X3 h" m0 J
  76.                 jnz     get2
    % n( u$ L0 o( c5 A3 `
  77. exit4:          ret     
    + p. ~  e9 e" f
  78.                
    % W+ V2 |8 n" |3 f! _+ {
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()( E4 t6 o. @5 Z- g: R8 j& n
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
9 E9 g% [. y+ B8 p1 E' J) y6 k9 {        while(inp(0x64) & 2);        outp(0x60,0xdf);! v! N, u% b1 z1 @
        while(inp(0x64) & 2);        outp(0x64,0xff);
4 |0 _& w# x: E/ ~+ x4 [. M}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-25 03:37 , Processed in 0.041644 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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