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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM & ?% P5 H5 O5 C8 d
  2. ;
      A5 n* M. J# d6 A  E7 ^9 z% p
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    # O9 [! j4 j) o; W
  4. ;       ml A20ON.asm
    + K0 A- K5 s- c% V9 T
  5. ;
    9 f9 t& \* d: n, v! [* M! m
  6. .model tiny
    6 Q2 U9 F/ k5 c0 W+ H1 Q. ?/ V3 b3 y
  7. .code' f4 ^9 x5 B' T* ~" k( r- \; s
  8. .486  g* a4 p" F4 Q
  9. .startup
    " `! ?- ^/ v, o1 q- P

  10.   V% E, F" ~! i8 u
  11.                 mov     dx, offset msg_author
    * k' `4 x  l( K+ i: B. ^
  12.                 mov     ah, 09h
    3 S" k4 C4 U( n5 J
  13.                 int     21h( E& G% ^; \! f4 h

  14. . [5 v% Y, [: `6 n+ {, o& o5 ^
  15.                 mov     dx, offset msg_fail 3 `6 w' o. D+ H5 ]' L6 e
  16.                 call    A20_ENABLE
    # y* Q" |9 S$ z2 O' u* }0 B) q
  17.                 jz      exit1
    ) H- ~0 r7 h$ a/ P& _$ \" ?
  18.                 mov     dx, offset msg_ok
    2 S: P2 J: g. J) I1 D
  19.   ], h& W/ o8 ^" S! ~" r+ p
  20. exit1:          mov     ah, 09h 8 o' u+ g4 y6 s8 ^" ?
  21.                 int     21h 8 c5 m# f$ {, ~& m
  22.                 mov     ax, 4C00h
    1 r# _* C+ y  g  p3 q- ]
  23.                 int     21h ! B1 \2 F$ ?& [& k, d* ]* e0 x
  24.                   B# J3 D: t7 W1 P% x% ]
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,; I; ^- c! a: s1 J# q% G
  26.                         "2008-07-01",13, 10, "$"
    4 f5 O9 m% H6 f
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    3 X* J' s* S& k+ F
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
      \$ A9 Q8 Q% S3 M8 ]

  29. ) x' z+ g5 L! K/ r. B
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------7 U5 h) B; u* b7 H, Y% s
  31. A20_ENABLE:
    ' ^! ?: j* n! v. ^. R& q4 T
  32.                 call    A20Write
    % |* B7 y  L3 ^5 p, m( N# [
  33.                 jz      exit_enable
    , l) b5 n  Q+ O& X/ u6 O

  34. 9 D' c6 Y2 N9 R8 z$ Z; x
  35.                 cli                             ; Only need for reading value from KBC
    % ]5 z1 s  C& u+ h* p" F" ?
  36.                 mov     al, 0D0h / Z- L3 g' M2 q) m2 h! ~: }. f
  37.                 out     64h, al   O! ?0 x4 J, n/ [) x8 o& r
  38.                 call    A20Read 0 }* z/ S  [& @# O
  39.                 jz      enable_int
    - ^, s  A& v( z5 }; c0 C

  40. 4 T; J$ z- H9 @  x/ D
  41.                 in      al, 60h                 ; Get current status # E" b) n! Q3 ]
  42.                 mov     ah, al
    + C) T# g/ P& e, k/ N* z
  43.                 call    A20Write
    - ?& m) s0 W- N5 F( g( @  n
  44. enable_int:    sti
    + P. s7 @+ i; ?5 W$ v
  45.                 jz      exit_enable
    " E3 V/ Q+ f% I8 q% s' m- W- m4 t

  46. * S& I6 N/ t2 }: p' r3 Q) y3 U
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    , g( k- p/ z% j) @3 u3 a) y$ i8 X
  48.                 out     64h, al                 ; Out Put Port next ( N/ x1 g" D( C" g7 P; u
  49.                 call    A20Write 3 t; `; L) x7 u8 V( M( P& z+ A- r
  50.                 jz      exit_enable
    ! B( Z, p8 t8 S1 O) v0 S& }

  51. 5 ?3 x1 }( v" C' R5 I
  52.                 mov     al, ah 2 _" |3 J8 G( X7 z" }  d1 @/ J& l
  53.                 or      al, 2                   ; Enable line A20 + Q! N6 e# H9 R2 o/ F
  54.                 out     60h, al
    . p* {8 }7 u5 E1 ~) x% J0 z
  55.                 call    A20Write
    6 {/ I. o: ~/ W
  56.                 jz      exit_enable
    - p& `1 [; f# l7 n. H
  57. 4 n' y: c% Y1 I- C; n
  58.                 mov     al, 0FFh                ; NOP
    * O9 y% p. [5 l  A4 Z: A2 |, l* m
  59.                 out     64h, al
    * v. ^  x, w2 f
  60.                 call    A20Write " z0 [# D( C. S+ b

  61. $ S" Y& a2 `2 }% K+ G- l# H9 n
  62. exit_enable:          ret
    . L- u+ D$ `! G* i' d
  63. % k. ^: g9 M# x$ g$ r4 G
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 6 g6 j( ~) @/ N) @* c+ o
  65. get_wirte:      in      al, 64h                 ; Get KBC read status " r  E0 h3 ~; e
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 7 J( a# y, O+ ^) P, ]( p  ?# I
  67.                 jz      clear ! D% I! n( @4 ^: B0 x5 ?
  68.                 dec     cx
    7 c$ |, X& V/ x# ~( W
  69.                 jz      exit_write 9 X" k3 _1 w2 g& S+ g/ `% y: w, L
  70.                 jmp     short get_wirte , x  M4 U4 e+ K9 W% L7 c# X1 `3 \
  71. clear:          inc     al                      ; Clear ZR 1 o: \2 I# [8 ?& I9 m% w- V# U: @" j
  72. exit_write:     ret & \) M8 Z4 c) E6 ?' ~7 p4 T
  73. 6 O5 K/ v6 e5 I: a" {8 ?, b

  74. ' W! j- r& O( e/ J4 h! L; g
  75. A20Read:        xor     cx, cx . L& G* ]) h) e# \
  76. get_read:       in      al, 64h ; {0 }* v# v. R% _$ }
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' v/ v" J: Y1 H0 n
  78.                 jnz     exit4                   ; ...
      f7 M) g: X0 R. t/ O
  79.                 dec     cx . D7 I% o4 P8 n. P: Y
  80.                 jnz     get_read
    7 z$ e3 \7 g% F; E4 L
  81. exit4:          ret     . |% ]# H; R' |. F+ v: {0 F
  82.                 ( K% |2 M  H; e" s* S: d5 b
  83. end
复制代码
  1. ;A200FF.ASM ; j5 Q) J! r  `
  2. ; " b5 p* ^- \7 J# M. r4 T" b" l
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01& m6 b* Z! {, N( V4 ]. s) G0 i3 Y
  4. ;       ml A20ON.asm ! i' U+ A/ o6 f& ^8 k
  5. ;
    , q( m' A% D& m& @  A9 C
  6. .model tiny
    2 x" C6 u+ g' B" ^
  7. .code2 O0 \- ?  B( t  ^
  8. .486  f$ s0 j1 K0 n
  9. .startup
    8 M; L; T+ M' S" x( z7 p
  10. 3 E" W% y! A1 N; q
  11.                 mov     dx, offset msg_author) Z: l9 J4 e% T6 L) J4 ~5 }
  12.                 mov     ah, 09h
      }- T# {2 j, j% B2 u9 e9 \
  13.                 int     21h
    & w' Z% o* O9 c! A7 ^0 s* M' N
  14. * N5 C, Q2 b7 `. `* |' ]
  15.                 mov     dx, offset msg_fail . w0 z5 c- T& k! u% ~
  16.                 call    A20_DISABLE2 c$ G/ o$ c2 d+ m/ h
  17.                 jz      exit16 e8 X  K$ t6 p/ P& n" ]: `
  18.                 mov     dx, offset msg_ok
    + ?/ j: [: H% Z0 V" Q
  19. $ c2 y, e( S) K7 w
  20. exit1:          mov     ah, 09h
    ) E' T8 w7 m/ Z- u: p! d2 A/ X, F
  21.                 int     21h
    4 h2 z( I1 B/ k2 q
  22.                 mov     ax, 4C00h
    : E% s; L) G6 D# i. V8 K3 g
  23.                 int     21h ' L2 s$ a* z! ^& _. O
  24.                 , @( o2 l, Q' x6 ~/ }3 K
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    % L# {) n1 k" q: E% z- c
  26.                         "2008-07-01",13, 10, "$" " D' @2 e: y1 R% U
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    $ }3 h. |  F* o5 q- S
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" # ~0 i4 I& t) K+ Y! G9 I! |) T* A
  29. 4 A: n5 j% F6 |2 O  t1 j
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    8 g3 G) }# Q/ h) h, {/ r
  31. A20_DISABLE:
    # [% ^6 V2 B$ N; k
  32.                 call    A20Write . N; H9 g6 e9 Z0 N
  33.                 jz      exit_disable+ M6 w0 o8 a* T* a- W

  34. 3 m1 q1 X7 w! M# `" ]! D
  35.                 cli                             ; Only need for reading value from KBC * L/ R& D6 \3 I& ~7 m# M
  36.                 mov     al, 0D0h 2 b& [. b' d4 c) U' @9 ]! |1 H& b, i) ~6 l
  37.                 out     64h, al
    ! P$ d/ {: T0 |8 k& r% U
  38.                 call    A20Read
    8 c0 W" ~8 R0 b
  39.                 jz      Disable_int
    $ b; g: C0 K( T; T

  40. 1 t: m. o$ r+ E3 S  Y* T4 v
  41.                 in      al, 60h                 ; Get current status
    2 v, R: e2 m: g- c4 I+ `  ^
  42.                 mov     ah, al
    * `8 T) i5 J+ B4 r. y; ?( B
  43.                 call    A20Write ( b9 H6 n- ]- z5 u; h- v+ L/ e
  44. Disable_int:    sti
    0 C' Y- Q7 R( i0 U
  45.                 jz      exit_disable% ]3 M: M7 f# w, q2 ~3 P

  46. + M8 T% x! q) O) t3 \+ F
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    9 Y8 e0 r# O8 M. o! n. d- `. k
  48.                 out     64h, al                 ; Out Put Port next . d0 X5 k) T, X3 L( G
  49.                 call    A20Write
    " S/ x5 u" r, C3 x) z. P
  50.                 jz      exit_disable" N0 p3 f/ x: C* Y& K0 _+ J2 F! a
  51. 2 }; Z; y" J) d+ X" k
  52.                 mov     al, ah
    4 K! [  Y+ |. \- U8 O# b
  53.                 and     al, not 2               ; Disable line A20
    & ^- g: k. t" R8 ^8 ^- D
  54.                 out     60h, al 4 Q- n9 D- j, U& Z' e0 B; q
  55.                 call    A20Write
    7 N$ p' w% Q9 J2 R7 ~, M) @
  56.                 jz      exit_disable
    $ Y* \1 {* O2 L* t
  57. ( E% c( u/ w& P
  58.                 mov     al, 0FFh                ; NOP
    5 _- [. d. T/ D0 ^  J, V" B) y
  59.                 out     64h, al * E! A9 _8 l# U1 S
  60.                 call    A20Write
    / o& j+ k: `7 ], e9 K9 ^( u& }
  61. " S: b3 P: @9 T5 _# Q% u7 e
  62. exit_disable:          ret 1 V" O, |  ]- g; P$ {

  63. 2 Y8 ^8 S* x2 R% D
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - ?, [* O; t' ^* J0 h
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ; B: t6 m- {3 _* ~. }* Z
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear # c: I& W4 w- C* s5 x! G' D
  67.                 jz      clear   Y+ L# x! o# w7 P
  68.                 dec     cx " e+ r1 C# Y9 x& M
  69.                 jz      exit_write
    0 {5 A/ B! n* A$ k
  70.                 jmp     short get_wirte
    % W; {7 z( \. `+ X6 s
  71. clear:          inc     al                      ; Clear ZR / S6 q8 m# m- k; ~
  72. exit_write:     ret
    / _- \4 ^6 c9 k$ u% ~" B$ o6 L

  73. , O4 C+ A5 q. h3 M1 t! G1 Z, ?# V

  74. & t2 E& i0 [" @
  75. A20Read:        xor     cx, cx % p5 l" s! r8 x2 Y$ W' x
  76. get_read:       in      al, 64h 2 M6 x2 C* B& K  E/ P" p
  77.                 test    al, 01                  ; If the 'output buffer' is full, has $ p( b2 T; Y- p% V/ m7 o
  78.                 jnz     exit4                   ; ... - m& `& S) `( G% R* L
  79.                 dec     cx 5 q0 m/ O8 P4 ~. l. e9 |" c
  80.                 jnz     get_read% S  F2 T) Q6 z# M; N8 D# s2 T6 j
  81. exit4:          ret     
    % x; O; y3 V. e; ]
  82.                
    % x6 q- J; j, L# ]9 c3 U* [
  83. end
复制代码
  1. ;A20STATE.ASM
    & X$ \( r+ A5 l1 f# {# C
  2. ; " F3 j- J. E/ X) P3 v; B6 w
  3. ; Returns the status of the line A20 through the KBC   r3 S3 v% J8 `: y* `% H: l
  4. ;       programming by bini for debug. 2008-07-01
    5 e# k5 j$ _$ ?
  5. ; : F3 x1 z* b# U( O( L. N
  6. .model tiny; e' E3 c7 `$ n$ B3 W5 A% U
  7. .code
    4 F& K# h, J# Z2 R0 }' M4 j' Y
  8. .4863 D6 k& N1 ^3 Y5 [+ I
  9. .startup
    6 E/ }" B8 W3 M% L" j& F- Z6 Q2 W
  10.                 mov     dx, offset msg_fail
    2 a8 e# n5 y: R( r+ w
  11.                 call    _GET_A20_STATE_8 n# f% I4 {: K& N/ l, x& \; ?
  12.                 jz      exit1                           ;  was a problem
    $ a' T4 O6 W$ ]  r7 d) g) a, J
  13.                 push    ax                              ; Save state, AH + p6 I: k3 @7 t. `$ e8 y
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem : q/ |. [3 s+ U! U
  15.                 mov     ah, 09h
    ! w' _4 q/ \+ f2 H+ w% R
  16.                 int     21h                             ; Print message " o( T, _# _$ |  t7 j- }
  17.                 pop     ax                              ; retreve state 0 S: f9 w2 c# v4 s% I$ N. {
  18. % z+ `. K8 X0 ]2 s$ i$ Q. m
  19.                 mov     dx, offset msg_dis
    6 B4 o; y! D- W$ ^
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state ( V- Z, a- s. D- Q9 f
  21.                 jz      exit1
    5 l1 P7 o9 c+ ~$ E6 @
  22.                 mov     dx, offset msg_en
    ) L1 b% _3 j+ L/ a/ `% q
  23. $ w, O+ A9 v* ]$ w
  24. exit1:          mov     ah, 09h 4 K! f1 j: _  j, u) y6 c
  25.                 ; DX already contains address of string # V6 \# @- F; a( _% ^) J! G
  26.                 int     21h & v3 j- _0 E  q) R

  27. / d2 n2 Q1 v) _
  28.                 mov     ax, 4C00h
    . I6 j" a2 o: M* [: V
  29.                 int     21h
    ' E+ k+ b  F0 Y5 f  `
  30. 8 o% U9 ^6 H7 X( F, v
  31. msg_ok         db      "OK", 13, 10, "A20 $" 5 Z) Y! S* C. f2 l
  32. msg_fail       db      "FAIL", 13, 10, "$" 6 I  ], @3 r* z5 u/ B
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ( i: w. n& Z2 q& S( X+ z" Q
  34. msg_dis        db      "DISABLED", 13, 10, "$"- [2 N# U# Z0 p
  35. + P) [# s1 P+ \. `1 e) O# ]
  36. , W: O7 n# O5 J
  37. _GET_A20_STATE_: & u! y1 `' P5 I6 ?" R9 i0 J. O* R& L
  38.                 call    A20Write                ; Wait till the input register is empty
    " \0 n0 V+ `5 [; B! j* F' T
  39.                 jz      exit2+1                 ; Bypas the reset int's
    / i8 n5 a: k0 W4 X2 Z
  40.                 cli                             ; Disable ints so we'll get our value , V1 q4 ~% ^% `' M6 z; H0 |: I) l
  41. & ^! V# B& c' S) I+ O4 d/ X5 B5 i
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    3 Z% Z" A6 _% P. g5 b
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    4 d5 r4 k2 C! ]& v7 S6 J
  44.                 call    A20Read                 ; Wait till the 8042 output register
    * Q, C/ f" e9 ^! Z+ J
  45.                 jz      exit2                   ; has something in it's buffer 9 z( R- d3 S/ W8 O) k# q

  46. 1 E$ a6 S! C0 U# c. f
  47.                 in      al, 60h                 ; Get it ) K9 g4 {1 ~3 I% L  Z, T0 O
  48.                 mov     ah, al
    7 d6 ?1 u! [+ Q/ V
  49.                 call    A20Write                ; Make sure the input register is empty ! B7 A* u$ @& D
  50.                 jz      exit2 : Q- F7 {6 m$ @2 `0 r

  51. 6 i& ]+ h+ H% w! A! F+ E( V8 ?
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing # m4 o  e" s. l% P% B, M$ w% D9 \
  53.                 out     64h, al
    . X' B( M4 b: L0 K& B3 v
  54.                 call    A20Write 5 i. @, E( [; P" ?' e( K: o( t! J

  55. 5 i/ `0 `8 \( R- \: h
  56. exit2:          sti
    # z% R/ U/ y, R2 ?  _5 {
  57.                 ret& b- `. v+ m5 D. b
  58. 3 O7 E1 ~: G% n( N, V

  59. # i8 j; d! \" @# {, h( D6 Y
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 2 G- M8 K! X, N( V- i' X
  61. get1:           in      al, 64h                 ; Get KBC read status
    . l: f( c% O% s. c
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ( Y5 F8 v8 |2 }* H) }. p; V1 k$ A& ]( G
  63.                 jz      clear / p4 e& M$ J" M& o4 Q$ `
  64.                 dec     cx # O0 F4 ~. _& @$ I- D$ X8 L( J
  65.                 jz      exit3 5 `* J- W9 r  ~& ?% z1 t' S0 c
  66.                 jmp     SHORT get1 4 R/ C# F# k# |8 a4 ?8 b3 t
  67. clear:          inc     al                      ; Clear ZR
    4 x6 i5 g) P( T0 U' _, g. o
  68. exit3:          ret 8 T3 j; W; F$ U/ x5 @; N2 ?
  69. ! {1 f% D1 V0 b

  70. 2 G. n- Y# e' l$ T7 o8 @6 m7 ^7 C# r5 t
  71. A20Read:        xor     cx, cx
    ) t0 s7 M0 X/ k$ x& ]/ A. R7 t
  72. get2:           in      al, 64h $ q! N5 w2 `' O% |6 |' ~
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    2 \& E& \. Y7 c8 ]0 U$ A
  74.                 jnz     exit4                   ; something for me
    & B6 h7 ]; M9 [4 \( ?
  75.                 dec     cx
    2 O8 g, l( Y5 Z7 x! Y) A3 F# n( i
  76.                 jnz     get2" N8 B/ w& E0 J# q' M& k3 G
  77. exit4:          ret     2 L" E% r; t$ \) z
  78.                
      |* t, P4 {& d7 O9 M7 p  M1 W
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20(): P  }* W# |( C) h& Q; b9 S
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
4 |6 j' d" v6 \" ^        while(inp(0x64) & 2);        outp(0x60,0xdf);
' g& m6 f5 S! A0 _0 w" J) }        while(inp(0x64) & 2);        outp(0x64,0xff);) n; d8 E" Q; L
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-21 21:57 , Processed in 0.087934 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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