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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    6 T7 i/ d: k' {4 K# x
  2. ;
    ; Z% G" A* c& @: i( `  x
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01  C1 m" l  j: M/ e# x7 j8 Y
  4. ;       ml A20ON.asm : x* A1 `" r3 J5 m; m. y& T
  5. ; ; F; q/ R0 S- _2 o
  6. .model tiny
    ) @) M, Z8 [0 f9 [. E! Y
  7. .code
    9 ^' Q, R) t2 W3 `* M- }$ E/ @
  8. .486
    5 j! M1 D% Z9 z* z2 a/ g0 p
  9. .startup
    $ Z7 T% w- E# F5 L4 V1 }0 K. o$ X

  10. 6 H' }, c) e# H
  11.                 mov     dx, offset msg_author
    $ i" H/ z! R" S) }4 D& j" W- g, x
  12.                 mov     ah, 09h+ ~! J0 O$ D  a# E4 B5 L
  13.                 int     21h
    / D0 P$ o- C- W( d- i+ p0 `

  14. 9 I. M+ t/ g3 Z
  15.                 mov     dx, offset msg_fail
    2 i  x6 J! G& E) _' J
  16.                 call    A20_ENABLE; X: M4 V9 w9 e- Z: |- O
  17.                 jz      exit1
    ) @) E% u# O" r0 v5 n
  18.                 mov     dx, offset msg_ok 9 X* X# A/ C# g& `
  19. 9 i( k! {, a8 s4 Y4 b3 R
  20. exit1:          mov     ah, 09h
    $ Q- j8 ?/ q: [( p6 Q
  21.                 int     21h
    4 u% C6 j: `1 L
  22.                 mov     ax, 4C00h
    : Z9 p: C3 O1 g. M
  23.                 int     21h
    + F' ?: \& ]- [% L4 A
  24.                 7 r$ l! P4 x3 X+ h
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    / B8 {; o2 f4 X. s: p: B
  26.                         "2008-07-01",13, 10, "$"
      l: s6 Y8 ~6 S2 h
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 8 e  T7 F% u7 |
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" " z' H6 J/ K* e
  29. 5 K. a1 x" g$ \7 k+ s$ p4 @) ?$ e; }/ k
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------+ D4 m8 ~* _( H; }( y
  31. A20_ENABLE: " c. ]" c+ `0 |; f5 X& Z
  32.                 call    A20Write : `. l) S- v0 [
  33.                 jz      exit_enable) w# {4 j" w1 P8 t& N7 Y. \

  34. % c1 K4 O: U" e  [1 ]
  35.                 cli                             ; Only need for reading value from KBC
    7 L" C8 w- y+ B5 ^- t) h+ u
  36.                 mov     al, 0D0h
    ( B5 j) V% z  O2 t7 S. h, ~# s
  37.                 out     64h, al
    ; h' g6 Q! A/ n3 V, b3 r
  38.                 call    A20Read 6 X1 d7 ~( h4 ~! A% ~1 j" G. v& Q9 N
  39.                 jz      enable_int 9 e1 ~0 _  x- w

  40. # e* f- u! m) Y, H: `
  41.                 in      al, 60h                 ; Get current status % P6 M2 ^1 g1 U& h0 x1 t
  42.                 mov     ah, al
    6 o0 M. t4 L1 m# `
  43.                 call    A20Write ) x3 U& ^( {" ^9 v
  44. enable_int:    sti ; ?: a0 Z$ f; }0 Y4 y
  45.                 jz      exit_enable4 J' c, l, \# d6 x& o: [

  46. ) x! _, u8 D- ^+ w2 Q' D
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ; }+ S0 T4 S% j: j9 w$ Q! X5 \
  48.                 out     64h, al                 ; Out Put Port next ' g5 c) h" [, s, Q3 X, S
  49.                 call    A20Write
    " s$ f7 u8 I% L6 U
  50.                 jz      exit_enable+ H/ d8 ]# P: d' b+ D

  51. ' r$ Y5 Z  d  q! N% ]
  52.                 mov     al, ah
    # }  Z. b" A" q' J8 i- z% e7 |
  53.                 or      al, 2                   ; Enable line A20
    2 [3 z; U% M" u# C  K& ]
  54.                 out     60h, al 9 l( V* [9 k8 f8 l: d
  55.                 call    A20Write
    * T$ c6 H! b- P" k* V0 y
  56.                 jz      exit_enable
    * k2 a: X. [/ t0 ?6 T3 r" K+ ~- u& _
  57. : o+ x+ b. a: s
  58.                 mov     al, 0FFh                ; NOP
    & t5 U/ A# a' f# K; J
  59.                 out     64h, al
    4 ^5 D& k7 i$ U" t
  60.                 call    A20Write ' z/ x. d( L; e9 d
  61. 6 W& {0 Z* \2 O0 \. a
  62. exit_enable:          ret
    $ N2 K7 p, M) F
  63. . O& R8 Q" O: e" e
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - R" ~: C" S( k9 U1 q- V- H
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ( o: J3 {! M; J$ u& a5 U
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    " Z" y* P6 x8 e3 W
  67.                 jz      clear
    $ x  Y; h) j. ~" \* l3 e
  68.                 dec     cx 0 ]) T! f2 m9 N( F4 b, X  c+ u
  69.                 jz      exit_write
    + G  M% m4 |+ }$ _
  70.                 jmp     short get_wirte
    4 h- t$ s4 [& s/ D( c4 J2 A
  71. clear:          inc     al                      ; Clear ZR ' }" p, c7 P8 O( h- ?. Q3 e
  72. exit_write:     ret
    - ]; _& q3 ?3 i6 s; \! k
  73. ' q0 y) I" V8 l1 w0 \# r5 |

  74. 4 d) h, j  X  ?% y( D# w
  75. A20Read:        xor     cx, cx
    # H' m  v8 D! }# ~4 q- j" o, Q
  76. get_read:       in      al, 64h
    3 b6 k1 F0 P9 G6 S" c$ a
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ( s$ y( l! W( H2 r
  78.                 jnz     exit4                   ; ...
    - l1 h, B* A7 {- {, K' e
  79.                 dec     cx
    . D. A9 W5 q. H  L  v
  80.                 jnz     get_read
    $ d  O2 V! E) A! T- j
  81. exit4:          ret     & ^7 C7 s! V6 }, `- K5 ~
  82.                
    9 t  a+ ^, x$ T$ R
  83. end
复制代码
  1. ;A200FF.ASM
    6 E! p9 v/ H* I# p( q1 ?: M) ^$ d2 B
  2. ; ; ~1 u  A7 [& }7 `
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01% A% N' R1 x1 C* \/ P
  4. ;       ml A20ON.asm
      s6 ]* G6 s( n- k8 ~0 Y
  5. ;
    4 ~9 h/ e# a6 _% J4 b% A" t
  6. .model tiny9 y$ d  A2 v- R; [' |$ q" A" _
  7. .code6 l6 {9 J& W3 H3 u7 j7 i. {
  8. .486
    # v/ l! S' [3 H; |# M2 }4 C% r; l) y
  9. .startup0 A* S, y0 S( M) ?1 w

  10. ' {& r7 e4 z+ p( o
  11.                 mov     dx, offset msg_author
    ( z+ _3 j" |3 G; @$ z6 C
  12.                 mov     ah, 09h) ?0 l, I2 q& V, G( s3 }
  13.                 int     21h
    * J* c4 ~* Y) x8 G. R

  14. 6 _$ g  Z7 P# @/ B! u
  15.                 mov     dx, offset msg_fail ; g4 X5 P; F" X5 L3 @
  16.                 call    A20_DISABLE2 P' N  ?1 V1 {, l4 a3 p3 ^' F
  17.                 jz      exit1; M3 q( m4 B2 m0 o6 `
  18.                 mov     dx, offset msg_ok
    # w) ]8 o, f" c: b
  19. 5 M  I# d' w1 @+ L, n. R
  20. exit1:          mov     ah, 09h 2 w, y8 c' ^4 n0 Y4 y; L4 x$ ]# m* \
  21.                 int     21h
    + O- I% A& V" b- P7 k
  22.                 mov     ax, 4C00h # n" {- k% a1 _. M" p: F9 L
  23.                 int     21h
    ; l0 P2 M/ ^0 Y" t  U
  24.                
    4 D0 N) x9 V1 L/ ^# i
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    6 l7 d, H& y3 N; T6 U, ]3 w
  26.                         "2008-07-01",13, 10, "$"
    3 S( N& M2 {% f
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    # N" J2 N6 M" k+ V
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    $ M5 ^- f- h8 X, S4 G/ j
  29. - H3 l' @7 R0 M
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    7 F- |* N; o& l  P6 `( x
  31. A20_DISABLE: 0 X4 G5 \* {+ U$ Y6 w$ K
  32.                 call    A20Write
    4 v* X% E3 R. Z' V
  33.                 jz      exit_disable- ~: S6 [7 B* ]2 f( l. N

  34. . K  C8 S& c/ W% b0 ^! P7 f& w
  35.                 cli                             ; Only need for reading value from KBC ' ^, E9 f" b  G) b* G7 L  [
  36.                 mov     al, 0D0h % o" V9 y6 Q/ r: Z) h
  37.                 out     64h, al
    ; O. f* R$ U% T* w
  38.                 call    A20Read
    * h0 t6 L) ?' }6 s7 @- f" g; A6 E
  39.                 jz      Disable_int ( y; ^( T/ y" C+ p, x) [

  40. ; Q4 {1 S2 n& v, {
  41.                 in      al, 60h                 ; Get current status
    " G6 W4 `5 \7 ~  I( y( W
  42.                 mov     ah, al 6 M* g% v1 c  D5 p0 N  L% Q
  43.                 call    A20Write
    4 W: u2 n' |, n# |( h4 R! d2 b8 g
  44. Disable_int:    sti
    5 J) j! ~) z* x" t/ P1 ^; w
  45.                 jz      exit_disable
    $ W8 L- @7 n& A; M5 @& R5 {1 e
  46. 5 ~  u8 e, W& S6 ^; Z) `
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ; r8 V5 ~) u: i
  48.                 out     64h, al                 ; Out Put Port next ' t" I( X* e& J4 ~5 \  \$ i
  49.                 call    A20Write
    * O7 k9 O% K+ u' ]8 B
  50.                 jz      exit_disable
    ; {5 ~5 e8 @- j* g# K- S/ y8 i
  51. ; ?! Q. r% o" D
  52.                 mov     al, ah + P! }; \. p; v; j0 N
  53.                 and     al, not 2               ; Disable line A20
    * n% ]* w/ `2 `
  54.                 out     60h, al 3 }5 A! |+ V0 E' V, ]2 C" d
  55.                 call    A20Write * R# m1 v9 N2 Z  [2 P- F3 B
  56.                 jz      exit_disable
    0 I8 x5 }6 P; c3 n4 y( A0 h

  57. % `1 W0 V4 `: s8 z
  58.                 mov     al, 0FFh                ; NOP ; Q% N! F$ F" g8 B
  59.                 out     64h, al
    0 j' F$ O/ K+ b6 u* ^
  60.                 call    A20Write 1 v( P$ E5 W: d, a. g8 H
  61. & E8 C, Z& p# M# ?8 }$ R4 {! r
  62. exit_disable:          ret
    + q8 N$ q/ @$ ^( {; z$ ]7 }

  63. 7 t. n, U2 n0 S  A3 s6 O
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 1 m( e( N+ h( E8 U
  65. get_wirte:      in      al, 64h                 ; Get KBC read status : X- C# k2 E$ q2 A
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear + t" z0 W' S/ E2 L! u/ `
  67.                 jz      clear , _4 P8 v5 ]8 L) t( Y
  68.                 dec     cx 7 D; \. `" H. S( x9 G! C
  69.                 jz      exit_write
    8 o3 M& ?: ]* J- r  [4 ?2 ~- ]
  70.                 jmp     short get_wirte
    + \5 d' A6 d5 q# \/ u
  71. clear:          inc     al                      ; Clear ZR
    . e$ j: P3 r( {  E
  72. exit_write:     ret
      n- |6 v$ `( S: y. I6 F5 m# i" U

  73. + l9 W! `2 T% S/ a: E) o
  74. 0 k3 T4 \6 N. T) A3 k% ^8 `
  75. A20Read:        xor     cx, cx
    ( o3 x- ]! P: }9 b* X
  76. get_read:       in      al, 64h - F( N5 P% S$ d  A: b
  77.                 test    al, 01                  ; If the 'output buffer' is full, has , s  @/ C$ s; o9 J( C
  78.                 jnz     exit4                   ; ... ( ^# V0 K" I2 x0 j* c8 N1 R" G5 v* s
  79.                 dec     cx 3 P$ u9 H! P, V2 Y
  80.                 jnz     get_read
    5 ~2 Z6 a" u5 B0 y* y+ U5 h8 v% W- n/ C
  81. exit4:          ret     
    8 `0 D2 D0 }  k' x  `
  82.                
    1 V+ v0 _* i; i  I$ N
  83. end
复制代码
  1. ;A20STATE.ASM : `- R+ ]5 ^3 t$ ]
  2. ;
    / X' W  y5 r/ f! ?( e: }2 C3 V
  3. ; Returns the status of the line A20 through the KBC # g9 Z) O  M+ y+ n1 U+ C
  4. ;       programming by bini for debug. 2008-07-015 l/ O1 ?, \0 d) F  ?4 D
  5. ; " x# A% b3 b8 `& |1 c  ^( U
  6. .model tiny6 w0 V! w6 d! X
  7. .code3 ]/ m; s6 ]* D( [+ T! d
  8. .486
    6 D2 n$ E# {( Y
  9. .startup
    % H, T# U" }/ v
  10.                 mov     dx, offset msg_fail 7 n& C, c$ u. u
  11.                 call    _GET_A20_STATE_
    9 S  d9 D+ y  v( I- M% o# i( o& D
  12.                 jz      exit1                           ;  was a problem/ S7 ?4 r9 w' X6 r5 h
  13.                 push    ax                              ; Save state, AH , ^1 B) {! I, H6 R
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem + _4 b5 [1 P& s  X+ O
  15.                 mov     ah, 09h - q/ d  M8 c" I1 G' X
  16.                 int     21h                             ; Print message 6 N# `) z) }6 W. ]
  17.                 pop     ax                              ; retreve state : H! V) {* ?# E
  18. 9 a6 K* ~. X+ m0 {$ x
  19.                 mov     dx, offset msg_dis
    ; W* P. y, u5 S* [: K' Q
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    " [" k% u# N/ L4 d
  21.                 jz      exit1 4 s. g8 w& f; Y" b7 V/ O& U8 j- D
  22.                 mov     dx, offset msg_en
    4 N# O0 A$ Z: Y: d5 X% ]  Y

  23. 0 z! n$ }# W4 U8 U+ f
  24. exit1:          mov     ah, 09h ! F$ y% i, Z8 W; F0 B
  25.                 ; DX already contains address of string
    3 T! g9 l9 D% h' T' I' l7 o# J
  26.                 int     21h
    + M& Y3 J4 \  }- Z' [  i" m

  27. 5 ]7 J* A7 [  O6 k
  28.                 mov     ax, 4C00h   ~2 I' c3 ~7 o9 C6 h
  29.                 int     21h + P) P1 v: H2 k( |# s( ^* D
  30. 9 Y0 `/ |5 h$ d6 e
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    * i# R7 ]$ j! s! @4 H
  32. msg_fail       db      "FAIL", 13, 10, "$" 0 I" _5 H: h0 g& Q& ~  B( P
  33. msg_en         db      "ENABLED", 13, 10, "$" / n4 U8 `( V: Z/ p
  34. msg_dis        db      "DISABLED", 13, 10, "$"$ ^) [5 D3 y2 x3 \$ a* k( r

  35. : z0 z1 }8 f5 O7 B( ]

  36. ' S# P& {' O; P$ v0 s& o. P
  37. _GET_A20_STATE_: $ J' N7 y% l1 B$ B' O! R! s
  38.                 call    A20Write                ; Wait till the input register is empty ) \  ?) \2 j6 V4 ^
  39.                 jz      exit2+1                 ; Bypas the reset int's 3 l* N0 W& C5 \' p/ Z# n: ~5 j, c
  40.                 cli                             ; Disable ints so we'll get our value
    9 y0 I: Q; P( n- j* Q* K

  41. 1 Z# _7 l, R' L0 C, \; k  w; C0 R
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register , n0 o6 f0 T" k/ y' V' {9 |
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port # L5 T8 v: {' X0 H, l# c9 C4 F
  44.                 call    A20Read                 ; Wait till the 8042 output register 9 d6 B; ?8 s. [* T- u% ~
  45.                 jz      exit2                   ; has something in it's buffer 0 N; G2 G) l2 `3 s0 X% T2 @, Y

  46. : D2 u3 I& r' e" n' @5 s: E; c
  47.                 in      al, 60h                 ; Get it 0 N4 N* f! z; j7 j
  48.                 mov     ah, al
    7 J6 K4 J/ V2 @4 V, ]2 ^! A
  49.                 call    A20Write                ; Make sure the input register is empty
    3 w7 v$ O0 T( _4 H3 F
  50.                 jz      exit2 8 a, c4 h2 ~% u

  51. 2 |' ?7 u+ P0 h1 `1 N0 `- _) A
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 3 n* O$ Z* y$ S) o
  53.                 out     64h, al
    4 z5 n& R/ J- G5 {& m: I
  54.                 call    A20Write
    1 x4 w, L) w  t2 ~9 p4 R
  55. * z2 v- k! U8 p
  56. exit2:          sti
    * B, c) \3 D3 ]) r3 K' D
  57.                 ret
    " J9 Q1 F/ a  F) P! ~

  58. 7 D0 ~# c7 I$ X; B+ g+ N
  59. % s! e; `' ?, t5 |: V
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    1 t! s( o9 c! {- V/ g
  61. get1:           in      al, 64h                 ; Get KBC read status
    * c* j" s$ e! I. W
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear 3 o; P9 a! T/ Z+ m9 J
  63.                 jz      clear 8 S4 x& k7 c6 [1 p7 @  B/ T
  64.                 dec     cx
    ; |; [& P+ J" N' @1 A, W
  65.                 jz      exit3
    % x6 `: S1 w7 c  c) Y- _+ ?+ B- J
  66.                 jmp     SHORT get1
    ( V  a& n: t; Y' P' Y
  67. clear:          inc     al                      ; Clear ZR
    * C. T) W% o. Z2 M& K
  68. exit3:          ret + t8 ]# ~' t" l! L% ~  E8 \- u) i

  69.   A3 P5 S4 l7 Z6 y

  70. ) Q$ A) @% n: `8 C! j
  71. A20Read:        xor     cx, cx
    - G' T4 X  ?# u6 y" D
  72. get2:           in      al, 64h ; |% H3 _9 o6 l
  73.                 test    al, 01                  ; If the 'output buffer' is full, has : i9 ~- D) M3 z' L0 u
  74.                 jnz     exit4                   ; something for me
    , ]8 X& k5 f( [/ h
  75.                 dec     cx
    : [( H: {" }; X. u/ W8 [& _
  76.                 jnz     get2
    1 U1 a; |9 t) t$ u- |" [7 [6 F& |* k
  77. exit4:          ret     6 E0 ]1 b$ F4 f0 S6 p/ T. }
  78.                 ' u" d' w8 i0 e) t( I3 M5 w+ j
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
: K7 d# {7 i$ `: |. U{        while(inp(0x64) & 2);        outp(0x64,0xd1);- ]; e6 ]+ [$ y
        while(inp(0x64) & 2);        outp(0x60,0xdf);; @, B: I9 ]8 X- ]% F* U" p
        while(inp(0x64) & 2);        outp(0x64,0xff);
0 r$ L7 y& c9 t7 v6 _/ u}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-4 19:00 , Processed in 0.104544 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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