Subversion Repositories HelenOS

Rev

Rev 4044 | Rev 4114 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
78 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2005 Jakub Jermar
78 jermar 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1888 jermar 29
/** @addtogroup ia64   
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
78 jermar 35
#include <arch/ski/ski.h>
577 palkovsky 36
#include <console/console.h>
37
#include <console/chardev.h>
1507 vana 38
#include <sysinfo/sysinfo.h>
1942 jermar 39
#include <arch/types.h>
1945 jermar 40
#include <proc/thread.h>
1942 jermar 41
#include <synch/spinlock.h>
42
#include <arch/asm.h>
3661 vana 43
#include <arch/drivers/kbd.h>
4060 jermar 44
#include <arch.h>
78 jermar 45
 
4060 jermar 46
static chardev_t *skiout;
1942 jermar 47
 
4060 jermar 48
static chardev_t ski_stdout;
1942 jermar 49
 
50
static bool kbd_disabled;
51
 
79 jermar 52
/** Display character on debug console
53
 *
54
 * Use SSC (Simulator System Call) to
55
 * display character on debug console.
56
 *
583 jermar 57
 * @param d Character device.
58
 * @param ch Character to be printed.
79 jermar 59
 */
3844 decky 60
static void ski_putchar(chardev_t *d, const char ch, bool silent)
78 jermar 61
{
3844 decky 62
    if (!silent) {
63
        asm volatile (
64
            "mov r15 = %0\n"
65
            "mov r32 = %1\n"   /* r32 is in0 */
66
            "break 0x80000\n"  /* modifies r8 */
67
            :
68
            : "i" (SKI_PUTCHAR), "r" (ch)
69
            : "r15", "in0", "r8"
70
        );
71
 
72
        if (ch == '\n')
3854 decky 73
            ski_putchar(d, '\r', false);
3844 decky 74
    }
78 jermar 75
}
519 vana 76
 
4060 jermar 77
static chardev_operations_t ski_ops = {
78
    .write = ski_putchar
79
};
80
 
523 jermar 81
/** Ask debug console if a key was pressed.
519 vana 82
 *
83
 * Use SSC (Simulator System Call) to
84
 * get character from debug console.
523 jermar 85
 *
86
 * This call is non-blocking.
87
 *
88
 * @return ASCII code of pressed key or 0 if no key pressed.
519 vana 89
 */
3844 decky 90
static int32_t ski_getchar(void)
519 vana 91
{
1780 jermar 92
    uint64_t ch;
519 vana 93
 
2082 decky 94
    asm volatile (
1942 jermar 95
        "mov r15 = %1\n"
519 vana 96
        "break 0x80000;;\n" /* modifies r8 */
1942 jermar 97
        "mov %0 = r8;;\n"      
519 vana 98
 
584 jermar 99
        : "=r" (ch)
100
        : "i" (SKI_GETCHAR)
1942 jermar 101
        : "r15", "r8"
519 vana 102
    );
103
 
1780 jermar 104
    return (int32_t) ch;
519 vana 105
}
577 palkovsky 106
 
107
/** Ask keyboard if a key was pressed. */
1945 jermar 108
static void poll_keyboard(void)
577 palkovsky 109
{
110
    char ch;
1942 jermar 111
    ipl_t ipl;
3880 decky 112
 
1942 jermar 113
    ipl = interrupts_disable();
3880 decky 114
 
1942 jermar 115
    if (kbd_disabled) {
116
        interrupts_restore(ipl);
577 palkovsky 117
        return;
1942 jermar 118
    }
3880 decky 119
 
577 palkovsky 120
    ch = ski_getchar();
121
    if(ch == '\r')
122
        ch = '\n';
4060 jermar 123
    if (ch && skiout) {
124
        chardev_push_character(skiout, ch);
1942 jermar 125
        interrupts_restore(ipl);
1570 vana 126
        return;
1942 jermar 127
    }
1507 vana 128
 
1942 jermar 129
    interrupts_restore(ipl);
577 palkovsky 130
}
131
 
4060 jermar 132
#define POLL_INTERVAL           10000           /* 10 ms */
577 palkovsky 133
 
4060 jermar 134
/** Kernel thread for polling keyboard. */
135
static void kkbdpoll(void *arg)
577 palkovsky 136
{
4060 jermar 137
    while (1) {
138
        if (!silent) {
139
            poll_keyboard();
140
        }
141
        thread_usleep(POLL_INTERVAL);
142
    }
577 palkovsky 143
}
144
 
145
/** Initialize debug console
146
 *
147
 * Issue SSC (Simulator System Call) to
148
 * to open debug console.
149
 */
4060 jermar 150
void ski_console_init(chardev_t *devout)
577 palkovsky 151
{
2082 decky 152
    asm volatile (
1942 jermar 153
        "mov r15 = %0\n"
577 palkovsky 154
        "break 0x80000\n"
155
        :
156
        : "i" (SKI_INIT_CONSOLE)
157
        : "r15", "r8"
158
    );
159
 
4060 jermar 160
    skiout = devout;
161
    chardev_initialize("ski_stdout", &ski_stdout, &ski_ops);
162
    stdout = &ski_stdout;
1507 vana 163
 
4060 jermar 164
    thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
165
    if (!t)
166
        panic("Cannot create kkbdpoll.");
167
    thread_ready(t);
1942 jermar 168
 
169
    sysinfo_set_item_val("kbd", NULL, true);
3657 vana 170
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
3718 svoboda 171
 
172
    sysinfo_set_item_val("fb", NULL, false);
1507 vana 173
}
1702 cejka 174
 
1942 jermar 175
void ski_kbd_grab(void)
176
{
4060 jermar 177
    kbd_disabled = true;
1942 jermar 178
}
179
 
180
void ski_kbd_release(void)
181
{
4060 jermar 182
    kbd_disabled = false;
1942 jermar 183
}
184
 
1888 jermar 185
/** @}
1702 cejka 186
 */