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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM ' o+ I* B# s9 w5 u
  2. ; 6 w! q; U+ I+ V/ n4 e) C
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01$ b: s0 w  N/ j$ X0 }
  4. ;       ml A20ON.asm / O  o3 h) R& F" }9 n
  5. ; 0 _% @. ^0 P8 |; S2 f& l! J6 N9 g
  6. .model tiny/ |$ Q# X3 q! ]
  7. .code9 \( x4 Q! O2 S' |
  8. .486
    : d" `3 Z4 S7 u' p+ W. k4 c% O
  9. .startup8 t$ V& _7 ]7 Q+ }8 b4 t
  10. 6 i4 l0 }- C  i7 p  H$ [; h6 T
  11.                 mov     dx, offset msg_author* ^1 ?( q% t# h: D% H% B" L, K
  12.                 mov     ah, 09h
    * l# a+ M6 ?! ~$ C1 B/ ~
  13.                 int     21h7 d$ r5 w+ c; V5 f1 k1 R

  14.   h3 [2 w5 B" A) Q% a5 H
  15.                 mov     dx, offset msg_fail . i  N+ u0 y$ Z7 j3 y. o
  16.                 call    A20_ENABLE
    9 I! g3 r* g. t# g* s
  17.                 jz      exit1
      E( M, T! Q. C  N
  18.                 mov     dx, offset msg_ok
    ' r  b, m0 v/ Q( W7 R6 Q; Y9 i

  19. + n8 |6 o; \5 q% G1 L6 o! I, ]
  20. exit1:          mov     ah, 09h
    8 ]6 S/ @3 T. n: g/ h6 r2 A& x
  21.                 int     21h 7 ?7 W9 c& {% d; g( ?; Z% ^; e
  22.                 mov     ax, 4C00h 0 E4 X: b( b2 t% E+ H9 B
  23.                 int     21h $ t! @/ A5 h' @! \6 J% S  u
  24.                
    - n1 k$ N" b2 }+ q; ~
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    # A2 K. d1 ?6 {- |) V
  26.                         "2008-07-01",13, 10, "$" / h- X$ I2 \# r2 J4 T2 }/ ^
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    3 q; A- K# X( g0 a+ p5 _
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    $ L( F5 Q1 {# y+ ?

  29. 7 c, d4 [' N4 _, J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------% X* S, b5 |2 N4 Y! I, E# J
  31. A20_ENABLE: 9 Y* S2 j! z8 n0 A' }; m: q
  32.                 call    A20Write & n8 R6 u' g" V0 T/ k' Y& |0 D
  33.                 jz      exit_enable
    6 i8 T/ f) R4 o. @5 T

  34. 6 e7 c9 N. U: [' J* Z7 Y' ?
  35.                 cli                             ; Only need for reading value from KBC
    / J- H/ {6 R4 c; S; a
  36.                 mov     al, 0D0h 3 l& l0 n% h+ a
  37.                 out     64h, al
    8 Q. h4 F, r7 }
  38.                 call    A20Read
    , J, |( F5 ^  q- ]( V4 \. P
  39.                 jz      enable_int
    6 O! ^8 p  b8 p& b

  40. 6 ~9 ~- p2 _8 `8 d( e
  41.                 in      al, 60h                 ; Get current status
    ( x- B: [$ _; l- y% e1 t0 K
  42.                 mov     ah, al
    3 V, g8 p7 f2 x+ f5 s% P
  43.                 call    A20Write
    & D# u' `8 o: Z/ c  B
  44. enable_int:    sti ' r1 L4 L4 U7 i- C! j2 K' B
  45.                 jz      exit_enable+ M2 g, E' h7 ~0 `3 H* z7 H
  46. 7 t" X5 C4 q9 I9 {) w
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the " H/ s3 r& C9 v. E
  48.                 out     64h, al                 ; Out Put Port next
    + h' [) P0 G) z8 j! W, s
  49.                 call    A20Write
    % Z/ |: D! F9 e6 q1 }8 `8 {+ L# A
  50.                 jz      exit_enable
    0 C! ]! d3 }% e. ]9 X" V) x& a
  51. % Z' h" Q4 D9 S1 x2 V& l8 d
  52.                 mov     al, ah
    # i( m0 ^, V2 U7 F7 N5 Y
  53.                 or      al, 2                   ; Enable line A20 " i- P6 L8 d3 ~& B% \* @+ i
  54.                 out     60h, al
    - T4 [3 ?' ?' p( e2 Y
  55.                 call    A20Write
    3 i6 D  \$ s# Y( e
  56.                 jz      exit_enable0 Z4 _" b4 N$ K" q, P
  57. " h9 V9 x2 P7 a1 G: M8 Q( P
  58.                 mov     al, 0FFh                ; NOP 5 g( X4 ]% N/ }; M: Q' b- b$ i
  59.                 out     64h, al ' D- M. N7 X6 S6 J1 x6 M: k( H
  60.                 call    A20Write 9 K9 {( m" }5 u* R: g4 J' o
  61. 0 e4 l7 \) y. ^$ v, S/ b$ b
  62. exit_enable:          ret 5 A  i  f5 w8 v1 J1 O6 s- Y
  63. ( }% B( o; I$ l% F3 U
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 3 P6 w5 v8 a% l
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 8 W4 r0 ^, f. ~1 k: }! b, u0 \
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 8 ^! @2 r% C& d- F9 }$ k9 z
  67.                 jz      clear
    + Z; P5 d2 i6 V% y
  68.                 dec     cx
    , b  l' s9 v3 N; h6 C5 T3 `
  69.                 jz      exit_write 1 D( o1 R0 f+ x- h  K: W3 u6 U4 [
  70.                 jmp     short get_wirte : w- q" o% u1 P& h2 N
  71. clear:          inc     al                      ; Clear ZR - R6 w. W# G1 s  ^$ A
  72. exit_write:     ret
      _) n# U6 P0 |& t! P8 w8 T
  73. $ _' ]6 _& Q# F% \

  74. 1 y6 E5 l1 t( r/ h6 |5 q. r7 h
  75. A20Read:        xor     cx, cx * ~! i7 A1 Q5 j0 j4 O; n
  76. get_read:       in      al, 64h
    2 C, y* L5 [7 U# i) w
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' {/ L/ e# n  Q' l$ C6 c
  78.                 jnz     exit4                   ; ...
    * p0 a3 }. O2 ?' A: T
  79.                 dec     cx
      E7 B3 o! W" G3 j4 L6 `
  80.                 jnz     get_read
    & u7 ?- W* J+ E  A
  81. exit4:          ret     
    ) Q, d# j/ W* O0 i! Y9 v
  82.                 / K+ w3 v2 |8 ]
  83. end
复制代码
  1. ;A200FF.ASM
    ! p/ g; P0 ^* q) M
  2. ;
    2 r1 ^$ d: B5 q* o0 \9 @5 E
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01/ }* x! c# n2 q! t
  4. ;       ml A20ON.asm $ \6 o3 D$ T! K7 n  a
  5. ; % d  t7 m" B+ e/ H4 Q
  6. .model tiny
    4 r, A" o7 @- W1 O/ D* }* y. _7 p
  7. .code# z' o5 J* ^. c) P, _$ Q
  8. .486& _* X/ D/ d5 u1 U$ @+ S
  9. .startup
    ( C8 g) m# s# k9 J( ~4 H+ \

  10. , Z$ G0 `/ \7 _" G& r3 M3 y
  11.                 mov     dx, offset msg_author  Z1 s9 f# S9 v( E1 s# g9 i
  12.                 mov     ah, 09h
    % Q# h1 w6 I# m
  13.                 int     21h" ?) g! k; ~' _

  14. " C* M) R; ~  a0 F4 M. H3 `+ z
  15.                 mov     dx, offset msg_fail
    ; `" @1 a6 M: _$ W1 n+ ^' k" c, o
  16.                 call    A20_DISABLE; h# q8 X- \* T% F$ e1 V
  17.                 jz      exit1. D  A; X4 e2 I9 d6 ~
  18.                 mov     dx, offset msg_ok
    5 w3 O7 b. T; i/ t8 W9 [
  19. . H0 P5 q9 S* U* _, T; h$ u6 ~, S
  20. exit1:          mov     ah, 09h # B6 T4 a- @- r
  21.                 int     21h 3 S9 y& }' Y) [3 E  A8 D$ f
  22.                 mov     ax, 4C00h
    9 F. {$ m, o* R4 {/ K8 y5 b4 c
  23.                 int     21h $ Y- H. h& H, `( u3 w. `2 C
  24.                 # G& a) a. [7 r# r4 x9 t
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    1 t& `. {- t6 A  j3 ]: {  s
  26.                         "2008-07-01",13, 10, "$" 7 J# ^4 G! ]; j% r8 D( ?
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" 3 |& C: V- @5 A
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
      }. ^& ]) g+ q' M0 V: }
  29. % T( i5 o( c0 J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------! L' X' d9 }6 j( D& U- e( Z
  31. A20_DISABLE:
    8 `; b5 C$ s+ V7 r+ C0 r
  32.                 call    A20Write # {# I7 F2 p% U, t" e  y
  33.                 jz      exit_disable7 Q& j8 }  ^  l" m, t  s6 o+ ^
  34. $ ^7 q0 Y2 E/ ?$ i/ S- l1 t
  35.                 cli                             ; Only need for reading value from KBC 5 V& [0 W1 D$ d/ y7 h- \5 H0 w
  36.                 mov     al, 0D0h ; {' a: q3 X- ?* w8 N1 w
  37.                 out     64h, al
    & N/ }# x6 Y$ M
  38.                 call    A20Read
    " X' k4 |& ~7 [  @+ h# J
  39.                 jz      Disable_int 5 M& m2 h( x% Z6 I; P
  40. , k6 ^  D/ e0 C% l0 Y8 |
  41.                 in      al, 60h                 ; Get current status
    ) d( u' _; ^5 B: o# d$ F, L
  42.                 mov     ah, al 5 o) m) Y0 \1 _7 h$ b
  43.                 call    A20Write % i' m$ ^4 l( F" J
  44. Disable_int:    sti 6 {/ l& [6 L' X! ~* _+ H! j! ]
  45.                 jz      exit_disable
    ; S8 h& ^9 e* C0 g* }$ b
  46. * x- W6 h( V- b! S7 q4 W3 g+ B
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 3 W0 C4 C8 R  P/ G
  48.                 out     64h, al                 ; Out Put Port next ( Z; S. S9 Y7 i
  49.                 call    A20Write # t2 ?. R, X, ~  z" R
  50.                 jz      exit_disable+ m  l! c- P; h7 Z8 ~; O; |) d. b5 h
  51. ) w# |$ v/ G/ l6 ?
  52.                 mov     al, ah   _* T) |: b$ ]
  53.                 and     al, not 2               ; Disable line A20
    ) r- p7 z! C3 |& N
  54.                 out     60h, al - b0 l  T1 S: t8 v! @! g& ]
  55.                 call    A20Write
    2 l% K0 w3 n( o  t& W" O
  56.                 jz      exit_disable
    % D" A; `" s8 I0 H' [

  57. 2 ^2 q$ ^2 c: `1 {) r
  58.                 mov     al, 0FFh                ; NOP
    ! R7 y4 h. O& v) {: q2 x
  59.                 out     64h, al 5 U; B$ r9 d' p6 m# `+ [
  60.                 call    A20Write
    , ?: H+ O& ~6 k/ |6 I

  61. " `( h9 f8 P  x4 H/ y
  62. exit_disable:          ret ( n  D" m! m1 l0 c' h
  63.   u+ M- o0 y( Y2 ^: ?2 G- }) I
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 5 r, n0 Q3 N$ n# a) p" O$ B, |0 o
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    * P5 ]7 S9 t" p$ L5 z# D+ u
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    6 o+ v+ C  X7 ~) V) s
  67.                 jz      clear
    4 `! _7 c" N5 s1 q
  68.                 dec     cx
    6 h* T2 p& z) o/ v( d' j
  69.                 jz      exit_write
    9 o' J# ]+ |9 y- r& ?. H3 A( Y
  70.                 jmp     short get_wirte ; Z, m+ c" e  c& C+ t8 g
  71. clear:          inc     al                      ; Clear ZR ' u& c1 Y% [4 t4 n
  72. exit_write:     ret
    * t; N+ T, B7 _# A
  73.   X( Z) a# m. I' U! A# O$ W: k

  74. - V% h7 S4 A3 z$ D2 L; e: R# ^$ ]9 \" e
  75. A20Read:        xor     cx, cx 0 [. X8 T2 e7 }. p
  76. get_read:       in      al, 64h
    ' _/ `) R, L' u& u7 J; d
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ' ^# s! W! E9 K
  78.                 jnz     exit4                   ; ... . Z) G  r: t+ x8 P" o8 V9 `& G1 R
  79.                 dec     cx
    8 d* }2 D7 m; {7 I1 B
  80.                 jnz     get_read
    ' B  ~; v4 `: O3 m/ e
  81. exit4:          ret     . g9 D& l5 p* t: s/ a" z
  82.                
    2 M* m4 ]1 K4 ?/ h) |" a" w
  83. end
复制代码
  1. ;A20STATE.ASM + w$ c! v* f( c9 h* {  y
  2. ;   _# t: v, A, {- T  Y/ m9 P
  3. ; Returns the status of the line A20 through the KBC
    ! ~( @8 ]" k4 v% v* M1 L9 E
  4. ;       programming by bini for debug. 2008-07-01+ F* `: V8 J7 W7 A# S6 q
  5. ; ) U6 m* _4 W# |
  6. .model tiny
    4 x% _; v, q. Z0 h* q. v
  7. .code
    2 v% F5 I# x: P$ j
  8. .486
    8 |: B6 c! t& n
  9. .startup
    5 \( e' W6 i8 o! f) {
  10.                 mov     dx, offset msg_fail 0 m7 o. `& K' x
  11.                 call    _GET_A20_STATE_
    ! N2 @# T3 D% K  @: U& N: ^
  12.                 jz      exit1                           ;  was a problem
    7 L& v9 q$ R( w% d
  13.                 push    ax                              ; Save state, AH
    $ T" e! N& `; \
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    , {! |0 L, @  w0 H! O( s; Q0 r% \
  15.                 mov     ah, 09h
    ; Y/ a+ @0 C8 U$ {
  16.                 int     21h                             ; Print message + Q2 X1 D, ?+ ?7 Y% E
  17.                 pop     ax                              ; retreve state
    4 Z( M6 V2 J- r9 V' \+ x6 v- m

  18. " @8 G! m7 A2 C6 v
  19.                 mov     dx, offset msg_dis ( M' g. u) f# o+ [  R
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 6 z: |2 M) z" J5 F; n" T
  21.                 jz      exit1
    : b& z0 u2 z( c7 p& L! w6 R
  22.                 mov     dx, offset msg_en * c8 C1 B7 U/ r3 a. r
  23. / P9 f: q' U! f; I
  24. exit1:          mov     ah, 09h
    8 _& O: U1 c: ^0 F1 m
  25.                 ; DX already contains address of string ( W6 P' y& J* H- i
  26.                 int     21h % m  x* H7 _6 `% n

  27. ( y; p# F0 k/ R/ ?6 F+ d  s
  28.                 mov     ax, 4C00h / F( y/ g8 W) ?+ Q5 ^+ I
  29.                 int     21h 4 l8 {: U4 V, S2 x! ^# Y1 n$ k

  30. + D1 S+ Y6 ?7 R. i& \
  31. msg_ok         db      "OK", 13, 10, "A20 $" / `) c* C' D$ V2 t/ N8 L
  32. msg_fail       db      "FAIL", 13, 10, "$" ( [  @0 o: v, E9 e9 u1 y1 Y, B# G
  33. msg_en         db      "ENABLED", 13, 10, "$"
    0 u4 r' ^: ]0 `+ B
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    2 G; B8 P" e. O  y! ?6 n. q5 v8 V* s
  35.   Z, n8 a, U4 y
  36. & q% M% V4 x2 _2 p* m2 T
  37. _GET_A20_STATE_:
    0 F, \& u: A* H9 }0 t
  38.                 call    A20Write                ; Wait till the input register is empty 5 @4 E7 @6 \. Q7 L9 D2 J* f
  39.                 jz      exit2+1                 ; Bypas the reset int's
    : n& ], L/ I: J. e, v
  40.                 cli                             ; Disable ints so we'll get our value : N3 j  ]$ g4 c6 n
  41. ' b: Z1 U7 X8 z! K+ b
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register & E8 B' d9 W; g, x# Y
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    % L0 a8 r1 Y) Q4 d  Q" G! C
  44.                 call    A20Read                 ; Wait till the 8042 output register 1 i$ K4 ?+ |; M1 h% y% [; J
  45.                 jz      exit2                   ; has something in it's buffer
    . W+ F4 V% [2 O/ V
  46. 1 V3 Q) N, g) |$ n1 M/ G
  47.                 in      al, 60h                 ; Get it 2 m+ ^  H# ]# ^$ e( |9 [+ A4 o0 {
  48.                 mov     ah, al
    6 F) Q/ E7 h* f$ z
  49.                 call    A20Write                ; Make sure the input register is empty
    7 \" c" u) z* g$ {
  50.                 jz      exit2
    - b$ Z% N8 R; l' e5 J7 [) x

  51. , @6 ]& R: B5 V5 C+ I
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    * Y5 \' ]' P8 l
  53.                 out     64h, al + q7 V4 T* P' Z/ {6 x: X/ U3 d* H+ T
  54.                 call    A20Write . o4 C: [/ h4 e' T+ Y' b

  55. 0 R) u( N9 R% d, K$ \% x+ t
  56. exit2:          sti
    9 `4 _" D7 n! Q
  57.                 ret
    & v. G( R1 H1 x5 q- x7 I
  58. ' M5 w9 S/ R4 W' f9 r* u

  59. 0 K/ @- D2 T  I
  60. A20Write:       xor     cx, cx                  ; Reasonable wait   n" p, u- b  [% G2 Q5 l4 j, G
  61. get1:           in      al, 64h                 ; Get KBC read status * ^4 B6 q3 [4 U4 M
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear ( _& m! z- I2 e$ H' ~
  63.                 jz      clear
    ' a# @- y( J9 p  p: x- f7 p
  64.                 dec     cx & @2 t9 `& E, W- J
  65.                 jz      exit3
    4 s% `2 j  {( y
  66.                 jmp     SHORT get1
    5 A, u! N& r! y
  67. clear:          inc     al                      ; Clear ZR # i% s% d  E& I9 z% F% W. j% g
  68. exit3:          ret
    4 e( y2 S# f$ \/ X
  69. , H1 [. V) M* i( h

  70. 0 e& b' F  _9 a5 n" q: W: j" u
  71. A20Read:        xor     cx, cx " g( L1 K- _9 }4 `; K2 E8 |
  72. get2:           in      al, 64h 0 l) X+ J7 m# G7 l: i; t. U- ~6 c
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    + Q4 e: m1 b' D+ q: y& Q
  74.                 jnz     exit4                   ; something for me
    & G8 u( c7 A7 B9 v; E; w
  75.                 dec     cx ! b* Q' i4 \; P& ?* Y( }9 A* A
  76.                 jnz     get2
    / D. }4 g; Y  x, e- h( Y
  77. exit4:          ret     
    / s; O8 Y) ]! `% M& ^, u1 u* W( p2 ^* g
  78.                
    " J& R4 o; g6 P% j$ ?, A" B
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()9 v; }1 |5 @! @3 r7 G
{        while(inp(0x64) & 2);        outp(0x64,0xd1);* T5 k- a) ]0 P) j
        while(inp(0x64) & 2);        outp(0x60,0xdf);
+ y; _* O- z9 E6 r7 q        while(inp(0x64) & 2);        outp(0x64,0xff);" |0 n6 u5 L, H6 t
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-17 00:24 , Processed in 0.234726 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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