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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM ; r. T+ i( n$ R$ K' m
  2. ;
    8 I' ]0 v) s* P: A3 B# x. q! o8 u
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-011 L6 ^1 H* l  b/ |
  4. ;       ml A20ON.asm   ?6 t& N' p' I, P5 g
  5. ; , w5 S0 r$ K$ Z& }' L4 ]
  6. .model tiny
    , p+ R9 K4 }$ {1 c
  7. .code
    / g) G* r' g6 |4 I/ r" z, P
  8. .486( b' [& T2 l1 ]) c, t' b
  9. .startup
    + T& q& E# u0 [$ |: L% M+ z
  10. & V- o  e3 H! v' z. Y
  11.                 mov     dx, offset msg_author0 p% E# O$ Y; A' i3 [# c4 ?: t+ H
  12.                 mov     ah, 09h
    ( x. c/ ?$ t% \4 J  m$ @4 F+ b% |- ?; r
  13.                 int     21h/ W. }0 N$ H& T+ U+ r

  14. / }+ ]9 a4 f" U' a3 P
  15.                 mov     dx, offset msg_fail 1 O/ v5 O3 h" u8 X
  16.                 call    A20_ENABLE$ Y$ {: Q' N7 y/ m3 |7 ]7 L" ~
  17.                 jz      exit1
    ! ?+ O& a( i, N& B5 [8 R8 @" r' U: V/ n
  18.                 mov     dx, offset msg_ok ! B. y7 Q7 k2 b) y/ c2 B, e
  19. 5 Q6 c0 R. l0 V1 s+ @9 H% R+ ~2 V
  20. exit1:          mov     ah, 09h
    1 g& K9 s2 t) j% i2 v- V, I
  21.                 int     21h
    4 G) V" U+ W& u6 J  m
  22.                 mov     ax, 4C00h 5 N% q. b9 c/ [0 C% [) L& F
  23.                 int     21h 3 ?8 t; i3 X' N8 ]- _
  24.                 1 j3 r3 ]9 }) ~
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    " t' L# p! D4 o- v) t
  26.                         "2008-07-01",13, 10, "$" 7 h8 y. v7 k8 E* ^9 C. d. j
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" % l% D# Y: f- G& p" \) M5 Q8 E
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" / q/ E: t- u4 E# b
  29. : J' c1 ~: C  ?- k. }
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    , h8 J5 a) P+ h2 A) K- H
  31. A20_ENABLE: : U; a! ]8 [% i  W
  32.                 call    A20Write
    $ {; Z+ d; o: _6 M
  33.                 jz      exit_enable+ }- ~6 f/ v/ T8 q

  34. 7 L( u8 [* m1 T" s
  35.                 cli                             ; Only need for reading value from KBC
    4 `. ]7 M. x! ~2 W9 o: \. L0 ]
  36.                 mov     al, 0D0h
    . k* ?7 Y7 B; J; r% @( W' P1 P
  37.                 out     64h, al
    ; L& a0 s6 J4 d8 u: Y$ r3 \5 u* {" }
  38.                 call    A20Read   t  V) L' Z: w  ]5 @
  39.                 jz      enable_int
    + W, e. x, D* r$ b8 Y3 ?( w+ G, J  a
  40. * b+ P& B& X( j. e  Q# |9 q7 _
  41.                 in      al, 60h                 ; Get current status
    ( [, y- n" B7 I2 x+ u& ?9 P
  42.                 mov     ah, al
    , a  p; ~: T: K, S
  43.                 call    A20Write ! m' }  a1 z6 Y( d
  44. enable_int:    sti
    ( ^5 r, b( {* L$ \8 z" p( F& _" h
  45.                 jz      exit_enable
    8 g5 }$ n+ {2 E, b1 m- s+ H# J& \
  46. 6 H# @9 C6 i" ?) O4 Q' Z9 m- e
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    : T3 o4 I( F8 g. ?7 n* p
  48.                 out     64h, al                 ; Out Put Port next   E8 j& r0 ]3 N, O  ?! R
  49.                 call    A20Write 8 p) _5 _% y+ u4 E/ C
  50.                 jz      exit_enable
    : n  ~( w) n! }

  51. $ z$ ]$ F1 j+ z" m
  52.                 mov     al, ah
    / ~5 E  O, H. R  o
  53.                 or      al, 2                   ; Enable line A20 & z1 a% r5 O$ f) h9 w
  54.                 out     60h, al 4 H3 `7 X) a4 P* u% P
  55.                 call    A20Write ' x% h; s# K. M8 x. y/ i
  56.                 jz      exit_enable
    ( s8 _* _6 |$ A' A

  57. 3 X5 p+ _; W! M6 M- |% O% y
  58.                 mov     al, 0FFh                ; NOP 1 M* p1 ~' R8 b& \$ [5 m
  59.                 out     64h, al 9 k! M# i( }- U9 O% T
  60.                 call    A20Write + n% n8 r' ^" j4 [5 Q7 b- M

  61. 5 |, R. J$ a* o0 s( U) E
  62. exit_enable:          ret
    3 n+ V; e/ X+ {8 C9 v& V" p0 |
  63. , u+ h* W6 E2 D; b( A
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 }& g* j1 Z' f
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    % z- S8 i% x* Z
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ( r3 {6 h# B+ I
  67.                 jz      clear
    * N% j+ C- Z$ l
  68.                 dec     cx ! }# X% M$ J  Y. Q- U- O! u
  69.                 jz      exit_write + F5 N! `2 j0 k+ B4 M6 v
  70.                 jmp     short get_wirte
    ! G. z5 u, W# `. ^2 O6 [$ D
  71. clear:          inc     al                      ; Clear ZR
    7 _" `7 y3 w1 g5 ]9 f
  72. exit_write:     ret " y) q1 D* }* d: ~$ p

  73. % G, E' S, B9 M$ P  @. h
  74. + C6 b% Z9 Z% @3 `% J; N$ c
  75. A20Read:        xor     cx, cx
    2 u3 }6 D  ?/ `* a
  76. get_read:       in      al, 64h
    3 n  }3 _1 t- d
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    * s" b: O* `2 f
  78.                 jnz     exit4                   ; ...
    6 w: I1 f3 z$ M( ?+ A
  79.                 dec     cx 6 ]4 u( [  b0 j7 T0 d
  80.                 jnz     get_read
    6 y# _- B2 K8 w$ e8 S
  81. exit4:          ret     / K1 l6 U0 y1 L
  82.                
      @! }" \+ B, K8 |
  83. end
复制代码
  1. ;A200FF.ASM / e9 I4 {. c- {, J4 p
  2. ;
    4 f- v% h- i6 {) O) p% y  a
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    % O, n- Q- W  u% c  m& c
  4. ;       ml A20ON.asm
    2 R0 H' _; y* s7 Z! d0 m4 _
  5. ; * v7 E* h* \" L
  6. .model tiny- I8 [) D0 e5 `) G3 C
  7. .code3 p: x; a7 ^1 V( ~' A
  8. .4862 o. }- a! J2 [8 V
  9. .startup7 w- O, `) f3 D, Y# {3 k

  10. 5 A! m% w4 C% O. O' A( b; {
  11.                 mov     dx, offset msg_author# z5 Z1 z. h7 B/ D0 M- {( g
  12.                 mov     ah, 09h0 g' @1 K6 D) O  q' I7 [
  13.                 int     21h
    * u+ j; r, g1 f/ A# l. _

  14. . v/ x5 w3 g6 F& ?  X( L3 h8 o/ @: p
  15.                 mov     dx, offset msg_fail 6 _$ }5 [! ^9 h* C" B+ c0 [5 p8 `2 C
  16.                 call    A20_DISABLE
    * f  R. u# |7 I7 i% v
  17.                 jz      exit1
    & H: D; q) A, e) V. G
  18.                 mov     dx, offset msg_ok
    8 K9 U" z& B, H7 k! t5 a& k8 \

  19. + a" @0 A# m+ H, r) h
  20. exit1:          mov     ah, 09h 1 G' n0 g/ I+ R" |9 P) l
  21.                 int     21h
    3 \9 G) m) Z$ Z2 P: ~4 l
  22.                 mov     ax, 4C00h
    . L: z* }7 }% A1 `' Y+ p0 j
  23.                 int     21h # U. f  X' L/ A/ i' A$ r
  24.                 3 A7 _8 R' k4 Y  v6 z7 ?/ I
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    , Q. v. H/ o' _" D6 s: z) t
  26.                         "2008-07-01",13, 10, "$" 1 Q# e$ f# g  v
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    % O$ z6 \' j; ?/ N0 L3 C0 M  Z; E
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    . s) [5 g5 h% a
  29. , c: I5 Y+ h8 U& D/ ]8 W( q! ~3 B
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    9 R$ d+ |- W# ]
  31. A20_DISABLE:
    1 u8 s. X* k3 T/ W: F- Q- e
  32.                 call    A20Write 9 `% F% B1 `( b
  33.                 jz      exit_disable9 j( [, m" L( x% y0 v
  34. 8 ?# _, w: n# b, N
  35.                 cli                             ; Only need for reading value from KBC 7 k/ J5 r: i+ l
  36.                 mov     al, 0D0h
    5 w. U6 M4 C* |8 W
  37.                 out     64h, al " ]( Q" H3 [- j5 J; C$ ^' S, m
  38.                 call    A20Read 9 [) F6 m- ?+ x/ h2 ~" b2 }
  39.                 jz      Disable_int 5 Q- h+ S4 @$ O8 S3 W5 }
  40. : z1 l) S) O7 u  ~, b8 j" t" ^- o
  41.                 in      al, 60h                 ; Get current status 6 ~. l7 R! ^& \/ q0 P
  42.                 mov     ah, al
    1 s2 {1 k' v: k) [$ O5 @
  43.                 call    A20Write ' ]* ^7 b, G) R
  44. Disable_int:    sti
    7 a: g: v) o1 |# p3 C! W2 G* u
  45.                 jz      exit_disable
    : }8 M1 N& |5 H% H5 \* r. F
  46. 4 ]7 Y* O* T7 _: O
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the . S6 j# l: Y1 g% @
  48.                 out     64h, al                 ; Out Put Port next
    ' m3 p! @1 u9 k. \/ c8 z; L, J
  49.                 call    A20Write & ^: D! o) [2 F# x
  50.                 jz      exit_disable: I) {2 {# j1 j  [

  51. , z. r" M6 r1 z' }
  52.                 mov     al, ah / h0 E) y) k; O. h, N9 G; d
  53.                 and     al, not 2               ; Disable line A20 8 j  a+ Y  k, L: A* O3 b
  54.                 out     60h, al 0 t9 O2 z: ~3 K; }3 h, @
  55.                 call    A20Write   W: O% V- B$ y
  56.                 jz      exit_disable
    8 U2 X6 O% G: V+ f/ q! E$ y
  57. ' m5 {9 ~9 J. O4 }, v9 ~1 _
  58.                 mov     al, 0FFh                ; NOP # w5 k& D  u. G  q, Y9 N
  59.                 out     64h, al 1 p9 C& [! z( F/ c
  60.                 call    A20Write + q# G2 s/ x# ^3 j
  61. , V3 V2 P- z, `/ g5 L7 X
  62. exit_disable:          ret ; @# p: k; A# U8 b4 U7 D

  63. . Q  L% I9 P# J# Z, {6 B' ^+ p
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 3 i: F# v6 z* b4 p
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    & d: Q9 F6 m- p& M7 n: U
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ; l% D# n8 b4 p" X3 r8 g- i( [( r
  67.                 jz      clear * {* O# l/ [/ e; h. g
  68.                 dec     cx 8 m, }/ Q$ W5 c$ x7 V
  69.                 jz      exit_write * G4 Y1 H6 J4 c
  70.                 jmp     short get_wirte ! e3 r9 f+ Z/ s- E( ]
  71. clear:          inc     al                      ; Clear ZR
    ; x( ?( d- G# [8 ~
  72. exit_write:     ret
    * l/ A) X- e, M. K
  73. $ y6 ?7 b. M' G7 n& Z& Q

  74. : I: e  |. i# ]0 m% Y7 s% ~3 f
  75. A20Read:        xor     cx, cx
    ; ]$ m* O3 c! W" X$ n0 o
  76. get_read:       in      al, 64h 7 L& k7 J! P1 V0 B; x# O# Z
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( T0 {0 n" r, B; M2 E
  78.                 jnz     exit4                   ; ...
    . w; q/ ?" C) j6 c( A
  79.                 dec     cx
    - F( W9 ?9 y# ~6 h0 C9 o+ {
  80.                 jnz     get_read# C' a- T% ^9 d+ I9 v
  81. exit4:          ret     
    & }7 }% h9 r! S! `
  82.                 / J% w$ |3 P& ^& [2 j8 L
  83. end
复制代码
  1. ;A20STATE.ASM
    " D. |3 k& k. @5 D
  2. ; % j7 L: m- ]6 m! F
  3. ; Returns the status of the line A20 through the KBC # u* M+ G, Y7 n4 t$ h# t
  4. ;       programming by bini for debug. 2008-07-01
    # S" B! M! {/ b! n- I0 y/ E
  5. ; 4 k+ T) c8 T( C1 ~9 f  I5 c& \
  6. .model tiny+ x8 _( j( l) N! I* {4 s
  7. .code. d& S3 F2 }1 s4 Z
  8. .486# N; Z  }# F9 L
  9. .startup
    # o* N9 t8 k9 x6 R, S8 s- o
  10.                 mov     dx, offset msg_fail & {6 _2 o( G% X3 Q6 \3 s3 M' y
  11.                 call    _GET_A20_STATE_% J5 Y& a% D7 h6 v/ J3 [
  12.                 jz      exit1                           ;  was a problem; N" C/ l" F# T' Q2 X
  13.                 push    ax                              ; Save state, AH 9 f; B% F7 v0 w8 U( s( T# a/ t/ p
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem * R. M% n) s2 ]! S7 t% t
  15.                 mov     ah, 09h , x; l7 X! o; l! L- n
  16.                 int     21h                             ; Print message # W4 n6 Q  C; G" N
  17.                 pop     ax                              ; retreve state " [+ }0 B. e, H
  18. # o, x& X, r3 \, e0 x0 J2 E! s
  19.                 mov     dx, offset msg_dis
    8 c. u* k: c/ a8 L  O; B
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    6 Z% w% n0 a1 j$ p
  21.                 jz      exit1   [$ `# a, }  u
  22.                 mov     dx, offset msg_en
    . _( m  o! ~3 O; ?
  23.   D! S$ s6 A4 m6 K7 a- M; C
  24. exit1:          mov     ah, 09h
    9 E5 u% c% Q7 E% H3 p, k
  25.                 ; DX already contains address of string
    , _6 r# L) _$ d( r. Z* y
  26.                 int     21h $ ], n$ I. O, {+ s" H

  27. 8 j, s. k* t% O& u
  28.                 mov     ax, 4C00h 2 E, b# x* B! {6 F9 G: V
  29.                 int     21h + c6 ?) P) f+ B( F! K6 D' l

  30. * v, j$ O, @! o" Z1 U8 z
  31. msg_ok         db      "OK", 13, 10, "A20 $"   Z- x! G$ {1 P
  32. msg_fail       db      "FAIL", 13, 10, "$"
    , X( c: T* ^7 x* M$ N7 @
  33. msg_en         db      "ENABLED", 13, 10, "$"
    7 ~7 Z( J$ H" u; U3 f0 D$ {0 G
  34. msg_dis        db      "DISABLED", 13, 10, "$", T. {: ~" K+ m/ i  K

  35. ' B7 W' e* T9 Q6 S" E- P

  36. 0 z: E7 k* w* o+ @
  37. _GET_A20_STATE_:
    . o; ?& g! F9 w  P8 D. e( ~
  38.                 call    A20Write                ; Wait till the input register is empty
    ) m# L- R7 y" Q# P% u
  39.                 jz      exit2+1                 ; Bypas the reset int's ' b4 J8 V5 R, X6 a9 p
  40.                 cli                             ; Disable ints so we'll get our value
    9 D# h; U/ E3 ^# ]/ q
  41. 6 G1 c3 J; p, v
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register " v# q- S$ |7 r+ }1 Y! Z2 c5 _8 p
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    ( d& e+ F& f* c0 @- @0 y
  44.                 call    A20Read                 ; Wait till the 8042 output register
    / C. d. N, N+ b- g: u6 B: |% ~
  45.                 jz      exit2                   ; has something in it's buffer
    ) |7 R' F$ w" ^. B
  46. 0 h- b% u0 E' h' L" G
  47.                 in      al, 60h                 ; Get it 5 @3 x2 g0 W- T& s  w5 H! A
  48.                 mov     ah, al & a# q: m6 _- X% C% n/ P
  49.                 call    A20Write                ; Make sure the input register is empty
    3 j5 l4 G$ f, @; z. \; t9 y
  50.                 jz      exit2 . R7 I# \7 P# Z; u# v
  51. * i8 v2 @, b' h7 E" T. U
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 6 d9 n2 z( C3 G. \. |. o7 B
  53.                 out     64h, al * c' V2 ~0 H5 q* D" |; d* L
  54.                 call    A20Write
    ( O% V- l9 v1 N+ z* `

  55. * u: ]. I7 s5 _3 b! E# y0 n. y# q
  56. exit2:          sti 5 u: H- o7 S5 S2 I3 E
  57.                 ret
    ' c* E% U' c! c: n5 k' ~2 A$ w

  58. 1 H, C& s- E- {7 E
  59. 6 `( Q7 T2 j) }2 G$ O8 X
  60. A20Write:       xor     cx, cx                  ; Reasonable wait ! `' i! q3 `: h$ @! p1 d- _* r
  61. get1:           in      al, 64h                 ; Get KBC read status ' y3 r6 R' u( U, b5 T3 y, O
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    0 F' Z, @' X5 }% w' K' H3 A
  63.                 jz      clear : L# F& n! g6 P$ v6 m+ ^% q% P; G
  64.                 dec     cx 6 y" V) a4 @. C
  65.                 jz      exit3 " v2 ]9 m! c5 a8 a/ B- f
  66.                 jmp     SHORT get1 - ]/ |* m* i0 R
  67. clear:          inc     al                      ; Clear ZR
    7 `8 ?8 e* i  ~
  68. exit3:          ret
    $ J# h) V& T4 x4 [" B9 ^4 E4 ]
  69. ) _7 e0 y8 }% E
  70. " P3 W# Q$ d# G
  71. A20Read:        xor     cx, cx 1 H9 v& E; n" A! P! Y) [( i
  72. get2:           in      al, 64h 8 m+ o! s7 `6 J" r- O) R
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    4 E9 m- F/ ~+ G' ^9 T3 `+ j
  74.                 jnz     exit4                   ; something for me . t" {! g. \! l0 t& c( @
  75.                 dec     cx
    & F6 W% e6 ^0 R& n$ `
  76.                 jnz     get2  D: f! M7 p$ o  d5 P
  77. exit4:          ret     # x% h4 V6 v5 l( ]* _
  78.                
    1 H$ W6 {4 {7 N2 V
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
& j- w1 `! M0 k{        while(inp(0x64) & 2);        outp(0x64,0xd1);$ G9 Q$ y7 x& ]& }2 ]3 S7 t. T9 g% ]* p
        while(inp(0x64) & 2);        outp(0x60,0xdf);
5 t6 T! K! n& d        while(inp(0x64) & 2);        outp(0x64,0xff);! U# L' H6 z! D" t, Q  Q; W
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-19 00:23 , Processed in 0.063742 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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