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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM ! }% M7 M6 \" y- U' F
  2. ;
    6 B7 x7 U# k$ g5 ]7 ^# J
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ; P3 _2 k" q- ?7 H
  4. ;       ml A20ON.asm " j4 U& P8 i8 m7 Y9 ^0 {- L+ B
  5. ; 1 M% p8 B  m5 V' N( ^6 e' n6 f. y
  6. .model tiny: e( t/ H+ p; Z8 ]
  7. .code
    3 _" h' G/ W- A' L
  8. .4860 r! o* M: d0 {5 W: K
  9. .startup
    7 ]7 F- [6 O2 Y3 \( s9 w: W
  10. 0 H3 \5 E2 w! Z: a
  11.                 mov     dx, offset msg_author8 o- ]# u2 `! `- ?( y3 ]2 g
  12.                 mov     ah, 09h3 J( @- {( O5 U, h  J
  13.                 int     21h7 [- G7 w" S: `" ~9 v% f, M
  14. ' }+ ~" y) l  x2 ?
  15.                 mov     dx, offset msg_fail
    0 Y/ ~9 _0 `' G1 \
  16.                 call    A20_ENABLE
    : t0 I4 P8 x4 p/ R7 z* {; L
  17.                 jz      exit1; O- \" S6 j! a: _0 M- {6 A
  18.                 mov     dx, offset msg_ok : X4 J6 X0 ?/ n; O
  19. / }4 N% Q8 t+ s- W
  20. exit1:          mov     ah, 09h
    5 p* L# h9 n8 n6 A5 b+ Q
  21.                 int     21h $ Y$ V1 l0 M$ \" b
  22.                 mov     ax, 4C00h ; E8 M' |6 q  E  @& I6 p
  23.                 int     21h
    " n  T6 M* {& D4 g, ^0 a3 u
  24.                
    * v3 P$ e- I, O. L# j3 h0 T$ O5 T
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    7 I8 X: ?4 e- V
  26.                         "2008-07-01",13, 10, "$"
    2 o; W5 P7 R" n4 H; v* D9 B
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    4 @! b7 r; l. s0 H) u
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
      b5 W  ?6 G: e. b5 g
  29. 1 @0 j3 |: A! I. S  z+ N7 H
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    - w9 n4 H, L8 e: O0 a
  31. A20_ENABLE: # K' ]5 S7 j( H" A$ D2 C
  32.                 call    A20Write , \: `: t: \4 E3 O$ E* j* T
  33.                 jz      exit_enable  J* A5 \0 Q4 k  d
  34. ) d: L. f  W1 E
  35.                 cli                             ; Only need for reading value from KBC   D$ q/ _  e8 s# \
  36.                 mov     al, 0D0h   S4 k& w# N( T/ o6 z
  37.                 out     64h, al 0 g9 b& Q& c! C4 ^" Y# B
  38.                 call    A20Read - I, K9 Q7 V& J6 k6 o2 ^# E5 S7 Z
  39.                 jz      enable_int , |9 U6 R/ t' R3 r* ]- d

  40. + h  d) P( j- L; l$ ^' f$ I: |
  41.                 in      al, 60h                 ; Get current status & s, H9 F4 ^( Z) I0 D
  42.                 mov     ah, al
    ) b7 e9 z, L: N; m! K
  43.                 call    A20Write # L6 h% y  E* A2 u1 n
  44. enable_int:    sti
    ! ^. U& w5 G/ o4 l0 ]: c2 W
  45.                 jz      exit_enable# u6 Q5 h. H" s

  46. , g; @3 y+ U' P! m: I$ p! D8 W/ M
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
      T1 C1 \  O! _" V  ~) C1 d
  48.                 out     64h, al                 ; Out Put Port next + G& _$ E6 v  W+ H
  49.                 call    A20Write
    5 D; k- V2 E8 _) s" y
  50.                 jz      exit_enable2 Z+ Z' D$ w2 P# _
  51. 5 d3 I7 a' d& O- r6 x
  52.                 mov     al, ah / L1 p9 I  k1 O" a
  53.                 or      al, 2                   ; Enable line A20
    , r! f9 T! j9 A! o1 A9 V6 F
  54.                 out     60h, al & ^! A+ V+ {0 B* [9 G
  55.                 call    A20Write
    - s" u3 }$ W. E& \5 W
  56.                 jz      exit_enable
    ! E: q- ]  v- D. |9 J
  57. 2 O0 ^, I' p0 b8 l/ B8 a5 z
  58.                 mov     al, 0FFh                ; NOP ; n- m4 l6 o& s3 t) {6 h) c
  59.                 out     64h, al % _1 y' K# Q8 D
  60.                 call    A20Write
    / M5 \" C) E7 O  O, ~/ t
  61. " k, T! q$ c0 }; p7 j; `9 G
  62. exit_enable:          ret
    # O+ M; c  {7 ?8 p! c

  63. - Y* `7 n+ m/ a
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 2 c4 b" ]0 m# o  P6 f0 M  N- o
  65. get_wirte:      in      al, 64h                 ; Get KBC read status / H4 a& ~: o0 m. P- w3 E/ r2 c
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    , U! T; T6 S( A* q. p
  67.                 jz      clear
    ' S, X* b* ]$ K5 }! p7 j
  68.                 dec     cx
    0 r, H. t  s- L
  69.                 jz      exit_write
    5 [# P2 a! q4 C& f6 _! q0 H
  70.                 jmp     short get_wirte
    : O. Y- N" c, K3 I9 F( J: _
  71. clear:          inc     al                      ; Clear ZR
    # k- X+ m6 n4 [) x4 p
  72. exit_write:     ret 0 U: ]1 z3 ^) ]$ ~. ~
  73. ( T  n, R# P% k& B# [6 z2 R
  74. , h8 t  @" I  m7 R0 ~
  75. A20Read:        xor     cx, cx 8 v# Q; `& u' S
  76. get_read:       in      al, 64h
    : V/ P! Y5 r1 t9 {$ |. r
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 9 U1 }. l+ o2 Q1 v4 X" }: e- _
  78.                 jnz     exit4                   ; ... 9 R. b+ `! g) k. Z; q
  79.                 dec     cx
    0 B6 X- o0 G+ |5 G
  80.                 jnz     get_read# x- i2 ]. m+ p/ a1 e
  81. exit4:          ret     1 h9 N# W- L, W
  82.                 - c0 |! K# w* I; z. z" L( `  t
  83. end
复制代码
  1. ;A200FF.ASM
    8 N  m7 m3 R2 z6 X5 e' ]$ |
  2. ;
    , [' }+ I; V0 d, H
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01; t0 P& ]/ K1 b7 Z: m, p% a0 c
  4. ;       ml A20ON.asm 8 `' y- P* b  ?. S, o) V, u8 U$ d+ n
  5. ;
    6 |0 `' F) H1 l9 Q7 x0 {5 i& V2 A
  6. .model tiny- o5 M3 b- Z6 q) y
  7. .code$ l  L9 n4 r4 |. d# V9 ^
  8. .4861 K: J. q, B! A/ i
  9. .startup
    3 ~9 Q5 a1 d# z8 l3 `& _

  10. + }, C% N7 w: b+ Z
  11.                 mov     dx, offset msg_author
    " x( j; u0 _  q6 A  l9 l# U" H. W
  12.                 mov     ah, 09h& D: A- v4 p( u: E, a4 g- e
  13.                 int     21h- }& P$ O* z& s9 t5 }
  14. * J' U8 V8 v6 \6 k3 e: p/ \
  15.                 mov     dx, offset msg_fail
    ! `9 m: }( R. s  \! t
  16.                 call    A20_DISABLE
    3 t+ J: V7 Q$ O5 {% m. `
  17.                 jz      exit1
    " W7 j6 I- p/ r; R* s
  18.                 mov     dx, offset msg_ok
    5 B; X0 o; n( g) {3 t

  19. ' |2 b7 {& m# C5 z0 o4 P0 R; g
  20. exit1:          mov     ah, 09h 7 b; V/ ?7 e% Z0 r  W4 {- |$ R% }
  21.                 int     21h $ X' B6 _9 v: P- Q" }
  22.                 mov     ax, 4C00h
    ; B* T# ^' m8 D4 ^
  23.                 int     21h
    + A7 P% X9 d, @. u2 H4 i
  24.                
    * b+ `4 k& \0 P" q/ ?4 N- K
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    2 n' f8 c/ E. ~, W" J
  26.                         "2008-07-01",13, 10, "$"
    ; {" l& U$ U. w! F
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"   ?# w* E9 N* ], c* O! L6 [0 f
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    - e, e5 V9 c: R8 }4 K
  29. 1 B# z9 |9 `& e! C/ q
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------5 I/ l& P0 Y* T. C/ J
  31. A20_DISABLE:
    ( X+ q8 `8 s0 [6 f+ D% P' k
  32.                 call    A20Write
    - Z! i& c) C" A; [/ m9 u' A
  33.                 jz      exit_disable+ }. i  \2 B/ Y9 C, M' q9 y

  34. 2 W1 {; N1 f7 V9 z  t- Q, U+ u
  35.                 cli                             ; Only need for reading value from KBC 1 Q" E& z! e1 ?/ A$ g9 W
  36.                 mov     al, 0D0h 3 Z9 C3 ^' b: Y/ u5 g1 i- g
  37.                 out     64h, al 1 g2 _8 Z1 G& s: j# e" w
  38.                 call    A20Read
    - L$ }( y9 A2 o1 ^- V/ c7 z
  39.                 jz      Disable_int
    : ^0 G* z- B! B1 g( D

  40.   ~4 e' L4 K1 u* y3 `& N
  41.                 in      al, 60h                 ; Get current status
    9 U' ?8 @, N" j
  42.                 mov     ah, al
    1 ]; m# j0 b9 @& D0 y, }
  43.                 call    A20Write ' w1 |- H) {% Z7 ]
  44. Disable_int:    sti # ]4 C- x+ G' [8 t
  45.                 jz      exit_disable; y( d1 o1 n/ _2 _+ m* H0 T4 \

  46. 2 l; n4 F" M  B: w
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the : |- ^7 D; t; ]& h2 z. B
  48.                 out     64h, al                 ; Out Put Port next . A1 v/ B. a: s: v: a
  49.                 call    A20Write / M! {' ?$ m& p: G
  50.                 jz      exit_disable
    ) ~; j7 Z! b: x2 ~( H+ j

  51. . y- l. x# V9 g, _0 c
  52.                 mov     al, ah
    9 n4 x+ C8 l; Z* {' {
  53.                 and     al, not 2               ; Disable line A20 , D, F5 R* w9 t: X1 Y
  54.                 out     60h, al 1 j* V6 T( Z: B0 Y
  55.                 call    A20Write 8 b4 _( }; @7 n7 Q$ A
  56.                 jz      exit_disable7 f8 j2 j2 |7 h5 m% k/ e7 p

  57. % W' [9 p- d2 |, H- N  u; [/ V6 m
  58.                 mov     al, 0FFh                ; NOP   ^6 {- h! d) a( u
  59.                 out     64h, al
    9 v- t" Z. S# s2 V6 P
  60.                 call    A20Write
    & m4 V& {3 }: j9 q# q4 X/ D# Z9 Z* N
  61. 2 {  V1 _5 N1 z4 a$ @5 D
  62. exit_disable:          ret 7 {5 i  t, D: R; ~

  63.   _0 g% ]' G7 }9 h
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ( \& H  O7 e! v5 |
  65. get_wirte:      in      al, 64h                 ; Get KBC read status * T& i% l8 z9 n1 I
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 1 j5 _. G8 ?# C/ ]: ^# |
  67.                 jz      clear
    1 F, D1 O( _# j
  68.                 dec     cx
    2 Z! I+ h  c8 N/ e% A4 i
  69.                 jz      exit_write
    * g9 B2 @8 Z6 Y
  70.                 jmp     short get_wirte " y5 s1 e- h- o7 P$ ], F. J' V- Z
  71. clear:          inc     al                      ; Clear ZR ; n# u  l- }6 a8 D4 y8 z4 b4 p3 G
  72. exit_write:     ret
    9 B$ U8 L+ P& G- g2 M

  73. 1 F9 B/ X/ _) a6 m

  74. 0 X# U! T6 \+ K' E6 R4 k
  75. A20Read:        xor     cx, cx
    / I' f5 P+ ~6 a/ o+ a
  76. get_read:       in      al, 64h # ~4 ^6 v6 N5 a, L0 Z/ g
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 6 w: U' s" N  j, _6 C; o- N
  78.                 jnz     exit4                   ; ...
    / A9 V4 X( t" S) F) _5 f+ S% c
  79.                 dec     cx
    ' A" `- h, B& ]8 A2 ^3 T
  80.                 jnz     get_read
    # i3 j5 M' @5 h. L
  81. exit4:          ret     ( d, ~# }4 Z9 D6 d( l
  82.                
    * _. X# v" w  c7 M" o; P0 O
  83. end
复制代码
  1. ;A20STATE.ASM + f: K- [; a" ]4 M; ~( d( ~' v
  2. ; % V1 w. N  I- ~  p4 W. W
  3. ; Returns the status of the line A20 through the KBC
    6 z5 J4 F( Y# o) U) K
  4. ;       programming by bini for debug. 2008-07-018 }! P8 L4 R: `6 U5 s6 `
  5. ; ( l! g- ~8 h  m8 H2 Z: h
  6. .model tiny
    , e6 Z7 h! o" C+ I$ N, r0 ^; _  A
  7. .code% ~' [2 O- W  m, g. _
  8. .486
    ) W- G) l/ t1 m8 K
  9. .startup  W! F- }( Z' Y' l" t% w' h+ [3 N8 |
  10.                 mov     dx, offset msg_fail ; [/ Y( C4 a- S; q, K7 }6 g, P7 D  Q
  11.                 call    _GET_A20_STATE_
    " s$ ]/ O* {8 `% D' a6 p8 g( @
  12.                 jz      exit1                           ;  was a problem
    / Q& z4 a( V3 k. ^- b' K
  13.                 push    ax                              ; Save state, AH , Q& D" }' Z* W8 _) K! C! f5 j5 i% l$ u
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    % s! v2 ^$ O9 r
  15.                 mov     ah, 09h ( a7 Z6 j3 X6 X4 L
  16.                 int     21h                             ; Print message - F+ r* b$ p- m/ b5 y- K3 P
  17.                 pop     ax                              ; retreve state
    , d9 i8 o; h: x  g8 r
  18. ; ~; H5 ^1 d  V. `3 g' x/ U
  19.                 mov     dx, offset msg_dis
    * V, M) t2 t5 x, T
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    9 D0 E( M, D+ [4 R! k
  21.                 jz      exit1 ) l; [  a$ F! m! O; D& y
  22.                 mov     dx, offset msg_en
    + i$ p0 o: l. s+ E/ J4 \
  23. " ^3 k7 X" Q. c% {/ k
  24. exit1:          mov     ah, 09h
    ; B2 i% L' {! Q3 o
  25.                 ; DX already contains address of string ! `  X# R& N- \! m
  26.                 int     21h
    3 K! |- l" k, a! ?& z

  27. 5 c) l; f9 B/ t% M. n
  28.                 mov     ax, 4C00h
    . C$ K. J( s) R% D. ?
  29.                 int     21h
    7 v" G) H; a$ m# G
  30. 8 H1 y' i1 u/ B- D
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    . O, `1 u- p! w- n5 C  `
  32. msg_fail       db      "FAIL", 13, 10, "$"
    ( ]  V" V" ]. z7 ^/ G# X# H7 i0 o8 Q) K
  33. msg_en         db      "ENABLED", 13, 10, "$" 4 l; l5 }/ D: b1 C9 F
  34. msg_dis        db      "DISABLED", 13, 10, "$"- C; _8 `3 g! f3 Z' `; L  M

  35. 5 a. \! \9 M" X1 P4 l1 L0 W

  36. & _% n( u" q# o8 k( C- x$ H7 F
  37. _GET_A20_STATE_:
    8 A# M7 z7 D; d! N. t
  38.                 call    A20Write                ; Wait till the input register is empty
    & N! y9 r# X8 l: n8 L
  39.                 jz      exit2+1                 ; Bypas the reset int's % P" I. j! J* ?
  40.                 cli                             ; Disable ints so we'll get our value ; q: ?0 T+ a8 A: L0 \- E! y
  41. / m6 }" Y+ H1 Y% x( x) Z* j& F
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    $ f$ s; M( j: H7 U; J
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 8 N% Z- O2 I1 q, I: d
  44.                 call    A20Read                 ; Wait till the 8042 output register
    3 o# D* F+ [, D9 L0 }
  45.                 jz      exit2                   ; has something in it's buffer
    8 v( Q' m8 ?& k/ f
  46. 1 o: m' s, ^- x' q/ A
  47.                 in      al, 60h                 ; Get it
    7 z/ K5 X" A4 w* w7 H! |
  48.                 mov     ah, al
    . c4 ], V4 B! h, H! Y
  49.                 call    A20Write                ; Make sure the input register is empty ! l* ^1 y  M* ^: w: q) ^2 k/ o5 e
  50.                 jz      exit2
    4 J; G8 t& h4 U: v! S  m
  51. 0 z; O3 o. \5 Q& A; q% |$ z
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    , \4 W5 }* f8 I6 L- U: V
  53.                 out     64h, al 5 E) a" j' J' W  L) m
  54.                 call    A20Write
    , o1 {, l- |3 w3 ]5 J+ z6 a( \* v- L

  55. ! W7 q0 ~: q3 Y
  56. exit2:          sti 9 ^# Y8 R, m# F
  57.                 ret0 c4 `' b' X- Q
  58. ) S: p% g9 ]3 Y0 s
  59. # y* R9 O2 {/ d% J2 w  x' X1 _1 }( o
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 5 r3 N" X& D/ V7 M4 Y& V: t
  61. get1:           in      al, 64h                 ; Get KBC read status
    # H# q, r+ d6 q: r
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear 6 M" B7 a' Q- e% v( H4 w
  63.                 jz      clear ! U; _! \7 p' j: b& _& m9 B
  64.                 dec     cx 5 b9 A% b3 L; f8 A, x+ p* s
  65.                 jz      exit3 * R3 A! H2 \, X# e5 z. i- u
  66.                 jmp     SHORT get1   l; y. W; E; c
  67. clear:          inc     al                      ; Clear ZR 1 n. ~( \( V3 {0 L8 r
  68. exit3:          ret
    2 Z7 [6 F: ]. r/ Y: J1 ^( B1 g7 f

  69. ) u# n" e" p$ Y4 p# s
  70. 9 E8 J" G; @& e" d( v5 h
  71. A20Read:        xor     cx, cx
    + n. A* ~* [- N2 T4 w
  72. get2:           in      al, 64h : x/ o; w) u9 A7 T" G
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    3 @$ v7 N' v  X5 W  i# X% T/ Y3 \
  74.                 jnz     exit4                   ; something for me 4 d% t7 H9 w# x* Z1 X
  75.                 dec     cx
    9 p% e$ A( m& ~- q# S
  76.                 jnz     get2
    7 q- h/ h7 j4 O9 E
  77. exit4:          ret     6 u$ E# Y3 f$ H1 ]3 q+ W3 u, E. g5 x
  78.                 - F8 D5 f4 z7 N4 u9 ~
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
8 F5 s, h  q$ g( w% Y{        while(inp(0x64) & 2);        outp(0x64,0xd1);+ p2 `5 N2 W6 p) x: w
        while(inp(0x64) & 2);        outp(0x60,0xdf);
2 [/ {3 g# [1 V% r        while(inp(0x64) & 2);        outp(0x64,0xff);
5 ~; U* d. [- U9 L4 ~4 @/ I, G}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-1 20:28 , Processed in 0.168389 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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