Subversion Repositories HelenOS

Rev

Rev 4156 | 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
 
4296 trochtova 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>
4055 trochtova 43
#include <arch/drivers/kbd.h>
4296 trochtova 44
#include <string.h>
4156 trochtova 45
#include <arch.h>
78 jermar 46
 
4156 trochtova 47
static indev_t skiin;       /**< Ski input device. */
48
static outdev_t skiout;     /**< Ski output device. */
1942 jermar 49
 
50
static bool kbd_disabled;
51
 
4296 trochtova 52
static void ski_do_putchar(const wchar_t ch)
53
{
54
    asm volatile (
55
        "mov r15 = %[cmd]\n"
56
        "mov r32 = %[ch]\n"   /* r32 is in0 */
57
        "break 0x80000\n"  /* modifies r8 */
58
        :
59
        : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
60
        : "r15", "in0", "r8"
61
    );
62
}
63
 
79 jermar 64
/** Display character on debug console
65
 *
66
 * Use SSC (Simulator System Call) to
67
 * display character on debug console.
68
 *
583 jermar 69
 * @param d Character device.
70
 * @param ch Character to be printed.
79 jermar 71
 */
4296 trochtova 72
static void ski_putchar(outdev_t *d, const wchar_t ch, bool silent)
78 jermar 73
{
4055 trochtova 74
    if (!silent) {
4296 trochtova 75
        if (ascii_check(ch)) {
76
            if (ch == '\n')
77
                ski_do_putchar('\r');
78
 
79
            ski_do_putchar(ch);
80
        } else
81
            ski_do_putchar(SPECIAL);
4055 trochtova 82
    }
78 jermar 83
}
519 vana 84
 
4156 trochtova 85
static indev_operations_t skiin_ops = {
86
    .poll = NULL
87
};
88
 
89
static outdev_operations_t skiout_ops = {
90
    .write = ski_putchar
91
};
92
 
523 jermar 93
/** Ask debug console if a key was pressed.
519 vana 94
 *
95
 * Use SSC (Simulator System Call) to
96
 * get character from debug console.
523 jermar 97
 *
98
 * This call is non-blocking.
99
 *
100
 * @return ASCII code of pressed key or 0 if no key pressed.
519 vana 101
 */
4055 trochtova 102
static int32_t ski_getchar(void)
519 vana 103
{
1780 jermar 104
    uint64_t ch;
519 vana 105
 
2082 decky 106
    asm volatile (
1942 jermar 107
        "mov r15 = %1\n"
519 vana 108
        "break 0x80000;;\n" /* modifies r8 */
1942 jermar 109
        "mov %0 = r8;;\n"      
519 vana 110
 
584 jermar 111
        : "=r" (ch)
112
        : "i" (SKI_GETCHAR)
1942 jermar 113
        : "r15", "r8"
519 vana 114
    );
115
 
1780 jermar 116
    return (int32_t) ch;
519 vana 117
}
577 palkovsky 118
 
119
/** Ask keyboard if a key was pressed. */
1945 jermar 120
static void poll_keyboard(void)
577 palkovsky 121
{
122
    char ch;
4055 trochtova 123
 
4156 trochtova 124
    if (kbd_disabled)
577 palkovsky 125
        return;
126
    ch = ski_getchar();
127
    if(ch == '\r')
128
        ch = '\n';
1942 jermar 129
    if (ch) {
4156 trochtova 130
        indev_push_character(&skiin, ch);
1570 vana 131
        return;
1942 jermar 132
    }
577 palkovsky 133
}
134
 
4156 trochtova 135
#define POLL_INTERVAL           10000           /* 10 ms */
577 palkovsky 136
 
4156 trochtova 137
/** Kernel thread for polling keyboard. */
138
static void kkbdpoll(void *arg)
577 palkovsky 139
{
4156 trochtova 140
    while (1) {
141
        if (!silent) {
142
            poll_keyboard();
143
        }
144
        thread_usleep(POLL_INTERVAL);
145
    }
577 palkovsky 146
}
147
 
148
/** Initialize debug console
149
 *
150
 * Issue SSC (Simulator System Call) to
151
 * to open debug console.
152
 */
4156 trochtova 153
static void ski_init(void)
577 palkovsky 154
{
4156 trochtova 155
    static bool initialized;
156
 
157
    if (initialized)
158
        return;
159
 
2082 decky 160
    asm volatile (
1942 jermar 161
        "mov r15 = %0\n"
577 palkovsky 162
        "break 0x80000\n"
163
        :
164
        : "i" (SKI_INIT_CONSOLE)
165
        : "r15", "r8"
166
    );
4156 trochtova 167
 
168
    initialized = true;
169
}
577 palkovsky 170
 
4156 trochtova 171
indev_t *skiin_init(void)
172
{
173
    ski_init();
1507 vana 174
 
4156 trochtova 175
    indev_initialize("skiin", &skiin, &skiin_ops);
176
    thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
177
    if (t)
178
        thread_ready(t);
179
    else
180
        return NULL;
1942 jermar 181
 
182
    sysinfo_set_item_val("kbd", NULL, true);
4055 trochtova 183
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
184
 
4156 trochtova 185
    return &skiin;
186
}
187
 
188
 
189
void skiout_init(void)
190
{
191
    ski_init();
192
 
193
    outdev_initialize("skiout", &skiout, &skiout_ops);
194
    stdout = &skiout;
195
 
4055 trochtova 196
    sysinfo_set_item_val("fb", NULL, false);
1507 vana 197
}
1702 cejka 198
 
1942 jermar 199
void ski_kbd_grab(void)
200
{
4156 trochtova 201
    kbd_disabled = true;
1942 jermar 202
}
203
 
204
void ski_kbd_release(void)
205
{
4156 trochtova 206
    kbd_disabled = false;
1942 jermar 207
}
208
 
1888 jermar 209
/** @}
1702 cejka 210
 */