aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2008-04-05 19:30:02 -0400
committerKevin O'Connor <kevin@koconnor.net>2008-04-05 19:30:02 -0400
commit06ad44ee1e8b2e2e6dcfca206e5c29a62bf67f9b (patch)
tree65a3459ff9afd8c73f5bcbd06ffd17ea085430da
parente0113c99c083d9b812216e120aff9eb9806de91b (diff)
downloadseabios-06ad44ee1e8b2e2e6dcfca206e5c29a62bf67f9b.tar.gz
Introduce cpu_relax() and use it in busy loops.
-rw-r--r--src/floppy.c14
-rw-r--r--src/kbd.c4
-rw-r--r--src/util.h5
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;
diff --git a/src/kbd.c b/src/kbd.c
index 0e0dd5b7..3770305b 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -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));
diff --git a/src/util.h b/src/util.h
index dff1a116..344bcbc1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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");