Line 18... |
Line 18... |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
#include <inttypes.h>
|
|
#endif
|
|
|
|
#include "port.h"
|
|
#include "arch.h"
|
#include "ps2kbd.h"
|
#include "ps2kbd.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "sched.h"
|
#include "sched.h"
|
#include "pic.h"
|
#include "pic.h"
|
Line 112... |
Line 121... |
/* Break shift? */
|
/* Break shift? */
|
if (scan_table[c].shift) kbd_put (0xaa);
|
if (scan_table[c].shift) kbd_put (0xaa);
|
}
|
}
|
|
|
/* Write a register */
|
/* Write a register */
|
void kbd_write8 (unsigned long addr, unsigned long value)
|
void kbd_write8 (oraddr_t addr, uint32_t value)
|
{
|
{
|
int a = (addr - config.kbd.baseaddr);
|
int a = (addr - config.kbd.baseaddr);
|
switch (a) {
|
switch (a) {
|
case KBD_CTRL:
|
case KBD_CTRL:
|
kbd_ccmd = value & 0xff;
|
kbd_ccmd = value & 0xff;
|
Line 129... |
Line 138... |
if (kbd_ccmd == KBD_CCMD_DKI)
|
if (kbd_ccmd == KBD_CCMD_DKI)
|
kbd_ccmdbyte |= KBD_CCMDBYTE_EN;
|
kbd_ccmdbyte |= KBD_CCMDBYTE_EN;
|
if (kbd_ccmd == KBD_CCMD_EKI)
|
if (kbd_ccmd == KBD_CCMD_EKI)
|
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
|
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_write8(%lx) %lx\n", addr, value);
|
PRINTF("kbd_write8(%"PRIxADDR") %"PRIx32"\n", addr, value);
|
break;
|
break;
|
case KBD_DATA:
|
case KBD_DATA:
|
if (kbd_ccmd == KBD_CCMD_WCB) {
|
if (kbd_ccmd == KBD_CCMD_WCB) {
|
kbd_ccmdbyte = value & 0xff;
|
kbd_ccmdbyte = value & 0xff;
|
kbd_ccmd = 0x00;
|
kbd_ccmd = 0x00;
|
Line 144... |
Line 153... |
if (kbd_kcmd == KBD_KCMD_EK)
|
if (kbd_kcmd == KBD_KCMD_EK)
|
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
|
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
|
kbd_kresp = 0x1;
|
kbd_kresp = 0x1;
|
kbd_ccmd = 0x00;
|
kbd_ccmd = 0x00;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_write8(%lx) %lx\n", addr, value);
|
PRINTF("kbd_write8(%"PRIxADDR") %"PRIx32"\n", addr, value);
|
break;
|
break;
|
default:
|
default:
|
fprintf (stderr, "Write out of keyboard space (0x%08lx)!\n", addr);
|
fprintf (stderr, "Write out of keyboard space (0x%"PRIxADDR")!\n", addr);
|
runtime.sim.cont_run = 0;
|
runtime.sim.cont_run = 0;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
/* Read a register */
|
/* Read a register */
|
unsigned long kbd_read8 (unsigned long addr)
|
uint32_t kbd_read8 (oraddr_t addr)
|
{
|
{
|
int a = (addr - config.kbd.baseaddr);
|
int a = (addr - config.kbd.baseaddr);
|
switch (a) {
|
switch (a) {
|
case KBD_CTRL: {
|
case KBD_CTRL: {
|
unsigned long c = 0x0;
|
unsigned long c = 0x0;
|
if (kbd_kresp || kbd_buf_count)
|
if (kbd_kresp || kbd_buf_count)
|
c |= KBD_STATUS_OBF;
|
c |= KBD_STATUS_OBF;
|
c |= kbd_ccmdbyte & KBD_CCMDBYTE_SYS;
|
c |= kbd_ccmdbyte & KBD_CCMDBYTE_SYS;
|
c |= KBD_STATUS_INH;
|
c |= KBD_STATUS_INH;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_read8(%lx) %lx\n", addr, c);
|
PRINTF("kbd_read8(%"PRIxADDR") %lx\n", addr, c);
|
return c;
|
return c;
|
}
|
}
|
case KBD_DATA:
|
case KBD_DATA:
|
if (kbd_ccmd) {
|
if (kbd_ccmd) {
|
unsigned long rc;
|
unsigned long rc;
|
Line 180... |
Line 189... |
if (kbd_ccmd == KBD_CCMD_ST2)
|
if (kbd_ccmd == KBD_CCMD_ST2)
|
rc = 0x00;
|
rc = 0x00;
|
kbd_ccmd = 0x00;
|
kbd_ccmd = 0x00;
|
kbd_kresp = 0x0;
|
kbd_kresp = 0x0;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_read8(%lx) %lx\n", addr, rc);
|
PRINTF("kbd_read8(%"PRIxADDR") %lx\n", addr, rc);
|
return rc;
|
return rc;
|
}
|
}
|
else if (kbd_kresp) {
|
else if (kbd_kresp) {
|
unsigned long rc;
|
unsigned long rc;
|
if (kbd_kresp == 0x2) {
|
if (kbd_kresp == 0x2) {
|
Line 200... |
Line 209... |
kbd_kresp = 0x0;
|
kbd_kresp = 0x0;
|
rc = KBD_KRESP_ACK;
|
rc = KBD_KRESP_ACK;
|
}
|
}
|
kbd_kcmd = 0x00;
|
kbd_kcmd = 0x00;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_read8(%lx) %lx\n", addr, rc);
|
PRINTF("kbd_read8(%"PRIxADDR") %lx\n", addr, rc);
|
return rc;
|
return rc;
|
} else if (kbd_buf_count) {
|
} else if (kbd_buf_count) {
|
unsigned long c = kbd_buf[kbd_buf_tail];
|
unsigned long c = kbd_buf[kbd_buf_tail];
|
kbd_buf_tail = (kbd_buf_tail + 1) % KBD_MAX_BUF;
|
kbd_buf_tail = (kbd_buf_tail + 1) % KBD_MAX_BUF;
|
kbd_buf_count--;
|
kbd_buf_count--;
|
kbd_kresp = 0x0;
|
kbd_kresp = 0x0;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_read8(%lx) %lx\n", addr, c);
|
PRINTF("kbd_read8(%"PRIxADDR") %lx\n", addr, c);
|
return c;
|
return c;
|
}
|
}
|
kbd_kresp = 0x0;
|
kbd_kresp = 0x0;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
PRINTF("kbd_read8(%lx) fifo empty\n", addr);
|
PRINTF("kbd_read8(%"PRIxADDR") fifo empty\n", addr);
|
return 0;
|
return 0;
|
default:
|
default:
|
fprintf (stderr, "Read out of keyboard space (0x%08lx)!\n", addr);
|
fprintf (stderr, "Read out of keyboard space (0x%"PRIxADDR")!\n", addr);
|
runtime.sim.cont_run = 0;
|
runtime.sim.cont_run = 0;
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
|
|
Line 241... |
Line 250... |
kbd_kresp, kbd_buf_count);
|
kbd_kresp, kbd_buf_count);
|
if (kbd_int) report_interrupt(config.kbd.irq);
|
if (kbd_int) report_interrupt(config.kbd.irq);
|
SCHED_ADD(kbd_job, 0, runtime.sim.cycles + kbd_slowdown);
|
SCHED_ADD(kbd_job, 0, runtime.sim.cycles + kbd_slowdown);
|
}
|
}
|
|
|
/* Reset all VGAs */
|
/* Reset all (simulated) ps2 controlers/keyboards */
|
void kbd_reset ()
|
void kbd_reset ()
|
{
|
{
|
if (config.kbd.enabled) {
|
if (config.kbd.enabled) {
|
kbd_buf_count = 0;
|
kbd_buf_count = 0;
|
kbd_buf_head = 0;
|
kbd_buf_head = 0;
|