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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 7 J0 X( T; Q" v4 m! n0 J
  2. ;
    7 N/ ]0 i; z  A  ^& M- v( [* R
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    . y% N0 j2 ?# v/ l1 _2 u- a
  4. ;       ml A20ON.asm 3 P6 i; d5 j4 c9 p
  5. ; 6 L( `4 j' g8 `. o" H
  6. .model tiny% p# g* m4 C4 {( C) b
  7. .code9 C" n, p3 d% m4 {3 f% {
  8. .486" H" D0 I% b$ S, s( N' I6 X5 y
  9. .startup; |* o9 L9 ]+ S$ @7 `$ s
  10. + E% l: p3 @. ~6 s
  11.                 mov     dx, offset msg_author
    6 x8 z" h- R9 w( ~* d% ]
  12.                 mov     ah, 09h; c5 G4 H0 \5 I! W6 E
  13.                 int     21h4 N( g; }6 ^. w. E7 x: i" @
  14. * q! g7 f, G1 B- g1 m
  15.                 mov     dx, offset msg_fail 6 C& z+ X* T" v' {# [1 ~/ S4 \
  16.                 call    A20_ENABLE
    % I) ]0 }" y' E" h6 D
  17.                 jz      exit13 \0 W) g1 S# y
  18.                 mov     dx, offset msg_ok 6 e( z2 C; i8 F+ M7 x. P0 N- _
  19. # N- ~4 `0 K/ M! T# z# Q. ?4 ]- r8 k
  20. exit1:          mov     ah, 09h . p1 \5 ^  L) S5 y# ^# v+ n$ c
  21.                 int     21h " o" q6 o& Z/ h% K8 \
  22.                 mov     ax, 4C00h
    , O. e1 N9 t8 R/ a3 _4 Y& E
  23.                 int     21h
    4 i' A  k8 N) F- t( b
  24.                 6 q! `, w0 ^1 I3 w! T: t4 c9 X
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,( @% U; a) A3 J/ G) {4 a2 `
  26.                         "2008-07-01",13, 10, "$"
      f- R; A9 C" F& ?3 T
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    9 p9 Y0 h/ c0 Y; q1 z/ o: d
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    8 p3 s3 s! R& U+ x6 T( B* t
  29. ' z  ?; |! B9 q9 {) \) J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    , e3 ^/ M: \7 d5 ?; \
  31. A20_ENABLE:
    ; I4 p2 K" A( Q( I- {# d: P
  32.                 call    A20Write
    . R7 s. A+ {$ I
  33.                 jz      exit_enable
    - u: i. d, p( C3 y* l. G& t

  34. # o0 j( E2 @% F
  35.                 cli                             ; Only need for reading value from KBC 3 j! k, r! t, Z
  36.                 mov     al, 0D0h
    $ {: o# |" }" x4 h: D
  37.                 out     64h, al 4 Q5 |5 l) M% U, e
  38.                 call    A20Read
    0 l3 p1 K1 y7 |( Y% h( i
  39.                 jz      enable_int 7 e, I0 w0 r3 k. d

  40. 1 V2 b/ r4 X# F! x
  41.                 in      al, 60h                 ; Get current status 9 E" v2 s# l% N/ ?- @7 j* k
  42.                 mov     ah, al
    " A) |5 R* K+ Q: u( M
  43.                 call    A20Write ) K7 ?. F0 Q2 B  `
  44. enable_int:    sti
    3 }+ q1 o+ N' Q
  45.                 jz      exit_enable
    9 ~( O4 b) N2 c; c4 M( v# R$ @3 e
  46. $ H" c" s0 k9 H' h2 r
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 3 t4 J9 ?3 s6 ~9 u9 Y4 [' S
  48.                 out     64h, al                 ; Out Put Port next / ^  {  d5 q" H: X/ K7 P
  49.                 call    A20Write 4 p. Z& o; t1 ?6 u( i0 V# U7 B6 Y
  50.                 jz      exit_enable: V0 S/ h8 ?$ [& _6 t2 ?

  51. 9 _% ~4 j9 x0 g, p
  52.                 mov     al, ah 0 B2 N8 L7 `' m6 {  i8 _% O8 ?
  53.                 or      al, 2                   ; Enable line A20
    # C  u1 W5 P% W0 c
  54.                 out     60h, al
    ' d9 i. {! q+ u/ [3 I
  55.                 call    A20Write
    ; [0 N! |$ ?; T5 F3 [* C' m8 d
  56.                 jz      exit_enable
    . \" w4 f5 P. y' @. }

  57. " @2 d! e9 L5 w$ y
  58.                 mov     al, 0FFh                ; NOP
    0 P: N' T: f0 g1 B
  59.                 out     64h, al
    / Z0 a& K5 D6 P6 c* I
  60.                 call    A20Write ' I, y( O: c5 q! A1 ~
  61. 8 w2 o/ d" S( V# ], F: c3 q( c' W' L
  62. exit_enable:          ret * p% `* I  _8 H0 r1 p* r

  63. ! N5 @) U& k% N
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ! Y) ]/ [/ `, C2 Y+ a/ q  O
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    0 ^- @. y, j8 ?+ j1 |" ], k) e
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear : P" p" A+ J. V  O- A( w. ?
  67.                 jz      clear : k8 d  ~) s" H6 d. `
  68.                 dec     cx
    % P* z2 H  Y$ \4 ^
  69.                 jz      exit_write
    & @7 p$ v% t' S. P; T# t
  70.                 jmp     short get_wirte
    4 h7 g+ n( E3 R. ?7 k4 P# p, ^
  71. clear:          inc     al                      ; Clear ZR
    / ~) V9 w' U% `2 c) m
  72. exit_write:     ret & m# d) `9 _5 U9 p# F, t

  73. 7 `, K/ G1 q  C5 _1 u

  74. : D( x! g% h  K  T( e$ M3 ~) O  {
  75. A20Read:        xor     cx, cx * A' Y7 g9 L( _/ U6 {" ]
  76. get_read:       in      al, 64h . G. z: O8 c6 q! \' w  B5 H& Q
  77.                 test    al, 01                  ; If the 'output buffer' is full, has " B9 }+ _( f$ N0 Z
  78.                 jnz     exit4                   ; ... 0 _2 P" V6 ]2 V
  79.                 dec     cx + U$ X+ ]( e9 @! H2 G7 \; p; n
  80.                 jnz     get_read
    % w( U2 C: z+ S: P! \. O
  81. exit4:          ret     
    7 {$ U* o: Z* N
  82.                
    7 l+ M  l  n+ s" q
  83. end
复制代码
  1. ;A200FF.ASM
    9 g: Z6 d( J" K/ h' ?
  2. ;
    ; I6 Q7 Y: e( m9 k2 b! W
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01: @7 r* U" L* A  b) J. w
  4. ;       ml A20ON.asm ; w4 R0 q. `* t6 Y  a
  5. ; , z, n* j+ X1 ?  r3 r
  6. .model tiny
      i  a' U) B2 f- I+ g3 X. M, q
  7. .code' F9 k: l, d* S# G2 E
  8. .486
    2 X3 O* M# B% a8 _
  9. .startup
    , Z% ~: V% `! ^- e' s# \* E

  10. 7 W- d! U/ d) H9 Q
  11.                 mov     dx, offset msg_author( k* e* [! g+ E) ]
  12.                 mov     ah, 09h2 K% ?  u% V$ `% o
  13.                 int     21h
    5 L  h& f, Q& R) S
  14. 8 |0 `$ L/ Z! ]$ R% X7 n0 L8 r
  15.                 mov     dx, offset msg_fail
    # H3 P6 O) |  V0 j7 b
  16.                 call    A20_DISABLE+ e4 [* U* ~1 k. K7 R9 ~$ T9 R4 o
  17.                 jz      exit1, _3 r) I  q/ M' e
  18.                 mov     dx, offset msg_ok
    ! D5 Z5 p. r# w6 x0 h

  19. ; @' m6 l; Y3 E' X0 r% h' F
  20. exit1:          mov     ah, 09h
    ( x! U2 `- ]* ]6 ~+ c! g
  21.                 int     21h
    - j, c5 @6 v- Q  w; X1 b
  22.                 mov     ax, 4C00h
    9 \: v( e3 C6 g7 I6 |
  23.                 int     21h
      N$ R+ j/ j9 x5 e$ |4 X- u# x
  24.                 6 C! t( [" h# ^, w, C2 ?4 e, l
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,# g$ J3 }$ F, d4 s; I
  26.                         "2008-07-01",13, 10, "$" ; q  G+ q, `8 b6 r
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" ; C/ `. Q' z: K2 }
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    ) ]4 `& }7 \0 G5 ^' V" [4 d

  29. ' ?, J9 l* v- G! p0 {
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------. J6 l( {+ Z7 C8 m) ~0 D
  31. A20_DISABLE:
    . R# u1 a3 y9 w( P1 e4 ?/ B
  32.                 call    A20Write 2 x! v  ~% y( S* g. Q
  33.                 jz      exit_disable
    ) b# v4 P8 j* E

  34. 0 O! |) B& T8 A7 u3 e2 P% m
  35.                 cli                             ; Only need for reading value from KBC
    $ D- a5 g) g9 d/ E) Q  S7 Q) @
  36.                 mov     al, 0D0h
    ; H+ m" W* |2 ~
  37.                 out     64h, al
    * C2 B" W+ d& E
  38.                 call    A20Read
    4 a' t9 J; ]! D: G: ^9 ?
  39.                 jz      Disable_int ; Z: ~9 F8 W  Q7 Y5 j

  40.   \+ H' F, P; y# f4 |! ~* `* s8 F
  41.                 in      al, 60h                 ; Get current status 5 w/ r& N6 I! x  b# m- r, S; b! v& Y
  42.                 mov     ah, al : k; O2 D8 m+ T
  43.                 call    A20Write
    2 D* J3 r- V. T' K  a, \. o" `- Q
  44. Disable_int:    sti * Y2 h( Q5 P, C# ~
  45.                 jz      exit_disable
    7 Q7 b0 k& t8 q# i
  46. 7 U6 o6 \- T& `# O; r6 L5 R" ^" K
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the % ]6 e. V: Q8 z; _
  48.                 out     64h, al                 ; Out Put Port next 5 p- N& S* z" R, L
  49.                 call    A20Write 4 Z' u6 K* O- O! [! [3 Q4 Z+ F
  50.                 jz      exit_disable
    + _) T5 {" S& B6 a
  51. % \8 i# O2 a/ H% N7 |' V
  52.                 mov     al, ah - }* W4 H$ Z+ w' B
  53.                 and     al, not 2               ; Disable line A20
    + B5 b" r* M+ F/ h0 J
  54.                 out     60h, al
    9 R( H6 l, _, G. v
  55.                 call    A20Write
    % Y, F4 R  a! Y8 b
  56.                 jz      exit_disable
    : G1 Z2 `6 v2 B6 {. c1 R

  57. 6 e8 l# E% D& L1 B0 B/ }
  58.                 mov     al, 0FFh                ; NOP
    $ a) M: X* Z; r+ A! O
  59.                 out     64h, al ( w# d9 v5 j% A' U
  60.                 call    A20Write   G& \6 F' G4 W
  61. 8 w3 ~# y) \- ]& T( }8 {  z
  62. exit_disable:          ret
    3 S/ ~  q. E1 {, ^4 v* v7 M7 p. P

  63. # W% {+ b" T. Z7 I
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    1 w9 n# S! [9 s
  65. get_wirte:      in      al, 64h                 ; Get KBC read status   j2 V! ]* t. h% S& c
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    0 z+ \5 R. N8 P- |7 H+ B) B7 U' W
  67.                 jz      clear ) l6 V* D# C6 X& e
  68.                 dec     cx
    ( N, @8 T$ q" A; |7 ]
  69.                 jz      exit_write # F5 J: `  ]! B( ?; x; c, R" B
  70.                 jmp     short get_wirte
    6 q2 K( A1 Y+ L$ E
  71. clear:          inc     al                      ; Clear ZR
    ( l5 C: C. n" q* m5 `* g6 f5 J
  72. exit_write:     ret
    2 h/ O8 e1 e+ o6 K1 G0 o' g6 U5 |
  73. * b2 ]' B$ B( Y; Q
  74. 7 r) s0 R- z7 ?+ l' r/ t
  75. A20Read:        xor     cx, cx
    8 C% [  x+ w8 a" ?- |: W
  76. get_read:       in      al, 64h ) b1 S5 n% u5 D0 Y5 ]
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ( N2 S* `4 i; {7 Y$ o/ l
  78.                 jnz     exit4                   ; ...
    " V) y/ N6 `2 Y& E+ K- M) a2 m7 u
  79.                 dec     cx ( ^6 l7 l! F$ @9 a0 ]
  80.                 jnz     get_read
    2 R8 I" a! }, ~  S! h9 G4 ]
  81. exit4:          ret     9 t. B8 E& y* y4 \
  82.                 3 V* l  x. p; o
  83. end
复制代码
  1. ;A20STATE.ASM
    % z9 U& q8 o. D/ q
  2. ; * A+ z9 P% K/ S! k6 Q+ U" S
  3. ; Returns the status of the line A20 through the KBC 8 n0 F1 W, U, c; E1 y
  4. ;       programming by bini for debug. 2008-07-01
    ' P- [: z4 H1 Z9 |( k+ [+ C
  5. ; * h/ `6 v* j) r: g5 \$ B8 N1 T
  6. .model tiny6 Q% v+ e# [5 `0 Y9 q  s' S
  7. .code
    ( [& L2 ?9 z. {7 d) V
  8. .486: m. D3 Y" l( d& ~9 I# f$ L
  9. .startup
    " H, c2 ~2 P: R$ e" y1 N$ v3 ~& c
  10.                 mov     dx, offset msg_fail
    3 O8 B0 s+ |' U# {9 v( S
  11.                 call    _GET_A20_STATE_: x, w4 y; g  F) B* F
  12.                 jz      exit1                           ;  was a problem
    - M/ _) }1 n1 h
  13.                 push    ax                              ; Save state, AH . _1 _1 M* z7 L" A; q: q
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    6 o3 [# D3 J. ]8 S1 b4 |) Z
  15.                 mov     ah, 09h 2 w7 T+ e- ?8 r! M2 `
  16.                 int     21h                             ; Print message 7 U3 L5 I# w3 `) M' H" n: x
  17.                 pop     ax                              ; retreve state . ^" t  f8 m  u

  18. 3 J: X+ X, G+ H: r# D6 r1 g& w
  19.                 mov     dx, offset msg_dis
    / H, I$ n( d6 e* [, {
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    1 i5 C' S7 G9 q/ A2 ^4 T
  21.                 jz      exit1 ! A$ s9 s3 Y# C- e2 S  d- w
  22.                 mov     dx, offset msg_en ) q3 ?, x' ]! ]4 x' N

  23. : c2 ?! [0 o, G; m) }( N5 [7 @
  24. exit1:          mov     ah, 09h
    1 [& E9 A  Z* \+ n9 I2 |0 W
  25.                 ; DX already contains address of string 2 `. H9 q0 g- i: A" @4 E% i
  26.                 int     21h
    9 D# c6 d3 D0 i. {' e  e; F, ]
  27. % X$ G9 V2 ^$ B  D- [2 c; E! J9 X# S" [
  28.                 mov     ax, 4C00h 6 ^+ Y9 I  {' Y9 o3 e7 |3 e
  29.                 int     21h # t+ [3 }' N9 i  E
  30. 3 X0 Y! N9 u. K5 d1 B4 i* t
  31. msg_ok         db      "OK", 13, 10, "A20 $" 5 V, l( q. c2 T# Z  w
  32. msg_fail       db      "FAIL", 13, 10, "$"
    0 ?5 P; v  V7 S
  33. msg_en         db      "ENABLED", 13, 10, "$"
    - c6 e- R; p8 Z* F# s
  34. msg_dis        db      "DISABLED", 13, 10, "$"" r" K' B  r7 a* Z+ \
  35. : R& s2 s: O$ j4 D
  36. 1 s, T: _4 h5 x5 |4 B4 n
  37. _GET_A20_STATE_:
    ; e- j- k" S  q5 d* ]
  38.                 call    A20Write                ; Wait till the input register is empty
    ' Z" F9 g' F$ ~- Y8 O. N
  39.                 jz      exit2+1                 ; Bypas the reset int's 3 a- ^" k, G( o" F+ t/ `6 u
  40.                 cli                             ; Disable ints so we'll get our value & n( Z1 {7 C' f. x" l
  41. 4 W6 G) n; q8 Q7 \
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register + f' L% r( i7 B: V4 b: I
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port , P4 j% L$ L+ ^# {) a' y" G+ w# g
  44.                 call    A20Read                 ; Wait till the 8042 output register ( D9 D9 h5 c' K: f  A( s
  45.                 jz      exit2                   ; has something in it's buffer $ i: X/ ~: }3 X' \- b7 b3 `7 k% t% c

  46. , U" L4 G; B# Q! x- _) d4 I& f  K  @! Y
  47.                 in      al, 60h                 ; Get it
    % d+ i. \& [$ ?4 u* X3 A5 d
  48.                 mov     ah, al . k0 d3 p0 y( E) X3 G5 c
  49.                 call    A20Write                ; Make sure the input register is empty 2 O& f. \. q! O* l0 i4 j
  50.                 jz      exit2
    $ f) \6 S7 L0 I
  51. . R" x, Q# X( g( l$ S/ S5 Q0 c8 n) _
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ' {. J3 E! h  a% g% u0 r% M5 k
  53.                 out     64h, al * m9 }7 X) {, ^' O0 D2 ~, o: s
  54.                 call    A20Write , T- d  Z! d* G" G

  55. 9 o; w9 n' K9 e5 o
  56. exit2:          sti 3 I$ _+ X5 F3 R& t1 G$ j/ I
  57.                 ret! I" E9 Q( x/ Q. `; Z

  58. : H( X" E8 j9 a7 C6 b1 E

  59. . i8 ?, O8 q. ^9 \( I
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 2 y2 O3 _' t- i& }
  61. get1:           in      al, 64h                 ; Get KBC read status
    0 M. v  N0 Z1 e# O, a9 x" \4 C
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    " i3 C& H0 O; p& _, X
  63.                 jz      clear 8 J+ {6 X( J$ m1 y0 [: Q; P6 `: ~
  64.                 dec     cx
    ( l/ r$ T0 m9 t. F. V( Q% K  o
  65.                 jz      exit3
    1 s1 E+ s2 ]' {- B
  66.                 jmp     SHORT get1 * U% n: d$ j. Z5 W
  67. clear:          inc     al                      ; Clear ZR 1 M0 s6 D5 u% h; [. j# w8 g
  68. exit3:          ret 7 M( Z. a( ^" \4 E2 N# r0 j

  69. ' v7 R, C5 O" O+ d! o: W
  70. ) n5 `- e1 m8 j
  71. A20Read:        xor     cx, cx
    8 G1 }% c. [: x; w
  72. get2:           in      al, 64h
    . m1 L5 K! R3 ?* @- ?% u7 S
  73.                 test    al, 01                  ; If the 'output buffer' is full, has ( g0 @# e# ?$ m% u3 U7 t' M2 l# F% r6 z5 O
  74.                 jnz     exit4                   ; something for me / m0 x4 s; C1 e' Q
  75.                 dec     cx
    ! ?$ S* p- z" u* _
  76.                 jnz     get28 O" J1 k0 @! r$ G. l
  77. exit4:          ret     
    ) k$ s$ @5 {0 L! x
  78.                
    % X1 B+ Q5 z- O6 [* I0 @  u- K
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
! K4 H' k$ L4 t( T" p5 j+ [{        while(inp(0x64) & 2);        outp(0x64,0xd1);$ f' H2 Q7 m1 w# f* c1 o4 r, Q$ p/ n: S
        while(inp(0x64) & 2);        outp(0x60,0xdf);# A3 l; D) n4 u; Y
        while(inp(0x64) & 2);        outp(0x64,0xff);, n4 f4 R0 @+ a, D4 L8 Z- f$ a
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-22 05:15 , Processed in 0.069138 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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