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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 6 _  S- c  k  f. B  g' b, @
  2. ;
    $ {8 G  Y* ^+ v% y- Z+ h
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    % V; y8 o; |* J$ k- l. x% y
  4. ;       ml A20ON.asm
    ) h6 P0 {0 ?$ q% @" T4 N2 L
  5. ;
    ( m3 x' x/ |; m1 S- \# d
  6. .model tiny
    $ n5 Y" H4 A, r8 M3 n
  7. .code
    5 k" e* N5 c! M& \+ J- ]8 u
  8. .4864 b8 M9 L' Q8 F! {. O8 D
  9. .startup
    ' C. [8 k$ i& A4 A) k

  10. 8 c% O0 X" c0 C+ u' a; H
  11.                 mov     dx, offset msg_author
    % ^6 h( E+ ?8 A; A
  12.                 mov     ah, 09h
    . ]: P4 q6 l* X+ {+ s+ W
  13.                 int     21h
    # U  ]  a3 g/ S$ I
  14. 2 r9 _/ {; k& ~" j
  15.                 mov     dx, offset msg_fail
    2 `1 t) V6 w3 P1 A
  16.                 call    A20_ENABLE& g, U3 h0 n* Q
  17.                 jz      exit1- {! [4 U/ p! t
  18.                 mov     dx, offset msg_ok 0 Z. c- k& v. g# _2 c
  19. + w& ~2 s7 H3 a3 m6 N# f; ~
  20. exit1:          mov     ah, 09h   ]3 M" e# R8 M. u" e, t3 |. u
  21.                 int     21h 5 b) W1 S0 X; t9 h- {+ Z4 b
  22.                 mov     ax, 4C00h
    / ], S4 c/ N) {6 q, n/ Z$ C
  23.                 int     21h 3 C. q2 E+ G/ p0 x$ b
  24.                
    . }0 d' A8 e, E# d
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,6 Q( W- |' [0 I, m: M7 o
  26.                         "2008-07-01",13, 10, "$" 4 t5 }0 S) ^  ^5 E0 Q) b
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ) d1 `6 [2 z5 t# c
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    2 `8 G4 Y* I, I  [
  29. 2 n9 H2 Z; K5 @  X, \2 L
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------% u  y& |2 L; Q0 n/ X
  31. A20_ENABLE:
    2 R8 M5 f( Y) P# ?" H3 L+ ?
  32.                 call    A20Write
    " N3 O. [2 }! R' G" K7 J
  33.                 jz      exit_enable4 D; O1 R6 S, N0 j9 E) e
  34. ) |9 J' [: V3 P
  35.                 cli                             ; Only need for reading value from KBC & H3 d0 J) A2 ^7 y: F! a( e
  36.                 mov     al, 0D0h
    ! i! k" d, [" {3 ]- c+ U/ ~
  37.                 out     64h, al % [- A: n4 U% R% U  o4 d6 w
  38.                 call    A20Read $ V/ g- B2 ]9 i* N) n, f
  39.                 jz      enable_int
    0 c3 Q) l$ B4 W" t

  40.   R) n9 g* W' _& i% \" `3 s8 \$ X/ i
  41.                 in      al, 60h                 ; Get current status ; e7 Y7 J5 y2 f; L4 N/ V  O  j
  42.                 mov     ah, al
    ' o% Q$ _  @8 S1 g* x- @
  43.                 call    A20Write
    ( G4 ]  F1 r! g
  44. enable_int:    sti 8 ^( e/ L2 B( ^$ @) n5 o' Y. ?
  45.                 jz      exit_enable" k  v0 a/ ]$ c
  46. 0 K& c0 f) l& x2 Y& j
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the % s- n, ~* H0 _9 D6 ?6 H
  48.                 out     64h, al                 ; Out Put Port next ' G% V9 }" l; q9 L- ^! ~
  49.                 call    A20Write 4 s: A' ~" h: y
  50.                 jz      exit_enable; {% F; A9 t0 T
  51.   E/ h5 ^# u: r
  52.                 mov     al, ah . y" Y; g5 A9 u
  53.                 or      al, 2                   ; Enable line A20
    ( M! _1 W0 `8 D
  54.                 out     60h, al
    / l, d+ f! B9 r+ |0 t% W) w
  55.                 call    A20Write + H, Q5 d- t2 \  S
  56.                 jz      exit_enable
    " z& w0 Q; _+ C! q; C

  57. 5 N) Y' _+ f8 {* i0 S
  58.                 mov     al, 0FFh                ; NOP
    ( B( w" T$ v8 w1 d( O4 \
  59.                 out     64h, al : y' R4 t: e: G9 p5 s4 ~
  60.                 call    A20Write
    ; P' _) K! R, A' B6 r6 B% L$ L
  61. 4 n+ b9 v$ J1 K1 \0 \& C# x
  62. exit_enable:          ret ; h0 c) b$ ~+ y: R7 ]
  63. 4 J9 e0 f" n0 u/ u. t% a- X' M
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    4 \( c. f3 M+ i% {3 o. T
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ; Z0 X1 c" o# A' c, ?1 n/ D
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    6 A: s' M; T) c1 |! y
  67.                 jz      clear
    0 a& e' n. r4 ?0 ^; A7 i; J' y  c
  68.                 dec     cx ( j) X6 o9 d; P
  69.                 jz      exit_write " `, |% F. f' \
  70.                 jmp     short get_wirte 9 h+ W9 d' H, n- h/ ]
  71. clear:          inc     al                      ; Clear ZR   o# o) o, s$ p  g) _% b9 X4 r/ a
  72. exit_write:     ret - P8 T7 d7 d: v0 w( A
  73. 4 C1 Z6 x, f2 ?
  74. 4 {* d+ m3 T2 G0 ?1 H
  75. A20Read:        xor     cx, cx % X3 w4 v" b9 c; a- B2 d! t: H) _
  76. get_read:       in      al, 64h 2 u7 K, l/ \; o- S
  77.                 test    al, 01                  ; If the 'output buffer' is full, has - I1 J$ B; A9 [
  78.                 jnz     exit4                   ; ...
    9 w- V/ K9 S6 a) f
  79.                 dec     cx 7 |" u4 P, }# O
  80.                 jnz     get_read4 @2 M2 O) I- X$ m( h( l! J
  81. exit4:          ret     0 h5 n1 w% ~4 X' Y5 [( b5 E
  82.                 0 {* [' {0 |7 p0 b) F, e
  83. end
复制代码
  1. ;A200FF.ASM 3 g9 |. w( i: W2 l5 ]9 S
  2. ;
    # R# t  g! D' U5 j- Y8 S% ]
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    9 R2 J2 i  R! m: g/ Z
  4. ;       ml A20ON.asm ; b& x3 r3 c! N6 w; Y
  5. ; . K5 D6 R8 f5 S# V: K+ j
  6. .model tiny
    $ s1 T5 B) f! K0 ^8 b
  7. .code
    $ ~4 P: K% ~/ ]" x, }
  8. .486
    + G0 U# N9 C3 }( h/ I$ }
  9. .startup
    ; f: P8 q% C$ x' _

  10. 2 }, ?0 ]; y$ @
  11.                 mov     dx, offset msg_author
    2 J* P3 M+ }4 F: o
  12.                 mov     ah, 09h
    4 `' P3 B9 z0 x. z
  13.                 int     21h
    $ m" o& H1 O4 }: `
  14.   b7 T; B" n2 i3 ^- O8 i
  15.                 mov     dx, offset msg_fail
    $ N" {" a7 ?& K2 b1 N
  16.                 call    A20_DISABLE: V7 v; H5 ~$ r
  17.                 jz      exit1
    . G1 r8 ^$ ?( U# C: {8 t. a
  18.                 mov     dx, offset msg_ok
    9 o0 o3 X6 Y" l

  19. " r% B1 {$ x( @* W
  20. exit1:          mov     ah, 09h
    % ?& ^8 D/ n/ m* r$ p
  21.                 int     21h ) n5 z4 p3 I! B$ ?  o- A
  22.                 mov     ax, 4C00h
    ! `/ i5 g6 s6 D0 b4 |
  23.                 int     21h 4 V: m- O, ^$ V% v! ~/ p: g
  24.                 / R) N. S7 s: Z* _9 x
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,* T; ^) u& ^& C
  26.                         "2008-07-01",13, 10, "$" % R7 `9 d8 J' f3 T; ^
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    % v8 H) @* M; t$ w0 k& Q0 ~' i
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    5 w! @$ r: e( T

  29. 8 d* [% Z5 g8 |1 G& B7 L
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------6 f; ^& Q) c1 F- j: Y! K
  31. A20_DISABLE:
    4 W2 v7 Q) s: n$ D3 R
  32.                 call    A20Write . s% P1 S& h! j$ P% r* X
  33.                 jz      exit_disable* F6 d0 `1 L/ Y6 h# G. [' `! ?) x

  34. # {7 B; ^) r+ r
  35.                 cli                             ; Only need for reading value from KBC 8 K$ {4 f0 B8 V
  36.                 mov     al, 0D0h 9 _4 ~* z$ P# X1 J' b) Y
  37.                 out     64h, al 6 D5 `4 L  q0 t  y0 q4 Y1 B' O& _
  38.                 call    A20Read
    0 n, Z" r0 S' k0 n% A! d
  39.                 jz      Disable_int
    2 P- m( }) S( Z

  40. # F! x/ g5 {& `* G8 ^* r# \
  41.                 in      al, 60h                 ; Get current status
    " x4 z" u- u' L4 a
  42.                 mov     ah, al 8 n3 g3 d+ B2 |
  43.                 call    A20Write
    & p, x4 H) M6 P0 Y' k: r
  44. Disable_int:    sti
    $ r. f9 f3 S0 \- m4 [
  45.                 jz      exit_disable& |' o8 n) }0 Q3 K5 F, x

  46. # D% o% v  R" U$ @- y% g
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ) O" l9 n, z  l/ Z! Z  Q+ ?% ]
  48.                 out     64h, al                 ; Out Put Port next " i" ^3 M2 R/ S9 O& a8 G2 z: O
  49.                 call    A20Write 2 d5 i( y* s5 l0 N7 l
  50.                 jz      exit_disable
    5 i( M5 n' z( Q% n# W" C) ?
  51. + w3 C' Z; }# X2 i! `2 }2 u
  52.                 mov     al, ah # g# r) c9 m7 C
  53.                 and     al, not 2               ; Disable line A20 : H0 K$ e9 }! A/ F5 _
  54.                 out     60h, al % n% [& I9 K0 B" S% A
  55.                 call    A20Write 4 Z, x1 P. J1 p; v. D
  56.                 jz      exit_disable
    & u9 Y5 D/ n6 P3 X% d% q

  57. & D* {" c/ ?1 T) x& Y9 M
  58.                 mov     al, 0FFh                ; NOP 6 Y6 [; S; d3 K% }$ C
  59.                 out     64h, al
    9 w8 u# v7 h+ ]. c3 I1 g
  60.                 call    A20Write : d- F4 f/ M( O8 g4 x
  61. . _6 j+ c& ~3 E& W/ `$ T* O9 U
  62. exit_disable:          ret
    1 `, I4 `( y7 ^  h  O# z
  63. 4 ^* Y  H; t5 U- Y  R
  64. A20Write:       xor     cx, cx                  ; Reasonable wait - T- j8 s4 M1 Q7 d0 F+ M2 p
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ; H4 P4 Q7 h9 q0 J
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ; u: k! k& [; P. E
  67.                 jz      clear
    / g+ X& v* f/ e
  68.                 dec     cx
    ! n3 y7 S9 w# p4 f, x# R
  69.                 jz      exit_write
    1 s) n, p! h) V$ Q9 ?: _
  70.                 jmp     short get_wirte
    9 \( a5 o2 @+ x: K9 l
  71. clear:          inc     al                      ; Clear ZR
    1 l; j0 l' y8 t" m) l) @
  72. exit_write:     ret
    8 j4 M0 }  R7 B0 G/ o2 P) k
  73.   S9 Z" o5 q6 w0 X

  74. 6 y( W( k) K' t( Z& O! i( Q* o4 ]
  75. A20Read:        xor     cx, cx 2 X4 m, l$ I, p% ?$ |) Q, S
  76. get_read:       in      al, 64h - U! e5 ]+ E, B1 p
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    - R+ e7 B. L: n
  78.                 jnz     exit4                   ; ...
    4 C3 g; Y' ^: M
  79.                 dec     cx
    ) }: W% Z' t8 E' K4 b
  80.                 jnz     get_read
    . G+ d9 w- C5 L4 [" v
  81. exit4:          ret     9 \6 ^  \$ [: R2 L9 X" E' ^
  82.                
    3 w# O" E3 G; y8 n1 x4 M( e' q
  83. end
复制代码
  1. ;A20STATE.ASM $ U6 Z' R+ a: s- N4 |. O9 g
  2. ;
      Y4 K9 F) W: R/ r9 d
  3. ; Returns the status of the line A20 through the KBC 6 X  X3 N: ^8 E  w  V+ }2 l. W
  4. ;       programming by bini for debug. 2008-07-01
    & }3 Y/ ^3 }# \6 w! m! u, l
  5. ; & @: J! u4 Y* z: b) P: u
  6. .model tiny
    0 _* e  k, g+ G5 h6 V; q" j
  7. .code$ b2 c2 e: }5 b9 [! a1 R
  8. .486
    . t! g4 N& ~% o4 t$ C9 ^
  9. .startup0 E8 g5 \* z% J; ~0 E( c
  10.                 mov     dx, offset msg_fail 0 g# [2 {9 k$ m5 v3 q$ b
  11.                 call    _GET_A20_STATE_3 A* K' l( q+ F9 L6 H& [  _
  12.                 jz      exit1                           ;  was a problem
    - ~& ^/ m( {' d4 N2 B
  13.                 push    ax                              ; Save state, AH ; m7 f. D8 X; y( d& Q) O
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem # U1 G1 |. u9 {7 C9 b) j
  15.                 mov     ah, 09h
    ! s# h2 `% a4 n( a" C5 K
  16.                 int     21h                             ; Print message
    ) q, O- {0 y% a3 `: g4 C
  17.                 pop     ax                              ; retreve state
    " z& D, C4 |# D
  18. - E2 n3 q5 a  G9 v
  19.                 mov     dx, offset msg_dis
    $ T0 ^+ k4 Y: _! Y2 z3 s3 ?" h7 D2 y
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    8 H* x9 p3 |  n+ U8 u
  21.                 jz      exit1
    5 f2 Y* x6 f1 _3 \: W" c. P
  22.                 mov     dx, offset msg_en
    . q( N& f' Q( k6 W, D: g

  23. 4 u6 P5 A1 B* b
  24. exit1:          mov     ah, 09h ( I1 z: v0 c& m. c" i8 T8 Q
  25.                 ; DX already contains address of string
    & O% P2 p9 D# |6 a2 H# a$ F% h
  26.                 int     21h
    * p+ f8 x( d8 }: F2 b5 z' g
  27. , a- a5 F6 j7 P1 ?# q1 k7 Z  O* f
  28.                 mov     ax, 4C00h
    4 s$ f' [) v& _
  29.                 int     21h
    9 c& f/ P& G; h# b* Z" o
  30. # P' [8 u4 V: T* P7 g. ~
  31. msg_ok         db      "OK", 13, 10, "A20 $"   v" K6 `5 X* J5 t" k
  32. msg_fail       db      "FAIL", 13, 10, "$" . p1 _0 o7 i% p. o( L7 x
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ' ^" e, t* i/ n/ u
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    " u! }, V3 n7 x

  35. . U& H& e8 C, z# ?5 q( ^

  36. & P1 {% o4 Y: L" _
  37. _GET_A20_STATE_:
    6 q7 j+ a* z" T* K* d; [( p
  38.                 call    A20Write                ; Wait till the input register is empty & G! B( ?0 ~7 ~0 c
  39.                 jz      exit2+1                 ; Bypas the reset int's
    * v% H$ X0 n+ |; B
  40.                 cli                             ; Disable ints so we'll get our value
    0 r! p" w. A1 N3 z! x

  41. # h+ Z; V/ \& s2 U; O" z3 X
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register * F! m' c) z& b! y
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    1 A% i( b" [! v/ S5 d4 L# t
  44.                 call    A20Read                 ; Wait till the 8042 output register
    " C$ V# E) @9 I
  45.                 jz      exit2                   ; has something in it's buffer : P8 w+ _2 {+ F. M9 u4 @

  46. - A8 Q8 F8 f" q/ L8 ?1 K. ^' A
  47.                 in      al, 60h                 ; Get it
    7 Z) k+ Z3 f4 Y* {2 {: M8 Z% }+ S; R
  48.                 mov     ah, al ' ?2 C2 W7 u; c' u& X* t( w
  49.                 call    A20Write                ; Make sure the input register is empty 7 S$ M. z9 W$ r& q' Z
  50.                 jz      exit2
    6 f+ E8 y( d8 G

  51. 7 r- ^( p! P7 H- x
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 7 T6 j  A5 o0 [  a/ ]
  53.                 out     64h, al : b4 h! P5 J% ~7 s$ _' J
  54.                 call    A20Write
    / h% h) Z- P: U7 z" V$ ?. b0 U
  55. ) b; T. ^1 m0 K: B# n- \2 M- H; k" m
  56. exit2:          sti * R. g# f( ^3 R" `7 ]
  57.                 ret
    0 e/ ~1 Z9 B- j$ m

  58. ) r/ F% ]' q0 w5 B$ {* s

  59. & C$ W6 b9 U( f5 Y; }' d% t0 c+ a
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    9 K+ }1 S4 o4 ]# l
  61. get1:           in      al, 64h                 ; Get KBC read status 8 `. R' H) ?8 Z0 n2 h, n
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
      U, i) n( V0 E+ {; G
  63.                 jz      clear
    + p! U* k2 H. ~4 u/ N5 M& m6 N
  64.                 dec     cx 1 ?* }' x6 J8 E) R
  65.                 jz      exit3
    " E& K' G& h. a/ g( `
  66.                 jmp     SHORT get1
    ; U" e6 w# p7 w! N+ O2 F- v% J7 d# A
  67. clear:          inc     al                      ; Clear ZR 6 N) Y+ F8 R5 V% O# A# {& w  Y
  68. exit3:          ret ! A' p3 L+ g: }4 P2 T

  69. " M9 e/ ]6 @8 U
  70.   R) z7 R/ p9 H7 s
  71. A20Read:        xor     cx, cx
    ! v% n3 s) N4 b9 K- |. X
  72. get2:           in      al, 64h 9 k9 g& a7 P/ h
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' u4 F2 l7 }8 B  O
  74.                 jnz     exit4                   ; something for me
    3 K4 ^9 |: y$ }* q& e
  75.                 dec     cx
    6 F- W# }1 e3 S0 \* ?# y
  76.                 jnz     get2
    # e' ?7 I3 u0 o, M
  77. exit4:          ret     
    " ^$ h. M- f/ k
  78.                 , C5 N! z, G& H( N" a) ^. K
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()7 r8 s: l! m5 c- Q& q# \
{        while(inp(0x64) & 2);        outp(0x64,0xd1);( Z5 J) H. O" ^+ x5 N; W7 U0 s
        while(inp(0x64) & 2);        outp(0x60,0xdf);% M4 O" n! c7 M# n, Y3 B4 ?
        while(inp(0x64) & 2);        outp(0x64,0xff);
" x* K  y" \: r2 ~1 d9 d! t4 M* o}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-5 17:37 , Processed in 1.124659 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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