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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    / t0 x7 l2 E/ P4 J  {
  2. ; 7 |6 h) z# t: @2 h$ G5 {6 i* ^
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    9 p/ k/ L  d8 [! k  a- M
  4. ;       ml A20ON.asm 0 ]1 g- ]" U5 f% v
  5. ;
    & }7 }3 d; A* A7 G( i
  6. .model tiny) ^1 x' z0 b# }$ |* Y; Q. V
  7. .code
    ; N0 Y  W/ Q8 {$ M! p4 e( x
  8. .486+ h  B4 Y, S( }+ A
  9. .startup
    / e2 w: G8 q  Y

  10. 1 j! H8 l$ }2 p- T) q. d
  11.                 mov     dx, offset msg_author# B3 Q% ~' j+ e% U0 I+ n4 Q. c9 z
  12.                 mov     ah, 09h4 Z# M0 t6 @# U% ~
  13.                 int     21h
    * m0 X5 w9 y9 a9 c

  14. , y  W; c& [" H; I
  15.                 mov     dx, offset msg_fail ( R. a* q, p* L2 ^
  16.                 call    A20_ENABLE
    - N- W3 G* J" f
  17.                 jz      exit19 R: d" n* R7 T) y, J+ i
  18.                 mov     dx, offset msg_ok
    + ^: D6 S* W0 q$ V; Z  X
  19. 4 s! V/ C. k" ]* v9 S9 K
  20. exit1:          mov     ah, 09h
    9 C2 Z' J8 a8 S4 t
  21.                 int     21h - j& M$ O( g  E7 \
  22.                 mov     ax, 4C00h 3 J/ m4 D; g1 \
  23.                 int     21h
    " g0 {3 L9 r& ?6 P' }8 d+ s$ k
  24.                 : t+ n% Z$ b, n
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,2 {) _: K4 s$ A) ?- H# I
  26.                         "2008-07-01",13, 10, "$" : P6 b  p! x" X& c9 q" P; m; m" m
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" % I2 k9 Z, c) L4 w
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" * ~) Z" T  j+ n' U5 |6 Z
  29. 2 p6 s1 G; Q) p2 f
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------8 T  [. T3 S0 L4 E" M5 o+ {
  31. A20_ENABLE:
    8 ~8 b% v# [- f
  32.                 call    A20Write
    - j3 @* a! e" ]
  33.                 jz      exit_enable
    + A: P0 h; S* X5 A8 E) j6 |
  34. : M# t5 ]" d% A8 ^4 R
  35.                 cli                             ; Only need for reading value from KBC * }3 `# d& c& [
  36.                 mov     al, 0D0h
    . p$ k9 P1 u2 @& p8 ]
  37.                 out     64h, al
    $ [# s8 [; E! @4 i' K/ H
  38.                 call    A20Read
    # ^- ]% [+ B7 U. s6 s
  39.                 jz      enable_int
    + |2 I" u3 a4 D: \( K8 H5 X
  40.   {% B1 f, F7 j$ V" _- t* y3 w
  41.                 in      al, 60h                 ; Get current status
    8 D  B9 C( c6 ]! r9 ?
  42.                 mov     ah, al
    4 O1 ^) u. Y4 m2 }3 q
  43.                 call    A20Write 1 r3 W- h2 U" p7 u. c5 I4 ^
  44. enable_int:    sti - |0 C9 S0 h3 a) e3 ^3 p
  45.                 jz      exit_enable
    - w1 E6 A8 C, [  [$ t- r1 \2 @! D
  46. 0 m& l' p( N+ |  g
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    , g- l3 ^7 Y  x( }! x+ u
  48.                 out     64h, al                 ; Out Put Port next
    : V4 M* l5 ?. f1 _2 r
  49.                 call    A20Write * F. P. B6 f2 g# A3 ^
  50.                 jz      exit_enable' E% o. u9 ]7 P4 }
  51. , X1 e6 K5 C' H8 B9 M/ F+ x3 f
  52.                 mov     al, ah
    " R( f$ K7 e! J0 x/ U9 v0 T
  53.                 or      al, 2                   ; Enable line A20
    + {6 W% h5 o( r) S# H" Z, e# o, R
  54.                 out     60h, al
    8 x- d5 W7 ?% O" t1 G
  55.                 call    A20Write
    & b9 `/ s9 ~6 ^+ f: z: r: K
  56.                 jz      exit_enable
    & w/ x6 s' F) O) d" q

  57. $ f7 v2 i8 D- f% u8 {$ {# Y
  58.                 mov     al, 0FFh                ; NOP
    * |1 L" w' R' G; b2 D, L
  59.                 out     64h, al
    6 {9 T$ V' d8 {. b" [  G2 |( v/ P. L
  60.                 call    A20Write 1 W. k& \3 d$ n# C: L6 o( g4 F
  61. % M- ~' o* u4 N+ F  y8 ~' x
  62. exit_enable:          ret
    8 d8 a$ w6 x  O
  63. $ f' g: s2 t& w: r* |2 ?
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    6 G2 w+ s8 u9 G) D$ k0 Z: P# h5 W
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    - g# }. _& g' i9 M
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    0 K$ N* u/ v2 |1 `
  67.                 jz      clear ! X4 i' W7 J2 b' e
  68.                 dec     cx * F( Z# @$ @, P6 C% n$ s; ?/ g4 }
  69.                 jz      exit_write % j% c5 a+ ]: d
  70.                 jmp     short get_wirte
    " h* F" l3 b/ O
  71. clear:          inc     al                      ; Clear ZR
    + V# q$ S8 r8 o5 ~; q
  72. exit_write:     ret 7 y! r+ p; T2 n, |% t
  73. 3 B/ l+ o9 j! u! Q% x1 c8 s" |0 `
  74. + F5 I* i0 r0 g4 E+ D
  75. A20Read:        xor     cx, cx
    * i( U& C( j& p9 ]
  76. get_read:       in      al, 64h
    , c  u3 m- O; O, w5 J$ |1 a( [- v
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    0 u3 g: f  l6 k0 W. I
  78.                 jnz     exit4                   ; ...   b/ X( s* [, P: s  D
  79.                 dec     cx
    4 d1 m9 ^. S$ W1 l& C" ], Y
  80.                 jnz     get_read
    1 o3 ^/ V3 e- ^, k& H6 G
  81. exit4:          ret     
    3 r6 v2 J2 u# e
  82.                
    2 {- q& }' |( L+ e
  83. end
复制代码
  1. ;A200FF.ASM ( R1 J' M0 y. p- K
  2. ;
    , m5 ~# x5 \7 m' z
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    , v; p1 H5 e: o$ G& R5 j  R
  4. ;       ml A20ON.asm 8 M. _+ N* N" X1 g
  5. ;
    * P; A1 h1 L1 C+ K
  6. .model tiny
    + Z8 Q7 g/ Z4 w# W1 @& R9 `0 w
  7. .code
    / q! X! f) e7 c7 N
  8. .486  h+ ]- g$ S. |; l; V) K
  9. .startup
    & E, |3 m  M: Y
  10. ! G' y; a: U( G1 p) [  ]
  11.                 mov     dx, offset msg_author
    9 d5 z6 X8 z4 Q4 a) J1 D  ^6 K/ n' G
  12.                 mov     ah, 09h5 H; N7 D: c  Q. s2 j% D( j
  13.                 int     21h
    8 o7 }' z! V# `  }. C
  14. * H  G) t) g3 N1 I- @
  15.                 mov     dx, offset msg_fail 5 o- W8 A! Q. e
  16.                 call    A20_DISABLE9 T$ P$ D3 T1 n" T
  17.                 jz      exit1
    9 z' r3 l' s* H! l: g* X
  18.                 mov     dx, offset msg_ok
    & U8 a- G; m, z1 @

  19. + ~) w* `; r- G  Q2 m
  20. exit1:          mov     ah, 09h
    : L$ K& Y) ]4 K. n" i. j) B6 }5 O
  21.                 int     21h 0 f, _3 W  C8 G
  22.                 mov     ax, 4C00h
    % ^, `8 G+ V5 Q3 S& @9 C
  23.                 int     21h
    " }; b2 g) u- p+ h  ~3 i0 k  D8 Y% W
  24.                
    : e/ {5 r' w' e% p
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    5 v% l# A) ]3 R( Q$ O
  26.                         "2008-07-01",13, 10, "$"
    9 f0 ]- o. p5 Q, t8 D  \
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    8 ~4 b$ ~8 N& t0 f/ _1 x
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" * z! y8 y- R" O& n4 n
  29. + j* n, M$ \4 o' U
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    4 p! {5 k+ x. x$ \7 ]
  31. A20_DISABLE: ' R1 q. O" B, `. \- k6 e# u
  32.                 call    A20Write % v" j" m  s: L" _0 m# E2 @' @
  33.                 jz      exit_disable
    + T$ t1 W* e) D- P

  34. 8 Z, `4 M1 D6 n( @! ^" D) V- {
  35.                 cli                             ; Only need for reading value from KBC ' @7 s+ z/ S; ]3 Z
  36.                 mov     al, 0D0h & g2 t1 o, F9 H, L+ a
  37.                 out     64h, al 7 l* F( b% Q& j- Z  l
  38.                 call    A20Read
    0 u; ^# z+ p4 Z! I1 }
  39.                 jz      Disable_int
    * N: X0 T) k$ v6 I; Q
  40. + g: V' L: Y; b
  41.                 in      al, 60h                 ; Get current status
    ; T" u& V' h2 g0 L& a$ v/ r
  42.                 mov     ah, al
    1 @- y$ o% l7 T3 J& I: l
  43.                 call    A20Write
    2 I6 `: ?/ }; R9 q9 ^8 e
  44. Disable_int:    sti
    , X/ Y: c& |: V& g9 K2 s( M( ~  c' M  N
  45.                 jz      exit_disable/ s" V0 Y! ?/ y+ l/ V

  46. 8 w/ R( l, P" h9 {- V* n7 Z
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the * J# o/ z) j! B" A: V. Z# |
  48.                 out     64h, al                 ; Out Put Port next
    % d* s! _4 g- Z" B( h
  49.                 call    A20Write
    & Y* z0 n( t: j& U- H4 ~, `2 s
  50.                 jz      exit_disable
    / G% l2 H6 `% B( X3 H1 x4 p5 J

  51. 1 O. ]( Z$ H& W5 h" y. z$ ?
  52.                 mov     al, ah 9 l. w% V# j$ ]1 b& `
  53.                 and     al, not 2               ; Disable line A20
    ; _1 N1 e$ N5 v* q1 |4 W' I- {) l
  54.                 out     60h, al
      ^% g& Z( _. e2 r/ J. L
  55.                 call    A20Write 1 B8 s7 s/ N: \  `3 X! m
  56.                 jz      exit_disable
    , M% ?6 M8 W$ ^) @( p  F
  57. 3 ]( T: M/ e8 n7 L% o' j
  58.                 mov     al, 0FFh                ; NOP ( k" |% d3 ?1 G& k' A
  59.                 out     64h, al
    $ N+ Z  U8 Z' t5 e2 e9 X9 v! a
  60.                 call    A20Write 7 c) s0 t5 r/ N, S
  61. + p$ p" u' |* w
  62. exit_disable:          ret
      B9 i9 \9 Q1 |1 @
  63. 7 j/ E5 ]7 T0 T; S2 j4 J  x9 U, @9 Z
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    # ^* u& M; t9 C# p- E5 L
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 2 ^% c  d, T- l1 Q, P
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear : J+ D1 Q) Z% a% R' S4 y* [5 Z- ]
  67.                 jz      clear ' e8 l3 y- ~1 K+ w2 p
  68.                 dec     cx
    & l- w6 I6 c  _" M
  69.                 jz      exit_write ) ]" D& s6 v7 X+ @
  70.                 jmp     short get_wirte 8 x! ?& L1 ?  r! [' W5 N
  71. clear:          inc     al                      ; Clear ZR : b$ n+ z( z, W4 a7 _
  72. exit_write:     ret
    , ?/ I" I  O7 G) M; m! U" {

  73. * H4 i% A  O$ L& Y

  74.   b  t5 Z! @- E2 I
  75. A20Read:        xor     cx, cx
    & R; V7 @) B8 h$ j5 {
  76. get_read:       in      al, 64h 2 v: D6 H9 M& M" m! O
  77.                 test    al, 01                  ; If the 'output buffer' is full, has : W3 i0 |, {2 L& v5 b7 O+ ]
  78.                 jnz     exit4                   ; ...
    % t. L) l% z+ M8 d% l9 }
  79.                 dec     cx 2 Q9 y. h- c' ]; }$ V
  80.                 jnz     get_read% E7 y( }% y& a' _6 f! D
  81. exit4:          ret     
    . O! p5 a: b( L$ _5 Z) j1 j- j
  82.                
    ; O& M% E& q" S+ ]2 W. T3 Y
  83. end
复制代码
  1. ;A20STATE.ASM
    7 R- u5 a+ s/ N2 X, O5 \
  2. ; & u( R9 g" O7 i* t
  3. ; Returns the status of the line A20 through the KBC
    # a) x" @1 }  D+ v; `8 J
  4. ;       programming by bini for debug. 2008-07-01
    * V$ ?1 ^- ?! A
  5. ;
    7 V8 c# R$ I, K0 k2 |
  6. .model tiny3 s5 d- ~  Y; [; q
  7. .code  L& R5 b; }6 x
  8. .486( ?6 K* r, n. [1 ]0 g
  9. .startup+ j: g- F8 Y0 S' d  z+ x
  10.                 mov     dx, offset msg_fail
    ( i$ H! P5 z$ x% X
  11.                 call    _GET_A20_STATE_$ T! d1 ^6 S2 K: {7 L- f! a
  12.                 jz      exit1                           ;  was a problem8 k6 o0 c. m* [% O+ A+ _7 T+ X
  13.                 push    ax                              ; Save state, AH - K! h% |$ i, a5 f: `
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    ' T) Q9 x' c3 C
  15.                 mov     ah, 09h
    ! J& E# w$ }; ]  d
  16.                 int     21h                             ; Print message
    ; u, @. U- Q# e( y
  17.                 pop     ax                              ; retreve state
    + @, P# r9 y; M2 M5 [

  18. ) z6 L1 o& {+ g) y3 P( z: B0 u
  19.                 mov     dx, offset msg_dis
    + l6 b3 R& T% d2 q
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    # H- S; G4 U( ^
  21.                 jz      exit1 / Y9 \4 t9 }* w' W6 d/ C$ k
  22.                 mov     dx, offset msg_en
    - r7 f; Q% g/ k1 g: l) Y+ d& B

  23. ( x( N, j/ H( }$ C0 p
  24. exit1:          mov     ah, 09h
    ( X- j$ g" ?( s
  25.                 ; DX already contains address of string
    8 D  j9 x* ^  d
  26.                 int     21h * V6 x% @& C5 c2 u8 t

  27. $ D# c9 P& g5 ^: n8 i8 E
  28.                 mov     ax, 4C00h 9 q/ Q# U4 O, E' m- c6 k
  29.                 int     21h
    & p1 f# h  H$ ^. U+ e

  30. 0 m, S$ ?- C$ K# u. v! c
  31. msg_ok         db      "OK", 13, 10, "A20 $"   m4 Q% v2 s$ ?2 e; n7 }4 B' ?3 b; D
  32. msg_fail       db      "FAIL", 13, 10, "$"
    4 ^# N& ]8 `2 K  l  ?0 D  D
  33. msg_en         db      "ENABLED", 13, 10, "$"
    # D- r7 }7 y  N, u, |: }
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    1 C/ Q8 s5 t& O
  35. 7 g: k2 N( `4 M0 l; {/ q( p0 y

  36. 0 c* l2 w$ i  g" T
  37. _GET_A20_STATE_: 3 G  `0 g6 W6 k" |
  38.                 call    A20Write                ; Wait till the input register is empty 7 _. r* t. g9 J/ m8 |% W9 v
  39.                 jz      exit2+1                 ; Bypas the reset int's
    , T% N3 \3 v* m5 C8 q7 G
  40.                 cli                             ; Disable ints so we'll get our value 9 J- S7 f3 d1 Q4 N: G8 ?+ i
  41. 3 Y5 S  C. O, c6 y& V8 {: K; H
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register $ J3 [2 g" \( E
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    % T2 [, b9 ]( o
  44.                 call    A20Read                 ; Wait till the 8042 output register $ U. @- n$ b3 f- t0 V
  45.                 jz      exit2                   ; has something in it's buffer
    % V/ P* J5 ~" `  ~4 J% ?

  46. + x. x8 z2 z) U. z$ R' d
  47.                 in      al, 60h                 ; Get it
    6 g; [0 k! I: ^6 K
  48.                 mov     ah, al 3 U5 `9 M4 {/ ]! K2 `7 n4 G
  49.                 call    A20Write                ; Make sure the input register is empty ; G9 \/ J& ?8 v! {- _7 C3 h
  50.                 jz      exit2
    : w& W. u! a' L
  51. ) B$ C; j% `5 c7 X
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 2 h8 Z1 l9 @" E, ?8 k
  53.                 out     64h, al
    & M$ S. V9 w+ b  B, `# g
  54.                 call    A20Write
    2 _+ L- }. V+ r. J

  55. 2 @1 J$ z. [. c' J
  56. exit2:          sti 8 i) N  }) R2 w, L* T
  57.                 ret+ K# D" N# }4 T  i: N1 p: D; h

  58. , f( A! p! x* q' k1 S

  59. " W: N  ]- I: u6 X5 a4 Q5 E
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    & @# t9 {: H# k% S: m
  61. get1:           in      al, 64h                 ; Get KBC read status
    . `. b7 o# t  y( Q2 y1 P) P( r: J
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear   K2 F; h! c- Y, V8 B& }
  63.                 jz      clear   w  l; s( B: m, J2 h0 {7 H
  64.                 dec     cx . o, Z. d' d# G2 U1 l" i6 {
  65.                 jz      exit3 / _/ y/ A6 v: }. s3 M6 Y) ?
  66.                 jmp     SHORT get1 ! n5 r2 Q  `4 @4 s% U
  67. clear:          inc     al                      ; Clear ZR . e; Q+ e4 P3 x3 D% w  L( N' r% i2 N
  68. exit3:          ret
    , ~" P3 |/ c6 C) h' P; Y* H+ I
  69. # A4 A2 x+ G: S5 D" _2 W* {

  70. - S4 w. v7 l2 D3 r+ a) m5 D9 w
  71. A20Read:        xor     cx, cx
    4 @* p4 X( ?: e# E, F. L
  72. get2:           in      al, 64h * r/ r: Q+ P$ P2 v- a8 y, g
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ; G6 J' h$ |: o) G9 _- k
  74.                 jnz     exit4                   ; something for me
    : S9 G( L( \; n( F9 `# V
  75.                 dec     cx . U/ V) J& @, @- f$ j( B3 p- N
  76.                 jnz     get2* [8 v+ I/ ~4 W+ j& p( c
  77. exit4:          ret     
    ) u. }& S3 O: z) A6 C, i8 D4 l& c: J1 g
  78.                
    5 g% h' i4 @- o+ e- r  k
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()/ _% E3 \' A% N$ v% t: J
{        while(inp(0x64) & 2);        outp(0x64,0xd1);: {* p1 k  {  |" H5 ]5 z1 S
        while(inp(0x64) & 2);        outp(0x60,0xdf);
4 O! ^+ ?- w, [$ s: A        while(inp(0x64) & 2);        outp(0x64,0xff);
+ g% {  w, N7 n8 w7 P" ~/ c}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-4 14:40 , Processed in 0.069970 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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