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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    8 l: L( u% t  t; @. Z5 `& }: `+ i
  2. ;   p0 Q' H) h$ b0 K" q+ @
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    8 S. Z% L' e3 `3 _; {4 K) f) U
  4. ;       ml A20ON.asm
    # _7 a/ x: f- h" S) O" I6 n
  5. ;
    # _0 @5 K7 u0 @0 ^- H
  6. .model tiny, i* S# x$ i0 F3 p/ ]7 [7 c
  7. .code
    8 j/ K2 |0 f: \  V6 @: Q6 `
  8. .486* W: y2 n6 G# [! P; F
  9. .startup
    - z% s  Y' V4 X

  10. : n% x9 U5 ]+ D; [  N, W, j
  11.                 mov     dx, offset msg_author% U. U+ y* i4 |6 J; ^* [
  12.                 mov     ah, 09h5 \2 u9 J" r, z4 Z6 O# Y9 C- N
  13.                 int     21h
    % X' l  m% q1 n% X: V% \+ O
  14. + e0 s  {3 K3 `, J! F
  15.                 mov     dx, offset msg_fail 3 p  \( W2 W, M) P
  16.                 call    A20_ENABLE4 G+ l$ Y4 @# ~2 C
  17.                 jz      exit11 b  D2 y# u6 l" f/ g% G# ~+ R
  18.                 mov     dx, offset msg_ok ! H* H& g* U+ ?2 A3 _
  19. $ E# R! Y- g$ z
  20. exit1:          mov     ah, 09h
    4 U- G8 r9 J6 o7 j# Q. L0 c( ]
  21.                 int     21h + [9 r# F/ G. j, s: s1 N
  22.                 mov     ax, 4C00h 9 v, ~8 s% O- O% X. l4 Y
  23.                 int     21h 1 M: j# \* P' Z: G  r
  24.                
    4 \% B: u! u: S3 Q# i
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,: v9 b: ?0 S3 V1 u0 f1 D2 g
  26.                         "2008-07-01",13, 10, "$"
    + P( [  B6 o* Z) M3 A0 R1 f1 x
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" . n, ^6 N0 {' G8 A+ Y
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    - Y, U( v" o$ w' z0 P
  29. / u2 }) X! R+ j0 ^- _3 n' a
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------7 c6 J! s# Z4 q3 s6 u
  31. A20_ENABLE:
    " W) h- x7 v$ P" d
  32.                 call    A20Write
    ' d7 S8 m, n( f
  33.                 jz      exit_enable0 a  `% T* j# X+ S. L) J' j7 U
  34. + X' H/ l/ s# D# J5 ]4 s: U
  35.                 cli                             ; Only need for reading value from KBC
    1 i+ C& [! H# h$ w+ N
  36.                 mov     al, 0D0h
    7 T- C* V; a; }
  37.                 out     64h, al
    9 r7 N! A/ v: ~; m, t, K, [* f
  38.                 call    A20Read 3 V8 b9 ~: \7 s
  39.                 jz      enable_int 3 o! J1 G0 i2 \; `

  40. / d9 ?) L3 _3 V3 }+ f. V
  41.                 in      al, 60h                 ; Get current status
    . r2 p! z) X8 P& H+ \0 O
  42.                 mov     ah, al
    . \; ?6 V  p/ t
  43.                 call    A20Write ( ~' l% d' {- k' n9 F! \
  44. enable_int:    sti
    - n4 Q0 Y  a5 D  a3 M3 b$ }
  45.                 jz      exit_enable4 \8 P% J3 F  Q/ x/ a8 A  a

  46. 7 S1 @9 v- k  c1 [
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the / l) Y  ^7 V# d: l, p' R7 I
  48.                 out     64h, al                 ; Out Put Port next ; A& b' _& ]4 U! {, D
  49.                 call    A20Write
    , z2 B; l  h) b+ S
  50.                 jz      exit_enable; H; B; L+ p* y1 @, j, N

  51. 5 C) A. L* `% N" j
  52.                 mov     al, ah
    9 f) B5 j" i2 {" T6 m  ^
  53.                 or      al, 2                   ; Enable line A20 1 i+ V# c/ r  |0 j( H; N* A" [
  54.                 out     60h, al ' v; D& _' S1 e+ _: {
  55.                 call    A20Write
    5 Z% l8 o1 l4 H0 ^6 ?/ S& g! H
  56.                 jz      exit_enable
    " e% L  A) [- @) j. R
  57. - K* K. X, d# \2 J, F+ v  P
  58.                 mov     al, 0FFh                ; NOP
    6 a! |6 H( J' V3 w8 f8 r" L7 _6 U
  59.                 out     64h, al
    . @. l; S  O$ o/ g. u" G( c$ {' |7 U
  60.                 call    A20Write
    + b# c; E' v+ z

  61. ; Y% u  }" G# C2 s" ?" c
  62. exit_enable:          ret
    ' r- @3 z5 N7 D5 v
  63. 1 q. W$ Z1 U; z' X3 |
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 2 D' M, \+ B! t; i* ]: g( g. @
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ) y! }3 i+ I7 c/ R# Q& ]0 T* L1 s; t
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    5 }$ N, n( f9 M
  67.                 jz      clear
    $ ^# U/ b/ H6 }8 a( @3 b
  68.                 dec     cx
    : U3 L# y9 G3 b$ T4 p/ A! f$ [# ]
  69.                 jz      exit_write 7 o0 y/ l) K. o# c. s; h  G; |
  70.                 jmp     short get_wirte   L' U4 _! N: H3 I) ]
  71. clear:          inc     al                      ; Clear ZR $ ?- \: Z; V" s6 C4 y6 @# s: g/ h
  72. exit_write:     ret
    3 b; R! Z6 m0 x% h8 {) o) ?
  73. . t/ B: h6 C/ v% \
  74. ) M; f, M5 `$ J) K1 u9 M7 T
  75. A20Read:        xor     cx, cx
    " Z* W4 F* A# f! Z& Z/ Z2 C8 i
  76. get_read:       in      al, 64h
    9 ^- V, q' t+ q/ Y/ R6 h$ a
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 6 c: G3 {) ]" I$ L% O9 t8 V1 k( t
  78.                 jnz     exit4                   ; ... + j' ]) U6 k1 T+ D2 c
  79.                 dec     cx $ l( C9 K+ h6 w* f, ?
  80.                 jnz     get_read
    ! x" A! O9 |9 }" h& E7 l5 y
  81. exit4:          ret     / |' I; A6 b: a, G0 z' E! m, f" |
  82.                 7 w& ]. y! O7 O
  83. end
复制代码
  1. ;A200FF.ASM
    ( h2 q$ @8 X, f0 t2 c
  2. ;
    3 {2 Z' I. s$ R9 D! G/ [- y" T# L
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01. l# [6 F, l$ H! B  o4 M4 g
  4. ;       ml A20ON.asm 6 |* H9 J) m- d; ^+ x6 w) g7 x
  5. ;
    - n( }8 N" G, @
  6. .model tiny
    * E, e8 N% ?4 l
  7. .code
    # U8 ~* j- j* D0 H! y
  8. .486/ d5 A4 V; M; I; g) k, I7 N
  9. .startup2 Z7 _. E# P/ c
  10. 3 z" L3 W: ?2 x6 K; A% k
  11.                 mov     dx, offset msg_author* G0 P; _% [: u7 p7 j8 E. x
  12.                 mov     ah, 09h4 ~( j) N6 A$ q! i6 L0 i
  13.                 int     21h# o0 \. x; p; M7 b
  14. : Q/ U. Q, }2 |& |
  15.                 mov     dx, offset msg_fail
    2 O3 I3 B$ k8 b- @( N8 Q
  16.                 call    A20_DISABLE
    , B, @: v$ b6 S8 j% s7 Q* p
  17.                 jz      exit1
    7 `' B. u" g2 `
  18.                 mov     dx, offset msg_ok
    ; A4 T( |, v; G! I( [2 k

  19. : M; I+ w. L8 O& F0 \
  20. exit1:          mov     ah, 09h
    + K! z) L! v% E8 L+ ?- v( ~0 o! `
  21.                 int     21h : j. r/ Q5 c5 i2 Y
  22.                 mov     ax, 4C00h ! h# W6 `' \6 T# U* j5 \
  23.                 int     21h : ]; t8 |5 y5 u: z' ^
  24.                 " I4 F0 G) j$ t' `& ~5 \
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    / H) }1 U; `, Q% T  p! |$ T( A
  26.                         "2008-07-01",13, 10, "$"
    0 N. J( S9 \0 N5 {' I8 ^
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    5 r# \) V% J7 e( @" \3 @: r' A
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" & e( e* L+ [% J, C. O& {; f
  29. % M# l" [1 j+ K# t: V
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------( x: G1 ^* z% k2 S7 q+ ]; o1 e& V$ N
  31. A20_DISABLE: ! N6 C& P. U& H2 w. \
  32.                 call    A20Write 0 {% b* ]9 l8 {4 H
  33.                 jz      exit_disable& c+ g* K0 y. l& o

  34. 3 a) K$ I. a  P5 i4 g
  35.                 cli                             ; Only need for reading value from KBC
    . W+ _, A) P$ n- E9 o' k
  36.                 mov     al, 0D0h
      ?9 W3 Y- M3 _0 j
  37.                 out     64h, al 8 @4 [! N6 T' h' L, [
  38.                 call    A20Read
    7 }# X: Z3 T3 y, R9 b' [; t
  39.                 jz      Disable_int
    ' Z1 ]. s$ y& ^
  40. * n# Y7 u, q9 J% U! c6 [4 c
  41.                 in      al, 60h                 ; Get current status
    $ H! k7 x. z" g2 r: P) ], e
  42.                 mov     ah, al
    ! o/ g" t' @) ^) p5 m
  43.                 call    A20Write . {0 r0 M  q; n! {$ r) a& i9 i
  44. Disable_int:    sti
    ! B. k3 D: T6 Z# ]/ _+ R2 E
  45.                 jz      exit_disable7 R+ `) {3 A2 {# l7 Y

  46. . G. g0 x! [: s& J4 R  Y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    4 G+ C( B( i9 m2 q: v+ I
  48.                 out     64h, al                 ; Out Put Port next 4 N4 p; L0 b" E" L* T
  49.                 call    A20Write
    ( X0 I$ N4 g' `# U9 ]
  50.                 jz      exit_disable% ?9 j4 N) `4 X+ P  y* Q" j5 Q( y) Q
  51. $ o) ~8 J: i+ A5 i2 w) K, r' r# t
  52.                 mov     al, ah
    ; f: C3 _$ M/ }! d0 U
  53.                 and     al, not 2               ; Disable line A20
    / L& o6 Q4 b; g' @, A. @; U
  54.                 out     60h, al * u+ t( [- |" @$ q+ ?
  55.                 call    A20Write 8 i$ ^0 g$ V4 L
  56.                 jz      exit_disable0 b) Q; @/ d& T6 Z# _) v

  57. 0 a& t2 k% s/ X$ A9 D
  58.                 mov     al, 0FFh                ; NOP ! r. R6 t4 F4 R9 J2 N! V
  59.                 out     64h, al
    ; r" N) k# d, `; s* o* r5 v
  60.                 call    A20Write 5 o8 ?* F9 U; R& s& T! D
  61. # G. k0 Z' x& G0 h5 V
  62. exit_disable:          ret
    4 G. j1 Q3 }& b4 ?" F- v! g) B3 G
  63. # o1 |* j- j. B6 H& Q2 q
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    6 i8 G% b! I+ A- j5 j1 Q
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    1 b5 ?" i9 ?$ R$ L7 `) A
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : {! _( |! L3 a3 r0 ~
  67.                 jz      clear 0 O& n$ q& r+ l% ^! b
  68.                 dec     cx & U- n) d# C% V; n; c9 s: |
  69.                 jz      exit_write
    1 v- X; q/ ^$ r$ t( V. l% E/ q; H
  70.                 jmp     short get_wirte / i6 x7 z: }. F2 k# D- x3 n
  71. clear:          inc     al                      ; Clear ZR 2 o( b) J# g" N
  72. exit_write:     ret & w% o: G: q3 e
  73. 6 d5 K7 e! o/ m! l: D
  74. ( T( d* ]1 K8 W% j3 D
  75. A20Read:        xor     cx, cx 0 b2 y4 \" G/ |9 d7 U8 S" \7 D
  76. get_read:       in      al, 64h , I( H+ T  m! _7 h5 x' v" C5 }
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    7 j2 x1 T! o6 ~; ]* z) @
  78.                 jnz     exit4                   ; ...
    " q* E" q$ ~; K& ^+ w5 @$ m; }
  79.                 dec     cx 6 W; J( d2 ^8 h, b
  80.                 jnz     get_read
    1 `7 m, K) @; k+ \6 n
  81. exit4:          ret     : {  o+ O% z5 a" w4 ]* Z
  82.                
    1 w  ^: F* v; U$ h
  83. end
复制代码
  1. ;A20STATE.ASM * H/ q8 i# x) N8 I
  2. ;
    * K+ L) ]5 `5 e% J
  3. ; Returns the status of the line A20 through the KBC
    ' w* |1 B) X8 O7 A
  4. ;       programming by bini for debug. 2008-07-010 q' z  N7 O# F* T( J0 ~0 n
  5. ; 6 @  F& @4 u9 L( ?- M" @, S( r1 z
  6. .model tiny
    2 ]! R5 [' \( `; f- D
  7. .code0 |. C1 V4 e$ P% l0 U
  8. .486: r* D& ^$ g8 _+ ^3 `, L& s) F
  9. .startup
      d7 V& \/ x+ c
  10.                 mov     dx, offset msg_fail
    - X. t2 B* v" Q* a8 J
  11.                 call    _GET_A20_STATE_
    " o; \* j. i) Q8 Y/ M/ q0 B) Z+ H
  12.                 jz      exit1                           ;  was a problem5 I: L( C1 @& x% j4 \! [
  13.                 push    ax                              ; Save state, AH
    8 d+ b7 g6 D+ b1 f' a. }' |
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    3 ^& B3 d+ P6 g
  15.                 mov     ah, 09h + Z5 ~, t" g; A; m0 }
  16.                 int     21h                             ; Print message + e7 M& r( V& j' g; V
  17.                 pop     ax                              ; retreve state
    : I! _; Z, N5 l7 Z3 S# {
  18. . T  X, k6 J# }' s
  19.                 mov     dx, offset msg_dis , t1 Q1 g( C" A0 [0 _9 _% M
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 3 c! E. t/ |- `( a! }# j
  21.                 jz      exit1 ) a. r1 N0 C% y& B8 K
  22.                 mov     dx, offset msg_en - h. l' l! c) P
  23. 9 r, s; L5 e" U) ^8 X
  24. exit1:          mov     ah, 09h 4 T# E6 C- l6 Z7 H' o
  25.                 ; DX already contains address of string 4 s$ \* k( p$ @% C# }5 C. r) ?
  26.                 int     21h
    - d4 q5 f1 @) K' p

  27. & x1 H9 ~8 K0 W+ [9 m5 t$ j! L
  28.                 mov     ax, 4C00h
    / `6 ?9 V3 P% M1 r, Z9 Z) \
  29.                 int     21h
    ' d5 k$ s: E6 |3 {' B$ |% k. E: ~

  30. . f0 k1 {0 R- E5 L- n3 H: ^
  31. msg_ok         db      "OK", 13, 10, "A20 $" 3 d7 ~# {! g9 z& ^1 U
  32. msg_fail       db      "FAIL", 13, 10, "$" - D+ P3 m6 |! J! E( F( ]" b# h2 H
  33. msg_en         db      "ENABLED", 13, 10, "$" / w" I6 B$ x/ V6 ^+ O0 r% J
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    $ m% Z/ D) H( p- L2 K1 k* o

  35. ) U5 ]5 S$ I$ o. M% S$ X
  36. / F8 p2 b- z" r/ ^% U
  37. _GET_A20_STATE_: + X" i  p  V5 d7 v! X* G
  38.                 call    A20Write                ; Wait till the input register is empty # [$ L! S, c8 a3 r/ u
  39.                 jz      exit2+1                 ; Bypas the reset int's
    8 d. n% K0 Y; G/ f
  40.                 cli                             ; Disable ints so we'll get our value & X- |5 ~& I# o' ~4 J

  41. 7 `; {! U3 s+ |$ ^8 r
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    % G' |9 M6 u# b' y$ {: `3 O: \$ i( p* _
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port " p/ K% c6 T2 A* A3 M5 I
  44.                 call    A20Read                 ; Wait till the 8042 output register
    % ?& P% g3 S: Q+ y
  45.                 jz      exit2                   ; has something in it's buffer 7 C. v% X. `4 {+ t

  46. * r( a( J5 T! J
  47.                 in      al, 60h                 ; Get it
    " Q: A: N3 E% S* n, R% |
  48.                 mov     ah, al . y* T5 V7 r( R: C
  49.                 call    A20Write                ; Make sure the input register is empty
    5 g+ M* v, o- v, |- K+ W' S
  50.                 jz      exit2
    ' D2 p0 Z/ L. i3 G( u1 p

  51. 3 R- D, r- o) Y
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing $ k% G  D' X( V" I8 s2 `
  53.                 out     64h, al ! l1 e, G4 R: q& T0 |* {- |7 W% o
  54.                 call    A20Write
    $ j& f* `! A# t( B* x  b; ~

  55. 7 K7 w2 x$ i1 h! K0 \6 C
  56. exit2:          sti 7 e& v  P: N, p! J6 W
  57.                 ret/ ~7 u  d3 K' x; W0 ?2 N
  58. 9 d0 Z9 Y: f  R. W7 T' a8 A

  59. 8 U8 w9 g( u+ d* {# R
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 t2 C* X3 l7 \3 x
  61. get1:           in      al, 64h                 ; Get KBC read status : L" a6 y8 Q; W+ h/ a) n8 D
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    , [: X: m5 g5 j! p& g3 E
  63.                 jz      clear ; E" M1 g/ ~" F/ j% i; w+ Q1 c9 j1 Z# K
  64.                 dec     cx % F7 n) @: }) w
  65.                 jz      exit3 & q0 g3 R+ |3 ]8 y! b$ `
  66.                 jmp     SHORT get1 9 [4 F) E) J: q- ^# `  d% c
  67. clear:          inc     al                      ; Clear ZR
    ; I$ n( i0 a, c( J+ h; o
  68. exit3:          ret
    ! G4 j0 ?8 j  _. X6 c$ ^: @& c
  69. * v+ d9 C4 n0 P2 F( t
  70. * P  I  }& w* W& k4 q" Y3 {8 }
  71. A20Read:        xor     cx, cx
    2 g! g7 q; e+ d2 y0 K+ ~: ?% @
  72. get2:           in      al, 64h 7 F. C) @; C, T6 j' d" r8 Z
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( a* d/ a. y+ ^8 w2 D  l' l. T( C
  74.                 jnz     exit4                   ; something for me
    9 M7 N9 x) F2 a: l' |0 ]+ p1 t
  75.                 dec     cx 8 c3 ]) l3 U; ~5 o0 ^) f+ H- [# S. c$ I
  76.                 jnz     get23 B" L. b# g- e) [
  77. exit4:          ret     / y2 n0 g6 r5 `8 C; Y
  78.                 # i$ y5 }' F" b6 E
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()5 \! R( F8 q5 t* d2 c( p6 w* I1 \
{        while(inp(0x64) & 2);        outp(0x64,0xd1);; F2 F. |5 t  X; i6 l8 g! e
        while(inp(0x64) & 2);        outp(0x60,0xdf);1 R! X; u. t* m/ z( t
        while(inp(0x64) & 2);        outp(0x64,0xff);
, x! x3 p% _- J  }7 O' f2 K: Y) M}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-8-11 17:00 , Processed in 0.047769 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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