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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM # Y' ~; I! a  j9 n
  2. ; 8 @6 `( a2 `6 a* c6 Y, `$ A
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01& x; h( n! B  r2 R3 V+ \" h
  4. ;       ml A20ON.asm % n5 ]  N! ~+ F$ c, C
  5. ;
    1 p- p. @6 Y* W
  6. .model tiny
    ) c4 ]% O; G, X7 M7 k% D7 v+ u
  7. .code9 v7 j' Q5 W7 Q1 u
  8. .486/ r6 V9 ^& v# Y# K' i! @
  9. .startup
    1 B8 B! q0 f7 h  i& N  Y0 K
  10. / e. `% N; Z7 `: Q
  11.                 mov     dx, offset msg_author
    5 P4 V, `. c1 |; D. M9 X% h
  12.                 mov     ah, 09h7 L+ T; y/ h4 N, A' K4 w, ]
  13.                 int     21h
    + ^# ]  V, Y6 r- a: A
  14. 9 @0 }7 q# f0 N# a& u6 Q5 Y0 }
  15.                 mov     dx, offset msg_fail ( B( J# ]6 J1 W1 i2 u5 g- }+ K
  16.                 call    A20_ENABLE" D4 l6 U. Y, b) t  e$ s& P
  17.                 jz      exit17 c: R# I  j) k3 j/ A9 J4 A: {
  18.                 mov     dx, offset msg_ok
    3 w; {7 \, G6 b; k- U. Q

  19. : U' W9 Z, k' M6 [3 O2 ~
  20. exit1:          mov     ah, 09h ! b0 p$ J1 y3 e* M
  21.                 int     21h
    6 V; I4 R' G* a/ P5 n/ C$ i5 e# G
  22.                 mov     ax, 4C00h
    2 w" B6 B8 `) ?$ O
  23.                 int     21h 7 z8 A+ C, F6 F. t. B5 c9 r
  24.                 . O* R5 s- b* |% _  ]* h3 N
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,( {3 I. H4 o1 Y: j$ U+ ]
  26.                         "2008-07-01",13, 10, "$"
    6 M1 Q3 Y; R, S( H( R- O& C  m$ N8 ^+ R! I
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    1 b  {" {' |6 a: `7 k
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 6 R: Y! Z+ \8 }+ x
  29. + p  Z5 w5 x( I* }2 G
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------4 E+ O  J. j6 J9 g: O8 {% g5 F
  31. A20_ENABLE:
    6 I- t8 @+ R7 \, t  _) j7 I
  32.                 call    A20Write
    + G% i6 z1 J( Q5 o
  33.                 jz      exit_enable6 @2 @8 i( [+ }% D6 H6 t9 E

  34. 7 |" ^& k/ m, @. H, g+ |1 y. m& n5 d
  35.                 cli                             ; Only need for reading value from KBC
    1 G! n$ U" ], i  Y$ s- s
  36.                 mov     al, 0D0h
    ( L8 D6 p# M6 q" }3 a3 X
  37.                 out     64h, al , ]" Z4 A2 a% A8 a  s
  38.                 call    A20Read
    9 ?8 p  Q# \+ c
  39.                 jz      enable_int
    9 Z3 U9 k- l: }# x7 W
  40. : X* E6 g; t5 {
  41.                 in      al, 60h                 ; Get current status
    & R( y  s, V8 D
  42.                 mov     ah, al
    * Z# X* @: V) U) l' p7 }
  43.                 call    A20Write
    . ~4 Q" X( D1 d# Z7 R, E3 |
  44. enable_int:    sti
    ( J6 l$ v5 I7 I+ [4 i
  45.                 jz      exit_enable
    : a6 N2 X; O% W: O7 G2 T
  46. 0 L0 d% M/ I0 G2 A3 ~4 f% k
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    $ R3 c  B' V7 |2 [
  48.                 out     64h, al                 ; Out Put Port next
    # v1 {: @/ R4 T% _* v  k9 n
  49.                 call    A20Write
    1 E4 X5 f" Y( w7 T( ]# e6 g6 a8 a
  50.                 jz      exit_enable
    & ?4 k3 {* N" S
  51. ! [1 z) e* l9 B; H( [+ f
  52.                 mov     al, ah & X: M) @6 n' L
  53.                 or      al, 2                   ; Enable line A20
    ! k1 [8 t/ d/ @; d/ j4 y9 E) F6 @
  54.                 out     60h, al 3 B' C1 X) l% Y( W
  55.                 call    A20Write * c8 ]3 s4 F* ]% q; E6 A
  56.                 jz      exit_enable- j+ ]" r! J6 v# p' q
  57. 4 x' w$ _; R* V
  58.                 mov     al, 0FFh                ; NOP 5 u( T, p, C% t9 E, T1 ^3 E
  59.                 out     64h, al
    3 N2 L( f- S$ z! i5 d2 G9 X3 I7 a
  60.                 call    A20Write 2 `# I* ]- M$ x/ V/ C

  61. # l  B- Z5 }* e3 S2 L9 j! i, h8 v
  62. exit_enable:          ret 2 O' j0 M9 \9 Y* E
  63. ! x' m0 w1 |5 `8 E" w+ m. i
  64. A20Write:       xor     cx, cx                  ; Reasonable wait ' Y/ `: m1 m8 S1 ]3 S$ @& F' Y
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    % D0 t) H+ ?' i
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    " b& P6 a$ r6 x
  67.                 jz      clear
    2 `" B3 ]8 g3 u% K% l. R' |
  68.                 dec     cx
    ' s6 O& f- ]: E# M* }1 Q6 m
  69.                 jz      exit_write ( I$ V: N. @. J1 [: i
  70.                 jmp     short get_wirte
    7 j( u$ m) k3 ], I) {7 I
  71. clear:          inc     al                      ; Clear ZR $ d7 o3 X' v" N% j9 {, z& z
  72. exit_write:     ret
    ; q+ J% B7 I' s6 _

  73. 1 M7 U3 U& B: R4 p& V
  74. ) a5 N) T$ x; b0 K# G
  75. A20Read:        xor     cx, cx
    1 d  M; H# z0 S$ x3 J5 g
  76. get_read:       in      al, 64h
    8 `( _2 o4 X  M$ D/ z
  77.                 test    al, 01                  ; If the 'output buffer' is full, has : w4 w, l6 W% x# e8 g6 d* l
  78.                 jnz     exit4                   ; ... 9 b+ |3 L$ M7 j5 o' [: @! {1 a# d
  79.                 dec     cx
    * w5 ^4 I; a4 a  y4 I# Y% x" }( G9 J
  80.                 jnz     get_read
    , Z% b* p& |- U$ Q. O
  81. exit4:          ret     
      c. e& C, ?) r2 q5 x1 t. T1 N0 {
  82.                 ; B: `* b) _6 x9 c
  83. end
复制代码
  1. ;A200FF.ASM
    ) i9 \8 }+ r& a. L+ q
  2. ; # X5 u# L) x3 [( f  I, G2 s
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " k2 Y& ?+ g! i2 `, }3 z
  4. ;       ml A20ON.asm
    * B, z$ S/ L2 |& M8 m/ c+ W
  5. ; 4 e3 a3 j+ J/ T' `& q
  6. .model tiny& J5 q9 v2 B+ ^5 O
  7. .code+ c) ]. G/ D* U5 b/ ~0 ^
  8. .486
    2 W. O; V; _/ F" Z
  9. .startup7 |6 z) \5 }# ?0 _! x* F. W

  10. / n9 z/ a) s& a
  11.                 mov     dx, offset msg_author: _8 j: g+ u$ Y( i& S- U+ v" c
  12.                 mov     ah, 09h
    0 {' e4 C; u% n% z. _3 }5 C4 S0 b* Y
  13.                 int     21h' n( D% J* Y4 d' ]
  14. * n9 |1 }+ @- R( O
  15.                 mov     dx, offset msg_fail
    * u9 X& e3 c; h2 V6 r# P8 ?6 I& V* z$ i
  16.                 call    A20_DISABLE
    6 c1 @2 B" L; ?: a- y
  17.                 jz      exit10 l+ g. {  ~# w) ^) L" [! ]
  18.                 mov     dx, offset msg_ok $ L+ V$ [, t9 r; R: R* H

  19. ( l, L8 l6 V! p2 z5 V' |
  20. exit1:          mov     ah, 09h
    9 D/ M9 Z9 ], Q. G' Y* z5 f1 Z2 j3 N
  21.                 int     21h
    * g# h  ]- d7 V1 m- j
  22.                 mov     ax, 4C00h 5 E! W/ [! E. t9 H' d3 L
  23.                 int     21h
    5 F$ a2 l, V5 l5 W( L- I- ?
  24.                   l8 Q4 n+ J+ c: ^& u: Y
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,4 Z' t+ Y8 ?( g) e
  26.                         "2008-07-01",13, 10, "$"
    ; A- E! u) @7 |; C. S- H
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" + ?  d4 C, u, F/ f
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
      S- ~4 h, |0 C9 ~
  29. 2 b3 n  q+ \; X
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------* h" a" Q- \, h9 R
  31. A20_DISABLE:
    . A7 ?0 E/ a/ k+ F
  32.                 call    A20Write 1 L$ W3 w* ~1 ?1 ]- w6 `
  33.                 jz      exit_disable4 q# s. }, o4 F( j  I; O
  34. 1 h1 Z# `3 K& v* n
  35.                 cli                             ; Only need for reading value from KBC
    ) ~  O; ?2 E' M( b0 I
  36.                 mov     al, 0D0h # R- D3 p; p; L. Y' t# Q1 K
  37.                 out     64h, al
    9 S2 d0 n. F* `* l
  38.                 call    A20Read ! a" L) e  y0 M9 i# k* `
  39.                 jz      Disable_int 2 j& k& |  p1 G6 Z; n

  40. ( u9 R+ U' s9 ?: G/ p
  41.                 in      al, 60h                 ; Get current status
    + c- ~5 o4 t3 @
  42.                 mov     ah, al
    7 ?9 B7 w, r% [+ ~2 j* Z. C
  43.                 call    A20Write : c( C$ |3 E; B& ~- g
  44. Disable_int:    sti + l/ `& E* O9 [/ a2 o7 f( P0 f
  45.                 jz      exit_disable" _* o6 w+ B5 H
  46. 7 X( S1 r1 b+ [* U& ]
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the   @. L( L# T% o! b# B" [5 p
  48.                 out     64h, al                 ; Out Put Port next - |- H. [3 |/ c- H$ L
  49.                 call    A20Write
    4 `1 }9 I- j5 n9 E
  50.                 jz      exit_disable8 F1 A+ C8 ~; o" c8 o1 Z' \
  51. 3 Z% |) d9 `8 H
  52.                 mov     al, ah ' P# H% Z5 W2 S
  53.                 and     al, not 2               ; Disable line A20
    7 e  I* ?8 s; ^0 i2 n8 w4 C4 `
  54.                 out     60h, al
    ! x7 z! `, K- x/ w9 y8 r. A6 N9 o
  55.                 call    A20Write
    # f7 [! ^2 f% \
  56.                 jz      exit_disable
    + `/ _4 F5 d( q
  57. ' w. m4 q! c' L0 K, n
  58.                 mov     al, 0FFh                ; NOP $ j. z# c6 v- i) `  l* z
  59.                 out     64h, al 7 I/ `+ {- ]) {
  60.                 call    A20Write
    : i- E9 w8 O0 b: }$ O# u3 ^; U
  61. 9 {( g6 A0 G$ ?! x* H
  62. exit_disable:          ret
    6 h) E) I+ N5 R& n
  63. 0 Q! L# L1 I# M# H4 x$ M% u
  64. A20Write:       xor     cx, cx                  ; Reasonable wait * c& c3 R# ^( c' Y$ F3 ~' f
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    7 u' N# W1 e" S& v0 e
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    / g% i% n* s7 O3 \- ]) D  `  x
  67.                 jz      clear
    ( l. @; U! f! M) j
  68.                 dec     cx
    , H3 z& w8 i# P) d" V
  69.                 jz      exit_write
    & r+ O( B) q+ f( D! J
  70.                 jmp     short get_wirte
    # }" J% D: i+ H
  71. clear:          inc     al                      ; Clear ZR 7 Q5 \( l8 o! }, f: s5 |# J* a' d- e
  72. exit_write:     ret
    & }3 H4 {! ^  d  Z4 z

  73. " q3 |2 ?( J$ ~" i% i
  74. * m" `+ u- I4 m$ h0 K" I% r5 Z+ B5 t% N7 X
  75. A20Read:        xor     cx, cx
    - Z9 [9 `) L- w" Z  g
  76. get_read:       in      al, 64h ( c9 y) |1 k2 l( Y
  77.                 test    al, 01                  ; If the 'output buffer' is full, has   t3 j0 q/ f! H8 e/ l- M
  78.                 jnz     exit4                   ; ...
    : ?0 [9 {! |! O. h$ x4 l
  79.                 dec     cx
    : g, ]! {& c7 Q) s9 Y" E9 N
  80.                 jnz     get_read
    7 m" c' T' U5 N4 Y
  81. exit4:          ret     & H3 J" |2 K1 [
  82.                
    & \: b4 C# V) [& m, f, A2 p# u
  83. end
复制代码
  1. ;A20STATE.ASM
    8 v' p" B/ x& V9 W: M9 j2 g. K
  2. ;
    % N1 I2 v' y( O
  3. ; Returns the status of the line A20 through the KBC
    % H  }% V6 x" f4 L* p# a( p; W
  4. ;       programming by bini for debug. 2008-07-010 ?. W- {6 ~8 H- A- T$ u
  5. ; " s/ h) F& z/ u. c. b2 ]
  6. .model tiny8 E6 T8 f2 c/ t5 M/ j& @, [, I
  7. .code9 H2 `) r6 [" A7 H# U4 ?9 o
  8. .486
    2 \% x8 A, p: |6 W2 b
  9. .startup
    " c1 V& L7 _: Q
  10.                 mov     dx, offset msg_fail ! o: Y% I1 D' M- Q
  11.                 call    _GET_A20_STATE_$ v( a4 N4 q: D, z, l( T
  12.                 jz      exit1                           ;  was a problem/ c: ?$ Y! j; Y0 V# Q# a
  13.                 push    ax                              ; Save state, AH
    1 e; k  v1 g9 Q( S
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    2 A) P- j0 ~! I( ~& M- d7 D
  15.                 mov     ah, 09h
      l% N$ R: V3 O( v1 p
  16.                 int     21h                             ; Print message $ _. Q% S: ]3 R
  17.                 pop     ax                              ; retreve state # p* f7 a! r3 f" A2 K, `" E) b
  18. & q2 W: l7 d$ `& `  V
  19.                 mov     dx, offset msg_dis
    $ ^7 K; F1 u9 q  v& F3 i
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    ' f7 D( Y" E% V% n! y  S$ ?
  21.                 jz      exit1 / D& l! R# z9 [& }2 Y
  22.                 mov     dx, offset msg_en - c& t0 V  O  s0 W1 F
  23. ( m  d# |7 V* h9 e& r3 d& w& h+ {
  24. exit1:          mov     ah, 09h
    1 `1 G" V  G- ^/ {8 _6 o
  25.                 ; DX already contains address of string
    8 c( {/ B4 ~# e. n
  26.                 int     21h
    # u# i" [# \) _

  27. / f3 _: z1 K5 W1 k+ j
  28.                 mov     ax, 4C00h " }  X% B- K4 ]7 b
  29.                 int     21h
    * f9 Q* F0 M' e3 o
  30.   Q5 k" v4 i6 S: Q
  31. msg_ok         db      "OK", 13, 10, "A20 $" - {$ W% {) ^" G" a
  32. msg_fail       db      "FAIL", 13, 10, "$"
    $ s" d* [% Y; v2 f  `. C4 P+ h
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ( D' H7 B/ ^: F
  34. msg_dis        db      "DISABLED", 13, 10, "$"% M' t* C, S7 g# G/ E8 N+ g1 D2 w, W

  35. % Q/ i9 U) T0 E) E9 W7 h3 y3 v" G( Y
  36. # d# D' t8 T0 f! ~
  37. _GET_A20_STATE_:
    % w& `1 O# m" y/ G, w5 m5 E
  38.                 call    A20Write                ; Wait till the input register is empty . F8 J7 I. Z& P
  39.                 jz      exit2+1                 ; Bypas the reset int's ( l; T6 f' H- u) K9 f* v6 L
  40.                 cli                             ; Disable ints so we'll get our value
    6 N& m& e% b! q1 E% O

  41. + Q$ O! e6 J, C6 ]6 C6 b
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register , e) P$ K! O) T. a* k4 n3 g
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 7 `6 N! `' C* E- n2 R
  44.                 call    A20Read                 ; Wait till the 8042 output register
    0 b% i* j' t& n5 r
  45.                 jz      exit2                   ; has something in it's buffer
      Y6 d# x  [" F2 B0 r
  46. + z7 z. Y! q; L( ^$ D( U
  47.                 in      al, 60h                 ; Get it 6 [0 ^1 E+ B6 K! o8 H
  48.                 mov     ah, al
    + r. J6 U* j6 ^+ t; e5 S
  49.                 call    A20Write                ; Make sure the input register is empty
    : s' K6 R/ j; O- F2 x4 A; a+ V
  50.                 jz      exit2
    4 Q. @! e. j/ Z0 n. a

  51. ( g+ m( }; {( D6 A
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    / r# D- S" Y' s0 V% U
  53.                 out     64h, al 4 K- d: A# m# z9 x1 D# g
  54.                 call    A20Write
      @- Z; ]7 D2 M) X4 d% o7 H
  55. : X. M- a! r) |
  56. exit2:          sti ) N6 ?! n" q6 [$ F5 y/ X: p. p8 R+ }
  57.                 ret
    , c& \: r7 L0 X( M0 l5 Y
  58. ( M4 j$ V3 [; A; Z5 x$ t
  59. 0 N  I% |5 @: f+ o' A
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    # O  S8 ]: r" M
  61. get1:           in      al, 64h                 ; Get KBC read status
    . J/ B  k! g& w# ^
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    , Q4 h7 W5 ~5 O( ]4 A  d7 S8 o
  63.                 jz      clear
    ; b$ C+ m: E; G/ `( {/ l" e* U
  64.                 dec     cx
    * q6 T+ O' i2 Q9 I
  65.                 jz      exit3 . F) Y( [/ W/ z6 Q' \+ A7 i2 `- y
  66.                 jmp     SHORT get1
    ' n; o) _1 M, S+ Z: |
  67. clear:          inc     al                      ; Clear ZR 1 E8 X8 M6 Z) m  N  ]; u, U* {' e9 c
  68. exit3:          ret
    7 S- Y' Z. }+ d) |* Y7 s: N

  69. , u3 V5 C4 x9 \4 s" Q, {4 X& R8 A; u

  70. / S  m" Z0 D2 k* @/ W
  71. A20Read:        xor     cx, cx
    4 F7 t! a0 _4 i  n
  72. get2:           in      al, 64h 8 p. t. Q; Q" X0 l9 |' o  U9 ?
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 6 F- c5 y& ]  p5 E$ q8 N1 e
  74.                 jnz     exit4                   ; something for me
    # J' z8 b2 x$ T' [
  75.                 dec     cx
    / X" k" X; z% I: z0 M+ A. q
  76.                 jnz     get2
    ) o' I5 {; y& N# \- ?
  77. exit4:          ret     # g0 }. _0 N2 r6 T5 u2 J) T5 X
  78.                
    " _% L- k- g- F. L
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
9 [6 V- \" U* z{        while(inp(0x64) & 2);        outp(0x64,0xd1);. ~3 s& A) }) p$ i) {: K2 A& }
        while(inp(0x64) & 2);        outp(0x60,0xdf);) Q% m$ g2 X0 m; n* ^" U
        while(inp(0x64) & 2);        outp(0x64,0xff);
' R7 x3 W: ]# ^+ }& V9 ~; [}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-23 10:15 , Processed in 0.037367 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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