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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    5 b5 a7 x0 z9 l) [1 F& H
  2. ;
    - C5 e* r) n9 q; X3 B; s% E
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01" H) u' z- `9 _( M. H/ k# K
  4. ;       ml A20ON.asm
    1 P/ S# M' {) l0 _+ F5 f: L7 j
  5. ;   S9 @  z1 B. H" P9 N* k! Y* N0 W% q
  6. .model tiny! b, ]) q- f! B& K/ \! M0 L
  7. .code8 r# ~! d4 y; _  N# ~" v0 z
  8. .486
    + n  O; l- K- f, s0 T
  9. .startup
    * o7 K0 I  c! D9 F  D8 N. ]& V9 y
  10. 7 m  S# y0 |  L- m5 a
  11.                 mov     dx, offset msg_author
    . i: n7 C- ^' F
  12.                 mov     ah, 09h
    : P6 O- P7 @0 J. K
  13.                 int     21h1 s' @, s5 H- X/ S3 `' Y9 S: ]

  14. . j, S6 |& `8 Y0 @. X& N; f  r: v9 i
  15.                 mov     dx, offset msg_fail 9 w$ v: N3 u9 O2 T! o8 G6 S
  16.                 call    A20_ENABLE
    6 O% V4 H- p: ?- D
  17.                 jz      exit14 N; c* k( D( ?& @8 j3 c- s
  18.                 mov     dx, offset msg_ok
    ' D2 I8 N, ?( M& _

  19. & s6 ~6 r& \: x" I
  20. exit1:          mov     ah, 09h
    5 U9 X2 F: W& o  B
  21.                 int     21h + w0 j$ J% Y; Y
  22.                 mov     ax, 4C00h 7 F* F6 l/ ]8 t9 Z3 y
  23.                 int     21h 5 g1 P, U, l& W, x; f; {. T
  24.                 - Y& ]( I5 L# f
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    # ]' X/ {+ ]% E" W. s
  26.                         "2008-07-01",13, 10, "$" & i$ \& c, K& r" G- M
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    7 f9 o7 I) x5 ?! r" A% F: v8 s2 o
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" . O- L2 ~( L2 C: b2 S0 O8 l& ^: l3 s
  29. : i& J4 b1 W7 J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------+ @. \/ o+ u3 I
  31. A20_ENABLE: # Q+ {6 M  N+ f3 ?# O9 X; r2 u! ?4 X: f
  32.                 call    A20Write
    " Z5 Q6 v+ p  [1 T0 G. \
  33.                 jz      exit_enable- o+ {* d1 g7 m

  34. ' @/ z0 A, B0 Y' b7 y# t
  35.                 cli                             ; Only need for reading value from KBC ) A! b3 Q: q1 a; `+ X  v/ j
  36.                 mov     al, 0D0h ! ^2 B4 s# v9 k- }( J$ U( L
  37.                 out     64h, al
    - {; K, L; d$ ~+ Z  M% t; B
  38.                 call    A20Read
    , e. K! V6 C( k( N1 y
  39.                 jz      enable_int
    * m: v- }9 t4 `3 H* H6 ]

  40. # M$ A) B4 r. X( H; o3 [) ?7 f
  41.                 in      al, 60h                 ; Get current status
    7 u' O7 D$ |8 q2 V2 F! c# W
  42.                 mov     ah, al
    6 y+ J8 t! R+ R& Q) Y. V# r6 d% O) \
  43.                 call    A20Write
    5 j+ ~  B$ c( ?8 u2 ^4 S8 H
  44. enable_int:    sti
    & K( W2 s7 k$ U; b& _! e
  45.                 jz      exit_enable  Y8 r6 x2 V' B8 Z5 p' V
  46. ( h; ^, p% A! l$ {* A
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    * o/ E, _6 o8 r  L: q7 X' d7 k" c
  48.                 out     64h, al                 ; Out Put Port next ; q4 u) V- E+ A1 I8 G- P' S
  49.                 call    A20Write ; \; {) m$ Q! s: r# ]" r; e9 ?
  50.                 jz      exit_enable
    ) L+ m( \, J  m; \3 Z: i0 ^# R/ O9 J: @

  51. 5 O0 H0 Y' S* e
  52.                 mov     al, ah
    / Y( ]5 t% j  C4 o3 C1 ?% \
  53.                 or      al, 2                   ; Enable line A20
    ( t; s1 Q6 P4 q. ?/ G
  54.                 out     60h, al
    # W) Q& o* Y7 j/ J6 n7 q8 p4 {
  55.                 call    A20Write 1 ]8 C+ s" T5 R$ x8 r) F* @. [
  56.                 jz      exit_enable
    $ W  g( l) i% ~2 @3 }3 X6 y
  57. * q5 C) Y  r) B8 ?5 U; ?4 _! \
  58.                 mov     al, 0FFh                ; NOP
    - [+ b% T: \5 O8 d
  59.                 out     64h, al 7 n# L! O: \, N
  60.                 call    A20Write % F$ ?2 h  T7 w+ b, h, c$ v% |
  61. : h. Y1 D, h1 L: j1 Y1 f( ^
  62. exit_enable:          ret 7 x0 i% S: P. g" s6 w( N- @' B2 ?7 i

  63. 0 I6 w0 |/ z9 y' K" }. E: H
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    * ^* R+ `. h% A3 e! I8 L
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ) Z/ x$ U/ f+ `5 C( ?
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    4 Q/ S# K, A7 h, b
  67.                 jz      clear
    4 l* R  |& H3 w
  68.                 dec     cx
    9 W& f2 t" Q% f
  69.                 jz      exit_write
    . u. S% ~4 I+ ?3 r! x* t5 ~
  70.                 jmp     short get_wirte
    + t( P1 @7 ?9 A% e* X2 f5 i: t
  71. clear:          inc     al                      ; Clear ZR 5 o* I, f+ m: J" u) b5 Z3 P4 g4 G
  72. exit_write:     ret & C- ~1 n: a4 W$ Z5 Y) j  _

  73. 7 b1 s  ?  V' Q. I1 n
  74. . U; h% [- D& Q8 q5 C
  75. A20Read:        xor     cx, cx
    + N1 b4 U( }) A9 Z" A) T% G
  76. get_read:       in      al, 64h
    1 C; F, z  t( j: k) F  S8 P' S
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 3 Q2 @. z* M/ m, N0 i- Z2 ~" l; z; t
  78.                 jnz     exit4                   ; ...
    ' [3 i5 I1 E$ U2 j5 _0 l: j' P
  79.                 dec     cx " \$ E) B- D; {5 \/ K& x0 H) Z
  80.                 jnz     get_read. E3 l: T% N8 ?/ g
  81. exit4:          ret     
    7 j5 j4 Q0 d/ R
  82.                 ; u+ i; U1 V# ^( K' l& A0 \
  83. end
复制代码
  1. ;A200FF.ASM
    " s$ {+ d* {$ s8 j# K7 E4 @
  2. ;
    $ C  q5 B- b' j5 d7 W, ]# H
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    6 I1 z  L7 x& G/ y' e
  4. ;       ml A20ON.asm
    ) ?) M1 y  z' e, V
  5. ; - E+ K* U  n7 g; p  e  y0 O' v8 N
  6. .model tiny+ z4 x& V0 J% v6 d# l& ^9 z
  7. .code
    / R; G" r7 F: k* |" O" o( x* m( }
  8. .486
    2 ?9 S+ @" T3 A8 _0 r' i# l
  9. .startup
    3 ^# X, r2 Q. n1 w6 \+ [9 X- _
  10. ! Z. g0 s% I8 r6 @0 _9 h
  11.                 mov     dx, offset msg_author
    # w' w2 p, X4 p7 t/ E
  12.                 mov     ah, 09h) N* S% N/ `- S, `) E0 o  K
  13.                 int     21h& i; ~/ y; g$ W  P

  14. . ^, k9 S* a6 W+ J2 p
  15.                 mov     dx, offset msg_fail 1 e: g- r) h" s& D2 {
  16.                 call    A20_DISABLE  Z8 ~- O- u# b% R+ H* `
  17.                 jz      exit1! o' Y3 @$ e! f: j5 M4 I% c
  18.                 mov     dx, offset msg_ok
    * Y, e4 r& s6 T6 t
  19. , U- P, g5 Q1 a; T( I5 {
  20. exit1:          mov     ah, 09h : {) [. I. e* M2 |/ z
  21.                 int     21h : p2 B  M- E; n
  22.                 mov     ax, 4C00h
    5 D4 K7 n9 N; B- h& h4 l& ]
  23.                 int     21h 0 s$ N7 f. e6 f& U' Z' l8 i
  24.                
    8 E/ A* ~6 c* A1 i& |' Z( ?' |: }
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10," c, t2 I2 h( l
  26.                         "2008-07-01",13, 10, "$"
    6 ?, S: |" \5 f' A
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    ; a  E: w& S3 N8 W: }
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" + u# I5 d  m5 j9 g2 ?! z( Z

  29. . @. X1 W3 d' `  b5 C* M. D
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    $ ]. {7 k( a7 I+ I' o& F
  31. A20_DISABLE: & H. Y) c: ]. [% |& @/ g1 I/ k
  32.                 call    A20Write 3 P$ k% z. i( [- j/ z  Z9 ]' {- D
  33.                 jz      exit_disable
    6 _' U& d( l% v4 ~6 }
  34. : A- f  J' H: b: k9 r' H# ]7 ?
  35.                 cli                             ; Only need for reading value from KBC
    * B) n0 G* j9 |2 J7 i' B6 e
  36.                 mov     al, 0D0h
    8 d  y7 A2 e: `' R6 L1 q. p& o
  37.                 out     64h, al / t: x% a& p% I7 z
  38.                 call    A20Read
    % i/ `) A- J5 p4 A
  39.                 jz      Disable_int   E: K% y8 P% @  L

  40. $ ~- g  |, v7 [9 w8 d6 r
  41.                 in      al, 60h                 ; Get current status
    " [# G" V9 a9 ]( l8 d0 r9 M
  42.                 mov     ah, al
    4 f5 p; G1 p; }/ C& g" v
  43.                 call    A20Write
    , q( L) D, \5 f# h% D9 u7 E
  44. Disable_int:    sti
    3 O- F, }/ Y. n3 @
  45.                 jz      exit_disable% [7 U" S/ _, o" k  H
  46. - a* q1 }+ l: Z' S1 M2 _+ e( O, z
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 5 v5 E9 ^4 d8 n! z$ R+ X( Q
  48.                 out     64h, al                 ; Out Put Port next 6 g! ~* ^' \0 _  q+ I! J
  49.                 call    A20Write # V* }$ G' t- F& q! F+ E, h
  50.                 jz      exit_disable: A. y2 g8 m/ u" w) I* T" e" B2 Z
  51.   Q3 h+ y# h5 H" L# ^
  52.                 mov     al, ah - [% I( D$ m/ T
  53.                 and     al, not 2               ; Disable line A20
    ; D3 U- r5 ]2 l# Z9 u
  54.                 out     60h, al
    . A$ x& b; q+ G. [: y( I
  55.                 call    A20Write 6 f' l$ F- ]2 x. E* p
  56.                 jz      exit_disable
      s6 i4 y7 `  l7 B7 V# a5 f! V

  57. % p9 T1 n& t: l, E" M
  58.                 mov     al, 0FFh                ; NOP
    4 |( P( M) O" `7 q3 n0 q
  59.                 out     64h, al # z' A* L% ^8 t' Q' a8 C. @
  60.                 call    A20Write
    6 R2 ^9 S- h/ h
  61. 2 a) l9 u3 N. f% x
  62. exit_disable:          ret
    * i7 U& ]5 j( D: c
  63. ' Q& N- [4 \( @4 S. ^- ~+ ]
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - B  S( l( Q& e) Q7 E
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    / f0 B% j1 g- H7 c' s) P
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear   g! }' z8 `) J5 q9 O
  67.                 jz      clear
    ; U4 {$ v1 t2 j$ Q- P* ^( U' ?
  68.                 dec     cx
    # t7 h6 L1 n7 q& y* e- l% S" u% E3 w
  69.                 jz      exit_write ) d9 {7 L. ?2 v% C% |% m4 i6 N
  70.                 jmp     short get_wirte 9 @7 d7 J' `6 i- T9 Q
  71. clear:          inc     al                      ; Clear ZR
    + |+ `  z' u5 @$ W0 r
  72. exit_write:     ret 4 e; _9 P2 U% `8 ~9 P9 O3 f/ M

  73. 6 N: N6 i" y6 O+ N: A4 g
  74. 8 k8 a$ y$ X, V0 G* a
  75. A20Read:        xor     cx, cx % r2 o7 R8 N3 g: u2 ^8 F4 F- H+ `
  76. get_read:       in      al, 64h 6 y4 G% B" r6 E) e- ?
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 1 f, H$ T7 I; ?: t4 |; [8 x
  78.                 jnz     exit4                   ; ...
    , K1 o5 [- }% i. j) b
  79.                 dec     cx
    2 X7 k7 |7 a, n5 i9 K
  80.                 jnz     get_read
    8 M! E  G! d& V0 l& L
  81. exit4:          ret     
    * W) B8 p, W! M- e# a& X% u
  82.                
    9 [' n2 |" n, b# G8 o) o. |
  83. end
复制代码
  1. ;A20STATE.ASM
    # X8 g7 _9 C& h7 t( n
  2. ; 3 `3 {$ }/ o7 h; U
  3. ; Returns the status of the line A20 through the KBC
    & R  j0 M# R! Q- y6 o( B
  4. ;       programming by bini for debug. 2008-07-01; r4 H3 B7 d: y2 L" F/ z
  5. ;
    * `9 _* {0 l5 k, u: x+ g  |
  6. .model tiny) T( |' @; `* W# |: B+ e
  7. .code
    2 q: R9 x+ v; M0 j& n
  8. .486
    / d2 N( c# X. @) L' I
  9. .startup( E; n" A- a/ ^  B
  10.                 mov     dx, offset msg_fail " t; W1 w, z2 y) C. P0 Q# W, e5 `
  11.                 call    _GET_A20_STATE_% c. P1 \. X7 t5 d4 u+ j
  12.                 jz      exit1                           ;  was a problem% ^% r! l7 a7 H1 E0 z7 c
  13.                 push    ax                              ; Save state, AH   ]% u2 k. r0 `' C
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    0 j& k' ^% J! |/ v& N5 s
  15.                 mov     ah, 09h
      w; h) \( K  P( T- l2 t8 Q" o
  16.                 int     21h                             ; Print message
    0 \+ R' T6 w1 \4 _. ^1 l
  17.                 pop     ax                              ; retreve state " h+ u- `0 m9 N# \
  18. & C& u$ x' l9 g% d" D
  19.                 mov     dx, offset msg_dis
    $ Z+ ~- B4 |0 n: l3 F: [3 B0 i
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 0 P1 d0 y! Z3 w5 K% U9 Q
  21.                 jz      exit1
    : a* ^3 ~' Q+ l+ s
  22.                 mov     dx, offset msg_en ! p8 }6 L; g9 F  k2 y) i

  23. ; f# l$ [* E" {
  24. exit1:          mov     ah, 09h 2 X+ H: r: U9 u
  25.                 ; DX already contains address of string
    ' P' N& R& f3 X# f
  26.                 int     21h
    ; B6 G  T: K4 }( m4 P' D; Z" b
  27. $ S8 \% W6 S  k/ a" H, I, a
  28.                 mov     ax, 4C00h
    9 A9 _; n+ n- Y! l+ e
  29.                 int     21h
    $ B9 A- u4 s. a. b- v; c
  30. $ B# [: |% C* \1 _
  31. msg_ok         db      "OK", 13, 10, "A20 $" + b& q) J0 f) r6 q! @% n0 f1 x
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ! N, d+ S! L9 z4 e8 G$ I6 m
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ) n+ r, u; _$ N
  34. msg_dis        db      "DISABLED", 13, 10, "$"3 ]7 M0 n+ H/ M
  35. - L9 M4 h# x4 a. n

  36. 7 j5 P( Y# U, s, Y7 J- d
  37. _GET_A20_STATE_:
    3 g( ^4 H. @. x/ L/ i8 ^& y( ?5 S6 J- Z
  38.                 call    A20Write                ; Wait till the input register is empty 3 {% I- X3 K. l/ M1 ~/ L5 H. p! p
  39.                 jz      exit2+1                 ; Bypas the reset int's
    : e2 ]# t$ N5 j4 O& e4 }
  40.                 cli                             ; Disable ints so we'll get our value
    ) W# o' |# L' f

  41. 9 l3 I/ R+ r1 r  r
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register - H  `! t, ]7 M+ X; T
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    % I, o9 _6 ~# x  {+ w# G- C2 A1 x
  44.                 call    A20Read                 ; Wait till the 8042 output register 8 M$ b, g( m' w" l$ c, T' S' T: c
  45.                 jz      exit2                   ; has something in it's buffer   F; s3 k" l: h/ E% t

  46. ' W7 g! p, a9 L3 t7 O0 T# w! y3 s
  47.                 in      al, 60h                 ; Get it 7 i# I2 o+ T( ~  q
  48.                 mov     ah, al
    " }+ T: l+ {/ S; R
  49.                 call    A20Write                ; Make sure the input register is empty
    : t# r/ w2 g# n0 c. Z
  50.                 jz      exit2 ! \2 ^& }  {7 Q/ B- h* ^+ f, ~

  51. ' h% n4 H- N. F* r! v8 u. U7 p
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    3 \5 I( T  H4 T4 S; z, d
  53.                 out     64h, al
    / I6 Q  U/ L! o3 Q
  54.                 call    A20Write
    / s5 D$ z; {8 f8 y- w

  55. $ X) H6 E4 g2 G2 B
  56. exit2:          sti 5 s3 @7 m5 D5 y9 F- E
  57.                 ret
    ; b8 h' e0 S! g6 W1 h$ S5 B
  58. 1 ?! y3 p  n8 u# U3 N# b, Z
  59. 5 D& m* R0 K# v1 A; ]8 P( y
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 7 _# |# f) ]( b, B) i: m1 q2 v
  61. get1:           in      al, 64h                 ; Get KBC read status ) k6 Z# E& R) @) B
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear ( K9 J, G( d+ E2 G9 L
  63.                 jz      clear " |4 z2 E  z1 r* N
  64.                 dec     cx
    ! s  i, o% a$ J& H/ @" x/ G$ x
  65.                 jz      exit3 9 L+ ^& V, |) L1 W& {/ I0 d
  66.                 jmp     SHORT get1
    ! w! |$ c9 m( E
  67. clear:          inc     al                      ; Clear ZR , D9 T+ F, F8 u1 G( W! u
  68. exit3:          ret
    + B& H! K6 k( g! F2 k

  69. ) _: R2 l$ N5 a& _! ~! ]: A
  70. 9 e. ^. g0 \! K& G) N
  71. A20Read:        xor     cx, cx % r) W2 F5 @; N6 f( n" z
  72. get2:           in      al, 64h
    7 Z( k* f' t0 o+ b- Y2 N3 {
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 5 l. ^- l! ~; w" P/ q
  74.                 jnz     exit4                   ; something for me . ]( i1 [7 Z4 p2 ]0 {% u$ t$ ~
  75.                 dec     cx
    9 h2 {" @# Z# ^+ F4 O
  76.                 jnz     get2
    3 m$ y% `+ e) r5 c
  77. exit4:          ret     : ~, C' |& ?1 ?
  78.                
    - O4 J/ r+ D- L+ N
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
- Z! K4 I3 W4 p" P- f+ L: x3 J) Q{        while(inp(0x64) & 2);        outp(0x64,0xd1);3 d$ z; G' {; k4 v/ D  |+ S: u, N
        while(inp(0x64) & 2);        outp(0x60,0xdf);
( j# Z4 x5 Y: i# }( A        while(inp(0x64) & 2);        outp(0x64,0xff);( b" e/ E1 Q: J4 s+ C
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-12 05:36 , Processed in 0.055509 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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