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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    8 ?( s) j1 ]! u' k
  2. ; / L- _4 |# Q, X) J0 {4 K
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    ! |4 r& A& Y, v. W- y+ d4 P
  4. ;       ml A20ON.asm
    1 r; T. t1 f' B: v8 h+ [) k
  5. ;
    3 }- K+ b  z! @3 D4 S1 p
  6. .model tiny
    ! W: j' w9 X2 W* X2 I- J/ L4 T
  7. .code9 r3 A7 E9 U% G. P$ S, Z1 [) r: f
  8. .486* o: g. ~- r3 o+ ^" c
  9. .startup
    0 p0 V2 S5 \. P/ M8 @
  10. 8 M7 h* J1 d. G6 P; i1 n! W
  11.                 mov     dx, offset msg_author
    # k- M% D7 w9 Q& Z9 u
  12.                 mov     ah, 09h$ _4 ?4 ]. I  ^$ b, x0 Z
  13.                 int     21h1 k7 S! G. l9 n9 k9 B
  14. 9 u. \# S- r9 d- o7 a' Q) W
  15.                 mov     dx, offset msg_fail
    - U% k; j+ T/ T7 Y9 Y) @& d
  16.                 call    A20_ENABLE
    ; r1 ~  I, L  i) L1 B' l( k
  17.                 jz      exit1
    $ V/ ~- a. F% ^& n1 ?
  18.                 mov     dx, offset msg_ok
    / c# W& ^. N1 l# t) H
  19. 0 _0 f; h8 J8 _# d7 U6 _
  20. exit1:          mov     ah, 09h # l; ], D9 k$ W" V. n1 Y4 b; S. x
  21.                 int     21h
    / C3 b' v; X* q
  22.                 mov     ax, 4C00h
    9 w8 n0 v: A3 c  w; l0 f
  23.                 int     21h
    1 K* g* P+ `$ [' Q& h+ O; f
  24.                
    + Q  p1 r* Z& s+ b, [, N1 A& J
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    8 I8 _1 f2 n, x# a+ F1 |
  26.                         "2008-07-01",13, 10, "$" 6 y' Z$ |$ m. R2 n
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    5 h8 U  G5 j3 b6 i+ @5 g
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" + h, i% _6 _: H' j0 a* |

  29. ( \4 F' `  F! X$ ?: j6 f
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------' H8 n- W2 p4 ?; z/ |2 Y
  31. A20_ENABLE: 1 T0 u9 S3 R0 j. F" ~
  32.                 call    A20Write
    , [2 W- w- S; Y) D
  33.                 jz      exit_enable( E  N6 A" v+ {

  34. 0 f1 H2 |' d$ U, b
  35.                 cli                             ; Only need for reading value from KBC
    & `0 t8 p, N5 R8 S1 u
  36.                 mov     al, 0D0h : {: X* X0 U2 }9 S! _
  37.                 out     64h, al
    - L, {+ R( F  v) w" K/ \+ ]6 p
  38.                 call    A20Read
    ; A1 i2 [3 Y) k/ n6 R
  39.                 jz      enable_int : e! r5 v4 D! F# h0 J, e4 g
  40. % F+ T* @) ]8 T7 x! @% b
  41.                 in      al, 60h                 ; Get current status , S5 Y1 r* W( w
  42.                 mov     ah, al - g/ _5 C' l& E! ^; |* v/ v
  43.                 call    A20Write
      }  F. `( o: t4 K9 X, b5 y
  44. enable_int:    sti ( u/ ]0 r. u  N. Y
  45.                 jz      exit_enable: Y) k% E3 G  M- X) n( A4 B

  46. 3 F* S, O' O, q5 n
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the $ f& B" E7 G) G* O
  48.                 out     64h, al                 ; Out Put Port next 5 O' x) T) v$ p: _; H2 k
  49.                 call    A20Write
    * j1 U! j% `. V. c" H# Q
  50.                 jz      exit_enable
    % s8 k5 q- K& `8 x6 G" [
  51. 3 e  v& h$ n' V4 Y; \& K
  52.                 mov     al, ah
    5 a. _' I$ w  R4 B4 h+ M  ]3 [5 X
  53.                 or      al, 2                   ; Enable line A20 ; Q  K" h- G2 q5 ?2 n8 O& Y
  54.                 out     60h, al
    2 ~+ ?* _1 m/ L3 O$ L' x4 o. Q
  55.                 call    A20Write
    : a" b# I  a: p) F! L6 Y* c8 V6 C
  56.                 jz      exit_enable4 K& l  D/ a  n! `5 w: A% t
  57. ! A* q* }8 D  e1 I" W
  58.                 mov     al, 0FFh                ; NOP
    3 F* Y# B: G/ Y$ v8 M% A; m
  59.                 out     64h, al
    - `8 B# c( Z. O  ~5 a; g" E
  60.                 call    A20Write
    " d3 _2 w9 G( |' J3 ^! ~

  61. ( C) h2 k" u( d: K! b
  62. exit_enable:          ret
    6 @1 I4 [$ w. H

  63. 3 Y+ N5 I% Z9 j7 P% _9 c! E
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    0 d- q$ K( h3 Z% h0 \1 H3 g" V! `
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    , r" d& [% \4 ~. _
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    * G) C$ O4 @, U- D+ G
  67.                 jz      clear " q! P% K& `! G
  68.                 dec     cx - X8 O" J; ^3 P7 i! T
  69.                 jz      exit_write ; u5 K* v* H$ x3 x) z* V
  70.                 jmp     short get_wirte
      Y  g( Z  `! a, j; J2 R4 T0 p
  71. clear:          inc     al                      ; Clear ZR
    $ s2 O6 E% R6 d* A: r* n1 K0 m
  72. exit_write:     ret 5 [9 }0 t& ]% e2 r5 Q8 F

  73. . |% c' i3 L5 A8 U, `

  74. . e1 v$ Y* r% _
  75. A20Read:        xor     cx, cx
    : x" p) f' {$ w, @9 |
  76. get_read:       in      al, 64h 2 Z1 s- r( j9 S* @1 o& k. ~% r: B5 e
  77.                 test    al, 01                  ; If the 'output buffer' is full, has " I5 g0 m2 R" g) d# L5 V
  78.                 jnz     exit4                   ; ...
    & o* y9 x) K% g1 V% ^- M5 \4 b
  79.                 dec     cx ! L' X9 V+ t1 i7 w6 z6 c0 |: o
  80.                 jnz     get_read
    # ?4 D; F6 h  B8 t; p
  81. exit4:          ret     
    7 Q( P2 D9 P; ?3 Z- Z
  82.                 7 {, }5 }5 s/ y& e8 M" {0 W
  83. end
复制代码
  1. ;A200FF.ASM ) d; p, L' C  E* c" f* @
  2. ;
    / I" i! n6 [* w4 s; I  d
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01! W9 }3 u9 y$ n' D% t3 g
  4. ;       ml A20ON.asm ) _" [; H) J5 I5 s3 ]4 e
  5. ;
    3 \1 C2 v' @7 L' R
  6. .model tiny3 V! L3 L7 u8 a/ }
  7. .code7 p: r- E( B8 }" ~/ E8 C7 v
  8. .486
    % T! d4 z% ~- ?
  9. .startup
    " X( }4 ?: b6 ?; E

  10. 2 @( x+ I. C  |5 D# d
  11.                 mov     dx, offset msg_author1 _' d0 g& c& D" U! N' y
  12.                 mov     ah, 09h
    4 b* W3 d: w. L* D/ z
  13.                 int     21h
    - V& U( C: M' X, `: Z
  14. . A' N3 y1 ?# H7 ?' b
  15.                 mov     dx, offset msg_fail / ~- f/ X% k  l# `- n- r
  16.                 call    A20_DISABLE
    $ t- T1 r: K' _! J. p
  17.                 jz      exit1; L* W" `* E' V0 Z% b
  18.                 mov     dx, offset msg_ok
    3 \, C  C; h. ]1 s
  19. 6 L8 \" D) e* ?
  20. exit1:          mov     ah, 09h
    3 e+ X- R" G$ R; c
  21.                 int     21h   K- f- D+ B0 B4 Q# u4 W
  22.                 mov     ax, 4C00h
    8 i9 K! z( G! J8 ^0 O
  23.                 int     21h
    $ \4 c3 D; D2 N5 O
  24.                
    2 Z6 ^0 F. R+ m. l* f
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    ! P! F& a% I. E7 `# d
  26.                         "2008-07-01",13, 10, "$"
    - F4 F! u3 Y) L& s* R2 u9 }5 _
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" , G% ], O  ^% e/ Y2 E  ~
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    * w0 ?, ^$ x2 Z4 O
  29. % F$ ^2 `. ~" l6 V. }0 V' F% x8 @) |* a
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------. E/ j0 m# A4 D& \5 V/ W, L
  31. A20_DISABLE:
    9 d8 E) T# _" b0 j
  32.                 call    A20Write 8 ^$ D' ~8 ~7 \' m# [
  33.                 jz      exit_disable
    " G" r. G, t, p& l% k

  34. 4 E( M8 W! Q: k% q& U7 M! N% s" j
  35.                 cli                             ; Only need for reading value from KBC
    5 ^9 `9 D5 P6 q
  36.                 mov     al, 0D0h
    , [" ^6 R8 L$ x: X
  37.                 out     64h, al 2 E1 Y$ x, K+ f# p: i+ x
  38.                 call    A20Read
    5 j0 M4 a) ]* T5 U1 F$ C2 u
  39.                 jz      Disable_int ; d* Y3 |  f* d3 _1 }
  40. 8 N& j3 E( ~: s  D1 m1 ]! d
  41.                 in      al, 60h                 ; Get current status ( o3 d6 {  V) ], s5 h
  42.                 mov     ah, al   T* x: x, i* y' ?  n7 P) [2 u- B
  43.                 call    A20Write : a4 E( `+ P5 N
  44. Disable_int:    sti 0 s0 z3 g1 p4 s/ j0 [5 E4 B
  45.                 jz      exit_disable$ r) r8 I( ~+ E( b4 I0 M
  46. ) k; C( z8 e/ {  @( b2 C8 C
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 9 [; R, N$ g3 m) `
  48.                 out     64h, al                 ; Out Put Port next
    3 o7 q: }/ M! r6 X& A9 }! N' s
  49.                 call    A20Write
    9 P, U+ r  K2 g- ?; H. U. E
  50.                 jz      exit_disable
    / o& [9 z' m1 n+ F

  51. 0 V2 U. Q; P  z+ z/ @, f
  52.                 mov     al, ah
    2 o: ]$ J3 \! A6 U1 ?, C
  53.                 and     al, not 2               ; Disable line A20
    % N* m, X( ~/ T/ a  h+ |! Y  h
  54.                 out     60h, al * L; s8 F2 R' V* a: }' F  p, P
  55.                 call    A20Write
      U3 i/ d- w. Z; g' h* f
  56.                 jz      exit_disable
      L* m2 s0 I# q

  57. + E3 A: V' _% F8 u. Y6 v
  58.                 mov     al, 0FFh                ; NOP 7 W# ~/ _& ]+ c$ I/ B
  59.                 out     64h, al
    ( p$ _! h2 K) \7 K$ V. F
  60.                 call    A20Write ; D% O7 M9 r0 J# v  q
  61. ! j) v% ?3 E+ P$ E
  62. exit_disable:          ret
    2 w5 d' a) @  E: z* ?6 v& A
  63. + h& j* T( _1 n: n/ p
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    $ S5 |; l0 ?3 u
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 4 s) U2 ^" a7 f3 c4 ~, c2 W6 ~6 a; q
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    + Z0 S2 ]: O0 j6 e+ _7 n
  67.                 jz      clear 8 T; P# L/ @' |9 E. W& t( y/ j
  68.                 dec     cx
    6 W0 k/ G- k: o3 E: @0 \! u
  69.                 jz      exit_write 9 k: b  ]3 h* j* B5 F( S
  70.                 jmp     short get_wirte
    ! g' z. n. m& a4 T$ t- i% G
  71. clear:          inc     al                      ; Clear ZR
    & B8 m: i2 C% g8 D. w* J% q+ s4 P3 ~
  72. exit_write:     ret 8 d4 J9 X4 Z$ M2 J
  73. 3 r  Z: I4 U; @) x6 E
  74. + x* ?+ n; X* m, _$ L  a4 {
  75. A20Read:        xor     cx, cx . i; s9 a- O  Q& Y7 y0 d. @/ h
  76. get_read:       in      al, 64h
    7 @' I$ e% t# L  p2 N& k2 K2 S9 ~
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    & R! ^+ C: K/ Y7 k% k+ N
  78.                 jnz     exit4                   ; ...
    $ O3 C1 ^4 l! U! M" Q
  79.                 dec     cx
    1 M8 l& m+ _6 o) {% @; X
  80.                 jnz     get_read/ T# a7 f% V6 @4 U8 Y; L, l  H. N
  81. exit4:          ret     3 o$ a5 P" X3 K% f9 m7 a
  82.                 9 W# _- E  W- g6 c5 n
  83. end
复制代码
  1. ;A20STATE.ASM
    + I- V' m* ?" ^
  2. ; 3 r' w* b2 {) a7 L! W
  3. ; Returns the status of the line A20 through the KBC 9 W( X. t4 ]* i. m! z, F
  4. ;       programming by bini for debug. 2008-07-01+ r3 s, X5 h3 t- E% }
  5. ;
    # K' l. V* Y' L6 w2 w, s
  6. .model tiny& B  O: r& R  a4 Y5 R+ r! x$ e' g
  7. .code
    # U4 H& z+ S6 @$ }8 v3 Q! X4 U
  8. .486
    & S2 Q6 _% ~8 u( Q
  9. .startup
    . V0 k# m8 c, ?
  10.                 mov     dx, offset msg_fail
    ( `8 ^' l, ~: I( A$ O- {
  11.                 call    _GET_A20_STATE_5 z+ P- ^' b/ {* g$ B& {
  12.                 jz      exit1                           ;  was a problem' n: j0 L/ L/ Q( C4 ^) L+ J
  13.                 push    ax                              ; Save state, AH / {% q3 S. b7 X, O
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    . ]. [; l/ I2 {$ Q
  15.                 mov     ah, 09h
    % H) I& P: z9 G. f0 H; Z* w
  16.                 int     21h                             ; Print message / e- H. E; i+ n  G
  17.                 pop     ax                              ; retreve state
    0 H" e9 h# q* n; |( S5 f; V

  18. 8 O& @! O# y& n: c# H
  19.                 mov     dx, offset msg_dis
    3 R8 M8 f  h" {$ M: M
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    - ~* \8 O, V1 R/ ?  t- u2 g
  21.                 jz      exit1 1 W) r8 z3 v5 x1 x# b8 D
  22.                 mov     dx, offset msg_en
    . {& ~/ ~) L6 Q" B9 w$ a1 e
  23. + k3 ?( M4 A% ?
  24. exit1:          mov     ah, 09h
    " q# z6 J% Z4 m  a: m8 V1 ^9 V
  25.                 ; DX already contains address of string
    ; G, O3 I6 a( o
  26.                 int     21h
    & U: [& g' B( Z7 f
  27. ) P4 T1 n& K: q0 [5 c1 F1 l+ f
  28.                 mov     ax, 4C00h , U7 t% N: T- o' N3 V1 I& }1 C
  29.                 int     21h % r9 F+ G( }+ ~4 S7 i6 t% T

  30. + G) t9 b0 G/ G* \
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ) W# _; [+ e0 I3 s# L
  32. msg_fail       db      "FAIL", 13, 10, "$" " v7 p. [+ H$ N
  33. msg_en         db      "ENABLED", 13, 10, "$"
    4 j* U- n) [6 x/ v; l& R+ G
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    9 E& Z' `/ i# x; a5 o# E
  35. + Z. G' H$ Y0 C; h) H$ ~

  36. , ?  r% u- Y. a- @5 Y7 l3 X
  37. _GET_A20_STATE_:
    2 i. ~; i5 M, H, s, h* z7 P
  38.                 call    A20Write                ; Wait till the input register is empty
    $ U% ~6 Z+ T+ v' B  M. c
  39.                 jz      exit2+1                 ; Bypas the reset int's , O5 W& L: ]  O8 b! S! i. a
  40.                 cli                             ; Disable ints so we'll get our value
    - l7 `3 m/ j2 f& ]2 {/ F

  41. 1 N9 w: a) R* U0 i7 U
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 4 D5 i1 p+ ^) ^  d% o8 ]4 e
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port & F% e, F8 S/ J* Y+ j9 W- T
  44.                 call    A20Read                 ; Wait till the 8042 output register 8 [2 t7 i7 a" V1 ?3 B# u
  45.                 jz      exit2                   ; has something in it's buffer
    0 {* |3 ^8 X; f' \
  46. 6 p+ a* ^' C7 h0 u# f% x
  47.                 in      al, 60h                 ; Get it 7 @# `0 t: E' b# H" j, l2 H+ y6 a9 Y
  48.                 mov     ah, al $ P! p' `8 U  d6 Y; e  E2 ~2 c
  49.                 call    A20Write                ; Make sure the input register is empty
    . @. L/ _8 g' l+ k0 p) W5 O- A
  50.                 jz      exit2   g+ C1 k( w7 X$ V8 V

  51. 5 J+ a' C+ q  D6 H: x
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing , k* K# V; d5 b* n7 H" B3 |
  53.                 out     64h, al
    ; z% S  b- A% u: r0 \# D9 q
  54.                 call    A20Write * u1 b' p- c/ o! A
  55. - s& {  |5 U6 x! }$ h7 u
  56. exit2:          sti ) Z% O1 A2 [, N3 E) ~8 O1 J
  57.                 ret# V3 p$ {4 ^" l3 q/ t" k4 f
  58. ' e7 \) [8 H% r" N. N( f) q
  59. 9 h5 B" y. ^' `" l
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    7 P# S/ M9 D7 B) e" Z! w3 R5 g) ^0 R  L
  61. get1:           in      al, 64h                 ; Get KBC read status
    2 q7 }; J) v% D0 {) \# P
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ' T" y  F% }+ Y! l! ^  I& g9 y
  63.                 jz      clear
    / g4 X0 Z0 n$ |2 j, `, g/ d
  64.                 dec     cx 1 Y/ N  G, r+ [* E/ t
  65.                 jz      exit3
    ) x, E7 ~3 K6 p2 R% M' Z  b& u: R
  66.                 jmp     SHORT get1 * p( m" F  t4 F/ Z* |% U) P5 C
  67. clear:          inc     al                      ; Clear ZR   L$ J' I/ f$ w6 q& Z
  68. exit3:          ret
    ! I* y! }6 b6 w- I( G2 g
  69. . _5 g# l7 c. y
  70. 2 e7 _, X6 |! K
  71. A20Read:        xor     cx, cx
    : {: q. R* k( h; w! H7 e  U4 B
  72. get2:           in      al, 64h
    0 ?- A) o5 w5 X7 e; Z3 j
  73.                 test    al, 01                  ; If the 'output buffer' is full, has 3 s8 v5 ?! q/ J1 e" D$ E1 N* h
  74.                 jnz     exit4                   ; something for me + p' Q5 i5 o1 a% U2 p$ I; |
  75.                 dec     cx
    4 u& @8 _5 D+ B" E! x
  76.                 jnz     get2+ d, T* k; A) I- F+ g0 o
  77. exit4:          ret     
    - x0 Q0 _2 G& J, y* ^3 }
  78.                 & ^/ M- i$ h" ?
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
/ w& E0 r5 c- m5 {{        while(inp(0x64) & 2);        outp(0x64,0xd1);; p1 q7 Z) Q7 h! @
        while(inp(0x64) & 2);        outp(0x60,0xdf);& c  Q3 i# Z" P) {6 m
        while(inp(0x64) & 2);        outp(0x64,0xff);
2 V4 Q+ L2 T$ T. T, v  E/ B}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-4 00:17 , Processed in 0.050065 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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