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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    % M' _8 b  K6 }/ x$ j( [
  2. ;
    + n# y' h$ x8 z( d" u
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01$ _7 Y/ L) f6 @/ C
  4. ;       ml A20ON.asm
    , q6 n( }) R+ n8 R& t+ R
  5. ;
    7 T! L9 n; d" \2 y# l% O" z$ Z* @5 d
  6. .model tiny$ K. t* b' m) a- S
  7. .code' k+ {- f, t- I. m5 a
  8. .486$ f! b3 S9 x' L. J7 Y3 e! N: x
  9. .startup. L4 Q) @# a. S  w: k
  10. : E& w  J- p. }, [  w
  11.                 mov     dx, offset msg_author4 M$ L0 L" k& A2 [
  12.                 mov     ah, 09h
    ) F' ?" l1 f1 e4 N
  13.                 int     21h2 A& z+ i! T$ ^5 V
  14. 4 L8 P- ~, ~7 p2 i* U9 D# j5 @' p- {
  15.                 mov     dx, offset msg_fail
    / G: f. D1 D2 r: _: |
  16.                 call    A20_ENABLE2 P7 ~3 N; ^  W! i( ?
  17.                 jz      exit1
      o5 G/ N( H, M7 H+ Z# q
  18.                 mov     dx, offset msg_ok % P3 d, _" k* v, G5 Y; `8 E

  19.   e( N6 w) f/ o3 r
  20. exit1:          mov     ah, 09h * d5 G, Q4 I7 [  S: k
  21.                 int     21h & m9 x1 J& U, z) D" h2 {
  22.                 mov     ax, 4C00h
    7 \) t9 v/ z% @* z3 h2 J
  23.                 int     21h & H/ D* l, l! s8 [  O
  24.                
    5 d3 e8 j4 }/ H9 {
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,; e% m, X0 y5 e* @
  26.                         "2008-07-01",13, 10, "$" % A1 p5 M5 ^2 T# K% a) m
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    3 T, i- P( w, u, M
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" . F- l! f! e2 d6 B

  29. 0 P5 n9 i# H6 G8 X' _  t) m$ H! `6 k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------. {# D' W( U; u2 Z1 d, P
  31. A20_ENABLE: 2 q7 ?7 L5 c9 O% i! _  P: e; m
  32.                 call    A20Write
    $ C! m0 x/ p' c  }( G! E
  33.                 jz      exit_enable/ {. e  g2 i; ^

  34. * W- A  `" c: [! Y9 Y! P' R
  35.                 cli                             ; Only need for reading value from KBC
    - x4 l4 E# k3 c  r* p+ L
  36.                 mov     al, 0D0h
    ) g6 k* ~, A+ P5 a6 @
  37.                 out     64h, al # o0 B0 d: }: r' J
  38.                 call    A20Read
    ; F& Y7 z0 \, Q& B, R
  39.                 jz      enable_int % o  g  p9 p4 ~/ ~% d8 e5 [+ H

  40. 6 d: z! ?/ s! a3 E0 l9 |
  41.                 in      al, 60h                 ; Get current status
    + z4 d# B- N. \6 W% f
  42.                 mov     ah, al
    7 x# [0 c5 H& a$ A
  43.                 call    A20Write   R) m1 q, R$ y* x  `' D* l! n8 J
  44. enable_int:    sti
    8 I: C' [, O# X
  45.                 jz      exit_enable9 |0 l" k& a1 v# I$ V4 I' b
  46. / U- ]% g- K' p) s. c
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    % [* d* }/ H( n( Q7 e. G) h
  48.                 out     64h, al                 ; Out Put Port next
    ) f1 h, d/ [8 b; [7 B# L
  49.                 call    A20Write
    ) ?! o$ |$ B; V5 e
  50.                 jz      exit_enable
    8 y. Y: f- ^$ A) R' r. D0 K

  51. # J2 R8 O* i5 |, }% f" s* c, y
  52.                 mov     al, ah
    7 u1 X2 T1 n/ j7 W4 z
  53.                 or      al, 2                   ; Enable line A20 ! z6 T  M' u. h* Q0 L! Q
  54.                 out     60h, al
    6 W9 m1 A& \4 {, L3 Y3 ~
  55.                 call    A20Write 0 L# U1 K3 l0 C" H
  56.                 jz      exit_enable
    0 Z) y; V( r0 x4 E& q

  57. ' H7 z; S+ n3 R" D; |1 y& C
  58.                 mov     al, 0FFh                ; NOP   l( U! Q% A$ x' i
  59.                 out     64h, al
    $ i1 V* V. e' Z4 v, ^
  60.                 call    A20Write 2 g- f. v! m3 S- I; m/ R5 u7 `9 d
  61. : A, L8 Z# x1 R6 C% n
  62. exit_enable:          ret 3 k. a: _& \9 C0 M
  63. 6 k! u0 W3 h- a0 R+ a
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    . k; `& |4 M; L/ ~$ ~: q
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 8 a0 s& m$ l3 q4 c& Y8 C+ C/ I
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ( n7 _: w# q) b8 i  ^( [: B6 Z+ c
  67.                 jz      clear % e- F1 w9 F5 g. B
  68.                 dec     cx
    , |) R5 \9 @, W# L: x7 w
  69.                 jz      exit_write
    # R! m7 I$ T7 I7 {- H3 A5 s7 L1 v+ Z+ k" K
  70.                 jmp     short get_wirte
    ) b& W+ Z% }; ^5 H! n) Z
  71. clear:          inc     al                      ; Clear ZR $ C: o$ `9 M$ c
  72. exit_write:     ret ' \0 [8 [: o; u1 x! j7 y" [

  73. 1 W6 V0 I+ c3 w* V  G
  74. ' F' {5 v! |0 K/ v) G; S
  75. A20Read:        xor     cx, cx 7 Y3 D% R, M/ S) L
  76. get_read:       in      al, 64h 4 l% i/ e/ L% {- X
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ! [0 \+ `; `( {( D: m6 ?
  78.                 jnz     exit4                   ; ...
    * H9 ~! W$ x7 ?3 W2 H9 y  s' X% T
  79.                 dec     cx
    & v6 P1 P2 i; |: w$ j+ u2 X
  80.                 jnz     get_read
    1 D( r4 a1 x* z2 B+ `2 m. ?! [) x
  81. exit4:          ret     , F* a7 f; V. `1 Z2 h$ Q  a$ v
  82.                 4 F+ w1 i$ [3 b
  83. end
复制代码
  1. ;A200FF.ASM ' m9 C7 a/ n1 q: c
  2. ;
    & G4 r7 y$ i# S( g+ v
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01* n1 K% K+ T0 E
  4. ;       ml A20ON.asm
    0 ^  L! U8 T! r1 x
  5. ;
    ) W8 J" R' m) f
  6. .model tiny
    / C! m' m+ P! q5 r1 ]0 A7 M, Q
  7. .code
    3 D" Q7 Z$ r: o0 W5 \4 j. J3 \" j
  8. .4866 u, D* K7 O+ g1 C) v
  9. .startup
    $ d, K: O1 z5 r7 C

  10.   H) t" z. Q* h6 m
  11.                 mov     dx, offset msg_author0 q) L5 C! p& K4 V
  12.                 mov     ah, 09h
    6 F0 a! Y. |& j5 q9 @- w+ m
  13.                 int     21h7 E; a$ @7 o+ [. J+ A% ^; Z

  14. ( T6 X6 `( h* F* e  k
  15.                 mov     dx, offset msg_fail
    * j* E  I( H6 j; }% j" k: Y2 R' W
  16.                 call    A20_DISABLE
      @, ]4 ~+ E/ Z: F8 W
  17.                 jz      exit1) T9 ]4 f" J3 [: R& K, W* G
  18.                 mov     dx, offset msg_ok
    * W* ]# Z; p& d# D
  19. 4 X+ U- A3 x  o: D/ `+ B1 y% o. q8 V
  20. exit1:          mov     ah, 09h ! K9 _3 t3 v! c- p- Q  m7 J
  21.                 int     21h
    & s: g* W7 |! H& D" s* `% ?
  22.                 mov     ax, 4C00h ! G. Z& S% N3 p- m: p6 D. e1 ]3 |
  23.                 int     21h ' @: s4 M. j0 B/ u
  24.                 ; F( d5 F8 z& j$ g. H. m! ~
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    0 p) P+ p" v- }" O+ x
  26.                         "2008-07-01",13, 10, "$"
    & N: }6 h( q* b# A6 l# q
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    0 r2 i1 B0 R# P) H+ [
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    : {1 j! P- u- B8 \( K3 w* d+ o
  29. : W) y/ S6 p: [) M
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------& b9 z4 I0 _' @  p* k' `0 ^
  31. A20_DISABLE:
    9 F' u+ M5 n( d2 L6 O
  32.                 call    A20Write
    / g0 I- b' i, ^" [
  33.                 jz      exit_disable9 j/ Z7 ~% }9 {4 [
  34. / ^6 P( J3 ^9 ?/ H# a
  35.                 cli                             ; Only need for reading value from KBC . w& g! h$ I  I4 W" p
  36.                 mov     al, 0D0h - L. a! R+ Y3 v( |5 Z  k
  37.                 out     64h, al
    ! P+ y9 g: ~: b, u2 o
  38.                 call    A20Read
    0 f4 a, H3 f% s5 o& }
  39.                 jz      Disable_int . d8 c) v6 _3 z# T. o/ k% Q( @. l
  40. ( {& d* h3 O4 Y7 ?( |6 [) q
  41.                 in      al, 60h                 ; Get current status 7 i% q% a/ ], i: Y# M0 Q( j. p
  42.                 mov     ah, al : n( J6 n0 P- y. ~' M( K/ P" `' _
  43.                 call    A20Write + i) c, f, K) r# Q2 Z! K6 {, i/ e1 [
  44. Disable_int:    sti : n2 q$ m& D$ X9 R8 l8 M  [# A6 O
  45.                 jz      exit_disable3 h1 J9 c/ [7 y' f: C7 ?6 k

  46. % i  ?6 l1 \# K* D
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    + c8 V- n9 H+ K# k+ J2 d) @7 f, t
  48.                 out     64h, al                 ; Out Put Port next - @9 Q! Y, R. E8 h) u
  49.                 call    A20Write
    1 E7 `( w8 `8 E. Z2 x3 a8 _& v
  50.                 jz      exit_disable/ h+ e! Q8 A" d; ^+ s" u1 I

  51. : Z% y4 Y6 J! e4 k: i3 m
  52.                 mov     al, ah & l$ s  j6 J$ M9 x& k1 ~  M$ Y
  53.                 and     al, not 2               ; Disable line A20
    ) M4 _$ M/ P8 y' E; M1 |
  54.                 out     60h, al
    " }. h! d% U" {
  55.                 call    A20Write
    ' ^  H/ |- E, m) R, L. N  F+ c
  56.                 jz      exit_disable
    $ i8 j( a0 r5 x' u

  57. : s: G) W5 R% J8 d
  58.                 mov     al, 0FFh                ; NOP
    & h! Q- |% D8 i2 l% x- l2 f# y; n
  59.                 out     64h, al ' {0 _& g0 y6 g, }5 B+ J" f
  60.                 call    A20Write 0 f8 p5 x" i0 s1 h( B- a
  61. / p1 Y3 I" x5 O( W! i
  62. exit_disable:          ret 8 q( E, Q, M  z/ G% s7 [

  63. 7 U- B4 a8 q/ y
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    . r  a. Y1 l0 a
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ( j# }" f/ {0 x3 V  g7 ?( w
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ( E% K) ^. Z: R" [) |/ T6 u! ?
  67.                 jz      clear
    ! B2 i$ |5 Q2 ^3 i! k% F
  68.                 dec     cx 8 F2 U( }6 a5 a9 P5 n
  69.                 jz      exit_write 7 D8 W$ z4 a; L, C
  70.                 jmp     short get_wirte : y( X1 }8 X. m, ^/ v
  71. clear:          inc     al                      ; Clear ZR ( Y' W7 N* ?& j) I
  72. exit_write:     ret 1 {0 c# j7 c9 H( |
  73. 0 J# b) I0 Y3 H5 H" ]0 J

  74. & A  K9 Y, W0 ^  y" i1 b1 ]
  75. A20Read:        xor     cx, cx
    ' f# C: X5 w. l+ p- f# `% r  H" ^
  76. get_read:       in      al, 64h 1 g  |& I& g  v* Z4 \9 ]
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( Y# g  x) \) H: |; E- \- m6 [' J
  78.                 jnz     exit4                   ; ... 3 q8 B' z  R$ Y2 h) {
  79.                 dec     cx
    9 o+ T4 G6 r) x! J! c$ ^& ^
  80.                 jnz     get_read
    ; o: O8 c- j* P" j% }" O, r8 n
  81. exit4:          ret     
    - x! O2 P7 T+ Y& X! K
  82.                 ' \) o2 F  R6 v6 s8 ~4 C& P
  83. end
复制代码
  1. ;A20STATE.ASM
    5 P- Y6 w2 j7 V1 _  C
  2. ; $ z5 k+ h" D/ ?) c0 X
  3. ; Returns the status of the line A20 through the KBC 8 j7 C5 G! F6 G1 \. ~9 d+ a4 @+ l
  4. ;       programming by bini for debug. 2008-07-01# }) H6 h  Z' b( m' B: y7 M1 _1 w
  5. ;
    ) O  r6 O4 u2 `+ ]
  6. .model tiny
    # Q. N3 J# S5 x: \
  7. .code
    ! ?( K* U3 g1 a) Q  |0 L
  8. .486% p8 s, f; n; @
  9. .startup. A' m4 c$ T; ^% R
  10.                 mov     dx, offset msg_fail
    . [  [  \5 \% P. i
  11.                 call    _GET_A20_STATE_
    , ?; y; L+ {5 Z1 B$ T
  12.                 jz      exit1                           ;  was a problem
    % }+ E/ Q, I+ u2 }% }9 D- [7 @& @
  13.                 push    ax                              ; Save state, AH / |$ O5 U  `0 ]$ s2 T4 _$ |  m* U+ k
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem ' v# W% b0 l! f; P8 P8 N1 p5 V
  15.                 mov     ah, 09h
    - V* P) U  W! H8 `1 j0 p- l( L2 ~
  16.                 int     21h                             ; Print message - t1 S0 a& w  M" O5 H
  17.                 pop     ax                              ; retreve state
    # M8 T8 R: L, D
  18. 0 R1 R: K8 H$ q. P* \
  19.                 mov     dx, offset msg_dis
    ; v8 j2 S+ I* k8 N+ y# q
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state : j0 g7 y7 G5 ^$ @9 e
  21.                 jz      exit1 , |8 ~7 x0 H& ~, I, n3 F  C+ W
  22.                 mov     dx, offset msg_en ' t# X/ w$ w  p' n; h/ u" B. A
  23. 0 @8 F% j# |& k5 J# H
  24. exit1:          mov     ah, 09h
    + \7 K3 X. u" g6 K
  25.                 ; DX already contains address of string , O  g* k! X+ A5 |* u/ q
  26.                 int     21h
    . B, G2 Q6 A: z! |7 h
  27. " p2 `& f3 D2 V2 z2 G
  28.                 mov     ax, 4C00h
    4 K( Z8 M; {" k  j( P3 z; f$ c, ]
  29.                 int     21h
    * K0 I- r' X) e3 m* g8 b

  30. ) V4 d+ [" ?) K& W3 J
  31. msg_ok         db      "OK", 13, 10, "A20 $" 8 T7 T5 Z2 K, E& `. |* k0 t3 g
  32. msg_fail       db      "FAIL", 13, 10, "$" 8 A0 e0 U5 e7 b6 p9 L
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ( u2 S2 A1 {0 M/ P1 d
  34. msg_dis        db      "DISABLED", 13, 10, "$", H  }5 u, x8 _, }' o

  35. # N9 K) p2 j1 [/ }
  36. , C: `) g7 L; O& ~# ^1 j/ c9 B
  37. _GET_A20_STATE_: 9 \. C% j! H9 G5 X6 i  K
  38.                 call    A20Write                ; Wait till the input register is empty " c+ i) j4 t; e% N
  39.                 jz      exit2+1                 ; Bypas the reset int's 7 A8 r8 \+ c( f# B3 r
  40.                 cli                             ; Disable ints so we'll get our value ( B7 g& U- m/ ?2 x5 r) E2 W

  41. $ N7 |. J: X) g0 r9 T
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 6 r2 i7 V+ o) J
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    ! L8 ~4 S% F8 Z7 H# _7 I( i5 R
  44.                 call    A20Read                 ; Wait till the 8042 output register
    9 ?  A. K7 j/ W& r$ {* k
  45.                 jz      exit2                   ; has something in it's buffer
    ' ^" O8 A0 F8 v  z& B

  46. 8 J1 q9 R* k6 U
  47.                 in      al, 60h                 ; Get it
    ' @# t2 [1 d* e6 M
  48.                 mov     ah, al
    3 n9 ]1 y6 M* W# P" u
  49.                 call    A20Write                ; Make sure the input register is empty 4 P2 [/ h- |5 u  W/ I
  50.                 jz      exit2
    ! J& l+ _! k' f, T, C
  51. 3 f7 j; h# D2 a) r8 U7 U
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing $ ]" J; M& y% q" ?! d& D  w5 L
  53.                 out     64h, al
    , ~3 n8 `$ B% T5 V. z0 [# q: T
  54.                 call    A20Write $ J5 G" J: s2 y9 K! }

  55. . I7 J: O) C+ }9 M* ^" G
  56. exit2:          sti
    * }9 Y6 |: _( f  `/ J$ V7 {; Z& A
  57.                 ret# z  R2 ~/ ^% @
  58. & B% E% ?6 L# u

  59. 0 b/ b- R4 z" x5 k; o3 e
  60. A20Write:       xor     cx, cx                  ; Reasonable wait " O! [: T6 ]8 p7 _
  61. get1:           in      al, 64h                 ; Get KBC read status
    - t. ~$ `+ W" u- C. q
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    3 E  H! B3 s6 h8 C& ~4 ~* g. R
  63.                 jz      clear
    , P6 S& n+ I7 n0 y
  64.                 dec     cx
    3 x) G4 J" S' {
  65.                 jz      exit3 4 E2 }4 I7 D6 k# b& [& c8 T$ J
  66.                 jmp     SHORT get1 4 p. [: E% h, y, |8 a
  67. clear:          inc     al                      ; Clear ZR
    $ B( H3 G! q% A
  68. exit3:          ret
    2 \' r$ _5 P+ D
  69. + ]% y4 t4 L& L2 y) q

  70. " C: u% e2 I& ?: u+ d4 _. j& w- T
  71. A20Read:        xor     cx, cx
    $ c* X! h! I" K. F2 }
  72. get2:           in      al, 64h
    $ i0 J2 `4 h" `7 ~
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    3 B# M7 r, q) k, ]2 _) o, _
  74.                 jnz     exit4                   ; something for me
    8 k( n; {1 t9 r9 k, R; {" x
  75.                 dec     cx : U# E3 q# J0 C% @
  76.                 jnz     get2! n( n* q- X" n7 H8 i; Y$ }( K
  77. exit4:          ret     
    1 E% Y1 }5 d$ ~8 Z: J
  78.                
    3 a& b# Z7 G/ y: l3 B: }  D6 t
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()5 V( \; e4 A7 I" n, ?3 j7 C( S
{        while(inp(0x64) & 2);        outp(0x64,0xd1);, \* z6 _1 A2 d, M" b) h+ e
        while(inp(0x64) & 2);        outp(0x60,0xdf);+ r9 Q5 G8 z+ @* J- c) r  z
        while(inp(0x64) & 2);        outp(0x64,0xff);9 B/ ~. q" m2 M" J8 R( v
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-29 04:41 , Processed in 0.029045 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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