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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 8 o$ F7 I0 g4 a! J0 m- O
  2. ;
    ' r$ b; V$ I2 S
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01! X2 G* V; U& ?" ?  q# v  b
  4. ;       ml A20ON.asm 2 I! j& L- S: U" i, Y: \( i
  5. ; ) u4 v4 i% }' {- e! a1 @4 j
  6. .model tiny, w; p7 Y" ^& ^  v
  7. .code
    0 k+ g( [/ c) k4 d; j( v
  8. .486& ]0 _+ N6 K; W0 a
  9. .startup
    $ ]/ {* G  K/ R9 G
  10. 1 U. Y2 t5 a6 L5 W# e7 z+ Q
  11.                 mov     dx, offset msg_author
    0 k; d2 ~" Y9 ^% t( l
  12.                 mov     ah, 09h
    8 j( B0 x0 |/ i! [* U
  13.                 int     21h
    0 ?9 x) n: S: l6 D

  14. 6 K$ n: G9 ]% n1 w: d6 K: K' R3 O
  15.                 mov     dx, offset msg_fail 2 o$ _3 {0 p4 B+ V
  16.                 call    A20_ENABLE
    * |+ _4 n; Y' b- g/ W$ v
  17.                 jz      exit1' E, l% n9 ~, f6 t
  18.                 mov     dx, offset msg_ok
    6 C0 _. j6 C4 W9 u3 M; O

  19. $ T- |" O6 u. j9 H! o+ h( U8 E3 p) r
  20. exit1:          mov     ah, 09h
    # P! B( V) k# o9 Z- z+ {- Z% J
  21.                 int     21h
    2 g, a$ `" X- S- v, n8 O2 ~- |0 K$ B
  22.                 mov     ax, 4C00h 3 L, ]$ A+ ~- ~# `0 T+ ~; _
  23.                 int     21h
    ; A$ b- X5 b( S8 t6 |4 k6 f# A
  24.                
    5 z- u# c" R0 a0 T, n8 ^4 ^5 ]
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,8 V  j. w- }( {7 ~; l$ M# g$ P
  26.                         "2008-07-01",13, 10, "$"
    3 Z$ _9 ?8 ]; v& W
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    ' |! I! f, z. F2 Q- g2 [* i
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    ' F1 Z5 e4 z2 G8 _9 U
  29. 2 A6 W1 c4 U% `0 j1 a0 K5 d
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------* w& f) }. s1 X3 R9 H! u/ q# k- T3 }
  31. A20_ENABLE:
    3 t! ~: b9 H. c" m# o! R
  32.                 call    A20Write ( f# T: l. m* \1 |" b1 T" I/ G" z
  33.                 jz      exit_enable4 X; m8 h% ^) ~6 E* M' T7 ^

  34. # F, {( _: o: }5 Y. _' P
  35.                 cli                             ; Only need for reading value from KBC # \. \& O% W9 |0 |  M& O
  36.                 mov     al, 0D0h   d6 q" t7 [- Z- k# L( D2 p
  37.                 out     64h, al
    5 \4 z( D8 e, _. H0 \
  38.                 call    A20Read / w& v& N1 x! v
  39.                 jz      enable_int
    ; c0 Z" O* N) [0 Q% Y

  40. + A8 `7 z8 I4 ]5 |3 [6 h
  41.                 in      al, 60h                 ; Get current status 1 v0 }7 l4 O3 e
  42.                 mov     ah, al
    2 i8 }+ q# t* d; }0 s8 u
  43.                 call    A20Write 1 p9 h6 d- h2 q0 R. b" U! x% G( W
  44. enable_int:    sti
    2 Z3 m" z$ \, _' B7 u/ |- t
  45.                 jz      exit_enable
    , J! e/ o( g3 n; E+ G2 \; h! h: g1 o

  46. 9 {4 E( K/ ]: B9 j4 _
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the # f" }9 z9 ^1 g) n( C/ a
  48.                 out     64h, al                 ; Out Put Port next
    2 X3 t$ g4 b- l1 l/ [
  49.                 call    A20Write ! T( Q- X- i0 _8 [* \3 o- I
  50.                 jz      exit_enable1 _! r0 A6 b5 w" ?5 @" A

  51. ; K; Z; x# y/ B4 o; v& O
  52.                 mov     al, ah
    4 b: u2 m4 B- [% V, A/ L- B' ~) L
  53.                 or      al, 2                   ; Enable line A20 ; H. \9 g- ]( X3 m, Q3 A% h
  54.                 out     60h, al
    ' ]) ~% F, c) A+ K$ R9 D5 F0 n
  55.                 call    A20Write
    % p4 U! h7 h/ \; w
  56.                 jz      exit_enable
    7 d" g8 ?1 w3 p3 l2 M( P- C
  57. & W+ [) Y' u/ ?
  58.                 mov     al, 0FFh                ; NOP
    6 O% R3 S1 }; ?3 I1 a8 N" L( c# r8 J
  59.                 out     64h, al 5 d. C. y! l* q  N
  60.                 call    A20Write ; H; F1 Y' f; j
  61. 8 D& R' n, [! C) M
  62. exit_enable:          ret
    0 k/ s0 Z3 v3 E. d

  63. / O$ Y  w. q9 h. _' a
  64. A20Write:       xor     cx, cx                  ; Reasonable wait + D/ d: D# L& m& a! f
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 9 G* N5 N8 ^6 g. ?
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    + Y/ W! _4 `0 L
  67.                 jz      clear 5 \2 u* b- z8 h4 T" g; ]1 K$ F& E
  68.                 dec     cx
    & J/ l. }0 `0 ?6 C% P
  69.                 jz      exit_write
    & t, T6 E/ ?" o) X7 w. B
  70.                 jmp     short get_wirte ; m2 Y$ W' p' c3 G; j. w9 m
  71. clear:          inc     al                      ; Clear ZR 4 l- \+ I: U6 ^: D8 A; g8 A
  72. exit_write:     ret $ N1 H5 @# R2 D& M. q8 z0 F$ J

  73. 5 s; ^* ~7 A* D6 v1 f; c4 S, r

  74. ( o8 ~$ O' Z, ?3 F  c2 X
  75. A20Read:        xor     cx, cx   ]6 S9 n6 }2 C% k
  76. get_read:       in      al, 64h
    - N. E( h1 Q+ l6 M8 V' e% K3 C, Y/ N
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    . L5 _9 e* l) G  k
  78.                 jnz     exit4                   ; ... 9 j# Z! I4 T* {, M* S
  79.                 dec     cx ( j3 e5 U! G1 e) B& }0 [2 s9 ~
  80.                 jnz     get_read
    % ?3 O* s& J* t0 U. z6 r( _7 n  R  ]
  81. exit4:          ret     9 d$ k/ R* Y: w. p5 B7 x
  82.                 1 y7 C0 g7 f% P" [* R$ h6 W
  83. end
复制代码
  1. ;A200FF.ASM ' u3 \1 m3 j' k$ Q  h
  2. ;
    ; I- O. \; w3 Y9 V* N, R4 ?$ i' B/ ~
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-019 g3 o$ y: @: M- T6 m: h
  4. ;       ml A20ON.asm
    " ~1 f- M' \" V  |
  5. ; - c/ N7 T2 x: F, V  F
  6. .model tiny
    9 Y/ U2 g7 A$ C# g
  7. .code) E2 |) f: \9 G/ _7 ^# N. m1 v
  8. .486- ^6 s  Q. _6 `  F+ W! ]; @
  9. .startup: t; }# n) Y4 c0 a' E: G
  10. - h8 z/ {+ ?& f4 K
  11.                 mov     dx, offset msg_author- L- o- Y- p) A1 K
  12.                 mov     ah, 09h# b( U& n' k+ Q
  13.                 int     21h
    1 h! Q9 ]5 \, F8 _
  14. 1 i7 R5 f2 {, i, a9 q1 T: |
  15.                 mov     dx, offset msg_fail $ V  |' z9 ~# G8 n0 B
  16.                 call    A20_DISABLE
    . @1 \, y. J" ]( h+ L+ v
  17.                 jz      exit1: w; K9 s2 I/ t
  18.                 mov     dx, offset msg_ok 7 S6 w4 X, O, e% g$ i2 ~9 Y, G' U7 _! Q

  19. 8 G4 l  {' o9 S. D! u4 b! w
  20. exit1:          mov     ah, 09h % b+ {6 r6 s) e3 k% k3 R1 {
  21.                 int     21h % K0 v/ B+ c& L9 [; L
  22.                 mov     ax, 4C00h
    : ~( E3 M8 l! l2 I- R9 ]4 [
  23.                 int     21h % c5 q) }2 Q5 t2 Q$ \, [5 l4 k  l
  24.                
    ' {- Q! M5 M) ~! I4 \& n1 n: b
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,: m$ X9 v# ^# E
  26.                         "2008-07-01",13, 10, "$" ' G+ e( a/ Z9 Q; g9 ?) }
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    6 y3 ], n6 b+ k8 ]& Y
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    7 X  O" B. ]6 ~; L' n& a

  29. " l: w9 n. q; n4 D
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ; R( l$ z& p) e
  31. A20_DISABLE:
    " J5 i# o6 _5 @; p. I' f
  32.                 call    A20Write
    , B- }  L" i1 j# U  z% k
  33.                 jz      exit_disable0 I; G" |9 n  c
  34. + @" q1 c  S5 h# q* e
  35.                 cli                             ; Only need for reading value from KBC
    7 R: ~( K9 d- T* M
  36.                 mov     al, 0D0h
    % k* F) v3 Q0 S
  37.                 out     64h, al + n$ p! ^+ w' b7 C& A" \! g0 x
  38.                 call    A20Read : C' f$ n7 [! y4 j
  39.                 jz      Disable_int 5 |6 A0 ]' H4 i- i3 U4 D

  40. 2 v! a# O: C2 _2 f
  41.                 in      al, 60h                 ; Get current status   w$ m3 Y0 Q9 x
  42.                 mov     ah, al
    8 }3 Y( w: s, Y3 r
  43.                 call    A20Write " J: [; }5 F+ }# [- Y3 t
  44. Disable_int:    sti ' f, `, B9 }$ a2 w& I
  45.                 jz      exit_disable3 X! q3 H2 h1 z* {& q
  46. + z( _( G7 D* X
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    & _) U  {4 u- m' f
  48.                 out     64h, al                 ; Out Put Port next
    $ ]: a1 V: z5 ]& L: c* b0 y
  49.                 call    A20Write 3 F- G4 `0 Q: \* J
  50.                 jz      exit_disable
    0 `* G1 e* q5 n2 F" {" [6 k* _
  51. - v+ P8 X: i1 M8 C6 V' k4 N
  52.                 mov     al, ah & Y! l4 ]4 M5 D- }/ ^$ ]" n
  53.                 and     al, not 2               ; Disable line A20
    / y6 O- o( y* F
  54.                 out     60h, al ; M  P3 z3 @3 c3 P* s+ L- S
  55.                 call    A20Write ( P5 O4 K2 C  Z! w" v* `
  56.                 jz      exit_disable& C/ I3 H& B9 o" h1 y
  57. 9 k8 r# w4 S# o) p6 b  V  |+ Q
  58.                 mov     al, 0FFh                ; NOP
    & U( @! s. ~9 x. F8 D2 Q$ G$ E
  59.                 out     64h, al
    4 l; H4 x2 l" [* D8 h8 F8 ?6 A
  60.                 call    A20Write
    & Y2 j9 P$ q  V$ F2 i- P
  61. % p& Y4 Z# z* ]. v9 U0 v3 b( C
  62. exit_disable:          ret + H6 F" B3 i/ b1 v! u* Q, ]
  63. # o( E/ E4 _5 W* v% `
  64. A20Write:       xor     cx, cx                  ; Reasonable wait , U9 p1 [( w+ ^5 z( [) F
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    + t3 P" O  q8 f7 t+ |, E. k* R4 n
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear $ i2 {& e  a3 Y0 d  T' }+ o. O
  67.                 jz      clear
    + N* P8 R  W5 ^" e/ d4 O
  68.                 dec     cx / `$ y, b4 E7 T2 ^3 L
  69.                 jz      exit_write ; ~0 c4 D3 w: X6 j* j9 l4 e$ O
  70.                 jmp     short get_wirte
    ' c, x/ o3 @: R6 E: e& O, s) e$ C
  71. clear:          inc     al                      ; Clear ZR
      @8 f3 [- s8 }3 H2 Z, u
  72. exit_write:     ret ! B. `1 m) d( E" m
  73. * {/ ~) j: q0 s; b2 Z8 X) [

  74. * ]7 y. S# K3 m
  75. A20Read:        xor     cx, cx - O" ^, c0 C+ N4 m/ N
  76. get_read:       in      al, 64h
    : J4 O8 J- P# @
  77.                 test    al, 01                  ; If the 'output buffer' is full, has % I0 ]3 q2 H" }7 k( ~: t1 g/ K  t
  78.                 jnz     exit4                   ; ... ( Q* T6 U9 s' a
  79.                 dec     cx
    + y( t* i9 N6 ^; i  F
  80.                 jnz     get_read
    : h: b$ S; @7 l9 a
  81. exit4:          ret     
    * I0 ^: O1 ?" Q1 C8 M
  82.                
    $ l; Y* g  e! {# |, d( W
  83. end
复制代码
  1. ;A20STATE.ASM
    . Z0 z9 l/ v/ v; B$ m- j
  2. ;
    / S3 o6 A# g  n; C3 o/ @
  3. ; Returns the status of the line A20 through the KBC " ?4 [& ~- k/ J# `1 Q
  4. ;       programming by bini for debug. 2008-07-019 u1 J9 h+ n/ d: b5 _
  5. ;
    $ ~9 a% ?6 {/ z+ z0 E2 B( @8 X3 x
  6. .model tiny. T0 Z: u2 a$ T' P  X
  7. .code
    + {, d* T% a$ w- _
  8. .4864 x# C$ c( u/ A' s% I  g0 j1 @
  9. .startup8 T1 {4 I0 Q; u. t9 Y# {1 e
  10.                 mov     dx, offset msg_fail - g' m4 X5 B! G5 }' P' X
  11.                 call    _GET_A20_STATE_+ Y, F$ k4 F$ H8 k6 ]( ^/ K6 A
  12.                 jz      exit1                           ;  was a problem
    ' A! D& X  q* }4 k( `
  13.                 push    ax                              ; Save state, AH
    4 E* b8 h8 C3 M/ t: R5 J/ ^) e
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem + @( T# a  x2 H, U: i/ ?
  15.                 mov     ah, 09h
    3 T. C0 K# F7 ^2 q+ Z2 x6 Q
  16.                 int     21h                             ; Print message
    " o; _7 a7 F) d5 u4 n, M2 w
  17.                 pop     ax                              ; retreve state
    , z0 T1 _% s  E' `! g- Z
  18. 5 ^8 E- S) Y: q6 c* u6 c
  19.                 mov     dx, offset msg_dis " V# I& d  d  E2 k& `9 V
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    6 N- G5 a4 l4 @' P5 [5 b& `4 n
  21.                 jz      exit1
    5 }' s: {% P& e3 Y2 M
  22.                 mov     dx, offset msg_en # m, p' m, d2 H6 h" _* o: L

  23. ( t; B8 r* Q. M8 \' O+ @& H
  24. exit1:          mov     ah, 09h 5 V, \5 L' W/ _* r3 Y
  25.                 ; DX already contains address of string
    ' x3 l; v- T9 Q7 R& _0 u# O, R
  26.                 int     21h
    8 Y& w- Y) Q+ t4 ?) q  ?' ~% P2 n
  27. + ?' L$ O- J: B2 j" e1 ?) a$ ?
  28.                 mov     ax, 4C00h % U+ S3 Y/ D7 W9 p$ j
  29.                 int     21h - d) I/ E9 h- u: ~5 L
  30. + E# j7 ]* C- W
  31. msg_ok         db      "OK", 13, 10, "A20 $" : d; [- D  B: H; g! B5 {
  32. msg_fail       db      "FAIL", 13, 10, "$"
      w5 C0 G, j! ]* I; A' O# u- U6 }
  33. msg_en         db      "ENABLED", 13, 10, "$"
    " \, ^9 x9 Z& k+ _/ l. B
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    % `8 Q" Q! A& l) }2 n

  35. * P6 F: q3 L! h7 n3 Z

  36. ( {9 F0 a  Q2 |$ R
  37. _GET_A20_STATE_:
    % K$ p# z" q/ y, E3 j  W
  38.                 call    A20Write                ; Wait till the input register is empty : A/ b  }$ I+ m: |" g6 A
  39.                 jz      exit2+1                 ; Bypas the reset int's ' L/ ]! a. j% y% }
  40.                 cli                             ; Disable ints so we'll get our value $ g; z" C9 ?6 d2 ~+ c
  41. % Y- m) K" \, {$ J7 n4 h
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    $ ^& f4 H  K! K8 ?) \: W5 G
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port # ~6 ?  q, ?+ U& x$ N0 o5 s# q& @
  44.                 call    A20Read                 ; Wait till the 8042 output register . H! |4 Q/ K4 q
  45.                 jz      exit2                   ; has something in it's buffer 5 q4 B% k0 l0 F- [" X$ d* }

  46. $ l; Y8 I: e! i+ X2 J- ?' u
  47.                 in      al, 60h                 ; Get it / u6 U$ }5 W# L1 x3 N
  48.                 mov     ah, al & ~  G1 C6 W9 b4 A- b, w
  49.                 call    A20Write                ; Make sure the input register is empty
    , M9 M0 o0 y* G; q' T" \+ V5 {
  50.                 jz      exit2
    4 z$ C0 ~9 w+ z. \8 ?" p9 h
  51. ' X* o# N: ^$ L( Z: k
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing 5 o1 z3 p  T9 T6 W+ e" J
  53.                 out     64h, al
    5 P- e8 a; \6 }$ I1 e, o$ Y! }* ?
  54.                 call    A20Write . ]7 f( V. e# q1 Z

  55. # Q# m6 z$ m6 y& _! Q# ?- G; w
  56. exit2:          sti . f# D1 ], r: p3 K- O7 A( I5 [+ t  _
  57.                 ret
    ) \% M( J4 |, V5 R( s
  58. ! Y5 m; p8 `: k/ B0 ?1 H& X
  59. , s  J9 H9 s9 ]8 T! g7 L( S
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
      J$ i* k: Y" e. A
  61. get1:           in      al, 64h                 ; Get KBC read status
    - n7 p+ M  W$ }" a
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear . g, P5 k& |0 c6 u
  63.                 jz      clear + f6 y6 n- T; v8 L
  64.                 dec     cx : U& j% y+ _# Q  K( |# Y/ ^
  65.                 jz      exit3
    ( z* o; |$ u+ Q
  66.                 jmp     SHORT get1 ; U& T$ j. S. y9 P* a+ s0 b
  67. clear:          inc     al                      ; Clear ZR
    / e# C" K1 f: h5 E2 s
  68. exit3:          ret 6 a5 f& r0 v6 M- H
  69. ; _9 t8 {0 T4 K2 y. e1 P, Z
  70. 6 v' _% p8 k+ n$ P6 o4 |7 ]9 u# g
  71. A20Read:        xor     cx, cx
    + Z: ]6 d; ^2 r! ^9 u
  72. get2:           in      al, 64h
    3 ]' {7 j3 K& `  M
  73.                 test    al, 01                  ; If the 'output buffer' is full, has ( }9 w$ e; v; i& E1 v! o. o
  74.                 jnz     exit4                   ; something for me
    ; C  d+ `( v& n) o+ y1 V
  75.                 dec     cx
    9 U7 v& d5 p3 E  T+ {: s; P5 {
  76.                 jnz     get2, D7 Q' o! [( J
  77. exit4:          ret     
    % F: a, h: @0 T& F  ^" j
  78.                 , w$ X9 z- p8 _, b" V! R: ]+ i# a: f
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20(); n$ i1 H8 T0 E. q
{        while(inp(0x64) & 2);        outp(0x64,0xd1);  H, ?  F; S0 [/ Z/ r
        while(inp(0x64) & 2);        outp(0x60,0xdf);; \1 q8 L( Y+ j
        while(inp(0x64) & 2);        outp(0x64,0xff);
+ q- S" V& o" g( z* l$ Q2 O- I* b}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-7-21 22:15 , Processed in 0.056653 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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