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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    - w( G: O/ S8 T: ~. ~
  2. ; : h' H' a0 z6 W) @+ N5 F
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-016 t9 T  J) o- y
  4. ;       ml A20ON.asm
    : |) b4 k) g+ w7 R" M! d) |/ z
  5. ; 0 m" F  M/ |  `" R4 [
  6. .model tiny
    # `2 T' n7 `" T  D+ c, K& M- h
  7. .code% H  A% O6 Q, G' j5 |
  8. .486
    + y+ P& V+ f* f4 d
  9. .startup
    5 R2 h. T  l) _

  10. 2 z! j$ e6 w, }2 F
  11.                 mov     dx, offset msg_author' L2 \2 F1 Q% J& v/ w
  12.                 mov     ah, 09h
    . D. j$ C4 A5 o4 S5 W
  13.                 int     21h
    * ~: c6 N5 v- U& H' D) V, Q
  14. . f, m$ G1 J+ _' j) g5 f
  15.                 mov     dx, offset msg_fail 8 H0 F. ^+ @( z7 o
  16.                 call    A20_ENABLE
    1 M5 O0 g5 t$ ?
  17.                 jz      exit13 p( U% g5 A3 m5 F7 p# U+ h
  18.                 mov     dx, offset msg_ok * B- @5 W1 S  D3 ~
  19. ( }3 B5 ]% L$ u
  20. exit1:          mov     ah, 09h . Z, }. n1 V- U. `5 [
  21.                 int     21h $ t% B% G, X) I4 r% k" q2 n
  22.                 mov     ax, 4C00h " X- y: v: l: _7 j8 {
  23.                 int     21h
    5 `9 g/ w$ t1 r$ a
  24.                
    - x5 W) z+ M  n- R- [" K
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    & R( V2 H  }0 P* |) i$ L0 y
  26.                         "2008-07-01",13, 10, "$" ; R  i$ n7 H  B2 C3 v
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ) S, k! D  [6 P8 e- N
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    ; j% ]% ~# j- W6 U+ l" P9 v8 ^

  29. 2 M; l" I2 Z* j2 }
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------7 R0 y2 U: e0 k) \: T3 `
  31. A20_ENABLE: ' ^' p' c! s5 T8 [1 s+ `
  32.                 call    A20Write
    & {0 ^( @1 x4 ]" Y3 D, }
  33.                 jz      exit_enable& m( m" C5 n! v+ @

  34. ) G# Z8 J$ H1 r6 h
  35.                 cli                             ; Only need for reading value from KBC 9 N: o9 Q( f3 T
  36.                 mov     al, 0D0h
    0 T2 n+ n. \, Y: O& z
  37.                 out     64h, al
    8 Y* \7 T: u2 C" d& o2 L
  38.                 call    A20Read 9 `' T2 ]- B/ \7 [
  39.                 jz      enable_int 0 n$ l: k' E% p2 C
  40. - l; o0 S# |: z5 m" y! R
  41.                 in      al, 60h                 ; Get current status 3 ?2 z. w. \6 @0 L- J& \
  42.                 mov     ah, al
    / e( e! m& W: E: b. O/ }; z
  43.                 call    A20Write
    # I* E2 ~$ @* o. {2 K! C
  44. enable_int:    sti
    . i/ x- X  E/ t+ g1 d
  45.                 jz      exit_enable9 ^3 C% A3 ]8 T* O

  46. + i8 r$ j" n# {6 m5 R( I; e3 Z. r  R& {
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the & s, V) V' \* E" N, ]5 y( r: U' L$ P
  48.                 out     64h, al                 ; Out Put Port next 3 q2 @: b5 ?6 B
  49.                 call    A20Write
    ! l5 E! p9 s4 s, T
  50.                 jz      exit_enable
    ! x' G: l( L& _: j6 a) H" G
  51. ) F$ v% ]9 b3 r+ r6 ~
  52.                 mov     al, ah
    " Q4 m2 \5 |! y6 j9 f
  53.                 or      al, 2                   ; Enable line A20
    4 R; n" Y, \. `
  54.                 out     60h, al 1 T; ~* g0 N* a; X7 r$ n
  55.                 call    A20Write " m( y- T! `4 U
  56.                 jz      exit_enable
    6 Q3 U4 C' \# d3 H, Q# U
  57. + k( b6 s2 b' R0 y& c" K
  58.                 mov     al, 0FFh                ; NOP
    5 d9 p# W7 D6 m! a4 D: `8 Q( }
  59.                 out     64h, al
    4 ^6 E: H9 @% @4 K
  60.                 call    A20Write
    ' U% ^- c' J0 I3 R7 f

  61. 0 l1 Q% u, i# h1 G5 f4 U* Y8 Q( Q
  62. exit_enable:          ret / V* I% x  F5 x

  63. 2 L0 M4 A# i+ f& t# J9 m1 T" t
  64. A20Write:       xor     cx, cx                  ; Reasonable wait ; {" e5 s; K# i
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    , y7 E/ K' u, d3 g; ?6 _2 G
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 2 D0 s! c6 C$ }- ?# W1 C
  67.                 jz      clear
    7 C$ S9 T' E: h9 C
  68.                 dec     cx 3 a1 f' ^( T0 Q5 J
  69.                 jz      exit_write
    : d) {$ u% R' v" m" `, m
  70.                 jmp     short get_wirte ' b" a8 q% @( H3 U
  71. clear:          inc     al                      ; Clear ZR ( t2 o) N7 C0 ~3 q$ D' h
  72. exit_write:     ret
    , Y/ U* a, O- b$ K! [- W1 e/ Z
  73. 0 P& y& V9 F1 a" K4 F" H

  74. 2 l9 r6 V# _9 d+ y. r: ?$ o$ Y" ^1 i
  75. A20Read:        xor     cx, cx
    ' W' h% B/ L8 x% g
  76. get_read:       in      al, 64h
    - b) K+ g" V& g  S+ l
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ' w- C* b( j7 l3 I
  78.                 jnz     exit4                   ; ... . ]/ p  x5 T' L2 y- S
  79.                 dec     cx
    ' M1 m5 \$ G# y# P2 v8 L# U
  80.                 jnz     get_read9 O4 U, l. Z7 b. @$ I+ T" x3 @
  81. exit4:          ret     
    0 p9 Q8 u2 T0 p( f  |& H
  82.                 # a9 Y( u; F* D/ \- f
  83. end
复制代码
  1. ;A200FF.ASM ) N" }( S: J* I
  2. ; : w9 X" f1 E. P9 K, p7 |
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-011 f% r' a# ^$ c# r
  4. ;       ml A20ON.asm + d' k' O$ I8 H' Z( I: m& N
  5. ; # l, z  e) {1 D  V
  6. .model tiny
    3 _8 Q: z. o: a4 K6 O
  7. .code
    $ i6 p$ B2 s0 M/ A) P$ b5 q: c
  8. .486
    8 S6 s! u* e( X# \9 q) Y9 W; J5 L9 S
  9. .startup
    ! G. c2 O+ @6 J: ~; H
  10. 4 }3 d' j% e3 U: r2 [, d
  11.                 mov     dx, offset msg_author, }  Z( G& S. W
  12.                 mov     ah, 09h
    ! B5 l0 w7 J2 C1 u$ U
  13.                 int     21h) k) u& m  a7 g! z

  14. , N! Y, w. e2 [, ^0 N# N& y5 m; @
  15.                 mov     dx, offset msg_fail
    7 e( [$ C0 }- O# i6 Z* I
  16.                 call    A20_DISABLE" a( a- F; \3 H
  17.                 jz      exit15 H; j* v) e4 c2 W. {5 H
  18.                 mov     dx, offset msg_ok - u. x% s3 n2 O1 k

  19. ' o$ g# E1 ?- R& F0 W+ s- t
  20. exit1:          mov     ah, 09h
    * r. u; ?. }) Z  g) j  m
  21.                 int     21h / r# N2 ^* M: m9 @# C
  22.                 mov     ax, 4C00h " w5 T4 C; z" y+ y+ o
  23.                 int     21h 3 y" [& N7 j& L$ [0 Q; k+ j
  24.                 % S" {5 \& W5 P
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    ; j  d% r  l* A4 C% M
  26.                         "2008-07-01",13, 10, "$" : ?8 h) e# R" g) X: ~$ \0 S
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" & b/ o  N, b$ \9 }) O3 Y7 @
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    ' e8 L7 I. M0 j3 L

  29. 2 T  v( h3 p' F1 J
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------; Z8 D5 b8 D- T3 S" u
  31. A20_DISABLE: 2 B. J) Z7 [' t6 s7 I
  32.                 call    A20Write
    ; b0 A$ v6 l/ b
  33.                 jz      exit_disable
    0 \! U1 i! h2 M) D" A( c
  34. 4 h  y3 b; O7 p5 m$ e
  35.                 cli                             ; Only need for reading value from KBC
    ' v( @9 h2 R' W6 e: l
  36.                 mov     al, 0D0h ; ^( {, F- t/ Q) h1 n
  37.                 out     64h, al 8 w5 ~& D* T3 N# k. l  g
  38.                 call    A20Read : S9 r' u7 E& B
  39.                 jz      Disable_int 5 I- D. R. ^% W( ~
  40. # D: L  S, i' p* d! o" h8 O
  41.                 in      al, 60h                 ; Get current status
    + H# h+ A" |% V3 O1 j
  42.                 mov     ah, al
    & F$ U0 h2 _% K/ m: e+ G5 ^. M3 d
  43.                 call    A20Write - o% |6 Z$ a5 X: i" D5 [
  44. Disable_int:    sti 5 k' `0 R' `: Z0 X+ v, T9 T& u
  45.                 jz      exit_disable
    ! E, p; A% f/ }- S, G; E7 O$ W! q
  46. " D6 D5 o6 O  O
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 4 T" a) V6 L2 L0 U: l( S
  48.                 out     64h, al                 ; Out Put Port next
    ( Z; i# E8 |# Z5 E' U- q& @
  49.                 call    A20Write
    8 K4 E; x$ ^8 a, c  ?0 a* u# i
  50.                 jz      exit_disable
    . Y5 t) V& |2 `& Y

  51. ! }( U; T$ z2 E$ h8 d
  52.                 mov     al, ah
    + G$ h" }# E1 E, Y
  53.                 and     al, not 2               ; Disable line A20 & \# |# q! H& [. ~8 F/ `& z2 x
  54.                 out     60h, al
    " t1 G8 r# q0 h1 g3 r
  55.                 call    A20Write
    + p4 X9 W# B, u( j
  56.                 jz      exit_disable
    - b' Q  j8 G8 N) M( {  |' I2 }6 R

  57. # N/ X9 ^  ~/ A4 A6 l9 }! G! P
  58.                 mov     al, 0FFh                ; NOP + T9 J0 V% j4 p. a3 W
  59.                 out     64h, al
    / y7 I& ^- U' U
  60.                 call    A20Write - N$ \2 q1 E5 G" Q4 }" i3 H

  61. 8 T" j: Y! t# Z0 u5 l
  62. exit_disable:          ret 2 g4 B" C( X( ^2 r: _2 q8 X% S

  63. ) i# ^& s6 n/ q. \6 }" \
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ( H3 j" v# C  P7 k! Y" I
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    7 o+ R/ f+ O) K7 b
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 6 r. ?0 R# i5 P
  67.                 jz      clear ! E: D- {! ?3 Q" T# _3 w, d3 {
  68.                 dec     cx
    8 P! N6 Z" q: d+ [. F7 C8 w" d
  69.                 jz      exit_write $ Z2 T; S4 _6 ~9 T( K
  70.                 jmp     short get_wirte 8 v1 Y( |$ w, E  ?0 e
  71. clear:          inc     al                      ; Clear ZR
    4 e) h0 W/ o6 p% v* P1 @! `. s
  72. exit_write:     ret
    ' ]4 l" |5 p3 B# s  y2 K4 H0 g

  73. / i; M) e% |$ R* b& u& Q
  74. - j4 D+ v6 z1 X
  75. A20Read:        xor     cx, cx
    , ^8 D1 `* p+ y2 y# m" ]
  76. get_read:       in      al, 64h 2 f) a. S+ [. O8 s
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ! E; p" D. K  k! k
  78.                 jnz     exit4                   ; ...   \2 D# R* p( N" ]
  79.                 dec     cx ) {& V7 a( x: L; S) d9 p& n7 Z
  80.                 jnz     get_read' a- p! I  C/ j# u1 T
  81. exit4:          ret     + a5 ^& S# y2 R2 c4 e4 K; A5 C. g
  82.                 4 M4 ^9 l. k5 g0 v4 s
  83. end
复制代码
  1. ;A20STATE.ASM
    / K% {1 p9 h( w/ }: k6 n" D
  2. ;
    2 n5 x# r4 a7 j+ {2 F) [# ^( t" k
  3. ; Returns the status of the line A20 through the KBC - v6 z" w% f& f, }6 C
  4. ;       programming by bini for debug. 2008-07-01& E( o6 R# n$ r& g+ d- y
  5. ; 2 T" D- k4 ~! Z: v; m8 T) h) Y
  6. .model tiny% S& h: X# j; O0 E
  7. .code, y$ ^" H/ p7 i. e5 S# d
  8. .486  V4 v4 E% {7 F8 ^6 x3 c2 C  F" I
  9. .startup3 e% w% m/ r$ r0 V
  10.                 mov     dx, offset msg_fail
    7 w$ N! F3 _1 v" C$ E5 F: H
  11.                 call    _GET_A20_STATE_" N8 k: z: {! g  H4 K2 p( T( H
  12.                 jz      exit1                           ;  was a problem
      j9 v) i2 S* k2 \' k* `
  13.                 push    ax                              ; Save state, AH
    ( |* r3 y# W) P' ]2 d, q; N. h
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem ( n* G9 Q- H! ]3 I
  15.                 mov     ah, 09h + b( e3 y/ }- Q& P; E, P6 G
  16.                 int     21h                             ; Print message ; T$ J4 T3 F; Z8 B' p3 K0 }9 d
  17.                 pop     ax                              ; retreve state 5 q+ H  {& `" i- N2 ?
  18. # V# ]; ^& X2 u# ~, \7 q, w
  19.                 mov     dx, offset msg_dis
    1 k* a1 N4 H6 q6 |
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state 8 @5 G3 g8 g* |- H2 M$ `: t0 r
  21.                 jz      exit1   q& }. m9 Q3 k! }+ h
  22.                 mov     dx, offset msg_en 8 B* z1 x# h! C% E  z4 i

  23. 1 Y' m/ W  L# Q4 z$ F' E
  24. exit1:          mov     ah, 09h
    # t2 [' h/ t. F$ o
  25.                 ; DX already contains address of string ; b4 D+ w* ?8 Z. t% X
  26.                 int     21h
    $ _3 O. K" F/ ?
  27. ' X( }* s& k: g1 H6 x1 s+ E
  28.                 mov     ax, 4C00h , u! d) Q2 h0 g1 b7 |$ ^1 L5 d
  29.                 int     21h
    ) s, K) I0 {/ S2 L
  30. 7 ~/ P: O9 _3 R: z) I$ F* K6 i
  31. msg_ok         db      "OK", 13, 10, "A20 $" / c* [. j# ~  g- t) j. n
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ' Z, G; [5 s# f
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ; ~3 y6 x1 [5 e; `4 f
  34. msg_dis        db      "DISABLED", 13, 10, "$"& K  a: {9 ~) o; q) H8 ^; S
  35.   y+ [' f" L5 E% A+ T
  36.   W1 `( x0 P# M' M" y4 g7 H3 j; h- f
  37. _GET_A20_STATE_:
    8 e) h2 k$ |/ |- G$ c" y
  38.                 call    A20Write                ; Wait till the input register is empty
    . e* c; z) c: t2 S# J! d
  39.                 jz      exit2+1                 ; Bypas the reset int's
    6 C! C4 @' H) T& Y
  40.                 cli                             ; Disable ints so we'll get our value
    2 g3 ]# l6 u6 ]% _1 r5 w: @! T) {% [

  41. ; x& X' r8 o6 s' E( M8 n
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register ) Z* O( j5 X! @8 p6 W
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 1 D/ q$ R5 P& \- F
  44.                 call    A20Read                 ; Wait till the 8042 output register / l3 w& `+ U7 [# c7 Q
  45.                 jz      exit2                   ; has something in it's buffer
    3 |3 s( ?4 x5 {9 j- z! U1 b

  46. 2 E# r+ k: [  F9 P+ n3 F
  47.                 in      al, 60h                 ; Get it ) M9 \0 O8 L' g1 p
  48.                 mov     ah, al
    $ S$ ]6 I' e- E. @' c- V& D
  49.                 call    A20Write                ; Make sure the input register is empty 8 n( t" O! i2 I3 l( F. V4 r( m
  50.                 jz      exit2
      d4 I2 _  ]& R

  51.   }  D3 G5 W$ r4 v- c% q
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing : J( L# i4 _; B8 P; b2 S, R
  53.                 out     64h, al ; a0 O2 W. o! r8 r+ C
  54.                 call    A20Write : F2 ^0 V  t6 r
  55.   ?' z: k3 |4 U$ b( Q( p& _
  56. exit2:          sti
    & r( L/ \% u* e2 J$ o9 h7 a% c
  57.                 ret& N( p5 Z- l- f- d1 ^/ v* v9 ~1 O

  58. 4 N! g) q5 }4 m# L$ }5 n/ k+ _9 S
  59. 4 O  j! ~  H8 F" ?( Y5 H+ A9 A8 D
  60. A20Write:       xor     cx, cx                  ; Reasonable wait $ }5 p! H3 g& o9 P( Q# F
  61. get1:           in      al, 64h                 ; Get KBC read status $ P# X0 r2 q1 \% D, L* y0 A
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    % I2 s- V* _1 r. M' T
  63.                 jz      clear
    5 [9 j" `( Q# ^5 S) ~) i( C
  64.                 dec     cx
    . \, C8 Q% u8 f4 P% s% U' F
  65.                 jz      exit3
    % k* [4 s. F8 {5 G# w* y
  66.                 jmp     SHORT get1 ' _1 u5 H: j; g' C  h
  67. clear:          inc     al                      ; Clear ZR 1 W* n: K* R$ o/ ~% G1 Z3 `
  68. exit3:          ret
    1 ~( M4 H! q( q/ p1 z0 a6 [

  69. ! O9 \. T7 G- f
  70.   u' `& v4 b9 D" Z3 |. T7 x9 z
  71. A20Read:        xor     cx, cx
    / H4 }8 D) w9 ~! S. n
  72. get2:           in      al, 64h
    2 P+ p' X) f& B( z1 S2 v7 u3 _* H
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 4 c, n2 V) A, J6 p/ D$ ]; h
  74.                 jnz     exit4                   ; something for me
    5 Y4 F" K) ?) V5 _0 l3 ?( g2 o
  75.                 dec     cx % e5 Z; ^, z! K' Q2 L
  76.                 jnz     get2
    " }# {2 \9 l) ]8 a* K& w2 \* d
  77. exit4:          ret     
    5 X& ?) v. g+ y0 K4 e0 x
  78.                 % F9 W* k! `+ s. l
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()+ A% p- Y" l3 t0 }4 l- \  Z# y; X
{        while(inp(0x64) & 2);        outp(0x64,0xd1);! J& \5 |; G$ I/ s- S& ?/ A& U
        while(inp(0x64) & 2);        outp(0x60,0xdf);
: t. C* s0 y+ k1 X0 b! [& H- g        while(inp(0x64) & 2);        outp(0x64,0xff);
+ d* L1 q+ ^3 Z" c# F% }* ~* L}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-4 01:51 , Processed in 0.771180 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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