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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    % @6 ~# r; c  {: t. p/ n, s
  2. ; 1 v) d/ ?# y: m) q
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    0 N6 o! s4 ^, O* T4 V4 |
  4. ;       ml A20ON.asm
    - {) j- b# N+ m! b" d. O$ T
  5. ;
    % m3 J+ U6 E2 O7 O
  6. .model tiny
    ( E2 g1 q- _- A" n  \8 S
  7. .code0 f$ c1 x9 e& N1 z7 B
  8. .486
    $ [/ r3 R) O% M5 W: C, a- k
  9. .startup+ L# b9 Q( n4 v. N3 y% W( }

  10. " Q) e& N- w! J3 h: s
  11.                 mov     dx, offset msg_author* A* e9 {# H" }
  12.                 mov     ah, 09h
    1 d  W5 q0 Z& g
  13.                 int     21h4 U! ^9 N0 `" ]( @, @3 g: A

  14. 9 z6 r& T! D; X6 ?4 O: A6 w1 K; C$ T) q
  15.                 mov     dx, offset msg_fail
    " J  B- N* [: }
  16.                 call    A20_ENABLE4 o! f5 [  @8 J* o; s& f, x
  17.                 jz      exit1
    5 y) O9 Z* {6 D. d4 D
  18.                 mov     dx, offset msg_ok
    5 R  j6 ^$ v2 i  s& c
  19. ; L* v# Q4 c) V# x  n* L
  20. exit1:          mov     ah, 09h
    $ e' d6 O$ L& _3 f
  21.                 int     21h
    . O4 A$ c% \2 X+ S) ?- w
  22.                 mov     ax, 4C00h
    - v9 w- L7 e+ q# F0 f4 \# n
  23.                 int     21h   v8 s! z9 S* `$ X, \" i
  24.                 : S6 B) N, ]' C9 W$ b) Z3 A2 ?6 Q
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,) E5 m( V, x' k) x2 G) F7 l# u
  26.                         "2008-07-01",13, 10, "$"
    ' Z" U; |# y. c  W9 _7 E
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 8 y/ t% h. e4 U6 f6 F' x' I3 U
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 4 {0 I4 ]' v5 P
  29. 2 _* i4 |6 z+ H7 r" f- s
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------4 T  `. G9 k3 ~4 |! f* t) \- k- Z
  31. A20_ENABLE:
    " X% b) n" W' O7 k4 A
  32.                 call    A20Write
    + j7 w1 F: K/ N3 ^2 p7 D
  33.                 jz      exit_enable2 ?. s; \& N+ [, ]
  34. 0 L3 a2 d+ u+ V7 A1 ~, ^2 n
  35.                 cli                             ; Only need for reading value from KBC
    * G* Y  A# E! E, u% M2 d; ]# Q4 B
  36.                 mov     al, 0D0h 7 m) X# c/ P% Z5 L9 w3 o
  37.                 out     64h, al 3 d  X" y: o0 [: L0 I! m1 @
  38.                 call    A20Read
    ! S& c$ l1 u, s3 ]# S' r% Q
  39.                 jz      enable_int # q6 g( P. g7 q/ n7 A$ `* l9 L/ w0 q7 u
  40. + l/ n# C4 _4 \  b6 d- I
  41.                 in      al, 60h                 ; Get current status
    7 ^6 G) _  G9 K, _* x  E# I
  42.                 mov     ah, al : ?- j+ m% C/ L! ?0 ?
  43.                 call    A20Write
    . r% [5 I; t  ^8 A
  44. enable_int:    sti 9 {* [$ r8 U- q: f7 T! O2 T
  45.                 jz      exit_enable: Z- r& t) B+ |( f; n
  46. 0 I$ Z' [2 [9 L5 w; d2 Y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    + i4 y- h! V; w4 F* Y$ j
  48.                 out     64h, al                 ; Out Put Port next
    ' ~! q0 g6 d: Z  b5 N
  49.                 call    A20Write 0 ~4 t) `! x  T2 Z
  50.                 jz      exit_enable
    - ?" F4 m; {8 k% K' z

  51. + d7 o+ n- M9 o, ^- q- n7 r
  52.                 mov     al, ah + l. \- D: f' }# _- g
  53.                 or      al, 2                   ; Enable line A20
    ( ~: ?1 A1 p5 P1 o
  54.                 out     60h, al
    ; s0 b6 n4 l9 b) C
  55.                 call    A20Write ( g* K$ Y, t6 M4 s! z+ R' B
  56.                 jz      exit_enable: J: T( H9 a$ A
  57. , a2 e0 V  ]% H9 d9 K% }3 {; y! w4 |
  58.                 mov     al, 0FFh                ; NOP
    % ?$ y" ~/ N3 L. x* T
  59.                 out     64h, al ) ~+ v# y8 ~- @8 }' Q7 f
  60.                 call    A20Write , Z7 `. v0 K) }

  61. 2 {& H+ T/ J2 N3 l/ q9 @' M
  62. exit_enable:          ret 4 z2 n7 `. C1 ^8 S+ K- v" c2 p
  63. 2 W2 S6 j+ F2 B
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 ]- E& w& h( ^/ B8 B0 }' k
  65. get_wirte:      in      al, 64h                 ; Get KBC read status - F0 ~0 g/ e% j. i3 y' B! T/ B: U
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear . V% `5 W% L- C
  67.                 jz      clear 3 o* i7 d* G. m
  68.                 dec     cx - x. q2 y+ ~( [: |
  69.                 jz      exit_write 6 \  p2 `' [+ F2 E$ I, H
  70.                 jmp     short get_wirte : Q& D% w  |3 c/ m5 q# U6 b
  71. clear:          inc     al                      ; Clear ZR
    7 P' X: Q# J9 [4 v3 M+ a3 [! j
  72. exit_write:     ret
    7 R2 X' g0 k2 m4 j0 D" x6 s1 d

  73. $ n: B) |  g! b/ K" @( v
  74. 6 O6 g" M: l' N- y. Q6 |7 \
  75. A20Read:        xor     cx, cx
    $ h+ [0 U1 c2 Y0 @
  76. get_read:       in      al, 64h
    / _/ U9 ?7 H* a: }: H  @* D# v6 ?
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    6 {% ]8 D. ~4 ?
  78.                 jnz     exit4                   ; ... 3 r; @6 O9 q2 _! v0 R/ @4 y
  79.                 dec     cx & k+ r+ |# Z5 _$ b
  80.                 jnz     get_read% K) Z# @" P1 Q% o$ z
  81. exit4:          ret     
    3 o$ m: ]$ R8 j; }- U
  82.                
    7 Y) J+ a4 _" B& Z9 ~
  83. end
复制代码
  1. ;A200FF.ASM 3 |6 y- \, s! U/ \) F
  2. ;
    7 _) z- |7 E5 k8 f" u5 ]
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01/ H8 E6 |6 j& ^& U- c  M1 U
  4. ;       ml A20ON.asm 8 M) v. K$ c4 J: Y  d
  5. ; / D" p& \6 W( z* U5 A' s
  6. .model tiny
    ) ^, H& y4 ~+ G" E& \. E4 @
  7. .code
    - [* W0 |0 u: ?  P6 ]
  8. .486
    4 D5 S& U; w) T$ C' p- m7 h
  9. .startup
    . b- O% ~0 P" D- }

  10. ! ^4 y7 L5 z: S! \0 O3 s
  11.                 mov     dx, offset msg_author
    ( a- c' k/ c) J- d% L( H
  12.                 mov     ah, 09h
    ) V& y$ Z8 H# G
  13.                 int     21h
    8 M. ]! K6 `5 ^5 j, i) B& t9 x; z
  14. ! e/ a: a' U. P& g: g+ Y
  15.                 mov     dx, offset msg_fail
      @- D# @" S3 p$ _3 P4 \
  16.                 call    A20_DISABLE
    ; Y; [+ y# C$ j( l- E
  17.                 jz      exit1# ]* B8 T  K, L6 a
  18.                 mov     dx, offset msg_ok
    5 R8 R3 ?; ^$ x: s) K9 Z4 ?

  19. : ]5 k6 V5 g! D8 [3 B5 f7 v
  20. exit1:          mov     ah, 09h 1 s' x) S; x* A; X* p$ J7 A6 R
  21.                 int     21h
    . x5 t) X# Q. k" i
  22.                 mov     ax, 4C00h ! ^( ?3 r" D0 \# \* O
  23.                 int     21h 5 t) h& G- Y2 H4 I8 h/ [6 M
  24.                 % [5 \7 _) V1 @7 R1 Z, w" a
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    , b" L6 U: S3 s8 Y: g
  26.                         "2008-07-01",13, 10, "$"
    # q7 y! O1 P* n; D1 H, ?1 O6 i/ g
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    6 q4 k4 K7 P. A) ^! x& T
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" . C8 {. ?4 i) l4 r# m

  29. . y" W+ t0 h* X/ \/ o
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    # e8 a. F) a# l! T/ m1 e, }7 m
  31. A20_DISABLE:   ^/ [0 _( }9 `" V/ P
  32.                 call    A20Write ; ]& Y; {3 v1 T: ]
  33.                 jz      exit_disable
    $ F, W% @9 N* d0 d! D7 y' u

  34. 7 ~- ?5 a6 ?' S! e1 S
  35.                 cli                             ; Only need for reading value from KBC
    . e0 O! d9 Y6 H/ M! ?+ @* u
  36.                 mov     al, 0D0h
    / u( y* x8 Z. [( ~0 j2 n
  37.                 out     64h, al % }! r% D/ @1 r. |$ a' B( C  @
  38.                 call    A20Read % C8 b2 v9 A$ P) R
  39.                 jz      Disable_int
    4 Y! Q5 Z2 @! a; ]7 s
  40. % b1 D( X; Y7 C8 o# H: C
  41.                 in      al, 60h                 ; Get current status
    $ K% V- ^1 [* P* k) _7 p& @$ w
  42.                 mov     ah, al
    4 x. P: \/ F! \
  43.                 call    A20Write
    % [" i- C( y0 ^; C2 N/ I+ |
  44. Disable_int:    sti 3 B$ n' N' n  y  ]7 ?/ s' Y2 w
  45.                 jz      exit_disable0 c. B3 y0 h+ P

  46. 6 G1 N, ?2 H  A  r1 c4 T
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 7 V8 k5 a) f5 k  C2 ^2 G
  48.                 out     64h, al                 ; Out Put Port next
    7 k; O: V' v% G" ]
  49.                 call    A20Write
    : K7 u2 t2 F; f: Q
  50.                 jz      exit_disable
    " K  z4 D( e/ \( m, S

  51. 5 f3 I" ]) @" |
  52.                 mov     al, ah
    1 N% n6 ~  _6 ^7 d. d+ \
  53.                 and     al, not 2               ; Disable line A20 9 X; s; q# a" s+ ^
  54.                 out     60h, al ; g8 c. r" Z' f; w9 c2 i
  55.                 call    A20Write
    " y9 O6 ~4 t3 b3 O& j3 b) x: c
  56.                 jz      exit_disable6 E( J3 S# ?3 ]

  57. # l& j7 Z+ ]  |$ _1 y
  58.                 mov     al, 0FFh                ; NOP & h% B6 F1 k. Z# v, Y5 v
  59.                 out     64h, al
    ! r$ O. f) U- A
  60.                 call    A20Write 6 q8 O8 B- E1 ^0 l: T4 u
  61. 1 y4 f; n1 P3 ?; F! r, g! o" u4 T
  62. exit_disable:          ret
    3 u" i& L# H- F3 \2 O

  63. & O' p9 D! y$ b2 G6 X* \
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    5 k5 v$ i* z; k; M$ e
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ( t( t- U2 b& U
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ; o5 z, o8 j8 V3 j, Z9 y) a
  67.                 jz      clear 6 g! u+ f, h6 G1 ?+ ]
  68.                 dec     cx
    3 d7 p6 }: D+ q9 F
  69.                 jz      exit_write
    ) j* j) N  }. w! g. e0 _
  70.                 jmp     short get_wirte ; A5 m8 R' G" m& H! h
  71. clear:          inc     al                      ; Clear ZR
    - w4 }8 l7 `! y$ `1 ]7 a
  72. exit_write:     ret
    , T- h7 }" |8 f& r0 n2 T

  73. / m0 T6 k% x6 v7 a, c) L+ t
  74. 7 @! m5 C; i$ f0 S+ p$ }2 b3 [2 ]
  75. A20Read:        xor     cx, cx - e' Q4 p/ x& M( t3 N: I) h' m
  76. get_read:       in      al, 64h ' P* v7 n+ T) h0 Q# V+ }1 r
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    2 P* K2 @! F5 d9 V) U! ]. E& k& Z
  78.                 jnz     exit4                   ; ...
    ( M2 i8 K4 W) s( s4 h! S
  79.                 dec     cx ( N" J; X- p4 q- @# D& F
  80.                 jnz     get_read
    8 d3 e* m3 B1 o& k  H
  81. exit4:          ret     - z6 c$ A9 b( A, N. f+ z# L! Q
  82.                
    ( ]4 h, }1 C# Y! f
  83. end
复制代码
  1. ;A20STATE.ASM 8 ^+ S+ F' w6 S" e8 W6 Y- D
  2. ;
    ! p- V- o8 P' V! O% N
  3. ; Returns the status of the line A20 through the KBC 0 p, ?- ~+ E9 A8 R2 A" i
  4. ;       programming by bini for debug. 2008-07-01% |0 T4 G  ^7 ]; ~2 ~& \
  5. ; + _' |( p! c, _* W, Q3 Y/ v# x6 j6 v
  6. .model tiny
    : w6 Y- k2 u* O, M4 |! ^+ K
  7. .code
    0 V: u5 v/ }9 L5 }7 o
  8. .486
    ( e+ j5 |. {' U+ Q" ^6 P: h0 C
  9. .startup6 Q. l; |. O( P$ G0 t
  10.                 mov     dx, offset msg_fail
    - `' ~$ a9 J' z& {5 r9 ~
  11.                 call    _GET_A20_STATE_
    ) w+ ?) f" B& k+ X; @
  12.                 jz      exit1                           ;  was a problem0 I& N6 m8 x6 m2 v0 u3 }
  13.                 push    ax                              ; Save state, AH " O7 ~, N; J# S, }6 S
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem   u' f, _  L/ l" E0 }2 _! b
  15.                 mov     ah, 09h $ y* t5 m* j6 l! T
  16.                 int     21h                             ; Print message & l# _, L+ t% |* Y2 s
  17.                 pop     ax                              ; retreve state 6 m6 t+ K& D0 s: ~- ?0 O
  18. 6 t* ~2 ~3 a" ?: _& Q
  19.                 mov     dx, offset msg_dis ) ^; x: z" _% g. {% Z- c: _; h
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    : D  S# S! A. K0 v6 z
  21.                 jz      exit1
    " y" F( r' ~0 ~8 g+ \
  22.                 mov     dx, offset msg_en * q( Q# O* r9 ~+ ?. k  m& v
  23. 9 D2 {2 M+ Z% b5 y
  24. exit1:          mov     ah, 09h 1 A% I/ M& H2 D5 P" [
  25.                 ; DX already contains address of string
    & q, G" W% o/ n, @
  26.                 int     21h
    ( V3 u( M4 x# r0 d  p

  27. ! R2 U- o9 g6 l/ U( K
  28.                 mov     ax, 4C00h 5 B3 |2 I' p) n
  29.                 int     21h
    3 Q' a0 p( l8 `) f% T/ Q$ t
  30. ) I  n5 P0 ~9 Q: K  C
  31. msg_ok         db      "OK", 13, 10, "A20 $" 5 x  b* w* F0 K: [
  32. msg_fail       db      "FAIL", 13, 10, "$" 5 O- d! Y/ z( |' s. z& r& S
  33. msg_en         db      "ENABLED", 13, 10, "$"
    0 m* P& T5 T4 [# n
  34. msg_dis        db      "DISABLED", 13, 10, "$"8 m# u+ W$ \3 }8 t0 J
  35. : G" Z! c- u% B# |
  36. / o; O5 R8 X  {! P- e7 _
  37. _GET_A20_STATE_:
    4 K3 n1 t  n" t& d- y' C
  38.                 call    A20Write                ; Wait till the input register is empty 5 |/ m; S2 \" f0 {9 w2 h7 n
  39.                 jz      exit2+1                 ; Bypas the reset int's ! q1 |7 v! M  m) F
  40.                 cli                             ; Disable ints so we'll get our value # H9 J4 B; k$ x! P

  41. & k$ l% w! Q- d8 r5 n
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 4 s& J5 N# m$ H* \! i0 {: W
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port : A0 r. U6 [/ o) J' @! }4 F; L5 W
  44.                 call    A20Read                 ; Wait till the 8042 output register 3 `( c! \- D& X* k5 b5 A. l
  45.                 jz      exit2                   ; has something in it's buffer * f' A+ G  r1 r* a
  46. ; z  D6 R  S' q; {# f
  47.                 in      al, 60h                 ; Get it * g9 w  T# u5 K9 A% S( V# G
  48.                 mov     ah, al
    3 l- }* o2 ~1 s* y4 y7 z
  49.                 call    A20Write                ; Make sure the input register is empty - i8 Q* P! @7 F
  50.                 jz      exit2 % N; C, D$ i2 d. U" ?' G: P
  51. 3 ~: y1 b3 |7 C0 \: b2 K& e
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    " I, d$ R0 r# l, T4 m1 I3 y
  53.                 out     64h, al   q% U8 U( R( |" F- S
  54.                 call    A20Write
    1 \: ~) @5 r! M6 p% G

  55. 3 _. m& {: i5 W- G# S7 i) v# f
  56. exit2:          sti
      ?0 _, T$ X# t8 q# N5 |; }; E
  57.                 ret
    : k7 ^8 E: h# T9 n/ i# A

  58. 5 _1 c/ ?8 d( v, c0 Q9 n

  59. . a' t2 j" N0 z% I( o! F
  60. A20Write:       xor     cx, cx                  ; Reasonable wait * |$ c& J: l1 ]/ n& ]6 a
  61. get1:           in      al, 64h                 ; Get KBC read status 7 H: e) R, C, f* e
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear % B1 x# F, w. g) J9 @! m
  63.                 jz      clear
    " ?* o: \. F+ e8 s
  64.                 dec     cx , Z. s, u7 ]* E, G: U
  65.                 jz      exit3
    ) J/ }6 ~5 w/ s# C4 [1 @/ _3 a
  66.                 jmp     SHORT get1
    . u9 Z- a0 i8 {# y
  67. clear:          inc     al                      ; Clear ZR
      s6 w! b) `9 x6 I
  68. exit3:          ret
    0 H+ _4 a; P8 G' L0 P

  69. 9 \1 K8 O) i+ T3 R: R+ R' W
  70. 7 s4 A- {1 J' V' Z7 A4 T. P
  71. A20Read:        xor     cx, cx $ ]" x& V  L, V& e) ^( ?
  72. get2:           in      al, 64h & `* l! v2 |) G2 b( c) ^  }9 {
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    : \! R3 d% Q2 ]3 W- x. [7 I- A
  74.                 jnz     exit4                   ; something for me 2 E# M# P6 y9 E, ~8 N% x
  75.                 dec     cx
    ' M1 g1 o+ x0 z4 U: J' S
  76.                 jnz     get2
    " n; c. S- N2 p. `& S
  77. exit4:          ret     
    1 ~4 L* `1 z$ l* G$ u3 S
  78.                
    . n6 A6 J; Z7 d- |+ C- A3 H  K
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()& c$ e6 K  O5 G4 b& L  r
{        while(inp(0x64) & 2);        outp(0x64,0xd1);0 Q# p5 u8 K6 `
        while(inp(0x64) & 2);        outp(0x60,0xdf);
) O' Y$ b2 D+ i. h% H! A  {" n        while(inp(0x64) & 2);        outp(0x64,0xff);+ r/ h/ E5 F, w& g
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-29 06:01 , Processed in 0.093674 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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