uint32_t ps2_read_data(void *opaque) { PS2State *s = (PS2State *)opaque; PS2Queue *q; int val, index; trace_ps2_read_data(opaque); q = &s->queue; if (q->count == 0) { /* NOTE: if no data left, we return the last keyboard one (needed for EMM386) */ /* XXX: need a timer to do things correctly */ index = q->rptr - 1; if (index < 0) index = PS2_QUEUE_SIZE - 1; val = q->data[index]; } else { val = q->data[q->rptr]; if (++q->rptr == PS2_QUEUE_SIZE) q->rptr = 0; q->count--; /* reading deasserts IRQ */ s->update_irq(s->update_arg, 0); /* reassert IRQs if data left */ s->update_irq(s->update_arg, q->count != 0); } return val; }
void ps2_queue(void *opaque, int b) { PS2State *s = (PS2State *)opaque; PS2Queue *q = &s->queue; if (q->count >= PS2_QUEUE_SIZE - 1) return; q->data[q->wptr] = b; if (++q->wptr == PS2_QUEUE_SIZE) q->wptr = 0; q->count++; s->update_irq(s->update_arg, 1); }
void ps2_queue(void *opaque, int b) { PS2State *s = (PS2State *)opaque; PS2Queue *q = &s->queue; if (q->count >= PS2_QUEUE_SIZE) return; q->data[q->wptr] = b; #ifdef CONFIG_TCG_TAINT q->taint_data[q->wptr] = 0; #endif /* CONFIG_TCG_TAINT */ if (++q->wptr == PS2_QUEUE_SIZE) q->wptr = 0; q->count++; s->update_irq(s->update_arg, 1); }