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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    " N6 ^/ w0 K, t6 u: t3 e7 i
  2. ;   J) S7 l" E6 f% \  u' }
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    4 ]4 x2 U3 X# `' k8 n
  4. ;       ml A20ON.asm
    : l9 b1 g0 k8 w$ o/ ~1 ~/ A7 b1 B8 M
  5. ; * N8 I0 D' U! W4 f2 A; }
  6. .model tiny* l0 c" _) O: r. _% V6 L
  7. .code$ r0 a! F1 h# ~( n% V+ b' a& b& H4 C! e
  8. .486
    / i) l% m# [9 b
  9. .startup1 D0 ?2 k9 q0 Z

  10. # s) \4 M& _. z. E
  11.                 mov     dx, offset msg_author
    - k; P2 D" t( x2 Z
  12.                 mov     ah, 09h
    9 u6 T' T3 r4 C5 \8 O: }
  13.                 int     21h! L4 y. t9 T% t2 v
  14. 2 S) f  Q" ^* S$ m) _+ p& V" @) m0 P
  15.                 mov     dx, offset msg_fail
    . T$ L  V& }3 z0 d' ~$ `; D7 h
  16.                 call    A20_ENABLE8 T* S6 q4 |$ e0 n" H
  17.                 jz      exit10 ]8 H0 D' w: X$ W
  18.                 mov     dx, offset msg_ok
    / K2 @) Q% L4 o* `: X* k7 l4 w
  19. ( _( F; k0 ~9 m' ~
  20. exit1:          mov     ah, 09h
    9 u; t) X) ^3 m: n: {
  21.                 int     21h 6 G$ z1 E  s7 m' y5 @7 D
  22.                 mov     ax, 4C00h
    $ j) l9 ^! `9 D4 Z) H7 C' C: x5 y, e
  23.                 int     21h 6 c% @5 G6 j& a! F- S7 ~
  24.                 & @6 ?3 N- n! T0 y: b$ Z
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    # n6 e9 o1 z7 C) }8 @) p4 T
  26.                         "2008-07-01",13, 10, "$" # r& P: e1 a4 [3 F7 a  u5 V, ]+ l
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" & Y; z# z$ u/ c
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" 6 o& m/ M, `; _  }

  29. 8 m& J0 c. M, Y4 m5 }( l
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    3 K* V4 k  F, Z' Y2 U
  31. A20_ENABLE: & Y) w4 K7 G& t6 o. A( G+ b& Y
  32.                 call    A20Write
    - [! T1 n* C1 S
  33.                 jz      exit_enable. i9 c9 R4 z( \- d- S! z6 p- E
  34. : i# x- ~3 y: u
  35.                 cli                             ; Only need for reading value from KBC
    0 N( G1 B7 |2 O( g4 m: W# a6 ~
  36.                 mov     al, 0D0h , f" \; A  k/ H6 E) j) e% z$ y
  37.                 out     64h, al
    3 y0 p6 Q2 x6 _) K5 S
  38.                 call    A20Read * K! E: Y* j! j) [' `  ?0 @; a
  39.                 jz      enable_int
    * a  S" Z/ C# K8 x6 N# |

  40. $ X, w/ b8 N$ ^! _0 y3 n* n& B' ^1 p
  41.                 in      al, 60h                 ; Get current status 8 r: z. N2 D2 Y2 _2 T' C  r
  42.                 mov     ah, al ! A( T: d7 l& s; g9 v
  43.                 call    A20Write
    1 Q! @" w+ k, O& ~7 s& B+ b4 ]$ X
  44. enable_int:    sti
    ' A2 ]' B% o* M  ?# r- i, U0 o" \. q
  45.                 jz      exit_enable* V- @8 u" E! J: f" l( S& F

  46. * Z' q$ S! E' ?# H5 T* ~  X
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the # y1 d$ d9 l& ?' B0 K( O
  48.                 out     64h, al                 ; Out Put Port next 2 {0 l' q: k0 U" c
  49.                 call    A20Write
    4 Y  }% H* N3 h/ H* z, q3 p+ O
  50.                 jz      exit_enable
    / {+ L9 f3 Q& O% F
  51. , q7 {: U/ ~$ d8 T1 o5 W) E
  52.                 mov     al, ah : }4 _5 O" q# J( ?/ Y
  53.                 or      al, 2                   ; Enable line A20 ) r0 k7 z0 [% M. i
  54.                 out     60h, al   r- }! ?  S; {4 p% v& X
  55.                 call    A20Write 9 _3 _% S6 e% O4 A! z0 q8 O% {
  56.                 jz      exit_enable3 |: n& W" ~4 n0 i$ J) |

  57. ! i) {7 m1 g6 m2 ~8 o2 e
  58.                 mov     al, 0FFh                ; NOP : A1 ?: I; p3 s) T6 H
  59.                 out     64h, al 6 P) a* j* s5 x; v7 F3 F" L
  60.                 call    A20Write
    5 d& P' w3 t0 l/ v$ B
  61. 4 V2 A( H3 \( j& N& {
  62. exit_enable:          ret
    , T3 }+ z. V) q: Q0 G( N* f

  63. * D9 Y+ P2 A% g
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    6 E8 h2 I7 S$ b7 k% _6 G
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ( [  v' S7 r) ?5 J
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear , [) b( s7 w5 Z. B9 Z% Q# u+ i
  67.                 jz      clear
    7 ]+ Z/ d4 R" [+ ?
  68.                 dec     cx + h+ B6 Q" Q/ z( G
  69.                 jz      exit_write
    " S- y. @3 Y" @/ S4 l8 P5 m
  70.                 jmp     short get_wirte
    , ~5 Y* U! z* H6 A4 T# e
  71. clear:          inc     al                      ; Clear ZR
    % n6 `0 i! o' c; s  S/ k+ T
  72. exit_write:     ret
    ( J* ^" l  U- O/ H- _8 b4 Q3 }( K
  73. 2 E4 g. m5 i! @, q& M2 N4 o

  74. 1 U. l/ t$ Q! v5 x
  75. A20Read:        xor     cx, cx
    $ ?. p: X) t. |* e
  76. get_read:       in      al, 64h * X8 p4 ?& c' K. ]; u8 W
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ) O% X& ?& \* F
  78.                 jnz     exit4                   ; ... 9 F# r+ T# p" w8 d  q# c5 J
  79.                 dec     cx " b+ g: G% A( _  g% }8 V
  80.                 jnz     get_read1 s' B; u* o$ t9 B+ V+ Z
  81. exit4:          ret     * P* o4 A9 @7 w+ m, ^; t' s( {. O
  82.                 ! E+ [& ~( K" n& p" ]( V- W
  83. end
复制代码
  1. ;A200FF.ASM ! }9 @' `2 t6 B7 q  X# D
  2. ; : u' \, ?# s3 w8 ~8 ^
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-010 N0 A  X% f8 ~& `: A, }
  4. ;       ml A20ON.asm
    ) H" j- @( j& C3 h* Q  U- s
  5. ; : a& W( y0 ?. H* c- g2 A" V1 M5 \
  6. .model tiny
    * }" ]: I% V# L2 w; `4 D
  7. .code& c, V3 u2 \. h$ Y
  8. .486$ [& g7 i3 N4 ~
  9. .startup
    ) O, v1 \# Y' e: t

  10. % o% U" g# r5 X8 W* C; R7 e- `8 P
  11.                 mov     dx, offset msg_author) y2 E: s! x4 J" ~1 B3 G5 I
  12.                 mov     ah, 09h$ n2 N, W. ^" }: U) p7 L
  13.                 int     21h
    8 J( Q) l$ L; [; K  i

  14. 4 b; L, X8 J) z, x
  15.                 mov     dx, offset msg_fail
    + d. b2 n( ~# h9 ]
  16.                 call    A20_DISABLE
    4 I! h4 G' T* Z! e9 ~5 X( B0 j7 c
  17.                 jz      exit1/ {6 @0 H3 d/ B8 J7 O
  18.                 mov     dx, offset msg_ok ! q  Q* t/ i6 G+ ^
  19. 6 c/ L% }( {, n8 R' h9 I4 s& V' l+ D- B
  20. exit1:          mov     ah, 09h
    $ a$ e' f/ J, S6 e0 r, |3 I
  21.                 int     21h
    ) C" v5 B( f  h+ I
  22.                 mov     ax, 4C00h   D+ v- G% ~# ^
  23.                 int     21h
    1 A# m! t9 Y: W7 \
  24.                 3 {2 {8 X# G- \0 J
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    & J- o, I0 T' W8 K4 M
  26.                         "2008-07-01",13, 10, "$"
    - r6 [; y4 \0 g( x
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    . V6 \% f/ v: ]9 {
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"   S  h' {9 w' p# X3 R

  29. . J' W0 @  E' G/ z  C, P6 {: |% F
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ' Z- t- r& j2 Y# Y' q& P& l1 K
  31. A20_DISABLE:
    0 U# k/ L7 B- F2 `
  32.                 call    A20Write
    ( ~% x+ Y: s, g! a" D$ h/ X1 i4 L/ P
  33.                 jz      exit_disable/ P0 S, w4 L: Y8 b
  34. ( P* B0 \2 o8 K, I  x$ I
  35.                 cli                             ; Only need for reading value from KBC ' j$ K* x. ]$ k
  36.                 mov     al, 0D0h
    - x/ m0 P) v' Y! f" z
  37.                 out     64h, al . Z7 g9 V5 s8 g* L  |2 q
  38.                 call    A20Read
    4 M* u% ?% h, T$ H: E8 r
  39.                 jz      Disable_int 1 l  m- R, I" T' A" b# Z1 Y0 n
  40. 7 {/ H) n; I% h# X5 A8 u
  41.                 in      al, 60h                 ; Get current status
    ( d2 V; J0 |' q; U9 m3 c- `
  42.                 mov     ah, al
    ( l) c0 u1 K4 Z- ?
  43.                 call    A20Write
    6 O' j( ]* A5 j+ y/ ~" r
  44. Disable_int:    sti 3 S& I: ^$ [1 K' \' I- n0 @8 m9 J9 _' g
  45.                 jz      exit_disable3 R8 l$ N% m& {! _- z& M. i* E6 d
  46. - U  x- z7 c7 ^3 L
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    . S) I( p1 [" H8 }, I! C/ b7 T
  48.                 out     64h, al                 ; Out Put Port next " P! P; P% T" Q' ?* m
  49.                 call    A20Write
    6 J) Z4 O) }0 j! c
  50.                 jz      exit_disable
    2 E( Z; y: q' o/ {. P
  51. ( \7 ^) P2 G1 O6 I7 L
  52.                 mov     al, ah : b1 g9 l* l( d5 K( ~* F
  53.                 and     al, not 2               ; Disable line A20 . A! }" S7 }! P# t
  54.                 out     60h, al
    9 D( P% f$ n9 A  r, z
  55.                 call    A20Write 6 f8 s# h4 e2 `) [, z% d1 l
  56.                 jz      exit_disable
    ( c# e( Z6 L5 ]# H* q& G
  57. # V7 K$ t' R: p6 i5 n4 s' f% _
  58.                 mov     al, 0FFh                ; NOP : S' v$ h0 l/ f* k$ s- m$ M- G# a
  59.                 out     64h, al
    . d- S/ M; T* j: Z/ Z
  60.                 call    A20Write 9 n0 v* f6 c+ p9 W0 K( C

  61. ! P+ h( \5 T! n' |
  62. exit_disable:          ret , q4 p6 R( p; j* \  U- N% {! W

  63. 5 n5 E8 `  M. ?& n
  64. A20Write:       xor     cx, cx                  ; Reasonable wait % }9 d* U% J% u) f* b# d: K1 ?% u/ D
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 2 Q; Z0 o! C4 E* z1 w5 L: T
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    1 A0 G8 L  B; e, D
  67.                 jz      clear ( ]( T; S  J* K8 }5 n0 b4 p
  68.                 dec     cx , ~/ Z, S# g4 q8 y$ I# M7 Q
  69.                 jz      exit_write & o( ]2 f4 s7 s: g+ n
  70.                 jmp     short get_wirte 0 M0 v/ R2 H" J! O
  71. clear:          inc     al                      ; Clear ZR
    9 @3 B* X" O: Y$ d1 |
  72. exit_write:     ret * c9 ^8 v2 o" o# w# f# [

  73. ) J2 t! R, e) H8 Y3 v( J
  74. 2 f5 S$ \. u% i# e% p7 h, q
  75. A20Read:        xor     cx, cx 7 a4 c$ D3 a9 N9 w& |
  76. get_read:       in      al, 64h 3 J; p5 [6 z- f" m$ F5 ~: ~
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    8 r1 y9 b* C6 `% V5 @: o
  78.                 jnz     exit4                   ; ... & r# h9 z' b. y: I# O; [7 Z6 W
  79.                 dec     cx 8 C* G+ _% `5 `: e- U
  80.                 jnz     get_read: ?; r# n6 x" d- }7 O. f# Z4 h9 G+ [
  81. exit4:          ret     # v+ {9 ?* l  W2 Y& Z( C
  82.                
    8 T7 Z, {4 S/ U! ~
  83. end
复制代码
  1. ;A20STATE.ASM 7 `  k' o; }( ^2 h; l+ d
  2. ;
    # y0 D3 n, K8 C8 I( \. @3 ^
  3. ; Returns the status of the line A20 through the KBC 1 N/ z6 |; }, A9 Y- ]- f
  4. ;       programming by bini for debug. 2008-07-01
    # y1 a* h. d" [/ b; s
  5. ;
    ) y$ S- N8 q6 k0 x  s
  6. .model tiny4 {) F( C0 j2 |8 r* y
  7. .code1 ~) @) A& e6 J
  8. .486
    ' g# W" g+ L) x
  9. .startup
    & Y8 a0 [/ u  S4 F2 W& c' d9 D: K
  10.                 mov     dx, offset msg_fail ) O$ Y0 R, g9 t4 E
  11.                 call    _GET_A20_STATE_& H; E( r0 Z: m/ S8 N7 z7 ?
  12.                 jz      exit1                           ;  was a problem" b7 W+ x0 N# s& ^% V
  13.                 push    ax                              ; Save state, AH # i( o* f% k: t
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    - ?2 i2 Z! n- s! J6 @5 e2 c
  15.                 mov     ah, 09h ) d4 W5 ?! O/ B( g9 C
  16.                 int     21h                             ; Print message " |! E  r5 Q( M% c8 t1 z: q
  17.                 pop     ax                              ; retreve state % X0 y$ m7 \6 T7 S: w4 |: v

  18. ' j, o& A) E! V( {/ e
  19.                 mov     dx, offset msg_dis
    9 B9 D8 H, e. o5 U3 c  G" \" q% ^- V
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    ; g: k/ U' m" n  S" C3 I9 {
  21.                 jz      exit1 ) U3 t. H1 G$ r! ^
  22.                 mov     dx, offset msg_en ' [! Q. L" I' p; t" O0 J- s

  23. $ F+ |' W: h. H" C$ f
  24. exit1:          mov     ah, 09h
    % r2 ]+ X; |6 G9 d8 ], O
  25.                 ; DX already contains address of string
    : {# t7 n$ o5 H) o; @% [- ?2 w
  26.                 int     21h
    8 {' L, Z2 Y0 P* Y& S

  27. . j8 j, r8 N" k& c/ V
  28.                 mov     ax, 4C00h 4 g% a0 _* p( ]& D. D& ^% u
  29.                 int     21h
    & X+ \1 b- k6 s$ S6 q( r

  30. " v4 C. m5 f* ?0 ?1 x  a
  31. msg_ok         db      "OK", 13, 10, "A20 $" ) b8 ?0 q1 E# p8 N% Z
  32. msg_fail       db      "FAIL", 13, 10, "$" 4 E7 ]. M/ o9 T3 ?4 l. r! _( X- Y
  33. msg_en         db      "ENABLED", 13, 10, "$" ' y9 B( B- I- w, X5 M, b  h
  34. msg_dis        db      "DISABLED", 13, 10, "$"" E0 n6 u0 I0 b. v
  35. : D; U5 ?. U4 w' Z2 K

  36. % h" S. c% E0 a! d
  37. _GET_A20_STATE_: $ p$ k! I, l. D; W4 S) z
  38.                 call    A20Write                ; Wait till the input register is empty 3 M! y, k/ q+ T) }2 N) ^/ Y% }  x
  39.                 jz      exit2+1                 ; Bypas the reset int's 5 y8 X$ V. d; c4 y
  40.                 cli                             ; Disable ints so we'll get our value ) [& y9 Z2 F+ K3 D
  41. & j5 q- Y! z$ A# W/ D" n5 D8 a5 a$ B
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    , |0 l6 D' l% F* ^
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    ' V1 L6 a' J1 o
  44.                 call    A20Read                 ; Wait till the 8042 output register , Y$ U+ Y: l8 q, M1 X& N& ^
  45.                 jz      exit2                   ; has something in it's buffer   ]8 i( h: u2 b0 u
  46. 1 l2 i; z' \3 [* ?* y( \( f$ R) x
  47.                 in      al, 60h                 ; Get it
    2 H1 t0 {8 V' X5 D# |  p/ E& T' `4 l" ~# @
  48.                 mov     ah, al
    6 Y! @1 X( Z8 ]: @
  49.                 call    A20Write                ; Make sure the input register is empty 2 g% M( z0 f5 [6 i( w6 e2 S
  50.                 jz      exit2
    # l/ I/ i- a/ i! b; Y
  51. ; b% U. x1 Z  N% O/ ~+ J
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing . C' F' u) E, E% g! Y8 w
  53.                 out     64h, al
    $ F* y) Z$ T9 ~0 U: [! C# l
  54.                 call    A20Write
    4 Y5 I' m1 d8 d2 U' R' L4 [

  55. 5 b) e5 [$ ^1 a" q+ l0 b
  56. exit2:          sti + }7 ~* N4 p4 Q$ b& p
  57.                 ret9 I) y% w9 s0 ^, Q8 \# K; N; ~

  58. " W) ^% G' D0 s5 b
  59. - v/ P( q3 M6 t) O
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    - G, [3 ^7 u. {* v! s, p
  61. get1:           in      al, 64h                 ; Get KBC read status   b; D4 ?* {7 G; ^
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear * ~% Q: R* o" R! E, J
  63.                 jz      clear % Y3 D3 k2 z5 u2 d
  64.                 dec     cx
    % A) C4 s) h: b% l# M
  65.                 jz      exit3
    7 y# n: M) ]. p$ Z! ^
  66.                 jmp     SHORT get1
    ; U$ X1 y) g2 j
  67. clear:          inc     al                      ; Clear ZR
    8 L$ S9 w4 h. d. z' K. _! N7 `
  68. exit3:          ret
    . M3 F8 J$ Y5 t# \/ ]

  69. ! Y$ f. E- D' Q: v: a* r

  70. ; A; B: k3 Y4 J7 @) G- z) @2 T* v
  71. A20Read:        xor     cx, cx ; o) }# L! i0 F6 {) d' H
  72. get2:           in      al, 64h
    9 R* ^( [- V4 `. v' c
  73.                 test    al, 01                  ; If the 'output buffer' is full, has % Y2 f$ f) r8 a: Y' w  N/ P3 b0 c
  74.                 jnz     exit4                   ; something for me * ]4 \! R2 u" e9 l. }. q' w+ b- o0 l
  75.                 dec     cx
    : f( D3 b1 X1 d7 c3 Z; ~
  76.                 jnz     get2
    3 y: r3 y+ y7 ?3 N4 ]! R. X+ G* B
  77. exit4:          ret     + W/ W, D( r* R* N9 h& Y, ?
  78.                 $ i5 ]9 b" H, s- d
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
) X; J( q3 D: m9 X{        while(inp(0x64) & 2);        outp(0x64,0xd1);9 J+ b7 W8 V& \( D! b: Y. O
        while(inp(0x64) & 2);        outp(0x60,0xdf);
3 g: \' z: o$ I! s2 N8 E+ S        while(inp(0x64) & 2);        outp(0x64,0xff);6 X5 H- M3 Y% l: M/ y
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-19 21:03 , Processed in 0.243603 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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