diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2008-04-05 19:30:02 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2008-04-05 19:30:02 -0400 |
commit | 06ad44ee1e8b2e2e6dcfca206e5c29a62bf67f9b (patch) | |
tree | 65a3459ff9afd8c73f5bcbd06ffd17ea085430da | |
parent | e0113c99c083d9b812216e120aff9eb9806de91b (diff) | |
download | seabios-06ad44ee1e8b2e2e6dcfca206e5c29a62bf67f9b.tar.gz |
Introduce cpu_relax() and use it in busy loops.
-rw-r--r-- | src/floppy.c | 14 | ||||
-rw-r--r-- | src/kbd.c | 4 | ||||
-rw-r--r-- | src/util.h | 5 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/floppy.c b/src/floppy.c index 0954720e..c27ee87a 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -117,9 +117,12 @@ floppy_prepare_controller(u8 drive) if (prev_reset == 0) { irq_enable(); u8 v; - do { + for (;;) { v = GET_BDA(floppy_recalibration_status); - } while ((v & FRS_TIMEOUT) == 0); + if (v & FRS_TIMEOUT) + break; + cpu_relax(); + } irq_disable(); v &= ~FRS_TIMEOUT; @@ -139,14 +142,17 @@ floppy_pio(u8 *cmd, u8 cmdlen) irq_enable(); u8 v; - do { + for (;;) { if (!GET_BDA(floppy_motor_counter)) { irq_disable(); floppy_reset_controller(); return DISK_RET_ETIMEOUT; } v = GET_BDA(floppy_recalibration_status); - } while (!(v & FRS_TIMEOUT)); + if (v & FRS_TIMEOUT) + break; + cpu_relax(); + } irq_disable(); v &= ~FRS_TIMEOUT; @@ -59,8 +59,8 @@ keyboard_init() if (inb(PORT_PS2_STATUS) & 0x01) { inb(PORT_PS2_DATA); max = 0x2000; - } } + } // Due to timer issues, and if the IPS setting is > 15000000, // the incoming keys might not be flushed here. That will @@ -193,7 +193,7 @@ dequeue_key(u8 *scan_code, u8 *ascii_code, u8 incr) break; if (!incr) return 0; - nop(); + cpu_relax(); } *ascii_code = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+0x400+0)); @@ -32,6 +32,11 @@ static inline void irq_restore(unsigned long flags) asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc"); } +static inline void cpu_relax(void) +{ + asm volatile("rep ; nop": : :"memory"); +} + static inline void nop(void) { asm volatile("nop"); |