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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    5 C4 `3 `$ U2 j! Z$ ~: Z. w
  2. ; 6 j; T1 ^8 G8 [7 _$ @+ s
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    8 Z( d7 Z2 N, \% Q
  4. ;       ml A20ON.asm % f9 ?+ ?0 G7 L8 e0 T
  5. ;
    & Z3 b) k& E7 y5 `, s' m* t# t5 n* C. Q
  6. .model tiny
    . P4 R: N- v! U  B% l' w
  7. .code
    # D0 c# j; p  A9 R8 J2 F7 k
  8. .486
    . T& k; T2 Z/ ~4 Y  z6 I# I5 o8 I
  9. .startup' H6 M6 u4 D7 b
  10. ' y) ]: Y" `4 _* o( h
  11.                 mov     dx, offset msg_author
    * P5 w8 [% p& D: {  ^
  12.                 mov     ah, 09h
    ; G# |4 v+ R/ M0 a" i) X/ Q
  13.                 int     21h
    ! D/ T6 j) F( [8 X+ n
  14. 1 r# f! Q) y! m3 b2 m9 Q
  15.                 mov     dx, offset msg_fail
    8 Y5 b. D, H% G7 P6 S& w' O5 L
  16.                 call    A20_ENABLE
    ! K/ K3 ~+ j+ P* h! @& ~
  17.                 jz      exit1
    - l* ?: {5 }8 t
  18.                 mov     dx, offset msg_ok
    + {! B) ~7 e2 H) k
  19. . V2 g  x, S9 c$ J, u4 c* v
  20. exit1:          mov     ah, 09h
    - N9 x4 q/ u5 ~" X2 A$ K0 M/ o* J
  21.                 int     21h / R, Y! h7 c. T9 ]2 O5 H9 l3 P
  22.                 mov     ax, 4C00h
    % w, ]* a$ u& _
  23.                 int     21h
    ; v" h" U0 N4 w( Y- O/ s
  24.                
    ) U$ N0 I* i1 \4 u% d/ r
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,- L/ A8 u) L! _, b) }0 {8 G
  26.                         "2008-07-01",13, 10, "$" 0 u6 n% P: ?. E& O# U, ]; ~5 y6 f# W
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" # f" q  J3 m% g' i  u7 t
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" ! v/ Z* B9 n$ n/ w- u
  29. 7 ~: |0 ?9 P3 l! I8 K4 e" {
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------/ a' i3 G8 H3 P% g7 O
  31. A20_ENABLE:
    0 o$ i8 d; C4 l7 g: v7 d& E
  32.                 call    A20Write
    & y' k" H& a% h0 Y3 c; K
  33.                 jz      exit_enable
    # Y8 b* L5 [- O% r  Q
  34. 2 B) m- C. O% a4 r* t9 n
  35.                 cli                             ; Only need for reading value from KBC 2 C- a8 l6 x+ I. ^
  36.                 mov     al, 0D0h " \" O; E8 |4 ~+ g# ~
  37.                 out     64h, al
    2 t7 \8 D% j! U$ U( H0 ~
  38.                 call    A20Read
    % B( f. R  C4 F- ^. z# ~: O
  39.                 jz      enable_int $ L+ w, h9 Z- B) V; q9 C
  40. 9 n" W- L) k( k  O
  41.                 in      al, 60h                 ; Get current status * A' X* E+ s* f3 l  C9 B# u
  42.                 mov     ah, al ; ~( |* G# K/ \0 J$ b9 b. V
  43.                 call    A20Write % g% s% i$ o4 R, o; Q. X) k3 J, y
  44. enable_int:    sti
      `( R9 R, P' ?2 J" e
  45.                 jz      exit_enable
    # W1 `) h2 ?- n! V, K9 E9 V
  46. * I% _# H/ J! J. f) V7 e/ c
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the & x, _2 j: ?& {3 u6 j
  48.                 out     64h, al                 ; Out Put Port next
    * p2 r% G( g; o4 k$ c+ z
  49.                 call    A20Write
    4 U! V4 J# V' s- }1 g0 C/ M1 Z  f
  50.                 jz      exit_enable, G* |' ~3 Z, E9 k! p* d8 @& V
  51. . P2 U7 }: Z: c9 r0 f4 \7 K
  52.                 mov     al, ah 3 [4 N4 \5 f2 M; O+ q
  53.                 or      al, 2                   ; Enable line A20 6 P6 @- h) D- P" F* u
  54.                 out     60h, al
    & a4 c; I  [& V& C
  55.                 call    A20Write
    & u" w3 Y# z# L
  56.                 jz      exit_enable  t9 L0 A! u: E
  57. * a9 f: V& f/ z) a- w. |. G
  58.                 mov     al, 0FFh                ; NOP $ F# N- ^8 [1 m+ A; g% x! N/ w4 ^% }
  59.                 out     64h, al
    5 J5 T& }( i* Z! L5 K% L  l, R
  60.                 call    A20Write
    4 i0 F5 N' E- F; ~% @  u
  61. : o9 e, Q7 l3 e" n
  62. exit_enable:          ret
    3 [4 \' ~$ j* C. A8 Q: T0 c( j
  63. 2 v3 O1 i# K5 Y- R) g
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 G, h- j7 _- B' g( x) P* o
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 3 s7 W& I1 L( @5 l+ y
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear , m  T* {% G4 l. W) f
  67.                 jz      clear
    $ T; F2 i* l( t" t6 x+ [0 r
  68.                 dec     cx 8 B$ k( ^+ G0 u( X9 D3 q9 X) I
  69.                 jz      exit_write
    3 J9 t3 R, a: \) ^. @
  70.                 jmp     short get_wirte
    % I- M( J* a3 v4 }) ^4 I6 @
  71. clear:          inc     al                      ; Clear ZR
    8 @5 G3 E6 X. a' f# b
  72. exit_write:     ret
    $ W! @- u. a/ L+ p+ F
  73. * |+ T) @4 {% a7 f) ?$ L, x! H

  74. + z: D8 _, U8 t4 X/ X0 }6 z3 C
  75. A20Read:        xor     cx, cx
    & O% g6 C9 V9 b5 _! e0 \
  76. get_read:       in      al, 64h
      d+ e9 x9 e! H. B. a
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    1 j: c: r+ {9 f3 K" n( Q. I
  78.                 jnz     exit4                   ; ... 6 H! \* U; g3 H' R: `8 D
  79.                 dec     cx % f/ I* V( d* w3 ]8 q2 @; K2 S4 v
  80.                 jnz     get_read
    ; J& `6 o: l) C/ U: l
  81. exit4:          ret     
    3 l# v0 ?; j3 t. ~9 k
  82.                
    , [" k2 I2 f6 ^# T8 k5 Q+ x6 {- }* N
  83. end
复制代码
  1. ;A200FF.ASM
    9 A6 \9 c7 i* k/ `# J7 ~( u% Y
  2. ;
    + Z- O5 |8 W# D1 J0 Q+ [0 O
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01( J% U" `0 s. c% }6 F! K
  4. ;       ml A20ON.asm
    , y$ w: o7 w0 f
  5. ;
    & v8 B: K, u# R$ U/ u! l
  6. .model tiny8 f  {& f$ |0 [; `( S- A, e
  7. .code
    " e" Y  _) g$ t/ ^- N! w
  8. .486
    $ J; g8 \; k. I
  9. .startup4 b6 y  M; F  d1 P( @3 g

  10. % O- ^* u- d$ q% L0 A
  11.                 mov     dx, offset msg_author3 W" k: }0 B( E- F
  12.                 mov     ah, 09h
    3 Y5 W4 _' _+ A+ d: J: _
  13.                 int     21h8 K1 b2 S: p/ V. c& }

  14. / c+ Z' L) b# Y$ M
  15.                 mov     dx, offset msg_fail
    9 E2 ]& c, x% Z0 s0 r
  16.                 call    A20_DISABLE
    9 F0 Y: l& a1 M  x4 O" |3 n
  17.                 jz      exit1. X5 f$ @- v7 M$ d' |, u' _) e+ J
  18.                 mov     dx, offset msg_ok
    ; m, r, \8 j1 A; P; I. |

  19. 2 l+ u8 E3 C6 z, ?8 H% F; K: Q
  20. exit1:          mov     ah, 09h
      M& [3 u( k5 {7 ?$ F) @5 a
  21.                 int     21h
    * B4 t5 b. ]" s0 c
  22.                 mov     ax, 4C00h 3 n; |4 V& S1 [+ V1 E
  23.                 int     21h
    7 H3 t/ X! v0 g( o: j$ _$ |: g# r5 ~
  24.                 , ^. ?3 U8 W9 c, W' M' k
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    0 ~- o3 t7 E/ w8 A8 r
  26.                         "2008-07-01",13, 10, "$"
    4 g8 y; U/ J' t! @3 X- {8 d6 }
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" . b9 T$ T, R0 c7 C4 `- Z+ W
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    ; P" c9 ^) F! j( S% B- E

  29.   y/ y7 P" I$ V* ?" B: c* q
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------5 U/ \) A9 k: F4 m- Y1 @- _$ m
  31. A20_DISABLE: 7 f, ?8 `9 A2 @9 i
  32.                 call    A20Write
    2 D9 c) n1 T/ y- U
  33.                 jz      exit_disable& [& z8 v; u7 U4 i

  34. 4 s' e) |* i  f; X$ C; l
  35.                 cli                             ; Only need for reading value from KBC ! w" S% J# E* `" x2 b- p
  36.                 mov     al, 0D0h
    $ k- e" i; G) a1 w4 `7 O* [
  37.                 out     64h, al
    . c# @% g# }+ h/ @$ d4 y( m
  38.                 call    A20Read
    4 P6 [1 G. u3 A
  39.                 jz      Disable_int
    9 N- f; t" b7 |/ L' C
  40. 1 M. s9 ?0 h5 |; z; `
  41.                 in      al, 60h                 ; Get current status
    2 C, f2 z2 {* k% C- g! P  g' _
  42.                 mov     ah, al ! ^6 v; x3 V2 D- T7 |3 ^
  43.                 call    A20Write ' V) z# @+ J$ v  u
  44. Disable_int:    sti
      |7 r* k5 n, E& i! N/ ?
  45.                 jz      exit_disable! O8 `0 u1 W; ?- r7 [6 s
  46. 7 N' O0 D0 M: h
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    - M. m% t. A# h1 F4 p% ]6 B8 H1 S
  48.                 out     64h, al                 ; Out Put Port next   A5 m) l- g4 z) U* U: m! V8 X$ @
  49.                 call    A20Write . Q  |/ p/ w" s/ R. M
  50.                 jz      exit_disable
    & j3 j9 O9 k" w0 C+ W  r9 s+ m

  51. . F! L: I" e7 ~) a+ c/ B
  52.                 mov     al, ah
    4 y. t5 s) `0 A8 M+ ?
  53.                 and     al, not 2               ; Disable line A20 5 }! v( {& a) \6 }8 e
  54.                 out     60h, al 9 N$ _( l4 B" e9 i2 I
  55.                 call    A20Write
    ' l* g0 ~1 q) U* {" f4 c1 Z) A0 f
  56.                 jz      exit_disable$ T7 B  t; S6 j0 [  B# t
  57. * R8 `$ v5 N/ R
  58.                 mov     al, 0FFh                ; NOP
    5 Q7 C: _1 F! h0 z3 d
  59.                 out     64h, al + }: w( c( ]$ D" ?
  60.                 call    A20Write / e& M' y9 G1 D: s3 J# R# z

  61. ' S4 e. k" S& G( C# B- a: o& r
  62. exit_disable:          ret 3 Q0 y0 P& Q) v6 {* ~1 r3 m4 x* d
  63.   k$ ?4 G; Y4 f$ Q  D! L
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    5 A3 y( ?3 C; c; [. X( q
  65. get_wirte:      in      al, 64h                 ; Get KBC read status " v0 M! ~/ A; ?; S) b- r/ c
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    $ x- q) q7 g0 _: M. x# N
  67.                 jz      clear " e" D. N) z/ c+ n* e
  68.                 dec     cx 7 {7 {' g  g) ~
  69.                 jz      exit_write
    9 l( N- B% |, X, \
  70.                 jmp     short get_wirte : N4 [! _, t8 {; l; u
  71. clear:          inc     al                      ; Clear ZR
    , |: e* f% y% P/ z( V% N# R' {
  72. exit_write:     ret   M. z( z3 q5 u5 ~8 a
  73. ) Z! T  i! k& K- x1 ]

  74. ( L. d; X1 t* M$ r- y% p- ?
  75. A20Read:        xor     cx, cx
    5 D- ~  S4 y) k" [% W
  76. get_read:       in      al, 64h 3 B* Y3 c- m' c6 C
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ( F3 N- G+ `1 e% Y
  78.                 jnz     exit4                   ; ... " O, e: z5 _% u  N& a+ p
  79.                 dec     cx   J4 |3 L2 o+ p- B6 w! F& D% D1 S. @
  80.                 jnz     get_read' q1 L/ ]3 Y  A9 _
  81. exit4:          ret     ' E& R9 P) y" E/ `  B+ F  P
  82.                
    - g' S, w& c% R9 }& g8 B
  83. end
复制代码
  1. ;A20STATE.ASM 3 N( L4 K) ~: O$ W$ p9 ^4 `
  2. ;
    0 x0 s! K% p9 f4 H* I9 \4 E6 I
  3. ; Returns the status of the line A20 through the KBC
    , D6 j4 [$ u. h) K! n: U# p$ C
  4. ;       programming by bini for debug. 2008-07-013 k1 c& R. G7 ]+ K  Z8 q
  5. ; 4 O- I& U9 K* ^; D7 G
  6. .model tiny& D4 B9 X- R9 z9 Y0 O/ k
  7. .code
    3 N6 _: G9 _: ]" q- Q- Z
  8. .486
    % r0 B' g$ u4 b1 v5 L7 |, Z
  9. .startup* S; {7 r/ \8 l3 a  G
  10.                 mov     dx, offset msg_fail
    , M9 p, d8 W- C
  11.                 call    _GET_A20_STATE_
    + C* \3 \; X% D% ~- J
  12.                 jz      exit1                           ;  was a problem: K* k, D. J$ S$ d4 X% j
  13.                 push    ax                              ; Save state, AH
    ! R$ r6 ?" @/ x1 m
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem 4 v: x- F- b4 n3 R
  15.                 mov     ah, 09h
    ! e, n  N+ q# C( B5 y
  16.                 int     21h                             ; Print message
      H, S- q! ~. D5 b, m
  17.                 pop     ax                              ; retreve state
    . z* c  x  ~+ o
  18. 1 p5 W& ?* s$ e  {9 L9 f& Y2 Z
  19.                 mov     dx, offset msg_dis
    3 k$ F$ B# ?6 {/ F0 L* w3 v
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state - o' \. m5 s5 k2 C. `. M' }
  21.                 jz      exit1
    7 s" o, k) h  E- u3 o
  22.                 mov     dx, offset msg_en 3 {9 Q' w9 v6 D9 j+ b3 n
  23. " e6 `# H7 M" M( _2 e& o; r! }7 |
  24. exit1:          mov     ah, 09h ( V. z2 C, ]+ K- U5 N4 W8 a
  25.                 ; DX already contains address of string ; b/ }' E& C( j% J- I
  26.                 int     21h 5 L9 }; A9 H8 M! I9 d

  27. . E8 Q& `, N, L! K/ {
  28.                 mov     ax, 4C00h
    . b; |. j3 g# F1 F5 ^8 {/ Q5 R
  29.                 int     21h
    % i1 F0 d5 k( D% o
  30. ! S. y$ U/ E" d1 x6 W# u
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    / ^- o/ x, Q: y( E
  32. msg_fail       db      "FAIL", 13, 10, "$" $ W" c7 `8 L6 t& @% u# S
  33. msg_en         db      "ENABLED", 13, 10, "$"
    8 H% O% h& E; R7 \  v9 q
  34. msg_dis        db      "DISABLED", 13, 10, "$"2 T8 H3 c* B0 d3 t3 p
  35. * j8 W5 P% N' b/ p/ N2 M$ f# {

  36. 8 S' d: H9 U! Y
  37. _GET_A20_STATE_:
    % s. A) ?8 |* x( L; l
  38.                 call    A20Write                ; Wait till the input register is empty
    + c  t. j; D; l5 e' H: R
  39.                 jz      exit2+1                 ; Bypas the reset int's   ?% B: C5 k& t8 {% `& |
  40.                 cli                             ; Disable ints so we'll get our value / V% s; k+ l0 s1 z1 Q" |- o
  41. ! W. D' |7 h9 J' R7 j6 _
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register # D6 p( J! y0 H! E7 z
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    % y& ?2 Y4 a( P
  44.                 call    A20Read                 ; Wait till the 8042 output register   N- W3 J6 H5 L3 L
  45.                 jz      exit2                   ; has something in it's buffer
    9 p( a9 F1 p; l4 E: t7 L& r

  46. * w* Q# g0 L/ u' t- F4 ^) Y
  47.                 in      al, 60h                 ; Get it
    ( J& j2 q& m# |1 I5 b; ]
  48.                 mov     ah, al
    & L+ r& _/ S% [
  49.                 call    A20Write                ; Make sure the input register is empty + W) ~" a3 V# s
  50.                 jz      exit2
    4 o1 h0 S0 A) g# W1 P  }

  51. 6 j3 W6 @  x1 N/ Y7 F' f* R
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    ' {8 Z* _# }+ }9 g
  53.                 out     64h, al . M3 R/ I" o! z
  54.                 call    A20Write
    # \( a6 |; Q# n

  55. ) u* v" ]/ H/ i+ @3 e
  56. exit2:          sti * ~8 r  w  |- d9 ]0 M
  57.                 ret3 E- V1 p+ T  z5 ]1 x
  58. # x& M# }. I& S3 ?

  59. $ c: S$ a( ]+ }% {* Y% A
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 7 s% \: t2 |+ k3 T
  61. get1:           in      al, 64h                 ; Get KBC read status 4 e- E) @$ j4 Z+ Z3 P$ }: s# ?
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    2 [+ |2 {* E* j1 m
  63.                 jz      clear " K9 p9 @  ]9 t- [7 Q
  64.                 dec     cx
    - A# g4 D8 n) H1 K5 H
  65.                 jz      exit3
    ) p! w/ \! L. c* |0 x: O/ w* S% a1 f
  66.                 jmp     SHORT get1
    ) }4 e- P+ i2 g8 T! j" ~& |9 R
  67. clear:          inc     al                      ; Clear ZR 3 |; }: ?; t5 E+ R- K
  68. exit3:          ret
    ' D/ y' I! J  I0 G# F
  69. 8 z" O/ T+ }- c
  70. * q4 ]5 A: F2 I3 ^9 V" ^' K& v9 K
  71. A20Read:        xor     cx, cx
    $ e% a: Z/ p) t6 ^
  72. get2:           in      al, 64h , N5 O; e" M4 i0 x. w
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    9 u5 g+ K2 D$ {* ?% _
  74.                 jnz     exit4                   ; something for me
    ' B' k$ |4 Q+ a$ {# x, G9 o, d
  75.                 dec     cx 5 r  ^- P- F0 {* n; T5 D  Y; d
  76.                 jnz     get2
    * K5 H, @2 q! V" V4 M! \
  77. exit4:          ret     , l, [/ O4 f! I! G& @+ E! h' R
  78.                 ' l# m3 \6 H  z( T; d! `
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
- M, w1 n7 A: a  a3 M{        while(inp(0x64) & 2);        outp(0x64,0xd1);0 i3 ?) ~. Y4 m9 e/ k
        while(inp(0x64) & 2);        outp(0x60,0xdf);, C& Y& `: V/ G6 Z" \
        while(inp(0x64) & 2);        outp(0x64,0xff);
# i0 c5 u( n# X* w1 R; K6 p+ o}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-17 14:55 , Processed in 0.138778 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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