- __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
- "stc\n\t"
- "int $0x15\n\t"
- "pushfw\n\t"
- "popw %w0\n\t"
- "cli\n\t" )
- : "=r" ( flags ), "=a" ( discard_a )
- : "a" ( Enable_A20 ) );
-
-
- if ( flags & CF ) {
- /* INT 15 method failed, try alternatives */
-#ifdef IBM_L40
- outb(0x2, 0x92);
-#else /* IBM_L40 */
- empty_8042();
- outb(KC_CMD_WOUT, K_CMD);
- empty_8042();
- outb(KB_SET_A20, K_RDWR);
- empty_8042();
-#endif /* IBM_L40 */
+ /* Fast check to see if gate A20 is already enabled */
+ if ( gateA20_is_set ( 0 ) )
+ goto out;
+
+ for ( ; retries < A20_MAX_RETRIES ; retries++ ) {
+ switch ( a20_method ) {
+ case A20_UNKNOWN:
+ case A20_INT15:
+ /* Try INT 15 method */
+ __asm__ __volatile__ ( REAL_CODE ( "int $0x15" )
+ : "=a" ( discard_a )
+ : "a" ( Enable_A20 ) );
+ if ( gateA20_is_set ( A20_INT15_RETRIES ) ) {
+ DBG ( "Enabled gate A20 using BIOS\n" );
+ a20_method = A20_INT15;
+ goto out;
+ }
+ /* fall through */
+ case A20_KBC:
+ /* Try keyboard controller method */
+ empty_8042();
+ outb ( KC_CMD_WOUT, K_CMD );
+ empty_8042();
+ outb ( KB_SET_A20, K_RDWR );
+ empty_8042();
+ outb ( KC_CMD_NULL, K_CMD );
+ empty_8042();
+ if ( gateA20_is_set ( A20_KBC_RETRIES ) ) {
+ DBG ( "Enabled gate A20 using "
+ "keyboard controller\n" );
+ a20_method = A20_KBC;
+ goto out;
+ }
+ /* fall through */
+ case A20_SCPA:
+ /* Try "Fast gate A20" method */
+ scp_a = inb ( SCP_A );
+ scp_a &= ~0x01; /* Avoid triggering a reset */
+ scp_a |= 0x02; /* Enable A20 */
+ iodelay();
+ outb ( scp_a, SCP_A );
+ iodelay();
+ if ( gateA20_is_set ( A20_SCPA_RETRIES ) ) {
+ DBG ( "Enabled gate A20 using "
+ "Fast Gate A20\n" );
+ a20_method = A20_SCPA;
+ goto out;
+ }
+ }