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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 4 u0 v4 _1 P5 n3 V
  2. ; / d$ w  n6 ~( u6 G/ G$ m
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01- A4 l8 l0 |8 C- J: k  R
  4. ;       ml A20ON.asm ( }* F" f4 K# N+ |( m) z& a+ }* @" o
  5. ; : r  _% ]/ `" A, o8 R/ {" D. d5 u
  6. .model tiny3 F4 P4 E0 M! M9 d
  7. .code
    8 p" P( T" h; Q+ k5 Y
  8. .486; K$ f7 ~% e6 \/ v8 N, E+ g
  9. .startup& ]& _* f0 e, n# y4 F

  10. ) G" }. S" ?9 M0 F) Y6 X0 B# u
  11.                 mov     dx, offset msg_author
    8 O$ |% Y+ M8 s6 v; h/ T
  12.                 mov     ah, 09h+ z  ^8 n" @4 I9 u# y( W% S2 U8 ?
  13.                 int     21h
    , Q4 Y& b3 r& h9 Z; t" e

  14. ' q4 m1 [# h- b* h- y6 o. E
  15.                 mov     dx, offset msg_fail 8 k4 ~1 ~! l" e; t! D$ u
  16.                 call    A20_ENABLE( h7 v7 C+ \* u3 b  d, }7 ~
  17.                 jz      exit15 ]* y" `& M% t3 r: r, ]( E
  18.                 mov     dx, offset msg_ok 5 j5 @: u) U( L* [7 E/ Q% q

  19. ( [. _" ]  Q/ ~1 j, U
  20. exit1:          mov     ah, 09h ) H" R  M! s  T  B6 ^5 y
  21.                 int     21h 7 E. r$ \! v7 T; C" K
  22.                 mov     ax, 4C00h
    : l1 O' N' c3 d: Q% q' a( d
  23.                 int     21h
      C! I% q% m0 x6 ]/ w7 m+ p
  24.                 4 C/ ^# R' E8 I8 e( ^# i. W- M+ K
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,& M9 z% _5 {. h% V. w2 J% |
  26.                         "2008-07-01",13, 10, "$"
    ; G; B3 l* {) h3 |* T" v8 v
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    5 }9 z6 {' c  g3 R
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" , N7 T# I% d; m

  29. 9 S5 }# S# D- g
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    # R. a6 P" X2 `* L6 S
  31. A20_ENABLE: ! a; v3 i) [! B  R% N
  32.                 call    A20Write
    * u, g! V1 {* T" H% V$ I
  33.                 jz      exit_enable0 Q6 G: J2 p( g/ n% C% @1 \  X

  34. - U  g, |8 Y. @; G+ ~
  35.                 cli                             ; Only need for reading value from KBC
    / r* w! O. R# b- M
  36.                 mov     al, 0D0h $ \6 u, P/ Z' A" _
  37.                 out     64h, al
    1 r& D8 A7 @! D( c
  38.                 call    A20Read 1 p0 v/ x8 @9 l& ?' Q9 w$ d
  39.                 jz      enable_int
    5 k/ N1 i( S3 [# m

  40. : M/ E" n5 N0 [: G
  41.                 in      al, 60h                 ; Get current status
    ' U  ?2 M* e! i( f# ~; R
  42.                 mov     ah, al
    ' w( |2 ~3 a7 R3 Q$ K& |1 _9 M4 e# `
  43.                 call    A20Write
    9 w3 N+ P0 N, ]3 N
  44. enable_int:    sti & P8 e- J5 c: s' Y, b; g
  45.                 jz      exit_enable  y) `# U* A) D+ I" V. T/ b( X
  46.   ]3 [, c8 y6 V( b5 o
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    % j- [) G4 g( C$ {& `! X; c
  48.                 out     64h, al                 ; Out Put Port next - Z# {& s8 M# e; k* a8 Q' X
  49.                 call    A20Write / s# p  z' C: s* }
  50.                 jz      exit_enable
    ' F7 V! O! q  A( i" F

  51. / c; |/ i. B. A( R3 W
  52.                 mov     al, ah
    ' ^* O' w: u+ A7 @
  53.                 or      al, 2                   ; Enable line A20 * a9 H* S0 ~! Q  h
  54.                 out     60h, al
    8 X' k1 ~/ c0 }& j3 U
  55.                 call    A20Write
    " ?/ X: R- x( Q( M5 |- r9 c4 W
  56.                 jz      exit_enable; I3 [5 ?% ]! Q& y
  57. 0 I' n6 _, ~: b7 X7 O
  58.                 mov     al, 0FFh                ; NOP
    & G3 ~9 f7 p/ \$ R$ |+ E$ V
  59.                 out     64h, al
    7 Y# K" k, ^$ s* W( V0 z7 K
  60.                 call    A20Write % t! ^( G1 |0 P( S7 M* B

  61. , k5 R  b! u& }  `5 s  `
  62. exit_enable:          ret % b" D8 J5 Z: }3 Y+ L, H; T

  63. 7 G; J. E1 c- E- N
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 E+ X! g( j: [1 T& |% M! ?& r& u; e
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ; r+ W! j# h5 t2 X( R8 b
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear . x9 `, T& V& L
  67.                 jz      clear 4 Q3 Z: w: K6 o6 j
  68.                 dec     cx
    ' D/ ^: C  N9 M) ]+ z, L0 }' _
  69.                 jz      exit_write 1 h  a% Q- o0 N: @' v5 p2 V
  70.                 jmp     short get_wirte
    $ i1 X/ D- p3 Y: G
  71. clear:          inc     al                      ; Clear ZR $ L5 r$ X0 l( @$ d" L2 s
  72. exit_write:     ret ' \6 g& j' h$ m/ v7 ?4 {* U: n
  73. & ~( {" l1 c9 v; H! L; [
  74. 9 |! Q, k3 r: P
  75. A20Read:        xor     cx, cx 8 u$ J/ h1 a6 j/ O7 ^! a2 Z: t
  76. get_read:       in      al, 64h
    7 Z% j  J7 O6 F% K( l  m  z
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    5 P. e7 i' z, |9 {% U$ A
  78.                 jnz     exit4                   ; ...
    3 Z. \8 {6 a- h
  79.                 dec     cx
    2 x$ k4 U/ y4 [8 C1 r& n6 W5 \% c
  80.                 jnz     get_read
    1 Y' _/ _. c0 b6 q
  81. exit4:          ret     
    ' I/ v1 |# m  j1 N" u$ I
  82.                 0 O1 M7 Z! L) v! y; z7 l! N2 ]
  83. end
复制代码
  1. ;A200FF.ASM 2 C& S% z0 ~/ a* x* _1 A4 f$ E
  2. ; " J9 O* k4 A. ^% A! H, f
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    2 u8 F. D4 a" R1 x
  4. ;       ml A20ON.asm 7 Z( [4 }; _0 ?& S) U  o7 u7 `/ T
  5. ; 5 [/ r. j( R; M5 ]: o" |* Z7 |! F
  6. .model tiny
    " Z+ o% W3 P7 K+ w1 |" O3 L
  7. .code
    6 p5 x7 ~: L; X3 J, `) w  t
  8. .486
    8 I* C% \' E9 A" H0 u% w
  9. .startup1 Q0 S- y0 m: y4 u4 K% V
  10. * t8 M) ]  y5 J; a; y1 _7 T7 D, {
  11.                 mov     dx, offset msg_author6 J$ j1 L* @& q5 t; F. [% Q
  12.                 mov     ah, 09h8 I1 r0 T3 f7 ?, v# o# ?3 q3 M( Q
  13.                 int     21h
    : _0 [6 ?: q# {) _& x: B: t

  14. 8 ~5 ]- ]3 u" W
  15.                 mov     dx, offset msg_fail
    ) v: \/ A- X/ F0 W: u
  16.                 call    A20_DISABLE% x+ k4 c2 P7 c, w- Z3 K, Q
  17.                 jz      exit1' @4 D8 |- s, L0 N  M7 f7 _/ X
  18.                 mov     dx, offset msg_ok
    ) U* T& @' @2 K0 i. e& i, b

  19. 5 \- s! `1 W$ @- |
  20. exit1:          mov     ah, 09h
    : r% `/ g  |6 c: k0 h# V. y
  21.                 int     21h " x9 N6 _1 g+ @6 N) R; j1 K/ T
  22.                 mov     ax, 4C00h # w  ~" d" a6 E0 y
  23.                 int     21h ; }$ @, c0 l6 z- R" ^: r6 Z- Q+ p
  24.                
    ; \4 [( a1 v  n, G4 H+ [
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,3 x! E& }5 e/ Y* b4 y
  26.                         "2008-07-01",13, 10, "$" ! ]2 X9 S9 D! R) n/ _
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    : G; U2 j; U* N2 q' _. ^
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
      ?; Q$ h& {& S/ x
  29. & @9 ?$ g. o: _2 X9 C1 k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    9 K3 @: ?& q( P, O: b1 j
  31. A20_DISABLE:
    $ P( n2 X) V9 Y8 k% x* }$ _
  32.                 call    A20Write
    - ?% h& M/ N1 w# c+ I
  33.                 jz      exit_disable1 A2 ?! a/ e% v, F7 Y

  34. 6 t* s. h( z  E- B4 j1 q
  35.                 cli                             ; Only need for reading value from KBC 7 f9 w  ~" |  t3 c3 c$ E$ Y
  36.                 mov     al, 0D0h * n( k: g  R' B6 I- T* }+ X9 Q- p8 B
  37.                 out     64h, al - i8 T6 R2 p% E7 X) Q
  38.                 call    A20Read
    1 m  [# X4 h2 p- J+ {
  39.                 jz      Disable_int ) S" f- ]* H# ?5 z/ `

  40. ) i! L# o7 ?1 H+ O  o: l
  41.                 in      al, 60h                 ; Get current status - b. H% u+ @! q5 H, k
  42.                 mov     ah, al
    * `/ e* I3 w: [% u, Q% Q- _
  43.                 call    A20Write
    1 b0 V; F7 k6 w; y' \
  44. Disable_int:    sti & R9 t( `2 c" L8 Z. t/ W
  45.                 jz      exit_disable
      s' J7 f6 |( f# a/ ]
  46. ! v8 J2 ~! k% v! f% p
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    - `' A/ L- l, U# D# V. I
  48.                 out     64h, al                 ; Out Put Port next ( o9 D2 N( |. Q0 b& u6 @3 `  J
  49.                 call    A20Write
    ( \7 e: `7 A! \/ w
  50.                 jz      exit_disable& T! ^& H2 `( b, F" M2 V

  51. $ z5 C" `: Q9 Z4 ]8 S
  52.                 mov     al, ah 3 q0 H# o' |4 H  b$ Z6 {
  53.                 and     al, not 2               ; Disable line A20 5 u" {$ w3 D9 g: h
  54.                 out     60h, al
    ( l9 o2 C2 `: e! H
  55.                 call    A20Write
    - N; D6 u2 \) m% |
  56.                 jz      exit_disable0 N) H, a. I) L& L# w& N5 B& F

  57. 3 k" o  G& F" c+ k* l
  58.                 mov     al, 0FFh                ; NOP - N3 w6 L3 u$ [
  59.                 out     64h, al
    ) O8 I3 I* I- a8 |1 D. [7 G. c
  60.                 call    A20Write
    # T( }" ?% a4 K; G7 m3 R0 Z
  61. 0 P/ p- c6 H; {7 T- ~! t1 i- X( D3 a
  62. exit_disable:          ret
    9 v. L4 y0 ?, a3 l4 x4 q
  63. / m# h- o8 K2 V
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 R! a7 ]: d) }1 w
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    " H# f  S6 O% X+ k* U, F$ z" D
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ! I* Z3 j2 y' y1 Z. t$ ?! P
  67.                 jz      clear ) a1 T( ]. f4 p% e* j# f
  68.                 dec     cx
    8 C+ ?- W: X3 x3 k2 W
  69.                 jz      exit_write
    ' u% {+ }# _& I' j6 q/ o
  70.                 jmp     short get_wirte 1 k( h7 q' N4 l+ r( w9 u6 s9 |2 t/ T
  71. clear:          inc     al                      ; Clear ZR
    # ^5 e" z) e! U
  72. exit_write:     ret ( i. f: F4 {6 o' {8 j7 z2 m& A" ?

  73. ) e3 I6 Z# c$ y3 O

  74. 5 S" \# `4 y. w' p* ]2 R5 {
  75. A20Read:        xor     cx, cx
    4 H2 w7 L- d3 w: s9 R
  76. get_read:       in      al, 64h
    ! D: u1 \& H( Y. k9 D, L5 a
  77.                 test    al, 01                  ; If the 'output buffer' is full, has : K7 @, Z9 e" H# i
  78.                 jnz     exit4                   ; ... - T' A$ J5 T, C  Y  K7 D
  79.                 dec     cx - K" m1 Q9 }1 L4 G: M; ^, z4 F
  80.                 jnz     get_read6 o5 g0 o( P) t/ y" g
  81. exit4:          ret     6 a- h) J  ]" k0 K" N$ b$ Y. @
  82.                 6 }% i) l$ x6 F/ A" J
  83. end
复制代码
  1. ;A20STATE.ASM
    2 q- y& W8 X( r+ A
  2. ; " L+ L0 R! ]  n* f* T1 t
  3. ; Returns the status of the line A20 through the KBC $ ~0 u; t4 S' E$ g1 X5 C! s  d
  4. ;       programming by bini for debug. 2008-07-01/ p2 y0 i( [- J9 k6 J5 U
  5. ;
      \6 n: k/ h+ I( I6 o
  6. .model tiny/ i8 K9 \  }- \0 |5 V( \' J
  7. .code
    6 r# {3 |7 \  f& H0 y7 v& U8 q
  8. .486
    9 W6 C: z1 s3 y9 r
  9. .startup
    2 q( }& D. h9 D2 o& G8 C
  10.                 mov     dx, offset msg_fail : m8 a. ~# m! z  w- a" h
  11.                 call    _GET_A20_STATE_1 Y1 t1 w4 v) A" l
  12.                 jz      exit1                           ;  was a problem
    : M& w$ v3 a7 n3 y
  13.                 push    ax                              ; Save state, AH - |1 `, a4 E( U3 x
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    ) U. X. L& n2 U" V
  15.                 mov     ah, 09h
    ) Q' n4 s1 m2 D
  16.                 int     21h                             ; Print message
    ; e6 K3 O( W0 \; ^
  17.                 pop     ax                              ; retreve state : u5 F" o5 W  o& y' ^

  18. 1 |+ z/ |' \9 H6 d' J6 F9 M
  19.                 mov     dx, offset msg_dis
    # s1 w. x1 A9 F# t8 H5 J7 e
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    $ \7 P* w0 K3 Y7 b7 Y' W
  21.                 jz      exit1
      `: A9 J9 k! U( d1 c/ D' r' ~$ p
  22.                 mov     dx, offset msg_en
    : Q2 }  A3 u% w$ _+ S- `
  23. ) F/ C. Y' Z3 w5 \" V
  24. exit1:          mov     ah, 09h - c) r0 a7 ~: o& J
  25.                 ; DX already contains address of string 0 p/ _4 f$ [  u3 d
  26.                 int     21h
    ' ], t* W! v9 z- r( a9 f

  27. 6 u8 R6 o& G1 t- n8 w5 {' s
  28.                 mov     ax, 4C00h
    - T" y# y( A0 H" ~
  29.                 int     21h
    ! S2 @9 u5 S1 d: P5 N
  30. ; s5 M9 s3 D% K9 _# r4 A+ P3 }5 R
  31. msg_ok         db      "OK", 13, 10, "A20 $"
      @1 _$ F- H( x$ s5 q% j8 R
  32. msg_fail       db      "FAIL", 13, 10, "$"
    . T$ C4 l- `8 `$ B# \
  33. msg_en         db      "ENABLED", 13, 10, "$"
    & [, c, n; s4 i7 Z+ ^
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    3 `$ F0 y: ~" ]! L

  35. / v+ t/ X  f) b. J! |

  36.   F  c8 L3 J$ g' U, J: ~- A- G
  37. _GET_A20_STATE_:
    + f: T. r+ D" N: ^4 T  h
  38.                 call    A20Write                ; Wait till the input register is empty * h7 c$ [# ]* u& G* \
  39.                 jz      exit2+1                 ; Bypas the reset int's
    : ~' \5 K+ ?3 w; s' T' y$ K
  40.                 cli                             ; Disable ints so we'll get our value : M: r% J2 I4 v4 z: H
  41. + T5 p: }0 F, H0 k% Y% V& N
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register ( i8 w  V8 v7 }: L
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    & Y6 {( [( m" V) a
  44.                 call    A20Read                 ; Wait till the 8042 output register 3 g5 p. h& f4 y
  45.                 jz      exit2                   ; has something in it's buffer 6 p% o# W$ {% Q2 f0 ^0 V% Q5 q

  46. . V( v! u- q" j: |
  47.                 in      al, 60h                 ; Get it ' c/ O2 C+ |' f7 B( {. D
  48.                 mov     ah, al ( l. U5 X. ?$ l' J
  49.                 call    A20Write                ; Make sure the input register is empty
    ( H% b% M8 w6 s8 W  A
  50.                 jz      exit2
    ' g1 g  p. n, P" v( ^5 n3 J

  51. * A! \$ g9 ^: ~$ ]8 B/ `; j% s
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing   D/ a; Q0 O5 k* {8 |/ _1 G% I
  53.                 out     64h, al
    $ f( x/ H+ Q3 H  ?1 }
  54.                 call    A20Write 0 A% d5 d# M+ p  A( ~
  55. : y4 @4 |. O4 G3 k
  56. exit2:          sti 8 d- R+ Q# b8 y) H* m
  57.                 ret# @7 j" i5 j" q! s2 k
  58. 7 h* z6 W1 p, z

  59. 6 ^5 Y5 }. g" v" M. s% {
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    , i+ H. z5 s1 h9 O( f
  61. get1:           in      al, 64h                 ; Get KBC read status
    7 Z" g8 f. W' }& j* v0 Q: A0 P
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear , X% p! q' c* P! u. E% D
  63.                 jz      clear
    ( a) U: l( F, b' u; S
  64.                 dec     cx
    & ~  [7 @+ c. `7 n; e1 _
  65.                 jz      exit3 0 c1 q* M! t2 D+ f4 l4 m
  66.                 jmp     SHORT get1
    - c# Y% ?( R" I$ l* h
  67. clear:          inc     al                      ; Clear ZR , V0 `( |& A: s% B  m3 k+ Q2 N
  68. exit3:          ret 3 `$ X/ b  r5 A
  69. & x( j. M7 V" m8 P" d
  70. ! e8 O6 w0 R# W6 W/ w5 T: }$ v
  71. A20Read:        xor     cx, cx
    1 C7 s& T- Q+ F& H' E
  72. get2:           in      al, 64h
    " B  e# ?! X8 w* k% U1 T1 e) A
  73.                 test    al, 01                  ; If the 'output buffer' is full, has ) a, K; K6 y3 i* ^- I
  74.                 jnz     exit4                   ; something for me   }  P  C7 ^5 I7 u1 R
  75.                 dec     cx
    , H0 `' @7 @7 U
  76.                 jnz     get28 h3 h- `- X( a8 w1 U; Z
  77. exit4:          ret     
    ; L4 N  t% b7 \  o- h0 c! n" s% Q
  78.                 1 F$ R2 [/ Z1 s  e) j
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
& X. y4 }( `2 F! r{        while(inp(0x64) & 2);        outp(0x64,0xd1);3 c% Z" R; T% b+ f% Z, O
        while(inp(0x64) & 2);        outp(0x60,0xdf);" `/ v1 N) S" C
        while(inp(0x64) & 2);        outp(0x64,0xff);
* u! c8 p1 S0 I+ c+ j; a# k( A0 Y}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-8 08:29 , Processed in 0.558647 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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