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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    9 E1 V! S# d3 p( V0 D
  2. ; 0 }! V$ ?- E/ j$ {9 _2 k
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01
    4 ~* q0 M  ]7 J- ^) o
  4. ;       ml A20ON.asm
    0 v+ @  i' R/ ^' I! g5 B* L0 X
  5. ;
    + k: |" q5 ?7 L; w& c
  6. .model tiny+ m" ~# J) ^. A4 i
  7. .code6 n# {7 U; D% ^
  8. .486% G  P: ^! E' l! Y8 Z1 w7 `* @6 y5 d' u
  9. .startup
    9 l; O& @/ _% \; Q3 |, {. P6 w) x
  10. - r# ?! T: @2 r! v4 @
  11.                 mov     dx, offset msg_author
    / Y% G1 e1 G3 {2 ?/ s8 K
  12.                 mov     ah, 09h
    0 T" G, k: W, ?$ [
  13.                 int     21h
    % m  R# a$ x3 @. F3 Y0 z

  14.   M1 n# D) i% y" {% S5 D. ]
  15.                 mov     dx, offset msg_fail
    / H" s6 C* v3 F0 u5 A# n* F: e5 \) O
  16.                 call    A20_ENABLE
    . A3 ^- q; c; L/ u( T0 N3 I
  17.                 jz      exit11 h1 G. S( O& w+ e1 _
  18.                 mov     dx, offset msg_ok
    $ ?. [% q2 @( {# D
  19. / t" o" T6 ?# ~8 N8 Q1 g0 ^# @
  20. exit1:          mov     ah, 09h # ^9 f  q: i# s8 X! F
  21.                 int     21h 4 `1 f7 M2 h' [0 p: w$ P
  22.                 mov     ax, 4C00h
    4 T6 i3 Y! H/ F% {$ ]( z) m" c
  23.                 int     21h # C; D6 g- D) b; t
  24.                
    - L$ ?! [+ T+ z: Z4 _
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,% ]$ E+ T- }$ n. o# v6 E2 J* d) B# r
  26.                         "2008-07-01",13, 10, "$"
    ' G$ w8 f3 V; W; N7 [% L
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
      W: Z, D/ u% o8 n9 K; }: ]6 T0 r
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    4 W% _  _0 ~0 ?! s

  29. 9 R' r9 A/ [! ?& S( m* O( [, ?: h
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    ) d, o1 q5 A" y4 ]: u$ V
  31. A20_ENABLE:
    " p8 s, o+ z% D( V4 F/ w
  32.                 call    A20Write % E9 |! I3 Y5 T* O
  33.                 jz      exit_enable
    & y9 s! s1 Y9 Y# o/ m2 ^
  34. 0 M8 Q5 K0 j4 F$ {% G3 |: M$ _# B
  35.                 cli                             ; Only need for reading value from KBC   c# ^7 Y% {+ Q. S7 K0 G
  36.                 mov     al, 0D0h
    6 _: w( `7 [/ P1 C4 l
  37.                 out     64h, al
    - o3 |. j& ^. t8 N2 j
  38.                 call    A20Read
    : X) g3 m$ |: N+ c, e) G/ }
  39.                 jz      enable_int , ?& @% c* _; q+ R4 Q

  40. 5 o/ s- w6 V1 Y5 K
  41.                 in      al, 60h                 ; Get current status   ]/ U( X6 F1 D
  42.                 mov     ah, al
    ( v, ~2 i! Y$ F7 Y+ L, w
  43.                 call    A20Write ' F3 z: W8 F) K2 j/ D1 m5 L
  44. enable_int:    sti
    , \9 [& S$ f4 M2 I3 A7 c0 t. V
  45.                 jz      exit_enable7 x1 E$ o8 p7 n; \( d2 i

  46. 8 j+ _- t1 d1 [
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the " e) {, ]2 X. ?5 q5 c
  48.                 out     64h, al                 ; Out Put Port next
    & e# v9 ~+ j* O" u. F
  49.                 call    A20Write
    ' h" e' c$ T8 z( M1 {) ~& B8 `
  50.                 jz      exit_enable
    ; Z( u* T. i$ p( s6 E' l& \$ v
  51. . T! _4 v" Q( J; q8 n/ M
  52.                 mov     al, ah 3 [8 e  @& E: x$ D  j
  53.                 or      al, 2                   ; Enable line A20
    6 T: P5 c6 M! c0 @6 |* E& L# \
  54.                 out     60h, al
    , b9 w& {6 N9 t, J! [1 Q
  55.                 call    A20Write : A* {/ N0 s# o" h- c
  56.                 jz      exit_enable
    * A4 h4 X; x7 j% c6 u  j" ^: ?

  57. + L4 b: R" t0 a+ [$ }7 Y  W3 n
  58.                 mov     al, 0FFh                ; NOP - |# H1 Z+ |% D' K  c/ p
  59.                 out     64h, al
    + V8 L+ ?* U9 q% O' q& F
  60.                 call    A20Write % \$ ?( J* G  F: l, w
  61. 7 v( f7 m5 J5 P4 \+ I
  62. exit_enable:          ret
    5 d6 d& J. f" `$ g2 }$ W
  63. 9 R  H3 C1 i/ h2 [+ Y
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    ) M  k: y& v! e- w0 K/ }
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 6 ?$ z; ?$ |7 [1 D0 X
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    . [2 B) C  m; J* D
  67.                 jz      clear
    / l; K0 v7 L  }4 f1 Q8 p, z2 K% K
  68.                 dec     cx - H1 Z2 w. S4 J
  69.                 jz      exit_write
    4 U& P; x- E: y2 Z4 g: A0 t1 \. m
  70.                 jmp     short get_wirte 7 V. A: i3 m2 f0 h" z+ p
  71. clear:          inc     al                      ; Clear ZR
    : C) O* L* K5 t
  72. exit_write:     ret
    ! T' |/ f. m; g' F  f' o

  73. * c6 ^* w. N9 Y/ U0 g- ]

  74.   g8 O" A; `& }
  75. A20Read:        xor     cx, cx
    # U7 U6 L# I/ s  ?3 U
  76. get_read:       in      al, 64h " v1 O6 r! c7 v6 T0 _) D# D, }
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    ' O: i& Z# F: E$ o
  78.                 jnz     exit4                   ; ... ! h7 x- Z0 _9 i0 q# {# ?
  79.                 dec     cx & I2 N$ G+ ?3 D: O# n7 n! Q
  80.                 jnz     get_read5 o7 ?$ J7 h4 h7 m" ?5 w3 T$ A; ]
  81. exit4:          ret     ! X; [$ @, o: q5 Q$ X6 P; ?8 `5 u
  82.                 " t8 o. _' u$ K3 R* n
  83. end
复制代码
  1. ;A200FF.ASM
      s) D5 a5 f5 q
  2. ; ; E9 O2 q1 J% [: [3 B8 P0 J& s
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-018 w- T2 Q+ M( X
  4. ;       ml A20ON.asm , Q7 X, a1 A! D) s- f9 d$ u( T
  5. ;
    9 \5 P/ B8 @4 s- ^! u: _# |
  6. .model tiny! Y' \# L. r, G% J) |7 `
  7. .code
      D  @1 y) ^4 v
  8. .4865 P, z6 k/ W7 T7 e
  9. .startup0 ^; a2 k) z  x* ?
  10. ! ?) a  F8 X9 F8 R1 n  `6 v, D2 ^% y
  11.                 mov     dx, offset msg_author
    2 x4 h0 j4 ]# v  \; ]1 L7 @4 I
  12.                 mov     ah, 09h' }- x3 t7 e9 M$ y
  13.                 int     21h- h3 Z8 ^* ~- S* d. M
  14. % |6 {) Z/ L, g2 X
  15.                 mov     dx, offset msg_fail
    ; f# F0 h: }! a1 k( g  y& S
  16.                 call    A20_DISABLE
    / G3 ?5 C2 ~3 f5 }2 e6 J
  17.                 jz      exit1& Y9 H0 e3 M! A: @
  18.                 mov     dx, offset msg_ok
    6 E( a5 D( P- P+ L3 y/ R! k
  19. $ Z4 H' Y5 |. I, N6 n
  20. exit1:          mov     ah, 09h
    ) b/ R8 m& f' G0 M$ w. X7 ^# o
  21.                 int     21h
    4 c1 H9 c- x) @- b* e5 h1 V
  22.                 mov     ax, 4C00h
    # {+ E) g4 F7 p" I
  23.                 int     21h
    6 C" Z$ h) ^( V, s
  24.                 * Q4 r2 A  P8 [0 U# N
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,  m2 S. Y4 @( ^' G
  26.                         "2008-07-01",13, 10, "$" , g5 `& E3 u+ j- K
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    $ R! f  d# ~9 k! T
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    4 ^: w5 ?% |5 ]* k; {/ R- d
  29. 1 z' P2 n; s9 F7 R
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------  }$ @' ~/ w" S! E7 C; z  \1 ^
  31. A20_DISABLE:
    # B6 l7 {4 H$ Q& Z9 M
  32.                 call    A20Write
    0 }9 |$ o( q3 _- \0 h- q" r
  33.                 jz      exit_disable
    4 p# q' F6 \9 W+ T" d2 E. L
  34. - X% g$ k  n: @! o
  35.                 cli                             ; Only need for reading value from KBC 4 I% V9 u/ I; k  J
  36.                 mov     al, 0D0h
    2 ?5 ?3 W5 I0 Z! i) W* M5 z4 z
  37.                 out     64h, al 5 b# l$ a4 G0 o) h% _0 y0 w' |
  38.                 call    A20Read " o0 D- h, p7 g+ p  e
  39.                 jz      Disable_int
    4 z" P" `3 U% \8 x; u! G
  40. ; N5 s! i6 O* W4 |! V' {& y
  41.                 in      al, 60h                 ; Get current status
    & X6 s; f9 U- {+ O8 ]8 T% R
  42.                 mov     ah, al
    5 h5 S8 |) L' F  z
  43.                 call    A20Write
    2 D6 C9 F$ z* g2 H9 Q8 `; v
  44. Disable_int:    sti
    $ f3 K9 d2 w5 g
  45.                 jz      exit_disable
    ; E" G& D8 I5 O8 W  K$ j

  46. 5 O# e' f8 H+ K% w+ {
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    % K! d" U6 i; S" {0 @
  48.                 out     64h, al                 ; Out Put Port next
    4 N  F. Z- F0 R6 K- O
  49.                 call    A20Write / j9 r; |/ \, ~' K
  50.                 jz      exit_disable2 v6 N. K1 B/ R* \7 U' o
  51. / H$ ?2 t; N0 e( c1 `; o% \3 e
  52.                 mov     al, ah 1 J6 e) v( p0 }; i. D6 `5 f
  53.                 and     al, not 2               ; Disable line A20 3 k+ Y6 y( z$ z8 d
  54.                 out     60h, al
    , h9 S8 f/ x! S. ?# z6 R# d0 x
  55.                 call    A20Write
      Y) g) r' S% e8 }! g. K
  56.                 jz      exit_disable
    + G1 E+ g3 x9 G; e
  57. # Z9 C0 [1 G0 K" N8 M
  58.                 mov     al, 0FFh                ; NOP   x* v1 t; F9 A
  59.                 out     64h, al / V4 n$ ]' _0 j/ E& H$ g% {
  60.                 call    A20Write 8 [) q/ Z' n- {# M$ F9 h! ]/ v
  61. - g. I8 j1 K7 |% \
  62. exit_disable:          ret " R. j* w, ^; E) U. S" E1 E
  63. ; I' R* c' e1 d6 S. Q
  64. A20Write:       xor     cx, cx                  ; Reasonable wait & t" n) k/ ?3 x5 e) s
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    ! @6 J2 `" S+ {4 F5 I- W* u
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear + M! [( l4 A1 S* Q
  67.                 jz      clear
    3 c9 U# Z" t' x; X$ h+ }
  68.                 dec     cx 9 Y: A8 W. I! i$ l
  69.                 jz      exit_write ( |0 X- Y* ~9 J) }4 b4 p4 Y% _
  70.                 jmp     short get_wirte
    ( I0 c- @4 G6 J  Z! m: B* J1 F
  71. clear:          inc     al                      ; Clear ZR & C: U2 f( N3 m' x: @1 S
  72. exit_write:     ret
    3 d" u, J# c# p8 }
  73. ' x9 W, l# T' z* t& o* c  K% t
  74. ( a3 X8 f3 U) a8 i1 h4 |' T
  75. A20Read:        xor     cx, cx ( O9 H$ [6 P9 V1 o6 I4 g
  76. get_read:       in      al, 64h ' [- w; b5 Q2 s' k  z2 m) @! P
  77.                 test    al, 01                  ; If the 'output buffer' is full, has 1 l; X1 [9 Z8 l/ Y+ y6 c4 G
  78.                 jnz     exit4                   ; ...
    , J! o0 d' Q$ V/ ~( \2 S3 u
  79.                 dec     cx " _# Y# Y7 Y' K/ D+ P
  80.                 jnz     get_read+ B% p( Z4 I: T9 z* O
  81. exit4:          ret     * T  ^" C* ]/ O% x: l" {$ y
  82.                
    * H3 a+ F( K$ V% O% a( V
  83. end
复制代码
  1. ;A20STATE.ASM 0 |% [5 M* Y6 r& ^" `* {  ^- {" @
  2. ; ( @) u+ l: |  I
  3. ; Returns the status of the line A20 through the KBC
    ( D' O' S) J5 l6 M0 r7 D
  4. ;       programming by bini for debug. 2008-07-01
    9 O# u  f9 G6 P- @+ P  B9 F
  5. ;
    5 S% ]$ U; S% b4 w4 {
  6. .model tiny! ~! N5 t9 B  C3 F5 P/ L
  7. .code
    + |, Y8 ~( m, z0 h: V
  8. .486
    ( g6 o! v3 X$ @
  9. .startup: m/ ~6 J6 T( X
  10.                 mov     dx, offset msg_fail
    ! [* R' K( Y: N3 Y" S" n: p2 z
  11.                 call    _GET_A20_STATE_
    ! a( T/ l& O. c/ \3 i9 Y
  12.                 jz      exit1                           ;  was a problem# [# t! i8 @" j$ U  @" d
  13.                 push    ax                              ; Save state, AH
    ( P7 P0 W* E! b- A
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem 4 S4 Z' @  Q  X  k% _. e1 `
  15.                 mov     ah, 09h
    0 @6 a4 o' O- Z; h! W( o9 _
  16.                 int     21h                             ; Print message
    2 f- T* s' w: Q$ {- q" a+ ?/ v2 Z1 g
  17.                 pop     ax                              ; retreve state ' |1 `" q$ w+ q  F: S2 l( o
  18. 2 _0 O3 P8 b6 U2 B8 {# O
  19.                 mov     dx, offset msg_dis
    : l8 G4 ?) @5 I
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state $ W* m- ?5 d3 }( c/ Q3 q& I
  21.                 jz      exit1
    9 O2 n" g1 c% F) F
  22.                 mov     dx, offset msg_en 4 p. p" Z0 e; h

  23.   f3 V0 D3 R5 ]' x% I
  24. exit1:          mov     ah, 09h
    . Q, A$ g+ c( s+ l
  25.                 ; DX already contains address of string
    $ ~% F5 T/ F' M4 x% T+ z
  26.                 int     21h
    ! [, Y- R1 D) [
  27. 3 |5 g( K) u- {& b2 `$ c
  28.                 mov     ax, 4C00h 0 [. E2 r: i8 b& C5 t
  29.                 int     21h ! h+ K) Y8 X! v. ~6 Y
  30. % S1 m$ T; @3 D, g
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ; Z# c$ J' w( N: a0 l
  32. msg_fail       db      "FAIL", 13, 10, "$"
    / X, D' N$ g( U, ?- _9 _4 e
  33. msg_en         db      "ENABLED", 13, 10, "$"
    ( _- l* a+ I, A, B, e& U5 r# Q
  34. msg_dis        db      "DISABLED", 13, 10, "$"
    0 |8 C& ^  _2 i1 T5 W0 O0 _& d
  35. * o0 i) [; |4 |  a. T  O

  36. $ u4 V: d+ s" D2 F  Y8 N. J
  37. _GET_A20_STATE_: , C( f% l0 `. d  B3 ~
  38.                 call    A20Write                ; Wait till the input register is empty 1 H8 L; \9 c" n. p) W, a
  39.                 jz      exit2+1                 ; Bypas the reset int's
    + D1 n" l9 {+ {1 [/ I% e
  40.                 cli                             ; Disable ints so we'll get our value
    ) S. ~% r* ?- x  ?

  41. 5 y; D1 F2 K. d0 E% d& m: O
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register . D) t" K! X( |* ?8 I9 v9 ~2 F
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    , P3 {6 |" U4 w7 w5 |6 c9 Z. h
  44.                 call    A20Read                 ; Wait till the 8042 output register   K" d% K& |  i. j
  45.                 jz      exit2                   ; has something in it's buffer
    $ i1 z% J- B7 ~7 ~5 I, _7 ~! t, k
  46. ) Z4 K, S( G! x4 N8 _( V4 e, _5 v( R
  47.                 in      al, 60h                 ; Get it
    ! h  N! l: g1 z. i
  48.                 mov     ah, al
    # ]* Z7 P2 a. q$ }
  49.                 call    A20Write                ; Make sure the input register is empty 3 Q, g% k0 W+ L7 h# Q! c6 P
  50.                 jz      exit2 $ a, _' i' V$ ~' Z2 S$ B& k

  51. ) _, [, S: t$ P) f% Y7 H$ u8 m
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    : P5 j9 `* b, F/ K2 u
  53.                 out     64h, al
    3 f' y/ @* t, u# H* Y; z1 s4 Y) ~
  54.                 call    A20Write 0 O" e# s9 _7 l1 g* ?( \

  55. & y! Z9 f+ ?7 _+ l, j
  56. exit2:          sti
    ' a6 W* h( f8 V) @  o  A+ R
  57.                 ret
    2 {: E$ g& t" n
  58. 3 _; A7 G  {: E) k
  59. & h) O) v) x( V: K. Y$ t; k0 \
  60. A20Write:       xor     cx, cx                  ; Reasonable wait ; R* Q7 r7 y( P1 S9 k  o
  61. get1:           in      al, 64h                 ; Get KBC read status
    3 y5 }; X7 W- k" |
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear . @4 K5 {6 @: }2 g% H
  63.                 jz      clear
    % ~, l% r+ C  _  O4 F4 ?6 M2 N- c+ J
  64.                 dec     cx , g3 @* L9 Y+ u7 k, T
  65.                 jz      exit3 / T7 r' N; _# o6 |/ x7 X
  66.                 jmp     SHORT get1
    ' B6 W: }0 \( Q8 M9 y: a
  67. clear:          inc     al                      ; Clear ZR
    1 A( H1 @& f% g* [7 d
  68. exit3:          ret " @1 X5 i' y! n1 u8 V

  69. + P/ h5 F; [5 L# K7 M
  70. 3 t7 q* x0 J- u5 \2 R) [3 `
  71. A20Read:        xor     cx, cx ; Q1 K+ r5 g3 V1 j
  72. get2:           in      al, 64h
    - K/ h/ u4 s7 y4 O" o$ w6 y
  73.                 test    al, 01                  ; If the 'output buffer' is full, has
    * B" O( n2 g! v
  74.                 jnz     exit4                   ; something for me 3 g# _/ k0 N* B- d
  75.                 dec     cx
    0 i2 J( u' h3 x/ _3 f& u9 ^4 ^$ a  p
  76.                 jnz     get2
    ! p4 C8 ~. m: X% \1 G3 ?/ P  |
  77. exit4:          ret     ( T5 Q* J& b, d+ Z  U
  78.                 & o, W" o$ _% o4 ]1 k# [
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()( b- Q9 Y* m' |  W
{        while(inp(0x64) & 2);        outp(0x64,0xd1);: i. c! A% f2 J4 `" {& }1 h0 D6 U
        while(inp(0x64) & 2);        outp(0x60,0xdf);6 Y7 a8 G; M/ z
        while(inp(0x64) & 2);        outp(0x64,0xff);* {3 o4 b$ Q& x! M6 K7 }9 |
}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-19 21:01 , Processed in 0.080017 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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