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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    ! @8 b% c% T9 Z! c
  2. ;
    0 u7 H" `$ U3 b: r9 x$ l* P1 F3 A
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    $ m7 ~: g. e+ o- K
  4. ;       ml A20ON.asm " m- j) l# t. f5 \
  5. ; 9 \6 a6 |' [2 m6 z8 {
  6. .model tiny! ]. a- [5 Z4 x" T3 G9 F
  7. .code
      p% L, @" L5 _1 K5 }( W
  8. .486) C6 r% x) M$ _6 A# f0 v6 A
  9. .startup" x* A6 C, t5 @6 X" E% k- t
  10. ' m0 W0 S+ y/ Q2 k, b6 S) F0 ]& }
  11.                 mov     dx, offset msg_author
    6 E* r+ q* s: ^4 f7 e. j
  12.                 mov     ah, 09h% H0 m5 }5 m, _" R/ I2 M/ x0 w
  13.                 int     21h/ ?' n( S6 `3 A7 p5 R: F7 {0 Z* \: M
  14. # _, |9 O/ Y6 `8 ^" @# Y
  15.                 mov     dx, offset msg_fail 9 o# L: {! s7 g4 M! j
  16.                 call    A20_ENABLE
    4 a4 m7 D, z5 ?2 `
  17.                 jz      exit1
    3 ^3 P: N. o/ R& Q$ m0 Y
  18.                 mov     dx, offset msg_ok * D0 t$ e1 q- n, r& _6 S* l
  19. * [5 v9 ]) D! L/ {( }/ M6 Q+ e( j
  20. exit1:          mov     ah, 09h
    ; P! N2 A5 m( Q+ e3 w; r& H
  21.                 int     21h
    ' P7 r1 A& h/ M* V4 K
  22.                 mov     ax, 4C00h
    * T( K2 W2 ~! k  `- F2 f" u
  23.                 int     21h ) u" P- g, c( C1 C
  24.                 9 ~- c( e" G7 |" {
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,; J. f9 U+ _! e+ {) ^
  26.                         "2008-07-01",13, 10, "$"
    " p8 K: i+ B+ K/ h
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    4 ~3 I: H) @6 C7 x/ J$ L
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    : W6 P; |8 G* r4 t: `2 j

  29. . o$ V1 y5 O  b" M" R
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ( u8 E+ e3 T' u' D
  31. A20_ENABLE:
    ; I1 F! ?; i6 l4 U. p- k
  32.                 call    A20Write
    1 G/ R" ^- F$ ~; v" X( ^
  33.                 jz      exit_enable  g. ~: C# e" d/ u' }

  34. 3 s, C0 i# [* t$ ^$ @4 F' B
  35.                 cli                             ; Only need for reading value from KBC
    8 l( c4 @+ F$ L9 ]( c
  36.                 mov     al, 0D0h
    . `" A! M. {" d. E4 I' u
  37.                 out     64h, al $ G0 m. [' Z7 R$ }
  38.                 call    A20Read
    0 s9 L% L5 C! D% f- x4 f! c7 H, X8 B
  39.                 jz      enable_int 2 H# |6 a. K( y8 ?

  40. ( P  \& b9 R( Y  s
  41.                 in      al, 60h                 ; Get current status
    3 \! P7 U% ~- Q4 b! ]. `( X
  42.                 mov     ah, al
    1 h/ r3 ]. b  O  x2 W0 }' q" N
  43.                 call    A20Write 9 v$ C6 c; b8 U  S% h2 o
  44. enable_int:    sti
    ) ]) b4 U4 E% t: m" U9 b7 w
  45.                 jz      exit_enable
    & A1 U0 x8 ~! _2 q
  46. % N8 ?  c( ^; I, ~8 U
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    ) Y6 G! D- A" F# t) s# m1 h
  48.                 out     64h, al                 ; Out Put Port next
    3 ^; ^+ G8 [# C# v5 h
  49.                 call    A20Write
    ( r2 b# D+ t; f
  50.                 jz      exit_enable, w0 @5 Z  {. z) n/ N: |. u. ]
  51. 5 d* ^, g* D( k7 n) L# z3 `
  52.                 mov     al, ah
    , a4 z9 s1 ]% j, H; z7 N. Y2 \. I5 R
  53.                 or      al, 2                   ; Enable line A20
    5 d( d( y$ P3 q7 B
  54.                 out     60h, al
    ( f( k" G* i- r# p, @
  55.                 call    A20Write " k" M9 V! E5 I/ R, t% }; i" c: \
  56.                 jz      exit_enable9 C* Z5 C* a- h+ J' k/ x+ y
  57. 2 y0 ^5 e9 V# o% o' y
  58.                 mov     al, 0FFh                ; NOP % T: n2 S% H$ I) I4 b( U) o' A4 Q; U
  59.                 out     64h, al * G- {2 L. _2 C+ `. t/ M
  60.                 call    A20Write 6 b! n; V) L/ M8 s
  61. , m$ a, W- R+ G! N, A. L* g4 {
  62. exit_enable:          ret 0 S# S9 s1 p% m2 i2 P6 E

  63. . o7 s. ^. w9 V! j7 O& b
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    . {) Y0 i; |9 _, U9 S
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    8 m& z7 q" n. z! [6 C
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    * r  ~, X) M, N+ @+ ]
  67.                 jz      clear
    0 b! e, I+ n% \7 V: D
  68.                 dec     cx
    . Y1 [' ~/ O5 K0 E  X' a6 v
  69.                 jz      exit_write 9 U- x1 g( _! R! d) v9 i
  70.                 jmp     short get_wirte
    + x3 {( k& j2 R- B5 i* a" @
  71. clear:          inc     al                      ; Clear ZR 9 l8 E( G( e9 ?0 z$ b0 M$ I* R5 ~
  72. exit_write:     ret 6 [  M' M! W& V1 G, @+ m% c6 a

  73. ' b, U' w/ u  u% B+ }$ O3 J
  74. 2 F) [' U: O* w) E7 p
  75. A20Read:        xor     cx, cx " ~2 p* }5 }2 D$ t6 v, G) P/ @- W3 b. n
  76. get_read:       in      al, 64h
    # S* _; ]& x: Z3 V/ }% D$ b
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 2 L& N* f& G, E" j( g; G2 A
  78.                 jnz     exit4                   ; ... # V! p! x5 ?, b
  79.                 dec     cx - r: v% H; u6 ?1 L( a2 P- {
  80.                 jnz     get_read% }9 Z; r. T; ]1 `$ }( d
  81. exit4:          ret     6 c1 _6 a; Y0 D6 I: D
  82.                 , n1 M% {7 C8 t! I' E1 N$ [. m& U
  83. end
复制代码
  1. ;A200FF.ASM - S! y4 ?! D) M
  2. ; , c) Q7 j# _1 k, [: U" \
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " X" S* W! m# f+ H0 Z7 ~/ {/ G
  4. ;       ml A20ON.asm 6 f5 N2 H8 s. X
  5. ;
    ! i1 a* ], E7 D2 y
  6. .model tiny
    1 [' @& _% U4 Z: J
  7. .code1 i/ {, G2 z+ O
  8. .486$ W8 g$ V8 {- _8 k3 r$ H
  9. .startup; x2 v4 {4 |4 ^% t

  10. ) p! l7 ~8 K6 r5 c- w+ N: H0 D
  11.                 mov     dx, offset msg_author! Z6 d9 E( G5 ^: u8 K
  12.                 mov     ah, 09h
    9 @1 H& {8 i' m
  13.                 int     21h- R+ ~9 |  ~, M% j/ _7 w- Y* i! P

  14. - m* A- J" _  q$ |
  15.                 mov     dx, offset msg_fail 2 B: E$ e3 t; m5 G1 q0 p8 s
  16.                 call    A20_DISABLE
    , [" o( S# |5 e5 A
  17.                 jz      exit13 q4 }( h! w$ I
  18.                 mov     dx, offset msg_ok
    7 d$ @$ M/ J! b: {% _
  19. ' o. q! }  |9 `9 y
  20. exit1:          mov     ah, 09h 1 S, Q" W7 e6 n& w
  21.                 int     21h
    , [/ H; ]- c! I. [0 D; @
  22.                 mov     ax, 4C00h 4 ~; e, q5 ^4 y  A* ~1 j! I
  23.                 int     21h
    0 [5 v" j, v; `+ s; P8 }
  24.                
      J1 b- Q2 l& H
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    & ~8 s7 P3 @7 y5 {9 b9 {; e
  26.                         "2008-07-01",13, 10, "$" * q# R& _' h" H8 _0 K
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" , E5 F3 G- }; j4 E$ {
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    2 E1 C' e. h; Y
  29. $ s! r. g; c& J! L5 C& T
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------; U# z2 `" o2 [  g# g( `/ Z
  31. A20_DISABLE: 4 K6 m% j  E' s2 v5 Q8 v
  32.                 call    A20Write : |3 H, n$ _* d* }  t
  33.                 jz      exit_disable8 Y5 L! }0 m: e# E

  34. # w5 @% o+ D, j
  35.                 cli                             ; Only need for reading value from KBC
      R7 _4 m6 V+ j. l
  36.                 mov     al, 0D0h 3 [/ ~' |- V  r$ v5 s7 |9 k8 {% _
  37.                 out     64h, al 9 T# G+ s! W+ V* m8 X; R; @4 j
  38.                 call    A20Read
    9 m2 l8 ~( M& V7 m4 r& B1 r- X# ^# C# `
  39.                 jz      Disable_int
    5 R& h. ]1 J' p& a" k+ z: U3 |8 ~
  40. - W  ?# j1 q& g7 A
  41.                 in      al, 60h                 ; Get current status & J9 u, O" t0 \; `4 G" I# X
  42.                 mov     ah, al
    * o" d- [! @' L6 a6 N' J
  43.                 call    A20Write
    7 U" y4 N, m0 J- r+ O
  44. Disable_int:    sti : U! V7 o' J/ d  S
  45.                 jz      exit_disable
    $ y- o- J$ \/ [

  46. 9 v. `& ?% {  _/ |+ |7 a/ Q  C
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    0 K+ f& f' y# e0 n
  48.                 out     64h, al                 ; Out Put Port next 6 c: i+ k8 s0 w7 C* o8 P3 B3 n2 @
  49.                 call    A20Write
    ' \! G+ M' {$ C/ L
  50.                 jz      exit_disable2 J0 Y; X2 Q7 t8 \1 c" R& t2 [
  51. 5 x" @$ g) y+ }; p, A  q6 a
  52.                 mov     al, ah , G, {4 V3 O9 Q7 I* _
  53.                 and     al, not 2               ; Disable line A20 0 x( g& H/ P% K: @
  54.                 out     60h, al
    ( C. k% g$ u) F5 @9 S
  55.                 call    A20Write
    " x5 @, v+ h- z3 N+ S$ ]8 g
  56.                 jz      exit_disable# m. ~6 l3 _9 r; J/ M/ t
  57. % J. M! e) G' i$ F1 f
  58.                 mov     al, 0FFh                ; NOP 0 L  F1 ]' x* j$ c( a& E. m
  59.                 out     64h, al
    ; C- i4 t8 ]  r& ^  f( P
  60.                 call    A20Write
    $ R8 j0 L# U  z6 W; I2 P# e
  61. ! L  _# W9 g$ \" s4 E
  62. exit_disable:          ret
    & m2 V  Z+ D5 d  C$ g

  63. $ F7 j: L7 ^% \1 C$ I
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 2 l% E* |% j4 w. O* J3 {) K
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 8 y) I/ [$ c% \$ @5 u$ j, q
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    5 J- X4 h  }5 }; G7 R5 e( ]! Y
  67.                 jz      clear
    ( Q8 C. n# x' q% z0 P
  68.                 dec     cx
    0 d2 _5 Z" K. h& s6 f- c
  69.                 jz      exit_write
    ! P5 I0 Z' R0 y4 w4 y
  70.                 jmp     short get_wirte
    , o" B, m( `9 B- |* F
  71. clear:          inc     al                      ; Clear ZR
    8 Q  Q. i" ?1 O1 _2 B# S6 V
  72. exit_write:     ret
    - X4 Y. Y* e4 `3 M" I9 }$ s
  73. 5 Z. i# e5 @% w2 I( E( A$ s7 N

  74. ; I) y- }3 U# {$ l* T( i
  75. A20Read:        xor     cx, cx ' A4 X' |! Q: Q/ \9 N, e4 J( Y) d
  76. get_read:       in      al, 64h
    , G) Y7 W$ F" o- o
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ! a4 q0 v2 P% Q  ?6 z+ @; z
  78.                 jnz     exit4                   ; ...
    6 k3 d" t  C; o6 \- i& u$ w2 x
  79.                 dec     cx
    4 E: W* P9 h# K( T+ m
  80.                 jnz     get_read
    9 v" c- B$ l8 |! H4 G! y1 v/ f
  81. exit4:          ret     
    0 }+ k  v& [/ d, g
  82.                 ) h! n& T2 x, f# K7 j$ D8 l& X
  83. end
复制代码
  1. ;A20STATE.ASM
    1 a* o3 F8 M: a5 }  b- u- |' `
  2. ; ) Q! O  a5 S7 ]6 [
  3. ; Returns the status of the line A20 through the KBC
    ) Z/ W1 L3 y( b$ Q( y* U
  4. ;       programming by bini for debug. 2008-07-01# _" T4 D' J/ V" H
  5. ; * S+ j! }1 r2 k8 [
  6. .model tiny% R6 j! \7 ]/ g4 o2 u+ C8 X
  7. .code, ]) N  P# v* @  l
  8. .486
    2 P# I+ u0 k. N! d2 r( u
  9. .startup
    - G% \( ~. E& h$ ~/ S
  10.                 mov     dx, offset msg_fail ; {; K5 g$ b; x  B* P  T
  11.                 call    _GET_A20_STATE_; ?; }$ \5 D+ h9 n& o
  12.                 jz      exit1                           ;  was a problem" e' I* ?' W' \- j8 H
  13.                 push    ax                              ; Save state, AH ; P# h" A1 X+ i  e
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    7 P# L2 P9 E- F/ ~
  15.                 mov     ah, 09h $ e4 t- e+ S8 j& W
  16.                 int     21h                             ; Print message 1 f# m9 |6 C7 J" J+ o
  17.                 pop     ax                              ; retreve state 9 E3 l7 w2 A5 u+ ]0 u
  18.   ?  m/ }# M- @9 k, f3 z9 w
  19.                 mov     dx, offset msg_dis
    ( y) o8 A% |" _7 I+ T# J- W
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state . D  z5 b1 O' D0 n5 x" S8 }0 H( u
  21.                 jz      exit1   b* W0 W/ a  a5 |2 P
  22.                 mov     dx, offset msg_en ( Z* C, p! e6 N; U8 m( e, N
  23. % s8 d( j. G; d6 ?
  24. exit1:          mov     ah, 09h ( [. H! R6 d+ v
  25.                 ; DX already contains address of string : p  C7 y5 K4 E, y+ m$ P
  26.                 int     21h
    " G3 y, T9 w5 G+ v
  27. ; k$ }3 k: [$ k8 a* _! `# y
  28.                 mov     ax, 4C00h
      o5 H5 w2 b0 W% v1 I1 K, u, |
  29.                 int     21h * p: z+ t1 U4 h* N1 H: c  V

  30. 5 `  E& \/ X+ z; q
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    + |; B1 s, h# K$ |* e* B* M
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ' n$ P& _# o9 L2 q; k+ G, t% n( G
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ( k+ h& v2 w3 q" @
  34. msg_dis        db      "DISABLED", 13, 10, "$"' A! [& F1 v  S3 |
  35. . z- u; C" S4 b2 J. ?# i1 ]

  36. % A7 z: E- G9 G7 m
  37. _GET_A20_STATE_:
    7 e9 a  E9 Y% `: P1 l; n: R6 G. \
  38.                 call    A20Write                ; Wait till the input register is empty # {2 X: U8 [7 M+ o* O$ Q5 F
  39.                 jz      exit2+1                 ; Bypas the reset int's
    ) ]+ z% r1 O8 |
  40.                 cli                             ; Disable ints so we'll get our value / x4 S4 Y! V1 e* b0 ~( e
  41.   {) W% W4 w: R: R* \
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register $ u1 |4 n3 W, B7 ^! s0 {5 n
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    $ w/ T7 f. \* Z) Q+ z
  44.                 call    A20Read                 ; Wait till the 8042 output register
    : l3 }% }3 J+ ~' Z
  45.                 jz      exit2                   ; has something in it's buffer
    ) t3 A( I- F, C; D

  46. ' d1 @% H, @+ M( K2 H& \1 t, q
  47.                 in      al, 60h                 ; Get it
    + D& G0 o/ t, r2 B' _- K
  48.                 mov     ah, al
    9 M% ]8 T8 ~) n1 |
  49.                 call    A20Write                ; Make sure the input register is empty 6 A. n4 G, o/ f8 M* K  e
  50.                 jz      exit2
    ) e% k  @7 `0 U1 W; G. A9 t

  51.   W9 F# I% }+ J# l9 I
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    8 z4 ?7 Z9 @6 W! P4 l9 [
  53.                 out     64h, al ; \$ Y9 l  |$ w. _: M
  54.                 call    A20Write
    & I+ M) W( `1 x9 Q
  55. ! }- T0 u/ f% D* @
  56. exit2:          sti
    0 |8 @  R6 f% j5 h
  57.                 ret
    4 v8 T3 A+ i% @+ P) x" v8 B
  58. 1 J, q3 I* }8 r) v
  59. 9 C/ I) E0 K; l$ Z
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    4 U" [+ Y9 k9 U" D. ~
  61. get1:           in      al, 64h                 ; Get KBC read status
    1 Q$ D( V% H' p4 F3 B
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear 2 A/ G3 d3 w3 t7 r
  63.                 jz      clear
    ) {' a0 J! C& r1 ]7 {1 }) ^
  64.                 dec     cx 1 x  X0 L* B( }9 G& `2 H8 t
  65.                 jz      exit3 ) g: [# t  z5 D
  66.                 jmp     SHORT get1 , H1 ]: Z$ ^9 C; I* u# R
  67. clear:          inc     al                      ; Clear ZR
    $ M% R" s0 F1 X- ]
  68. exit3:          ret + l/ N& S/ T6 j8 y8 |' H2 z6 Z

  69. " o4 v5 |" b  N6 G( r3 [3 d# J

  70. ; }5 d6 ]4 ~; N1 v) a/ T) k
  71. A20Read:        xor     cx, cx % w8 @  j1 C- y  `' F9 B: L' k
  72. get2:           in      al, 64h 2 y8 h4 a( }( I+ A. }7 u
  73.                 test    al, 01                  ; If the 'output buffer' is full, has - H3 P! c6 u; c
  74.                 jnz     exit4                   ; something for me ; p: k2 A) i: y6 i
  75.                 dec     cx # _. r+ P  o  a/ i. B! P7 K# p
  76.                 jnz     get2: j5 K- I! Q0 N3 f& B
  77. exit4:          ret     
    9 Z3 a3 }8 N( }/ Z6 `" E& O
  78.                 $ Z) j  F- p  O1 ^; v
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
& \2 H$ J# V& K  U{        while(inp(0x64) & 2);        outp(0x64,0xd1);
! ~" U$ w- O% U, ~        while(inp(0x64) & 2);        outp(0x60,0xdf);) Q$ Q& [( x4 ]: |& D/ N: C
        while(inp(0x64) & 2);        outp(0x64,0xff);
4 C* A9 L) {; t+ S" w2 Q}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-1 09:14 , Processed in 0.128969 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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