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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    & X9 b2 Y* }) J" e' k3 D! w! a
  2. ;
    3 [& }: [5 ~  t. O- C" x
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    , G4 w: E0 Q5 ]; U, q4 Z  {
  4. ;       ml A20ON.asm " L; R6 m' i: M: O5 y# A0 s* Q+ D! k
  5. ; / m, O+ m$ N0 h' j; i9 A
  6. .model tiny
    ; Q' f5 u- _) i. _
  7. .code( N1 V/ ^: U% c9 W, L
  8. .486! y. ]2 R4 @4 X0 K/ r9 K& F# n
  9. .startup1 Q: _. z& I. P

  10. ' b' P" Q! m- O5 N; u# A
  11.                 mov     dx, offset msg_author
    1 A! G6 C) q, x
  12.                 mov     ah, 09h
    4 u3 f5 b! l/ T" l) G6 B! ~
  13.                 int     21h5 C8 l* r- D" I% |5 ~2 n

  14. 5 o* O! U+ I5 |
  15.                 mov     dx, offset msg_fail
    4 U, h8 y  T5 L3 c, W3 |
  16.                 call    A20_ENABLE
    * e6 l# n: A# l
  17.                 jz      exit11 e/ C6 d, ]2 c1 L
  18.                 mov     dx, offset msg_ok ! i, Z$ `2 _) W+ Z
  19.   j! [5 ?3 F4 J# H; p/ f
  20. exit1:          mov     ah, 09h 6 V! `/ c5 e4 g' m, z
  21.                 int     21h . K8 x" A; N6 c" [0 K9 }
  22.                 mov     ax, 4C00h
    9 p, m2 b' ^( `0 t' D
  23.                 int     21h
    7 [$ Z3 W, A& c5 }
  24.                
    4 m4 D( r6 c  K( R0 {& [  Z  Q
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    " D# Q6 K. {7 g( F% @: p4 v# s* U
  26.                         "2008-07-01",13, 10, "$"
    " ]7 D/ g  U/ h. u& W3 ~
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 9 ~' i4 ]4 k$ v5 k" k
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    8 P! Z9 R8 s/ t0 Y

  29. & D1 Q1 u5 E0 }- z7 F
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    $ E  I% X# R! W6 k
  31. A20_ENABLE:
    ) p% W" N6 W$ k. j/ I/ {3 V6 u
  32.                 call    A20Write + ~! f; f9 [, _
  33.                 jz      exit_enable3 ?) `8 F3 g) I. n, t% r
  34. : U' n0 O& N% X$ C2 Q1 y! Y, Z! P
  35.                 cli                             ; Only need for reading value from KBC : z- @% x1 _) @/ u6 D$ G4 s/ q! l6 e
  36.                 mov     al, 0D0h
    & i! h/ k- X0 Y# I+ W* m* a) D. T- A
  37.                 out     64h, al 8 u* E1 ?. w/ ?8 f  Y3 Y
  38.                 call    A20Read
    5 X4 u6 Y. D% h. A
  39.                 jz      enable_int
    5 m; D9 b  E9 j" j5 x. M% p

  40. * q+ z  i& o# f' b) ]6 ~( \/ J% \
  41.                 in      al, 60h                 ; Get current status
    : S7 X& C; S9 l% u7 e
  42.                 mov     ah, al & X) d$ x3 S8 u; z' W9 C
  43.                 call    A20Write
    8 S$ @4 h& o* r6 y+ z8 M
  44. enable_int:    sti 1 ~  P2 \6 o. M  b/ v) K! C  ]4 E
  45.                 jz      exit_enable2 R" z' g1 @2 J: T/ i/ {" V% U3 u
  46. 8 e1 P6 y6 m2 O1 y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the $ ~+ |: d4 B2 @6 d- D1 s( F
  48.                 out     64h, al                 ; Out Put Port next
    ) ?) ~+ v( z* a" l2 D
  49.                 call    A20Write ( {1 y8 o7 t3 {4 Y. F
  50.                 jz      exit_enable
    : J" f4 ~  U" y
  51. : W2 I$ c( n6 a' X' }! n
  52.                 mov     al, ah
    6 k8 J! ?4 ]/ Z
  53.                 or      al, 2                   ; Enable line A20
    8 ?0 }3 c( ?  A# q3 n4 Z
  54.                 out     60h, al
    & Q) y8 |8 S" G
  55.                 call    A20Write 1 D7 a% Z2 x5 X3 l! d+ f
  56.                 jz      exit_enable
    : s+ e$ z+ n6 G0 p' S0 ?0 p1 p! R
  57. 0 e; X) r9 R+ ]; Z4 k. Z, H
  58.                 mov     al, 0FFh                ; NOP
    6 h: W- I* ^$ u
  59.                 out     64h, al " d" I" X- s  N) e0 [/ l
  60.                 call    A20Write $ @/ U0 O" E4 e: D- c1 Y& z% ^
  61. 0 m! D$ s6 v  r
  62. exit_enable:          ret * y& c3 k: e/ ~$ D$ c
  63. ! ?% i) R% q) j' Y! a: ?
  64. A20Write:       xor     cx, cx                  ; Reasonable wait + h6 R1 }1 L- W2 l' X% x. t
  65. get_wirte:      in      al, 64h                 ; Get KBC read status " m3 s9 F4 d4 q/ l/ |0 W
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : u( y+ G% @. b& b; i
  67.                 jz      clear
    6 b3 z1 M0 w4 m) S& E* J
  68.                 dec     cx
    9 I( [8 ~6 r/ ~1 l7 R: l
  69.                 jz      exit_write ! j* N( ^. h# u5 b% o
  70.                 jmp     short get_wirte , {& [. {/ B( I* K2 p/ d" ^
  71. clear:          inc     al                      ; Clear ZR , B7 A& {9 X5 q5 Q( O$ j" r, n9 \
  72. exit_write:     ret
    * U  J. t( H8 {4 {
  73. % ~; P' K1 W1 f& J

  74. ; |; Z, j" J/ h$ Q/ j
  75. A20Read:        xor     cx, cx 1 w2 [) O- U4 c, [" s* d8 X  o
  76. get_read:       in      al, 64h
    : J" U4 b; a3 V# Q+ o1 g& ]
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    + P) T% p+ G8 t$ I  O
  78.                 jnz     exit4                   ; ... $ v" Q7 c# F7 F) ~# b( e3 W; g
  79.                 dec     cx 8 f: i  y- [- z' [* H
  80.                 jnz     get_read
    3 c3 O5 |1 P( q2 m5 p2 t
  81. exit4:          ret     * g* g- ]/ |+ m) i* |, {
  82.                
    % @, i3 Y2 m6 `
  83. end
复制代码
  1. ;A200FF.ASM
    , O& _1 e) f- W
  2. ; ( Q, w+ I8 Q+ f
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
      t, G9 d% ^& j  Q# K& A
  4. ;       ml A20ON.asm
    6 x2 S+ d* L3 _
  5. ; # @0 W; z; n# o/ L9 f
  6. .model tiny6 M0 K9 r2 z; c5 G% q) m) S
  7. .code, B) s; w& e& [
  8. .486# H) Y. p% X$ k
  9. .startup
    " p3 q( u8 q  S: s+ X. g
  10. 3 V/ f" q8 ~  O
  11.                 mov     dx, offset msg_author6 ?4 W+ B/ ~6 S, `9 ]9 R
  12.                 mov     ah, 09h
    - p& a. [9 M) s
  13.                 int     21h5 N* _: \& j) k8 v

  14. 7 r/ X& n7 F+ v9 N
  15.                 mov     dx, offset msg_fail
    3 o1 e2 b1 I" Z. U
  16.                 call    A20_DISABLE
    ! ]- ?) M4 G8 A
  17.                 jz      exit10 q- z! \; I8 x1 |/ T
  18.                 mov     dx, offset msg_ok
    2 B, u/ X. |# p' v. p
  19. ! a; M; D( ^! _" m
  20. exit1:          mov     ah, 09h
    5 @$ ?- m1 T# W1 F- F
  21.                 int     21h & Z' M7 J2 W* j6 x
  22.                 mov     ax, 4C00h
    , C  w" z) a( N1 p
  23.                 int     21h 1 U5 m8 X0 N3 U% [! p6 q( ~
  24.                
    9 j% T. |. P2 O
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,! R& c% o' A' V; v- w
  26.                         "2008-07-01",13, 10, "$"
    3 M- E# r7 L6 d2 }
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" ( g- A; \% d+ |. i" y: c+ g# h
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" 0 A% T; c" e' @3 l$ b, y8 G6 G9 N2 B
  29. ( j& }+ V- J# Z" F' u5 Y6 _
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------+ ~# L0 t5 R) `% f/ f
  31. A20_DISABLE:
    + \2 j: W8 v) u/ ~  f# O0 {8 m) \# L
  32.                 call    A20Write 2 u" O' x0 w, Y$ [0 `2 H3 p
  33.                 jz      exit_disable( V5 i. ]" c9 \1 N# E- I7 f  }
  34.   `% t$ b1 w0 }( ~6 M* N5 U8 {- P
  35.                 cli                             ; Only need for reading value from KBC 7 I8 l1 _5 `0 B5 l9 z7 T
  36.                 mov     al, 0D0h & k- b5 _% P4 ~. z7 i
  37.                 out     64h, al 6 T% ]: H  B/ f9 t% F% Z9 ?
  38.                 call    A20Read   f) L2 k, e0 J5 r5 E% q" ?
  39.                 jz      Disable_int
    " j$ b7 {1 l( Z+ Z$ w

  40. - F' a2 s0 n" V2 W3 W
  41.                 in      al, 60h                 ; Get current status
    / r3 ~: h" L9 J  ?/ i4 u
  42.                 mov     ah, al % B" O% [3 a2 I& d; h
  43.                 call    A20Write
    1 q+ A2 Z. I6 N5 v3 U
  44. Disable_int:    sti
    $ L, R$ I3 A, R  H$ d% n
  45.                 jz      exit_disable
    3 ~' ]4 Y: Y9 U% E( w6 i
  46. 8 J* j+ R8 z& X9 D
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    0 ^  w* v8 r, h) y
  48.                 out     64h, al                 ; Out Put Port next . c. \: v% C& [$ X! U: B* K
  49.                 call    A20Write 1 a: S( |( X0 h/ u
  50.                 jz      exit_disable
    , c! ^- T2 W/ c1 ~- s% p# f

  51. 5 ?0 ?; N' T7 o5 e( [
  52.                 mov     al, ah
    1 _/ g9 x# \7 u& e2 I
  53.                 and     al, not 2               ; Disable line A20
    % P: `. T- Y' D; @1 l: m
  54.                 out     60h, al % g4 z- h0 I  p; Q
  55.                 call    A20Write
    0 F* r! B+ J0 P3 O- x; J5 U
  56.                 jz      exit_disable
    % S# W- r$ n" C4 H0 v

  57. " h+ I) _, j, c' C, U
  58.                 mov     al, 0FFh                ; NOP
    ) A: W( y3 x! e% O) d# |
  59.                 out     64h, al ( M; O* S# b) |2 K
  60.                 call    A20Write 6 Q+ t: g+ f) O
  61. 7 C9 T0 {5 P' o. [" d+ P# d8 N# p
  62. exit_disable:          ret 5 \) S( c- K6 S. D8 y2 F
  63. + x& o) M3 x% g% Z* g
  64. A20Write:       xor     cx, cx                  ; Reasonable wait + E3 j8 C6 O1 k) S" E
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 7 s: U+ ^9 _* S
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ) R6 Q2 Q* v/ `4 W: E$ x* M
  67.                 jz      clear 8 f/ l+ Q+ V: ^$ J" V
  68.                 dec     cx   f5 y% q. J- A% I
  69.                 jz      exit_write ' a1 k. D& O) `) h: f: S
  70.                 jmp     short get_wirte ! N& @5 S1 Z# k* X
  71. clear:          inc     al                      ; Clear ZR
    7 E2 I) [5 R3 s* z4 Z4 j
  72. exit_write:     ret
    9 O) J7 J/ ^3 N

  73. + |. i$ z& T# f3 Z# d8 G' X) [
  74. ; p$ A2 F( D! ~
  75. A20Read:        xor     cx, cx
    % S- j+ T9 k$ I! \+ S, r
  76. get_read:       in      al, 64h % B/ v: o, M6 x" M# \1 r
  77.                 test    al, 01                  ; If the 'output buffer' is full, has . z& b4 V$ i3 y2 z0 w" x& Q
  78.                 jnz     exit4                   ; ...
    , s. U& B* ~( J3 O
  79.                 dec     cx
    : P0 T9 A( _, \) L0 {/ E: Z
  80.                 jnz     get_read6 X" d  |7 U% p4 {. `0 _+ `: D$ N
  81. exit4:          ret     9 A: ]3 B6 M; p- r5 c
  82.                
    2 {8 a; M  l5 \
  83. end
复制代码
  1. ;A20STATE.ASM ( X! D! |( W# @1 U7 g
  2. ; ' e6 \' P+ s, M3 u
  3. ; Returns the status of the line A20 through the KBC
    " m: ]0 j; C  y( H" o# [
  4. ;       programming by bini for debug. 2008-07-01
    & v8 L6 _7 `3 W2 R, V" V: D# R# v
  5. ;
    ( V* X1 O8 Q9 Q) z' I2 M
  6. .model tiny
    ) B' O. i5 B. j5 A& h; ~- S: \
  7. .code
    . s* N& V& y& C: j5 z1 I; x; W
  8. .4865 J# F* U& G3 `% n0 N6 [0 ]
  9. .startup
    4 g" C' _7 x7 b  \
  10.                 mov     dx, offset msg_fail ( ^4 y0 u" B# `. Z! a, M! ?: v
  11.                 call    _GET_A20_STATE_* g: w  j: [  |* K, u/ p2 B' [
  12.                 jz      exit1                           ;  was a problem
    - T6 r' l  }0 R# Y3 |) J8 E
  13.                 push    ax                              ; Save state, AH
    ( z) h6 [$ A* u
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
      w$ [1 i3 P# D3 S* ^
  15.                 mov     ah, 09h ; ]) M1 U/ ?) s
  16.                 int     21h                             ; Print message # W* c* c: O1 o
  17.                 pop     ax                              ; retreve state ' i1 T% \4 q* J- g

  18. 2 X$ }5 N$ r( ^2 s  O  t
  19.                 mov     dx, offset msg_dis
    / H  R2 p. x/ q/ `2 e" q+ U
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    - k% k1 e. t- {# B; t# ^
  21.                 jz      exit1
    # N4 {1 I0 ]7 v& p8 U: T
  22.                 mov     dx, offset msg_en
    ) Y$ R# f1 c% G0 P. W8 ^$ q

  23. 2 Z+ H. T' s1 c; j5 y: ]
  24. exit1:          mov     ah, 09h
    . M) I" D0 b& d2 c4 O7 U3 M
  25.                 ; DX already contains address of string # k8 D- R8 h$ H. f+ p3 I
  26.                 int     21h # E( J+ c2 K3 L6 l3 v

  27. * m7 p+ ^/ m# x& h- p, r2 H
  28.                 mov     ax, 4C00h 6 s/ @8 ~2 M( Q) r# Z. ?
  29.                 int     21h 1 P7 Z. b% z1 _! r4 A
  30. 7 X" _2 u' {3 k* {3 [4 D+ p/ w
  31. msg_ok         db      "OK", 13, 10, "A20 $" 0 J8 j- _8 l! t7 \, h/ c' P" ]) ~
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ) D- }) v2 H. ?. U7 A
  33. msg_en         db      "ENABLED", 13, 10, "$"
    / j" W6 t7 \. _( S9 e* a4 w
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    ' ?9 d* H8 |6 N7 `% ~9 J+ s

  35.   J! d5 J& I# z- b
  36. ( ]( j7 d& Y' {3 a" A* F' n! b- K9 I
  37. _GET_A20_STATE_:
    $ t7 h) i- K' p6 C/ U# A
  38.                 call    A20Write                ; Wait till the input register is empty - U9 }2 \8 `! x* U- J
  39.                 jz      exit2+1                 ; Bypas the reset int's
    9 Z8 _; r: T" N0 I$ |
  40.                 cli                             ; Disable ints so we'll get our value % B, t4 g3 B" r8 ^& O3 k

  41. - p6 [' s* l) W  H6 B6 C: X5 N
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    % Q7 u- y5 d- i  y
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    5 _6 ~! [% S2 ^1 y
  44.                 call    A20Read                 ; Wait till the 8042 output register * E. n% z% i" e7 y# T
  45.                 jz      exit2                   ; has something in it's buffer
    & H* y9 E6 k0 N# k. `

  46. : Q1 u! M) z& c% `% H+ R
  47.                 in      al, 60h                 ; Get it
    4 v/ A7 x  R$ l9 |0 ?( ^
  48.                 mov     ah, al
    : w5 k; i% b9 d2 C7 w  q
  49.                 call    A20Write                ; Make sure the input register is empty 5 }; S: S, C7 |( R& F" G2 A3 ]
  50.                 jz      exit2
    2 |$ _, {6 T) ^( v. R4 n8 _
  51. * q, T: v% z: O9 Q
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ; S* S! w4 M4 b' v: j5 D- _& N6 F
  53.                 out     64h, al 1 m; O: `9 w! T7 K% [
  54.                 call    A20Write * y; r, p1 n" K9 d
  55. 3 `9 Q1 p8 w  Z& |% t  ^' q5 F
  56. exit2:          sti & N( z- R. K  x$ A, z/ g
  57.                 ret+ q; H. ^! r  V$ r
  58. - ^" |+ x1 G7 _# ^4 Z- c
  59. : q/ n  s6 v3 s/ h& m/ Z$ u
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    - O/ H, a  `" V# O- j# m  Q9 ^
  61. get1:           in      al, 64h                 ; Get KBC read status 1 V5 o4 w7 H& I1 V" _5 J
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    & w4 t6 X: m2 C7 K9 [  I
  63.                 jz      clear # {. q; r. @, \: R2 I% B! p
  64.                 dec     cx 1 B4 _1 p; Z# U: @
  65.                 jz      exit3 4 k  ?& z5 z: r4 J* C" H" |1 O
  66.                 jmp     SHORT get1
    9 l1 E6 [. T% J( A7 l
  67. clear:          inc     al                      ; Clear ZR   Y& u" s; i& V+ k: L$ p) y
  68. exit3:          ret % Y0 W6 x9 @1 i( Y
  69. ( K' J+ @% |# R$ i& ?

  70. + b' A2 b. i# j7 D6 ]! i' H
  71. A20Read:        xor     cx, cx ' g1 j; k2 n" y" D
  72. get2:           in      al, 64h
    4 x! q6 h. x; J$ V6 h$ f! F
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    6 O! P0 m/ q( n2 a* `
  74.                 jnz     exit4                   ; something for me
    * G4 y5 J+ u; e9 C/ T7 S' u
  75.                 dec     cx ! o( U' R' K9 `+ r' h5 g
  76.                 jnz     get2
    ! e: t4 C+ S5 a/ @1 w
  77. exit4:          ret     ! W8 L% l* L. v8 P( y" ~; x6 J2 l! @  O
  78.                 ; e4 _) B7 m* g2 l" [) H1 C" v2 v/ j
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()1 n; V4 ]# k0 U* J, }1 l* |: n& `
{        while(inp(0x64) & 2);        outp(0x64,0xd1);0 M' P+ v0 X  F3 i7 X2 c9 m
        while(inp(0x64) & 2);        outp(0x60,0xdf);
/ ^4 E2 ], U2 `        while(inp(0x64) & 2);        outp(0x64,0xff);: S6 }& m) ~# {/ ^
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-8-11 16:57 , Processed in 0.048000 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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