Subversion Repositories HelenOS

Rev

Rev 4327 | 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
 
4223 decky 29
/** @addtogroup ia64
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
4311 decky 35
#include <arch/drivers/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>
4220 decky 44
#include <string.h>
4060 jermar 45
#include <arch.h>
78 jermar 46
 
4581 mejdrech 47
enum {
48
    /** Interval between polling in microseconds */
49
    POLL_INTERVAL =  10000,  /* 0.01 s */
1942 jermar 50
 
4581 mejdrech 51
    /** Max. number of characters to pull out at a time */
52
    POLL_LIMIT    =     30,
1942 jermar 53
 
4581 mejdrech 54
    SKI_INIT_CONSOLE  = 20,
55
    SKI_GETCHAR       = 21,
56
    SKI_PUTCHAR       = 31
57
};
58
 
4311 decky 59
static void ski_putchar(outdev_t *, const wchar_t, bool);
60
 
61
static outdev_operations_t skiout_ops = {
62
    .write = ski_putchar
63
};
64
 
65
static outdev_t skiout;            /**< Ski output device. */
66
static bool initialized = false;
67
static bool kbd_disabled = false;
68
 
69
/** Initialize debug console
70
 *
71
 * Issue SSC (Simulator System Call) to
72
 * to open debug console.
73
 *
74
 */
75
static void ski_init(void)
76
{
77
    if (initialized)
78
        return;
79
 
80
    asm volatile (
81
        "mov r15 = %0\n"
82
        "break 0x80000\n"
83
        :
84
        : "i" (SKI_INIT_CONSOLE)
85
        : "r15", "r8"
86
    );
87
 
88
    initialized = true;
89
}
90
 
4220 decky 91
static void ski_do_putchar(const wchar_t ch)
92
{
93
    asm volatile (
94
        "mov r15 = %[cmd]\n"
95
        "mov r32 = %[ch]\n"   /* r32 is in0 */
4311 decky 96
        "break 0x80000\n"     /* modifies r8 */
4220 decky 97
        :
98
        : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
99
        : "r15", "in0", "r8"
100
    );
101
}
102
 
79 jermar 103
/** Display character on debug console
104
 *
105
 * Use SSC (Simulator System Call) to
106
 * display character on debug console.
107
 *
4311 decky 108
 * @param dev    Character device.
109
 * @param ch     Character to be printed.
110
 * @param silent Whether the output should be silenced.
111
 *
79 jermar 112
 */
4311 decky 113
static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
78 jermar 114
{
3844 decky 115
    if (!silent) {
4220 decky 116
        if (ascii_check(ch)) {
117
            if (ch == '\n')
118
                ski_do_putchar('\r');
119
 
120
            ski_do_putchar(ch);
121
        } else
4311 decky 122
            ski_do_putchar(U_SPECIAL);
3844 decky 123
    }
78 jermar 124
}
519 vana 125
 
4311 decky 126
void skiout_init(void)
127
{
128
    ski_init();
129
 
130
    outdev_initialize("skiout", &skiout, &skiout_ops);
131
    stdout = &skiout;
132
 
133
    sysinfo_set_item_val("fb", NULL, false);
134
}
4114 jermar 135
 
523 jermar 136
/** Ask debug console if a key was pressed.
519 vana 137
 *
138
 * Use SSC (Simulator System Call) to
139
 * get character from debug console.
523 jermar 140
 *
141
 * This call is non-blocking.
142
 *
143
 * @return ASCII code of pressed key or 0 if no key pressed.
4311 decky 144
 *
519 vana 145
 */
4311 decky 146
static wchar_t ski_getchar(void)
519 vana 147
{
1780 jermar 148
    uint64_t ch;
519 vana 149
 
2082 decky 150
    asm volatile (
1942 jermar 151
        "mov r15 = %1\n"
4311 decky 152
        "break 0x80000;;\n"  /* modifies r8 */
153
        "mov %0 = r8;;\n"
154
 
584 jermar 155
        : "=r" (ch)
156
        : "i" (SKI_GETCHAR)
1942 jermar 157
        : "r15", "r8"
519 vana 158
    );
4311 decky 159
 
160
    return (wchar_t) ch;
519 vana 161
}
577 palkovsky 162
 
4581 mejdrech 163
/** Ask keyboard if a key was pressed.
164
 *
165
 * If so, it will repeat and pull up to POLL_LIMIT characters.
166
 */
4311 decky 167
static void poll_keyboard(ski_instance_t *instance)
577 palkovsky 168
{
4581 mejdrech 169
    wchar_t ch;
170
    int count;
171
 
4114 jermar 172
    if (kbd_disabled)
577 palkovsky 173
        return;
4581 mejdrech 174
 
175
    count = POLL_LIMIT;
176
 
177
    while (count > 0) {
178
        ch = ski_getchar();
179
 
180
        if (ch == '\0')
181
            break;
182
 
4311 decky 183
        indev_push_character(instance->srlnin, ch);
4581 mejdrech 184
        --count;
185
    }
577 palkovsky 186
}
187
 
4060 jermar 188
/** Kernel thread for polling keyboard. */
4311 decky 189
static void kskipoll(void *arg)
577 palkovsky 190
{
4311 decky 191
    ski_instance_t *instance = (ski_instance_t *) arg;
192
 
193
    while (true) {
194
        if (!silent)
195
            poll_keyboard(instance);
196
 
4060 jermar 197
        thread_usleep(POLL_INTERVAL);
198
    }
577 palkovsky 199
}
200
 
4311 decky 201
ski_instance_t *skiin_init(void)
577 palkovsky 202
{
4311 decky 203
    ski_init();
4114 jermar 204
 
4313 jermar 205
    ski_instance_t *instance =
206
        malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
4114 jermar 207
 
4311 decky 208
    if (instance) {
4313 jermar 209
        instance->thread = thread_create(kskipoll, instance, TASK, 0,
210
            "kskipoll", true);
4311 decky 211
 
212
        if (!instance->thread) {
213
            free(instance);
214
            return NULL;
215
        }
216
 
217
        instance->srlnin = NULL;
218
    }
219
 
220
    return instance;
4114 jermar 221
}
577 palkovsky 222
 
4311 decky 223
void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
4114 jermar 224
{
4311 decky 225
    ASSERT(instance);
226
    ASSERT(srlnin);
227
 
228
    instance->srlnin = srlnin;
229
    thread_ready(instance->thread);
230
 
1942 jermar 231
    sysinfo_set_item_val("kbd", NULL, true);
3657 vana 232
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
4114 jermar 233
}
234
 
1942 jermar 235
void ski_kbd_grab(void)
236
{
4581 mejdrech 237
    kbd_disabled = false;
1942 jermar 238
}
239
 
240
void ski_kbd_release(void)
241
{
4581 mejdrech 242
    kbd_disabled = true;
1942 jermar 243
}
244
 
1888 jermar 245
/** @}
1702 cejka 246
 */