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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM , E$ z! W8 ^% u1 O
  2. ;
    6 H/ w; }( I: D! G9 ^2 D
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    $ b& ^+ {& m; V) B/ _; l! Z4 N  M9 l6 z
  4. ;       ml A20ON.asm
    % m5 \& v7 p3 _
  5. ;
    3 E8 p, q6 e8 K' q$ u
  6. .model tiny  Z) F8 R( ?- V% I( ~) x. C
  7. .code& j5 V+ `# ~, _3 K  Q
  8. .486; B- N4 [! s7 ~+ y3 @: \$ n  I# Z7 D
  9. .startup
    0 ^8 \9 ~2 _9 ]; ], F
  10. ' x$ T; n% v( ^7 R# U; \( t4 [
  11.                 mov     dx, offset msg_author- R" C% x* {0 n
  12.                 mov     ah, 09h7 ~8 m) T6 j3 Y  m
  13.                 int     21h7 C, _8 W0 {$ k- ?# b3 j

  14. . y' y  x, m/ K" u" U
  15.                 mov     dx, offset msg_fail * u0 c7 c* o& a6 H8 `9 a
  16.                 call    A20_ENABLE
    1 q: a1 W  A5 B5 r, B5 X0 d, t
  17.                 jz      exit1
    5 s/ \9 ~, `* M! I0 J. ^" f2 P* g
  18.                 mov     dx, offset msg_ok 4 C* A( N& l  {6 @5 G! D

  19. 9 \& L% D! ~5 F: h0 o  f; ?6 I6 X  }
  20. exit1:          mov     ah, 09h
    6 u* |$ m* O( g! q- b
  21.                 int     21h 3 v( B% o  D' u, n/ ~7 Y( o
  22.                 mov     ax, 4C00h
    2 Z' P9 ]+ y9 X) D+ ]
  23.                 int     21h 7 u- J" Z( _: R8 q0 z
  24.                   D7 g! V- z. R# {4 p" z
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    ( n; @1 l6 Z1 ~! B5 a& F! j! V
  26.                         "2008-07-01",13, 10, "$" 2 Z5 `2 i$ U" e2 z% _. F
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 1 m) [' K6 f' k8 `/ i. r, C
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    8 T' x* o1 s0 H- C; k1 O

  29. . p2 |, O( E- l; N+ `& f  I- x3 }
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    7 \; J8 ?4 l4 Y0 _1 M6 d
  31. A20_ENABLE: 8 a2 ], s7 q( w! i
  32.                 call    A20Write , @: R$ ]) P1 e5 b, w- Q& C0 a
  33.                 jz      exit_enable( y1 J4 s. Q: q' m
  34. # S* s/ C6 N9 B# e" Y! R; S) y1 r
  35.                 cli                             ; Only need for reading value from KBC
    / _# B; r' I  \9 ]
  36.                 mov     al, 0D0h ) }4 O8 G, j: |$ h
  37.                 out     64h, al + I2 N0 w% m$ x7 c& w
  38.                 call    A20Read
    ' d3 P6 E1 {+ Q) w
  39.                 jz      enable_int
    . {; ~2 b5 R0 q, o7 x
  40.   w$ s# [+ X) h4 s- X) o% ^
  41.                 in      al, 60h                 ; Get current status , D" m% n! R, h) N+ d
  42.                 mov     ah, al
    * z- t5 Z% L) J% N9 j. b: C: B5 Y$ H
  43.                 call    A20Write
    ; M0 o2 h* o4 v, G' h3 o/ m8 q9 u9 _
  44. enable_int:    sti
    / P# R6 I  ~+ {3 ?3 W. W( ?, E. ?
  45.                 jz      exit_enable; y, z! ?2 V8 v# d3 H9 e

  46. 8 O: d$ _0 n" z+ z% Z
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    ( o/ p1 ^, q: t, H/ c
  48.                 out     64h, al                 ; Out Put Port next " A# Z, |# N4 z% {% J" D. u( T
  49.                 call    A20Write - m) u9 C' f2 X& \$ `( t6 T  K
  50.                 jz      exit_enable9 r/ Z8 Q3 J1 z( x$ K/ P$ O

  51. 3 s" Y5 t% a- G. S* V* r
  52.                 mov     al, ah
    4 R, w5 h; b' c. j; F' t
  53.                 or      al, 2                   ; Enable line A20
    8 H% b& t2 w8 O/ E6 k: p0 h
  54.                 out     60h, al
    6 |8 |1 y! O+ N# s: m; u/ q! a9 R* r
  55.                 call    A20Write ) X1 z5 u1 p3 m- X0 b3 ?9 d
  56.                 jz      exit_enable
    ; [% X7 @* [% _1 V( h1 ?4 Z: m
  57. 2 r% K% B/ ?( r- u9 Y8 g( w# r
  58.                 mov     al, 0FFh                ; NOP
    : F3 z* f. Y5 g  d) _/ H0 ], m
  59.                 out     64h, al 3 \8 m# i& H! l( [: z2 A
  60.                 call    A20Write
    ) K1 }4 o; R/ _9 u4 G3 o

  61. 5 C: R, `! L$ ]* @5 x. B7 @/ X
  62. exit_enable:          ret
    9 M# Y9 Z; h' O1 L

  63. ) h$ o' Y, Z3 Z2 ~/ f
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 9 t& m( {( a! I3 i2 h& l
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    / A9 V' q( {2 p7 {3 D9 g
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear # C( E" m3 ~7 v1 V4 U9 h) K
  67.                 jz      clear
    - a6 }/ K6 Q! g. W+ I2 [
  68.                 dec     cx
    7 n8 i1 K) e3 C. _
  69.                 jz      exit_write
    - W0 D* ^# |5 {6 l8 b/ ~
  70.                 jmp     short get_wirte 1 P, ~0 U! S$ i  m
  71. clear:          inc     al                      ; Clear ZR $ J2 N/ Q( y# X1 S7 M, T9 R
  72. exit_write:     ret
    ! T  e8 A* L) g! ]* O! T8 u0 R% W% w
  73. " V2 f2 r: w, o4 z5 A( T1 M5 W

  74. ' J( L  w; ^/ ]4 ^' _6 V3 q
  75. A20Read:        xor     cx, cx / u$ a( z, u/ M; s! m0 c
  76. get_read:       in      al, 64h
    * S, }& ^1 }) g$ V6 y1 f
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' q! R  k) J, \
  78.                 jnz     exit4                   ; ...
    . q2 Z8 Q; F, B" ?. A& I8 r; E
  79.                 dec     cx
    " W1 g2 J# p* |6 m4 A
  80.                 jnz     get_read/ H  B. S( [3 q+ P+ x; j7 F
  81. exit4:          ret     
    & z/ D$ P0 h. o; l. o' C
  82.                 ( x8 R9 I* M. x# M# \/ l, L: p. L$ Z' P
  83. end
复制代码
  1. ;A200FF.ASM ; R; G6 V2 _2 R
  2. ;
    3 ]* X9 `  [. @( k
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " D( I2 g; {. [2 x
  4. ;       ml A20ON.asm
    1 p$ {) e9 I( i1 {$ H  h* Z5 U
  5. ;
    * H( l) Z! B# F/ i( y" Z8 a$ }
  6. .model tiny
    0 Z( F4 u( F  x: Y. V$ O+ o  r* j
  7. .code7 \' X% J& M; J, K$ S8 K
  8. .486( p( r% ^' A) V8 \# d& {
  9. .startup* B2 k  ]4 T! h  `1 Z+ X

  10. & o4 @8 U6 D; @& e& f" x+ O' c" M8 q
  11.                 mov     dx, offset msg_author
    * C7 p6 C! x5 w5 m% d5 j
  12.                 mov     ah, 09h
    " {7 k$ J; j% j7 g2 e
  13.                 int     21h
    3 K8 m* N9 e" I
  14. % c) n* L' I" v
  15.                 mov     dx, offset msg_fail   D1 F8 ?5 K1 Y9 q% J
  16.                 call    A20_DISABLE
    2 c; r5 V0 r. U! U
  17.                 jz      exit1
    4 S8 X# v5 m( p" J4 p4 F
  18.                 mov     dx, offset msg_ok
    : J5 W) h7 X0 M/ D

  19. % d. F% S! `( c
  20. exit1:          mov     ah, 09h $ j0 M) N& L& x7 q9 `
  21.                 int     21h
    1 A1 a4 w& p( }0 u/ v, c
  22.                 mov     ax, 4C00h ( {; V) t1 J1 |" i4 E
  23.                 int     21h & H4 R$ T1 q& p  U% h& c
  24.                
    4 f' ?, o$ P" v' K# F
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    9 d* ]$ k- t0 u- M
  26.                         "2008-07-01",13, 10, "$" 0 y3 t5 V+ v3 c; Y1 l& q# {
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" + J. T' w/ U1 W5 A
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" ! q8 O& S4 ~: q5 ^3 \9 w( g

  29. 2 G9 L. S7 q6 m. o
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------* Z  x' e8 n, v' B4 ]
  31. A20_DISABLE:
    9 I) C5 g% y9 u  q
  32.                 call    A20Write
    ( Q: D) c1 d/ a0 T+ Q7 V
  33.                 jz      exit_disable
    & r  X8 X  s. R

  34. . J# m' D5 t4 ?2 F+ @6 }
  35.                 cli                             ; Only need for reading value from KBC
    9 |9 b) K" t' ]) m9 I0 w
  36.                 mov     al, 0D0h / E- K) B2 x6 `( Q  w
  37.                 out     64h, al
    * D% j$ s% K. M+ a
  38.                 call    A20Read
    ) a4 Y1 b8 F; X. E1 \$ y* c
  39.                 jz      Disable_int $ \2 S) F9 o+ h8 z6 Z
  40. / ]2 z( t; q7 ~  f
  41.                 in      al, 60h                 ; Get current status 6 w6 Y; F  W8 v7 ]4 B
  42.                 mov     ah, al + L, Y# T7 B+ o* y1 Q* @* M& T. w
  43.                 call    A20Write
    2 c6 K4 @, k; i0 Z2 s6 m
  44. Disable_int:    sti * z0 L% V4 q7 T* Y
  45.                 jz      exit_disable" Q! }# u! c& @8 a2 i+ o
  46. 5 B" d# H/ D6 L+ s6 x  c1 f
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    & E; V) d* W) v% Y
  48.                 out     64h, al                 ; Out Put Port next
    5 q- i3 _3 E5 _+ F; `
  49.                 call    A20Write 2 e  p- A/ ~  k# V# F1 x
  50.                 jz      exit_disable7 Q7 n( w" y& m9 I/ H
  51. ! T8 J7 `: b# s+ W- Q0 I  V
  52.                 mov     al, ah
    0 H2 E* p  I$ i' j6 o
  53.                 and     al, not 2               ; Disable line A20 ! l* f" r: N) `: F1 r
  54.                 out     60h, al
    3 n1 y; r3 d3 ]  j( |/ [" }  f
  55.                 call    A20Write 9 ~/ t$ t% u7 k& d; {  W& l
  56.                 jz      exit_disable
    ' B8 J% z" i( @# Z8 L1 O

  57.   o; ]4 i. P, h, x: p
  58.                 mov     al, 0FFh                ; NOP & t: _& M2 w1 l* t. X! T" U
  59.                 out     64h, al
    # H  C- C: H+ ]0 P( r- ?. O
  60.                 call    A20Write
    : @3 E6 P2 M: m
  61. * m/ g4 Q# Q$ s9 D* U
  62. exit_disable:          ret , `0 c$ R6 p6 S& Q$ a

  63. # r1 G' T5 j6 L% s6 Z* X$ m4 S; Y, X
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 9 U! K. V! S6 X; Y* O1 ]& j, b& @3 Y
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    2 J! i; t" v5 j- y8 g
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 2 y, E- [6 ~' J- [& n# x
  67.                 jz      clear
    ( ^# L& c  ]0 A1 S) t7 ~
  68.                 dec     cx
      m- ?! u0 `3 t
  69.                 jz      exit_write
    & w: R) L' z  M4 g" W3 D0 V
  70.                 jmp     short get_wirte
    % ~$ s9 M  R( f( a7 E& S
  71. clear:          inc     al                      ; Clear ZR 5 n$ F' n" [2 Z* {
  72. exit_write:     ret 1 M5 u6 Z+ V0 U' I8 B: Q+ Y6 {

  73. ( w: J: y. H% z) t
  74. + D& s* d# }3 E: t* p
  75. A20Read:        xor     cx, cx
    / c; R3 g$ _3 }7 V! l' V6 J9 |
  76. get_read:       in      al, 64h   Y- T; M7 W! Q6 I. Y9 i' p
  77.                 test    al, 01                  ; If the 'output buffer' is full, has & s! Q& `% D# A" L9 r. Y5 ^0 h
  78.                 jnz     exit4                   ; ... ' v2 u7 Q; ^. z. S: C  D
  79.                 dec     cx + g2 Q+ l& L. i" C' B! R
  80.                 jnz     get_read
    ! M. j* m, z2 C6 k
  81. exit4:          ret     
    5 {: `( u* k  `5 \
  82.                 ( w1 e; M9 j7 Z" Q$ A
  83. end
复制代码
  1. ;A20STATE.ASM 8 _- i0 ^7 U9 y5 x
  2. ; + Z  [. E/ L# m" G
  3. ; Returns the status of the line A20 through the KBC * e0 d* z, e1 U& n
  4. ;       programming by bini for debug. 2008-07-01# O4 W0 K7 l7 T% B/ X: L" Z. T: m& }
  5. ;
    * V7 U% g, N9 k4 X: M* u2 h
  6. .model tiny- R2 \' k/ g* l- t, K; {# R
  7. .code
      W9 [" a8 ]& ^/ J' B$ y' c
  8. .486
    ; {+ y: ~& n% ]
  9. .startup, Z$ |' D' R6 I1 H6 j1 M% p$ V$ l' U
  10.                 mov     dx, offset msg_fail 2 y/ x4 T! p# I" h8 Y; \" ]( r" z
  11.                 call    _GET_A20_STATE_
    " A4 ?' a9 }1 l9 z+ _
  12.                 jz      exit1                           ;  was a problem8 d; n8 m! `. S4 z! g1 @
  13.                 push    ax                              ; Save state, AH   U; V: M" E4 C5 w4 b0 f5 u9 H! {- r
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    5 a  ?* p3 _/ G
  15.                 mov     ah, 09h 3 v; t8 J7 u9 O1 o5 @& `1 B
  16.                 int     21h                             ; Print message
    # Y0 R7 C8 ~" X, g
  17.                 pop     ax                              ; retreve state
    ! N* o3 H: P7 K; f9 H& \

  18. 0 a9 U1 q1 w7 |! Z6 P& c
  19.                 mov     dx, offset msg_dis
    * ]$ `5 U& F- R" }) y) i$ ]
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state ) y; x/ l& C6 d6 e
  21.                 jz      exit1 9 w; T7 E/ x( ^' A4 k
  22.                 mov     dx, offset msg_en
    $ \9 H4 r; h1 b4 r3 m: R" G! b
  23. " A# D8 S% Q$ T! D. y. v
  24. exit1:          mov     ah, 09h , Y2 R' W! K; L
  25.                 ; DX already contains address of string
    / O$ b1 w/ x! N1 I" o2 J
  26.                 int     21h 5 F% B* K0 c  {* R/ A% t2 f# u5 Y+ S( z
  27. # w0 M; \5 b! h. K
  28.                 mov     ax, 4C00h
      C4 [6 |: E( ]
  29.                 int     21h
    % N* A; Q9 l! D8 X5 C5 m9 `
  30. ) L/ a. o4 B$ |5 k* z( _% \7 b
  31. msg_ok         db      "OK", 13, 10, "A20 $" ) |0 I+ F" N. [' H! F
  32. msg_fail       db      "FAIL", 13, 10, "$" 5 S( e( T; @. X, A6 i
  33. msg_en         db      "ENABLED", 13, 10, "$"
    + w  O. H  O8 r# T. K
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    1 b6 O" S7 y+ Y& B
  35. : R9 n  M7 I; J: `) c
  36. 2 e! W, b. V$ {" V. E+ @
  37. _GET_A20_STATE_:
    * w( E/ J$ J6 b! m/ N7 S% h
  38.                 call    A20Write                ; Wait till the input register is empty
    3 f  G& q, |1 @& l6 m2 E2 E; d
  39.                 jz      exit2+1                 ; Bypas the reset int's
    ' x* T; [( y, G
  40.                 cli                             ; Disable ints so we'll get our value / |7 n  g5 Y  q

  41. + b: f! _0 Y1 R; P/ f  ], W
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    7 W. l, n- h! H/ z; G* O
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 0 t; |3 @5 V/ Q7 O2 c% E7 l3 \' p
  44.                 call    A20Read                 ; Wait till the 8042 output register 0 E3 V- t5 S4 Z* f; @4 f
  45.                 jz      exit2                   ; has something in it's buffer # E! Z) \  t; _& b4 G, B+ {5 Y

  46. 9 E& b6 O  H/ Q8 f5 r/ [4 f7 s
  47.                 in      al, 60h                 ; Get it ( A( D; t( K5 G' d' Q* D2 g
  48.                 mov     ah, al
    : y# ^( d( B: S; [* J
  49.                 call    A20Write                ; Make sure the input register is empty 9 f  I. b/ A: g7 Y. J6 L
  50.                 jz      exit2 % }- l7 Y0 h* k. M$ N

  51. ; K3 W$ h6 _6 U5 t5 b* Z0 [  x
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    " J! k" p. I. J5 F5 Z/ G; T2 E
  53.                 out     64h, al / Y. ~7 E- }/ R. I
  54.                 call    A20Write
    ; z! U/ B: B: D8 g% ^: g( \4 y

  55. 6 g# ?2 d5 w& E/ b5 y
  56. exit2:          sti " c8 r! W+ X& @" m- T
  57.                 ret. E" u" D9 u& }# V6 h* S5 m
  58. ) h! K; _! O1 U6 ?7 W* |4 m

  59. / r/ o  [! S- r
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 2 c9 w9 U& }- k" }) h  M
  61. get1:           in      al, 64h                 ; Get KBC read status 7 B! D/ {0 c4 q# T, ~, U+ t
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    8 O; G- z& I" W+ V* m$ {  z3 E7 w
  63.                 jz      clear 0 q& W. W$ e! p1 P
  64.                 dec     cx
    - S/ G0 K4 Y* Y/ |
  65.                 jz      exit3
    % S: a# @$ H: M8 c, B$ \, t
  66.                 jmp     SHORT get1 , W) L+ S1 H$ F& f* R, S
  67. clear:          inc     al                      ; Clear ZR
    . r1 s2 T% Z) s: V5 B0 V
  68. exit3:          ret * k6 C; j3 v  a

  69. 1 \% x, l$ s# a$ w9 ?6 {
  70. ( b7 C6 x" ~  ?4 C
  71. A20Read:        xor     cx, cx & ~, `4 q1 h! K
  72. get2:           in      al, 64h 9 f* k! ~; [4 A9 i2 z& {+ ~4 K
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 0 x. b) e" {) B) c( e+ O( m
  74.                 jnz     exit4                   ; something for me
    / X) b4 q% f4 O6 ?* i- ]
  75.                 dec     cx 3 g3 L, ]& f: U9 W
  76.                 jnz     get22 n8 S8 s+ T9 ?# Q  Q+ f! ?# ]8 A
  77. exit4:          ret     ; k4 j7 c4 f' G, }8 X: ^
  78.                 1 l$ y7 I8 I2 \/ n9 o
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()5 h0 F2 E: q% r% ~
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
+ C7 B8 ]8 B9 ]! y0 j  p        while(inp(0x64) & 2);        outp(0x60,0xdf);: ^& n8 P, l1 R. I5 n$ e. t
        while(inp(0x64) & 2);        outp(0x64,0xff);
7 }' U. o$ |* G0 y' Z}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-4 18:37 , Processed in 0.049198 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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