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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    1 @. `- z- }6 R: D1 h
  2. ;
    1 Y4 f; n+ A/ H: I2 `
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    , ?# B6 j, }8 g
  4. ;       ml A20ON.asm 0 ?. G2 m9 \) `# y4 Z
  5. ; . u* |8 y6 k) f  h7 r
  6. .model tiny8 h1 d0 W# ?, u7 G9 C/ E9 k. ?
  7. .code& `- Q' I$ Z9 p1 x5 X- A1 {5 ~
  8. .486
      b# Y( A9 i; q1 b  y
  9. .startup
    " r; @5 M8 }2 d5 T" |
  10. 2 z# R6 F' T- M5 d
  11.                 mov     dx, offset msg_author. |1 a2 Z  j6 g4 \8 @: L2 G, V
  12.                 mov     ah, 09h$ P- u! e# x# [* y9 C
  13.                 int     21h  r" l4 i4 \& W. Q! [4 i4 s

  14. 2 f: m6 Z  c& x3 v9 E% V2 ^) u! }7 X" I
  15.                 mov     dx, offset msg_fail + y" _/ R$ V( B  }
  16.                 call    A20_ENABLE
    / t6 C( j% i7 ~' J
  17.                 jz      exit1
    & X' M' F, Z5 R# [3 L
  18.                 mov     dx, offset msg_ok # l" |9 D% i; A* O  R! \6 b/ d

  19. . Z. _$ L; o. ?! n8 }- k3 C; W& |! f
  20. exit1:          mov     ah, 09h 9 d( }) Y. Z% q5 O
  21.                 int     21h
    ) w0 Z% T1 |! V1 O5 K% v
  22.                 mov     ax, 4C00h ' S8 v8 I- @0 [5 F3 u' P3 {
  23.                 int     21h
    " d) M& t1 D8 N& @7 Q6 Z! ?! H: k# h
  24.                 7 |" k* W( L; Y; K: }4 G. q8 ^% a) f& _
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,, v' E3 ~( L: j$ x
  26.                         "2008-07-01",13, 10, "$"
    * m$ L: b$ y" s; x/ n6 h
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ; S  G7 h) @6 f- |! p
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    0 V0 U7 S* I8 }$ n' `4 w( ^' L
  29. 4 c0 d* @5 X# K$ Y7 v. N9 E; H
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------8 ^& H3 H* ]* c0 u# R& l
  31. A20_ENABLE: , g" h2 [  s: ]
  32.                 call    A20Write : H7 d9 A  J% W) v
  33.                 jz      exit_enable
    + f3 }4 J3 M% w# K4 z, X, w

  34. $ \5 O: f* E6 |" y1 Q4 X$ {: M9 N
  35.                 cli                             ; Only need for reading value from KBC
    & b& r  c. c- Z: F! Q
  36.                 mov     al, 0D0h
    9 c# B8 g. A# s
  37.                 out     64h, al
      N7 }8 i6 g6 O1 u( ?
  38.                 call    A20Read : Y* G5 l6 {( W3 u1 g3 H$ G! @
  39.                 jz      enable_int * L4 v  I! N6 c$ v4 G

  40. : \! I9 `/ }6 W' o1 w  D8 {
  41.                 in      al, 60h                 ; Get current status
    . G) l" Z  ]5 b* F; ]
  42.                 mov     ah, al
    5 u( d. a/ k3 c3 s: v6 q5 p4 u  o
  43.                 call    A20Write
    " S3 p+ y" b& n" P( N- r+ |
  44. enable_int:    sti
    + u9 f1 b* a* w8 }
  45.                 jz      exit_enable
    9 F3 l# w8 H: ~+ C# D

  46. " H, {) L7 O; ]7 @9 J
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ; c  f7 K$ S% Q  S
  48.                 out     64h, al                 ; Out Put Port next
    $ ~: s$ R  L: m' ]
  49.                 call    A20Write
    ! ~1 a9 i# L% S3 g! X+ L1 e
  50.                 jz      exit_enable; h; X8 T& D- M- [" C

  51. . p8 }) L- ?% k9 y5 P
  52.                 mov     al, ah 2 l% r' N% M4 W& v* P' h1 V
  53.                 or      al, 2                   ; Enable line A20
    0 v" `$ {! Q/ W
  54.                 out     60h, al . N2 C0 n2 O" L" t* k; l
  55.                 call    A20Write * z7 _9 K" ~# ?8 ^) P) m& B5 D
  56.                 jz      exit_enable0 j; c$ U, i9 u9 q/ h0 a

  57. 8 H) l3 }6 H8 K  Q
  58.                 mov     al, 0FFh                ; NOP 9 s* p  H6 Y) o9 L# z" P
  59.                 out     64h, al
    2 d9 j  K- t7 U+ t
  60.                 call    A20Write # h- A$ Q- j7 R9 Q
  61. 7 ?8 O+ w0 e$ J& U. Y- _
  62. exit_enable:          ret
    : X1 e4 s+ K- a+ q, h3 D
  63. " S* b1 u% |6 A- ~
  64. A20Write:       xor     cx, cx                  ; Reasonable wait & j4 i% |) W# Q
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    9 u" ^5 ?2 a; W/ t- h0 R0 O1 c' x
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ) I* r/ O: }" `' A/ C
  67.                 jz      clear
    8 l( {9 w& p- w; a  G* s
  68.                 dec     cx
    ' ]+ ~' }; B2 g. |( G
  69.                 jz      exit_write 8 A9 ~; ?# T% a% r9 ^, i
  70.                 jmp     short get_wirte
    % k# a8 Z# n1 o% V
  71. clear:          inc     al                      ; Clear ZR ( f8 C+ p( D1 h8 C, j- L
  72. exit_write:     ret
    : }( W  x" K% P2 G" j4 `9 F! M# f* f7 [

  73. 7 W. s# Z9 I( ~8 m# n
  74. % D' _4 J- t# K9 A1 O3 i2 l
  75. A20Read:        xor     cx, cx : j! {* t. r+ x$ G9 ]6 o7 u
  76. get_read:       in      al, 64h 4 _( ^( {  T* N3 b! C
  77.                 test    al, 01                  ; If the 'output buffer' is full, has % m  \9 s3 }3 j1 _1 {$ r# t
  78.                 jnz     exit4                   ; ...
    ) z& J% j4 C0 G  b4 n" J4 }
  79.                 dec     cx , [, f* U! R$ q; N: D
  80.                 jnz     get_read
    5 K. r2 r& G  h2 }# ~( Z0 w2 @
  81. exit4:          ret     
    4 L, A" r- k) C. \  S: v  f
  82.                
    & [: t% n6 X' G1 b+ m& e
  83. end
复制代码
  1. ;A200FF.ASM 6 J1 H6 ?0 l: f; j
  2. ; 1 }- n, i; e2 a
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01% s, ]: ?8 Z( D& j0 t2 N3 l6 N, j0 Q
  4. ;       ml A20ON.asm
    3 B2 r! e) _" y' j; G% \3 ]( f( p
  5. ; ) Q6 V9 x8 d" [) f& f* c
  6. .model tiny  p# D  \% ~2 D5 T5 g
  7. .code' ]* p3 d& e& T
  8. .486( S& d+ P; b5 z0 U! H
  9. .startup3 p# f+ ~% F6 @7 Q; o5 |

  10. 5 ?; k1 }, r! F& C  H+ I
  11.                 mov     dx, offset msg_author& P# W, s3 |6 e6 F
  12.                 mov     ah, 09h
    6 D( h6 |  K6 g1 Q7 A# ]+ l& w
  13.                 int     21h
    ; O/ p9 A9 ]" R. N& u" k: {, o

  14. 3 M6 _) T9 S$ h, C2 O9 Q5 m. A' U
  15.                 mov     dx, offset msg_fail
    " G1 Z6 R" l6 v3 B" j5 r- f+ f' d
  16.                 call    A20_DISABLE9 y5 `5 s% B: @. o- l! F: D5 v5 ]5 ?
  17.                 jz      exit1
    . v$ L5 g, j0 r  e) n
  18.                 mov     dx, offset msg_ok + W& Z- Y" P' u, ]5 M* C2 ]9 H

  19. * a( V* o! F+ Y1 J7 x) b8 _" B
  20. exit1:          mov     ah, 09h
    9 c* ^7 z) G0 p- ]2 e' Q/ v
  21.                 int     21h 7 E/ x4 ~% n+ s( q2 D
  22.                 mov     ax, 4C00h ! r$ g1 z2 F) H2 w/ b
  23.                 int     21h - j4 _9 V1 d  ~/ k+ r
  24.                 9 h- Y8 _( m" r, V1 a
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,! v) u- G0 J9 Y4 z
  26.                         "2008-07-01",13, 10, "$" 7 D0 b" w' {7 Z
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    * w3 `7 g$ [$ o/ T% k
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
      x% [# s+ K. z+ @7 j

  29. 5 Q9 p- Y# ^% |$ J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------* C6 U1 g0 v: D: \8 w5 @! m* [) Q
  31. A20_DISABLE: ) ]$ H- L& w* K" B/ _
  32.                 call    A20Write 1 _  a6 x- O/ @; |7 ?
  33.                 jz      exit_disable
    ' C& J% e0 [( {7 ~: h" h

  34. 4 n6 h/ F; Q: v& _+ k- A
  35.                 cli                             ; Only need for reading value from KBC ( m- `; X: z4 V' U: u4 L& J
  36.                 mov     al, 0D0h
    . L9 \( q% ]' K4 I0 T0 i
  37.                 out     64h, al 1 u! g; L" f8 Y" K- x" z8 b
  38.                 call    A20Read
    , f$ u* W. C+ S2 y
  39.                 jz      Disable_int
    , T3 B/ f+ N4 k+ B* c* |, F2 q

  40. 7 e  Y1 V! V# y  H
  41.                 in      al, 60h                 ; Get current status
    % t; t0 D- h$ T' R0 x# Q
  42.                 mov     ah, al
    : ?5 K' k5 b# x# w# X
  43.                 call    A20Write
    6 e& m/ ~9 ]9 @+ w# C
  44. Disable_int:    sti
    9 H" p% |/ t: ]" A6 P) M. ]$ ^& q
  45.                 jz      exit_disable+ Q0 }8 n' h% z$ ]" e0 U  ?

  46. ' Y" \) p" l3 R9 p- \( h
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the # C1 S8 f9 E3 c" L
  48.                 out     64h, al                 ; Out Put Port next
    3 f( N' {2 B6 p1 p8 K& X
  49.                 call    A20Write & ?; {/ U$ X% E' e/ t  q4 P' v
  50.                 jz      exit_disable
    3 ?- W- y0 C8 J9 y5 s
  51. 0 n' f1 V, r1 {# `2 V
  52.                 mov     al, ah " C% [( E" e2 R- g2 o+ L
  53.                 and     al, not 2               ; Disable line A20
    7 j9 T6 U3 R2 m% l
  54.                 out     60h, al * k# Y) V* u# e: R5 X, _
  55.                 call    A20Write
    4 M, T  Z& X! k& a
  56.                 jz      exit_disable
    " ^8 m, Y# Z/ O

  57. * b$ n4 W% ^7 }  {# \3 k( F3 h* k
  58.                 mov     al, 0FFh                ; NOP
    5 }' M8 |! Z0 u  r
  59.                 out     64h, al
    7 N8 j/ t+ f! U0 x% [# |
  60.                 call    A20Write
    ( U" e3 _- `0 T! s2 y+ e% b( X
  61. * e6 z7 k5 Q% Q+ C- f: U6 L
  62. exit_disable:          ret
    7 z) _8 V$ _, U/ V( Q; `* F

  63. ! w! [0 C: X! G# ~+ O7 K
  64. A20Write:       xor     cx, cx                  ; Reasonable wait / k1 F" K* K; ]
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ( z* L, ~) L2 G9 w) H$ f, M) d
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 3 e) P# `4 e2 {; R
  67.                 jz      clear
    + ^0 ~% a' C* {* g7 Y$ Y
  68.                 dec     cx 8 w; z0 i! M: {) w% T
  69.                 jz      exit_write 4 `" g/ t! Z1 Q& t( Y
  70.                 jmp     short get_wirte
    7 Y! ?9 Z* V- f
  71. clear:          inc     al                      ; Clear ZR 4 p0 k/ l  ?6 Z; ?4 R/ X: h8 w
  72. exit_write:     ret
    4 i/ k: K, y( ]( [% h' g4 Y# K) _
  73. , F  @  ^9 b; i

  74. & E" q' _) @$ ~' w7 F
  75. A20Read:        xor     cx, cx
    8 N. Q1 d9 j3 F
  76. get_read:       in      al, 64h ) m' ]3 w' R9 i% g# ~5 L5 [
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    : ]* k. u: O; [0 j' q
  78.                 jnz     exit4                   ; ...
    & W# O! n: a/ u7 L
  79.                 dec     cx
    & A5 M& c/ z& W* F3 q
  80.                 jnz     get_read
    ( F3 f' T5 K' |  R7 D
  81. exit4:          ret     % p( Z8 Q' v- m. Z% \" E; r
  82.                
    : H) D4 ]) A! `8 J
  83. end
复制代码
  1. ;A20STATE.ASM / B0 z, e, g+ I" K/ F
  2. ; . {! z" K4 d! b$ ~  e% Y4 Y" {% I9 `
  3. ; Returns the status of the line A20 through the KBC 0 O% N% n) P' n* D) n
  4. ;       programming by bini for debug. 2008-07-01
    , T0 l( N$ q" x0 |9 R* Z
  5. ; : @% |' N  G5 Q4 K3 l3 k4 ]# P% P
  6. .model tiny# ]" U7 h0 H5 |& o8 U
  7. .code# {/ {8 B! M$ k3 y( R* u9 S
  8. .486
    1 f4 @- S$ @  h- q- ]8 ?% d( [3 u0 {- p
  9. .startup; ?, {/ d. O9 a& S8 j, t
  10.                 mov     dx, offset msg_fail 7 U; D, a& w+ c4 J5 i
  11.                 call    _GET_A20_STATE_
    0 Z4 l2 f' i+ p1 {
  12.                 jz      exit1                           ;  was a problem; o( R: L* a- }
  13.                 push    ax                              ; Save state, AH % J# J1 D  P2 c
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem * k; u2 P, W4 h7 U$ }
  15.                 mov     ah, 09h 5 o/ l  R! @6 g* \" W) E
  16.                 int     21h                             ; Print message
    7 K% i$ w/ d: P6 R* B  K
  17.                 pop     ax                              ; retreve state
    9 {8 j7 F9 _7 ?6 P1 S6 a

  18. * E1 `* t8 F+ f. v7 ~
  19.                 mov     dx, offset msg_dis 8 T( U* A8 i8 r/ c! Q
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 5 u+ v& t2 `+ G7 z* f- p5 e
  21.                 jz      exit1 / U$ v) m" f9 ]4 a7 b& }! P( O
  22.                 mov     dx, offset msg_en
    : b) Y. b/ W; t' h( r" Z$ }

  23. : {6 B# @0 M% @9 a7 z
  24. exit1:          mov     ah, 09h ! a, R& O8 Z4 }; H* U" `
  25.                 ; DX already contains address of string
    - [8 `1 s8 y% O: A8 o
  26.                 int     21h
    1 [( @) }1 `% D' L4 w, _

  27. 8 `# a- n% d) b. m5 H3 K& `
  28.                 mov     ax, 4C00h 5 m3 m: u7 p$ W
  29.                 int     21h - U( i7 v3 b1 A

  30. ) W+ b6 `8 I- H
  31. msg_ok         db      "OK", 13, 10, "A20 $" - q5 b! n- T% X/ \3 I$ e* K
  32. msg_fail       db      "FAIL", 13, 10, "$"
    9 |$ W! e( o( Z, B
  33. msg_en         db      "ENABLED", 13, 10, "$" 4 _! y2 i% d0 r/ l1 J
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    # _5 l6 b* `0 `4 K$ ]( `% I
  35. 4 H# ?3 V* ?+ `  h. T1 ?1 L
  36.   {1 J& e. |7 ^5 n$ ^: d# b
  37. _GET_A20_STATE_: 7 V" Z  C9 n/ `
  38.                 call    A20Write                ; Wait till the input register is empty % m. I, j2 D1 P; `! q
  39.                 jz      exit2+1                 ; Bypas the reset int's 8 G  @! s3 J: A7 B
  40.                 cli                             ; Disable ints so we'll get our value , i" t" H  ]2 ]) H8 s
  41. # n8 l: H$ y0 N# X
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    & M. O/ h" y& ]: r
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    ! |3 N8 J$ v9 {
  44.                 call    A20Read                 ; Wait till the 8042 output register % A4 d/ U, h$ p% D
  45.                 jz      exit2                   ; has something in it's buffer
    ' L# `( ^& @+ f( _

  46. $ D5 D, a) @0 \# q( F9 E0 C, ]2 v
  47.                 in      al, 60h                 ; Get it
    ! O( h9 L9 e! S
  48.                 mov     ah, al
    8 U1 p5 X5 x* ?* B
  49.                 call    A20Write                ; Make sure the input register is empty ' k% R! f& C& Y9 I9 n& g
  50.                 jz      exit2
    * V/ j0 i& T7 v1 j/ V

  51. 2 t3 E2 {6 O. V- d
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing + ^- f- w2 j, l) g9 A  O, D8 S
  53.                 out     64h, al
    . ~+ ]$ a& Z$ A4 ]8 m" {
  54.                 call    A20Write " |/ q) E, [8 U& e" j: K

  55. % m  i6 a6 B) R
  56. exit2:          sti ) @. F0 H. R& e6 n
  57.                 ret8 {$ f3 q6 Q" ~% n" `

  58. 3 `0 i4 E# f  @6 s$ W

  59. + H% t8 m; u9 s8 i- J0 k
  60. A20Write:       xor     cx, cx                  ; Reasonable wait / s1 K% h1 z& J% _: g
  61. get1:           in      al, 64h                 ; Get KBC read status , s: P* n0 M) a; g2 Q: m# ~2 o
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear ' _  \8 S0 P1 Y5 O1 a+ l1 a5 @
  63.                 jz      clear " H- }6 Y3 a, e& l" ?- M/ j+ b9 d; q* h
  64.                 dec     cx
    7 G0 E, r" R  K$ P' i" ^
  65.                 jz      exit3
    0 H( g% S5 r* V( N) \1 @
  66.                 jmp     SHORT get1
    2 E4 G  W4 m* Z: L
  67. clear:          inc     al                      ; Clear ZR 2 v6 A0 {  d" g
  68. exit3:          ret , t: P4 Z% F& s! w
  69. 5 \/ Y2 j- b( F, Q4 Z9 K! @  i
  70. - O: h# Q3 D' S: e
  71. A20Read:        xor     cx, cx % n+ |9 L8 D/ Y
  72. get2:           in      al, 64h
    8 {) r  k. T; X0 E; r3 c* o
  73.                 test    al, 01                  ; If the 'output buffer' is full, has ; Z  d0 |8 V, ?; N6 W" S- v
  74.                 jnz     exit4                   ; something for me . j. z& x; Y3 I" t! T' D3 j
  75.                 dec     cx & Y) j! a2 j0 ?' h6 D2 X/ C4 V
  76.                 jnz     get2/ Q9 B: o5 h6 p
  77. exit4:          ret     ; W% ^/ U  P, n6 I; |& Y% u
  78.                
    $ {! [$ m0 j* Y9 Q1 ^4 M3 Z: K
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
4 ?6 E1 Q. A* i# a# J{        while(inp(0x64) & 2);        outp(0x64,0xd1);
1 x5 G, F" e3 u" T3 h" L8 Z        while(inp(0x64) & 2);        outp(0x60,0xdf);
) h: @+ R8 c6 x9 W* S. w        while(inp(0x64) & 2);        outp(0x64,0xff);" W$ f, v5 D( \' j
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-20 03:46 , Processed in 0.039040 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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