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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM . Q: R& x9 j1 R; J
  2. ;
    7 F& h* Y( m/ R3 X3 t" n* ?
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    - X3 g9 ^2 |$ b8 I% d
  4. ;       ml A20ON.asm
    - W0 R% A0 o+ A7 G
  5. ;
    3 k. j2 v4 I- ?* ~( d1 E& b8 z
  6. .model tiny
    1 D  O4 p) a( ^. n$ K
  7. .code8 f% H7 _- v0 C/ j1 w: ]
  8. .486
    . }7 H" d' F5 m- J: o; Q" G" u
  9. .startup
    ( ?1 ?$ {3 k+ Z
  10. 0 p$ D# t- q( A! R7 X
  11.                 mov     dx, offset msg_author
    / C8 n2 W/ q  U/ `& C( p
  12.                 mov     ah, 09h
    ' Z9 H* E/ a) i
  13.                 int     21h9 U& k0 \3 {6 j$ L  e1 {

  14. : y' d5 v% T2 D5 l
  15.                 mov     dx, offset msg_fail : k, y9 d( h, y  S
  16.                 call    A20_ENABLE  Q% i! l' c4 b: q. I' |* j* O( H; \
  17.                 jz      exit1& f5 c) y4 ^" h, C' w, Z
  18.                 mov     dx, offset msg_ok # U9 V& |3 N9 \2 L
  19. * ]! G' K. R; Y) l! f
  20. exit1:          mov     ah, 09h " r3 a' [: ?8 E1 i6 J# I3 x
  21.                 int     21h " R# o4 f, I6 O8 K# c2 T
  22.                 mov     ax, 4C00h
    ' E5 ^+ m0 r3 h3 b
  23.                 int     21h 5 M0 H' d8 v+ C# z: k9 f1 i( i$ k- ^; t
  24.                 8 K( J$ f* V% t$ d# [
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    ) B; S9 H; q7 }- _' p- A- d/ a
  26.                         "2008-07-01",13, 10, "$" 7 M2 I3 u# u0 t- l
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" ! i- Z! R+ H; {: s
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    1 q4 E% _- O. O. I2 i- W; _9 g
  29. - X. @+ o/ J2 ]$ ~! N# {& _
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ! Z7 v5 |/ i* V! S' o
  31. A20_ENABLE:
    3 ?5 w1 w; r0 m0 N
  32.                 call    A20Write
    6 ^4 Z/ c, q( g, t! f
  33.                 jz      exit_enable$ f" w, x9 m& j$ j; j$ r
  34. ; Y% w) ^% R; M* s! }2 C
  35.                 cli                             ; Only need for reading value from KBC
    # _% \, a* f/ W2 c6 ]$ Y) Y7 u9 K
  36.                 mov     al, 0D0h . ], {- P' s; [) K* w
  37.                 out     64h, al
    8 L) p; N; X; u* S
  38.                 call    A20Read   a* M# U3 b5 ]
  39.                 jz      enable_int 9 c7 r$ U7 U5 B4 f9 \! f

  40. * W& P$ ]" w5 ^1 W7 f, D1 {
  41.                 in      al, 60h                 ; Get current status
    ) Z) t1 Y, c' e
  42.                 mov     ah, al
    2 K7 [. o& y3 u- g7 @
  43.                 call    A20Write
      ?8 A3 X1 [( g6 U  x
  44. enable_int:    sti
    " T  ]' i. L9 ?
  45.                 jz      exit_enable
    , E9 n+ @* I/ T1 A" D  }3 u; O

  46. # S4 z7 c/ g1 M4 x, Q
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 7 H0 E" z, C8 Z- b% N: r
  48.                 out     64h, al                 ; Out Put Port next ' G4 w. `( s2 K0 y7 h, |
  49.                 call    A20Write
    7 T) J! h: ?* b# t5 ]
  50.                 jz      exit_enable2 p+ G; U/ }' Z

  51. : E9 p- ^$ N( c
  52.                 mov     al, ah
    8 g. w# N+ o* U- U8 U
  53.                 or      al, 2                   ; Enable line A20
    , D3 _+ t. l) ^. \
  54.                 out     60h, al ) c9 n+ h' Q7 z6 H' m3 U8 k
  55.                 call    A20Write 8 }; I# j6 p5 u4 D3 ?
  56.                 jz      exit_enable
    6 A* y9 c  B  A7 U/ e
  57. 1 s+ r) i8 e' ]/ _
  58.                 mov     al, 0FFh                ; NOP # ~2 ?% Y4 ^, K/ W6 [
  59.                 out     64h, al
    $ o! p& v) e9 m  {
  60.                 call    A20Write , E  M! ?1 P4 R
  61. - V. P, A! |3 l6 i% @
  62. exit_enable:          ret
    " ?0 m, l$ U7 o: y
  63. 7 P" e4 p0 @8 X9 |) W
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    $ S6 E* k% A1 ~8 O3 e
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ! @) Y! g# L1 G' @6 Z) h
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    0 H% R4 G7 z# `: y; E
  67.                 jz      clear 0 F* f$ y7 x' C4 v
  68.                 dec     cx   p2 A0 {& {! p4 h! W& M. j/ F
  69.                 jz      exit_write & f: J; Y$ r9 x
  70.                 jmp     short get_wirte * s/ v6 u4 Y* M3 Q5 M" [
  71. clear:          inc     al                      ; Clear ZR
    # B- y# @8 ~$ l4 \
  72. exit_write:     ret
    2 h. Z+ F# |3 a" d1 l7 I/ o* y5 ?- |3 ^2 Q
  73. ' P, \- V3 ~" c& a

  74. ( C& \* Q- s* f9 g6 S. L) ^) ~
  75. A20Read:        xor     cx, cx # Y7 \' {" _7 z' b* P' O; y9 y
  76. get_read:       in      al, 64h
    ( O5 H1 W& |; o" \# W7 K
  77.                 test    al, 01                  ; If the 'output buffer' is full, has ( O) V& Q0 }- l( Z4 O
  78.                 jnz     exit4                   ; ...
    ! R( E+ P% d' N
  79.                 dec     cx ) q5 U( j9 O1 Q
  80.                 jnz     get_read
    2 v' w/ q4 W9 V
  81. exit4:          ret     $ t$ b2 c/ r- q1 J7 G( ?
  82.                
    ) \  M7 u1 f# ~, I" R
  83. end
复制代码
  1. ;A200FF.ASM " P2 `% `9 e  K1 y( n3 ]+ H  M
  2. ; 5 _* u+ u) H8 Z
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-011 ]+ r9 e% W2 q. \" B1 A
  4. ;       ml A20ON.asm ' O0 T, h7 [& y4 r: t
  5. ;
    , }: x' E; s8 }2 ?3 s$ T
  6. .model tiny
    ; k' V# W+ e: i3 ]4 S
  7. .code
    0 i1 p; I$ H, G0 K$ t
  8. .486
    0 Z7 o# ^# j2 k6 E2 O4 t
  9. .startup. C# ?( K0 v- H$ B0 N5 ?; H  z
  10. 0 U$ U: o8 Y+ f
  11.                 mov     dx, offset msg_author
    ' `. J( P, q& M% k& P. C
  12.                 mov     ah, 09h
    - [+ y, S7 y0 p3 U( c& J7 E
  13.                 int     21h& H, Z9 i- O! Y
  14. 7 `% }! v; o  U- b! V/ C" Z
  15.                 mov     dx, offset msg_fail
    2 T: E' l) c8 _. Q
  16.                 call    A20_DISABLE
    1 f3 F& u* Q# P+ j
  17.                 jz      exit1: W( {0 E1 u" j" J
  18.                 mov     dx, offset msg_ok
    0 L4 @! Q' R/ ~3 ~

  19. # @5 {2 @0 D* T, e: Z1 y
  20. exit1:          mov     ah, 09h 5 \" s/ P! n! T0 ?0 @# Q9 D
  21.                 int     21h ) m# e2 {0 H8 }8 D8 q% Y1 i3 s! U
  22.                 mov     ax, 4C00h
    $ z' ~" q) d3 q
  23.                 int     21h 7 C  w- y" E, x0 ?7 t+ T5 u
  24.                 % l" F4 G! H* P/ _) C
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    % a1 k/ u9 i) I; Z2 m& v- O$ x
  26.                         "2008-07-01",13, 10, "$" * {7 _5 F; H" a$ d3 Z5 `! W0 K( ^' H
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    ' w* D# b7 Z& j2 g1 O, m4 D- C
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    + W8 F1 ]( s5 K% K4 u8 O) m, \

  29. ) f4 a% @  e) t. p: i: n
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ' C2 w9 l, R2 Q2 D4 w
  31. A20_DISABLE:
    4 E3 m9 _( r3 o$ Q) v. \# n+ d
  32.                 call    A20Write
    $ n( F7 x) J+ L' X3 T
  33.                 jz      exit_disable
    + U2 P6 z+ \! D* b, Y
  34. 9 ~* ~0 Y0 K! K- u9 Y# }5 p
  35.                 cli                             ; Only need for reading value from KBC
    2 j$ K  A% a" _3 s
  36.                 mov     al, 0D0h ( L# J0 e. c3 Y6 K( j( X
  37.                 out     64h, al
    / U  M" M5 H6 a2 {: z; V
  38.                 call    A20Read % B* w/ u; k1 C6 @
  39.                 jz      Disable_int
    4 w, \7 J4 r2 Q& V/ Q" \( I5 l' y

  40. ' f. M/ Y5 F+ b4 ?8 _2 }9 k
  41.                 in      al, 60h                 ; Get current status ! K# A* [3 [! N; g: ^- \3 N
  42.                 mov     ah, al
    1 q8 A& t5 a. L, r3 A1 p1 K
  43.                 call    A20Write + T* a/ x" \! o- P, k9 v
  44. Disable_int:    sti : G* n% `/ P$ o
  45.                 jz      exit_disable0 g9 k2 F1 q2 O. S

  46. 9 m# T  W! e4 C0 i% [9 Q1 u
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    , E/ k- w# _9 p7 \& h$ o* S
  48.                 out     64h, al                 ; Out Put Port next * @3 E  o* o6 h) }
  49.                 call    A20Write & q* B- L$ f; T# n6 r5 `7 I
  50.                 jz      exit_disable2 ^3 n/ C( _* ~3 B% M) {8 E
  51. 1 b: u, S; i! W$ D
  52.                 mov     al, ah
    ) R0 V, x5 s, x+ L
  53.                 and     al, not 2               ; Disable line A20
    ! Z/ A0 {( a) T4 F+ r& C
  54.                 out     60h, al
    & ^9 a5 d9 F: ^
  55.                 call    A20Write / ^# @, i% Q3 x% y7 [/ \- r
  56.                 jz      exit_disable/ U: O9 t  M0 A7 K8 ^0 q6 D
  57. # J1 C* w$ x) s0 N, ~  ]
  58.                 mov     al, 0FFh                ; NOP
    3 g% r' U9 X# k2 P! V. h" O, D
  59.                 out     64h, al
    8 [8 \7 ?5 r+ j
  60.                 call    A20Write 0 E6 ^2 y4 A# ?) D
  61. 0 j- g- E# |5 r- R0 K8 ^
  62. exit_disable:          ret ! l; j  D) Y  n

  63. & ?7 K1 \) c- f% N! f, m$ b
  64. A20Write:       xor     cx, cx                  ; Reasonable wait . Z' Q! r0 m3 c: `# i! F
  65. get_wirte:      in      al, 64h                 ; Get KBC read status $ N% n) }( t8 S% I3 \$ m* u* h
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear * Q5 t% L6 `, ^# P
  67.                 jz      clear 4 w. E& @! }4 a" S" `% m
  68.                 dec     cx % k  I0 ?. b0 d# y
  69.                 jz      exit_write - k1 R2 T. E1 n2 s
  70.                 jmp     short get_wirte
    , T4 z  B: G4 V
  71. clear:          inc     al                      ; Clear ZR # O- Z% y* i) w- w) @; Z. W: W
  72. exit_write:     ret
    $ a- @- z8 A/ P( i6 v

  73. : N! m% {5 S! t+ U' R5 p+ d0 g5 [
  74. ( t( H% u  L( {5 Z
  75. A20Read:        xor     cx, cx
    & f9 C1 E* a# ^& S( r# n
  76. get_read:       in      al, 64h ! }6 X& D- D( C
  77.                 test    al, 01                  ; If the 'output buffer' is full, has # |4 n$ [1 Q+ z0 v  h& R/ m
  78.                 jnz     exit4                   ; ...
    , Y/ Z- }& {; `1 f8 E2 y1 j( e
  79.                 dec     cx   g. q( l5 d: ]- V! Q" G* A3 d
  80.                 jnz     get_read
    7 t9 Y4 W- R/ y* N& h. d$ j: p$ Z
  81. exit4:          ret     : x! ]1 \7 c) b% ^; a, }$ V
  82.                
    6 \' b" ?  L! v7 Y/ ~3 s
  83. end
复制代码
  1. ;A20STATE.ASM
    + u0 S0 g$ b; h3 I
  2. ; / I* f0 Y  Y6 J& [
  3. ; Returns the status of the line A20 through the KBC
    ( C2 v+ N. J+ d0 U$ n9 P
  4. ;       programming by bini for debug. 2008-07-01$ M/ g: c. }9 F. h0 X9 `  B9 |
  5. ;
    , w0 x  G1 V" X; z, b
  6. .model tiny% u/ a7 M0 e$ c8 ?: z5 a' x7 k
  7. .code. p7 }6 D% z3 m' h7 u1 f
  8. .486) H3 X3 b0 V6 Q8 F( B! _: S
  9. .startup" u1 z+ g% v% q: }$ |. b$ N
  10.                 mov     dx, offset msg_fail
    9 o! L2 h5 O& C& [$ q
  11.                 call    _GET_A20_STATE_
    ; a- M( U6 }  {- \
  12.                 jz      exit1                           ;  was a problem4 b4 I$ r, x- c
  13.                 push    ax                              ; Save state, AH   f$ n( A  Z# r% N
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem 7 s- R- z. b/ @/ q" v! _
  15.                 mov     ah, 09h
    & Q) p5 q6 U, d: F6 t; U
  16.                 int     21h                             ; Print message , v7 i( d- ?  U8 h1 N+ a
  17.                 pop     ax                              ; retreve state 3 S6 C! _/ J3 H- r  `8 n3 O) `

  18. ; F7 W' ?0 _8 g4 E& P
  19.                 mov     dx, offset msg_dis
    : i: Q9 t* D7 w+ Q
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state " n3 b7 d+ @9 l- ]1 ]
  21.                 jz      exit1
    " }8 d8 f* t  n
  22.                 mov     dx, offset msg_en
    1 {9 k+ Q  W  Q  K1 Z* \! J) f

  23. ) U% o' [- W# U/ m% y
  24. exit1:          mov     ah, 09h ) w- A3 `& x3 i; ]+ w0 I
  25.                 ; DX already contains address of string
    + e/ j" _- X+ B5 z6 s
  26.                 int     21h ( E5 T  `2 @) h5 Z( [5 S' C
  27. ! K+ b9 z' U: B0 M! f# i$ {7 |
  28.                 mov     ax, 4C00h 4 a1 x* I) [/ ^5 }$ s$ d
  29.                 int     21h 6 G% {- f$ p* C- Q/ ^3 v

  30. / l/ A5 W# p9 d
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ! ]' E5 U3 d* B- |& u0 o8 i6 ?
  32. msg_fail       db      "FAIL", 13, 10, "$"
    4 X  P$ y: S* P. u. B+ L5 p) I9 |
  33. msg_en         db      "ENABLED", 13, 10, "$"
    8 K7 O4 e& e' G
  34. msg_dis        db      "DISABLED", 13, 10, "$") I% J- `3 H8 C  C4 o5 |4 b

  35. 5 o4 }# `6 w+ c2 `7 U7 R

  36. . W( j5 {6 g- ^8 u+ ~5 ?: F
  37. _GET_A20_STATE_:
    ) F( n3 K) k: m% T+ b2 \  I
  38.                 call    A20Write                ; Wait till the input register is empty 2 ?& f4 Y4 s" {  Z1 [
  39.                 jz      exit2+1                 ; Bypas the reset int's . s4 n1 U9 o( y, c, i
  40.                 cli                             ; Disable ints so we'll get our value 5 L: p$ C1 u8 i2 S
  41. 4 \' a  @' F3 A
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register . p0 F9 a" s  z
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port   |# n4 ?& g4 Y( B
  44.                 call    A20Read                 ; Wait till the 8042 output register
    - ~$ V# J( X- `4 h5 r5 ~$ p
  45.                 jz      exit2                   ; has something in it's buffer 6 |/ b6 c& O7 M2 [2 Z
  46. 3 s+ l* w4 x4 x0 n2 K( s+ Z7 M
  47.                 in      al, 60h                 ; Get it 3 X# |. H6 L8 ^* ~* [3 C& ]
  48.                 mov     ah, al 2 Q5 d4 M4 y) ~( o' S3 z( l
  49.                 call    A20Write                ; Make sure the input register is empty ! ]7 B4 f- v+ x) J: p
  50.                 jz      exit2
    3 P( G0 M( G* b$ I6 w

  51. + C9 T: C' h  j7 D+ |& k6 ]  F- P
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    3 p( P' j( s  q) R
  53.                 out     64h, al 5 I% u7 M) ^$ m, K
  54.                 call    A20Write
    ; j" @1 z2 u, H4 T' `! D' S( U
  55. ! s% o) M5 x! A. z
  56. exit2:          sti
      I4 G. C9 \5 b" Z9 E# x) F/ l
  57.                 ret
    , o, F, @$ ?9 @& F. M6 W

  58. " J7 I# r% i8 Q
  59. ' V  ]9 _9 A7 {7 Z% n
  60. A20Write:       xor     cx, cx                  ; Reasonable wait 6 W7 n& H( q# o- N( t
  61. get1:           in      al, 64h                 ; Get KBC read status ; V) r5 N) v; q" l6 H. m
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear $ O/ I! p) M% V! g& J
  63.                 jz      clear
    : Y: Q% @7 r( ~% p# H" O/ }$ q
  64.                 dec     cx * [# v; t# b6 ]& x( _. W
  65.                 jz      exit3 / m5 @. D; t8 m+ Y1 z
  66.                 jmp     SHORT get1
    ' y0 c  u, G+ x& t- h) i! i. }
  67. clear:          inc     al                      ; Clear ZR
    5 C2 m0 J; b  o5 J
  68. exit3:          ret 9 D& A! n  H. U: l
  69. & l  h" |" a& `' O+ n! X3 O7 K

  70. % p, k1 {) J- W! B) Y- L9 r
  71. A20Read:        xor     cx, cx $ I" l) }1 N$ X5 ^  ]
  72. get2:           in      al, 64h ! w7 o/ n" X& p- H# L3 K+ `9 S
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
      N7 D! c9 S/ d1 H
  74.                 jnz     exit4                   ; something for me
    0 i% s! a5 i9 y5 K( \5 J
  75.                 dec     cx : v$ i( D/ u( A' Q" J9 W
  76.                 jnz     get2
    2 T- A# k% r: u7 D! P2 ], g1 k9 I& d. s! s
  77. exit4:          ret     : \3 q0 A' R1 ^0 V0 h' E
  78.                 3 G' s$ O8 S3 k9 e% p
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
+ y8 C2 M3 W1 E, l, C4 H" u8 V{        while(inp(0x64) & 2);        outp(0x64,0xd1);# f  E, b$ Q4 T$ N4 M& ^, L8 U
        while(inp(0x64) & 2);        outp(0x60,0xdf);' h. w- m8 ?$ P- g" ], e3 h. v
        while(inp(0x64) & 2);        outp(0x64,0xff);
; q+ r* k6 c0 m& V$ R5 u$ F}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-20 03:37 , Processed in 0.052715 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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