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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM
    5 f% F, I) }" B" b  C& t
  2. ;
    + p1 y2 Q  |0 @8 `, A* m
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-01, t, a+ v: B8 C8 h4 r3 `3 @4 T
  4. ;       ml A20ON.asm - b" @/ d  M; f/ I* M
  5. ; 8 w& E. r- B% v/ e+ O
  6. .model tiny0 J( u2 u3 }3 G+ x- Y1 W
  7. .code. P- c4 A. {+ l3 w) s8 e
  8. .486! x/ U. E' C8 `& M
  9. .startup
    % x& q. b8 U, C4 V6 _; p
  10. 7 _7 l; u( T, S1 I& D  {
  11.                 mov     dx, offset msg_author: g# k! K1 C# v9 E
  12.                 mov     ah, 09h
    $ I* m: p0 }1 g; K
  13.                 int     21h, p* K$ Y# i6 v3 l3 k( P
  14. . B) D5 o! |0 z! y5 l( b
  15.                 mov     dx, offset msg_fail
    " G' G  F2 P# C0 e0 v
  16.                 call    A20_ENABLE4 r+ u* U3 W2 ^: ?: H' }
  17.                 jz      exit1
    ; ~2 E- Y  w3 w* K* G2 u# f2 X9 z
  18.                 mov     dx, offset msg_ok 3 ?1 Q& T$ b, U

  19. ! z4 J. H2 _9 \4 m% B
  20. exit1:          mov     ah, 09h
    7 y# W  L8 i0 k! d5 h
  21.                 int     21h / Z2 g6 I4 G- Y  a+ p
  22.                 mov     ax, 4C00h
    ! ?+ R/ {2 E* a, ?
  23.                 int     21h * I; Z' o3 b+ Z& T3 G# q) X
  24.                
    0 z; K8 O, C9 {+ N" D
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,# n$ b+ ?: m+ }
  26.                         "2008-07-01",13, 10, "$" 8 x: p& P, N# d5 \1 G4 U
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    # s8 m- T- h% k7 H+ C7 B' j
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$" # V  h& u, D9 E7 N3 Y' T

  29. 4 e) ?; @! ~) |0 g; ^% c
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
    , A( n2 a0 M: W+ W4 W# f/ A
  31. A20_ENABLE:
    + F; u( P2 B  }$ }2 k. ?+ M: h
  32.                 call    A20Write . ?) X3 g/ Z0 y9 S$ C' D/ s/ i
  33.                 jz      exit_enable
    2 D8 t- l) g4 o/ K
  34. : \0 Q$ M. r$ K4 ^. }* @
  35.                 cli                             ; Only need for reading value from KBC
    2 z. t. d( s6 i
  36.                 mov     al, 0D0h
    1 ]% V( J& {/ F" F
  37.                 out     64h, al   Q1 N6 t/ b+ d
  38.                 call    A20Read
    7 R" y/ c* |; q' V" P$ Y# M
  39.                 jz      enable_int ! O- m# N' o* `" u7 e4 Z" j$ }8 B
  40. $ D! Q! h1 ?# H! n' C& k
  41.                 in      al, 60h                 ; Get current status , ~% t1 l8 _: w
  42.                 mov     ah, al * V& X& Y& I  m6 N: `
  43.                 call    A20Write / c3 `$ G2 P( z/ V+ ?
  44. enable_int:    sti ; G% p" \6 `2 V( N( p( S/ W8 A/ E
  45.                 jz      exit_enable
    ' W$ Q/ H% h" C1 g- w5 x2 F& F
  46. ( h# l" t" K. i/ {1 E
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the . `7 m3 `: [, ^/ w% p
  48.                 out     64h, al                 ; Out Put Port next
    ; q' w( `& d8 c* Y4 ?4 O2 e
  49.                 call    A20Write
    % f5 P" D5 k: n8 A8 N* s( v4 W  v
  50.                 jz      exit_enable6 ]# S2 Y9 n' Z  q( T" [) l  I3 X
  51. * h8 J/ v# X9 z* Y4 a
  52.                 mov     al, ah ) i  f, d& ^) S7 {* s
  53.                 or      al, 2                   ; Enable line A20
    & M9 g  E$ W. H5 n
  54.                 out     60h, al & u) \& g9 J$ e! |  H% a0 O7 |+ o
  55.                 call    A20Write 7 f- T- S* B7 r1 W
  56.                 jz      exit_enable' d& v. ?& O: I* w

  57. ' D, k- D2 R% @% A2 o, t3 U) o1 F/ p0 y: f
  58.                 mov     al, 0FFh                ; NOP 3 J2 j, e2 p5 W& [& \. I
  59.                 out     64h, al # n% X% Q6 b# h/ o
  60.                 call    A20Write ; y6 a4 @; M4 @0 A
  61. 7 L0 O$ ^$ l2 F# ]
  62. exit_enable:          ret ( K: ~2 Q6 k  Z/ z% a
  63. 5 M$ H+ [& n' Y: w' n3 n, T
  64. A20Write:       xor     cx, cx                  ; Reasonable wait : t1 I' r0 w3 F$ V  P8 X
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    % x, ^* k# Z- |( R, u3 D
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear 6 \9 ?7 F2 g: w5 n5 C) s, V/ l$ W
  67.                 jz      clear / z% S' C, t+ I6 A5 q' k, H
  68.                 dec     cx * _; i- v: e( n0 {
  69.                 jz      exit_write
    . J' I: m5 M. l, y4 z/ N" B2 K
  70.                 jmp     short get_wirte : G% E7 u' i# M2 V1 r
  71. clear:          inc     al                      ; Clear ZR
    7 W9 j& w3 Y  i$ ~* k, G* l) ^
  72. exit_write:     ret # p# _8 D8 q& I/ y

  73. " t4 ?+ v" E8 S/ B) L4 z4 T
  74. ' i1 X0 @+ M0 A& B$ ?1 ]$ A
  75. A20Read:        xor     cx, cx
    7 N  h$ v' a* B, _1 A
  76. get_read:       in      al, 64h . ^" m+ R' w) E) J1 G" E
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    6 a# T/ e) _$ A; G0 u& S  H
  78.                 jnz     exit4                   ; ...
    9 ~6 W2 B: F$ a  d$ Q, n7 ^: ?
  79.                 dec     cx
    # x- H: h9 A) S$ R
  80.                 jnz     get_read1 T, S+ o8 g8 K7 P: k$ P
  81. exit4:          ret     5 g1 L/ z; q8 @9 X: h
  82.                 + P  p: \- {/ j9 y8 A5 {
  83. end
复制代码
  1. ;A200FF.ASM # a' Y: T# o2 c
  2. ; 3 W/ I; d) Y" t1 U
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01# h( c* N/ ~( w. l7 O4 g2 P& N
  4. ;       ml A20ON.asm   S& o3 j; H' ^' u9 c9 k- _9 E
  5. ; * ^5 w7 s4 h- Y; q! W
  6. .model tiny; g" W! {6 P5 k
  7. .code
    1 u& i, e- u8 ~, P3 }  }
  8. .486
    ) }( x$ P# S% K
  9. .startup/ o0 {) n% }/ Y- ]. |

  10. ( [! {, M4 }2 t7 ?" x5 K0 [0 T4 u- |
  11.                 mov     dx, offset msg_author
    & b- B, l" u: r: G5 n
  12.                 mov     ah, 09h; O/ c+ y  B( G3 x2 |2 U0 ?5 b
  13.                 int     21h
    $ M) z* u  {1 l% m& l
  14.   F, F* a& `$ S
  15.                 mov     dx, offset msg_fail . `  o2 J' X5 y7 P6 w  [3 @' Y( {
  16.                 call    A20_DISABLE4 {1 v1 i1 _3 k' l" d' z3 G. ?. L5 N
  17.                 jz      exit14 z3 _" H8 F, ?1 F$ K* n$ Y2 z$ D6 x2 d
  18.                 mov     dx, offset msg_ok ! Q1 m/ `0 M: c, z* a- L$ s7 s' M
  19. * y( T3 s6 W: P- f0 E1 d
  20. exit1:          mov     ah, 09h
    % q5 Y; u3 z# o- Y- D8 `4 ?" W
  21.                 int     21h 6 c/ K6 ~9 c7 g: ~
  22.                 mov     ax, 4C00h
    9 x' K9 r7 K8 j/ p' I! e
  23.                 int     21h ( Q9 h- ^+ ]! [6 V8 e
  24.                
    . P% A; ]6 i2 b5 S
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,% m! u4 i  c6 S% T, D% N" A  o5 X
  26.                         "2008-07-01",13, 10, "$"
    4 ^. }( |4 U' ]; k9 M
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$"
    7 A" ^' c0 J7 n4 V
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$"
    9 @' M" Q9 ?8 m6 Y
  29. ( _" c& n3 u* `, E: j5 e& n$ s1 _" G
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------" Q& S8 D4 v, P9 d: O" S
  31. A20_DISABLE:
    7 Z9 k9 V* W6 v2 i
  32.                 call    A20Write
    # V6 O! M% Z) v! o$ q
  33.                 jz      exit_disable0 I0 h% Q0 F, g# i3 `' ^
  34. & o, [( U% u0 B8 {, ~
  35.                 cli                             ; Only need for reading value from KBC
    8 @, O+ x& w. P! @& Z& V4 l  w# O
  36.                 mov     al, 0D0h
    3 z* ?* m/ S8 O; K
  37.                 out     64h, al
    ' T, T3 Y/ W8 W# B/ O  \3 Y
  38.                 call    A20Read
    4 a1 [6 j6 \: o5 I& }$ H
  39.                 jz      Disable_int
    : p/ x' A9 J9 ]3 p) W

  40. 1 L& ~0 u; V) @
  41.                 in      al, 60h                 ; Get current status 3 z# r: C5 g+ E: l9 l3 ~0 y% X
  42.                 mov     ah, al % O5 f& u9 f2 R. u# c
  43.                 call    A20Write
    / A! |- P  F! D9 G  V
  44. Disable_int:    sti   m( m, ^4 n" d+ E1 H$ [: v* T
  45.                 jz      exit_disable
    + ^: p3 Z+ N8 N! B

  46. 6 X; ?8 ^$ j# [9 o0 Y
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the
    / i) B* i, u! i" ^2 u/ r. v) G4 ~
  48.                 out     64h, al                 ; Out Put Port next   J8 ]/ X5 }* Y: {9 P
  49.                 call    A20Write
    7 O  b* R9 ~9 }$ ~: ?
  50.                 jz      exit_disable- Y8 [9 k; k& E0 f: d
  51. 4 |, [6 ?7 B! W
  52.                 mov     al, ah
    % I0 t* f6 j# Y% b. {7 X6 z8 H
  53.                 and     al, not 2               ; Disable line A20 0 O" c' K% h" x. X+ @
  54.                 out     60h, al
    # C0 A. f& F. g; Q  G
  55.                 call    A20Write . v7 p. ?, z8 b" `
  56.                 jz      exit_disable
    : s7 w4 m9 O2 {
  57. " e; }  j3 ~/ ^9 ^! `, [9 H7 A7 n% L
  58.                 mov     al, 0FFh                ; NOP , D: l5 Y& {- x6 d2 u4 J
  59.                 out     64h, al & _6 J5 v# G$ T, e8 h7 n
  60.                 call    A20Write
    * D- S! F4 }6 ?, }

  61. ' e) s# c1 s* @5 N6 I% N
  62. exit_disable:          ret % j5 q; V% l$ a% R) D5 h6 e; P
  63. 5 W+ _+ O% i) ]  |
  64. A20Write:       xor     cx, cx                  ; Reasonable wait ' s! I0 D0 m2 ~( `2 w) p/ C; ]
  65. get_wirte:      in      al, 64h                 ; Get KBC read status ' R5 r& H1 N/ c; W7 X% s( Q* R
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    , ^# D! A7 h0 o8 e1 q
  67.                 jz      clear ( C) V" }% O  ]/ u4 I, ^
  68.                 dec     cx
    5 @+ r$ T; Z$ P4 T5 o. c  L
  69.                 jz      exit_write + M6 i8 @" }* T( p8 X
  70.                 jmp     short get_wirte
    7 H# u) b; B( S& ?& I/ p) v$ L" M
  71. clear:          inc     al                      ; Clear ZR
    7 J, \% v( I  ^  F$ c
  72. exit_write:     ret
    * _* {+ M0 W8 S
  73. 1 ]: K0 B% R. C& s
  74. # l9 h0 p, N! Z' g+ c2 Q
  75. A20Read:        xor     cx, cx
    8 h) \2 N" c  n& a* f; ~: e
  76. get_read:       in      al, 64h
    ' V1 p9 @4 s6 c' T' @
  77.                 test    al, 01                  ; If the 'output buffer' is full, has + M" Y# k+ d! }: V1 e
  78.                 jnz     exit4                   ; ...
    ) u# b5 X3 s4 @* f& S4 y: g( l1 U4 _
  79.                 dec     cx
    ' `6 N, `& Q/ r- |! s" w
  80.                 jnz     get_read6 j5 R8 Q+ u  j1 g' F! t3 W; y8 {
  81. exit4:          ret     
    : @" Y% M5 l7 ?) X+ s
  82.                 - F: H# ^5 z3 x+ Y
  83. end
复制代码
  1. ;A20STATE.ASM
    " h8 a: l+ v6 E+ U7 S+ c( T) f' Z
  2. ; " V5 S% V1 G* D3 _) a0 N, Z
  3. ; Returns the status of the line A20 through the KBC " F$ w( {% i! ^4 @( `2 |
  4. ;       programming by bini for debug. 2008-07-01; n8 k8 H! ~3 o9 u( R7 ~9 @$ o
  5. ; & n0 d; ]8 |9 n7 g& D0 Y$ @2 B0 t
  6. .model tiny, X$ X$ a- E; K3 F. {- |
  7. .code9 s! e1 M: {1 Y
  8. .486& q5 ?4 N% f6 s1 r4 g7 j: R
  9. .startup5 ]+ Z- K$ j! G, l) s& I, K
  10.                 mov     dx, offset msg_fail
    ' z. X- N# X1 Q5 m$ y
  11.                 call    _GET_A20_STATE_) `( b4 o/ B2 x+ y- i: ^4 ~  `6 ^0 w5 c
  12.                 jz      exit1                           ;  was a problem% K/ }5 s' L* X* v
  13.                 push    ax                              ; Save state, AH 0 }! y/ W1 q0 C( ?1 g0 V
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem # g1 C$ Q( c7 m
  15.                 mov     ah, 09h ; y( A! F5 @' h- a+ J. \! F
  16.                 int     21h                             ; Print message
    ) Q/ m3 Y. U* X4 R* E9 \
  17.                 pop     ax                              ; retreve state
    0 }: }0 q0 {, g- n

  18. - I: \: B% Y- L
  19.                 mov     dx, offset msg_dis 8 {/ Q* X: o7 x
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state
    : X* h. Q' E3 T* m3 |% W0 h+ Q
  21.                 jz      exit1
    ( `+ {; z$ L3 y1 E7 W/ g
  22.                 mov     dx, offset msg_en & M. m% t7 s7 @. W3 h
  23. 0 o9 \4 Y5 Q) g$ R# c
  24. exit1:          mov     ah, 09h . o/ n* _$ i/ g  j
  25.                 ; DX already contains address of string
    * s1 ~' E0 T5 I7 ^6 H$ q& @
  26.                 int     21h % q) `- ^. {# @$ n3 j
  27. % X" o. u! l9 Q' h7 `
  28.                 mov     ax, 4C00h
    6 T0 Q9 h4 c7 d$ W3 C- X
  29.                 int     21h 0 ]/ m/ Y# y5 r& L! p% }

  30. . U" x( W4 w* ^3 Y' B9 r/ O2 I
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    ! L8 m' d/ Q3 }  t* {3 O7 L1 T
  32. msg_fail       db      "FAIL", 13, 10, "$" - m; }% E- n' S6 |0 W, u: C9 X, M
  33. msg_en         db      "ENABLED", 13, 10, "$" ; o5 X. ]2 |1 K7 S
  34. msg_dis        db      "DISABLED", 13, 10, "$"8 w# {  g. Y2 _1 R4 N
  35. ' O8 {& n( z4 P% Q; k3 q3 d" T, V

  36. % E' R  C  s0 v, I
  37. _GET_A20_STATE_:
    / c$ x6 b! c8 F+ F6 h4 M, ~
  38.                 call    A20Write                ; Wait till the input register is empty ! i/ {1 S) |6 \8 _# n- R
  39.                 jz      exit2+1                 ; Bypas the reset int's
    - Q; \3 J/ ^1 |$ X* T; x  L% L: k
  40.                 cli                             ; Disable ints so we'll get our value
    ) H% Y( C& i, t2 ~" @" y

  41. % E$ p/ v- K) W" l  S5 `% a; N
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register
    $ n1 ~% ]$ M; W5 x, }2 k; N
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port
    : E. I& \4 d, S! ^
  44.                 call    A20Read                 ; Wait till the 8042 output register
    6 X- I+ B+ t: }  v' `2 o- W
  45.                 jz      exit2                   ; has something in it's buffer
    4 C  N5 V; ^6 D  G& M+ W6 y

  46. 3 F! i& O2 j0 I, O+ T& {0 m" F  N
  47.                 in      al, 60h                 ; Get it
    1 z6 d6 z- b4 Y1 T  O  U9 n
  48.                 mov     ah, al 9 C0 z2 }0 D/ [- i
  49.                 call    A20Write                ; Make sure the input register is empty
    ) ]4 e9 n! h3 }3 a
  50.                 jz      exit2 9 S7 D- `0 \$ H% ]

  51. 0 a: C; D- S0 |0 E# i4 b' ^2 V4 _
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    " D$ _8 c- J& [/ g
  53.                 out     64h, al
    ) R2 P' n% t; B
  54.                 call    A20Write
    ( b2 r" f6 h/ w8 g' j0 ]2 j

  55. 6 h  h: S0 F8 l, Q
  56. exit2:          sti
    % q, Z: L! \. y- t% Y* P
  57.                 ret' V/ N) f# W- }5 J5 E( A
  58. & @/ W5 U% G) e/ r# X  v( \
  59. " o' f4 w5 P) x  |5 l4 j- o8 T
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    " D4 H/ [9 A. d1 R0 a# A
  61. get1:           in      al, 64h                 ; Get KBC read status
    % P& a$ M0 D! G; O: ^# d
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear " O% W: u- p  `- {" R
  63.                 jz      clear * A7 T; N( b. ?$ U* Z! b  h* O# d2 {
  64.                 dec     cx
    8 ]& [! E* V% L+ t) r
  65.                 jz      exit3 " d9 \) Z$ a  o+ K- m+ j
  66.                 jmp     SHORT get1 8 x: W, [) U0 Q6 n0 x
  67. clear:          inc     al                      ; Clear ZR
    : s3 R& c( t0 n+ C( S
  68. exit3:          ret 2 R: ^" @2 l6 V. j- o! y# O

  69. & R+ u, X# _$ b, r& ^6 @' l" \
  70. , T& S- o# b6 p" L' g5 X3 E
  71. A20Read:        xor     cx, cx " Q8 c! t, m' I, L2 R; T5 @' @
  72. get2:           in      al, 64h 1 m0 a8 y' N. J5 _. q& r
  73.                 test    al, 01                  ; If the 'output buffer' is full, has * N" V- M" s4 f( I! Q1 B% V
  74.                 jnz     exit4                   ; something for me
    0 Q8 V$ I" `6 ]* Y% f. c& h, {
  75.                 dec     cx
    8 w1 c  O+ ?, i; r
  76.                 jnz     get2
    6 u, _4 W; e2 h9 r+ u" g! N- u5 |
  77. exit4:          ret     $ E* V2 v1 h& S: W* f: X
  78.                
    # y! {% U9 T! ?- R8 g
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20(); K" `6 P" |5 ]
{        while(inp(0x64) & 2);        outp(0x64,0xd1);
9 R( _3 m3 I1 ^5 S& H        while(inp(0x64) & 2);        outp(0x60,0xdf);$ m( N4 x' z8 ^2 k2 h7 l+ T; k6 k
        while(inp(0x64) & 2);        outp(0x64,0xff);
& n. s0 r0 Z1 ^  H* l}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-6-8 08:33 , Processed in 0.055510 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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