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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    : N% Q# M0 ^' G3 w3 t
  2. ; 9 s2 l) ]* T, H+ s- z+ Q
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01/ c3 ?9 @6 l5 I: k2 Y! F
  4. ;       ml A20ON.asm 5 }6 U" `) ]) z5 q# C* [( b4 d/ _
  5. ;
    ! r) D% e" {9 G+ L+ I' p
  6. .model tiny5 i% D' }& b" _% l! o1 m$ O
  7. .code# V* a/ \% `! [3 F2 b
  8. .486" _8 i; p/ `- q8 b! ?: G. O$ m  {* O
  9. .startup( I, j9 f+ x6 O: V  h
  10. ; {1 A9 @. E- D. [8 w
  11.                 mov     dx, offset msg_author+ e) i$ w4 z, l, P4 h$ d2 P
  12.                 mov     ah, 09h
    ; E, v- N. ^* C- e: N
  13.                 int     21h
    ) y% d: T  }+ \% e! g0 q

  14. 2 Q" [9 V  v! Z6 e, g/ m
  15.                 mov     dx, offset msg_fail 8 r; ~! ]$ q/ s, u$ L" P
  16.                 call    A20_ENABLE
    % Z, {5 j: }6 ]. b; ~% l
  17.                 jz      exit1/ C! L. o- x6 Z( I* H4 U. z
  18.                 mov     dx, offset msg_ok , K5 _& ^! a  Z7 B  s7 i# O: Y0 K
  19. - |) k5 `( R5 x# p& P; n
  20. exit1:          mov     ah, 09h $ I7 g/ l" H; p3 L' w. N
  21.                 int     21h
    0 _& L' j: ^) K- M' \1 N
  22.                 mov     ax, 4C00h
    , I8 p! I. Z% [* x
  23.                 int     21h
    % M' C, T5 C) F
  24.                
    7 T: {2 I* d' ?8 {
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,# P. u2 s, T( U6 N  o
  26.                         "2008-07-01",13, 10, "$" 1 g0 e& f0 b8 l9 }
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" + p2 ~( c3 G# J8 l! x- ~
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" ( z1 S$ r  z; a4 B4 U
  29. * p) X* i9 v! Y. {1 j
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------' }1 c, @1 M$ `  y% `8 m
  31. A20_ENABLE:
    + T8 q. A+ ?2 G
  32.                 call    A20Write ( d  {4 h  E$ X7 p
  33.                 jz      exit_enable# O  O) [' Z# q. y6 ]+ A
  34. 1 d+ g* Z. s! ^* z9 P$ m& n
  35.                 cli                             ; Only need for reading value from KBC
    : \0 Z# \' T7 }
  36.                 mov     al, 0D0h
    % _( b( R+ ]: w. b9 I2 @# ?% h$ B4 P. t
  37.                 out     64h, al
    3 Q0 f" j: n! B4 t7 J% Z  i6 M, v% j
  38.                 call    A20Read
    / }8 ~7 @4 V: P- ]6 e' G! Z
  39.                 jz      enable_int
    " P" {" c" G# ?2 T

  40. 5 a0 a5 T0 N+ d' S; i
  41.                 in      al, 60h                 ; Get current status
    % `5 W0 F* C# ^$ U* w9 l% Y- _8 s
  42.                 mov     ah, al
    + Y* P9 y& ]2 ?3 s& b0 E+ ?
  43.                 call    A20Write   b: N4 ^- K9 I; N# _: X' N+ F
  44. enable_int:    sti
      y6 l4 Z0 Q) q0 A2 j1 {' T& F
  45.                 jz      exit_enable
    6 o; ~5 L0 [0 t* `  \

  46. $ [3 Z8 I( E+ Q9 H# y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the / L( ^3 W% X9 q* Z% F  G  [- u4 E! k
  48.                 out     64h, al                 ; Out Put Port next ! r: [5 {( t6 m8 {6 K, z$ D" @: P
  49.                 call    A20Write 5 c: k+ \2 U7 z/ c4 X4 Y
  50.                 jz      exit_enable
    + j3 k5 T3 m! Z, n+ s4 |

  51. " [3 M4 q7 C" N  g  k) Q$ w
  52.                 mov     al, ah
    . w" U* j; x8 v; }3 I' o. ]+ m
  53.                 or      al, 2                   ; Enable line A20
    5 Q- p# ]; N2 \- J/ O1 s# E( m9 g) |
  54.                 out     60h, al   ?/ m& m. w/ G1 l; [, Q
  55.                 call    A20Write
    7 O& V0 N) L0 [$ s* r. F) `
  56.                 jz      exit_enable# {( q3 I8 C9 w& Z# S' }) p8 C
  57. " r) D8 P1 l  x2 m$ g( N
  58.                 mov     al, 0FFh                ; NOP
    + |$ X: o( o& q8 r) K' R
  59.                 out     64h, al
    ) \3 b$ i' q8 k& k+ ~+ t6 ~
  60.                 call    A20Write
    2 B+ W4 o# {! |+ [( M
  61. ) R" L, x: B/ U8 F6 D" r
  62. exit_enable:          ret
    ( D" b" |* G  e0 l. w

  63. : R% C0 c( M9 l9 ^# c8 h% t9 ]
  64. A20Write:       xor     cx, cx                  ; Reasonable wait * z; T+ I9 \4 A; G' }: Z
  65. get_wirte:      in      al, 64h                 ; Get KBC read status & e& Q2 t" S) N: k7 G; T
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 8 P* e! z6 U' y8 R8 y' P# l
  67.                 jz      clear + a5 V. r7 l$ y* ]) h( m( G9 b2 ]
  68.                 dec     cx
    . @: f- \# {9 V
  69.                 jz      exit_write
    , `7 L& T. ~0 B# ?& }
  70.                 jmp     short get_wirte 0 P+ t4 B" p3 y. h4 N9 x
  71. clear:          inc     al                      ; Clear ZR / z9 a: X' ^' _4 o; K% w% q* u
  72. exit_write:     ret 3 `5 }  K; {% _: x' o! [  q" c8 X
  73. 3 H0 x/ m4 d8 L! l3 _
  74.   p. T4 Z& x  {2 Z8 c& g
  75. A20Read:        xor     cx, cx
    4 {# a4 q% r( h5 b2 w' y& }3 o
  76. get_read:       in      al, 64h
    3 U5 Z1 }" m5 \, f8 C) j% E1 z
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    & o' ~! M) |! d8 F/ @, h" k6 k
  78.                 jnz     exit4                   ; ... & f. _' l% x, X; ?6 Z9 F9 p
  79.                 dec     cx
    ; K+ o" ]# F+ K( j) v6 v1 [7 H
  80.                 jnz     get_read
    ( N5 Z& K7 i/ e" ], n
  81. exit4:          ret     6 ~3 n6 h* @' O
  82.                 , ~9 @7 a0 q, a6 v
  83. end
复制代码
  1. ;A200FF.ASM * z% M/ B2 [1 i4 A# v  Y& S( O
  2. ; 3 m: Y1 G, C+ D- }9 l' C( G+ K1 q: z! W
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    7 `$ h% L( U% s" c$ `( `! f: l
  4. ;       ml A20ON.asm
    7 Q1 i0 W- P9 U# s
  5. ; 4 i8 y* K7 G. f* a5 A8 Q8 ]- j
  6. .model tiny! d# F7 C# Y; J) v  L
  7. .code
    ' |; F5 W2 I- \/ O
  8. .486  L% Z* e3 F) E8 I/ x" R7 @
  9. .startup: g$ ~+ h6 r- w3 Z. t) K. \
  10. * K8 l* U. ?: @& \5 N6 p2 L
  11.                 mov     dx, offset msg_author
    % ~/ F$ h# M1 s8 y2 J6 W0 Z
  12.                 mov     ah, 09h% y4 ^7 e& P1 {' J: c, s
  13.                 int     21h' ~5 _" m6 X( A2 }/ M8 T* {: i

  14. / H# z3 \* j0 x* j6 b5 D
  15.                 mov     dx, offset msg_fail * b9 X' W, P" L; r# s
  16.                 call    A20_DISABLE
    , s' s( G( r. N2 s2 c
  17.                 jz      exit1
    6 w0 b& t7 X5 J8 L
  18.                 mov     dx, offset msg_ok / d& O+ l: o2 d2 C0 s* P

  19. / |! `# H, W8 z9 j7 e
  20. exit1:          mov     ah, 09h : U& w* a. O; ~" k
  21.                 int     21h
    2 s4 a( V/ M0 V' c8 J
  22.                 mov     ax, 4C00h
    % `2 C7 Q1 z) Q* X3 m7 \
  23.                 int     21h
    / n( j& P( I  a2 X$ p, d# c
  24.                
    ) ~# o3 `. L( u+ F
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    5 O- l7 X1 B5 v, F3 o# @1 B
  26.                         "2008-07-01",13, 10, "$" 5 L/ M& k2 U# G$ x+ J
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    $ u! d2 Z8 J2 _3 O  M4 m+ T0 z1 q
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" / n7 t, D2 c; v- D$ F; j
  29. 6 ^5 n9 V0 _2 x' O: W. y& g2 k* s) e
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    * T7 a' ^8 z. z% u% D4 [$ F0 K
  31. A20_DISABLE:
    % U* T6 g2 K: E! u3 A& o! e
  32.                 call    A20Write
    % D5 x6 t. M3 i8 u3 Y0 D
  33.                 jz      exit_disable% p; M5 N, r+ q0 x9 y1 c5 L, w
  34. & h% v4 _0 t7 p4 i
  35.                 cli                             ; Only need for reading value from KBC
    % K0 m* U2 [0 @+ P2 K
  36.                 mov     al, 0D0h
    - @  p4 g' I) ]  Q6 k' F2 ^7 A
  37.                 out     64h, al $ u$ E* S1 m! V* x4 n: I6 c
  38.                 call    A20Read
    6 g$ B% m- r# z( Q; u! Q. S" T
  39.                 jz      Disable_int + z! g/ Q2 v, I2 q, m8 O
  40. : A' n, y) p! o5 D/ _
  41.                 in      al, 60h                 ; Get current status
    # M# S7 b$ @+ N% f* x$ o
  42.                 mov     ah, al
    # w! {) s+ J3 e) @5 I1 _2 t9 |+ {
  43.                 call    A20Write
    ( A# R* {! l8 ~- a! M
  44. Disable_int:    sti : m- |" V" l( d3 _. |: z$ o. x0 A4 i
  45.                 jz      exit_disable
    ) L3 f; q( }2 k1 Y6 p4 D: d

  46. 4 p2 |! I8 s( V$ E$ ~7 B
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    / n5 _2 x9 S8 a7 f- t1 \4 g
  48.                 out     64h, al                 ; Out Put Port next
    . {; p7 n9 Q8 T; n3 A4 g7 ~
  49.                 call    A20Write
    & O% A' e3 f: d/ D( ~( S& E
  50.                 jz      exit_disable: B, n) ^9 z, N' C
  51. & d: Z0 a! h$ b8 O& k
  52.                 mov     al, ah % n% `; L- _1 k4 f8 G- `- {
  53.                 and     al, not 2               ; Disable line A20 # k' h( f( p+ [5 }
  54.                 out     60h, al
    , F3 W' k+ R- t
  55.                 call    A20Write & [8 {9 ]1 m3 R* P2 ^5 K& O8 k: g
  56.                 jz      exit_disable" n5 u! U/ f# M  O5 i2 n
  57. - x& [5 Z, i3 _/ H$ W
  58.                 mov     al, 0FFh                ; NOP ; N8 c9 R) d8 K$ q6 E: o
  59.                 out     64h, al 3 p0 t8 W4 A" S4 a# g( m0 M
  60.                 call    A20Write
    8 G  Z3 }# L4 q% a* L9 i

  61. & t2 ^1 k' T$ x9 i2 [
  62. exit_disable:          ret 4 |' F7 ^9 Y5 |

  63. / S" @$ `# ^# w& Y: X  @2 M; f
  64. A20Write:       xor     cx, cx                  ; Reasonable wait 0 ~* W. `7 X9 g% z4 b+ S, ^
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 2 Y  H. b1 k2 @9 B# J8 }$ o
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    " }8 {9 G9 x4 G  z  F# b
  67.                 jz      clear # d* k3 z6 {" y/ M9 ?
  68.                 dec     cx
    : D; `1 g! j  K+ Y/ X) j  X8 c
  69.                 jz      exit_write ) w; ~7 d' c3 f; _& H8 N$ u
  70.                 jmp     short get_wirte
    5 r& C2 T5 U& y/ Z' z8 d/ k' i2 p4 T
  71. clear:          inc     al                      ; Clear ZR + z7 W  ?6 H; r: s
  72. exit_write:     ret
    6 B2 b: X/ N! n, D3 e) g
  73. 1 f  s. m& r& Z, [
  74. 3 R' V' _: G" r! M' [, U/ [
  75. A20Read:        xor     cx, cx
    , U$ k4 Q: M! _
  76. get_read:       in      al, 64h 2 {/ ?$ l' R( b/ J+ o: S0 e( f
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    3 T+ ~) A( K/ v$ w$ ^
  78.                 jnz     exit4                   ; ... ; T" N. C; \$ p# \8 e
  79.                 dec     cx 7 K6 d) @- S; V
  80.                 jnz     get_read
    " A% A) @( q& W5 M% r
  81. exit4:          ret     
    4 r, l- |0 Y4 F7 {) V! O+ M
  82.                
    7 @) G/ i- K) c+ o
  83. end
复制代码
  1. ;A20STATE.ASM 1 y6 I: E8 _) e. n  A* O2 ~; o( z- F
  2. ; 1 k& `4 r# }, f7 y$ x' C! O) H+ J
  3. ; Returns the status of the line A20 through the KBC
      y  E" d+ `* b; j$ N/ o
  4. ;       programming by bini for debug. 2008-07-011 U& ^% V$ V* a" W
  5. ; ; a7 M5 B; g  L' e5 a' C
  6. .model tiny3 l- N2 g7 L& ~/ W, B5 ^/ N! y) s
  7. .code
    7 v* v( T7 b7 Q
  8. .486
    + Q3 s0 I3 w  Y  n0 y' m
  9. .startup
    ! {  e4 V- A7 L( D$ X2 E$ [
  10.                 mov     dx, offset msg_fail
    5 D2 ?0 k2 I% {1 \7 }
  11.                 call    _GET_A20_STATE_
    8 C* `, W2 u8 Y+ L, u5 }! G: V
  12.                 jz      exit1                           ;  was a problem& b3 T. s/ q" a# u" A4 @- p2 m
  13.                 push    ax                              ; Save state, AH
    : A8 J2 D( B) S9 N% M" }! D- W% c
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    / Y  a( S  a0 v. \2 o
  15.                 mov     ah, 09h
    3 Q0 G9 n5 d- w& k
  16.                 int     21h                             ; Print message   p) z1 v8 `6 u! G/ z
  17.                 pop     ax                              ; retreve state
    " m9 Z6 H$ Y/ p, A- |
  18. ) x' U/ ]5 X+ b
  19.                 mov     dx, offset msg_dis & R; Y# X' r0 N2 j0 e% I
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    1 K! J& V1 W: H; _4 Y) n$ C
  21.                 jz      exit1
    . K3 ?/ I8 A4 I6 b6 y
  22.                 mov     dx, offset msg_en   c2 z  U! j3 r8 o! a

  23. # J' {8 q# Q* v  T; `0 M
  24. exit1:          mov     ah, 09h
    8 A- n1 y& B: \7 A, E
  25.                 ; DX already contains address of string
    * H4 `0 l* b) `0 Y5 e
  26.                 int     21h 2 e7 f: Y& k  Z+ ~) z

  27. ) K' H5 Z6 E2 T- m# k
  28.                 mov     ax, 4C00h 0 A1 ^5 ]% I2 v; R, }6 M8 Q
  29.                 int     21h . K3 d4 ~7 B8 i# S6 D

  30. ' x6 _9 S, E4 N! |% `8 E# w7 G
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ; r% i7 L/ o$ q" R( R1 Y( ^- ~: @
  32. msg_fail       db      "FAIL", 13, 10, "$" ; G, z( P& s, k' S) d
  33. msg_en         db      "ENABLED", 13, 10, "$" ; I" g! F/ `% m" b- O2 x
  34. msg_dis        db      "DISABLED", 13, 10, "$"- Z4 N" d5 V, T) b, X; z  z

  35. / T% I; p. N' j4 L2 a" k) n9 p
  36. / |% L) O, V8 w" k* I; v
  37. _GET_A20_STATE_:
    3 P; {/ I" }& z. u; d
  38.                 call    A20Write                ; Wait till the input register is empty
    9 T7 u3 y% F) p
  39.                 jz      exit2+1                 ; Bypas the reset int's
    7 ?- A# x) Z4 a; z3 ^
  40.                 cli                             ; Disable ints so we'll get our value   ]6 f/ F% i1 t/ S
  41. $ W' C5 F, c0 t7 C9 C$ {' W
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 6 f9 k% E$ _, Y
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port 4 j! c- A4 x5 M$ h  @
  44.                 call    A20Read                 ; Wait till the 8042 output register 5 k- Q- a; b7 l! h2 u" K+ a
  45.                 jz      exit2                   ; has something in it's buffer 2 T; \3 P. ?, g6 H% h; A. @

  46. 6 |+ k% W4 Z- D6 Z
  47.                 in      al, 60h                 ; Get it 3 o7 r. H8 I5 A0 F& j. Z3 s
  48.                 mov     ah, al " ?1 x9 ^; K6 F/ e
  49.                 call    A20Write                ; Make sure the input register is empty
    ' }' H+ m8 |! l, `+ L7 X
  50.                 jz      exit2 % O/ e  V. o+ G( K! ^
  51. - r! o+ A% ]8 K  F& Z
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing ! M/ \1 }" U4 t# \
  53.                 out     64h, al
    * Z- l9 n8 M- U
  54.                 call    A20Write ) ]+ ^2 \7 m' d! G: r
  55. + W% M4 L, |1 y( u1 y
  56. exit2:          sti 0 H8 r1 V6 e1 Z% x3 U  Q, N
  57.                 ret
    * f% {; U1 I: l# U
  58. 5 U: e% c* V& j0 I# U  `9 [; l: W
  59. 0 S% T" P" X& H# _0 r
  60. A20Write:       xor     cx, cx                  ; Reasonable wait ' {: b1 r& U3 e4 Y7 h
  61. get1:           in      al, 64h                 ; Get KBC read status & j6 P! C) ]0 K# N
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear   t7 W$ S2 W# r- A( ?0 T
  63.                 jz      clear
    8 Q' q3 `" ]4 A; ~
  64.                 dec     cx 2 F5 _/ C  `9 I( @2 Z' O
  65.                 jz      exit3
    ( ~, [/ S6 J9 P- p; x: c
  66.                 jmp     SHORT get1 0 ?- M5 b2 U: N6 H) [9 w
  67. clear:          inc     al                      ; Clear ZR
    $ T1 q  j% v8 L4 p: B
  68. exit3:          ret
    ! d: o5 e, Y9 \3 k" e, j1 I( K* A% o
  69. # o( ]* ]/ B  Q: t4 Q! M" K
  70. * _6 p/ g# g/ A, g- k8 F2 Q
  71. A20Read:        xor     cx, cx
    3 @& @- P! Z1 o; ]3 u( y( l8 i
  72. get2:           in      al, 64h
    5 q* Y% v! |4 Z5 J) w3 P
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    * z1 g. m) u6 e# L
  74.                 jnz     exit4                   ; something for me
    8 U% M, h( i  {/ u: F5 B" k- I: P
  75.                 dec     cx + R) r- J0 v( z' |4 ~# v; V
  76.                 jnz     get2$ V6 D" m. W/ B0 v
  77. exit4:          ret     ! b$ e# e$ W5 m( R9 @
  78.                
    : B* x/ j% }8 I  l, N3 h5 \
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
+ Q; @  ?& e0 b& R# P% o{        while(inp(0x64) & 2);        outp(0x64,0xd1);
2 U" \. ?, Z# u" j6 C        while(inp(0x64) & 2);        outp(0x60,0xdf);$ K; D! r9 F$ u7 \. b- d' s
        while(inp(0x64) & 2);        outp(0x64,0xff);
8 [- h. j6 G6 n& K( O  K}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-5 15:59 , Processed in 0.337958 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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