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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    / g6 D) J% m! }3 a0 O8 R8 A( b% p
  2. ; 2 @) E  F/ p/ T, O
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-012 b2 B4 i0 u; g6 i2 b. ~
  4. ;       ml A20ON.asm 9 k8 n9 `" J8 l1 S3 E6 _+ O
  5. ;
    6 G5 V* S9 R  {, P( X
  6. .model tiny) C8 N) @0 G/ I. X
  7. .code
    7 I; D/ {, [  d; U* l" o
  8. .4866 L4 O' |4 L/ d+ R% A
  9. .startup; S& ]6 v9 I1 ~
  10. 6 R+ ]4 o2 T& \+ ]8 b  e9 t) b
  11.                 mov     dx, offset msg_author
    ; x. O8 U. l. Q2 c1 X2 ?
  12.                 mov     ah, 09h
    4 I. U) S' x3 q* d
  13.                 int     21h
    , d3 |9 u) ~3 }' K% S1 l& A
  14. . z3 n$ f# z: _3 D% k
  15.                 mov     dx, offset msg_fail ! m4 I* ^  Z5 d; G; i# E% X+ m) \
  16.                 call    A20_ENABLE6 u% O+ Z7 o. G# l6 D# A, y
  17.                 jz      exit11 ?! }. D3 c2 T. Z3 e+ N5 [
  18.                 mov     dx, offset msg_ok 7 l7 G( J5 n7 u+ z+ `

  19. % Z; H) e, z; ^# O
  20. exit1:          mov     ah, 09h 7 q' d! y6 a1 ~  ~
  21.                 int     21h & j$ b) r& A4 Q  T2 A1 p/ m) r" ~
  22.                 mov     ax, 4C00h " v0 F8 q( ?) C1 K- f/ C* {( K
  23.                 int     21h
    ' ?0 N; N& x6 x6 J6 f
  24.                 4 I( U6 u+ i$ j1 `
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    5 B6 k( _4 h# n4 Z/ j: |
  26.                         "2008-07-01",13, 10, "$"
    * x7 Q; M* e9 ]) n. o
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 0 _3 n' a# L7 C
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    . p9 o$ M5 p/ a, N/ m

  29. ' @- E4 B- t/ _' t
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------1 s# @. K5 i7 \3 r% g
  31. A20_ENABLE:
    : A9 I5 E! p2 Y, n- c/ D
  32.                 call    A20Write 6 Y6 ?4 n) V  X/ {( {8 k
  33.                 jz      exit_enable3 `7 ]! c/ c8 I  {- x

  34. 4 R$ L3 m- A* Q
  35.                 cli                             ; Only need for reading value from KBC 5 B6 G: X6 N' r: J+ s
  36.                 mov     al, 0D0h
    + m& @" r) i& [" o/ r
  37.                 out     64h, al - q7 t; z* m0 v  D  v: ~
  38.                 call    A20Read
    8 H! |  O: r* H
  39.                 jz      enable_int & @$ z, h3 m6 W/ E1 D# k( y( M
  40. 4 b6 ~* E# j7 |9 M7 ?
  41.                 in      al, 60h                 ; Get current status
    ) Y) q+ `) P% A0 i* k* h
  42.                 mov     ah, al 9 d  X4 a, J* z  G3 d; `& U
  43.                 call    A20Write
    ! a* l! q1 }* o" K  I4 x
  44. enable_int:    sti " J. J7 N/ j( V3 W9 P* x- d$ w
  45.                 jz      exit_enable
    % G2 |, `6 X1 W/ b; y  C! i

  46. 1 [$ e, g+ X+ s7 d3 |0 G- l, N
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    7 i1 @, V* g0 x# {3 O) z) t2 S
  48.                 out     64h, al                 ; Out Put Port next
    7 V9 W; _3 Q% s% l2 M7 [6 ], ?3 m
  49.                 call    A20Write & \$ H6 O9 N* P( m1 }& M
  50.                 jz      exit_enable
      F) @: T+ U  W% Y( Y0 D
  51. " g2 N8 h3 k7 x& v9 ]& K( {
  52.                 mov     al, ah
    ' l7 f4 B- i% e6 }% X
  53.                 or      al, 2                   ; Enable line A20 / Y1 z+ D$ g8 C$ E! b2 A- o
  54.                 out     60h, al
    - i* Q1 G! E9 U0 c2 E3 g
  55.                 call    A20Write 8 [) H+ G' u$ e/ ^  d  W
  56.                 jz      exit_enable
    " ], m9 y% C# A3 j  d

  57. * q9 W; U6 u  l# u  s. l
  58.                 mov     al, 0FFh                ; NOP
    , I: |" ^' B" v4 o, ?
  59.                 out     64h, al 7 y4 I# y/ d1 D% q. x5 [
  60.                 call    A20Write
    , W9 p4 {+ L% J/ c- O2 p$ P$ A

  61. " L( n, s$ Y# }0 W& i; C
  62. exit_enable:          ret . \1 ^* A4 R, k' A( E: u+ _

  63. # h# W2 b/ x: t& Q' T
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    3 g! }8 T( F! d! v0 V4 d6 D
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 6 t+ W: Z- o7 t/ L7 K2 G5 [
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    8 G9 D. x9 E" I5 ?$ p1 `" U/ X: D
  67.                 jz      clear
    2 t1 f7 q! ~- n3 N6 @
  68.                 dec     cx
    4 |0 T/ u% z$ s7 i8 }3 |
  69.                 jz      exit_write # W1 r2 @/ H3 A; Y% _8 c% v
  70.                 jmp     short get_wirte * d* c" J5 ^* ~$ @( \" V4 |
  71. clear:          inc     al                      ; Clear ZR * ^0 v1 q# K- i6 Y& @
  72. exit_write:     ret
    $ Y) s6 b$ T! `0 j" ]! ~
  73. : w4 Y  ~3 F& l

  74. 6 j  Y3 v# q- T$ X! Y
  75. A20Read:        xor     cx, cx / l: X' m4 R  K5 l6 P
  76. get_read:       in      al, 64h 5 h7 I) i# A. {! R" i, X5 `  b5 T
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    % G! W/ G2 ]9 k6 U* S/ J7 K$ `( q
  78.                 jnz     exit4                   ; ...
    ( h( D$ Z/ e8 Y1 {5 Q
  79.                 dec     cx
    7 c! D2 y* i0 ?+ f  k# D1 H5 i6 l. S
  80.                 jnz     get_read
    1 A4 ]9 @! f4 r- s
  81. exit4:          ret     
    2 v) F3 W; W8 Z- z. x
  82.                
    ; f" c5 H, R+ i: Y% h
  83. end
复制代码
  1. ;A200FF.ASM / Y1 m' f% T( ?  u7 n+ T
  2. ; + N  z4 T( _1 P& v" E& C% H4 H
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ; D% ~  s$ ]/ B/ K+ \: D- B' m
  4. ;       ml A20ON.asm
    ( E4 D+ I7 B9 A) C
  5. ;
    # l  f+ E2 [9 o# w6 L7 S- ~
  6. .model tiny" n( ]+ q' c* C; z4 E1 L
  7. .code8 F/ q5 g% @3 c, r
  8. .486  }3 |* R/ t3 m* F+ Y7 c+ o0 m0 E) b2 G
  9. .startup
    " v) r4 z- k* k0 V2 o, L( S
  10. & B2 ~4 p& u5 s, f) @$ Z
  11.                 mov     dx, offset msg_author2 A# N# y8 N7 a, g" L& F, O
  12.                 mov     ah, 09h# Q8 A. n& {0 f6 t
  13.                 int     21h
    ( S/ a: k% e- U1 {- @

  14. " i; J/ T) q& \* {; L. c: x# L$ [+ M
  15.                 mov     dx, offset msg_fail
    ) {$ u5 U& S3 |' z9 J2 K
  16.                 call    A20_DISABLE( z, U* L+ {$ ]) Y3 T) u) i
  17.                 jz      exit1/ t+ K8 h8 P7 V; E; [' p  L  L
  18.                 mov     dx, offset msg_ok ) x# {6 _# {, Z! f/ f
  19.   c+ W) e2 Y( ~: Z% S2 e
  20. exit1:          mov     ah, 09h
    & B6 s* k& Z+ {
  21.                 int     21h   L' j$ @: `% C! k- `
  22.                 mov     ax, 4C00h : S# N$ j' N& o8 e
  23.                 int     21h   R( V& x/ n+ X. F0 C' j
  24.                 * l! v  M$ f* v
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    " S; [" R( _+ T3 W/ y/ c
  26.                         "2008-07-01",13, 10, "$"
      k$ m3 I  t) z' k
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    ; F6 o  U3 t) k9 f, E- g( x
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    8 ?. T- f2 E+ e4 n% C

  29. 6 |& [. b; O2 C0 ^' ], x
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------5 k( Z- d- z5 b$ _( ~$ o: X8 f
  31. A20_DISABLE: . c" M$ O8 G+ E: N2 ?
  32.                 call    A20Write ) e& z2 L3 _3 q2 H2 ^
  33.                 jz      exit_disable
    4 f$ m0 G: o9 D, X5 B9 ?/ ^4 |

  34. 3 L0 r0 Z# z: w' `3 \# g6 ?/ R/ p
  35.                 cli                             ; Only need for reading value from KBC 5 g4 x( x; I# a/ r: _1 c% m
  36.                 mov     al, 0D0h
    % X; g1 W' l* j$ |  v2 Z
  37.                 out     64h, al
    6 ?6 B# ~4 o, F9 h3 C# h
  38.                 call    A20Read ( v4 N: Z+ e; q9 b2 s
  39.                 jz      Disable_int
    / b/ d  }$ ?1 _; ]2 w

  40. 2 E* }0 R, o- k$ v5 l/ R
  41.                 in      al, 60h                 ; Get current status
    5 q& _" n2 w7 p, b- Q, u* M& w
  42.                 mov     ah, al ' m- p5 A0 Z" p
  43.                 call    A20Write 2 ^( g4 |0 B: |( @4 a- a
  44. Disable_int:    sti
    7 k( ]/ T3 d( A( C& f1 D+ r
  45.                 jz      exit_disable
    7 [$ h* R; X$ |; U2 U

  46. ' [1 h* z* W  K& I. Y+ U6 w
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    ; ?7 P# J, \. m5 J& K
  48.                 out     64h, al                 ; Out Put Port next
    . ^7 C" {9 W0 ?- E5 j
  49.                 call    A20Write
    4 c9 f. i5 c1 r, K
  50.                 jz      exit_disable& R/ C- r3 O2 z# K: _" W2 t( ]0 y2 X, }

  51. 4 P$ g: |4 U2 f( Z5 G5 B
  52.                 mov     al, ah
    ( s# U% c( [1 G* \1 C' @
  53.                 and     al, not 2               ; Disable line A20
    7 K1 I8 N/ |8 ^* f0 Y- V1 G
  54.                 out     60h, al " W1 `% l6 I( Z  V& I
  55.                 call    A20Write 9 l# d( [+ q  c+ y) A! I1 A
  56.                 jz      exit_disable7 G& N, _" O# A, G8 v

  57. 6 a9 m( b; F/ f
  58.                 mov     al, 0FFh                ; NOP 2 q# X, ~( E! p* z3 x/ }( e
  59.                 out     64h, al
    4 ]5 t' _" n! E) b  m
  60.                 call    A20Write ( J0 {4 g8 R8 s' F6 E* K
  61. . V& }$ R6 c: c9 E+ @# G
  62. exit_disable:          ret
    # f$ }7 A+ t- Y
  63. ; D, A8 ^  j  b9 e2 q7 L
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    " T" b0 u9 ]# ?% S
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    , i. w+ q/ Y# ~* u3 @3 M$ }
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ! E' S& s2 g" U' h( {4 o
  67.                 jz      clear
    , r7 w. E$ {) S2 ^' k6 k
  68.                 dec     cx 6 m' V6 m) @5 k% B3 @3 E; S) z# P
  69.                 jz      exit_write 5 O; d8 m# u, m  e
  70.                 jmp     short get_wirte
    ; Q( |! I' r3 c. o( K$ s
  71. clear:          inc     al                      ; Clear ZR $ O: C+ s5 n. i; k" D
  72. exit_write:     ret % F+ s$ n* {  Q9 X
  73. 3 a5 t' h, e3 S" A  x' x
  74. # i, G; t0 c. G- P# O6 A. n
  75. A20Read:        xor     cx, cx 7 F" m' z$ Q5 R" z
  76. get_read:       in      al, 64h
    2 C! a. x+ O# t2 Y+ t  g
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ! I, |0 h3 P) J6 v9 Y' ~
  78.                 jnz     exit4                   ; ... ' {3 e" {! M" }  E6 d; f- V" [+ i1 G
  79.                 dec     cx
    $ P/ ?5 H; _, |; U' g
  80.                 jnz     get_read
    # z6 n. U% k! C# B
  81. exit4:          ret     % N- i, _: @( e1 Z% E) w9 ~. [
  82.                
    7 D9 V: F1 V1 N% X( }  t, O
  83. end
复制代码
  1. ;A20STATE.ASM
    " z* y& q+ @4 ~
  2. ; 8 |  _3 X$ ^8 T0 G8 Y6 O4 k8 P4 Z7 c+ V
  3. ; Returns the status of the line A20 through the KBC
    . g, o# A; {% w- |+ b9 h% d
  4. ;       programming by bini for debug. 2008-07-01
    6 @2 g" q" l% {0 p! ~; p
  5. ;
    ) x3 l# k$ B* B# e
  6. .model tiny9 w) P# `: h7 t  L
  7. .code
    1 H' N8 u4 v- V! V) |
  8. .486
      S; B$ X  E( T/ B
  9. .startup
    # w2 ?. g( u! n; `
  10.                 mov     dx, offset msg_fail
    1 O/ E- G8 V8 [6 F: W
  11.                 call    _GET_A20_STATE_& j7 z7 Z4 C$ \/ t3 ~5 k
  12.                 jz      exit1                           ;  was a problem5 ^! u& ~6 a- h
  13.                 push    ax                              ; Save state, AH # B2 S! t8 H% T# j9 d
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    9 w* o* z5 Z) R* @' Y2 h. }. ?: B
  15.                 mov     ah, 09h / u  v0 k" w, x2 w# b
  16.                 int     21h                             ; Print message
    ! ?' }; _( N, k3 x6 ~
  17.                 pop     ax                              ; retreve state * v9 V8 h! d; i

  18. . E; ^; V9 E# c, n( F! w5 \
  19.                 mov     dx, offset msg_dis
    . [% a& p8 Q( r! _  k
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 3 f, d1 P& A" n$ N
  21.                 jz      exit1
    ( p8 x1 A9 p6 j; k* z6 a/ D
  22.                 mov     dx, offset msg_en ) {: E# o; n% L$ `% `

  23. 5 ^5 D" ?( Z' Y- N4 Y* }; ~
  24. exit1:          mov     ah, 09h   k1 k+ l8 n, d/ V# R8 m0 o# S
  25.                 ; DX already contains address of string
    . X+ r  `( j' [0 ?: n
  26.                 int     21h
    5 ^$ j% V6 H! V9 l8 N& e9 ?
  27. % ]5 [" O5 m5 |) _, i4 v
  28.                 mov     ax, 4C00h
    4 D; K0 C- S' `* P2 ~: Z2 b# K
  29.                 int     21h
      ~' _5 D; t, K# w! n1 e

  30. 0 T2 s: k% p2 J- F; W9 t$ w
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    % e) `) q. ~, P5 D$ M1 V8 c+ d
  32. msg_fail       db      "FAIL", 13, 10, "$"
    : E: |# N- S- v5 j( I' s
  33. msg_en         db      "ENABLED", 13, 10, "$" / U$ [3 P- J: ^) a
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    5 E2 d! s/ n' L

  35. 6 Q4 F8 o7 I) x' |4 N! w$ s( o! A$ X
  36. ' c" d% u: f% v" `! z9 t
  37. _GET_A20_STATE_: % \( @+ [% |' T$ x. p: u7 \
  38.                 call    A20Write                ; Wait till the input register is empty
      v/ V  s4 k9 L7 `# f" I* X# l
  39.                 jz      exit2+1                 ; Bypas the reset int's
    0 s% S- K9 n" t! v* N7 E
  40.                 cli                             ; Disable ints so we'll get our value 4 U, b$ ?- e  F' z2 n/ t

  41. - G" \2 ^2 V, }! O
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    : P" Q0 U; E6 y- ?) d1 R# q0 C
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    7 [7 A2 G) _3 J' v/ L) H! {: P
  44.                 call    A20Read                 ; Wait till the 8042 output register
    " N. P/ S" j5 e8 L5 {3 N* d
  45.                 jz      exit2                   ; has something in it's buffer 3 r* ]8 E8 t- Z, T2 H

  46. ; G2 o. Q9 F( J! J6 V3 Y
  47.                 in      al, 60h                 ; Get it 4 b4 V! j/ U# r; ~/ z
  48.                 mov     ah, al
    + D4 k8 k* K# V; A2 r( R# J# h3 `
  49.                 call    A20Write                ; Make sure the input register is empty ) [! i/ R( j0 j0 w; r) \
  50.                 jz      exit2
    % e9 p2 n+ x4 @8 \, i
  51. " @- s0 R: g1 f! _, R; j
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    6 A6 x  k0 H( q  @
  53.                 out     64h, al 2 _; Q" W' \8 \8 {) w4 v
  54.                 call    A20Write
    % _& ]- h! r2 ~4 w, r& k! t5 i% f

  55. ( d- f+ [+ `8 f& w
  56. exit2:          sti
    : w5 ]7 U9 y0 x9 Q
  57.                 ret0 J0 R  k/ p: E

  58. 3 \/ x& o1 J; r! F8 c8 Z3 G

  59. ! }% q1 b+ T4 Y4 q0 y0 m2 }: j
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    $ U2 C' ~% v# ]6 s! e
  61. get1:           in      al, 64h                 ; Get KBC read status 1 P  r# p& |% D; G/ v7 m
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ; F* V7 c3 P2 B. v( E' _
  63.                 jz      clear
    ! B7 I. L1 \! \  r
  64.                 dec     cx 0 h$ o) ~/ h7 n1 E
  65.                 jz      exit3 : i+ h  q, {" W9 {
  66.                 jmp     SHORT get1 ( i' A: L& m& ~+ o7 k6 ?9 w6 _
  67. clear:          inc     al                      ; Clear ZR
    * a% ^+ B) ~, K- S
  68. exit3:          ret , {& U7 D! E2 J9 ^

  69. : `  o7 K! M$ e1 D& }$ U1 S8 f- m
  70. ! ], l6 b+ a. I( V5 S3 _1 y0 S/ s- v
  71. A20Read:        xor     cx, cx
    $ m; q  p( s6 s8 q
  72. get2:           in      al, 64h - R7 ^# D; B  B4 E' M& {2 Q% u9 ~
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' E. W# w, i) r  m
  74.                 jnz     exit4                   ; something for me
    ( i6 ^0 G" ]& j8 o/ E0 e5 K" Y$ [' y0 a
  75.                 dec     cx & \4 _# }' A( m% y% d. w6 l$ X
  76.                 jnz     get2  W+ z7 \$ K9 I- o( }1 A
  77. exit4:          ret     
    ' Y7 z* F2 w, a7 L
  78.                 : l6 ~# a3 s6 c5 r4 u
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()( b8 y2 t! p! g4 |
{        while(inp(0x64) & 2);        outp(0x64,0xd1);4 r' s: a9 R! c+ f. M$ Z. R
        while(inp(0x64) & 2);        outp(0x60,0xdf);
. P: e5 J4 ~4 p$ U        while(inp(0x64) & 2);        outp(0x64,0xff);
% U# Q& Q) j6 V# E& X- N}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-4 14:30 , Processed in 3.978668 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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