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

Enable or disable A20 gate through KBC demo code.

[复制链接]
发表于 2008-10-8 14:58:49 | 显示全部楼层 |阅读模式
反正图方便的,就拿去参照,也是之前遗留的code,整理了一下,好象其中的代码,一位Korea的同学有留下来一段code。
  1. ;A200N.ASM 9 g' C9 `, Z. @1 j6 M. H
  2. ;
    - c, V' K( f' C: N9 [  @
  3. ; Trun on the line A20 through the KBC, programming by bini for debug. 2008-07-010 R! O8 S9 A; J3 ]
  4. ;       ml A20ON.asm ( X$ D7 M1 B# h) r9 S
  5. ;
    " F! A3 f* y( q& g" M) {8 F
  6. .model tiny
    ; Z; m4 J; F5 f7 N" z( I
  7. .code( ]- P7 f/ J) A
  8. .486
    & r7 H7 _2 _4 D! k
  9. .startup- i1 l2 F4 ?0 K* ~

  10. : E1 v& d' d  o; C, ]! b
  11.                 mov     dx, offset msg_author
    & Q1 ~' }1 F9 t0 _
  12.                 mov     ah, 09h! S! T$ k) L, P% x  Z% y
  13.                 int     21h  x+ r& p9 B, Q6 J" e: x

  14. $ S, V# Y5 k) V# t
  15.                 mov     dx, offset msg_fail
    7 o3 ?/ d  O6 B: q9 v6 ^
  16.                 call    A20_ENABLE
    / f% q- w6 p- {9 c$ Z4 E) U
  17.                 jz      exit1
    ; {( @: x- [! z" `3 T5 Y
  18.                 mov     dx, offset msg_ok
    2 a- }1 {5 ~( T7 E2 `0 ~, J/ B* F

  19. % t1 q0 ^' S! _
  20. exit1:          mov     ah, 09h
    4 T4 v3 u2 w# W; J& R4 u  K) w
  21.                 int     21h / p+ s. d# l- a1 M3 w
  22.                 mov     ax, 4C00h ( a* t+ V# {4 u7 q- Q
  23.                 int     21h
    ; B- q4 p7 @3 t4 s  T
  24.                 ( Z. \, X; w% S* ]4 H  P2 _
  25. msg_author      db      "Trun on the line A20 tools through the KBC, programmin by bini", 13, 10,
    2 n6 }! ]! Z4 ^$ V: S" N) W4 g* B4 [
  26.                         "2008-07-01",13, 10, "$"
    , t3 a' d; \7 ~9 n1 k
  27. msg_ok          db      "A20 Enable OK", 13, 10, "$"
    * ^% i& ~% b& F; n& @
  28. msg_fail        db      "A20 Enable FAIL", 13, 10, "$"
    ) k) D" v! ^3 H0 t  V) s4 X3 C1 L! S

  29. , |' S# X3 V8 {6 g( S# c7 E
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------
      p, a9 d  p$ i& ~7 d1 R- t& A
  31. A20_ENABLE:
    8 H& g- c: `  I4 q: M" m
  32.                 call    A20Write $ x) ^: `% m. E9 Z4 k5 t
  33.                 jz      exit_enable
    " [( {2 c: B9 p; d( o6 I# U  L
  34. + @) ?  O! g: y0 E
  35.                 cli                             ; Only need for reading value from KBC
    * L/ D5 o8 l: X! R3 O+ z% @( ~
  36.                 mov     al, 0D0h
    ! l9 E" L9 z9 S$ h2 X8 m' A
  37.                 out     64h, al : _; g6 U; }1 r
  38.                 call    A20Read
    " ^6 }$ o5 o- ^
  39.                 jz      enable_int 9 [; s( z- f& W- K$ o& V9 {

  40. : [6 M( B% v0 q7 C! H2 |0 A- b6 P
  41.                 in      al, 60h                 ; Get current status
    * [# j% @. F* F
  42.                 mov     ah, al : i( y" U* e. L! Z: o' O7 i( N
  43.                 call    A20Write
    ; s7 b. K2 c# k
  44. enable_int:    sti
    / Q+ d/ P2 N: @; J6 L: v# b1 H7 r0 D
  45.                 jz      exit_enable: t3 t0 z, w2 g* n; `% c1 [/ @3 d
  46. 6 ?1 D: m8 Y' n8 t/ T8 j1 U
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the ; |( T  {2 I( c( {
  48.                 out     64h, al                 ; Out Put Port next
    4 L1 y2 D/ Y9 f) o
  49.                 call    A20Write
    1 A; L9 D7 v" W; A/ A$ [
  50.                 jz      exit_enable
    2 i- v' d6 v* `; k. H  S" H
  51. + q) e' N- K" l! P) I8 B3 I: @
  52.                 mov     al, ah
    , t9 p% Y  c- u0 Z! c: u
  53.                 or      al, 2                   ; Enable line A20
    5 _2 A! q& N; e, a. b' R
  54.                 out     60h, al ! P: ?" b. Y# w3 P
  55.                 call    A20Write & X5 X9 h8 p5 }2 G9 Y  ?% v
  56.                 jz      exit_enable  n& `' M/ Z3 W4 Y4 n$ Z
  57. " A. f# S% m" Y- {7 ]/ [. a) o9 d  l
  58.                 mov     al, 0FFh                ; NOP * z( @$ Q, A& \9 l: ~& |
  59.                 out     64h, al % e/ G8 ^4 Q" x" d3 X$ g8 j8 b* `+ ~
  60.                 call    A20Write
    1 [9 F2 a  X8 D/ T9 {" @
  61. 8 s- F$ z! s6 h/ W" U, ~/ V( P0 T
  62. exit_enable:          ret ) }0 D: S! b( g" @* @* u( v
  63. 5 q  w4 E8 C, k) P9 [
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    7 M6 h5 N: L9 _5 I
  65. get_wirte:      in      al, 64h                 ; Get KBC read status
    7 y" \9 ~7 x& Q+ p8 @3 B' c
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear + W/ ]+ F, C- v# Z. N4 \3 ~( A0 f
  67.                 jz      clear
    4 T+ m( \) v0 p! R# P1 i# y, D3 X# a
  68.                 dec     cx
    % _+ Y/ D5 n" q. l' T6 T
  69.                 jz      exit_write ) y; k& o; }* ]# C
  70.                 jmp     short get_wirte
    8 W$ L5 a. t2 [8 S$ P2 \
  71. clear:          inc     al                      ; Clear ZR 1 u. D) X- G* Z( {2 E
  72. exit_write:     ret 8 Q! ]. p6 E/ q8 z/ T4 u  K
  73. + }, J/ a- h- q+ O: k8 p' [
  74. & p9 F( |$ [7 z* F
  75. A20Read:        xor     cx, cx . B+ K- Y: R% ^) j% g+ p$ E* s$ r
  76. get_read:       in      al, 64h 2 @7 M3 F( O9 E- x' K6 a" n4 s, C
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    6 `/ U, ~% m7 K
  78.                 jnz     exit4                   ; ... 7 w9 ?- `& b+ O0 k& z/ u9 w
  79.                 dec     cx
    6 J4 p, _5 g3 e2 Y2 E
  80.                 jnz     get_read: b9 J7 P# }% B/ G9 n
  81. exit4:          ret     
    - x$ Y* ~0 d) {% m% u& l0 i
  82.                
    1 }- u3 z( P$ {  i% U/ C8 ]1 |
  83. end
复制代码
  1. ;A200FF.ASM
    # Z4 z$ o" H+ q5 z8 @2 U
  2. ;
    8 @$ f& o$ E0 [- s
  3. ; Trun off the line A20 through the KBC, programming by bini for debug. 2008-07-01
    * m: N' A" Z, k' a2 a; I( t
  4. ;       ml A20ON.asm
    - K0 M2 `- T( Y2 t
  5. ; ( R# N& s" W( b. Q
  6. .model tiny) I# o; R6 z) r# S6 |
  7. .code
    8 D$ K% V$ Q2 L( w9 _, v/ K2 f" y
  8. .486! d& ~, A; i% S  S! v
  9. .startup
    3 F9 k9 v9 C* V- x# ]4 Q6 a

  10. . s$ M8 A# g6 V/ ?" `$ i4 C
  11.                 mov     dx, offset msg_author# @. V+ p& Y) B0 `2 P' [9 P
  12.                 mov     ah, 09h4 K& h8 i; U0 V! x
  13.                 int     21h
      G) R( A: a. N& r" ~# f
  14. 0 ]  W# J6 d5 n
  15.                 mov     dx, offset msg_fail 2 b% q6 z1 _/ D. f  r# y
  16.                 call    A20_DISABLE
    8 T1 N/ R7 Q0 x3 n( P/ E
  17.                 jz      exit1
    7 e$ Q# O9 _2 V1 P+ R
  18.                 mov     dx, offset msg_ok 6 k7 [" E# N5 q  `  a% g, n

  19. ) Y8 r8 d: s% f' k% D* G& y9 I
  20. exit1:          mov     ah, 09h & i, t# f. ]% e" Y, m
  21.                 int     21h . \8 x4 W5 Z" r4 G6 s9 [7 h
  22.                 mov     ax, 4C00h 2 d1 G) A2 y, M! t) g$ @: U8 F
  23.                 int     21h . Q$ |* I2 p/ G  |
  24.                 / M* ^; T: R2 y, a, p- X7 Q$ y( I
  25. msg_author      db      "Trun off the line A20 tools through the KBC, programmin by bini", 13, 10,$ _2 Y: |  v% G1 x% v& N0 }) e
  26.                         "2008-07-01",13, 10, "$" 9 k  T- r( M2 {. G: w* ]+ |+ O5 l8 _& {
  27. msg_ok          db      "A20 Disable OK", 13, 10, "$" - n) D4 b6 B) H6 [; O0 j" A2 G5 V* \
  28. msg_fail        db      "A20 Disable FAIL", 13, 10, "$" 2 Y; N0 f6 F# B1 g

  29. + h2 s$ s5 g4 T/ L4 C" S
  30. ;------------------------ follow code maybe make to lib, if you want...-------------------------------4 k. ?- M3 f1 i3 K
  31. A20_DISABLE: # X& h3 B( N" Z$ \7 c4 E5 f1 ~
  32.                 call    A20Write 5 u( }! D* `7 w( s9 h
  33.                 jz      exit_disable
    ' |: s4 R5 e  W4 T6 N2 y! o& E
  34.   V- R" q& q3 a6 ^3 F
  35.                 cli                             ; Only need for reading value from KBC
    : y7 d: k5 F3 {
  36.                 mov     al, 0D0h 5 M3 U1 g* K: [  X+ K$ P/ J" v
  37.                 out     64h, al
    ) J) W  l1 d8 a
  38.                 call    A20Read
    5 e6 Y6 t: I' ~2 Z/ a) R5 d
  39.                 jz      Disable_int ! P1 \8 z( X% t: X' S! y
  40. 5 q7 F) o- N' P5 }) N  E1 L, J
  41.                 in      al, 60h                 ; Get current status , Z: d4 C" U) h/ |8 s3 H. R  U
  42.                 mov     ah, al ' }" p7 h2 V. }6 d- Y8 [1 {; k
  43.                 call    A20Write
    ; O- f* d0 X, h  L* a3 K
  44. Disable_int:    sti
    / p9 u" \9 [0 @" q* }, s
  45.                 jz      exit_disable* s% k# e' }! k% h

  46. 5 m# y! `/ U4 r* }. U. A
  47.                 mov     al, 0D1h                ; Tell the KBC , want to write to the & C8 S1 [1 T9 x' g( U% z: p
  48.                 out     64h, al                 ; Out Put Port next
    & i, C) @/ \  _  ?# A8 ?, {
  49.                 call    A20Write 1 K0 E2 v6 C$ l! W8 p/ N5 s) @& \
  50.                 jz      exit_disable5 Z' y! m, r" o5 ?, ^- n

  51. : o2 d2 Y5 \/ K# k$ A  ?# t
  52.                 mov     al, ah
    + o, u2 h0 {5 T
  53.                 and     al, not 2               ; Disable line A20
    2 z9 }$ r% k- X  ?
  54.                 out     60h, al
    1 u2 |$ {0 M2 s: T
  55.                 call    A20Write
    7 z- n" N5 }- {) v' E% O
  56.                 jz      exit_disable
    2 L9 _" F  i0 E2 r
  57. . C1 o3 W" ?! D( Y$ s8 v3 ^
  58.                 mov     al, 0FFh                ; NOP
    8 |% q' Q6 V7 e8 w4 _1 {. x
  59.                 out     64h, al " W0 z, g- b1 T" M' {- r
  60.                 call    A20Write ! I0 U0 r7 e) m/ }

  61. 3 C, }, n7 R" [6 H9 [2 v" J
  62. exit_disable:          ret
    : Q, A+ W! j# `  `7 |" B0 n$ ?( ?
  63. 5 M. e( ?, z$ [. M: B1 N. p% s
  64. A20Write:       xor     cx, cx                  ; Reasonable wait
    2 V& E/ A# x" s+ d( @9 P% |
  65. get_wirte:      in      al, 64h                 ; Get KBC read status 9 H) M. J5 b7 t0 Y9 _8 c
  66.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    ' |+ e# O3 S7 T- u+ l
  67.                 jz      clear   b& U6 d( z# [* b: f( H1 h
  68.                 dec     cx 4 d! Y# f5 g8 `$ \/ p; S
  69.                 jz      exit_write # B$ [8 y6 h+ Z, |* X
  70.                 jmp     short get_wirte , x" c$ L3 \7 a* g4 s
  71. clear:          inc     al                      ; Clear ZR
    0 B! S; `% j& O+ O/ a; W
  72. exit_write:     ret
    8 D. b- c+ L1 Q
  73. 3 r; V, x  F9 N  d: V
  74. : y5 [% s) p, V: k
  75. A20Read:        xor     cx, cx
    # z4 G/ t5 h* M: I  o& p
  76. get_read:       in      al, 64h
    . l4 `9 ~# g( q' A
  77.                 test    al, 01                  ; If the 'output buffer' is full, has
    & _9 j( Y& `+ K  L
  78.                 jnz     exit4                   ; ...   }( p0 g3 s9 Z0 b  m7 v& B; O
  79.                 dec     cx * [, J# a1 Z" P
  80.                 jnz     get_read2 m  M! a* y4 j, r. @/ P
  81. exit4:          ret     
    5 K' R3 I! b9 r$ }9 j, F$ W
  82.                 8 K! c( N# I7 p5 P  g
  83. end
复制代码
  1. ;A20STATE.ASM # e& j7 a0 z& U) q
  2. ; 4 F: f$ b( F  g6 T
  3. ; Returns the status of the line A20 through the KBC ! h3 r* o0 G8 U3 H1 P2 B3 t
  4. ;       programming by bini for debug. 2008-07-01' a$ \+ f8 a) I
  5. ;
    % _( P3 @8 Q) Z0 Q5 S/ n8 A
  6. .model tiny
    8 C  L: |! O' {9 M6 e
  7. .code
    ) y0 R- B5 T' T, b' v
  8. .486& U  o# l" q7 F1 Y
  9. .startup
    8 h0 f0 t' p# o3 t8 D- w9 w9 H. j
  10.                 mov     dx, offset msg_fail 1 t5 b0 x. I0 _, X* F% h+ F3 Y
  11.                 call    _GET_A20_STATE_4 P9 D; R1 U6 c# z. `. W1 F
  12.                 jz      exit1                           ;  was a problem: p, W' M9 `0 x! z$ @3 F! Z: F6 d
  13.                 push    ax                              ; Save state, AH , {% S$ C% R7 W9 f
  14.                 mov     dx, offset msg_ok                      ; There wasn't a problem
    $ }0 G- N" D; [1 Z" Z
  15.                 mov     ah, 09h
    . w& l/ [- m. V& L/ Y
  16.                 int     21h                             ; Print message + h7 [! C  e( z
  17.                 pop     ax                              ; retreve state 7 G1 A1 z  y5 }; f# i6 _7 J. a+ Q

  18. 5 }3 U/ [1 O9 z
  19.                 mov     dx, offset msg_dis ! w# U4 v8 h" k  R+ h. x5 E! f& J. X
  20.                 and     ah, 00000010b                   ; bit 1, 2h, indicates state * n; ?$ U* F( a* c  O% V$ G" ^' d2 Q' O
  21.                 jz      exit1
    . j* u! b( |" ]& `! C" W
  22.                 mov     dx, offset msg_en
    9 h: K0 T' d" T. {9 Y  x
  23. ; K) Q5 K3 `# V2 F' B/ ~4 N
  24. exit1:          mov     ah, 09h 0 N  \: V1 D# t  j
  25.                 ; DX already contains address of string " y8 b; `$ W# _6 r# ^) T7 ?
  26.                 int     21h
    ) g! a+ q2 i# i# z2 Y* K; l$ j

  27. 7 D2 c7 Q. T2 w% T, B5 @8 B
  28.                 mov     ax, 4C00h
    ; o8 d# v4 K  N) q) z9 R7 t2 \
  29.                 int     21h # A+ [3 C; t* g
  30. 7 C; ^' e5 K% r( b1 r
  31. msg_ok         db      "OK", 13, 10, "A20 $"
    9 |! M, X+ h* g# b3 s& B2 V
  32. msg_fail       db      "FAIL", 13, 10, "$" ' S( y4 G4 ]- y- }: h
  33. msg_en         db      "ENABLED", 13, 10, "$" ( u; l% M4 h  X3 ]- o8 {3 O
  34. msg_dis        db      "DISABLED", 13, 10, "$"
      j# [* [4 v  a$ ^7 o" \

  35. ) |9 }: w. P3 l% i

  36.   S. h3 L! A. a6 V- O
  37. _GET_A20_STATE_:
    9 K3 v# Q. J- Q! x- W
  38.                 call    A20Write                ; Wait till the input register is empty
    5 p1 D% K; E; s
  39.                 jz      exit2+1                 ; Bypas the reset int's
    + L; d# u6 Q; l7 ^
  40.                 cli                             ; Disable ints so we'll get our value
    ; Q% n8 I2 Y/ g4 c% q( i; G/ S
  41. 8 p- D( o) P/ I. _8 j8 {/ r2 {: d: K
  42.                 mov     al, 0D0h                ; Send command to the 8042 command register 2 Q' a1 w. N, H2 E3 j
  43.                 out     64h, al                 ; to tell it we want to Read the Output Port ! \( Z4 n! Y, w6 p0 V  J
  44.                 call    A20Read                 ; Wait till the 8042 output register   @# I( e% |; `7 Z! t: p& `
  45.                 jz      exit2                   ; has something in it's buffer
    ! N7 v0 c0 f, @  g
  46. 7 t7 c- g4 T% P0 u3 Q5 u
  47.                 in      al, 60h                 ; Get it 6 j+ S$ ]) H' B8 ]% V0 H0 ?0 y
  48.                 mov     ah, al & h1 f; t" u$ E( B# e" w# S  G- R& b
  49.                 call    A20Write                ; Make sure the input register is empty 4 Z0 G. X3 Y, f4 ?: q
  50.                 jz      exit2
      m  s' K& M- u6 }

  51. 8 X  ~/ p- k0 J. N  U
  52.                 mov     al, 0FFh                ; KBC NOP command, does nothing
    - M" y- s4 q+ B" u- ^- E3 H+ B. v
  53.                 out     64h, al
    8 ~$ e4 P+ j% z. ~% J( c2 @* t
  54.                 call    A20Write / y* f8 l' a9 A/ t+ f/ p3 U1 P
  55. ) K1 ]' H$ d( e; }0 g
  56. exit2:          sti
    , f/ V' f7 h' f8 Y6 `7 |7 g, W1 j
  57.                 ret
    : t/ A) x; P! H1 f

  58. * k) l3 Y/ {% k- k
  59. " M+ \+ g* i; S: `
  60. A20Write:       xor     cx, cx                  ; Reasonable wait
    & e! Q  e2 g  A. E1 }: `8 e
  61. get1:           in      al, 64h                 ; Get KBC read status - Q3 i/ B  }$ }: q. D6 K  F
  62.                 test    al, 02                  ; See if buffer empty, bit 1 clear
    2 e/ {5 {+ ~, }" `: ^# A
  63.                 jz      clear
    + h* f$ j# c0 O. D/ e7 P5 L2 ?" l6 A$ s
  64.                 dec     cx
    . m& z2 Q- ^( w1 T: u4 a- h$ F% S6 h
  65.                 jz      exit3
    8 L8 n) Z+ S' {6 S7 l! h" \
  66.                 jmp     SHORT get1
    * d# ]$ L% @+ d
  67. clear:          inc     al                      ; Clear ZR ; h9 N# [$ Q; d  I5 z: p; c
  68. exit3:          ret ( ?4 [" w# y$ m" I7 Q
  69. ! W0 F* r, A5 g' m
  70. ; C0 q2 }' m/ d8 l. ^' P! p9 p
  71. A20Read:        xor     cx, cx
    0 r9 ?, M5 X  O) B8 C
  72. get2:           in      al, 64h 0 k2 m1 \8 _8 v0 m5 Q
  73.                 test    al, 01                  ; If the 'output buffer' is full, has & p9 K( O; g% {% q* r9 h1 p8 _2 S
  74.                 jnz     exit4                   ; something for me
    8 ~, j1 A! }4 q$ v; @
  75.                 dec     cx : o' _: N# F' z2 \) P* b' K
  76.                 jnz     get2& {, d1 g4 k5 W! {) }- u
  77. exit4:          ret     1 t' I- h; Y* ?) [) {" o2 L$ W
  78.                   d6 H4 G* @$ f7 j$ X0 o7 @4 u
  79. end
复制代码
发表于 2008-10-21 17:14:36 | 显示全部楼层
void openA20()
! I3 H" N. v1 y! ?8 U$ U{        while(inp(0x64) & 2);        outp(0x64,0xd1);4 F/ X0 o* ^0 k0 h' G! o
        while(inp(0x64) & 2);        outp(0x60,0xdf);  v5 V$ K9 R1 N( B' |
        while(inp(0x64) & 2);        outp(0x64,0xff);
" v4 `& Y- p5 ^# ~- ~2 o- ]9 b( a}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-9-22 15:12 , Processed in 0.091523 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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