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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 4 p6 N" B7 E, r6 q& S- n
  2. ;
    ' S1 |% ~8 A: G9 T4 Z
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    9 ~. z8 Q! s! q% S$ a) T; _$ I* G
  4. ;       ml A20ON.asm
    9 h9 j& U0 F) [1 W
  5. ; ) m  x" ]1 `7 m, K: D+ p; K
  6. .model tiny
    * u" c( h! n' M6 \8 h
  7. .code, S$ ?6 v; A* z( M) m7 U$ @7 @7 S* [
  8. .486
    ! O# |0 K% i1 o
  9. .startup3 O/ c% ?" O2 P/ Y  P) p5 [

  10. 5 x1 q; u- e' D3 q
  11.                 mov     dx, offset msg_author
    . ^, X& A5 j6 B
  12.                 mov     ah, 09h& H8 R9 ?4 j3 `) s1 }4 ^
  13.                 int     21h% e  q$ \, j/ ]) `

  14. . U, @: t6 X$ ]) O
  15.                 mov     dx, offset msg_fail
    # B, U5 K, `$ K. X/ F
  16.                 call    A20_ENABLE- R; R% B+ |) Y: [9 M/ A% L  B
  17.                 jz      exit1
    7 H! j- b0 z- k) Q( f
  18.                 mov     dx, offset msg_ok
    ) k! l4 g- W2 K* b9 @# @
  19. # K; e1 f9 J' b( F* h8 L8 d
  20. exit1:          mov     ah, 09h 2 Y+ q. H% G4 a2 n
  21.                 int     21h 7 S7 E( B* U: g2 v
  22.                 mov     ax, 4C00h ! D, n2 f! u# t; k% ^
  23.                 int     21h
    ; U4 _( V! m4 {* d9 s# {) Y, w+ z
  24.                 3 w- q4 e; g+ K$ P, L/ r
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    : ]4 G/ b- d; Z8 Z+ e7 f" ^
  26.                         "2008-07-01",13, 10, "$" ) d6 F! P! O; v! j# g
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    . w; W5 M2 v- v( ~0 W
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" ) A7 _7 a- X) A
  29. " u" @; u1 b& J, z7 Y* P5 h  g
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------0 y& O$ ^! p9 m9 e  @
  31. A20_ENABLE:   H( P! F, A- ]& O- M
  32.                 call    A20Write 2 F: n3 m3 k5 r3 m; E0 j3 h5 f/ H
  33.                 jz      exit_enable
    $ c$ q! I' B* b  ]

  34. 2 P9 x' @. ]9 g1 e/ [
  35.                 cli                             ; Only need for reading value from KBC ; t5 j, F3 B9 y9 ?
  36.                 mov     al, 0D0h 4 j6 z" q- }2 Y: N1 _9 p
  37.                 out     64h, al
    # U  v( _6 V( O
  38.                 call    A20Read 0 L5 O3 _) S# P7 X$ e& J
  39.                 jz      enable_int
    + J7 |: Q  N  D' Y# {) n% f5 F3 G
  40. # D' Z0 m$ ~! P; t/ q1 B; I& y
  41.                 in      al, 60h                 ; Get current status " T& b+ U, n6 Q/ B/ f
  42.                 mov     ah, al " r* o  _/ B3 k4 ~9 D4 _; R
  43.                 call    A20Write
    5 l7 l, ]& N) f6 }7 @
  44. enable_int:    sti % ^* P, v9 A% Z, W; {# I
  45.                 jz      exit_enable
      s1 c9 ]- e5 z

  46. * b0 r& e9 o- o+ z
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ( K9 m: o$ Z& \6 _
  48.                 out     64h, al                 ; Out Put Port next
    / S( x& J9 E, y5 P4 y5 \+ s
  49.                 call    A20Write
    # i5 ^1 @' s% y. B9 Y' L' W
  50.                 jz      exit_enable- e' e4 Y: Q) l( T
  51. 6 Q: V. a# ~: l' h( ]7 j
  52.                 mov     al, ah
    + O  _. _. h/ `8 v* j$ z
  53.                 or      al, 2                   ; Enable line A20 5 D$ e, d& e" m+ U, ?3 W8 u
  54.                 out     60h, al 3 H8 ^( f' s9 }% N( |
  55.                 call    A20Write # `( N( A" }& K2 J) b, V
  56.                 jz      exit_enable5 s+ j" {# B( n$ V* v2 m

  57. 4 N) p) }' B6 _0 {. r* h, W3 X# p
  58.                 mov     al, 0FFh                ; NOP
    9 e; F  F3 K; J4 r( q* d9 E
  59.                 out     64h, al
    0 f: d  f7 Z1 M. ?+ ?6 q$ f
  60.                 call    A20Write
    ' U# e9 h6 w7 c: H7 `
  61. ( l! _+ x6 Z) o. E4 n; r( X' H2 m
  62. exit_enable:          ret
      k8 @# I" Z, u3 O

  63. 4 f$ y1 i1 H; X- C$ f
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 [3 [4 {& C, _) ~
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ! n5 p* x$ {$ o6 |0 i, `2 l; O
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear & ~% T$ X$ b( |( V/ f1 H5 }7 [' r
  67.                 jz      clear 1 p! W, @" t, G
  68.                 dec     cx
    / P0 Y9 m% g- t) Q7 |3 B/ A5 c
  69.                 jz      exit_write + i3 J  N; e4 R! e! |
  70.                 jmp     short get_wirte + q8 o% ?8 Q  l! S$ F( Q
  71. clear:          inc     al                      ; Clear ZR . d( g- V9 |6 v
  72. exit_write:     ret ' \) S- H' s5 e" L4 x$ C

  73. ' M0 I: q$ X# f8 k. t" `/ e& a
  74. 8 f! {" l# Z- p: ~* x$ s) J: W
  75. A20Read:        xor     cx, cx $ X9 H6 b, H7 k5 \
  76. get_read:       in      al, 64h
    ' n& V% |: R* k. @  B
  77.                 test    al, 01                  ; If the 'output buffer' is full, has / }1 L8 m# a/ R1 U: Q
  78.                 jnz     exit4                   ; ... 8 E8 H( z  p$ |6 H# n
  79.                 dec     cx $ l, C8 s( R: i/ O$ D
  80.                 jnz     get_read
    1 \! Y* |" ?& P9 {
  81. exit4:          ret     7 M" w: |8 w9 @) Q# L" N
  82.                
    8 `0 p+ t% d. m% s3 I
  83. end
复制代码
  1. ;A200FF.ASM
      N" p( d* A5 a* _, ]5 J7 R
  2. ;
    / j: T/ u5 n! y' X
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-011 @) f3 E( j5 d! C- v
  4. ;       ml A20ON.asm
    9 q, }9 F1 x: O7 T& h, B3 `
  5. ; % r( A- f6 y' w4 X, s- f  s$ e) \5 n; [
  6. .model tiny
    + x! F" n+ @' [7 l' {
  7. .code
    # u$ U5 I! }6 U* c
  8. .486* y% S4 a/ }" g' d+ f0 ], U
  9. .startup
    # b4 Z* f: l& i  l& J

  10. ' l, g% a% ~, u$ m7 D
  11.                 mov     dx, offset msg_author% w* q- T% M, x( A0 {5 E5 S2 }7 Y
  12.                 mov     ah, 09h- J, j# t* U5 ?' ~% _
  13.                 int     21h  N) L9 L* u+ O# O- S

  14. * w9 |8 u0 E( r- F) B
  15.                 mov     dx, offset msg_fail
    7 A% `; E& C7 k8 x
  16.                 call    A20_DISABLE
    / E5 Y7 L$ w, i
  17.                 jz      exit13 H4 Z! G: P' V  F
  18.                 mov     dx, offset msg_ok 4 d9 C8 j" R) ^* ~. \
  19. ' E4 G+ u5 i- b; x( t
  20. exit1:          mov     ah, 09h
    & b4 k% k8 v( D, ]9 N
  21.                 int     21h
    ( r- W' g# r4 _6 Y7 }! B; N4 B& F5 @' r
  22.                 mov     ax, 4C00h
    8 F" ^* e: H9 y4 B6 {3 m
  23.                 int     21h * q3 ^/ U5 L! O2 t  g1 o' @
  24.                 8 q9 o# A% A6 {2 @4 l
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,* I' A2 z  y2 p+ K0 R
  26.                         "2008-07-01",13, 10, "$"
    2 {% s$ |- g" K! v( w$ U
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    8 Q* q. [* H+ A0 Z
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" ' K* F# U" g! d5 q9 Y" o
  29. ! q4 V  `( l2 y( ]% c6 r, `
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------" \& i& }# A5 ?4 O" q! A% o
  31. A20_DISABLE:
    ; q& T# r* R& H4 A9 A/ Z
  32.                 call    A20Write ; g4 b8 q/ V& N. b0 B* ?- @
  33.                 jz      exit_disable7 A2 P. d* D0 L. T

  34. 0 I" t+ c  ~3 b5 ?" y8 p
  35.                 cli                             ; Only need for reading value from KBC ( I5 u+ d) ~4 E. C% Y0 Y8 E( I* b
  36.                 mov     al, 0D0h
    ( C* r* J, e; H+ @
  37.                 out     64h, al # ^6 T" \' f0 V. J
  38.                 call    A20Read
    5 d( O! s+ t5 C
  39.                 jz      Disable_int
    + G& B  m9 G5 \  Q5 ]+ h* ?: f
  40. : |3 v2 C" _- R% }1 q3 ~; m+ a; N
  41.                 in      al, 60h                 ; Get current status
    $ D! }  T! R/ P  i
  42.                 mov     ah, al
    4 [9 ]1 |- c9 Q8 \; B. w' t
  43.                 call    A20Write
    6 ?7 Z6 _9 h- O& \. s
  44. Disable_int:    sti
    * x8 q/ M, t3 K4 ~/ e% y3 X# V
  45.                 jz      exit_disable0 b5 [2 C$ H7 Y, C  O3 J

  46. / c8 L7 ]- t5 m
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    : J) u% ^; @; X: c0 t+ D* ^! V
  48.                 out     64h, al                 ; Out Put Port next
    7 a& }$ \% L9 w- T5 z1 o+ z) ~. g  l  i# K
  49.                 call    A20Write 1 d0 h- g3 ^  s# u8 U% e% x7 A- t
  50.                 jz      exit_disable
    1 \9 T( k1 u- S
  51. 3 n+ s2 U- n9 w
  52.                 mov     al, ah
    7 i! [: X- `1 w: w
  53.                 and     al, not 2               ; Disable line A20
    3 W0 r! {( b4 k  r
  54.                 out     60h, al
    % a) u7 R. v8 J' k* k. M6 n
  55.                 call    A20Write
    ! S- r3 P! |( y
  56.                 jz      exit_disable6 ?- ]! i+ N9 m1 e6 H+ _9 O
  57. 6 ]" y4 }4 I0 }. n, Y2 ~  W( d
  58.                 mov     al, 0FFh                ; NOP
    7 m5 m/ d$ c. ]4 V
  59.                 out     64h, al
    0 i, v  B4 B: H: ?
  60.                 call    A20Write 5 J5 D0 \4 R4 c4 q7 z3 `7 M
  61. 6 M. u$ p* }6 _7 R; {. {
  62. exit_disable:          ret
    * y! s& ~, G1 y- O6 M

  63. ) k* a, }+ Y4 e
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 ?' n, a3 |* s& C) X: s
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ) z" H. `+ m/ t7 b
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : S! g/ K& F9 `! W& x7 ]
  67.                 jz      clear ; {/ l8 O, c' N. ^8 e
  68.                 dec     cx - P9 F" K: o* R/ |
  69.                 jz      exit_write 4 ?( E6 m( g% B* r' N" K- {+ R
  70.                 jmp     short get_wirte
    1 ]$ z5 s- }, T9 j. s
  71. clear:          inc     al                      ; Clear ZR 0 K3 r. H1 c8 R. @  I- d/ f1 A
  72. exit_write:     ret 3 {* F9 @3 r% a6 T, q
  73. 5 F5 S1 V" G! e5 A  f

  74. 6 l2 F) D9 Q% T2 E7 A8 l
  75. A20Read:        xor     cx, cx
    ; x9 r$ l. r+ Y, x0 M! V" N
  76. get_read:       in      al, 64h # V4 _1 r3 G$ g
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' L' n7 A$ H8 X7 C) m
  78.                 jnz     exit4                   ; ...
    % B, B- ~/ @& v% `  M  C
  79.                 dec     cx ! f. H% u3 p  R6 H3 X7 I
  80.                 jnz     get_read
    # M0 q+ k) k2 [; |' h+ s! p% }
  81. exit4:          ret     
    ) ?# d9 B. C" S/ J% n+ D
  82.                 3 ^3 k* f& o( r; e7 c
  83. end
复制代码
  1. ;A20STATE.ASM $ K# |# ]. F9 y3 h! S' a2 h
  2. ;
    6 z, e3 V; I+ Y( r
  3. ; Returns the status of the line A20 through the KBC
    1 e4 P2 e% p, a9 k6 p! J* G* R1 \: e
  4. ;       programming by bini for debug. 2008-07-01& j0 I+ t* A& H" G& e: ]
  5. ; ) P; S% N7 o: U4 r' e. H0 i
  6. .model tiny" F/ G4 b( V; H1 s
  7. .code  l- e3 }- R$ U
  8. .4860 y9 |8 |1 L' N* i
  9. .startup
    . l; C$ P. `: J& B9 T5 I
  10.                 mov     dx, offset msg_fail
    + P; o  W& a& A1 ~; l
  11.                 call    _GET_A20_STATE_
    + n- q! Z/ }6 P
  12.                 jz      exit1                           ;  was a problem
    6 \( Z* X7 Z- K( f7 g' ~
  13.                 push    ax                              ; Save state, AH 0 I8 ~5 {, H! l& c
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem ' m- G: G. h% K! v3 c) v
  15.                 mov     ah, 09h
    6 ?) s* n3 h" G5 t; Q
  16.                 int     21h                             ; Print message 0 A7 ~7 m7 V* P* o0 @
  17.                 pop     ax                              ; retreve state 0 A5 l* c- F$ G/ E; E

  18. 1 h# w) j9 L  @# n
  19.                 mov     dx, offset msg_dis : |% P5 x4 Z9 }1 k6 c- A8 v7 x! e8 o
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    1 ]6 B! B7 Y" _$ H5 n* X
  21.                 jz      exit1
    6 q8 c6 O& y$ n" J, |, B: p
  22.                 mov     dx, offset msg_en & ~1 N! J8 ]: @3 x' D

  23. 3 T* \3 x! W6 R8 W: p+ t& C
  24. exit1:          mov     ah, 09h
      q0 t, F- ^$ A& h9 k6 z
  25.                 ; DX already contains address of string
    / [; L+ t% T  w9 m3 F4 ^) c5 @
  26.                 int     21h
    " L5 Q) V- H) Q0 N) G# ?

  27.   {* e) T  |8 b- H0 o$ R' p  x0 }
  28.                 mov     ax, 4C00h % O: E. k  Z; P/ h& o
  29.                 int     21h & W: s. s- `: \3 n3 o& [- T

  30. 6 Q5 X4 ~% ^- n; Y8 I: D; I  W! o; {0 H
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    7 ^' [4 F% z+ W7 H1 {4 X7 A% Y
  32. msg_fail       db      "FAIL", 13, 10, "$" 2 w2 F* b# n9 \, g5 n
  33. msg_en         db      "ENABLED", 13, 10, "$"
    3 V( e1 I& b& w$ x5 I
  34. msg_dis        db      "DISABLED", 13, 10, "$"/ B6 @: T' {1 q) ~+ _9 q

  35.   P* u: v) H) J3 T( l1 p, r

  36. - K/ l+ e$ U2 K) S3 ]( u2 \
  37. _GET_A20_STATE_: * H" w  X! N. U8 u, c# c% U. g& Y# P
  38.                 call    A20Write                ; Wait till the input register is empty $ J. j* A9 m: ]9 o
  39.                 jz      exit2+1                 ; Bypas the reset int's 1 u  T. T# n* P! \3 Y! D3 M
  40.                 cli                             ; Disable ints so we'll get our value
    1 a0 L! E" ^7 ^" ~  Q

  41. 8 q! R8 }! k! r4 d
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    * R0 A  N4 t& i* ]2 b5 I
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    , t4 P: I: M$ H4 b# q7 s! e- ~
  44.                 call    A20Read                 ; Wait till the 8042 output register
    ) ^' t$ V! \  P9 y* X3 d, G  H1 i
  45.                 jz      exit2                   ; has something in it's buffer : |+ _5 E) Y+ U4 \

  46. 2 U3 c. p: G" s
  47.                 in      al, 60h                 ; Get it
    ' H9 I: a, Z# R" R: I7 Z1 H* e
  48.                 mov     ah, al
    : A! w6 I7 _  w5 ^
  49.                 call    A20Write                ; Make sure the input register is empty
    1 c9 Z8 f1 g; C& @9 o
  50.                 jz      exit2 ' t. e, ?. P# B- L
  51. ! M5 j' S# B/ A( r0 p8 m* Q
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 9 n/ Y; A" y& k. E8 F6 `8 t
  53.                 out     64h, al
    7 N4 h. a8 s( p" O9 y8 R
  54.                 call    A20Write
    1 b: i, S( s: o

  55. 6 D1 _' a' c$ D+ ^# M& V9 [
  56. exit2:          sti * ^6 z* Z  i! n5 v
  57.                 ret
    ' D- U& a5 b- P# ^. U! j% V& n

  58. 4 b8 n! E8 H1 N

  59. ' d9 p+ {% T' r2 n/ O' e; [
  60. A20Write:       xor     cx, cx                  ; Reasonable wait + j, S2 c9 W4 x. e# |
  61. get1:           in      al, 64h                 ; Get KBC read status
    ; y9 s0 \* a! M- y
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear # g$ E; @. s& z6 S7 [6 d$ \
  63.                 jz      clear
    4 Y0 \3 D8 q: f5 `
  64.                 dec     cx
    , u% o( z( L' Z1 \- a% o
  65.                 jz      exit3 7 q9 m  j" ]3 E( g, |
  66.                 jmp     SHORT get1
    8 a0 h: N: Z, L0 e, n
  67. clear:          inc     al                      ; Clear ZR 0 [9 r4 k5 l# x% y: r! Q; V7 `
  68. exit3:          ret , Y  l+ o# i; `* l0 z6 }1 s" w. V

  69. 0 m( H6 o2 o9 Z% U6 }" G

  70. " U2 D* S  Y( y: [
  71. A20Read:        xor     cx, cx " A6 I' v/ v' ^6 Q) E$ t$ }
  72. get2:           in      al, 64h
      |  j2 e9 W+ Q# o7 }, ]! B- ^" g3 E
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 8 A; I4 X6 f# K+ V. p2 a; o
  74.                 jnz     exit4                   ; something for me & B3 d6 W+ e- l  H5 e5 F  d% ~
  75.                 dec     cx
    / {, P/ e2 v* p" D* Y. u# t
  76.                 jnz     get2
    7 b& |8 n; h$ a- C
  77. exit4:          ret     
    % y+ i' A( o2 Y" a  ^) \, T. M4 U4 b" G
  78.                
    ( ]: Z/ w" l6 n& s" C. Z
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()! F: t! X" _& m# \; @3 C$ [( g
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
  j" K& ?. }- ~2 f5 O. V( c        while(inp(0x64) & 2);        outp(0x60,0xdf);
( b' A) o2 b/ @9 R        while(inp(0x64) & 2);        outp(0x64,0xff);( Q# y5 y# A  x6 u0 ~  e
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-4 00:28 , Processed in 0.130589 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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