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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 7 O1 ^! G# |% t7 N: ^! I2 O
  2. ;
    ; N: n8 B1 _. _
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    " I6 K( ~4 K% A6 @( p! c+ o) e
  4. ;       ml A20ON.asm
    ) e1 V' c0 N- I9 P. i8 m5 s% R! |
  5. ; # ~* y% m2 Q$ M5 F6 Z) r
  6. .model tiny
    , U" y' s% ^3 |: ~+ g* V
  7. .code
    ' h5 O$ J/ t% u9 E5 e: @7 s: Z
  8. .486+ D% I. s  w7 u1 G
  9. .startup
    , z9 S9 k1 w% U6 t# E
  10. 6 b3 I: ~" N+ ]; g& o7 F% C8 H
  11.                 mov     dx, offset msg_author0 B5 K" |* {8 S* N5 O$ _
  12.                 mov     ah, 09h. D. e+ a$ |1 X% E/ N' m9 P
  13.                 int     21h
    / X2 G6 E- k( K8 ?
  14. $ m7 {  F/ z% p
  15.                 mov     dx, offset msg_fail
    ' V* R2 f5 ^& ^
  16.                 call    A20_ENABLE
    9 h& M' o& T1 W2 P
  17.                 jz      exit1
    ; g2 }2 {( O1 s( _4 b1 s
  18.                 mov     dx, offset msg_ok
    / y" [* F& b/ T# M) }7 s
  19. - \/ F' x2 m  |. c2 P5 Z: n
  20. exit1:          mov     ah, 09h * _; u9 N9 y* `0 K7 e
  21.                 int     21h 9 o* w: o) `7 C$ K: L6 `
  22.                 mov     ax, 4C00h ) l1 s: o3 \, g4 @2 _, }) W9 T7 s! s
  23.                 int     21h # \9 W  w: K! k  j
  24.                
    3 @6 r2 c, @9 @  w9 n
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,1 ^- J+ X: S9 }# ^1 E% @. `
  26.                         "2008-07-01",13, 10, "$" * C% Z% A/ M7 K
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$" 6 i; s9 c+ ~1 a: d5 M& s- j
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" ; f7 [( q7 X; t- G) X
  29.   P; @5 f, b, \4 P6 [* i
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    6 u" B- s& H# Z
  31. A20_ENABLE:   z. y# `3 O! n+ R+ d7 @
  32.                 call    A20Write
    , I- s; L8 Y, R0 H! V2 Z
  33.                 jz      exit_enable: z' F! l: ?0 b) a& B+ Q7 U

  34. ( i  B. t  s/ a3 N0 r; V
  35.                 cli                             ; Only need for reading value from KBC + S0 f8 m# X! e. p- D6 f6 }+ J
  36.                 mov     al, 0D0h
    $ j3 A; a( D! G! \0 m& t
  37.                 out     64h, al ) v# h; g0 H1 {( e. v
  38.                 call    A20Read
    1 }0 E  s0 {0 y- b; }7 y- D$ k
  39.                 jz      enable_int ! j" A& e  b- X# _2 ~1 M/ Q
  40. 1 r% [) ^: m: V; `% g! A" l
  41.                 in      al, 60h                 ; Get current status , A9 C( C# Z0 J7 E+ |2 v- r- T
  42.                 mov     ah, al " R4 L2 Q8 t' q9 f. b6 Q+ |+ c
  43.                 call    A20Write : ]0 L% d1 X( p) T! y2 S+ V& G
  44. enable_int:    sti
    4 h1 Z7 N: |9 |2 M. l. A
  45.                 jz      exit_enable. J  t# p* C0 l0 R! }" K* C' D* p
  46. $ c% d- \) P6 [1 Q1 @( T, ^
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    2 [1 C, s+ G) @; M3 o
  48.                 out     64h, al                 ; Out Put Port next - q0 Q0 a, k  B. o* Z
  49.                 call    A20Write $ ]  Z$ K( A7 Z, y9 S; I
  50.                 jz      exit_enable
    1 [! V6 s9 F5 R& ^

  51. ; @6 U& O/ m  @% r% L& X0 q
  52.                 mov     al, ah ! \7 [- E* p& a+ U
  53.                 or      al, 2                   ; Enable line A20 7 `3 E1 ^, V6 F+ ?' @
  54.                 out     60h, al , Z- t1 W1 b1 `* [! R) t
  55.                 call    A20Write + Q; A, _; N( R. P0 X0 i
  56.                 jz      exit_enable
    0 i+ L$ f2 J. M* g0 G! \

  57. . K: C" X- ^, }% m  |5 ~2 r
  58.                 mov     al, 0FFh                ; NOP
    # ^' d! Y8 n# w0 s- C1 E) Y6 ~: g
  59.                 out     64h, al : c' Z' v2 \7 [- z! Y+ A4 S, m/ |
  60.                 call    A20Write
    7 o  R3 p  |- ]% X0 B
  61. . `) H; w: K& p3 S. _
  62. exit_enable:          ret $ t+ d9 p& I. B! e
  63. 7 t0 Z, D5 S* `3 f) {
  64. A20Write:       xor     cx, cx                  ; Reasonable wait : b3 A1 k1 b4 k+ h* E9 z* _" K! W
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    * {2 w/ F: x5 d' k6 c9 R: n+ g
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 8 X' ?6 H/ |0 Y5 p- G: Z
  67.                 jz      clear
    : O8 _: @* j+ u8 z( `
  68.                 dec     cx
    0 |: I2 v8 f6 \5 z* h
  69.                 jz      exit_write
    ! `7 K* D1 f) O6 K
  70.                 jmp     short get_wirte
    : P5 k# e$ ?# \3 k0 C
  71. clear:          inc     al                      ; Clear ZR
    ) d& D0 {! k) l2 J4 S
  72. exit_write:     ret 9 M& \8 Q8 E1 f6 y5 p
  73. / X& @- F3 s9 `; a' p8 U
  74. 2 h! j: U; U# r. O, J# [
  75. A20Read:        xor     cx, cx
    ' }+ m/ k8 m" k) N1 P. B
  76. get_read:       in      al, 64h 4 L# A1 i2 y% i4 c
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ! G% C& _: w' j7 l" K4 V
  78.                 jnz     exit4                   ; ...
    - D  g# F& B! }- T, D4 }8 S5 S
  79.                 dec     cx
    & g; u2 r- U. C+ m3 z, w4 b
  80.                 jnz     get_read4 H$ I. a$ }: x. c# c" c1 u. {
  81. exit4:          ret     ! L* m0 y8 l1 R$ [. v* }6 @
  82.                
    8 j$ \: y! ?% s8 l* Z
  83. end
复制代码
  1. ;A200FF.ASM 8 @" |, c$ M% c8 V8 J) X' _( i
  2. ; ( x. m& I9 }6 I$ H8 D# S
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    5 V0 I4 R+ g! g3 q( o
  4. ;       ml A20ON.asm
    ; U; t% o$ E8 z5 S: p8 x9 y8 s
  5. ; * d  U) O* O  _
  6. .model tiny
    8 Z3 {4 {0 G( ?* O" H+ V8 n
  7. .code) E2 c; m* ]* k# I! K
  8. .4861 o0 K  M% o& F6 `2 Q$ D  ^
  9. .startup8 A4 K0 R; g" T; C( N; `5 e  h
  10.   O6 {$ c7 l' e
  11.                 mov     dx, offset msg_author
    * D. X$ M* A3 Z  C
  12.                 mov     ah, 09h* K" B* A6 G9 r2 z
  13.                 int     21h3 g/ X* \' x# n, r" N# }8 L3 A. C
  14. & u3 k$ u# F* P) p( ^6 R
  15.                 mov     dx, offset msg_fail 0 Z4 |; x3 p$ ]1 ^: e1 {) i- N2 `
  16.                 call    A20_DISABLE
    + E4 u6 i, u$ b
  17.                 jz      exit1- `+ ^6 ?, `, W2 T: v6 x
  18.                 mov     dx, offset msg_ok 2 j  s( \7 T& @, E  K8 V# o% H: o

  19. 7 N+ r6 P/ w1 f  G# H4 {. Y
  20. exit1:          mov     ah, 09h 1 W) w+ l- Q4 f7 i  {2 j0 l
  21.                 int     21h   y$ v, `# G  p2 m7 e" C- t# d
  22.                 mov     ax, 4C00h 6 {* x  z3 [1 @$ e0 }& o/ w: P. c
  23.                 int     21h
    , e0 a% Q: x+ s. f  d/ u' S% I7 N  j
  24.                 & h- r' U2 m# Q: f) a
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,
    ( j, g$ }- @* }$ n, \0 q& R
  26.                         "2008-07-01",13, 10, "$" , C+ R5 k4 V: x# l: D4 d. h
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    3 Q) C: E$ G  k2 i) {& n
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    ' f2 l1 F: c6 k

  29. " l* |7 q1 L, S9 V) z) m
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------5 p" J4 ]8 _! A( y0 o% }$ ?/ }
  31. A20_DISABLE: ; ~. j  l- u! R9 v$ x, ]
  32.                 call    A20Write ( f0 |! n( X. M. {" k3 J
  33.                 jz      exit_disable
    & |" s# v) Z5 A) H4 w
  34. 7 M2 O3 k* g; {, i
  35.                 cli                             ; Only need for reading value from KBC 6 Z* m1 C$ a) m8 v  l
  36.                 mov     al, 0D0h 3 d! c8 G- z9 b$ y
  37.                 out     64h, al
    0 S5 a* _7 |! I4 h
  38.                 call    A20Read
    + s3 a; x' o7 W) H
  39.                 jz      Disable_int / V; D5 b3 x, i* [

  40. + R3 a8 y+ ]; N7 e& j, t% }
  41.                 in      al, 60h                 ; Get current status 8 R! u, x4 f( t. k9 y
  42.                 mov     ah, al
    ( g& K! y  B, N" t4 F9 V2 i. s/ I5 |
  43.                 call    A20Write $ b1 z& K% M" X. I
  44. Disable_int:    sti 6 t% P# w4 W1 T: r  m( l( [! {
  45.                 jz      exit_disable
    ! w: i* r  k6 |3 B( {
  46. & F8 D6 y7 `4 P3 p" @9 u
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    # @$ b7 ~0 U' t# A/ v& y* F
  48.                 out     64h, al                 ; Out Put Port next 1 i9 r! I  }+ g* W
  49.                 call    A20Write ; G. ?! K7 P. k  X7 x
  50.                 jz      exit_disable* j0 S/ S) a6 H: H! k

  51. 0 f' h. `$ |) I% `$ j4 D
  52.                 mov     al, ah
    4 |9 \5 s9 y4 R& f; N) `! N4 x. J
  53.                 and     al, not 2               ; Disable line A20 ) k5 H" |( C" P4 h* o" X
  54.                 out     60h, al * h- E. L3 W- V& j, `
  55.                 call    A20Write 8 q0 ~/ ]# @- z1 |8 q4 h
  56.                 jz      exit_disable
    8 ?- ~) Z/ h: o3 e9 ]: s

  57. 7 C. t, F+ ^1 a
  58.                 mov     al, 0FFh                ; NOP
      p1 V0 F  P- ?! G1 {. n" h+ g( X
  59.                 out     64h, al : _: L8 l/ {9 b$ U+ g) c1 h8 o
  60.                 call    A20Write
    % X2 l) q4 L, W0 T  u  Z

  61. # r8 C" S, L2 ?+ f* D
  62. exit_disable:          ret
    : c3 b7 B! G: i; k0 S
  63. * z+ R( w, ~8 |
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    8 g! T' ?1 u  u( z5 a. s
  65. get_wirte:      in      al, 64h                 ; Get KBC read status $ U  M: m* k3 _; I; }! t
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    # a: B$ |( R. [, i
  67.                 jz      clear
    $ M6 Q- k. `" n# Z5 O5 H: f+ S
  68.                 dec     cx
    , v3 I6 h; s7 l+ ~$ L$ ]
  69.                 jz      exit_write
    ! A9 ?0 V3 F) D! z7 y
  70.                 jmp     short get_wirte
    7 T8 S5 z: i8 x0 A
  71. clear:          inc     al                      ; Clear ZR
    3 l# @) R% a: l$ H7 }5 ^6 |
  72. exit_write:     ret
    ; e1 ~* ]) k( y1 M, d, j
  73. ' i% x( N4 ]* U# O
  74. 0 m, s1 S' m' k: Y
  75. A20Read:        xor     cx, cx & s7 m0 B# e( d3 ]/ ~& J
  76. get_read:       in      al, 64h
    5 i# ~7 P4 T: }; ]" T1 f# X
  77.                 test    al, 01                  ; If the 'output buffer' is full, has & K1 q- D* n$ }; w. O+ {
  78.                 jnz     exit4                   ; ... 8 Q4 @# Q( g, W. c; ]! C
  79.                 dec     cx 3 g% Z, M! n) P) a- l
  80.                 jnz     get_read" U$ K7 I5 F# I3 p& u
  81. exit4:          ret     
    5 J; v7 R5 A, K3 S. t/ ?3 |
  82.                 2 W% l4 M7 S0 q* ~! n
  83. end
复制代码
  1. ;A20STATE.ASM * K7 h4 B8 F1 Y$ b7 ^/ a
  2. ; 4 L8 [, r$ M8 P, x$ l
  3. ; Returns the status of the line A20 through the KBC 1 }( x% z8 N8 K/ b, U% T2 M* [1 C! N
  4. ;       programming by bini for debug. 2008-07-01
    - h. ]" }' M) M( T) }! z
  5. ;
    ' D+ ?1 s7 N2 x% Z
  6. .model tiny) I! [6 C2 f+ c# v+ e+ J3 v4 `
  7. .code
    8 [1 h+ l1 p( a" q1 c+ }
  8. .486
    9 Q  ?' F  b/ [5 N' i9 C
  9. .startup+ r" w7 `7 f# K+ `4 x
  10.                 mov     dx, offset msg_fail ' `( V# o8 ?6 \$ ?6 a* h3 T* @
  11.                 call    _GET_A20_STATE_
    7 c: \" J( h) x0 s. Q; |$ F
  12.                 jz      exit1                           ;  was a problem* o2 Z* S+ g9 P; ^/ u- ?8 G9 O
  13.                 push    ax                              ; Save state, AH , a* D3 B3 d- l! \% p; n$ p* H# w  x
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem / d, H, k* Z! b& U" c3 _" W5 y
  15.                 mov     ah, 09h
    : t+ i! v1 J; X  [+ X
  16.                 int     21h                             ; Print message $ j  W/ D' l  {0 o8 n
  17.                 pop     ax                              ; retreve state
    6 g: ]$ c7 ]3 M7 V% d/ I) b
  18. 8 j5 ?9 s) D1 d9 m/ h" P7 e
  19.                 mov     dx, offset msg_dis
    & F1 j& _( O; M- y# K& F/ m
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    + w  h1 j: E9 v8 Q7 A
  21.                 jz      exit1
    # t4 C6 }$ e5 j) t7 h5 }
  22.                 mov     dx, offset msg_en 1 m2 y1 `  S4 @" L6 j" L4 g+ u
  23. 4 h( }5 v+ _8 b! t/ o& t
  24. exit1:          mov     ah, 09h 3 N7 @& b3 I% U% [
  25.                 ; DX already contains address of string
    * z2 p: b: ]" R3 Y! x  y
  26.                 int     21h 4 C: M! |$ W8 c0 [- U! p
  27. 8 w& I; I( l! r4 ~. h7 g5 l1 @
  28.                 mov     ax, 4C00h
    $ e* x+ v6 ~" Y( P' T
  29.                 int     21h : f0 h8 O# g( Z" E  Y- z
  30. 5 r) ^: S! q5 ]) p7 ^$ E0 I4 j
  31. msg_ok         db      "OK", 13, 10, "A20 $" 8 `; Q$ V; y/ J7 j7 Z
  32. msg_fail       db      "FAIL", 13, 10, "$"
    1 ]) A! H# E7 {" l" F6 G, \
  33. msg_en         db      "ENABLED", 13, 10, "$"
    9 m9 }) H& `& n$ x- L8 \. Z; z0 l
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    + H2 F! d8 V+ e8 \
  35. # A$ g3 ^- A0 a0 }( Z  f; w4 J

  36. % o& r' h$ L; T; [$ y7 b
  37. _GET_A20_STATE_:
    5 n, D' |& j+ t& Y+ T. n
  38.                 call    A20Write                ; Wait till the input register is empty
    , ~( \3 Z/ ?3 y+ l( x4 \5 k8 I% q
  39.                 jz      exit2+1                 ; Bypas the reset int's
    + Z  p- u& k1 N8 _& |
  40.                 cli                             ; Disable ints so we'll get our value
      w0 U8 o7 p: k, ?

  41.   s5 o! s  r( K: U  e0 ~& D, c
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register . T# m/ }; U& }* f# b. W, d
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port ) W8 j+ }0 ]) \3 |4 K& `: t/ o- t
  44.                 call    A20Read                 ; Wait till the 8042 output register 5 H* |/ [6 A/ @% H4 }
  45.                 jz      exit2                   ; has something in it's buffer ! d' Q, C& h+ u$ X: d) W+ U

  46. 3 J, `" q( _0 G
  47.                 in      al, 60h                 ; Get it
    $ A# b3 `3 {9 Y+ D4 J- J. x
  48.                 mov     ah, al
    5 u) ]  S  {8 t% m+ l; z1 L
  49.                 call    A20Write                ; Make sure the input register is empty ! E) d& }, u  ]4 F
  50.                 jz      exit2 % A; F9 n& `2 X' A7 `' y7 X9 S

  51. : V8 b7 H& d! U1 ]* y1 s
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing $ _3 g1 z9 Q' X" p' H8 Z9 U+ d% T& e
  53.                 out     64h, al
    4 x+ v! m; |7 W
  54.                 call    A20Write
    $ k0 j3 `8 s; s0 J* v" S& j- r5 ~
  55. 2 X4 N" o9 Q( }6 v, M8 j
  56. exit2:          sti , s2 A0 Z# W+ I! ]  q
  57.                 ret5 T) Z9 q7 y5 \( k6 s( p* ]
  58. 3 v7 l4 U, U. J; C/ D
  59. $ y4 r& i. c: }2 i/ U* c
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    & @8 q. n' W- k; {. ^  |: K
  61. get1:           in      al, 64h                 ; Get KBC read status
      z8 p+ I* h& C+ d# o
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    : x% ?' b; q2 `3 _
  63.                 jz      clear & K% \, I5 T4 R
  64.                 dec     cx
    1 l8 _. J- c; m
  65.                 jz      exit3
    / I$ l' W" Y: q; B% ~
  66.                 jmp     SHORT get1 & I2 }; m% G4 J7 O; j
  67. clear:          inc     al                      ; Clear ZR ( V7 G6 j' R# W4 v7 c6 m
  68. exit3:          ret
    4 t/ k8 l( G5 o5 n5 v; J

  69. 0 J* R0 _1 x2 ~, S5 ], T% a9 [- x9 ]

  70. & o- ^( x9 t3 o! u* n) v5 A6 U, D
  71. A20Read:        xor     cx, cx
    9 J: @! {" }7 y; A9 ^$ V" F% R  C
  72. get2:           in      al, 64h * Q" O2 c9 [, r1 ~2 ^  v6 `
  73.                 test    al, 01                  ; If the 'output buffer' is full, has * _9 G% L7 y" }0 G! k, O- S; J* }
  74.                 jnz     exit4                   ; something for me $ W9 c3 }' `+ J  J2 e
  75.                 dec     cx
    / f, F- Y; z, c) g. D
  76.                 jnz     get2
    $ `+ i9 m5 C& D( o
  77. exit4:          ret     3 [, m4 J$ w! _& O* h
  78.                
    9 v3 ~7 B9 g/ w1 z1 u( Z9 r  }
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
  f$ l( O0 A+ @4 U% _{        while(inp(0x64) & 2);        outp(0x64,0xd1);( {" ~3 ^$ r+ c. @* r# R" H
        while(inp(0x64) & 2);        outp(0x60,0xdf);
7 Y% |1 I3 s+ Y9 e4 Z( d' z, L        while(inp(0x64) & 2);        outp(0x64,0xff);" X; ^  w5 q9 A) ^7 N
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 19:00 , Processed in 0.026563 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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