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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    ) V$ K4 X! I: p3 }' d0 t  P( X
  2. ; / l2 T( ?) t( G# t2 u9 e
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-019 R2 z6 r" j1 J( @
  4. ;       ml A20ON.asm 5 M- _6 y% Y; t7 d* a
  5. ;
    6 U; w& q' i' F  q* K% s5 @, K" H( N
  6. .model tiny, ?7 k- L. E8 {: E+ Y7 G
  7. .code
    7 t; G$ q) E" w! Y. J
  8. .486; [" i% f  z' Y+ i. Y
  9. .startup
    " x1 U) m# L; y% O* z

  10. ; e1 T0 u) z$ H- U  Z+ y. Y
  11.                 mov     dx, offset msg_author" ~6 l4 B/ P; s+ A  ]
  12.                 mov     ah, 09h
    - ]  Q* ?% P" X& W/ I$ I5 q
  13.                 int     21h: u6 }0 n) o1 N! {& A6 [
  14. % X5 z* d4 _) q" ^/ ]% P0 f3 Z
  15.                 mov     dx, offset msg_fail # z4 t& d  ]0 K9 S" J
  16.                 call    A20_ENABLE  U; \- V2 h8 Z' E$ X6 ?
  17.                 jz      exit1# f2 T5 X4 w! ]: h
  18.                 mov     dx, offset msg_ok 4 F( _- |3 B3 h; z- K& m) P- H

  19. 1 E: Y( }, d: y3 o# W
  20. exit1:          mov     ah, 09h
    4 A6 _- H1 [# _3 L* p% y2 l
  21.                 int     21h 5 B8 A  m4 y! G6 j6 s% U7 a5 f
  22.                 mov     ax, 4C00h
    2 q2 B0 l1 @3 g$ D
  23.                 int     21h
    9 h8 `  M# L8 z" N- L- v9 i
  24.                 ( W: T; R: Y6 M
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    % T# w0 J+ J, L- m  ]  h
  26.                         "2008-07-01",13, 10, "$"
    , n2 W; v* V7 ?: Y# Z; V& @$ V) z
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" . N' E! g- [0 H3 U
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" ' x7 j6 g8 }6 q! _9 Y

  29. 6 ~& Z1 p: v% k3 g; o, n% N1 X
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    5 H; j+ b% F% `7 j
  31. A20_ENABLE: ; E8 m. M  q: b- k0 Q; s
  32.                 call    A20Write
    2 e$ I7 N$ |9 F! z- R' Y/ L1 F
  33.                 jz      exit_enable
    ' R" h  z! Z" H9 ^8 p

  34. . L+ g; M& s! Y" m! J4 a4 e& `- \' Z
  35.                 cli                             ; Only need for reading value from KBC
    ( \2 ^0 _8 v$ W$ t! }+ I9 C
  36.                 mov     al, 0D0h % b& n/ D" K. z8 c- _- ?
  37.                 out     64h, al 6 C, p. b. f; ~* [9 e
  38.                 call    A20Read
    4 b+ i, H0 F0 e& T2 \1 D
  39.                 jz      enable_int
    0 O( Q$ x1 H5 c* k6 g

  40. 7 K! a# o, M' O* i8 |
  41.                 in      al, 60h                 ; Get current status
    5 S7 P0 H9 s( {* S* d
  42.                 mov     ah, al " z* H: P) [5 m5 q1 w* a
  43.                 call    A20Write
    5 S/ E, {/ {5 @
  44. enable_int:    sti ' C; u  C! h2 g, m0 S: j2 s
  45.                 jz      exit_enable
    5 j. H& T* s$ m

  46. , i3 {0 B, D/ C
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the : [3 i* M4 w- z) [
  48.                 out     64h, al                 ; Out Put Port next , g; e9 X2 k( B9 v8 D0 N% g5 b& k
  49.                 call    A20Write
    ' u/ x4 j7 x& ~" r$ d0 k+ C. G
  50.                 jz      exit_enable
    ! w  k6 u) `& t+ j7 q: C: `

  51. " v/ I- b  d' q5 J9 ~$ k4 C4 l2 {
  52.                 mov     al, ah
    2 \0 V( \1 K+ Y' u
  53.                 or      al, 2                   ; Enable line A20
    . G6 x& U0 s" V  s" K- Y
  54.                 out     60h, al " l. i5 s8 ~" n& z4 d7 s# X
  55.                 call    A20Write : Z" f4 t3 D9 b  f7 Q3 w( S& M; M8 l
  56.                 jz      exit_enable0 D7 p0 y6 }$ \% i# E9 U; X
  57. ! w; [& d1 J+ r  c& ]
  58.                 mov     al, 0FFh                ; NOP 9 q, p: P6 v, @" T3 k2 i$ b+ V- t2 G
  59.                 out     64h, al 6 ^- a( k' B" q  a
  60.                 call    A20Write $ q9 O+ T) |# V; f- y) L

  61. : Z, g% J, i! w: \
  62. exit_enable:          ret ) [5 z* C5 G8 T0 Q3 x$ r) |% E

  63. # }! Z- ^1 f; _4 P' c* z
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 8 h3 A3 s9 R0 ]: F3 l7 H
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    8 N2 O& C- d4 c0 R2 l  ]
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    - c) E) a2 E% E, E: T, c# w
  67.                 jz      clear
    . p/ F2 t7 d* A4 }) m
  68.                 dec     cx % Y* z: ?* e6 Y2 d. \
  69.                 jz      exit_write
    9 Y0 ~( ~& q# d* O# V
  70.                 jmp     short get_wirte
    7 o7 C& H9 G# _+ e: I: x* ?/ Q
  71. clear:          inc     al                      ; Clear ZR - ~  A: E: G, t& f
  72. exit_write:     ret
    2 `8 _) c) t3 U" m) j/ J# N, q

  73. 7 _! ^, q- \/ Q$ G7 ^4 b1 L

  74. 9 R+ k& J  d# R; x8 J6 W7 @$ ~
  75. A20Read:        xor     cx, cx 3 E. p) x$ Y- v7 i" I# m- S
  76. get_read:       in      al, 64h # T2 r4 E6 Z; W6 z2 g
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    5 _) v2 K& t9 B
  78.                 jnz     exit4                   ; ... 4 Y; X% h2 }) A# f
  79.                 dec     cx
    7 `' i1 O% k/ a, R% J" q
  80.                 jnz     get_read
    7 T" a! {8 y& k: c5 V9 l! B
  81. exit4:          ret     
    ; P7 [% D! x" d' D+ G: _
  82.                
    $ [* j3 Q9 w2 z* [5 n, j' @
  83. end
复制代码
  1. ;A200FF.ASM - A! f7 X0 v2 \$ m: B# g$ R2 T  H0 e  t
  2. ; ! B  v, C8 ?8 D( R& c
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ; y" [" X( v. z4 p, d( s
  4. ;       ml A20ON.asm 6 U2 E* \9 A2 T; L# C" t/ k$ a# J
  5. ; % s2 u/ t0 `6 I% y  `. K
  6. .model tiny0 I) c% h: B( h& `3 e. b# x4 R2 a# L
  7. .code
    ' j8 K+ g3 D5 C
  8. .486
    9 J7 T9 ]2 [3 _0 x$ @7 g7 T+ ?( s
  9. .startup
    ) A1 {! d' V  [  z! _
  10. $ C/ Z7 Y, J, M4 s, e# _2 h
  11.                 mov     dx, offset msg_author
    3 C9 E) j8 _7 U/ W2 B3 \
  12.                 mov     ah, 09h$ n" a* H  e- E: |+ O/ T' {# O/ a3 b+ X
  13.                 int     21h
    . l$ n1 B! Q7 ?+ o- e: L

  14. % {$ J0 i3 o2 F: G2 u$ N) O
  15.                 mov     dx, offset msg_fail
    " K" [. m7 f$ m
  16.                 call    A20_DISABLE3 A0 q. B: }9 c" |1 R- M
  17.                 jz      exit1
    6 P% u+ @- |, x7 z5 _
  18.                 mov     dx, offset msg_ok 4 b2 q9 \1 Z+ c) G: s' n7 Q2 k

  19. 9 n% T" o, f: _! U- j3 v
  20. exit1:          mov     ah, 09h 1 ^" p7 c! L2 n3 V3 O3 j9 E3 K
  21.                 int     21h . U; V6 [/ l( s; m, [
  22.                 mov     ax, 4C00h
    ! M" u) n, S  Q3 r" T/ ^/ g8 u! Q
  23.                 int     21h + D" v- g7 `8 W  s! A4 V
  24.                
    $ h' i! p8 Z7 i/ ~( K
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,) w+ X% [& ]! @- W6 u
  26.                         "2008-07-01",13, 10, "$"
    $ v# J( L; Z: f# s3 b/ U5 ?* |
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    & j! H0 x' Q2 C9 `9 ^' |/ a
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    3 M  O! [3 ?- g5 s" d. J- ]

  29. 0 u; q' }0 O7 _' w; g6 L# [" k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------6 d$ s3 ]: Q6 ]# a" H
  31. A20_DISABLE: 6 C! P& T. i. v( n5 R/ i
  32.                 call    A20Write ( x) A7 n! S" l9 {  @
  33.                 jz      exit_disable
    / {1 x1 z. ~% U$ j

  34. 7 q  a9 Y5 q+ S# O) F! Z; y5 y
  35.                 cli                             ; Only need for reading value from KBC
      J' G3 ]& S4 S& D
  36.                 mov     al, 0D0h
    / X$ v( ^$ I8 `7 P& \
  37.                 out     64h, al + ]. \1 }0 R0 R2 g9 ^3 O
  38.                 call    A20Read
    ' H, B1 a) c% A( d
  39.                 jz      Disable_int
    3 a) l3 d5 ~1 c& {4 j! b3 \& m
  40. 5 w" l' I  Y+ t( p* P. j) [9 t, B( ]1 O
  41.                 in      al, 60h                 ; Get current status
    # c: y. y) L8 l' x
  42.                 mov     ah, al 8 o. @4 Y/ J  c% [
  43.                 call    A20Write
    ) k6 A+ N, R6 J$ f- |. {
  44. Disable_int:    sti
    " E/ E7 o6 @0 ], P5 @" f: }' H7 p
  45.                 jz      exit_disable
    . z( M6 _; C. @0 T" z; Q
  46. 5 Q' b# Y: s9 v3 p, j
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ! _6 v" n1 g$ R' s, M- [* \& I
  48.                 out     64h, al                 ; Out Put Port next , G$ r" t, b2 J9 b& h: u
  49.                 call    A20Write - T# G" @6 d% ?' V  l9 g' I- ?
  50.                 jz      exit_disable* A' Z6 J% P; Z" H( S

  51. $ z( h0 [' I5 l1 F( L
  52.                 mov     al, ah
    " t" c% O- Q- j/ ?% T" q/ x
  53.                 and     al, not 2               ; Disable line A20
    + D; a  P/ @' }% b
  54.                 out     60h, al
    2 S, Q/ B4 h) G* b
  55.                 call    A20Write
    * U6 h" }, K& Q1 J5 L3 i
  56.                 jz      exit_disable
    4 q7 d4 p4 \/ B; ^
  57. $ Y) F- g: r' R5 \# y+ q( V4 {3 j
  58.                 mov     al, 0FFh                ; NOP   \6 V1 `( f& \, G
  59.                 out     64h, al
    - u/ m* y$ A6 j! u
  60.                 call    A20Write
    8 J/ ^' J  T/ v2 |

  61. 8 Z5 `4 y8 _: M% |2 j0 d# a' @" g; x
  62. exit_disable:          ret
    3 v& [7 e; j2 w6 `- d. Y* }
  63. 8 {# u& j: g: v7 d, N8 T
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
      _; }0 K! d6 _; ^' _, R
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 8 x! t, X7 @, ?& q" o+ ^
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ! Z7 Z$ l) p5 N# g
  67.                 jz      clear
    # P# F& R' |3 x7 D! j: x
  68.                 dec     cx & n$ V9 G) B& N3 J7 H
  69.                 jz      exit_write
    ( \4 b) _. ?' k$ w) v& }" t
  70.                 jmp     short get_wirte # i' a% j2 D' p2 f: y, g0 i
  71. clear:          inc     al                      ; Clear ZR : z/ c9 [3 c" j. U: k) I5 z0 M
  72. exit_write:     ret
    * _( Q7 G# |/ L9 r$ u* K
  73. ! h1 X4 C- D7 P% |3 P/ L* Y

  74. - c. X6 G; z# Z9 }* P" }+ i+ K# R
  75. A20Read:        xor     cx, cx 1 u0 B& {3 v" k9 f$ |8 k; t6 g8 i
  76. get_read:       in      al, 64h 9 I) }1 n( S6 d- ^" u- D
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    6 U2 k2 Y! y6 d6 W, J2 n6 p
  78.                 jnz     exit4                   ; ...
    & b: g- Y" t5 L6 x  `0 U
  79.                 dec     cx " U* X- `- D/ f1 b) s
  80.                 jnz     get_read
    2 \  C6 X( x: q& A0 k
  81. exit4:          ret     
    . g: Y$ V% J& P' s" ]
  82.                
    & D" z  V% `" o8 y, R7 r2 J+ z
  83. end
复制代码
  1. ;A20STATE.ASM
    5 S3 \. `6 b. y% j
  2. ; , l% h9 d& a$ L% }% U1 r5 b$ I- m
  3. ; Returns the status of the line A20 through the KBC
    & u  s# H, |9 ~8 t0 ?
  4. ;       programming by bini for debug. 2008-07-01' J1 r" b' L4 z
  5. ; & m2 W9 I  B/ B/ h
  6. .model tiny
    5 i% \# |/ w* x8 T4 z
  7. .code5 ~# \& L; y6 T  {1 }
  8. .486& @7 I# m: T3 n  I2 g2 p; ~
  9. .startup
    & Y9 b8 p. j3 u0 k. s& H
  10.                 mov     dx, offset msg_fail   y: }2 E9 u" d  b& J4 h
  11.                 call    _GET_A20_STATE_' m! d) y" L$ c" B6 K0 I. b
  12.                 jz      exit1                           ;  was a problem/ n& E. T% _) I9 @
  13.                 push    ax                              ; Save state, AH ) ^7 e! N0 L$ [3 \  c+ \* }9 v" \5 N
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem - m$ F/ r: U* B9 u
  15.                 mov     ah, 09h 6 I5 @& j2 V4 q4 B$ T' j) Y
  16.                 int     21h                             ; Print message 9 x0 m  y# j# R7 Z) t; g. A
  17.                 pop     ax                              ; retreve state
    1 D; S2 X( d9 Z. c, t# Q

  18. 6 ^. C1 x$ w5 `4 d6 A
  19.                 mov     dx, offset msg_dis
    . u3 r( }" n( J$ o" Y$ @
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state * z! u9 H  ~, L2 R1 G9 s9 X! V
  21.                 jz      exit1 " ^6 s- o  Z+ e, T0 G
  22.                 mov     dx, offset msg_en
    1 B# k2 {& f, _2 j3 I% \( \
  23. ! x; s2 N4 b1 V$ i2 H: m. x
  24. exit1:          mov     ah, 09h
    & M; p! K8 e- t5 h
  25.                 ; DX already contains address of string
    6 n$ e, ?7 w! X1 f$ `) T
  26.                 int     21h . }0 ]7 G4 K6 X, l9 \

  27. , g7 O& S; }7 u. w
  28.                 mov     ax, 4C00h
    $ r7 N) R8 h2 f+ l
  29.                 int     21h + y1 n+ C. O2 x7 p

  30. ! ]: L( ~8 i1 `% I$ Y
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    & N5 }4 V3 y4 b( w
  32. msg_fail       db      "FAIL", 13, 10, "$"   r1 K9 r. v1 I  _
  33. msg_en         db      "ENABLED", 13, 10, "$" " h0 l8 P8 v8 p2 y: Z9 c  G) [
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    ! [# B9 W7 f3 f3 T& K2 C
  35. " t0 Q0 A( {5 |  B' S6 U% V

  36. 6 k* G9 e- [! d" R2 _
  37. _GET_A20_STATE_: 0 [/ w1 o+ w" A  O8 l
  38.                 call    A20Write                ; Wait till the input register is empty 1 A9 W1 v9 s: i# e' X
  39.                 jz      exit2+1                 ; Bypas the reset int's 5 F; H+ z8 r. ?- k
  40.                 cli                             ; Disable ints so we'll get our value
    5 J4 d% f: p; k

  41. - C0 |6 ~4 Z$ z- ~& x' H
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register . J8 F# |  W: ~, a# v
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    ; n& w4 @2 b% a5 V$ r: }+ q
  44.                 call    A20Read                 ; Wait till the 8042 output register & M0 d7 i! S+ ?0 G" H& g
  45.                 jz      exit2                   ; has something in it's buffer
    # h6 E/ Y- ~; L, B/ i( J: _
  46. 1 R/ ^; ]- z0 a" X
  47.                 in      al, 60h                 ; Get it 7 z% a# y$ o. U; [$ A3 r
  48.                 mov     ah, al + g% a: M" m7 u- i$ _
  49.                 call    A20Write                ; Make sure the input register is empty / l( K- b' m' t; z
  50.                 jz      exit2
      ^. j. X! e! e3 n4 |
  51. # U/ A) S* Y* L, l
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    * f/ m* c3 x: X7 i
  53.                 out     64h, al
    . R" [; Y% q  c& J* F7 r
  54.                 call    A20Write 6 Z3 f( w: m$ V9 d- [4 M
  55. % k( a& G0 g3 r6 T# P1 \
  56. exit2:          sti 3 h7 M8 L7 D5 ?  H% w  L' k
  57.                 ret  Q+ k- [  O* X$ t* `

  58. + U7 d- ^. ^, C7 H5 w( p' A
  59. 7 v: X4 J" g7 \( d' h. A, I. @
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
      h4 T( X7 f6 u2 k( Z
  61. get1:           in      al, 64h                 ; Get KBC read status
    " V: f) m7 C- ^& |: ?/ E# @8 V
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear , {* C4 e, a; F& O# }
  63.                 jz      clear 7 C! x8 m- Y- q7 n
  64.                 dec     cx
    3 w) I4 U1 J1 l5 V: @9 y, r
  65.                 jz      exit3 + V) P7 k- K: Q, n) \; o( L: [) y
  66.                 jmp     SHORT get1
    5 f6 v0 \6 W' r1 n% N" q& d
  67. clear:          inc     al                      ; Clear ZR
    ! F- o, c6 _" d' E
  68. exit3:          ret
    : y. T% F; x" `  c, V. t/ C
  69. 6 t$ K$ z# }# T: E& T7 c" f

  70. % i; A1 e' \5 h
  71. A20Read:        xor     cx, cx 3 E' ~9 {7 f* c- {
  72. get2:           in      al, 64h 1 I' v9 D' Y, C* C, I. ?% s
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
      S" g- c+ Q7 V: r, G/ q
  74.                 jnz     exit4                   ; something for me 2 y  l; ~$ z3 s- H& o1 c. r+ X
  75.                 dec     cx
    " {( ]3 r; t& ]( l: W4 `$ t+ G' P- v
  76.                 jnz     get28 S! Z1 X4 n2 P; k9 L; E
  77. exit4:          ret     
    ! I- C) d3 |$ d6 n% p' d4 B
  78.                 1 a) A  i7 L' w* `, n' I8 X, o
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
2 B* z/ T  B1 l' {2 _{        while(inp(0x64) & 2);        outp(0x64,0xd1);! e$ S2 _8 x/ ^( }: M( m
        while(inp(0x64) & 2);        outp(0x60,0xdf);
' ]7 @7 |" J2 ?0 f% R' {) j        while(inp(0x64) & 2);        outp(0x64,0xff);, r+ G  }8 D4 ~: \
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-2 13:37 , Processed in 0.046409 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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