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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM % z2 K# i! }/ l1 }4 h
  2. ; ' V% v; N, I& z- P' M0 k4 v
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    / B6 j/ q. v+ x4 t
  4. ;       ml A20ON.asm ) W$ f0 d+ d% i4 @
  5. ; ) Y; L+ W, W' o, O: B5 b
  6. .model tiny
    + X# b. x0 _. V. ^4 k$ t
  7. .code; A! {! N9 h/ C, H
  8. .4861 t+ A. b9 ?/ S7 R
  9. .startup
    : M" K/ I8 L6 n$ a" T
  10. ) B( h0 c4 t; e* q3 V3 `
  11.                 mov     dx, offset msg_author- d( ?  I  D! U# ^& x% l
  12.                 mov     ah, 09h
    ) S0 a0 i* p: {$ Y& y+ J1 z) h
  13.                 int     21h- N) L1 M: B% y% d. x$ A: n" G& F

  14. : o) G/ j3 F' l
  15.                 mov     dx, offset msg_fail ' K2 `' U) |: X3 q4 ^+ b4 B* w3 a7 k3 w' z
  16.                 call    A20_ENABLE/ q' q: ~1 U; n
  17.                 jz      exit12 }/ _- ^, d$ n* z7 ^4 ?( A0 U; k
  18.                 mov     dx, offset msg_ok - g  d6 \8 S* R/ n1 R7 V
  19. ; H, U7 }/ g  ^, M( r0 a( E
  20. exit1:          mov     ah, 09h   }6 Q) P) r' P8 H' ?( O
  21.                 int     21h
    " l. a& ?0 O" o5 F' U# o
  22.                 mov     ax, 4C00h 1 U6 d7 B; r0 d$ ?
  23.                 int     21h ( t2 @9 z! s, j1 G% `
  24.                 ( ~; p9 V+ O3 [# E
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    5 ~) I0 Q2 A0 s
  26.                         "2008-07-01",13, 10, "$"
    # |" t  S2 ?, Z& X$ L
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    - y2 _% h% g$ o8 S( U
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 0 M  m$ s; B5 j  \3 b
  29. % m& E: g5 x( s! l1 d% N1 Y
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    # l9 V8 d! M* G) U
  31. A20_ENABLE:
    ; C& k. h  v1 D& ]4 S  w
  32.                 call    A20Write
    ' A, e4 m8 L% `  b' D
  33.                 jz      exit_enable
    ) x2 Q! B4 B; s1 k4 J
  34. & \  G7 ]" d: _- e0 _
  35.                 cli                             ; Only need for reading value from KBC
    4 A' c& `* X0 B# r4 j) P' Y
  36.                 mov     al, 0D0h
      M1 y# v# r2 H* e4 K, ?
  37.                 out     64h, al * e9 d5 B* O% N4 ~" Y# U9 O
  38.                 call    A20Read 3 w( z/ s* o. k0 p5 ?6 O
  39.                 jz      enable_int 1 \# k2 x, q- I# M  `1 _7 u) E

  40. " Q/ k4 P, b1 G% C) {& S# Q3 {
  41.                 in      al, 60h                 ; Get current status : N! Z) [. d0 `) v% y
  42.                 mov     ah, al 5 h5 {, {; E$ h) v! ]6 P: Y
  43.                 call    A20Write 4 Q" `; D- n4 n
  44. enable_int:    sti
    . [9 }: M/ b6 `# q) Y! ]& |
  45.                 jz      exit_enable
    ) G9 L# L( y6 f6 g2 X

  46. ( W8 c& ?4 X0 d- W% W! S9 s, R
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    & ?% X. Y: s/ A) ^
  48.                 out     64h, al                 ; Out Put Port next
    9 Y, g6 ^  K/ Y" [+ r, Y
  49.                 call    A20Write
    7 N  r# k; v4 }- Y( `* y5 G
  50.                 jz      exit_enable
    $ l: U: e+ b- S' w: M
  51. 0 a, ~' v1 \. t* n. `! v
  52.                 mov     al, ah 2 a- g/ W  I& \4 j2 O! R( C
  53.                 or      al, 2                   ; Enable line A20 ' t+ N8 P/ q. B
  54.                 out     60h, al 1 I: I$ d% Z+ h% i  K# L) ^
  55.                 call    A20Write
    % L. b7 @" y8 b* M/ E1 P' g
  56.                 jz      exit_enable
    ( u, r  B% ?2 D( p

  57. " V; l$ f* x& O! m1 e
  58.                 mov     al, 0FFh                ; NOP 1 c  p2 |( W2 ^6 s1 U9 c7 p
  59.                 out     64h, al ( b9 @6 w' L; e( d
  60.                 call    A20Write
    $ [+ f' z$ w! {
  61. ( Y$ H: ^$ b2 e. }
  62. exit_enable:          ret * t$ A2 b/ V) Q

  63. 4 ^1 T1 g- J# g3 y/ S
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    , v# q. k8 e& |' }# s. Y; d% B
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    8 m- U8 ~& |* \# _
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ; u: w' ?5 f) h+ s# @
  67.                 jz      clear
    & t2 {+ i/ r6 G  c+ q. b5 g, _
  68.                 dec     cx - u+ g" R+ F( D. y' v# P: k1 D
  69.                 jz      exit_write + ^% S1 k' F7 A$ \' e) p  L/ n
  70.                 jmp     short get_wirte
    ' R- d, b( F1 @/ @$ J
  71. clear:          inc     al                      ; Clear ZR % x# k) Q" A" }
  72. exit_write:     ret 2 G" Q, W2 _0 _5 |# |1 N

  73. 9 p$ {3 U% R7 F  i( x0 m% b

  74. 7 k% E7 D7 j4 M7 q, v& R
  75. A20Read:        xor     cx, cx
    / l* d" U! K1 a; ^1 z0 F- |/ {: F2 j
  76. get_read:       in      al, 64h
    0 e5 w1 c* z" ]4 K
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    , K+ R( v9 S4 B% I5 t: y
  78.                 jnz     exit4                   ; ...
    + S+ r# ~9 ?& ~$ Q+ A4 a
  79.                 dec     cx ! q, g3 E' Q% V: y5 G# [
  80.                 jnz     get_read% Y$ k( o( b3 S; x2 t
  81. exit4:          ret     
    - r' x3 ?2 s* P5 @2 _4 b7 a
  82.                
    % m9 \! @9 C! g. M
  83. end
复制代码
  1. ;A200FF.ASM
    / ?, S' s- m& t2 N# j7 L
  2. ; ! n6 C4 z: Q$ S3 q6 t
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    0 P' o8 K) V& @- t' B8 J
  4. ;       ml A20ON.asm
    ; ]4 J% g0 {1 H
  5. ;
    ; e& V: l& j4 b: y+ s
  6. .model tiny8 f; t) `5 _9 m* D( E% K! X
  7. .code
    - ]3 k* F  R; C: I0 Z/ ~0 p5 _
  8. .486' L, m' ^% v6 P) J% w7 e
  9. .startup
    ' k; T0 ]* }! I% z1 S# \) f2 J! p. M
  10. . x9 R- _* }. o0 n4 V
  11.                 mov     dx, offset msg_author. P7 D+ I4 o: j" P9 i0 T: H" w
  12.                 mov     ah, 09h4 a% ^* s& I+ Q3 t- {, T
  13.                 int     21h9 K4 j9 |( P0 k: m
  14. + }" I; O# C. e) \  e$ u
  15.                 mov     dx, offset msg_fail
    ! o" R: [1 w2 q6 G; t
  16.                 call    A20_DISABLE
    8 H5 i7 Z. x$ ^4 J) K
  17.                 jz      exit1
    # q' k+ R8 {/ G- k& ]2 P
  18.                 mov     dx, offset msg_ok
    ) n, Y0 n7 g8 d2 S/ v, H
  19. & o5 g2 V. A- ~* T, p
  20. exit1:          mov     ah, 09h
    5 N* z9 l/ V  N& f; ]
  21.                 int     21h
    - r/ o7 Z0 ^7 f: a. e' D* p
  22.                 mov     ax, 4C00h
    : M; }! Q& U3 G' ~6 h, z) t' I  x
  23.                 int     21h 3 s! [: D' J1 c* q
  24.                
    7 ]* e: k8 _; O/ V* @* Y
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,/ a; G  T# K5 V- t, C
  26.                         "2008-07-01",13, 10, "$"
      l' p, d4 H0 r7 X8 n
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    9 w4 F+ w. v6 e/ I( T8 K2 M9 O6 {
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    & }" @1 s. o" j1 l" W. e
  29. " x5 t0 s# w/ ]: W- a4 H+ ~* D
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------( B, `5 U9 C+ m6 g; j
  31. A20_DISABLE:
    6 Q- Q6 b( r* k& S
  32.                 call    A20Write
    " m  v) Y& c2 _& ]" `$ U, d
  33.                 jz      exit_disable
    5 X  |9 @0 r1 X4 G4 u1 H- n9 L1 ^
  34. + N2 I$ [% s8 `2 A
  35.                 cli                             ; Only need for reading value from KBC
    : T1 S  R0 H7 i
  36.                 mov     al, 0D0h
    4 ?; X6 G' t/ ]& |( \2 q/ ]" {
  37.                 out     64h, al
    ) ^4 `+ L5 G) B0 c% t
  38.                 call    A20Read   [$ m4 B8 }+ ^- u
  39.                 jz      Disable_int
      Z0 v& J: @& I; R  }
  40. & W6 o% i" F. m  w9 T8 Z1 w
  41.                 in      al, 60h                 ; Get current status $ F3 A# m$ x# u6 Z9 z
  42.                 mov     ah, al
    $ _: J: s' k2 a$ T4 a5 i  R3 n
  43.                 call    A20Write 6 ~+ ?  o! R) X9 D" e
  44. Disable_int:    sti
    ( Q, b2 ^1 H9 _; e' E
  45.                 jz      exit_disable3 Y+ R; ]9 S' f* l) _+ }7 X

  46. ) |% O( L6 k/ i8 ]6 A$ q! A- e, ]! F
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 7 d; v5 @$ _* R% \% T" F8 |
  48.                 out     64h, al                 ; Out Put Port next
    # j$ a  h5 C  h  w$ m( z; h
  49.                 call    A20Write - @8 ~' g5 x5 X$ _: u
  50.                 jz      exit_disable
    . C9 G- w( _, u, p' ^
  51. ( a5 o6 o  _! G+ W
  52.                 mov     al, ah 2 c# f* F7 B: t# ], b
  53.                 and     al, not 2               ; Disable line A20 / O% @- n- d. T8 E
  54.                 out     60h, al
    4 _2 R# I9 I4 M
  55.                 call    A20Write
    , f. _3 n8 d4 C4 @9 o* w$ h4 R
  56.                 jz      exit_disable
    0 D* P) v% r" L3 q5 }* E/ s% O4 N

  57. ) {: w$ T( Q% w& P' S7 W
  58.                 mov     al, 0FFh                ; NOP
    7 D2 F. X/ F3 I( ]) W
  59.                 out     64h, al
    - c" \; L$ z! h' [( z0 p. ]/ Q" A
  60.                 call    A20Write
    " T; D* m) M) w5 C

  61. ; f: N7 B9 q8 ~' n
  62. exit_disable:          ret
    * y, C+ t7 ]6 j9 w" \4 A
  63. 1 x; B+ N7 `- w2 Q+ {
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ! R" S% ]- M8 a2 |# r
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    7 l) z) k& o& R# M' }4 N% f. l7 n9 A
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ! Y9 H' ~8 l0 k0 D4 R" x  n* E+ y, p  G
  67.                 jz      clear
    ) ~0 k% |, j) \& f' x- c" u
  68.                 dec     cx
    " p9 y# r6 m* O+ |) T/ E
  69.                 jz      exit_write - m" [, e) a( C4 c  `9 g, Q
  70.                 jmp     short get_wirte , o$ t* |0 U, K" O- _! v
  71. clear:          inc     al                      ; Clear ZR
    7 @& |% l& N/ `% \, y! J
  72. exit_write:     ret ! T6 F2 L# A' g
  73. ) Y+ y6 P0 }: F6 B" R. d

  74. . Q) t) L0 C1 S5 Z& b& h
  75. A20Read:        xor     cx, cx
    . [: V' t/ @2 E% I, e: S& q
  76. get_read:       in      al, 64h # u% b  @. R& f. v0 Y( `
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ( ?+ Q  a, a7 J1 y9 \) E
  78.                 jnz     exit4                   ; ...
    ) V. ?8 i( C5 Y4 f: w
  79.                 dec     cx
    " m) d+ D7 b& c2 u, v' c% m
  80.                 jnz     get_read: o" E) n" w1 G+ @% x: D% U
  81. exit4:          ret     
    $ p$ l- K0 d3 s/ G# T* b, d
  82.                
    " |7 N+ H! x% \9 d( V) R
  83. end
复制代码
  1. ;A20STATE.ASM
    ! ]$ r. H8 W& t
  2. ;
    6 r7 B; e8 {% n
  3. ; Returns the status of the line A20 through the KBC
    & L. J  d; I0 ~2 ?
  4. ;       programming by bini for debug. 2008-07-019 n3 |! r% P2 C" D( `/ a
  5. ;
    % Q3 A) K* I- B. }/ V: q. s
  6. .model tiny% n/ [7 y6 A  |' F' P. C7 V! q
  7. .code
    + B# Q1 v1 a; Z! w+ X0 Z( a
  8. .486
    % L. d8 v8 ]; v2 D3 d' F, Z
  9. .startup
    ; r5 ?" N+ k  |5 y6 {' d
  10.                 mov     dx, offset msg_fail 5 X7 T. }/ q" I/ U3 S$ {
  11.                 call    _GET_A20_STATE_8 u* `6 O  d$ }* n/ y0 F
  12.                 jz      exit1                           ;  was a problem
    * \/ j7 o9 w! v, w
  13.                 push    ax                              ; Save state, AH 0 a% B0 k4 }$ y& [1 R
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
      x& U$ U; t+ X' t: [
  15.                 mov     ah, 09h
    ! N" J& I: j& k( j4 t
  16.                 int     21h                             ; Print message 2 g$ Z) A( P: \
  17.                 pop     ax                              ; retreve state 3 y: @2 N/ U/ j+ ^1 I; N$ s4 h% W
  18. ; n. c: O/ F4 ~$ O( o
  19.                 mov     dx, offset msg_dis % C7 N% m+ Q& X* |
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state : V: D1 S0 U/ a0 r0 C8 ?1 y7 e; J
  21.                 jz      exit1
    6 U, ?* b9 X6 m" y1 X% z2 b
  22.                 mov     dx, offset msg_en & \1 Z7 V% M2 K* c6 t

  23. ! @: K5 N/ u1 \, p& M+ t7 L: d6 ~) z
  24. exit1:          mov     ah, 09h * Y* w) V2 E- B/ V* a+ i- H
  25.                 ; DX already contains address of string
    3 o2 W: z& S' t% z
  26.                 int     21h ( {$ l2 J0 Q8 X' z+ Z% m6 Y3 Q+ ]8 M
  27. 9 @, m* V! j' l- t
  28.                 mov     ax, 4C00h ) d2 o1 j- n9 L" l5 |% G# b& G
  29.                 int     21h
    5 _' j3 i, C6 ~% X# g) Q$ }6 J  L

  30. 6 d& r0 V% n& F2 |% X
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ( h4 _  G& f: E) T- B
  32. msg_fail       db      "FAIL", 13, 10, "$"
    6 v5 i6 f: ?* D$ R/ q- Q2 H
  33. msg_en         db      "ENABLED", 13, 10, "$" 8 @0 G* [: Z' c7 u1 x& \' p
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    0 _0 a; U& h, |  |( B5 ~4 d

  35. ! y, C  B( a0 T# y3 x# G" W1 t

  36. ( z+ x! z0 }  G& t
  37. _GET_A20_STATE_:
    $ m9 v3 P2 G* s' A
  38.                 call    A20Write                ; Wait till the input register is empty 1 B8 C5 q, Z- r7 O9 y
  39.                 jz      exit2+1                 ; Bypas the reset int's ' q+ }; t) H3 \
  40.                 cli                             ; Disable ints so we'll get our value ! j7 f9 r- n+ ?6 d0 b. }2 h: R
  41.   C) F% U" Q$ |( S
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    " {3 v3 S$ p$ C; q' K
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port $ R# I( u! P1 u, \0 N  M1 O
  44.                 call    A20Read                 ; Wait till the 8042 output register
    + U* l7 }- b$ r. U# W* `+ z
  45.                 jz      exit2                   ; has something in it's buffer
    ' T3 }6 ^4 j  v

  46. ) T7 l" _5 J3 `3 }: W8 P3 a8 L
  47.                 in      al, 60h                 ; Get it ; z2 A3 [0 \( z; P- S7 Q; e
  48.                 mov     ah, al
    8 _4 i5 ?1 J5 V
  49.                 call    A20Write                ; Make sure the input register is empty / _. n, X, B( S/ k/ r
  50.                 jz      exit2
    3 h! @& l  M7 e: A; n

  51. , N( y: I: a' W( V+ t3 m' i
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ! M- U, K, u. \; V- @
  53.                 out     64h, al - u7 Z! @$ f# f/ k/ B
  54.                 call    A20Write
    ' J: J0 ~& S4 I1 I
  55. - _( l* s: ]* a1 r, x8 ]
  56. exit2:          sti # D9 Q$ e& e7 D4 a5 o
  57.                 ret0 o6 S  T! v/ k+ E6 \1 _

  58.   D& X2 P( i) L, M7 y
  59.   Z" y( G2 S+ M- d0 ~1 i$ [' ~% h
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    + s% Z8 B; `# o9 j: [8 t5 q4 @
  61. get1:           in      al, 64h                 ; Get KBC read status 4 w" Y$ H7 z* Z5 J8 j5 c
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear # ?  C' \) @  m: L
  63.                 jz      clear
    * @' S( U8 i5 @" f
  64.                 dec     cx 9 _- m" `4 ]/ h2 \& q3 |/ A
  65.                 jz      exit3
    ( w, F+ M1 z6 [2 s2 s7 @
  66.                 jmp     SHORT get1
    ! K1 l9 m9 {  Y, Y
  67. clear:          inc     al                      ; Clear ZR 5 l) m7 u8 b! b8 ^( }
  68. exit3:          ret / s# z# P/ U: C9 z; `

  69. / e- L7 j* l$ }, A

  70. 5 o* c0 e/ P  K! G
  71. A20Read:        xor     cx, cx 3 L5 c* ?& V; g  S  [% H9 n
  72. get2:           in      al, 64h
      e2 G& }1 k- s6 i3 b8 H
  73.                 test    al, 01                  ; If the 'output buffer' is full, has , ~" `2 O! @3 S& y1 }: \  b
  74.                 jnz     exit4                   ; something for me
    & B5 }! i- @: o
  75.                 dec     cx
    ! U2 G( y0 k  {# Q
  76.                 jnz     get2  J. g5 X# l! T( E
  77. exit4:          ret     ' _# A7 a5 G4 l0 W+ n
  78.                 5 o0 v0 h3 r6 Z1 a
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
  u0 Q6 A+ T0 a5 f$ c% l{        while(inp(0x64) & 2);        outp(0x64,0xd1);. o6 q  |$ m8 M2 L
        while(inp(0x64) & 2);        outp(0x60,0xdf);
  l/ }$ p) q  v# K+ A        while(inp(0x64) & 2);        outp(0x64,0xff);
5 R- @- Z6 f% U, C' `& W}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-5 17:50 , Processed in 0.093880 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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