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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM $ ?6 |6 f8 ]+ d7 I; }- T
  2. ; : o8 L. W$ Q( W/ v7 M& w* G. Y
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    $ B: D  A/ p  T3 u9 ^& U
  4. ;       ml A20ON.asm
    8 R' r: U' s2 a0 C
  5. ;
    5 @- E( _7 k% G8 ^' ]' l, I& n$ J
  6. .model tiny3 d4 M$ d% b6 G4 ]+ C1 y9 X
  7. .code
    0 }# T4 k9 T4 f4 ]0 F8 m  C. D6 n
  8. .486
    # j" V8 `/ m0 [" A. I
  9. .startup0 y; Y. z$ d; S+ p( g

  10. * t$ E: k6 ~8 p. u( N" q% x
  11.                 mov     dx, offset msg_author
    9 v% z7 |4 k$ n; J  \# _( D* p# J
  12.                 mov     ah, 09h
    , X! {: f  ]& ]7 c  F
  13.                 int     21h
    & E, |2 I& ?: N) _. O% Z: s3 y3 ^

  14. " k0 x7 u  P* e; \3 l4 r
  15.                 mov     dx, offset msg_fail 4 q8 Y* _% M: I# B. f2 q8 L. x
  16.                 call    A20_ENABLE' o1 G2 K3 @: z5 A4 ]
  17.                 jz      exit1
    & n9 I9 U# ^4 x/ Y7 M% X
  18.                 mov     dx, offset msg_ok 1 d( n; U" V- n/ m

  19. 3 n6 P, r; v$ Q# R3 j! O
  20. exit1:          mov     ah, 09h ' \& a! W  U) r. a
  21.                 int     21h
    . ~9 N6 B( N6 c5 t# h# X
  22.                 mov     ax, 4C00h ( u  c3 I  d" A- i
  23.                 int     21h . b1 }: i0 B: c$ g' X5 y
  24.                 ) a  w9 |2 R4 Q% C8 Q( E
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    , R- z- F5 p! U, q( E3 V' s" o
  26.                         "2008-07-01",13, 10, "$"
    ! F6 u: H; r. y' s9 t. T
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" : M' o$ N" x& ^& M
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" / U  q1 w' N; g) i6 g* L
  29. - V- f8 ?  n6 @! [2 G! z
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------8 x# ]8 D" U9 S1 Q
  31. A20_ENABLE:
    , l) k/ [% ?1 v4 G6 w* D" }
  32.                 call    A20Write 2 M( [2 j, b; j$ g$ _8 |* i
  33.                 jz      exit_enable
    + a4 d. a6 T& {5 ]5 M, m
  34. / [* L9 E1 V- h) r7 c
  35.                 cli                             ; Only need for reading value from KBC
    , A9 g  }8 p# S
  36.                 mov     al, 0D0h $ L  Q+ `6 ]$ ?; e
  37.                 out     64h, al / E" S& ?) l# L) q( C
  38.                 call    A20Read
    7 F" u! d+ _. ~8 }6 p( `& `
  39.                 jz      enable_int * w3 x* u9 ]. I* }) X. H( h

  40. $ \" P& a& D0 m% ~
  41.                 in      al, 60h                 ; Get current status
    " I* F1 I- F7 F. [1 _
  42.                 mov     ah, al
    , j5 z  o5 R/ `& t7 ]- E
  43.                 call    A20Write
    3 e6 ?) m# ~4 r5 @; d, Z
  44. enable_int:    sti 1 g7 N# Z6 B) Q! ]
  45.                 jz      exit_enable8 T7 Z1 C4 p+ c
  46. : [# h0 d) ]2 [; W
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 1 K+ A$ F/ E0 v" e' l
  48.                 out     64h, al                 ; Out Put Port next   ^" w" @4 O( e: I0 c( A
  49.                 call    A20Write / V) D9 V6 P3 n+ R
  50.                 jz      exit_enable
    ; U" p1 i, B5 a, V) W" A8 \! R

  51. % z* ]  J9 w! f
  52.                 mov     al, ah
    9 H& W) `7 ~4 x$ a, o" d% j3 A5 Z
  53.                 or      al, 2                   ; Enable line A20 / Y& }! y6 r# M0 }$ e
  54.                 out     60h, al
    4 X0 C6 ?; f; m
  55.                 call    A20Write
    - r4 h6 j) U, g3 q; P9 n4 F
  56.                 jz      exit_enable
    ' X8 y* `2 [4 w/ v8 P+ e- I

  57. ! D6 B& \7 G. e: K& h1 |7 b1 R2 L
  58.                 mov     al, 0FFh                ; NOP
    $ n# [1 a3 I* ~; a; N) _
  59.                 out     64h, al
    7 O7 S; W. u. B3 m" s
  60.                 call    A20Write
    ( I: [+ v) B  ?7 _: i/ ^3 o
  61. ; M6 X- D) J1 ]5 x
  62. exit_enable:          ret   m- f9 o% S( l: q0 q
  63. 6 R7 Q  k( A" S6 F9 O# a) K
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    " w6 a) i1 c- e* _! U7 F: M* t% F
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    2 h* O; p! m; l$ x" {& I: v/ ?4 i
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 2 t) r: ~1 q5 P/ v) h( a
  67.                 jz      clear
    ! N+ [1 t+ }8 X% n# |, h
  68.                 dec     cx 0 w7 d  }" z! D! ]8 `
  69.                 jz      exit_write
    " f3 v1 J' ?7 T
  70.                 jmp     short get_wirte
    $ U  {4 k% o' z: p  A3 M: C
  71. clear:          inc     al                      ; Clear ZR
    7 P; J" Y) s+ r( x
  72. exit_write:     ret
    5 {. \6 f1 Z- h; i  e5 u) P2 B

  73. 2 Z* d$ n1 ~' x# `: y' q+ s

  74. 6 q6 E* S1 J( X8 k! }" W& T
  75. A20Read:        xor     cx, cx , b1 y' Q2 x/ K0 M
  76. get_read:       in      al, 64h % i$ ~5 |; i" E$ H1 g! o
  77.                 test    al, 01                  ; If the 'output buffer' is full, has # n! d0 w  V" E8 {
  78.                 jnz     exit4                   ; ... 5 ?& [1 D( O2 s& g4 d8 {
  79.                 dec     cx
    9 \. j8 ~7 z7 S/ B; W& I% {: {* }
  80.                 jnz     get_read
    ; s. q' D3 V# D* L. Y% ]
  81. exit4:          ret     
    1 P( u, Q! Z- @. n. ]7 `& t8 }) p
  82.                
    * L& J4 D! J+ J6 f' d
  83. end
复制代码
  1. ;A200FF.ASM # Z( r7 D) C, O7 j/ X% j
  2. ; 7 l% C* X' p% X( g) }
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    % X$ _9 c  R5 @5 h# k
  4. ;       ml A20ON.asm
    0 w, ^6 X5 w6 j+ r1 g# k
  5. ;
    2 \3 C1 C. J1 i. w( A
  6. .model tiny9 M% P* Z' X. T/ T4 J/ r6 A0 F" h
  7. .code
    ' s- |+ w! ]9 r7 G* e( D7 M
  8. .486
    # n6 K, Y' D' t' `5 K3 E  {
  9. .startup$ a4 |, J5 I+ D$ D& F3 O

  10. 6 w' ]  C8 c* n+ C- q9 i
  11.                 mov     dx, offset msg_author
    7 ~8 k3 g( a, Q8 K- p
  12.                 mov     ah, 09h
    6 p6 h; f: ^6 x
  13.                 int     21h
    , H: C( F6 P" e' w0 \

  14. ; f) g( ]! G8 J4 e# Z+ ?% H
  15.                 mov     dx, offset msg_fail
    1 K7 s" H! p0 A
  16.                 call    A20_DISABLE+ T+ h7 V. S  u$ l; X% K" G
  17.                 jz      exit1" z5 q, j% O( E5 ^( P- O+ D0 r+ u
  18.                 mov     dx, offset msg_ok " o( v; x% N2 R

  19. / W. }- J8 G, n
  20. exit1:          mov     ah, 09h
    3 a6 t0 U  @9 m: i+ B
  21.                 int     21h
    ; P2 S6 C. ?* ]& _9 @7 G
  22.                 mov     ax, 4C00h $ F3 k$ U- j/ M- O5 e6 H
  23.                 int     21h ' D' z1 a3 n! n
  24.                
    % T& E0 D' t1 ?9 A2 X) \
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    8 Y" c4 i! G% V% Y
  26.                         "2008-07-01",13, 10, "$" " ?8 z4 U( T: b6 n
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" 5 h% F% e, ?, i% E
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    2 B) Y4 E) e5 |
  29. ' Y/ W6 \4 q8 K5 T, L7 o$ V" k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------' A" _- t: X, A$ S6 d0 m
  31. A20_DISABLE: - V9 t9 {" R) k& ?  O
  32.                 call    A20Write # @3 S5 ?. T  [! o. t
  33.                 jz      exit_disable
    $ J. r" g0 A. ]3 d/ o2 U+ z

  34. & ]* K# O# ~" N. }6 S% ?% m
  35.                 cli                             ; Only need for reading value from KBC
    - t, j6 |& G* `7 D  m3 j
  36.                 mov     al, 0D0h
    ! |' M" a& q* U( \! C8 L7 k
  37.                 out     64h, al $ G' u! L/ G. G' N4 g
  38.                 call    A20Read
    4 g+ E* P) l  k2 O# ^7 ~
  39.                 jz      Disable_int
    , e! ~2 _2 C2 `  k, S
  40. & G( M  h! K+ }% j0 R5 Q* v
  41.                 in      al, 60h                 ; Get current status
    0 O1 M4 b+ E0 Q
  42.                 mov     ah, al 6 o' {& B  {/ s. I+ l
  43.                 call    A20Write
    8 M, i* v( U( T9 |$ U0 A
  44. Disable_int:    sti 4 Z4 K4 G: G$ O; M0 E- V
  45.                 jz      exit_disable7 d7 X: O" E, `1 N: o

  46. ' S! R0 Q3 A  N1 i3 P7 w1 z8 l
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    + N6 P- M- l3 _) r7 Y7 }' I
  48.                 out     64h, al                 ; Out Put Port next 1 [1 B* S. e* s; {0 w/ S
  49.                 call    A20Write
    * O9 z( V& v; E; B
  50.                 jz      exit_disable/ s. d! `' B4 G0 `0 p
  51. : J. M) l5 |6 j6 X  b6 r% G
  52.                 mov     al, ah
    - y$ r4 \' U9 P' g/ {
  53.                 and     al, not 2               ; Disable line A20 ; e- J' R( M$ V% P) b- V
  54.                 out     60h, al
    " Z- U/ ~( v& Z- ~# g; \
  55.                 call    A20Write
    3 l/ Z: m0 n8 h1 e  |/ ^. q
  56.                 jz      exit_disable% @) ^% L) H% G- G( m

  57. , z4 E( Y8 ^  P. n: W# C7 k) [7 R
  58.                 mov     al, 0FFh                ; NOP
    ' [0 r0 E, @" |- P+ C+ L7 S
  59.                 out     64h, al
    / N! g0 s! d, C+ V( N
  60.                 call    A20Write   W6 k: }, s: P6 A$ F

  61. / r  D" T" \% b
  62. exit_disable:          ret $ t5 K4 v7 t- p
  63. 0 n8 F7 ~' {0 f
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    , i! z; M: u6 i  d% y7 F6 I; r
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 3 A+ r3 z9 I( n' y8 h
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 5 G% B6 S( g( V
  67.                 jz      clear
    , v) n* j! ?6 B: R
  68.                 dec     cx / y! K# v1 Z* x  y1 @4 j- i
  69.                 jz      exit_write 2 @" z( M1 o) f, S$ i7 \
  70.                 jmp     short get_wirte 0 \1 B, G1 e2 h) \; c- B; L& {
  71. clear:          inc     al                      ; Clear ZR
    % l' V1 f( }: t! a  w0 |
  72. exit_write:     ret
    1 a) W) W) r! i. u$ c+ G# g

  73. / w5 c6 l* ^* H: o3 @' v6 I* q  x

  74. ' q/ N$ e' H7 l- w, ]6 ~
  75. A20Read:        xor     cx, cx
    ! B/ M( `$ E5 s; r5 p, `5 Z( H& S
  76. get_read:       in      al, 64h
    % J4 Z: D' X. E0 S' \  J1 K1 ^; D! P
  77.                 test    al, 01                  ; If the 'output buffer' is full, has   M0 H# n+ x: D. k& M
  78.                 jnz     exit4                   ; ... 3 l* r$ \& R* H5 C- g: y
  79.                 dec     cx - d% i" q6 Z( ?- R7 k- G
  80.                 jnz     get_read
    " r9 Q. z% y1 d" J2 K
  81. exit4:          ret     ; S, d9 @! s. ?
  82.                 8 _7 s, [1 E, g, g1 N, Y* W0 ~0 I
  83. end
复制代码
  1. ;A20STATE.ASM
    / V# F' v5 v5 @3 `5 v8 _# Q1 q
  2. ; * J9 s/ q1 T- ^' P
  3. ; Returns the status of the line A20 through the KBC
    ( b7 [/ {# I) M- l: M
  4. ;       programming by bini for debug. 2008-07-01: k( x. {) O+ v
  5. ; ( a: ~* t  v6 q6 J/ Q
  6. .model tiny
    ) U% B3 v! [4 p. r- h# \. ]! n8 q$ k
  7. .code
    ( n! ]' N8 s0 x) ^
  8. .486
    & q( n* v  b' F: z
  9. .startup
    / c% \% U  x! K: ~" q
  10.                 mov     dx, offset msg_fail % u* G5 ]. W+ Q
  11.                 call    _GET_A20_STATE_
    : s0 z# t1 B+ K( `2 m( e# q
  12.                 jz      exit1                           ;  was a problem
    4 C8 |2 t( S' `/ F2 ]4 }9 N
  13.                 push    ax                              ; Save state, AH - h" |5 I$ {# r+ g4 }, f6 F- G% y
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    6 V9 m+ t% c0 j; _4 X; ]* @% L
  15.                 mov     ah, 09h
    # g$ T( G0 V4 G( g  H- R, c/ s
  16.                 int     21h                             ; Print message
    - h' c# W7 n7 u* O& y% K* Z. e3 T
  17.                 pop     ax                              ; retreve state
    ) V  c$ q. O$ R7 i

  18. % V9 P/ u; n) K( Q9 k4 h
  19.                 mov     dx, offset msg_dis
    4 P1 j- E! _6 b3 x) Y& `/ j6 J9 a
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    6 u# |' S0 F$ o# \/ u9 a* K5 j
  21.                 jz      exit1
    8 Y: Z) E& m% b: @* T
  22.                 mov     dx, offset msg_en
    , y  _; d' n5 M3 N- W2 C6 b9 E

  23. 2 |4 Q8 |' m( j: I' c; W3 M
  24. exit1:          mov     ah, 09h 9 o7 p+ X8 \3 g; q) L# |  K
  25.                 ; DX already contains address of string
    $ z  V8 n) ~' P( A1 H1 z
  26.                 int     21h
    ; ?5 L1 E6 ]2 z) G6 s8 ?
  27. ' a0 R- j' E5 r, K1 [7 O
  28.                 mov     ax, 4C00h
      V6 {2 L- e5 L5 n
  29.                 int     21h
    ; D: Q/ x( z. k1 @

  30. 9 U8 p3 q* m: B% ?6 C) f9 D" U7 j- F
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    + V4 j* I! w4 ~% N$ D
  32. msg_fail       db      "FAIL", 13, 10, "$" 1 b! s, l; b* d( G
  33. msg_en         db      "ENABLED", 13, 10, "$"
    8 L  Y+ [/ l' a: j. u8 f9 [4 n* E4 H
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    ! b/ ^" H5 D3 z& q) X
  35. 1 S& x+ x# S4 Y) S- o9 i
  36. 9 X/ K/ l1 k9 J% L- P
  37. _GET_A20_STATE_: * I0 V. A2 J9 O( l1 \* M1 n
  38.                 call    A20Write                ; Wait till the input register is empty
    1 c/ [/ w# M2 B8 @. u) T+ f
  39.                 jz      exit2+1                 ; Bypas the reset int's 7 Z% _8 Q& U$ n* ~) f$ c4 R
  40.                 cli                             ; Disable ints so we'll get our value 8 ^1 f3 n0 U' O* ^% v3 n0 n( w% d1 i
  41. 2 L# N' {% Z+ F# o+ j/ V
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    * ?2 Z( Y, q4 W: j8 m: J0 t! w: f) f
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port + G9 W/ ~& W5 u0 t- |9 n8 i; A
  44.                 call    A20Read                 ; Wait till the 8042 output register
      Z2 y* n. a0 E& ~1 V
  45.                 jz      exit2                   ; has something in it's buffer
    8 L- R" q/ f9 @. S7 [0 [& w

  46. / ^8 g( H' N; d, V4 e
  47.                 in      al, 60h                 ; Get it % E- U" W$ w$ J/ `7 z/ Q
  48.                 mov     ah, al   v* t9 z; F3 |+ S% F
  49.                 call    A20Write                ; Make sure the input register is empty
    4 ~/ F8 J0 j: ~, \3 l5 G: x6 \
  50.                 jz      exit2
    * v% h( c4 J# g4 \1 P5 e

  51. ) U* [" y9 u0 W, m& j
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    0 Y7 c+ A: v5 t! X
  53.                 out     64h, al
    & Q4 d$ S* A1 z/ i4 g% Z
  54.                 call    A20Write
    $ t& B" y$ K# k" g( F
  55. % O4 i3 f5 _; ?1 M, H% O
  56. exit2:          sti
    6 H+ z$ m* D. X+ p- d1 F
  57.                 ret) M4 K$ Q) A6 l* }9 P- x9 O

  58. " @% x9 Z- x; \# m6 x- ~

  59. - r7 d* Z8 l4 w) c" n
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    $ i: i3 [& H+ M. Q: _
  61. get1:           in      al, 64h                 ; Get KBC read status % S# \; `. v3 }& l
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear % l; @7 y( V( V% W- l7 Q
  63.                 jz      clear 6 z2 K3 @  \* I! V) k
  64.                 dec     cx 2 Z+ U, V3 B! i, q4 S( {; Y
  65.                 jz      exit3 , ]& Y+ c* k6 L6 O. u/ V# x
  66.                 jmp     SHORT get1
    0 |# }+ k& B9 B0 R
  67. clear:          inc     al                      ; Clear ZR
    & a% g, B4 g7 F& C$ S3 Q% l, n/ B
  68. exit3:          ret
    2 n- U# {3 f1 q( [3 C, ^
  69. : t  r. D8 b9 R' L
  70. . @( ]4 H: r  g& E
  71. A20Read:        xor     cx, cx
    - f3 g" G- F; w$ e6 @* r: z" ]6 {$ ~
  72. get2:           in      al, 64h ! }0 N8 q4 v- j  c% |6 L8 W
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    & Q5 c: W8 i$ d; q+ I; r+ f7 b
  74.                 jnz     exit4                   ; something for me ; n, |9 Q! n8 s! M1 b0 y0 ]  G
  75.                 dec     cx
    ' f0 Q, R2 ]% Z7 r
  76.                 jnz     get2. g. c5 ^, y3 F+ A2 x* B
  77. exit4:          ret     * n) o# V- t9 l" d
  78.                 5 M( S' s" q& s$ O5 z, I/ a4 k2 L! x
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
8 d7 T$ I. I! e' ]{        while(inp(0x64) & 2);        outp(0x64,0xd1);  V6 i  _5 ]- I- }! T) S; Q9 s' V6 I; \
        while(inp(0x64) & 2);        outp(0x60,0xdf);7 m4 I& G/ x5 j
        while(inp(0x64) & 2);        outp(0x64,0xff);3 z1 w: U$ x, _, t! J- i
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-29 04:20 , Processed in 1.325618 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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