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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM % X# `) ^, z8 L, M$ F! `9 e
  2. ;
    " Y& ~$ x' m' ?% b* I
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01- k0 d1 C; d% ^5 K2 j9 r. w
  4. ;       ml A20ON.asm : H; w1 P0 y# p6 H; u
  5. ; + o: h$ A9 @0 \! ^; E3 w/ l) R  y
  6. .model tiny
    $ e( Y; H& S: o4 r$ N
  7. .code
    4 ]+ |' @; o" x
  8. .486
    7 J) O/ T0 W" ~
  9. .startup
    7 ^5 h$ _% t3 {8 ^
  10.   F2 Z; D- Y# R0 L5 N8 F! C, t. i
  11.                 mov     dx, offset msg_author
    ! A  l3 B2 K5 Z$ Y: t* b8 e9 E/ E
  12.                 mov     ah, 09h
    ; h# `0 b9 Q. v- C$ V
  13.                 int     21h
    4 Y  o0 e4 u! m3 Z  w0 E) V
  14. ) |$ a- L  K" ?4 M* K( X
  15.                 mov     dx, offset msg_fail : g9 s2 K% z) i  ^& ?
  16.                 call    A20_ENABLE, E% ]9 y  n. y
  17.                 jz      exit1. |7 c" p. H- G! P; K/ Y/ Z5 T0 u$ V
  18.                 mov     dx, offset msg_ok
    1 y+ [: L5 ~$ ?7 Y
  19. 9 l, [2 W' W% ]% I
  20. exit1:          mov     ah, 09h $ Y) s! y: k  C5 O9 j3 m
  21.                 int     21h
    : _* t; E0 Y1 y. N( R8 K, {
  22.                 mov     ax, 4C00h
    9 R% T# p9 K, p) j
  23.                 int     21h * c. e- j, O: i0 j: y. U4 @
  24.                
    4 b$ l( w  X+ {) v3 A
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,. N5 R5 c0 b4 }3 d6 t
  26.                         "2008-07-01",13, 10, "$" ) p# B/ t6 e8 x; \, |) p
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    / m" ^( E2 Z* }4 U3 l) g. K
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" * f: _+ V9 w8 r; b7 i* E2 ]5 m) m
  29. 3 |7 D* q- K, V3 ^2 `
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------0 H* T% c  g: g. B/ Z- Z; N# J
  31. A20_ENABLE: 1 K& ?9 G+ u8 T+ k; `4 s/ m6 B0 f
  32.                 call    A20Write 1 f: ]: v' a4 x
  33.                 jz      exit_enable
    & F; i! I  k) L' s# g; _: n
  34. 9 L! W, Q8 |6 M  W
  35.                 cli                             ; Only need for reading value from KBC
    8 a. N! j* t5 A; d6 U
  36.                 mov     al, 0D0h 2 }( ~- T. C# P! j
  37.                 out     64h, al & R8 Q4 Q0 Y$ K$ h- b3 w, W8 ?
  38.                 call    A20Read
    1 g1 r9 u; w* b1 T' x# i( r$ b
  39.                 jz      enable_int
    * {$ D4 O: U' j8 x8 C  Q

  40. * c. |6 c3 M" ~1 `0 S
  41.                 in      al, 60h                 ; Get current status 2 l* n+ I3 h# n3 [
  42.                 mov     ah, al * y; f% [- Y% s! y$ I
  43.                 call    A20Write 9 ^& N! E0 v# `
  44. enable_int:    sti
    ' ^3 z  {* m& t
  45.                 jz      exit_enable
    . h) u) i7 p7 ~( N5 E( f

  46. & C3 Q( P1 U  |7 p4 g0 h* H
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    % {6 K' y  Y* ]; @1 I7 ]
  48.                 out     64h, al                 ; Out Put Port next
    8 M) h% `% \4 L; b1 V
  49.                 call    A20Write 4 V6 s: U" l0 x5 ~
  50.                 jz      exit_enable
    5 w' S6 `" J2 D6 Z2 W

  51. 5 S3 u8 y+ X2 u% k
  52.                 mov     al, ah 7 G! k& ]2 t& W' P
  53.                 or      al, 2                   ; Enable line A20 4 _- m4 ?# p: H/ Z, S$ B
  54.                 out     60h, al
    ; G+ Y' W) T/ T, y* [
  55.                 call    A20Write 3 H; i0 \* L7 R- j& I$ _; s
  56.                 jz      exit_enable) W5 F3 d9 U1 D9 |
  57. 3 a# t$ r' K3 a
  58.                 mov     al, 0FFh                ; NOP
    1 T. Y: D1 X  V1 P
  59.                 out     64h, al
    8 f3 O) [: ?' @3 z3 Y
  60.                 call    A20Write
    1 Q& O- n8 W/ r

  61. * ]7 ]; ~0 A5 E5 Q5 J
  62. exit_enable:          ret
    ! c) W' U# {* \. O& x* L
  63. 1 @% F3 I3 h+ A7 U- l5 B+ o& v
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    - z- b3 P8 e# N. u( S! v
  65. get_wirte:      in      al, 64h                 ; Get KBC read status   j& _$ _- k$ ?/ C5 V2 O4 v) Z) @' ^
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear + Z7 m+ I+ W/ M; D0 x; ~
  67.                 jz      clear & X# ~  s2 c  V( e; u2 V$ n0 |; I
  68.                 dec     cx
    ( v- n2 }1 ?: V% r' v9 f9 M
  69.                 jz      exit_write / L2 [8 A' k+ f9 H+ s* P9 L
  70.                 jmp     short get_wirte ) ^. T6 S- K4 Y! _6 N0 N
  71. clear:          inc     al                      ; Clear ZR
    8 _& \8 R, _- q
  72. exit_write:     ret $ u8 P: V3 \: ?

  73. ; I3 g1 i  d3 e+ ]# z  y6 Z

  74. ( i8 ]8 Z  K$ W5 n+ n
  75. A20Read:        xor     cx, cx
    ; x* J# ?: p: G
  76. get_read:       in      al, 64h ) x4 W  O1 h) ?, K7 C. z
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
      W0 K) G3 M# O9 `  ]
  78.                 jnz     exit4                   ; ... * _4 ^4 u7 Z8 e4 u1 r8 D7 H2 q
  79.                 dec     cx ! p! h3 L, h" t
  80.                 jnz     get_read: q. Q5 J+ F7 h* w
  81. exit4:          ret     3 V( y. H; c' [
  82.                 * @; d2 c$ u& }$ P* K8 q8 i
  83. end
复制代码
  1. ;A200FF.ASM
    9 W4 v. Q7 Z' J" n& J
  2. ;
    9 K5 l3 C& L' ]* a& G3 S
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01* i) J9 z- `( K* m& N3 T9 K+ ]
  4. ;       ml A20ON.asm
    0 o, o7 E) P0 e3 h- C1 O: a
  5. ;
    : s9 G4 ?" Q# {. e0 `1 D' N& O
  6. .model tiny5 d1 W4 E+ t" @7 n& b. Z
  7. .code3 d  K( n" \" n
  8. .486
    . f+ z! B* O9 ?& J, \! @8 T3 i
  9. .startup
    / b8 w$ T% \% H- @4 w0 v. |; p' Y
  10. ! q% G# y0 ]5 }7 C! Q
  11.                 mov     dx, offset msg_author  J' K2 D: w6 e. x
  12.                 mov     ah, 09h
    % ~8 o" `/ T/ P$ r) R
  13.                 int     21h
    3 ~% B7 c! G( K

  14. 9 z6 Y% ^0 _! D
  15.                 mov     dx, offset msg_fail
    $ W( u$ W$ S! a! T# }. L
  16.                 call    A20_DISABLE
    & q/ `  C/ c9 \1 j$ p! V1 F& i
  17.                 jz      exit15 I& s" P" L; a/ f
  18.                 mov     dx, offset msg_ok
    " ~3 L/ t3 l/ I

  19. & a' y; M4 I( n. P9 e7 Z) }
  20. exit1:          mov     ah, 09h
    ) [; y; l* |7 H9 @  b" _, [
  21.                 int     21h
    1 I6 u: w: k2 g/ T% K+ L3 o) z
  22.                 mov     ax, 4C00h - _; b  Z8 D4 c, ~
  23.                 int     21h
    8 E, _! L, ^. K; f
  24.                
    ! U+ [* K$ Y1 l
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    " A# _6 F' @2 \9 R( v7 z
  26.                         "2008-07-01",13, 10, "$"
    ( G% u4 J4 [; q6 U
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" , Q+ h8 i6 x1 N* s4 b& z
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    " O$ ^6 N# l1 c, |
  29. - x6 a1 k( v# N1 {
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------9 e' C) j7 J# l5 }$ d3 J6 W9 q* X
  31. A20_DISABLE: 6 `( N0 C# X! P+ V. T. s: R
  32.                 call    A20Write - r$ r  n: H) A5 P0 q' M
  33.                 jz      exit_disable$ o* |+ L' a6 [# Q8 J/ |
  34. " X# [' F$ |1 \. h
  35.                 cli                             ; Only need for reading value from KBC 0 M0 B) a6 j3 `/ L; F" l
  36.                 mov     al, 0D0h , {- [2 K8 t) _) p5 g; N/ ?
  37.                 out     64h, al & I7 G; S+ @! R/ k9 \+ C3 U' b: j
  38.                 call    A20Read   V; L+ f: u) ?- w
  39.                 jz      Disable_int
    1 z  k, e4 M: n9 Y
  40. ; ~. X; f( ?- q. P  a' \- ]( g
  41.                 in      al, 60h                 ; Get current status
    5 O& ^* @$ [, o7 K
  42.                 mov     ah, al
    3 r$ e0 L& u( Z2 N' @4 o
  43.                 call    A20Write . D$ F7 |# Y+ N# d7 M
  44. Disable_int:    sti
    / v- J1 m* F" _& d) q9 B+ M9 g
  45.                 jz      exit_disable
    ' O; Z/ F: L/ F; w( H$ D9 s! M
  46. + K% b, ~# L: M. ^
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the 1 _! y& }6 w$ O9 s% o8 t7 F9 t6 J- m
  48.                 out     64h, al                 ; Out Put Port next $ m. ^$ C4 F* i4 c
  49.                 call    A20Write 0 \+ H" S/ ]- c: W) T2 M* n( e
  50.                 jz      exit_disable0 R& k# n0 y' w) C" u4 h
  51. ) j; K! S+ p3 s* J, A, [$ d
  52.                 mov     al, ah
    8 d2 W4 B9 I3 N; x4 a3 U! H# I
  53.                 and     al, not 2               ; Disable line A20 ; Z, f9 s5 Q* O! H9 B0 Y" Q4 {8 G
  54.                 out     60h, al
    $ R% J4 v) r& y$ }( h4 v
  55.                 call    A20Write * Q) |+ ~# t8 s  X+ e2 _4 |
  56.                 jz      exit_disable
    % p/ D% I+ A/ ]$ N/ ~

  57. ' B% w+ A; i2 t+ f: R
  58.                 mov     al, 0FFh                ; NOP
    1 L- r0 j. Y4 t: j6 s& m% ^
  59.                 out     64h, al
    & D# w. Q$ o3 _3 }/ n3 j
  60.                 call    A20Write
    0 W/ z2 ^* ^! o5 A
  61. # S; y, t, a# Q( E( [
  62. exit_disable:          ret
    + J  y9 K5 J: q  h

  63. ' u$ y! P5 t" V+ \' \" g' K5 ?" [: R
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    + @8 i; P( I6 x/ f
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ( T. M' R; z) t4 W: ]3 x4 M5 t
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
      e' \" k) }! U2 A2 V9 ?
  67.                 jz      clear
    + K& Z$ r8 C: q) P+ y# ]
  68.                 dec     cx
    / g1 ?  E8 t( ~6 ~+ Z) C
  69.                 jz      exit_write
    + M: g  v( b7 K+ g5 z5 k
  70.                 jmp     short get_wirte % x( j3 q4 F! P  j
  71. clear:          inc     al                      ; Clear ZR
    7 _" A- V# X3 g
  72. exit_write:     ret
    5 l5 B& X" E; A# G

  73. : X' [: n  C, }& Y. p( q: }- l

  74. 0 W+ d) L& m& T9 T8 ?- E6 D+ q
  75. A20Read:        xor     cx, cx # c" J  n2 L* f
  76. get_read:       in      al, 64h 8 d9 z7 I2 V& E( T7 N& @" S8 B
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 3 R* L1 R; E$ x5 m! j
  78.                 jnz     exit4                   ; ...
    2 i3 y0 K/ t! X/ H% |6 [
  79.                 dec     cx 2 w; T% y* x' [4 v& Q
  80.                 jnz     get_read" t: R" }9 z0 i8 _
  81. exit4:          ret     . S/ [6 L" p! M$ C) ?
  82.                
    " r9 T7 h& l2 K' H+ U7 w. x
  83. end
复制代码
  1. ;A20STATE.ASM
    / T5 u  f$ o* u4 [
  2. ;
    " v' K9 z+ u- T! \" j3 y
  3. ; Returns the status of the line A20 through the KBC
    " |- v- s: i3 U& E* I+ r
  4. ;       programming by bini for debug. 2008-07-01
    , i  V8 T. C- u! ~/ c4 n" }
  5. ; / K" d* F; }0 G7 |- H  z
  6. .model tiny" v6 m9 C2 N' L: Q5 {* Q  N: c
  7. .code
    / P7 c; @6 E9 R% ]
  8. .486
    & q( p6 g0 c& R7 W
  9. .startup- W7 p- v# E* |/ M* n) g
  10.                 mov     dx, offset msg_fail & ?5 [0 d3 S  Z% r: x/ T
  11.                 call    _GET_A20_STATE_6 [' ^8 L4 {$ E' H2 D
  12.                 jz      exit1                           ;  was a problem6 K5 K* j4 r. O# K# W
  13.                 push    ax                              ; Save state, AH
    : o% j9 a0 M3 s$ W/ Q6 S; J
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem , M) L1 g7 _9 \, v" ~( M
  15.                 mov     ah, 09h
    $ a2 i* m7 P$ w+ R2 T
  16.                 int     21h                             ; Print message
    2 w: O) k# Z9 B# u  d. h
  17.                 pop     ax                              ; retreve state 0 [: |3 x! |5 l6 |3 q

  18. * `- {5 A1 e/ n- O4 G8 ?, y- R
  19.                 mov     dx, offset msg_dis
    ! w* p  w6 R- E% x- |$ T. F$ X! Y
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    ' A, ]: E- k0 S. u9 |% B. n8 {2 ~
  21.                 jz      exit1
    ' t- ]8 D, F" n2 H3 v
  22.                 mov     dx, offset msg_en
    ) Q, c% |5 K6 n1 j" m9 d

  23. $ R. Z$ q) @" K9 b% C) k
  24. exit1:          mov     ah, 09h 9 R, B! _6 A( @7 s
  25.                 ; DX already contains address of string
    6 A, T! L' {) l$ B: Q* i6 T% K. D0 w
  26.                 int     21h 1 l4 Z' n8 B$ O1 F
  27. & n# a; C# M- h' n; W: U
  28.                 mov     ax, 4C00h 5 c6 W( @: k8 g1 m! B
  29.                 int     21h
    3 W( b( Z2 p& v' ]  }; t! R
  30. 8 O2 u1 a* I! c0 H/ Y
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    , i- p. z" B3 E6 p% X, O
  32. msg_fail       db      "FAIL", 13, 10, "$" . v) o" Z7 @7 D% T
  33. msg_en         db      "ENABLED", 13, 10, "$" : j0 N- {( H0 H6 `* C
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    ( x% k) j1 q8 l" h4 q  I
  35. / B" m0 F4 _/ v
  36. 9 x% `2 l+ ?; q& W' S
  37. _GET_A20_STATE_:
    9 g0 V% N9 J' f
  38.                 call    A20Write                ; Wait till the input register is empty , M8 `; {' |( ~$ h3 s" ^6 }$ u4 _
  39.                 jz      exit2+1                 ; Bypas the reset int's 3 U7 ^. w# Q5 d4 Q8 e7 n) V
  40.                 cli                             ; Disable ints so we'll get our value   t( c1 c) d, \+ m4 u2 E8 G

  41. . J. j3 @$ w* O5 ^4 @% [2 M+ F
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    # ]- L: _$ U6 v4 T1 K
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    2 I; `& w4 C' `/ j! j+ a3 n
  44.                 call    A20Read                 ; Wait till the 8042 output register ; ~* |7 I5 b+ U5 ^) x1 q
  45.                 jz      exit2                   ; has something in it's buffer
    ; `4 ^. a2 f2 ^- H0 T

  46. % }. g; u, _, Y5 |5 H
  47.                 in      al, 60h                 ; Get it
    8 L0 S1 m: l$ n' o
  48.                 mov     ah, al / D6 K0 R2 Z& B4 }7 Y7 @
  49.                 call    A20Write                ; Make sure the input register is empty , h+ Q( d- L8 B/ t# T
  50.                 jz      exit2
    7 T- b$ k, `1 z$ x
  51. $ O0 `* L. D  }
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 1 I+ b7 m( x# A6 M
  53.                 out     64h, al % C0 q! J$ x8 G/ e5 W- g, ]
  54.                 call    A20Write
    3 m, W4 r; j0 F; u2 A! d6 M( z
  55. 6 Z5 u8 f1 X; n$ c& U- g: s' U
  56. exit2:          sti
    1 G* ~2 n) t5 T8 {: `! T! h/ H
  57.                 ret
    1 I5 E* {: ]& j3 I! i

  58. & r; f$ x" R" F) Q4 y3 }; k' ]
  59. % F3 [' {5 v3 F& }" h; T
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    * G1 W$ V3 S3 I6 K
  61. get1:           in      al, 64h                 ; Get KBC read status ' J1 H# d. [. }7 n1 \7 H0 b: u
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear 8 Q1 x( U# n# u3 b  J& J
  63.                 jz      clear ; i3 Y0 E/ n' U- j, M* q
  64.                 dec     cx
    3 o' q7 `' d. U% {$ l1 Y
  65.                 jz      exit3
    7 L+ m9 @) o/ c- v2 Y
  66.                 jmp     SHORT get1
    1 x' x. s7 M; R( Z  s
  67. clear:          inc     al                      ; Clear ZR # w" e  X$ Y1 u" ^0 ]1 S3 g
  68. exit3:          ret 9 {, ~, l0 x. g: \: B" a& ?+ K

  69. " S0 T6 M$ k' I
  70. 6 ], j8 ~  g* r$ H
  71. A20Read:        xor     cx, cx
    * H2 X* }" l) l( @0 s6 \
  72. get2:           in      al, 64h # O. G0 N6 }3 J* I
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    " x8 J: h3 ?7 k# `  u- ?; C  c, W  D3 K
  74.                 jnz     exit4                   ; something for me 4 g7 H0 {. B' N& Q- ~
  75.                 dec     cx
    4 ?6 C' `! K4 I# n; Q
  76.                 jnz     get2
    ' J7 a, ~) e. t, E! z" S
  77. exit4:          ret     # _% K  V" {3 k' d/ @, K* F. |: D- o
  78.                 7 i% Y; \2 C! Z' o" T
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()4 J. R3 D2 Q  h) |4 J/ w6 V
{        while(inp(0x64) & 2);        outp(0x64,0xd1);) k0 }# D+ |3 B. P9 ?/ Z0 k
        while(inp(0x64) & 2);        outp(0x60,0xdf);
4 C2 f: l! D( a  a        while(inp(0x64) & 2);        outp(0x64,0xff);
/ W: W# m4 ?& N# A2 z( a1 d  a}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-14 04:54 , Processed in 0.026983 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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