コード例 #1
0
ファイル: mini-os.c プロジェクト: codercold/xen-4.4
int console_checkkey (void)
{
    if (has_ev)
        return 1;
    has_ev = kbdfront_receive(kbd_dev, &ev, 1);
    return has_ev;
}
コード例 #2
0
ファイル: mini-os.c プロジェクト: codercold/xen-4.4
int console_getkey (void)
{
    static int shift, control, alt, caps_lock;

    if (!has_ev)
        has_ev = kbdfront_receive(kbd_dev, &ev, 1);
    if (!has_ev)
        return 0;

    has_ev = 0;
    if (ev.type != XENKBD_TYPE_KEY)
        return 0;

    if (ev.key.keycode == 42 || ev.key.keycode == 54) {
        caps_lock = 0;
        shift = ev.key.pressed;
        return 0;
    }
    if (ev.key.keycode == 58) {
        caps_lock ^= 1;
        return 0;
    }
    if (ev.key.keycode == 29 || ev.key.keycode == 97) {
        control = ev.key.pressed;
        return 0;
    }
    if (ev.key.keycode == 56) {
        alt = ev.key.pressed;
        return 0;
    }

    if (!ev.key.pressed)
        return 0;

    if (ev.key.keycode < sizeof(linux2ascii) / sizeof(*linux2ascii)) {
        char val;
        if (shift || caps_lock)
            val = linux2ascii_shifted[ev.key.keycode];
        else
            val = linux2ascii[ev.key.keycode];
        if (control)
            val &= ~0x60;
        return val;
    }

    return 0;
}
コード例 #3
0
ファイル: sys.c プロジェクト: jonludlam/xen-arm
int read(int fd, void *buf, size_t nbytes)
{
    switch (files[fd].type) {
        case FTYPE_SAVEFILE:
	case FTYPE_CONSOLE: {
	    int ret;
            DEFINE_WAIT(w);
            while(1) {
                add_waiter(w, console_queue);
                ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes);
                if (ret)
                    break;
                schedule();
            }
            remove_waiter(w, console_queue);
            return ret;
        }
#ifdef HAVE_LWIP
	case FTYPE_SOCKET:
	    return lwip_read(files[fd].socket.fd, buf, nbytes);
#endif
#ifdef CONFIG_NETFRONT
	case FTYPE_TAP: {
	    ssize_t ret;
	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret;
	}
#endif
#ifdef CONFIG_KBDFRONT
        case FTYPE_KBD: {
            int ret, n;
            n = nbytes / sizeof(union xenkbd_in_event);
            ret = kbdfront_receive(files[fd].kbd.dev, buf, n);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret * sizeof(union xenkbd_in_event);
        }
#endif
#ifdef CONFIG_FBFRONT
        case FTYPE_FB: {
            int ret, n;
            n = nbytes / sizeof(union xenfb_in_event);
            ret = fbfront_receive(files[fd].fb.dev, buf, n);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret * sizeof(union xenfb_in_event);
        }
#endif
#ifdef CONFIG_BLKFRONT
        case FTYPE_BLK: {
	    return blkfront_posix_read(fd, buf, nbytes);
        }
#endif
#ifdef CONFIG_TPMFRONT
        case FTYPE_TPMFRONT: {
	    return tpmfront_posix_read(fd, buf, nbytes);
        }
#endif
#ifdef CONFIG_TPM_TIS
        case FTYPE_TPM_TIS: {
	    return tpm_tis_posix_read(fd, buf, nbytes);
        }
#endif
	default:
	    break;
    }
    printk("read(%d): Bad descriptor\n", fd);
    errno = EBADF;
    return -1;
}
コード例 #4
0
static void xenfb_kbd_handler(void *opaque)
{
#define KBD_NUM_BATCH 64
    union xenkbd_in_event buf[KBD_NUM_BATCH];
    int n, i;
    XenFBState *xs = opaque;
    DisplayState *s = xs->ds;
    static int buttons;
    static int x, y;

    n = kbdfront_receive(xs->kbd_dev, buf, KBD_NUM_BATCH);
    for (i = 0; i < n; i++) {
        switch (buf[i].type) {

            case XENKBD_TYPE_MOTION:
                fprintf(stderr, "FB backend sent us relative mouse motion event!\n");
                break;

            case XENKBD_TYPE_POS:
            {
                int new_x = buf[i].pos.abs_x;
                int new_y = buf[i].pos.abs_y;
                if (new_x >= s->width)
                    new_x = s->width - 1;
                if (new_y >= s->height)
                    new_y = s->height - 1;
                if (kbd_mouse_is_absolute()) {
                    kbd_mouse_event(
                            new_x * 0x7FFF / (s->width - 1),
                            new_y * 0x7FFF / (s->height - 1),
                            buf[i].pos.rel_z,
                            buttons);
                } else {
                    kbd_mouse_event(
                            new_x - x,
                            new_y - y,
                            buf[i].pos.rel_z,
                            buttons);
                }
                x = new_x;
                y = new_y;
                break;
            }

            case XENKBD_TYPE_KEY:
            {
                int keycode = buf[i].key.keycode;
                int button = 0;

                if (keycode == BTN_LEFT)
                    button = MOUSE_EVENT_LBUTTON;
                else if (keycode == BTN_RIGHT)
                    button = MOUSE_EVENT_RBUTTON;
                else if (keycode == BTN_MIDDLE)
                    button = MOUSE_EVENT_MBUTTON;

                if (button) {
                    if (buf[i].key.pressed)
                        buttons |=  button;
                    else
                        buttons &= ~button;
                    if (kbd_mouse_is_absolute())
                        kbd_mouse_event(
                                x * 0x7FFF / (s->width - 1),
                                y * 0x7FFF / (s->height - 1),
                                0,
                                buttons);
                    else
                        kbd_mouse_event(0, 0, 0, buttons);
                } else {
                    int scancode = linux2scancode[keycode];
                    if (!scancode) {
                        fprintf(stderr, "Can't convert keycode %x to scancode\n", keycode);
                        break;
                    }
                    if (scancode & 0x80) {
                        kbd_put_keycode(0xe0);
                        scancode &= 0x7f;
                    }
                    if (!buf[i].key.pressed)
                        scancode |= 0x80;
                    kbd_put_keycode(scancode);
                }
                break;
            }
        }
    }
}
コード例 #5
0
ファイル: sys.c プロジェクト: carriercomm/minios-hacks
int read(int fd, void *buf, size_t nbytes)
{
    if (fd < 0 || fd >= NOFILE) {
	fd = EBADF;
	return -1;
    }
    switch (files[fd].type) {
        case FTYPE_SAVEFILE:
	case FTYPE_CONSOLE: {
	    int ret;
            DEFINE_WAIT(w);
            while(1) {
                add_waiter(w, console_queue);
                ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes);
                if (ret)
                    break;
                schedule();
            }
            remove_waiter(w);
            return ret;
        }
#ifdef HAVE_LWIP
	case FTYPE_SOCKET:
	    return lwip_read(files[fd].socket.fd, buf, nbytes);
#endif
	case FTYPE_TAP: {
	    ssize_t ret;
	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret;
	}
        case FTYPE_KBD: {
            int ret, n;
            n = nbytes / sizeof(union xenkbd_in_event);
            ret = kbdfront_receive(files[fd].kbd.dev, buf, n);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret * sizeof(union xenkbd_in_event);
        }
        case FTYPE_FB: {
            int ret, n;
            n = nbytes / sizeof(union xenfb_in_event);
            ret = fbfront_receive(files[fd].fb.dev, buf, n);
	    if (ret <= 0) {
		errno = EAGAIN;
		return -1;
	    }
	    return ret * sizeof(union xenfb_in_event);
        }
	case FTYPE_COMPILED_FILE: {
	    int n;
	    if (files[fd].compiled_file.offset >= files[fd].compiled_file.size)
		    n = 0;
	    else
		    n = files[fd].compiled_file.size - files[fd].compiled_file.offset;
	    if (n >= nbytes)
		    n = nbytes;
	    printf("Request %d on %d, get %d\n", nbytes, fd, n);
	    memcpy(buf, files[fd].compiled_file.content + files[fd].compiled_file.offset, n);
	    files[fd].compiled_file.offset += n;
	    return n;
	}
	default:
	    break;
    }
    printk("read(%d): Bad descriptor\n", fd);
    errno = EBADF;
    return -1;
}