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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 5 V( ^- o; }) V5 ?$ ?
  2. ;
    % {5 s7 Z( G( h
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
      B( ]4 t) Q: E5 y. S! Z& y
  4. ;       ml A20ON.asm - l1 v" _& S7 A% s: ?
  5. ; $ R" B8 I. E, K5 U, U7 b2 T
  6. .model tiny
    / s; T/ s6 @5 \
  7. .code
    " i1 ?  W* V' o1 e
  8. .486
    5 g, `1 D7 Z/ {) x
  9. .startup3 ?$ `& n4 l9 B/ z- ^0 d" P
  10. 4 f$ x! V: E$ ?. ?4 c
  11.                 mov     dx, offset msg_author
    , i; ~% \" [$ @- I
  12.                 mov     ah, 09h
    : J& B  Y+ d, h7 b' m/ V) K2 H
  13.                 int     21h
    0 o6 l" {8 t3 G

  14. ! Y! f8 F  b* r# }
  15.                 mov     dx, offset msg_fail
    ; e3 J. B, b8 x2 L3 I; h
  16.                 call    A20_ENABLE& N/ J8 Z) l5 x" r8 N
  17.                 jz      exit1
    5 B% ^' N% O+ o. l: O3 e. c
  18.                 mov     dx, offset msg_ok
    , s2 y" Y  F; [, a* ]4 K# g

  19. 1 \5 \8 ^2 ]: P! o
  20. exit1:          mov     ah, 09h 5 X' T1 U# W. Z. y
  21.                 int     21h
    2 R* i2 F' V2 R/ |
  22.                 mov     ax, 4C00h - g- f! V; K/ X9 h/ E8 y
  23.                 int     21h
    % t& t) d" {! b; c
  24.                 / s# l7 |# K4 V: x- B- r
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,8 `6 H7 s$ K7 N# T) \+ Z5 h$ s
  26.                         "2008-07-01",13, 10, "$"
    0 `. i8 k/ r" A% w$ A
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    % {7 I5 A$ B- w
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" & M) t3 B. v. E; m3 z' K
  29. ( m" ?! J6 M/ K8 }; R% x+ U
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    3 g; v$ J. O+ s' U. X6 b8 V
  31. A20_ENABLE:
    * Y" f) b; e% R" S2 P" ~, B. n
  32.                 call    A20Write : L, R( e4 U) [1 T! D
  33.                 jz      exit_enable
    5 k! I6 m* J) W
  34. " V8 @) g; a5 ?. @; c- C
  35.                 cli                             ; Only need for reading value from KBC ; |% A3 A8 t. Y
  36.                 mov     al, 0D0h
    / ]9 ]. T" \; q' ], E) e6 ~
  37.                 out     64h, al
    ) v: h) J/ U8 h2 \. P3 e. }
  38.                 call    A20Read
    5 ]& w+ i' |6 F- U8 ~
  39.                 jz      enable_int
    0 ^8 k6 H; ^' B% `5 f6 e# w

  40. " ~& u# G! a$ b$ ^
  41.                 in      al, 60h                 ; Get current status
    ' r# S( q1 E3 o8 K( s; C$ e( v1 \) g
  42.                 mov     ah, al
    ; c- m* ]$ X% x  l; g) ~5 e
  43.                 call    A20Write 2 h( j' L' Q) z2 _
  44. enable_int:    sti
      u7 P# E& ^( B8 G; Q- k' m1 |
  45.                 jz      exit_enable
    ( o  d! P2 A# u5 l- V- v6 A9 E

  46. # U. N# _) U7 w: s
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 9 ]/ O# c& M! M6 ]) n- M* @2 L
  48.                 out     64h, al                 ; Out Put Port next
    ; j+ v4 \( M6 a. U( ]
  49.                 call    A20Write
    ; c6 p; i+ P% W0 X) ^' n( ?
  50.                 jz      exit_enable7 h1 s0 D$ I1 M% h7 v0 ~

  51. $ y& I0 d0 |- p$ u. B1 I$ o3 n
  52.                 mov     al, ah ; U* }- m; ?; Z. ^8 Q/ ^! S
  53.                 or      al, 2                   ; Enable line A20 6 Y# ^) t, _$ E$ o# R# z! M  V
  54.                 out     60h, al
    ( \8 ~# G5 a6 s
  55.                 call    A20Write
    2 p% K6 E) f) s: b! B0 d
  56.                 jz      exit_enable
    " G6 {, y5 T& w8 A

  57.   q' i% W6 E0 j3 y  k/ C
  58.                 mov     al, 0FFh                ; NOP
    9 {, l# P& e3 k0 ^2 x! }
  59.                 out     64h, al
    8 Q/ o0 }3 l3 _- t8 ~3 |: ?; o5 b
  60.                 call    A20Write 5 w, b" e' o3 u0 A3 b( c

  61. ! Q; @1 X. F$ c8 s# F* S( @
  62. exit_enable:          ret
      q- |% ~- k* F$ ~

  63. 1 y( u3 r* s3 K, q' ?1 K# T
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    0 l  s: R. S- p
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    4 n0 E5 H; F. c! v
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ! u$ e5 u- ^4 {
  67.                 jz      clear
    / X$ C5 `! c: D# B% o3 [
  68.                 dec     cx ' x7 x6 N3 l  P% S1 u  S$ c# T/ }
  69.                 jz      exit_write
    % `( j- {6 l% @$ e
  70.                 jmp     short get_wirte
    ( h" G' M! ?9 P  ?! s9 E
  71. clear:          inc     al                      ; Clear ZR
    # \& ?; M; n" Z$ R  i$ y% a
  72. exit_write:     ret ; O) W0 j3 g5 q7 p( v1 i+ i$ J

  73. 8 C$ x% N& M  E4 q3 K' j* `7 O

  74. % h' C! V" E0 F, g
  75. A20Read:        xor     cx, cx
    9 X( p6 }3 Y; c/ ]' H, \+ `5 n: f
  76. get_read:       in      al, 64h : E& Z5 f3 L% l' ]1 n$ H5 c5 S( ~3 ~
  77.                 test    al, 01                  ; If the 'output buffer' is full, has : @, J' N& o  _: Q
  78.                 jnz     exit4                   ; ...
    % K+ {- `9 `" R/ I
  79.                 dec     cx 3 @3 E3 j7 Q1 ]) t- K" V
  80.                 jnz     get_read2 M1 C2 c5 a6 r* j8 t1 j% v7 y
  81. exit4:          ret     
    6 v* {% G& ~% N- C
  82.                
    " M3 D$ R8 ]7 E1 r) }+ `' [  F
  83. end
复制代码
  1. ;A200FF.ASM 4 s! |- |$ ^7 Y9 ]: ?; e$ D
  2. ;
    , ?7 D4 X" I0 ]6 c* v2 b0 o
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    7 y+ x2 e2 Y: }% A
  4. ;       ml A20ON.asm " [4 f; `7 V0 @* I8 U0 s
  5. ; * Q( M- e* Y# t6 k/ @9 U( x2 C
  6. .model tiny
    * ]' @6 h$ h! X' g( T% k( N
  7. .code
    2 q( M; ^" W( z  ]& \6 f
  8. .4862 @6 O1 @6 J8 T9 Y
  9. .startup
    : F0 `) J6 X) x0 f

  10. ( J0 `/ D( p5 `: B& t3 i
  11.                 mov     dx, offset msg_author
    # ~9 D1 [2 |- n
  12.                 mov     ah, 09h, A8 T  g, k+ o, s! c* G
  13.                 int     21h2 }9 H1 B$ l* G* ~0 l
  14. , W0 |  `8 O5 J  S
  15.                 mov     dx, offset msg_fail + O- C" w; q" s& T: a7 ~' z
  16.                 call    A20_DISABLE+ u4 F" O9 ^& J3 {8 C" v
  17.                 jz      exit1
    0 e5 |# F- O2 z; G% \8 D# u- s
  18.                 mov     dx, offset msg_ok 2 x( }6 j! }2 F

  19. 4 f+ W3 ?! i1 @
  20. exit1:          mov     ah, 09h 8 `/ c& W: c2 J: g9 c
  21.                 int     21h
    * E' G; r: _8 x. h
  22.                 mov     ax, 4C00h
      V; f9 k$ i  }$ p+ ~
  23.                 int     21h
    - f8 z. j5 c* T1 K' F8 s" v. a
  24.                   Q6 s* R4 [' B3 l8 t& K* j2 j/ B
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,' ]3 j. P- _" M
  26.                         "2008-07-01",13, 10, "$"
    9 A. W& z' L8 T/ f+ D- Y% l$ S) }
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    / y% s  m  N# Y! _  a, t, q
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" # P' Q1 I: ?1 i7 A9 N! S
  29. 8 X# l" s: r/ j  h+ o4 l+ v& b6 \
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------% g1 T0 y% W3 s" w+ F
  31. A20_DISABLE: % f0 V! ?, l2 g2 ^: Q
  32.                 call    A20Write
    $ w: l7 Y: T, P; n4 a: E* H
  33.                 jz      exit_disable: j  T" g  P* e8 h9 N  g
  34. 0 V6 V# s- U4 C
  35.                 cli                             ; Only need for reading value from KBC ' r1 l2 A$ z  @' |3 H7 b/ O& N( |
  36.                 mov     al, 0D0h + {- I7 `, J3 s' M' R. e' i
  37.                 out     64h, al
      y1 r8 d$ c( s# \$ L2 p
  38.                 call    A20Read 7 O) s1 z& _$ ^) }* C" F+ [9 ?
  39.                 jz      Disable_int
      a6 K* X# q$ m4 H/ @
  40. 9 i) L% k2 |5 }/ L: L! D- q/ K
  41.                 in      al, 60h                 ; Get current status
    # C; J# g& _7 r; I. s; e1 |  m' n' j
  42.                 mov     ah, al
    ( L/ a' w4 l. B  ^. q( w
  43.                 call    A20Write
    * o/ m$ C9 Y6 C
  44. Disable_int:    sti 7 }! [0 X( a4 q# _0 `# n1 ^7 N
  45.                 jz      exit_disable
    % Z9 A% e( A( f8 C
  46.   }) N. h' h. X3 f8 O& V
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ' c8 _( i9 R0 F" m3 o5 P( R
  48.                 out     64h, al                 ; Out Put Port next
    8 ?9 m3 k. {2 J; X# g
  49.                 call    A20Write 7 G+ X5 I( b2 O. v& ~1 O
  50.                 jz      exit_disable, X: y7 y. p: @( [- q0 y, y# v( r- u/ v

  51. 6 Y1 w6 ~% ?4 z" Q8 C& q! N% X
  52.                 mov     al, ah
    ( c! N; Y5 L$ m7 _. ]
  53.                 and     al, not 2               ; Disable line A20
    6 U# _% |7 E/ o* \
  54.                 out     60h, al * \; d2 u0 `+ ~! c! X+ S
  55.                 call    A20Write ) C6 p' v3 }" [& L5 J/ m" `' O
  56.                 jz      exit_disable: d) y2 n& L6 K8 _! d% o. C* w3 ?
  57. 8 n6 a: m1 q- q6 @9 z
  58.                 mov     al, 0FFh                ; NOP ' D, ]. Y2 N9 N8 N, C
  59.                 out     64h, al
    ! r  d0 P+ Q: R6 C
  60.                 call    A20Write 8 A0 ^' B) P8 W

  61. # t$ S9 c$ _8 l) I7 F: `
  62. exit_disable:          ret 2 n. x3 U! j- M# ?

  63. 4 v2 s6 V- M( H$ x2 d5 |+ B
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    # ~) }1 s  T% A: Y6 i" }
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    - E0 [; G: m0 E8 C& K
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    # G0 f, |. y' T; {: Y: j1 ~
  67.                 jz      clear
    ! I: |0 v1 y! e- }
  68.                 dec     cx
    0 j0 c: g9 ~1 A" F& Y8 F2 c
  69.                 jz      exit_write ; y5 Q) M5 R/ t$ E
  70.                 jmp     short get_wirte
    0 v  o& b$ H! J! c- g
  71. clear:          inc     al                      ; Clear ZR   ~6 I. i) p; r/ \  v! {, [
  72. exit_write:     ret 7 T" S5 n' ?1 a# d$ b7 L8 k
  73. 6 w% p0 n1 z: q7 L% ~. l9 B* G

  74. 1 K8 Y; V7 C# b4 `
  75. A20Read:        xor     cx, cx
    : N7 |7 ~& ?9 l8 X
  76. get_read:       in      al, 64h
    4 z$ r3 y9 h: u0 n
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 5 _/ c8 ?. ~3 J( J9 L& E
  78.                 jnz     exit4                   ; ... . ?! v& e2 G, J) G: K7 v5 q3 o$ L
  79.                 dec     cx
    3 d/ @) e0 H; n( Q
  80.                 jnz     get_read' ^( T# o5 C. o$ C2 a5 q
  81. exit4:          ret     - y: z( q3 Y2 F6 m9 v
  82.                
    9 V1 k6 `/ @# m' o
  83. end
复制代码
  1. ;A20STATE.ASM
    4 h  i6 j0 L  ]1 F: S0 I
  2. ; ' t  a2 t% r1 A5 c/ G6 b! U9 I2 D. k
  3. ; Returns the status of the line A20 through the KBC
    5 t8 p9 B, F# D8 J) j2 p
  4. ;       programming by bini for debug. 2008-07-01
    , N* x/ k2 |. _) i" p3 o. m
  5. ;
    # n7 n& X% p3 D5 G
  6. .model tiny5 A$ H# P. o. {* m7 ~/ U2 K. w
  7. .code3 _5 Z6 u% _0 N1 P7 }2 \' L
  8. .486
    9 Y3 D" S5 [1 ?
  9. .startup4 T0 v, c9 N9 {7 o( U, V9 Z; g4 P
  10.                 mov     dx, offset msg_fail
    2 K, B9 g2 b0 S( _
  11.                 call    _GET_A20_STATE_( J) B5 D9 k7 c( X
  12.                 jz      exit1                           ;  was a problem% y0 A0 m, }7 j
  13.                 push    ax                              ; Save state, AH , o! v2 Y/ O) G! f9 u2 i
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    * u, c$ L) U: d! a- X& E' U0 v
  15.                 mov     ah, 09h
    9 Y# o0 {& l% ?) y' j( G0 Z
  16.                 int     21h                             ; Print message
    : i+ w1 e: Y. l# Y
  17.                 pop     ax                              ; retreve state 7 ~+ w; \  {% E3 m; Y
  18. 6 \/ T, w5 f. ?
  19.                 mov     dx, offset msg_dis $ z0 d% q+ i1 O# m8 @* n1 [
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    & g  h6 A9 w: G( d- G2 Z
  21.                 jz      exit1
    4 r5 _0 ^* T- |' v/ r1 ~
  22.                 mov     dx, offset msg_en
    3 K, f- L  n! r0 \7 o8 f0 g/ i- R

  23. 3 g' y  M4 P6 ~! b
  24. exit1:          mov     ah, 09h # B1 _7 e: t- g; |7 M2 c% x0 g
  25.                 ; DX already contains address of string 6 J+ ~" Z- o& T1 V
  26.                 int     21h
    - X! S& _  u( P  ~

  27. & Y1 J4 d9 s2 g. S, W2 G
  28.                 mov     ax, 4C00h
    . f" v1 a5 ^. d( B4 @) w7 [- U
  29.                 int     21h 4 e$ g" J+ e2 A  r# O" p1 I5 a

  30. # _4 u& |* w: o) V# T
  31. msg_ok         db      "OK", 13, 10, "A20 $" ) }3 U% D6 r: x! i. V
  32. msg_fail       db      "FAIL", 13, 10, "$"
    + P' t6 N7 w8 O/ b) \9 \
  33. msg_en         db      "ENABLED", 13, 10, "$"
    * O: a2 i6 o" r) S" {
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    4 X5 }1 N& U" k3 m' H
  35. / l5 x2 n- ?+ d3 ?. A

  36. 6 J# |# }1 P' U7 Q( g
  37. _GET_A20_STATE_: * c" q8 b' H' \1 m* d
  38.                 call    A20Write                ; Wait till the input register is empty * J* I1 \/ y, L. h+ f! H% U
  39.                 jz      exit2+1                 ; Bypas the reset int's
    3 t7 t/ t  m: r6 U" c
  40.                 cli                             ; Disable ints so we'll get our value 6 q) p( q- c# q% V% ?+ A% w
  41. ! w- R# ~. l/ o, B% u# W
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register ' Q& n. Z4 M) j  `: Y3 }9 L1 z3 X0 h
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port   @$ o( i0 B+ M- a
  44.                 call    A20Read                 ; Wait till the 8042 output register
      M0 `' ?9 N) D8 B6 i6 ^
  45.                 jz      exit2                   ; has something in it's buffer
    7 F; [5 H7 d% }' Y

  46. - p! a9 t0 b1 r# n0 ]! }
  47.                 in      al, 60h                 ; Get it
    3 X- T" F4 H4 G+ g% s% m; [
  48.                 mov     ah, al ' k/ C* V- F$ y7 G2 y
  49.                 call    A20Write                ; Make sure the input register is empty
    + d3 m3 }* i( I  e1 |
  50.                 jz      exit2
    # _2 |" `7 z+ m/ m8 C+ k
  51. , [: y: y) f$ y" d3 G1 @4 V
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ; m, \2 ^2 m% u6 L+ T- b/ b
  53.                 out     64h, al
    . o) j5 c3 q: y; p
  54.                 call    A20Write + V8 D/ Y: L, K# j/ h1 L
  55. 5 K9 M- j7 o. h5 o0 ?, R  L
  56. exit2:          sti 9 ?0 k8 d& f- x8 O- O7 D
  57.                 ret
    % {1 g3 {8 S1 a0 G# j" A

  58. 0 J, _4 Y" A0 B) X

  59. ; R  k/ c, L% t7 p
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    1 r0 \' i1 f3 u- C4 z
  61. get1:           in      al, 64h                 ; Get KBC read status
    ) S, m) [2 t, J8 t+ H+ l+ k
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
      O, m% c; V* u2 }# u' h
  63.                 jz      clear 8 m2 T9 B8 z0 Y- T! Y3 J  k
  64.                 dec     cx / m" k5 F4 Q" b+ O$ c3 e" ^
  65.                 jz      exit3
    ! S6 q9 n3 v& X( m* v2 s6 n+ E8 p
  66.                 jmp     SHORT get1 8 O$ E$ N: d% ^4 c+ n: ~4 _
  67. clear:          inc     al                      ; Clear ZR : q( O1 A0 k9 C" O
  68. exit3:          ret 3 [4 l* M7 I% [1 W; Q
  69. " ~2 C8 o# T( r  B) y
  70. 0 [& ?1 V+ H$ V6 w8 f7 i1 `. X! ]
  71. A20Read:        xor     cx, cx
    6 B: ^" t; o: x0 t
  72. get2:           in      al, 64h 1 i- B( C* V$ I! K0 t5 Y
  73.                 test    al, 01                  ; If the 'output buffer' is full, has & s5 I- k$ R3 e# y( a: \+ x" S
  74.                 jnz     exit4                   ; something for me
    $ u! A! }, Q/ T& e/ E
  75.                 dec     cx
    5 n4 P7 X7 x2 n- i$ L' w* D
  76.                 jnz     get2
    * K, I! o6 z5 t3 e. m% E
  77. exit4:          ret       a8 {5 K  L( ]1 Q; |
  78.                
    0 w& d, y  i1 ]) ?/ |9 L! {& i
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()! I7 H5 p1 W& X  E$ _* P
{        while(inp(0x64) & 2);        outp(0x64,0xd1);; L5 p2 |, {1 R; F7 M- n
        while(inp(0x64) & 2);        outp(0x60,0xdf);# \4 r) q9 U3 @
        while(inp(0x64) & 2);        outp(0x64,0xff);! r3 X3 J2 M  j( {' r3 i6 d
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-16 07:34 , Processed in 0.080373 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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