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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    : i& y0 ^. y0 m- N. f$ @# o  ]
  2. ;
    $ u) |2 Z, N. F
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ; K4 M) _; t6 ]* m. u; \
  4. ;       ml A20ON.asm # H7 d+ C6 Q/ N, s5 f1 H9 l
  5. ;
    . H  A1 s. D- O  |
  6. .model tiny; B: u8 v1 X/ A' ^
  7. .code
    - w$ I7 ^( l) B# v
  8. .486
    " E4 j6 }1 f: C
  9. .startup
    ' ]( h- }0 y8 ~, j5 i8 Q0 u' P) l# a

  10. + s! F6 d) x: x( R! o, T+ r" g
  11.                 mov     dx, offset msg_author
    0 @  q/ H3 E2 W, r2 I
  12.                 mov     ah, 09h. }2 v! N$ Z& C& s; o1 y: q
  13.                 int     21h
      v, H2 O5 d5 r( s9 K9 Q4 i5 M

  14. 8 c, _9 H( e7 s( R0 _4 O
  15.                 mov     dx, offset msg_fail
    $ r( `) W( B( i7 K) U* F
  16.                 call    A20_ENABLE
    # g9 l6 z7 L/ K, D
  17.                 jz      exit1- f/ F. z- u. c" T! Z" D
  18.                 mov     dx, offset msg_ok ) _; A  W' F4 V! v& C6 t

  19. / ~% g  P1 \; h- H
  20. exit1:          mov     ah, 09h
    # v; n6 v8 D# l0 N; t( V1 F( I
  21.                 int     21h
    5 n% m# d* I6 r* ~  w; |. Z
  22.                 mov     ax, 4C00h - O4 Z* F( O0 _( l6 [6 t' Y
  23.                 int     21h # Q4 X  o/ J1 h4 {4 g; J% d3 {+ p
  24.                
    0 \6 N$ S4 ]9 D8 i" a) M3 F; I
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    ! @6 @! E' g8 n: I0 W* B& _" M
  26.                         "2008-07-01",13, 10, "$" 3 C* n/ R( y" F  s
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ! L( ~, k) t: i" k* y/ H1 F; u
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" / f) l, b: w7 a: Q% i

  29. . j3 y& k. O2 D: f4 H8 r+ b
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    7 t, @7 T; w$ _8 G% ~# u
  31. A20_ENABLE: 7 w4 E0 |! ?9 `' ^
  32.                 call    A20Write , C+ I# N- h( ^  g0 U
  33.                 jz      exit_enable
    1 a9 z7 U9 b1 f0 M- U/ ~

  34. 2 T2 F( ~, T9 w! A4 {/ _, u
  35.                 cli                             ; Only need for reading value from KBC
    * k& U  E' L! Y! u: r5 V
  36.                 mov     al, 0D0h " D2 i1 W% q$ I0 q0 ~! T' p# e
  37.                 out     64h, al
    ( x3 r4 j& |3 X
  38.                 call    A20Read - U- k" s( y' ]% a4 b' r
  39.                 jz      enable_int
    3 s( o- n. K: p% I: u/ p& F  w5 \
  40. / G5 V$ \5 q* Y1 H9 b' J- z# w" D5 _
  41.                 in      al, 60h                 ; Get current status
    & m( h8 S+ M7 ]
  42.                 mov     ah, al 7 f- T; V9 J' ~
  43.                 call    A20Write
    4 x" ?$ b# D& S
  44. enable_int:    sti 9 R% H8 o# j! p7 ]0 G
  45.                 jz      exit_enable6 X5 h, J3 a8 t, [  Q. j
  46. ! b$ {) R; `3 m) o
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the % }5 `! a4 g0 M9 z& d
  48.                 out     64h, al                 ; Out Put Port next
    + p, Z6 @5 d8 Z& q+ ~6 I$ Q9 d# Q
  49.                 call    A20Write
    - v2 f3 a/ j8 `9 B7 j! Y
  50.                 jz      exit_enable% i% _! `' z$ c2 r& K7 F" n
  51. ( p3 X7 u+ \" S
  52.                 mov     al, ah " ~, F5 A6 \3 g' L. k
  53.                 or      al, 2                   ; Enable line A20 " i2 K3 d! n- `$ N0 p- x8 B* x7 K
  54.                 out     60h, al
    ( h5 c; M7 J3 _# r6 X
  55.                 call    A20Write : b, l# j0 z/ k; t
  56.                 jz      exit_enable% o" N; a# `0 E: a( c6 w
  57. * y  }# x' O4 Z; Y
  58.                 mov     al, 0FFh                ; NOP
    ; C* v8 L. z& w' Z; I7 p7 k
  59.                 out     64h, al
    % N% u0 Y+ n' Y
  60.                 call    A20Write ; V3 h3 ^6 t" ?6 |" Y# J% h, w0 X2 e
  61. 0 J6 j3 W- \  C" E  d  i! g
  62. exit_enable:          ret + n% K: G1 Y. D+ i' [
  63. $ V0 k$ q; `* N
  64. A20Write:       xor     cx, cx                  ; Reasonable wait * o" _# [5 }# w1 P$ o" u
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ' M! _7 \9 r- M- `
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear & t/ @, P( W7 g7 s: i; i5 j
  67.                 jz      clear , G! f7 M1 \8 a2 S( C
  68.                 dec     cx # p1 n$ n- c" e2 Q, J' \  r# X5 d0 ]! e
  69.                 jz      exit_write $ a0 K" T8 @+ X; R# {
  70.                 jmp     short get_wirte $ R% f% N8 T8 x6 Z7 C+ t
  71. clear:          inc     al                      ; Clear ZR
    - I( L  y. V, Q8 ^( e* W7 z
  72. exit_write:     ret
    9 _7 h: h, p3 W, @# F  l
  73.   A; ]  i2 E/ r) H2 ~: S, f3 y
  74. - p0 L. G6 T0 I7 d" Q* h
  75. A20Read:        xor     cx, cx 2 P( E. J) j5 d. \# |
  76. get_read:       in      al, 64h 9 _" [- ^1 ?1 P: X5 ?+ F0 q( y
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    * ]! j' `0 n, q9 M
  78.                 jnz     exit4                   ; ...
    5 e2 H9 W) i. D; |5 [4 B) l
  79.                 dec     cx   ~! V7 e. }2 m% z
  80.                 jnz     get_read* T7 h& g' P8 o( E5 u5 r' R( |
  81. exit4:          ret     
    * x! p) l+ m; z2 J* G
  82.                
    ( X7 h' |) n' _" r. F6 N& p
  83. end
复制代码
  1. ;A200FF.ASM
    : Q+ Y  F& S7 D5 [7 @* r( G0 N
  2. ; 1 `& c2 L! Z3 W6 a4 d3 e# K* {
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01" x! z6 \9 X. R) Z* T& K
  4. ;       ml A20ON.asm
    - x5 `% V4 h- v$ M6 R4 L% ]4 q& ~
  5. ;
    8 C! M. P' q" a0 c
  6. .model tiny# @6 p3 v0 y  j
  7. .code: C: m4 ]+ x! p* q% C
  8. .486  h) x, k; @2 a! K
  9. .startup
    4 x6 ], ]7 `0 Z* h

  10. ! k& J1 f# ?. o# z- V0 T: D
  11.                 mov     dx, offset msg_author
    0 o% O( ?6 V0 u% X2 c
  12.                 mov     ah, 09h
    5 W  K4 a1 r( B: \) B! w0 R
  13.                 int     21h) q7 Y7 `! |0 v1 J5 o

  14. ( m- h* b' s* s  w
  15.                 mov     dx, offset msg_fail
    % J! X! H. z' s& F4 O0 n
  16.                 call    A20_DISABLE
    - r/ O$ `  f7 C% j) G' p4 W7 U+ Q
  17.                 jz      exit1# O( \$ @+ V: i+ v+ ]  r9 Z" I
  18.                 mov     dx, offset msg_ok
    ( g& c# K8 O+ j7 k5 [+ w

  19. 3 |. T( |7 m' S6 C9 w5 P0 l8 P' p
  20. exit1:          mov     ah, 09h
    7 a5 Q% U9 `- g# R
  21.                 int     21h ) P# P5 t  S, m
  22.                 mov     ax, 4C00h
    % v/ m4 b4 g6 i0 _
  23.                 int     21h
    % u% v$ B# c  h2 a7 z
  24.                 $ r2 n* G6 C+ [: j: V0 L' S/ u
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,) a3 v) ^) H5 t7 B
  26.                         "2008-07-01",13, 10, "$"
    : l$ Z/ l7 g, h; Q, m. e
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    8 L8 ]% `8 j6 e
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" - c: y+ f) f6 w3 u

  29. * d, ?$ r7 m+ n& `
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------( }: V. V) f2 q) g# \& x9 `
  31. A20_DISABLE:
    2 z4 ^1 }$ J& {" ~4 G9 f
  32.                 call    A20Write
    % N6 _8 T5 T/ K) J( L/ F2 H9 b
  33.                 jz      exit_disable2 S0 T3 t- l6 f* P$ t
  34. 3 D" @; C  z- g; l# Y
  35.                 cli                             ; Only need for reading value from KBC * q) A6 u- S- Y! h
  36.                 mov     al, 0D0h
    ( f: g& V4 `! {$ D9 ~1 }4 n3 f
  37.                 out     64h, al ' [/ B1 D: d/ @. N: u
  38.                 call    A20Read " e: t" `2 K" m- j
  39.                 jz      Disable_int
    8 Y) C& c1 X# ]4 g

  40. . Q4 D2 _) N. i0 H0 |- c- l
  41.                 in      al, 60h                 ; Get current status
    4 z" y' E1 Z/ H; T3 ^1 D! e3 N) X
  42.                 mov     ah, al
    & M) E% E- Y3 a) Q: q, L2 t
  43.                 call    A20Write
    8 k% M. G' O2 H" ^  a) x. E' j9 D
  44. Disable_int:    sti
    $ Z$ a$ F( l, @5 b
  45.                 jz      exit_disable" `* b$ R: z3 A  e! n; R
  46. ) \; L4 Y) F1 S! y1 T, X1 b
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the . f: e+ r6 ~) g4 y) g( `* Q1 d) p
  48.                 out     64h, al                 ; Out Put Port next
    3 P1 X5 C2 o& P: R) H- i- O
  49.                 call    A20Write
    * \0 x2 O( @6 S7 G: d; x$ |& N
  50.                 jz      exit_disable
    3 _! n1 i' {+ ?3 {# R4 w# Z0 N

  51. , ^4 k% s5 B, m  N1 ^9 M- n
  52.                 mov     al, ah
    2 I6 ]: S' G% b: L: D0 \, [
  53.                 and     al, not 2               ; Disable line A20 ( L6 r& Z5 X% X8 ^* |% D4 w
  54.                 out     60h, al
    & R$ w* o* C% V, H$ P5 w4 A& r8 l
  55.                 call    A20Write
    1 R) Z+ `5 l* n7 x; z
  56.                 jz      exit_disable7 e% \$ ^' `8 c+ i# e4 F

  57. ( M/ P$ }, D5 A+ o. Z' S: Z- D
  58.                 mov     al, 0FFh                ; NOP
    + W& a; c1 u) V/ ?. S3 a
  59.                 out     64h, al
    , j, [3 |1 P2 B/ z! O* G
  60.                 call    A20Write ( g  P. d) K. N+ J8 I( Q( l

  61. . W7 J: M+ z) l% L
  62. exit_disable:          ret
    + c( N- v. o5 l9 v) a( o

  63. . }. y$ m& V. t
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ; q6 B+ J* q; Z6 \% [1 z6 r
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 2 y: d+ `! K0 F7 V/ N
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear , v8 ]# Q9 t4 H% N
  67.                 jz      clear 5 M3 I, {) |$ A+ T+ ^
  68.                 dec     cx
    . a% [  w4 V! w
  69.                 jz      exit_write * l3 {) N1 I* t* X/ B  @; {
  70.                 jmp     short get_wirte
    ) D" D* y; e$ S& O
  71. clear:          inc     al                      ; Clear ZR
    8 \( T1 B& z3 F- {8 ?; [2 U( x
  72. exit_write:     ret
    ( S. l  s4 S, u
  73. 9 g7 h' R; W0 J" m* O0 U9 o7 K2 j+ U
  74. + ~+ z: b; ]* g; L+ y  y9 d
  75. A20Read:        xor     cx, cx
    8 {( ~, [0 ~! }9 c: H+ C
  76. get_read:       in      al, 64h
    ! P; z: j3 o" m; U' i5 p% G
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    " U7 `& h7 [3 l) Q3 G5 {: ]
  78.                 jnz     exit4                   ; ... + A- t3 O" ~6 c" v
  79.                 dec     cx 3 _9 O# }& f9 x, }, ?) U- T
  80.                 jnz     get_read
    ! S# ]" I/ Y  E- E% ~( v8 \
  81. exit4:          ret     - n' ]1 Y2 g; a) t
  82.                 * \4 Q+ O& i5 S
  83. end
复制代码
  1. ;A20STATE.ASM   W( v/ _9 B2 R: e% ^/ o
  2. ;
    ) o; m1 ~. I; w7 }
  3. ; Returns the status of the line A20 through the KBC 2 [# F1 f8 a5 ^# v1 B5 S! w
  4. ;       programming by bini for debug. 2008-07-013 j9 P6 y" e7 R& U1 q0 w% {3 S9 ?" e
  5. ;
    ! i) v5 w! H8 ^: g- e" C
  6. .model tiny: R: j. ~% _: D5 y0 H" ]
  7. .code
    ) W1 ^, c: J$ X! D" _: q$ {  y( [
  8. .486
    0 T7 k5 g4 ~# [/ Z
  9. .startup! ]7 I  z/ N& G* H
  10.                 mov     dx, offset msg_fail 4 P" i" S3 E( I8 Q! T- I. e
  11.                 call    _GET_A20_STATE_9 o' v5 g+ b, Y* u5 Q' w) H
  12.                 jz      exit1                           ;  was a problem
    # r. t$ F  U) y; ?) j. c1 ?0 n
  13.                 push    ax                              ; Save state, AH
    * ^2 T4 j# Y5 G, f1 P2 }
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem & e  |- e% G# [3 k4 d
  15.                 mov     ah, 09h
    4 ]. U/ t, T3 C. i7 r
  16.                 int     21h                             ; Print message " ^# I5 g5 m8 q0 h
  17.                 pop     ax                              ; retreve state
    & n* y0 Y0 m) l9 g

  18. - ~5 ^* L5 X/ C- e4 s& s- y6 y
  19.                 mov     dx, offset msg_dis * \5 N/ Q7 M& E2 h
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    1 B; H+ e9 Q* `' n1 j' l5 C8 }+ k
  21.                 jz      exit1 : r% f( A5 |4 T: Q% D6 L6 ~
  22.                 mov     dx, offset msg_en 1 E/ b, V9 @. U
  23. ; d6 ~6 i% X9 a. g7 [0 P
  24. exit1:          mov     ah, 09h 5 Y8 b7 S8 ]  @3 s8 [6 R
  25.                 ; DX already contains address of string
    ! n) h9 W/ [5 h! w
  26.                 int     21h ) D+ H6 D" i! U" p
  27. 1 v" J. d* Z. Q; k
  28.                 mov     ax, 4C00h 5 ?& W2 T+ c1 F
  29.                 int     21h / c! Q. p8 S6 g' g0 R- \

  30. * l; z6 ?8 h; t  x) B
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    0 \3 j) H/ y' r
  32. msg_fail       db      "FAIL", 13, 10, "$"
    6 b9 V* h* r6 k2 D
  33. msg_en         db      "ENABLED", 13, 10, "$"
    / n! W- B+ p* ^& R2 O8 o- R% `
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    1 {4 ?# Z2 X# i# n7 h

  35. ; [; t5 ?; F" z  Q) Y

  36. " R4 A+ `8 h# ~
  37. _GET_A20_STATE_:
      w6 b& A# k, O
  38.                 call    A20Write                ; Wait till the input register is empty
    ) p/ Z- p7 ?+ @' b: P2 B2 m' v
  39.                 jz      exit2+1                 ; Bypas the reset int's % U# g; w; L$ O& R
  40.                 cli                             ; Disable ints so we'll get our value * e  ?& G9 \- C( y. s( I: N5 D
  41. 3 F$ _, C0 V- Y  R: ]2 U4 g
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    + S( D+ G) W7 ?" G# j; Z
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 0 z& d9 o8 `4 H' o* {
  44.                 call    A20Read                 ; Wait till the 8042 output register # O: d& z& f7 ?# [* A
  45.                 jz      exit2                   ; has something in it's buffer
    $ U9 k, q+ ?  O8 F

  46. + p; @, H; y, v) H
  47.                 in      al, 60h                 ; Get it ( H8 u, ?* O. }. v
  48.                 mov     ah, al
    4 q7 M, x) O5 _& ~* z
  49.                 call    A20Write                ; Make sure the input register is empty 8 D3 _# E* q) W7 Z
  50.                 jz      exit2 - d. B  O' O/ S. r0 P( E

  51. 7 V. o! K- T- V% X. f
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 7 i+ e1 h2 N! }6 O5 A
  53.                 out     64h, al 2 H1 D* W8 n* W0 b# o$ _
  54.                 call    A20Write 4 y# f( l/ E6 _$ c& M+ `- Q6 Z
  55. 3 T- {& D! v' i  j% p+ J! {' \
  56. exit2:          sti
    : s0 w2 _0 n* T, t
  57.                 ret2 C5 B7 N2 Z7 J0 F6 d0 E
  58. ) ?; L4 X3 p7 f9 U% q- T3 b9 }

  59. 8 Z% j2 S! h; e% A* a
  60. A20Write:       xor     cx, cx                  ; Reasonable wait % o+ s; z! R: X$ r, Q; R
  61. get1:           in      al, 64h                 ; Get KBC read status 0 \/ o9 _5 C( q/ e
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear % h7 }2 Y$ d4 l. ], R( m
  63.                 jz      clear
    + z3 U. [1 U( o5 ?+ v# X7 D
  64.                 dec     cx 3 t! O2 @' o2 p- Z* |
  65.                 jz      exit3
    # b# V2 ^, r) ~$ b; @$ a6 D1 l' O
  66.                 jmp     SHORT get1
    - _) k4 `% h: K# S: S
  67. clear:          inc     al                      ; Clear ZR 1 Y( o) O. o0 ^
  68. exit3:          ret + G4 g( E5 Z6 i/ i9 y
  69. & F4 B$ y9 R  \8 C% w4 ?' ]4 I

  70. # t) o" a# B4 a5 E
  71. A20Read:        xor     cx, cx
    + ~2 h4 [- t6 o% }! ^
  72. get2:           in      al, 64h
    ! |; N" G8 X% k5 K. c( f$ U
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    . j& v$ B6 ?) ^. R. s
  74.                 jnz     exit4                   ; something for me
      N; g" g9 l, M' H
  75.                 dec     cx
    8 Z; d9 w: w' O' Z% N
  76.                 jnz     get2
    ; o7 d1 O# f! L! J% A2 j
  77. exit4:          ret     8 n) U. a7 U; A$ r$ H$ l
  78.                 / m8 p, \! }# }
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()6 A$ D7 G; j, ?4 c# t
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
. q2 P: C2 Q- D$ ^        while(inp(0x64) & 2);        outp(0x60,0xdf);
. C  N# W: }1 i2 K9 a. Z) v        while(inp(0x64) & 2);        outp(0x64,0xff);' G+ K# g+ a, Y% L5 U* _* R
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-19 19:07 , Processed in 0.116763 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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