예제 #1
0
파일: pic.c 프로젝트: Kloniks/muk
void pic_ack(int i)
{
  uchar_t mask;

  /* not initiated by the pic
   */
  if (i < 32)
    return ;

  i -= 32;

  if (i < 8)
    {
      mask = cpu_inb(0x21);
      cpu_outb(0x21, mask);
      cpu_outb(0x20, 0x60 + i);
    }
  else
    {
      mask = cpu_inb(0xa1);
      cpu_outb(0xa1, mask);
      cpu_outb(0xa0, 0x60 + (i & 0x7));
      cpu_outb(0x20, 0x60 + 2);
    }
}
예제 #2
0
파일: pic.c 프로젝트: Kloniks/muk
static void i8259a_disable_irq(int i)
{
  if (i < 8)
    cpu_outb(PIC_MASTER + 1, cpu_inb(PIC_MASTER + 1) | (1 << (i)));
  else
    cpu_outb(PIC_SLAVE + 1, cpu_inb(PIC_SLAVE + 1) | (1 << (i - 8)));
}
예제 #3
0
파일: i8042.c 프로젝트: Kloniks/muk
static void on_interrupt(void)
{
  uint8_t status;
  uint8_t data;

  /* interrupt gate, can safely
   */

  status = cpu_inb(I8042_PORT_STATUS);
  if (status & 1)
    {
      data = cpu_inb(I8042_PORT_OUT);
      keyboard_putc(data);
    }
}
예제 #4
0
static uint32_t isa_mmio_readb (void *opaque, target_phys_addr_t addr)
{
    uint32_t val;

    val = cpu_inb(addr & IOPORTS_MASK);
    return val;
}
예제 #5
0
파일: kbd.c 프로젝트: 8l/os64
/* handle keyboard interrupt */
static void
kbd_handler(uint8_t intno, struct intr_stack *intr_stack, struct regs *regs)
{
    static uint8_t shift = 0;
    unsigned char *map;
    uint16_t key;
    uint8_t code;

    code = cpu_inb(KBD_DATA_PORT);

    if (code == 0xb6 || code == 0xaa) {
        shift = 0; 
        return;
    }

    if (code & 0x80) {
        return;
    }

    if (code == 0x36 || code == 0x2a) {
        shift = 1;
        return;
    }

    map = shift ? kbd_map_shift : kbd_map_default;

    key = ((uint16_t)code << 8) | map[code];

    (void)kbd_buf_append(key);
}
예제 #6
0
파일: isa_mmio.c 프로젝트: AmesianX/winkvm
static uint32_t isa_mmio_readb (void *opaque, target_phys_addr_t addr)
{
    uint32_t val;

    val = cpu_inb(NULL, addr & 0xffff);
    return val;
}
예제 #7
0
static uint64_t bw_io_read(void *opaque, target_phys_addr_t addr, unsigned size)
{
    switch (size) {
    case 1:
        return cpu_inb(addr);
    case 2:
        return cpu_inw(addr);
    case 4:
        return cpu_inl(addr);
    }
    abort();
}
예제 #8
0
파일: i8042.c 프로젝트: Kloniks/muk
error_t i8042_initialize(void)
{
  /* input buffer not empty
   */
  while (cpu_inb(I8042_PORT_STATUS) & I8042_BIT_IN_FULL)
    ;

  /* self test command
   */
  cpu_outb(I8042_PORT_CMD, I8042_CMD_SELF_TEST);
  while (!(cpu_inb(I8042_PORT_STATUS) & I8042_BIT_OUT_FULL))
    ;
  if (cpu_inb(I8042_PORT_OUT) != 0x55)
    {
      BUG();
      return ERROR_FAILURE;
    }

  /* test interface command
   */
  cpu_outb(I8042_PORT_CMD, I8042_CMD_IF_TEST);
  while (!(cpu_inb(I8042_PORT_STATUS) & I8042_BIT_OUT_FULL))
    ;
  if (cpu_inb(I8042_PORT_OUT) != 0x00)
    {
      BUG();
      return ERROR_FAILURE;
    }

  /* enable i8042 controller
   */
  cpu_outb(I8042_PORT_CMD, I8042_CMD_KBD_ENABLE);
  while (!(cpu_inb(I8042_PORT_STATUS) & I8042_BIT_OUT_FULL))
    ;

  /* clear output buffer
   */
  cpu_inb(I8042_PORT_OUT);

  /* enable interrupt
   */
  serial_printl("enabling interrupt\n");
  pic_enable_irq(1, on_interrupt);

  return ERROR_SUCCESS;
}
예제 #9
0
파일: qtest.c 프로젝트: Aakriti/qemu
static void qtest_process_command(CharDriverState *chr, gchar **words)
{
    const gchar *command;

    g_assert(words);

    command = words[0];

    if (qtest_log_fp) {
        qemu_timeval tv;
        int i;

        qtest_get_time(&tv);
        fprintf(qtest_log_fp, "[R +" FMT_timeval "]",
                (long) tv.tv_sec, (long) tv.tv_usec);
        for (i = 0; words[i]; i++) {
            fprintf(qtest_log_fp, " %s", words[i]);
        }
        fprintf(qtest_log_fp, "\n");
    }

    g_assert(command);
    if (strcmp(words[0], "irq_intercept_out") == 0
        || strcmp(words[0], "irq_intercept_in") == 0) {
	DeviceState *dev;

        g_assert(words[1]);
        dev = DEVICE(object_resolve_path(words[1], NULL));
        if (!dev) {
            qtest_send_prefix(chr);
            qtest_send(chr, "FAIL Unknown device\n");
	    return;
        }

        if (irq_intercept_dev) {
            qtest_send_prefix(chr);
            if (irq_intercept_dev != dev) {
                qtest_send(chr, "FAIL IRQ intercept already enabled\n");
            } else {
                qtest_send(chr, "OK\n");
            }
	    return;
        }

        if (words[0][14] == 'o') {
            qemu_irq_intercept_out(&dev->gpio_out, qtest_irq_handler, dev->num_gpio_out);
        } else {
            qemu_irq_intercept_in(dev->gpio_in, qtest_irq_handler, dev->num_gpio_in);
        }
        irq_intercept_dev = dev;
        qtest_send_prefix(chr);
        qtest_send(chr, "OK\n");

    } else if (strcmp(words[0], "outb") == 0 ||
               strcmp(words[0], "outw") == 0 ||
               strcmp(words[0], "outl") == 0) {
        uint16_t addr;
        uint32_t value;

        g_assert(words[1] && words[2]);
        addr = strtoul(words[1], NULL, 0);
        value = strtoul(words[2], NULL, 0);

        if (words[0][3] == 'b') {
            cpu_outb(addr, value);
        } else if (words[0][3] == 'w') {
            cpu_outw(addr, value);
        } else if (words[0][3] == 'l') {
            cpu_outl(addr, value);
        }
        qtest_send_prefix(chr);
        qtest_send(chr, "OK\n");
    } else if (strcmp(words[0], "inb") == 0 ||
        strcmp(words[0], "inw") == 0 ||
        strcmp(words[0], "inl") == 0) {
        uint16_t addr;
        uint32_t value = -1U;

        g_assert(words[1]);
        addr = strtoul(words[1], NULL, 0);

        if (words[0][2] == 'b') {
            value = cpu_inb(addr);
        } else if (words[0][2] == 'w') {
            value = cpu_inw(addr);
        } else if (words[0][2] == 'l') {
            value = cpu_inl(addr);
        }
        qtest_send_prefix(chr);
        qtest_send(chr, "OK 0x%04x\n", value);
    } else if (strcmp(words[0], "writeb") == 0 ||
               strcmp(words[0], "writew") == 0 ||
               strcmp(words[0], "writel") == 0 ||
               strcmp(words[0], "writeq") == 0) {
        uint64_t addr;
        uint64_t value;

        g_assert(words[1] && words[2]);
        addr = strtoull(words[1], NULL, 0);
        value = strtoull(words[2], NULL, 0);

        if (words[0][5] == 'b') {
            uint8_t data = value;
            cpu_physical_memory_write(addr, &data, 1);
        } else if (words[0][5] == 'w') {
            uint16_t data = value;
            tswap16s(&data);
            cpu_physical_memory_write(addr, &data, 2);
        } else if (words[0][5] == 'l') {
            uint32_t data = value;
            tswap32s(&data);
            cpu_physical_memory_write(addr, &data, 4);
        } else if (words[0][5] == 'q') {
            uint64_t data = value;
            tswap64s(&data);
            cpu_physical_memory_write(addr, &data, 8);
        }
        qtest_send_prefix(chr);
        qtest_send(chr, "OK\n");
    } else if (strcmp(words[0], "readb") == 0 ||
               strcmp(words[0], "readw") == 0 ||
               strcmp(words[0], "readl") == 0 ||
               strcmp(words[0], "readq") == 0) {
        uint64_t addr;
        uint64_t value = UINT64_C(-1);

        g_assert(words[1]);
        addr = strtoull(words[1], NULL, 0);

        if (words[0][4] == 'b') {
            uint8_t data;
            cpu_physical_memory_read(addr, &data, 1);
            value = data;
        } else if (words[0][4] == 'w') {
            uint16_t data;
            cpu_physical_memory_read(addr, &data, 2);
            value = tswap16(data);
        } else if (words[0][4] == 'l') {
            uint32_t data;
            cpu_physical_memory_read(addr, &data, 4);
            value = tswap32(data);
        } else if (words[0][4] == 'q') {
            cpu_physical_memory_read(addr, &value, 8);
            tswap64s(&value);
        }
        qtest_send_prefix(chr);
        qtest_send(chr, "OK 0x%016" PRIx64 "\n", value);
    } else if (strcmp(words[0], "read") == 0) {
        uint64_t addr, len, i;
        uint8_t *data;

        g_assert(words[1] && words[2]);
        addr = strtoull(words[1], NULL, 0);
        len = strtoull(words[2], NULL, 0);

        data = g_malloc(len);
        cpu_physical_memory_read(addr, data, len);

        qtest_send_prefix(chr);
        qtest_send(chr, "OK 0x");
        for (i = 0; i < len; i++) {
            qtest_send(chr, "%02x", data[i]);
        }
        qtest_send(chr, "\n");

        g_free(data);
    } else if (strcmp(words[0], "write") == 0) {
        uint64_t addr, len, i;
        uint8_t *data;
        size_t data_len;

        g_assert(words[1] && words[2] && words[3]);
        addr = strtoull(words[1], NULL, 0);
        len = strtoull(words[2], NULL, 0);

        data_len = strlen(words[3]);
        if (data_len < 3) {
            qtest_send(chr, "ERR invalid argument size\n");
            return;
        }

        data = g_malloc(len);
        for (i = 0; i < len; i++) {
            if ((i * 2 + 4) <= data_len) {
                data[i] = hex2nib(words[3][i * 2 + 2]) << 4;
                data[i] |= hex2nib(words[3][i * 2 + 3]);
            } else {
                data[i] = 0;
            }
        }
        cpu_physical_memory_write(addr, data, len);
        g_free(data);

        qtest_send_prefix(chr);
        qtest_send(chr, "OK\n");
    } else if (qtest_enabled() && strcmp(words[0], "clock_step") == 0) {
        int64_t ns;

        if (words[1]) {
            ns = strtoll(words[1], NULL, 0);
        } else {
            ns = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
        }
        qtest_clock_warp(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns);
        qtest_send_prefix(chr);
        qtest_send(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
    } else if (qtest_enabled() && strcmp(words[0], "clock_set") == 0) {
        int64_t ns;

        g_assert(words[1]);
        ns = strtoll(words[1], NULL, 0);
        qtest_clock_warp(ns);
        qtest_send_prefix(chr);
        qtest_send(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
    } else {
        qtest_send_prefix(chr);
        qtest_send(chr, "FAIL Unknown command `%s'\n", words[0]);
    }
}
예제 #10
0
파일: isa_mmio.c 프로젝트: AjayMashi/x-tier
static uint32_t isa_mmio_readb (void *opaque, hwaddr addr)
{
    return cpu_inb(addr & IOPORTS_MASK);
}
예제 #11
0
static uint32_t sh_pci_inb (void *p, target_phys_addr_t addr)
{
    return cpu_inb(NULL, sh_pci_addr2port(p, addr));
}
예제 #12
0
target_ulong helper_inb(uint32_t port)
{
    return cpu_inb(port);
}