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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 5 B0 ]& W. ^1 }/ ~* @: c* x& N  J
  2. ;
    & K; K* n4 ]: c" `9 v
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01  l; l8 x2 _  C5 m% L* X- @; L
  4. ;       ml A20ON.asm
    5 v6 L& T6 F, b* P
  5. ;
    0 U3 w6 w5 c* F9 x5 R
  6. .model tiny+ A- \# }6 H* q8 i
  7. .code" Z: R) J0 W) m% j" l: |7 S
  8. .4864 |/ W9 d( j7 ?) e& D
  9. .startup6 q0 j- B- ?; L

  10. 9 j8 E$ c; B  |
  11.                 mov     dx, offset msg_author
    ; R2 {3 u3 T6 w5 F8 {% b( Q! v0 X  N
  12.                 mov     ah, 09h
    6 I7 z& z) L4 ~" d& _
  13.                 int     21h
    / W8 P! k* l4 V% X9 l# Q

  14. * z# r3 F2 n7 a8 W8 ]
  15.                 mov     dx, offset msg_fail 5 R7 L+ y5 f7 A
  16.                 call    A20_ENABLE* _; {* g7 `+ x8 l2 `
  17.                 jz      exit18 a- G" a. l2 J9 h& v
  18.                 mov     dx, offset msg_ok - q0 X" {# ]+ N# Z
  19. 4 n) y; W; D% `  P& |6 \
  20. exit1:          mov     ah, 09h 4 J) ?5 y) {4 r. y0 J
  21.                 int     21h 5 R! R% A- v+ x. j1 _& \# [+ v
  22.                 mov     ax, 4C00h
    7 s3 }0 [& O2 K3 \1 K
  23.                 int     21h
    : U$ T9 M( b! M% ^
  24.                 7 X1 v7 j4 }) j# p- W
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,! B: n3 w% S% Q2 R
  26.                         "2008-07-01",13, 10, "$"
    + o5 z! U- {9 x3 y$ e
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    * Y1 U1 P# ~3 |0 Z  y
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"   j+ B0 ^- W, {6 \# h

  29. ) S7 }7 |6 H) H
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------: ?1 w/ g2 t; a1 g0 ^( U
  31. A20_ENABLE: 3 Q, x) ^7 |: J4 r
  32.                 call    A20Write
    / Q! W& W; h, F  p
  33.                 jz      exit_enable* ?) T  E  S$ _$ J, \- N) Z. d
  34. % ]7 c/ [3 Y$ i) ^  A
  35.                 cli                             ; Only need for reading value from KBC
    , r# @& b, T0 t3 k
  36.                 mov     al, 0D0h
    ; C0 Q, E: P$ ^7 i  ?! L- O' k2 y4 A
  37.                 out     64h, al
    / B; G0 [* n, A# u- }  ^% Q
  38.                 call    A20Read
    6 b+ r5 j  R" k
  39.                 jz      enable_int
    % R4 F& U. z* p' p: A6 d0 ?+ f. Y5 [

  40. : H: W$ f3 V" W0 `6 j
  41.                 in      al, 60h                 ; Get current status $ ~6 h2 A8 L3 F1 [/ D% K  O  J
  42.                 mov     ah, al 0 P: E, h) o+ {. V
  43.                 call    A20Write
    " @4 R( I" T9 m1 V
  44. enable_int:    sti 2 x- D0 ~9 u3 }5 O
  45.                 jz      exit_enable
    9 k: {/ w/ w" M2 F, ]# M! b

  46. - L; b# x4 z: S5 I! G- i$ w
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    , Y/ W& w, ~4 B6 z0 `: t: q  x
  48.                 out     64h, al                 ; Out Put Port next
    7 @+ B$ x1 b: e5 }- W! v# i
  49.                 call    A20Write 3 s& U6 a( E! x, t0 ]
  50.                 jz      exit_enable1 x* n3 p1 P$ o, b9 H0 u; Q+ S

  51. 0 v7 T) E, r$ S" ]* |% Q, q# C1 c
  52.                 mov     al, ah # X; t5 s6 }7 L6 Z
  53.                 or      al, 2                   ; Enable line A20 - v( ~& V  a( g2 y& ~1 Y; {2 v
  54.                 out     60h, al
    7 L9 `, K* T" [6 a) [( ~  f
  55.                 call    A20Write 9 u, \3 z4 H6 M) b  Y) i
  56.                 jz      exit_enable( Z: D# Q" q8 g, D2 I7 R

  57. & E8 R) @& M9 }" i; n5 Q7 h; S
  58.                 mov     al, 0FFh                ; NOP ( O. c. A( q" x8 e3 B0 H/ J
  59.                 out     64h, al / m9 S7 G3 H6 c, T8 i0 X
  60.                 call    A20Write
    + r/ p8 t/ I: a% u. B$ O

  61. ) ~1 }  ]0 }% X3 D9 W% Q
  62. exit_enable:          ret % w* h3 S. J$ S6 R* J3 E$ e
  63. 6 ^- Z: O! q+ S. Z
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    " E0 q1 ^1 q3 T& q- i+ u5 b
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ( c4 ]$ I, E! i8 g, u" [
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    - Z7 N: i" k, n
  67.                 jz      clear
    ) G5 U) V+ r7 Y( `
  68.                 dec     cx
    9 w" R1 [) M! z! C7 y- |9 |( j# T
  69.                 jz      exit_write $ _1 [9 p9 K9 i! ~$ W
  70.                 jmp     short get_wirte , T4 X4 C  z. x4 [! T/ w( p
  71. clear:          inc     al                      ; Clear ZR
    / X2 ?; `+ @: ~0 |
  72. exit_write:     ret $ Y9 v0 R0 ]6 Z! v+ E, g

  73. ) H& u! z) P  q9 H$ Z% ~3 w

  74. 2 U4 N  ^( L: Z. l3 n- }
  75. A20Read:        xor     cx, cx
    + y4 ]9 Y0 y& b0 l
  76. get_read:       in      al, 64h % b5 I: ]- ^. Y1 C& l% x% E( T$ L
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    + T, |9 ?# I& A1 F6 n: h
  78.                 jnz     exit4                   ; ...
      B7 U6 f5 J! R/ m
  79.                 dec     cx 7 F. s1 F* g0 z+ ^! e( C& w9 V8 v
  80.                 jnz     get_read* |. k+ o+ y2 B- m8 v
  81. exit4:          ret     2 T$ m* m' @: E5 m0 g
  82.                 $ p. s) B+ |/ _: [
  83. end
复制代码
  1. ;A200FF.ASM 9 F( y; B4 d* a* s8 O# j
  2. ;
    , y( J7 }. B, N2 P; H, E6 m3 ~
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    5 K2 i- S8 o# F
  4. ;       ml A20ON.asm
    ' W2 b8 B/ z( [4 I5 P6 u' ]. s
  5. ; $ c; ]9 Q8 s* A+ Q. d0 T, m4 Q
  6. .model tiny
    9 F, B1 i7 z, e8 X
  7. .code( _# }* I+ P6 f: V5 t# o- V. \
  8. .486
    3 e2 A5 }. s* o( ~
  9. .startup1 P# J# H6 ?4 b$ j9 L+ E
  10. ) ?$ w8 s6 C5 c
  11.                 mov     dx, offset msg_author4 b, B8 k0 M2 n" S. u
  12.                 mov     ah, 09h4 Y! K( I8 _4 S3 J
  13.                 int     21h
    4 V, {/ n/ s9 |
  14. + Y( J5 H1 D0 x+ U6 S
  15.                 mov     dx, offset msg_fail
    6 i2 c! x0 Y& W. r6 P
  16.                 call    A20_DISABLE3 h; Q5 B; X3 Q4 g8 C4 A
  17.                 jz      exit1* w0 o# ?* l! y9 b% X
  18.                 mov     dx, offset msg_ok 9 b. {0 F; X  y3 k" P

  19. 1 C! K) C( F2 s& t$ y) F
  20. exit1:          mov     ah, 09h
    ' ]0 V# k; Y4 r, a9 O
  21.                 int     21h
      [/ m) a' `/ w+ j( m! [1 y
  22.                 mov     ax, 4C00h
    9 j0 A; H4 C3 b$ B& C. @( Q. d- I
  23.                 int     21h
    % m1 F. {6 V! `& u" x
  24.                
    6 U& n8 g+ |, P# I6 e) h0 R& f. w
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,4 Q" h2 z* ?9 I, k8 u8 i: G
  26.                         "2008-07-01",13, 10, "$"
    ' N( b4 Q  G2 V& i
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    - p5 G: o4 [- B9 v
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" $ c" W9 x: E; x3 h+ d7 Z" |

  29. # K! |; u0 m% F8 c! ]* l3 @
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------  i/ b0 z. |7 h- J: Z5 s
  31. A20_DISABLE:
    ) |0 I$ S* D% Z7 i. a) _4 I
  32.                 call    A20Write 5 q5 R5 v" _3 h* y3 L
  33.                 jz      exit_disable. W/ d+ P" R" o* D8 {4 W

  34. 1 `& T8 R" ?1 ?
  35.                 cli                             ; Only need for reading value from KBC ( `: B1 t1 m0 d' ~& c/ s7 d
  36.                 mov     al, 0D0h
    % {% [* g: z9 r( C5 ~
  37.                 out     64h, al & J$ t3 ]4 Z4 X7 K
  38.                 call    A20Read ! y3 O) j6 H0 n* J( M4 r
  39.                 jz      Disable_int
    3 g% {) _( S* q3 J. g
  40. : I6 b1 A; p# J4 l1 x$ C8 N
  41.                 in      al, 60h                 ; Get current status - y5 o' B6 p* y6 s* R
  42.                 mov     ah, al
    ; y) I4 K6 u3 b1 v; p
  43.                 call    A20Write 4 W: s7 V( j  w1 h9 C* h9 C) h* O0 `
  44. Disable_int:    sti
    0 n) p) C4 g; b, O3 u  [3 Y' D9 L. b
  45.                 jz      exit_disable' ^6 x$ w5 z2 K5 y, d* P

  46. 1 F: e1 |. W8 A% r
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ( y2 o7 j. o* O- `3 B6 m  `5 c- Y, g
  48.                 out     64h, al                 ; Out Put Port next
    ' _3 g# c7 Y* S0 C
  49.                 call    A20Write ; k! i8 J6 V2 r% I1 }& O5 y
  50.                 jz      exit_disable5 _; _4 F1 V+ _
  51. - \. e, b5 l4 C1 @4 Q
  52.                 mov     al, ah ! v! J# q* v8 A4 E- @& J4 C
  53.                 and     al, not 2               ; Disable line A20
    - \  E! |6 v; O' j8 y
  54.                 out     60h, al
    # p4 Z1 p; Y# e4 i; i- e
  55.                 call    A20Write 4 @- h2 R# t* @+ o/ A: }2 D( h
  56.                 jz      exit_disable
    : P2 B& Q& ]* B/ y) o' t- H) g

  57. 5 K1 J* h  r9 B
  58.                 mov     al, 0FFh                ; NOP
      B6 D+ `' D  o9 B/ o' c
  59.                 out     64h, al
    3 {% Z& [- g) o* y% y3 L
  60.                 call    A20Write 6 u5 ^, ]8 Z; `! p# |  V& t% d

  61.   T; C( [) A1 k6 I3 Q1 \
  62. exit_disable:          ret 4 D$ A$ q* n8 _. X4 P$ f, F

  63. - d* t. u. \8 z, w% s
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 C' p7 B( n0 {* n
  65. get_wirte:      in      al, 64h                 ; Get KBC read status   w9 T7 K( m4 R3 N' s7 c2 n% j
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    4 W  X( Y$ m7 o/ U' {- c2 d# Y
  67.                 jz      clear " R( R: Z8 w4 h* m9 C7 e& b
  68.                 dec     cx
    8 M* E& N0 W+ ?) G; ~  o
  69.                 jz      exit_write
    " v% ~, ?, ~, q! v4 K* c' u* S$ N3 b
  70.                 jmp     short get_wirte
    ' k6 O) D4 I# v. }
  71. clear:          inc     al                      ; Clear ZR
    % T- P* u' b' m! N& b
  72. exit_write:     ret 2 o: q" p4 L% i$ v
  73. # p" u6 l. F, b. b  L8 J. u  N

  74. + w* U$ B2 t0 V
  75. A20Read:        xor     cx, cx
    0 x1 I. O( P8 d& |2 w; X
  76. get_read:       in      al, 64h ( W) C% Y) |& I
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ! q+ r: |, Z% Y0 g5 |( J6 V1 _% v
  78.                 jnz     exit4                   ; ... 5 V8 y& Y2 Y* p! N9 D8 }
  79.                 dec     cx
    7 w, r. c1 _+ B4 U9 A# E
  80.                 jnz     get_read! J2 ~9 n+ [/ {
  81. exit4:          ret     7 _+ ~. ^7 O/ `7 e% d7 S6 u
  82.                 1 U5 z  @0 [( e" \! |" O
  83. end
复制代码
  1. ;A20STATE.ASM 9 k; R; Z1 P5 Q1 q% V4 ~% k; ^: ~
  2. ;
    8 j" g+ ~" r- [* \: T+ r2 ^
  3. ; Returns the status of the line A20 through the KBC
    + }) S. D+ f/ B6 Y
  4. ;       programming by bini for debug. 2008-07-01
    & t% @0 p- H2 O+ d* ~; I% Z
  5. ; + h! ]" [, w2 [
  6. .model tiny6 t& g) R1 z4 ~; B, t# p
  7. .code
    : ?: o- }) w4 A2 z, c8 A  O6 a5 j
  8. .486) s( t% }" [" m& v9 x
  9. .startup
    # `. Z0 Q+ y, i# u. S
  10.                 mov     dx, offset msg_fail : M# I0 l$ S9 D0 b! \3 P3 _
  11.                 call    _GET_A20_STATE_
    , ?; b7 r3 t$ A+ R! E5 V' w# ]
  12.                 jz      exit1                           ;  was a problem
    . H9 L/ G" Y2 J- r) }+ }2 B% ]. y, E- T9 \
  13.                 push    ax                              ; Save state, AH
    2 ~$ x$ ~0 e4 U  U3 g1 M* p1 [
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem ( W; ^. O% Z$ P
  15.                 mov     ah, 09h - ^2 K3 z- @* [$ `5 A/ x
  16.                 int     21h                             ; Print message + X  E* F( l* W; |0 V
  17.                 pop     ax                              ; retreve state . f( ?5 }% z: h3 P8 {6 v
  18. 2 O/ b5 A/ w( \$ z, N5 q; J
  19.                 mov     dx, offset msg_dis
    $ ]7 x) s/ _6 F$ N' q8 v" |7 d
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 4 {4 T# u. J5 q3 y9 O( {" N$ |
  21.                 jz      exit1
    9 i% c8 L; ^% h  c6 Q9 a: X$ O
  22.                 mov     dx, offset msg_en ) J; r) Q% A% g% Y" a$ u5 F; g

  23. 2 ^5 R# m2 e" e) l  H& w' V
  24. exit1:          mov     ah, 09h
    , X$ Y4 E: `/ h7 A
  25.                 ; DX already contains address of string . o1 d: @6 i2 d! A9 x5 r
  26.                 int     21h
    9 @6 v! b) J; R9 z; [- g5 y0 T/ t" R
  27. + I. s' ~% L# U! T+ j& }
  28.                 mov     ax, 4C00h & P* e6 |3 n. J0 k
  29.                 int     21h 5 Q# g; U% `  }& X+ w. M" i
  30. 5 q  w3 b8 A, c# Z
  31. msg_ok         db      "OK", 13, 10, "A20 $" ( m+ v3 f* O6 t) w) K# Z
  32. msg_fail       db      "FAIL", 13, 10, "$"
    . e8 t9 t( \( H
  33. msg_en         db      "ENABLED", 13, 10, "$" 7 \$ G! G) f) s' N
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    7 g3 X5 ?3 c  g! `! V

  35. 2 ]4 F: _6 a0 `3 Y* x

  36. 7 ]/ q3 U; g" l; }" J$ x: N4 h" _
  37. _GET_A20_STATE_:
    - R! R8 a* V5 ?/ _3 {
  38.                 call    A20Write                ; Wait till the input register is empty + I6 |+ i6 Q1 \/ n) ?3 z, L( g
  39.                 jz      exit2+1                 ; Bypas the reset int's * b; t* D0 P  l9 ?
  40.                 cli                             ; Disable ints so we'll get our value ' c5 r7 ~5 H9 H& l" B/ R

  41. 7 `8 V0 n% _( i% ?7 R4 u6 v
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 3 W8 s, }( e( c- O. t* B  [
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    3 f& |* r# \7 s! r0 h
  44.                 call    A20Read                 ; Wait till the 8042 output register : b0 \7 ]: p# D* E  j1 S
  45.                 jz      exit2                   ; has something in it's buffer
    6 t$ `+ J( i$ x# I

  46. * w" Z( G& H( H- @, C5 w+ `$ t
  47.                 in      al, 60h                 ; Get it 6 X5 x, ]7 p9 q. \$ G2 Z
  48.                 mov     ah, al 4 }# E" p: @! |" J- T
  49.                 call    A20Write                ; Make sure the input register is empty 7 Z  M' \  J1 L5 A/ B
  50.                 jz      exit2
    - Z, z2 x$ a8 m2 m6 ^6 j

  51. : ~4 Q6 a6 l! c2 z; K) s
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 1 [* e& J, E+ m( R! p+ r  y; x& T3 _
  53.                 out     64h, al
    6 s* l! ?% r! e% V/ e
  54.                 call    A20Write 4 @% f9 B' I) {. E' l  @

  55.   r0 O3 g7 B# C0 m! Y
  56. exit2:          sti
    7 Z$ O- E8 M& S; ~
  57.                 ret
    5 t6 U3 _; R1 _& e5 c- l
  58. , i$ \% }0 A4 J/ [8 s2 k9 |( C

  59. 5 q) o6 _) `/ U: n
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    ; ~  Z! `3 ?& p# l7 H5 T
  61. get1:           in      al, 64h                 ; Get KBC read status
    ' \9 f9 `7 s3 h& |% f3 r
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    1 \# I, |+ A& {5 Q. \0 |* L
  63.                 jz      clear : @0 \9 S1 L2 i9 e
  64.                 dec     cx - @+ @" V& W! Q8 V# l( I
  65.                 jz      exit3
    0 p1 H2 L7 N. g1 E, V7 g
  66.                 jmp     SHORT get1
    / C' ?0 T' _, @
  67. clear:          inc     al                      ; Clear ZR * l4 m' w) J" _6 E4 c5 @; S/ A0 W* w
  68. exit3:          ret
    + M5 n$ b/ S  g6 s+ }: F) D! p3 L* Z

  69. 2 c% m, U+ F; L! b8 l! `  A

  70. 1 v* g4 `+ {/ ]; ]$ v8 D
  71. A20Read:        xor     cx, cx ! x9 l& x" z3 t0 g" t  F; R
  72. get2:           in      al, 64h
      j1 C4 Z5 N0 X8 r! j8 ]
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 9 c6 l$ @4 T9 H
  74.                 jnz     exit4                   ; something for me 0 g' U2 V+ B  j
  75.                 dec     cx 3 l6 n, o( I9 S# e
  76.                 jnz     get24 o- h( q, \, H  c8 w/ \) I
  77. exit4:          ret     # K. Q4 Y% Q5 N) z& ~& p. g$ I
  78.                
    # O( X$ h3 t( _" E: o+ r
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()2 r; }5 f- f9 i9 E
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
2 {  [& @0 ~! l1 a, C1 @+ e0 l' C        while(inp(0x64) & 2);        outp(0x60,0xdf);
- X- ]  k% L. d! a" J* i% k; E        while(inp(0x64) & 2);        outp(0x64,0xff);
; @+ O% f: p- N' h}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-18 22:41 , Processed in 1.002538 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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