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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    6 h% ?3 F1 J# e  a7 y$ z+ B
  2. ; 6 @; Z9 ?1 ?* W4 w# a% V
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ! W! _/ r! A6 ^: a
  4. ;       ml A20ON.asm
    ! i) f$ b, u. b* F2 s+ e
  5. ; $ q3 h3 M$ N$ C- _4 Y* [- r
  6. .model tiny+ K  N3 e$ p  k8 P8 H
  7. .code3 B* ^2 ?6 c" `4 f/ M1 A
  8. .486
    : y/ x& S' d/ K; E
  9. .startup* L: z7 l$ r- b0 n: Z* Y9 N
  10. 9 Z3 ~- \" Y2 f9 H: c7 Z' y
  11.                 mov     dx, offset msg_author
    ; {( ?$ K+ @. v+ e' A+ \
  12.                 mov     ah, 09h. A2 v' _" z$ l& @9 ~
  13.                 int     21h0 |: K$ N# k1 x! A

  14. 5 @1 ?5 h, N/ c. W" d& f0 Q
  15.                 mov     dx, offset msg_fail
    / a( x* T' V* v/ y* M! u
  16.                 call    A20_ENABLE8 j& Z2 l' G0 H1 D  f. z
  17.                 jz      exit1
    1 X9 P- |! D7 I  y9 ^: y& L4 v5 Y" c
  18.                 mov     dx, offset msg_ok 9 S+ V2 n1 y6 H+ M7 L/ G) m* F

  19. 9 d5 y4 Z' X2 c6 U1 u" \9 O  L/ h
  20. exit1:          mov     ah, 09h # e6 d  Z5 E9 \/ c( P- w
  21.                 int     21h 5 q! v& J' H$ Z5 w
  22.                 mov     ax, 4C00h - L8 j# \' Z1 k& ?- s
  23.                 int     21h ! N. e! g3 V8 n
  24.                
    : m: s7 D6 G( ^, L' ]9 e7 Q
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    + ~2 P/ N' M8 d. X9 z- E& M
  26.                         "2008-07-01",13, 10, "$"
    : J8 T( @4 F  r9 S( g
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    / a6 X* ^. y6 s- V& e
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    * b3 @1 j) y: h8 Q+ K$ M$ k5 k
  29. 1 _8 @4 q8 |2 X0 o3 x& V
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------# D& r. |" j. m% k6 Q! l& F& e' h
  31. A20_ENABLE: ! I  i6 X4 ~: z8 X0 y6 ~
  32.                 call    A20Write
    * E9 v: U6 Y, v1 a
  33.                 jz      exit_enable4 u& z6 i0 j/ O- S- t& @

  34. ' E. x, [2 i% S/ N! B; x
  35.                 cli                             ; Only need for reading value from KBC , q+ @# g4 P; L* Y7 o" i. X5 i
  36.                 mov     al, 0D0h % K/ T" ~2 {* m2 d' O2 c
  37.                 out     64h, al 6 I+ V% f9 A! u' N" N* I
  38.                 call    A20Read
    % W& O% z/ h! E; u" N- |
  39.                 jz      enable_int ' T) o+ y  q) J' k" E. A

  40. ; I1 U% G' G. z7 |- W/ v  {7 t
  41.                 in      al, 60h                 ; Get current status
    6 G# d0 m& ?+ i: Y) @- ~
  42.                 mov     ah, al ! t4 N0 g& C9 C- @! d; c& T
  43.                 call    A20Write ' I! Z0 S' u) u+ A
  44. enable_int:    sti / R& X+ V% c) X% U2 t0 ]6 g: B0 x6 I( C
  45.                 jz      exit_enable' h( g5 M" s% s  ^1 l
  46. . |5 Q5 Q6 m* p0 k9 I7 ^& g" y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the * U  V" |/ K) L5 N, P
  48.                 out     64h, al                 ; Out Put Port next
    : ^  o" l' ~6 s2 ^( L1 M2 G! s
  49.                 call    A20Write * d, ?: j4 ~! d+ f0 `0 c
  50.                 jz      exit_enable
    - o# e2 p, M9 b& Q

  51. ' u2 v& _) @0 ~5 t  I+ z1 M
  52.                 mov     al, ah , F- o5 T$ q  m! K) q
  53.                 or      al, 2                   ; Enable line A20 - t" a; O. i/ H% v( e1 [
  54.                 out     60h, al $ a$ q8 T+ }; J  u; ]
  55.                 call    A20Write
    0 T3 t0 U. K$ V7 |  q$ l
  56.                 jz      exit_enable
    6 h3 F0 j2 D! P# ~, o+ {

  57. , ]& }/ s% U, C& \& ^5 m+ _. U8 x
  58.                 mov     al, 0FFh                ; NOP , F( C9 \; F0 B" Z; K# Q
  59.                 out     64h, al , k8 s. B# z. v' {
  60.                 call    A20Write , s$ {8 k- D6 r" h
  61. / A1 k$ ?. Q7 E
  62. exit_enable:          ret
    * e& h: v, |' d1 p2 f2 x3 u

  63. $ S- Z! i( s+ [& m
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - Y' q5 E# D% S: u
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ; o/ T% }9 l  `: A) r/ }% v; K
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ; ^+ M# l- L: ~4 T  s
  67.                 jz      clear ) A- M! q* y) K$ m
  68.                 dec     cx 7 l" R% ]8 ]" N( Z4 B- a
  69.                 jz      exit_write
      H$ m3 G) \; R4 A6 c; i$ a
  70.                 jmp     short get_wirte
    - C4 J9 j. M$ D( w- X9 Y& F+ Q9 G
  71. clear:          inc     al                      ; Clear ZR / d9 q" x% E* j. h" Q
  72. exit_write:     ret # J8 l/ W+ U# p4 }4 o
  73. ( v0 B9 N* X- ~: ?6 f& y

  74. . e* n1 L( ~' q( {& i- B) s. _3 P
  75. A20Read:        xor     cx, cx
    - A% f+ l4 o0 _9 D  X0 z( t1 X
  76. get_read:       in      al, 64h 8 r8 o3 y$ l1 H, A# n& o+ y
  77.                 test    al, 01                  ; If the 'output buffer' is full, has " S  P0 E0 c) h4 R  o  A+ l
  78.                 jnz     exit4                   ; ...
    0 Y; L- r! H* s* y7 O
  79.                 dec     cx
    ' b1 ~3 I* I; p' c. j5 U! j7 K
  80.                 jnz     get_read/ [  Y9 c, l4 j- d3 x% M3 q
  81. exit4:          ret     7 v) G0 Y6 K2 _
  82.                   E/ _( g' g& W% \7 Z# ~
  83. end
复制代码
  1. ;A200FF.ASM " `8 j5 g* V3 p& Y
  2. ;
    " u; X0 X  U  V4 Q. D3 n1 E
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    $ v- }$ f- q# X- q/ c) u# D
  4. ;       ml A20ON.asm
    : U8 C! D5 |; W2 z& V
  5. ; ' A2 l- g' x5 T, j, `3 e( Y
  6. .model tiny: B0 y3 }: f7 D& X6 j
  7. .code: @' @+ n$ I0 B" ], M& t9 ^6 }8 L
  8. .486- h4 f7 V/ l. ]& g) Z
  9. .startup
    9 m4 [+ W( T- Z! j: H
  10. $ D8 F! T: G7 D3 q
  11.                 mov     dx, offset msg_author
    ! g8 ?/ I6 v- ?5 Y7 \
  12.                 mov     ah, 09h
    4 v) H0 L) F7 a9 D- }
  13.                 int     21h) {/ N3 m+ V) Y  j+ ^- r5 q

  14. - z# y$ _' ]! a. Y. ]  S
  15.                 mov     dx, offset msg_fail
    4 `. w# |/ C1 {( A0 G
  16.                 call    A20_DISABLE3 V5 ~. J8 d( G  ]
  17.                 jz      exit1
    , _  M, V9 ^5 ?- y0 g
  18.                 mov     dx, offset msg_ok
    & i* e5 ]5 d4 G1 q
  19. 9 S% f) }2 c) t1 r# ?
  20. exit1:          mov     ah, 09h # J% z& T! o  g5 i- p  y
  21.                 int     21h 9 \: e, x( q& y: j( j, `  A
  22.                 mov     ax, 4C00h
    * j0 X: I% r. z
  23.                 int     21h
    ) b  k/ d* n, l
  24.                
    3 A4 W! o; x( ^8 p- y8 Z! i
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,4 ^3 G: |; k; r/ ^2 v
  26.                         "2008-07-01",13, 10, "$"
    ' q( b: X0 z/ Z' H  H
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" 1 e4 Q3 T) L* D! B
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    # _' z" j8 I9 h, Q" M  t

  29. 0 v  L! d  ?* ]' {* C1 B' R
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------. V' i. I! [& X1 m
  31. A20_DISABLE: % ], V. n0 Z3 f0 _$ I: i( r: q# u
  32.                 call    A20Write
    # g- f% @) N0 \& m5 b
  33.                 jz      exit_disable0 l1 {5 M! B; D2 I9 S
  34. - i$ {/ _5 d6 ], \- L4 t
  35.                 cli                             ; Only need for reading value from KBC
    / h9 D. {& `% B  |" V0 x" {
  36.                 mov     al, 0D0h
    4 `" `. G) s2 E8 K: D: T
  37.                 out     64h, al
    2 r) L; n) A5 z- n6 D/ D
  38.                 call    A20Read & Q; D$ z2 [7 t, n
  39.                 jz      Disable_int 6 ~+ E" W) d$ |( ~' U  p, ]

  40. $ \2 P! L* M0 r* {
  41.                 in      al, 60h                 ; Get current status . I0 Y1 Q, e: a2 ~$ F) i0 Y* M6 f4 a) L
  42.                 mov     ah, al
    # d8 _9 [3 w' q, U
  43.                 call    A20Write 7 v  n3 D4 A  S. `7 @  }7 E
  44. Disable_int:    sti * M! T& \+ u; b9 {: @8 x4 V
  45.                 jz      exit_disable
    ) [; h9 R* x1 T( H9 e
  46.   H" l; n8 D8 e2 ~
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ' r5 t& [4 P' n8 [- ?
  48.                 out     64h, al                 ; Out Put Port next   B4 l4 \( g) N) L( I% b
  49.                 call    A20Write 0 r. I3 M: l5 P% p9 C" ^0 }
  50.                 jz      exit_disable6 |, {6 Z7 |5 u0 `6 B- _

  51. " a  H; Q( I. P4 B' h) M' u9 x
  52.                 mov     al, ah
    ' U8 M6 K1 j" p8 ~  ?
  53.                 and     al, not 2               ; Disable line A20 & k. z4 @$ U& _
  54.                 out     60h, al ! V" y* n  [) S. t* y* ^3 Z
  55.                 call    A20Write 6 }0 `7 d1 n) S0 M+ r" }0 P
  56.                 jz      exit_disable  I6 W& @7 e" W6 u
  57. $ j- j% m3 ^: _% K1 j0 l
  58.                 mov     al, 0FFh                ; NOP
    % R% o' W# v# ?( G; b5 y
  59.                 out     64h, al
    # X. Y$ H5 g; [/ ^  g$ B
  60.                 call    A20Write
    ; l0 P3 S9 B4 W, A! r: ^  \+ S3 k
  61. % l4 f2 r" g& D! S0 w+ n$ z  `4 s
  62. exit_disable:          ret
    0 p& }' K' x4 q6 h$ y  W$ j2 ]& U0 |
  63. 6 Z2 A0 e1 C9 ~
  64. A20Write:       xor     cx, cx                  ; Reasonable wait - E5 x( b0 h. Y3 \& q: H
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    8 ^- w7 L# ^3 W7 i
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 4 J+ t  ], N) G- Y5 C, f+ q$ ]- S
  67.                 jz      clear
    9 U3 g$ M- o5 k# g) {
  68.                 dec     cx . D$ b3 Q/ C1 f
  69.                 jz      exit_write
    1 m# p; n% T/ H* `6 T
  70.                 jmp     short get_wirte 9 |% _+ e* e9 H1 Q5 q/ q
  71. clear:          inc     al                      ; Clear ZR 3 t. ?: e& o* T4 t0 [, n
  72. exit_write:     ret - w* G# @3 P) q! d* v2 y" X) K

  73. & m* H. P+ U" }4 b" B, y

  74. ' s! f0 j8 \. V& }9 [
  75. A20Read:        xor     cx, cx / M# C( G5 D9 h2 ^
  76. get_read:       in      al, 64h
    / S- g: {  K  a! V1 {
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( Q; M9 L7 v2 @" ]0 K+ L( b
  78.                 jnz     exit4                   ; ...
      Z% {8 w& I6 ~2 i* L
  79.                 dec     cx # R3 m  T+ l; A: \4 r+ t$ p
  80.                 jnz     get_read
    1 U) A6 D; M2 c! z* l* k) \
  81. exit4:          ret     4 u( X6 l$ a% @3 t( K
  82.                
    - D" a  X0 V* i" c, \
  83. end
复制代码
  1. ;A20STATE.ASM " @9 u# N$ b6 L
  2. ; 9 ^3 m0 O* z4 d" |2 q
  3. ; Returns the status of the line A20 through the KBC % c1 C1 q) v5 O6 O& O
  4. ;       programming by bini for debug. 2008-07-01
    3 x- t* C( _2 L' g) Y7 U  Y
  5. ;
    & S: d' y, f8 q3 N3 m
  6. .model tiny
    " y7 M' Z; B% U& ~8 R
  7. .code* B! J. a  Q/ W
  8. .486. u0 ]* U) [. ^$ B% Q, d( j: }
  9. .startup
      f0 [6 f; _$ R! K' h) {4 _
  10.                 mov     dx, offset msg_fail
    , l6 k7 I2 I" R6 }# n7 r! G2 w
  11.                 call    _GET_A20_STATE_5 d7 H4 D2 t7 r& G# l2 o! @
  12.                 jz      exit1                           ;  was a problem. d2 d" Y1 }: u" r
  13.                 push    ax                              ; Save state, AH
    6 N) n) ~. S* ~9 ^3 r1 Y
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    0 L& H' \8 N$ i( p3 T
  15.                 mov     ah, 09h
    % r' `5 I8 w# m* Q) O5 G8 k# F- B
  16.                 int     21h                             ; Print message
    0 i: [4 D( M5 ], ]7 R4 v% B3 a
  17.                 pop     ax                              ; retreve state
    % Z. J+ u# }) x0 a3 X2 T

  18. " A  q, k; ~4 F) ]8 n3 y0 j5 D
  19.                 mov     dx, offset msg_dis
    ) [. C$ ~, a/ Q1 Z0 N) s
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 5 j- K# ?2 m* b7 p6 y# ]* S, ?
  21.                 jz      exit1
    & H7 Y$ V. t6 T
  22.                 mov     dx, offset msg_en 6 k1 S( t* D- @# F

  23. - M4 S2 J+ v2 d' J! o- g. K
  24. exit1:          mov     ah, 09h
    , c$ f& S) o% u  M; {0 ^* m/ i8 a
  25.                 ; DX already contains address of string
    3 U& g/ I: p- q$ ]
  26.                 int     21h
    " C0 [! \6 b9 }" k$ h8 C& V$ r
  27. - N7 V4 \+ L3 D( t( x
  28.                 mov     ax, 4C00h 2 p4 K3 R5 a+ w# D% O+ _; o
  29.                 int     21h
    ; h6 \0 }' K) l! i* A/ C- D
  30. $ `$ u1 V5 d- a% U  b9 H2 O
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    % d8 N+ v1 U8 u+ E' V
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ( x7 H! a8 u4 q& q, N7 q
  33. msg_en         db      "ENABLED", 13, 10, "$" * Z& T4 u/ B% B% w% M4 x$ U
  34. msg_dis        db      "DISABLED", 13, 10, "$"- ]7 K. [1 ?! j5 E& m
  35. 1 t& m8 w& ~$ K, f

  36. " Q2 B) l, j- R3 g: |9 M: F0 X
  37. _GET_A20_STATE_:   k& L$ B" |" x
  38.                 call    A20Write                ; Wait till the input register is empty % Q: ^: _5 B2 [4 ], z
  39.                 jz      exit2+1                 ; Bypas the reset int's
    : y4 n) o% C; b, ~
  40.                 cli                             ; Disable ints so we'll get our value : r5 r2 j, d1 S

  41. 9 {" d/ d; n5 A4 o+ b
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    9 D. C; A  v8 |% J! |
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    2 W7 v! b6 b3 s+ x( Z" v3 `, L
  44.                 call    A20Read                 ; Wait till the 8042 output register ' k1 ]+ E+ ^6 k6 N- f
  45.                 jz      exit2                   ; has something in it's buffer
    ! [% `  \# ~" O8 P& @& _7 U
  46. ' x4 j+ H+ Q$ W' j$ Z& e  a! t. n
  47.                 in      al, 60h                 ; Get it 1 t( v7 D* k4 X+ R) ?
  48.                 mov     ah, al
    ; e  t  M$ p4 T6 ?1 x
  49.                 call    A20Write                ; Make sure the input register is empty   }0 ?0 @! t* |. c4 y0 C
  50.                 jz      exit2 - V, n% w. b1 h3 T, G) x1 y/ {7 X

  51. % P* U# y. ~; P! S) T" u( U- c
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    ; u! z4 G  l: Z0 E
  53.                 out     64h, al . u5 t3 g; c+ J
  54.                 call    A20Write 9 f& @4 |. [0 G

  55. 8 _, H4 T7 Y0 W1 L/ M3 [# r
  56. exit2:          sti
    # s' ]  I* N+ `9 E
  57.                 ret
    7 F0 b$ N: h  o+ G  z

  58. 5 Y' m% k$ x7 Y. D1 P3 q8 J

  59. ( V- C) {. L0 b" |9 G
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 l! N! y; t7 d, m, N1 F& o9 _
  61. get1:           in      al, 64h                 ; Get KBC read status 8 G; R# y* C* t# \# [
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    $ k- ^+ Q% v, {3 C& R
  63.                 jz      clear
    4 ?. N/ f& J- x- e5 s
  64.                 dec     cx 9 w1 c% Q) M) v  U0 z5 U
  65.                 jz      exit3
    3 ]7 b0 V, ^8 I/ ?6 {- j
  66.                 jmp     SHORT get1
    5 \8 j. ]* {; g& p9 P1 a( A% X
  67. clear:          inc     al                      ; Clear ZR " s; j+ y, H( }- d6 D7 J( ^
  68. exit3:          ret ' F- d8 w; ~# [/ \
  69. $ B. ]) X* X0 g9 O; `
  70. , q2 n2 z/ `8 j. ]: N5 ]" p% B
  71. A20Read:        xor     cx, cx $ m3 C. ^4 w" S" }
  72. get2:           in      al, 64h & V) ^# E4 u! |$ S9 z6 E, R' {
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    / G! W' ~% H8 U  {: }
  74.                 jnz     exit4                   ; something for me 6 R& h1 N7 y/ z" X
  75.                 dec     cx : Y+ ?2 \% i2 W. A7 h+ b
  76.                 jnz     get2- ?0 m2 f) E5 J
  77. exit4:          ret     
    ! a0 y' o/ ^& ?& j- ?+ J
  78.                
    0 ?1 g: a& L# ?
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
# ?# f6 E7 r& j, L# r2 }" @{        while(inp(0x64) & 2);        outp(0x64,0xd1);/ V+ A- p* z/ ^6 w& f8 n
        while(inp(0x64) & 2);        outp(0x60,0xdf);# D' g# R0 [& k, q" P- I. e
        while(inp(0x64) & 2);        outp(0x64,0xff);
! g5 G+ F* \' l}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-19 06:35 , Processed in 0.025344 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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