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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    : e1 y5 b' H) ]8 O; a* o6 c
  2. ;
    2 |# `" {3 x3 v) n* S" ?$ i
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-010 j& A+ H" I4 x0 s  g, ]
  4. ;       ml A20ON.asm
    6 M, l/ G0 a& A& H
  5. ; & Z0 u+ E7 h/ d5 @0 v$ L
  6. .model tiny! t9 j/ D) b7 _4 U( h7 q9 |
  7. .code8 W: E& [/ v# C$ ?- Z; a* j; N
  8. .486) @3 L: }5 b" r: A
  9. .startup0 c$ U2 L7 o6 W' M# h! k

  10. * b, o+ G) ~8 f8 Q6 @, a
  11.                 mov     dx, offset msg_author
    7 W& S' Q4 t; a: \& `. c
  12.                 mov     ah, 09h; j8 R" ?/ Q/ t2 x' N9 V
  13.                 int     21h
    6 Y  c# D, v1 b& l' p  Q
  14. + ?: h# F# v1 |& c" H
  15.                 mov     dx, offset msg_fail 0 N. O9 z! k) }' a* r
  16.                 call    A20_ENABLE
    5 w- c2 I  B! h* k
  17.                 jz      exit1  q1 ?" q2 |9 U, }4 j; _
  18.                 mov     dx, offset msg_ok
    - q6 y/ k8 K3 k  \4 n
  19. 2 c$ I5 Z8 j# V* S9 s' R7 \3 [
  20. exit1:          mov     ah, 09h
    5 @- P: M# i& g- K! A
  21.                 int     21h
    . k1 V% ^3 E  w6 E% T% Z; ~
  22.                 mov     ax, 4C00h $ w5 a+ B8 G6 }8 @( i' v* z5 n' }4 o
  23.                 int     21h 9 ]" P2 n" H5 t8 [
  24.                 ; ^4 T  J7 c" l
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
      q9 m+ N0 ^' [; n: \
  26.                         "2008-07-01",13, 10, "$"
    6 ^8 L& Q  I6 P' Q
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    * z3 ^7 |7 V! n9 a  F# l0 ?
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" & U  F4 l. P3 b7 T: e3 V, V, k

  29. 5 o" j  b4 E% z+ Q
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    7 t6 n' ^! b  H1 G- l" j) V5 Q
  31. A20_ENABLE:
    : Q- _* h+ C$ g8 `: u
  32.                 call    A20Write
    4 S7 s' j! H) f# r" ~
  33.                 jz      exit_enable
    / i: V7 v2 U7 A
  34. - E- q& g$ q6 n% z( {; L. O
  35.                 cli                             ; Only need for reading value from KBC
    6 B/ }6 z7 y! p; Y" Y) W
  36.                 mov     al, 0D0h
    # A. a- n0 V/ Q
  37.                 out     64h, al
    * v' u9 Z3 X6 U; V& D0 p2 C: F
  38.                 call    A20Read + J3 c$ Y( c+ i4 i
  39.                 jz      enable_int - @: s' t. q& a$ n& Z9 e

  40. 9 I- m% L6 S0 Z, V! p' R8 k
  41.                 in      al, 60h                 ; Get current status
    # u$ C4 l# b: H. \2 J. u4 v
  42.                 mov     ah, al
    : z  ^, r- j; F4 d$ T, w
  43.                 call    A20Write
    1 C4 S) I1 z8 C9 o8 v1 {6 x# _% ~
  44. enable_int:    sti   u# L) X' ?  j% X: j: T
  45.                 jz      exit_enable
    3 p! J0 P/ U4 j1 \: D( S  S; a) c
  46. 6 k0 O5 k! y2 T7 R! P
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 9 B5 c5 f+ G6 t* Q; S0 [1 a) V) K
  48.                 out     64h, al                 ; Out Put Port next : I$ G" N1 X' r9 L: k( P& Z% ^
  49.                 call    A20Write
    " j3 m% V' L7 u6 t9 z
  50.                 jz      exit_enable; I9 ~* P$ B+ f0 X: n! _7 r
  51. " X3 B. }: Z% i  z5 T$ p; I
  52.                 mov     al, ah : i: ~( ^& e  g, f1 l
  53.                 or      al, 2                   ; Enable line A20
    9 P0 h8 O/ s% u" F' t
  54.                 out     60h, al
      o& k* F) p' G1 x# r7 s; s' A1 U0 L
  55.                 call    A20Write , u3 u5 T& k7 @% u, |% E* B, X7 p
  56.                 jz      exit_enable, S: v! N3 c5 ?" u6 P& X6 p8 U0 Q

  57. 7 V$ ~' s  `' A& U6 [0 m" S9 ?
  58.                 mov     al, 0FFh                ; NOP
    7 N, S2 l6 n8 z; H3 I' n* p
  59.                 out     64h, al
    ; E6 q" p6 j7 M* _
  60.                 call    A20Write % i( Q0 v4 T+ }& w

  61. * L3 P  ?8 |2 X- }: o
  62. exit_enable:          ret
    & o, j3 P# O% P9 _0 u
  63. 7 D4 g8 l6 a  C. S5 n. {, ^% d) i
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 q8 B, i" x3 E' X0 n
  65. get_wirte:      in      al, 64h                 ; Get KBC read status , B! J/ p! B9 M' L, e( I
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear ! X7 M/ S. u/ n& g' `5 c
  67.                 jz      clear & B+ f6 M4 A8 h8 A( G; ^
  68.                 dec     cx
    8 g6 o) \1 B$ L# l
  69.                 jz      exit_write
    . X$ @2 D: P. r( ?, p% H: M5 j& V
  70.                 jmp     short get_wirte
    1 T8 p2 s, l7 g9 i7 I: X9 S
  71. clear:          inc     al                      ; Clear ZR + J" i# U3 b- _7 z1 t  h
  72. exit_write:     ret $ R: N/ w! r# ]; e  \8 m

  73. % [2 H* l/ J% P3 G; D: s% ^! T

  74. : e' U1 w  a7 {
  75. A20Read:        xor     cx, cx 4 K( m4 X1 c( w. V& R( Z8 K7 W
  76. get_read:       in      al, 64h
    2 E% w) ]5 P9 U, @2 Q
  77.                 test    al, 01                  ; If the 'output buffer' is full, has % Q0 p" M+ y" x7 j( i( S
  78.                 jnz     exit4                   ; ...
    " G5 n, n7 N; F# a
  79.                 dec     cx   q$ ^, c4 T! @; M
  80.                 jnz     get_read4 z* `& q; A! B; V3 B6 V
  81. exit4:          ret     
    % |# ^2 x% b1 F
  82.                 % \6 d! y5 q$ @/ ?
  83. end
复制代码
  1. ;A200FF.ASM
    ) ~$ ]  g/ |  h
  2. ; 3 e4 i1 \, J& n3 ^" }- q
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01  |; T" T) u% z
  4. ;       ml A20ON.asm 0 T  R% g# L) @8 K' M1 l3 v* y& H
  5. ;
    : l4 Z1 c9 J( \4 k
  6. .model tiny" _# Y  S& B4 ]/ [' ~8 K/ B
  7. .code: y9 c% `: [  R( J9 j
  8. .4861 t, R9 g( q& k) [
  9. .startup
    $ o. s5 [9 d# `5 `1 h
  10. 6 k! r5 Q- ?9 P
  11.                 mov     dx, offset msg_author
    7 A+ l7 a" E& n7 D7 G4 T
  12.                 mov     ah, 09h
    - s2 W. q% E6 _: }3 M- H3 g6 B1 R% H/ ^
  13.                 int     21h; [- x$ w: i. \8 _

  14. ( ?9 ?, x% ?. Y0 F. B, |
  15.                 mov     dx, offset msg_fail
    ; o0 I! u) M, U
  16.                 call    A20_DISABLE
    2 T4 k6 b. q9 |  Q( s' L- e
  17.                 jz      exit1
    " i$ `9 v4 R4 e9 J! C$ B) W+ z$ c
  18.                 mov     dx, offset msg_ok
    6 o$ U9 k% n, ]- b

  19. ( x  S. a- B2 ~* i
  20. exit1:          mov     ah, 09h
    1 {4 ^& r* E( K! q& W2 T
  21.                 int     21h : Y  N7 K4 [  r# q) X( J7 i: h: S
  22.                 mov     ax, 4C00h " i& B2 d* b+ \' e; t$ b
  23.                 int     21h - ?+ Z/ T6 U8 s
  24.                 , f2 W2 T: @' a' M5 j! o5 {
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    * \! [) t- }& e. V% t
  26.                         "2008-07-01",13, 10, "$"
    " g2 z6 s4 S* n; Q+ q6 S0 a4 i
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    + a- @* A8 Q  m- s' @2 U8 e) `
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" 2 Y- I4 p, F: E8 ^- Y

  29. , k9 Y" F# H3 g
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------5 T1 S2 r* u, F
  31. A20_DISABLE: , o3 b/ o6 K3 D6 m
  32.                 call    A20Write
    0 K# o: {9 m5 U/ ?
  33.                 jz      exit_disable" W3 K  p; P5 M/ u6 u  W4 @, M& l

  34. & F/ u' r# |6 U
  35.                 cli                             ; Only need for reading value from KBC 8 a3 F" d$ Y+ Y) R; Z* c' Q
  36.                 mov     al, 0D0h
    % E6 r# r6 v# U& a8 K
  37.                 out     64h, al 3 k8 Y6 `" T  d
  38.                 call    A20Read
    6 m. E& O, J2 ?7 Y" E
  39.                 jz      Disable_int
    ! h( v7 x' f' P8 u& v+ A! G0 e

  40. / ~/ {9 Z! p, E* Y& E  g1 y
  41.                 in      al, 60h                 ; Get current status 9 C- f$ h  ?1 P7 r& C
  42.                 mov     ah, al ; p% b* o# H( [: P% R
  43.                 call    A20Write + A8 M- x) J. R/ v$ X5 K# l0 x
  44. Disable_int:    sti ! g2 U6 Y2 ]8 O
  45.                 jz      exit_disable8 U; W+ ^; p1 N3 M& K8 @- n% J
  46. : t7 v! q5 p4 F& D
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the : v; W  [, o$ i$ u( _
  48.                 out     64h, al                 ; Out Put Port next
    8 l! o# \" |* \) ?
  49.                 call    A20Write   A' t) ?  x1 O* ]- U7 Q- B0 a( [
  50.                 jz      exit_disable5 A3 z3 R) \4 e8 l: t

  51. . S- F2 _; i9 b0 i/ n5 C
  52.                 mov     al, ah
    / P  G& p: q" S
  53.                 and     al, not 2               ; Disable line A20
    " n# ~, n$ a. ^1 j) A4 q
  54.                 out     60h, al 1 w) {0 I- j7 x" ^, G
  55.                 call    A20Write ( b; ^  ~$ z" p
  56.                 jz      exit_disable+ X, a  p, k$ h

  57. 0 z$ L8 p; l) @7 w1 y
  58.                 mov     al, 0FFh                ; NOP
    & A7 h! s: H" k* d. B
  59.                 out     64h, al " d" t. u& g. c* M# K4 H$ o; e
  60.                 call    A20Write
    & A1 t2 a/ \3 i% l4 o

  61. & ]$ |; O  D2 N6 B: I  l) l
  62. exit_disable:          ret
    . W+ k2 r( q# q
  63. " d, |: K/ @/ W% U0 ~6 g) T
  64. A20Write:       xor     cx, cx                  ; Reasonable wait ! u6 |' E5 F" F. I/ Y; N
  65. get_wirte:      in      al, 64h                 ; Get KBC read status . @0 v' F2 c% \3 j" G- q; l
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    0 k# p0 I. [  M& {8 h* O
  67.                 jz      clear
    5 g/ k/ V# g1 f& f% r" c% f
  68.                 dec     cx
    8 q7 D! ^5 \/ g9 Y4 f+ h8 j0 h' {
  69.                 jz      exit_write
    5 q3 I0 c8 B0 V! _- p
  70.                 jmp     short get_wirte
    7 G! s7 [1 k1 s6 Q; F) b! ~) D5 F
  71. clear:          inc     al                      ; Clear ZR 5 P  d0 [2 i* ]( i
  72. exit_write:     ret ! A) _. ?1 M6 d! C9 o; i; t" i

  73. ) P# Y2 D, v2 n0 n' L6 k# G" [

  74. 8 u5 t2 K7 D; m( O5 C6 C
  75. A20Read:        xor     cx, cx
    3 ^4 \! b- a$ Z9 E  x
  76. get_read:       in      al, 64h ( ~4 E7 F2 C* w- z" c! }0 ]; a: J- u
  77.                 test    al, 01                  ; If the 'output buffer' is full, has $ z. M! t3 B" W1 k  _8 z) ~" A: J- m
  78.                 jnz     exit4                   ; ...
    ( M# N" _& r2 N! Z  P1 _- ]7 R
  79.                 dec     cx 0 i7 E  j2 S+ H: T' h
  80.                 jnz     get_read6 E, d, y$ |9 \3 h# }( J5 O
  81. exit4:          ret     
    ! t: N0 u* l! T' U
  82.                 3 `/ w/ x  L) V
  83. end
复制代码
  1. ;A20STATE.ASM 9 a8 F& G$ h" o6 D/ j" b/ l+ b5 m/ V0 @* |
  2. ;
    : y; z8 f; |# d7 d7 c
  3. ; Returns the status of the line A20 through the KBC % S! a) M/ E7 k
  4. ;       programming by bini for debug. 2008-07-01
    % S0 p1 a9 K2 W, i$ r! o9 s3 F
  5. ; ; _0 ]! {( V& ^+ C9 G1 I' l
  6. .model tiny
    % K6 x1 q9 X( g0 q- ?
  7. .code& l3 c' q- ^; o! m! t
  8. .4869 R3 g( C  S! _$ j6 E- m* F
  9. .startup
    $ x9 O* D* M& t8 Q
  10.                 mov     dx, offset msg_fail 8 r) w1 Y  Q* y  e
  11.                 call    _GET_A20_STATE_0 D1 g7 e% f. h) @& n# V
  12.                 jz      exit1                           ;  was a problem
    7 ]0 q7 t  G6 B" n5 C" Z
  13.                 push    ax                              ; Save state, AH / n2 M. u- q2 M1 ^
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    ' S7 Y# R& Q7 l) ]. z: j+ @/ X" \
  15.                 mov     ah, 09h - C: O) A6 n- K& F# c& ^6 U
  16.                 int     21h                             ; Print message 3 J( N: t- B8 z& u' c
  17.                 pop     ax                              ; retreve state
    / w5 l. S0 A8 |

  18. ; F4 {2 j9 j) g! u/ x8 k/ S0 k" ~5 k
  19.                 mov     dx, offset msg_dis 4 D; O8 q, N* p0 s5 h- M* e
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    ' z$ C: k/ E' Z% F  |! q1 f# H
  21.                 jz      exit1
    . I5 f2 X7 o. R# ~! q
  22.                 mov     dx, offset msg_en
    5 p  p$ D) `" w1 c( V' b1 N1 x
  23. ' p/ t' j  ~# }3 v. |# S, A6 N$ l4 u
  24. exit1:          mov     ah, 09h , _9 \) J7 m2 H8 N" Y# Q' e
  25.                 ; DX already contains address of string ) E  \7 o* F* Z9 Q; f% \/ r
  26.                 int     21h ; F  C' K, K( {6 G) h* l( Q, N
  27. 4 P* z% l! Q2 d+ j( ^& s
  28.                 mov     ax, 4C00h
    " P) w. y1 R4 r) C. h7 ]
  29.                 int     21h
    , Y1 b& `4 d* e+ p+ {
  30. ; w( n, C9 P% o2 |
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    . y& _1 V# _2 P( _1 l
  32. msg_fail       db      "FAIL", 13, 10, "$" & H' H, Z# {$ v6 ~* R5 I
  33. msg_en         db      "ENABLED", 13, 10, "$" 0 w/ C' {1 `/ h1 q
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    , y+ r9 D1 U( H
  35. 7 Z. `$ K) r1 r7 H, G; t0 s* |
  36. , p5 L$ |  Z- Q7 E( `
  37. _GET_A20_STATE_: 2 Z8 T; U2 q0 H+ W- ^/ Q
  38.                 call    A20Write                ; Wait till the input register is empty
    ' f" U. L& |5 c$ t- J
  39.                 jz      exit2+1                 ; Bypas the reset int's
    1 d. q8 k' G8 R& s  P  j
  40.                 cli                             ; Disable ints so we'll get our value # z, U4 M' R( O$ t& W9 k

  41. 5 C$ g5 h& S+ S
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    5 m& i1 R  \8 _$ |$ s
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    8 n2 T2 y# G2 H
  44.                 call    A20Read                 ; Wait till the 8042 output register ( h# R* s+ }! h  }# n9 p  ?
  45.                 jz      exit2                   ; has something in it's buffer
    : f" A7 R8 ]5 {) s
  46. 2 |  P3 n" _3 o" b) H' l, R: s2 U
  47.                 in      al, 60h                 ; Get it
    % |  F: v; l8 l
  48.                 mov     ah, al - j9 Y0 `" {# ]
  49.                 call    A20Write                ; Make sure the input register is empty * K- h& Q0 a' X5 `$ Q* W2 a. J5 T3 ^0 `
  50.                 jz      exit2
    7 ~3 K- d2 F! J5 z( a+ {) O2 G
  51. 8 g/ i/ s, G9 o% s& ~
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ( N# x; \3 ?7 i3 w8 `$ b. ~
  53.                 out     64h, al
    6 [: J5 j2 s2 P  e' u
  54.                 call    A20Write
    5 E, G5 A# ^  f, y. K; p& n% d5 d

  55. . i' t- v* Y3 |  c
  56. exit2:          sti
    2 W# w* {+ n1 {/ i5 y* c" o
  57.                 ret& p% X+ e' Z% H5 \

  58. ; P1 B& |% C3 n

  59. 7 W! e& O4 Z: j, O+ [. a2 Q& `
  60. A20Write:       xor     cx, cx                  ; Reasonable wait - K2 h2 c# O* |, u( _
  61. get1:           in      al, 64h                 ; Get KBC read status
    , X" }2 Y* |# B9 T1 n* T1 b
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear ' Z& n0 q/ g1 q7 X2 U- s
  63.                 jz      clear + G, X  z- h- v) H+ a3 s
  64.                 dec     cx
    % @- H* z2 {  \
  65.                 jz      exit3 / w9 z3 x- ~/ Q" l8 j' B3 i
  66.                 jmp     SHORT get1
    6 F6 h2 I# o. X, b+ u& }9 ]9 i
  67. clear:          inc     al                      ; Clear ZR - @. W/ w: w" U4 I
  68. exit3:          ret 5 O7 t5 C" t4 n+ |5 T

  69. ' K# W" f5 s( X7 Q
  70. 5 p+ J. z% o6 r) }# E
  71. A20Read:        xor     cx, cx 2 U0 W. w5 n0 z
  72. get2:           in      al, 64h ; x. X6 w* d# F; Z$ W+ g* c
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
      P, ^9 f# T9 ]9 l3 [
  74.                 jnz     exit4                   ; something for me
    $ j4 X* Y1 ^3 [! ^
  75.                 dec     cx , l6 ^1 W; H; Z: G7 d. b
  76.                 jnz     get2
    ) k  [( L% m( n
  77. exit4:          ret     
    3 C( w# m) Q. N  t
  78.                
    & V5 r9 O  N& O# ]: A
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()) d. c# s. `- v$ f5 I, s. {
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
' _* t8 z3 R! L/ Y0 e% R        while(inp(0x64) & 2);        outp(0x60,0xdf);
; M3 m3 C9 }4 |+ P+ l        while(inp(0x64) & 2);        outp(0x64,0xff);2 e" B! j* ]: G% q* s- A
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-10-12 08:08 , Processed in 0.057315 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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