Subversion Repositories HelenOS

Rev

Rev 4348 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4348 Rev 4389
1
/*
1
/*
2
 * Copyright (c) 2005 Jakub Jermar
2
 * Copyright (c) 2005 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup ia64
29
/** @addtogroup ia64
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/drivers/ski.h>
35
#include <arch/drivers/ski.h>
36
#include <console/console.h>
36
#include <console/console.h>
37
#include <console/chardev.h>
37
#include <console/chardev.h>
38
#include <sysinfo/sysinfo.h>
38
#include <sysinfo/sysinfo.h>
39
#include <arch/types.h>
39
#include <arch/types.h>
40
#include <proc/thread.h>
40
#include <proc/thread.h>
41
#include <synch/spinlock.h>
41
#include <synch/spinlock.h>
42
#include <arch/asm.h>
42
#include <arch/asm.h>
43
#include <arch/drivers/kbd.h>
43
#include <arch/drivers/kbd.h>
44
#include <string.h>
44
#include <string.h>
45
#include <arch.h>
45
#include <arch.h>
46
 
46
 
-
 
47
enum {
-
 
48
    /** Interval between polling in microseconds */
47
#define POLL_INTERVAL  10000  /* 10 ms */
49
    POLL_INTERVAL =  10000,  /* 0.01 s */
-
 
50
 
-
 
51
    /** Max. number of characters to pull out at a time */
-
 
52
    POLL_LIMIT    =     30,
48
 
53
 
49
#define SKI_INIT_CONSOLE  20
54
    SKI_INIT_CONSOLE  = 20,
50
#define SKI_GETCHAR       21
55
    SKI_GETCHAR       = 21,
51
#define SKI_PUTCHAR       31
56
    SKI_PUTCHAR       = 31
-
 
57
};
52
 
58
 
53
static void ski_putchar(outdev_t *, const wchar_t, bool);
59
static void ski_putchar(outdev_t *, const wchar_t, bool);
54
 
60
 
55
static outdev_operations_t skiout_ops = {
61
static outdev_operations_t skiout_ops = {
56
    .write = ski_putchar
62
    .write = ski_putchar
57
};
63
};
58
 
64
 
59
static outdev_t skiout;            /**< Ski output device. */
65
static outdev_t skiout;            /**< Ski output device. */
60
static bool initialized = false;
66
static bool initialized = false;
61
static bool kbd_disabled = false;
67
static bool kbd_disabled = false;
62
 
68
 
63
/** Initialize debug console
69
/** Initialize debug console
64
 *
70
 *
65
 * Issue SSC (Simulator System Call) to
71
 * Issue SSC (Simulator System Call) to
66
 * to open debug console.
72
 * to open debug console.
67
 *
73
 *
68
 */
74
 */
69
static void ski_init(void)
75
static void ski_init(void)
70
{
76
{
71
    if (initialized)
77
    if (initialized)
72
        return;
78
        return;
73
   
79
   
74
    asm volatile (
80
    asm volatile (
75
        "mov r15 = %0\n"
81
        "mov r15 = %0\n"
76
        "break 0x80000\n"
82
        "break 0x80000\n"
77
        :
83
        :
78
        : "i" (SKI_INIT_CONSOLE)
84
        : "i" (SKI_INIT_CONSOLE)
79
        : "r15", "r8"
85
        : "r15", "r8"
80
    );
86
    );
81
   
87
   
82
    initialized = true;
88
    initialized = true;
83
}
89
}
84
 
90
 
85
static void ski_do_putchar(const wchar_t ch)
91
static void ski_do_putchar(const wchar_t ch)
86
{
92
{
87
    asm volatile (
93
    asm volatile (
88
        "mov r15 = %[cmd]\n"
94
        "mov r15 = %[cmd]\n"
89
        "mov r32 = %[ch]\n"   /* r32 is in0 */
95
        "mov r32 = %[ch]\n"   /* r32 is in0 */
90
        "break 0x80000\n"     /* modifies r8 */
96
        "break 0x80000\n"     /* modifies r8 */
91
        :
97
        :
92
        : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
98
        : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
93
        : "r15", "in0", "r8"
99
        : "r15", "in0", "r8"
94
    );
100
    );
95
}
101
}
96
 
102
 
97
/** Display character on debug console
103
/** Display character on debug console
98
 *
104
 *
99
 * Use SSC (Simulator System Call) to
105
 * Use SSC (Simulator System Call) to
100
 * display character on debug console.
106
 * display character on debug console.
101
 *
107
 *
102
 * @param dev    Character device.
108
 * @param dev    Character device.
103
 * @param ch     Character to be printed.
109
 * @param ch     Character to be printed.
104
 * @param silent Whether the output should be silenced.
110
 * @param silent Whether the output should be silenced.
105
 *
111
 *
106
 */
112
 */
107
static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
113
static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
108
{
114
{
109
    if (!silent) {
115
    if (!silent) {
110
        if (ascii_check(ch)) {
116
        if (ascii_check(ch)) {
111
            if (ch == '\n')
117
            if (ch == '\n')
112
                ski_do_putchar('\r');
118
                ski_do_putchar('\r');
113
           
119
           
114
            ski_do_putchar(ch);
120
            ski_do_putchar(ch);
115
        } else
121
        } else
116
            ski_do_putchar(U_SPECIAL);
122
            ski_do_putchar(U_SPECIAL);
117
    }
123
    }
118
}
124
}
119
 
125
 
120
void skiout_init(void)
126
void skiout_init(void)
121
{
127
{
122
    ski_init();
128
    ski_init();
123
   
129
   
124
    outdev_initialize("skiout", &skiout, &skiout_ops);
130
    outdev_initialize("skiout", &skiout, &skiout_ops);
125
    stdout = &skiout;
131
    stdout = &skiout;
126
   
132
   
127
    sysinfo_set_item_val("fb", NULL, false);
133
    sysinfo_set_item_val("fb", NULL, false);
128
}
134
}
129
 
135
 
130
/** Ask debug console if a key was pressed.
136
/** Ask debug console if a key was pressed.
131
 *
137
 *
132
 * Use SSC (Simulator System Call) to
138
 * Use SSC (Simulator System Call) to
133
 * get character from debug console.
139
 * get character from debug console.
134
 *
140
 *
135
 * This call is non-blocking.
141
 * This call is non-blocking.
136
 *
142
 *
137
 * @return ASCII code of pressed key or 0 if no key pressed.
143
 * @return ASCII code of pressed key or 0 if no key pressed.
138
 *
144
 *
139
 */
145
 */
140
static wchar_t ski_getchar(void)
146
static wchar_t ski_getchar(void)
141
{
147
{
142
    uint64_t ch;
148
    uint64_t ch;
143
   
149
   
144
    asm volatile (
150
    asm volatile (
145
        "mov r15 = %1\n"
151
        "mov r15 = %1\n"
146
        "break 0x80000;;\n"  /* modifies r8 */
152
        "break 0x80000;;\n"  /* modifies r8 */
147
        "mov %0 = r8;;\n"
153
        "mov %0 = r8;;\n"
148
       
154
       
149
        : "=r" (ch)
155
        : "=r" (ch)
150
        : "i" (SKI_GETCHAR)
156
        : "i" (SKI_GETCHAR)
151
        : "r15", "r8"
157
        : "r15", "r8"
152
    );
158
    );
153
   
159
   
154
    return (wchar_t) ch;
160
    return (wchar_t) ch;
155
}
161
}
156
 
162
 
157
/** Ask keyboard if a key was pressed. */
163
/** Ask keyboard if a key was pressed.
-
 
164
 *
-
 
165
 * If so, it will repeat and pull up to POLL_LIMIT characters.
-
 
166
 */
158
static void poll_keyboard(ski_instance_t *instance)
167
static void poll_keyboard(ski_instance_t *instance)
159
{
168
{
-
 
169
    wchar_t ch;
-
 
170
    int count;
-
 
171
 
160
    if (kbd_disabled)
172
    if (kbd_disabled)
161
        return;
173
        return;
-
 
174
 
-
 
175
    count = POLL_LIMIT;
162
   
176
 
-
 
177
    while (count > 0) {
163
    wchar_t ch = ski_getchar();
178
        ch = ski_getchar();
164
   
179
 
165
    if (ch != 0)
180
        if (ch == '\0')
-
 
181
            break;
-
 
182
 
166
        indev_push_character(instance->srlnin, ch);
183
        indev_push_character(instance->srlnin, ch);
-
 
184
        --count;
-
 
185
    }
167
}
186
}
168
 
187
 
169
/** Kernel thread for polling keyboard. */
188
/** Kernel thread for polling keyboard. */
170
static void kskipoll(void *arg)
189
static void kskipoll(void *arg)
171
{
190
{
172
    ski_instance_t *instance = (ski_instance_t *) arg;
191
    ski_instance_t *instance = (ski_instance_t *) arg;
173
   
192
   
174
    while (true) {
193
    while (true) {
175
        if (!silent)
194
        if (!silent)
176
            poll_keyboard(instance);
195
            poll_keyboard(instance);
177
       
196
       
178
        thread_usleep(POLL_INTERVAL);
197
        thread_usleep(POLL_INTERVAL);
179
    }
198
    }
180
}
199
}
181
 
200
 
182
ski_instance_t *skiin_init(void)
201
ski_instance_t *skiin_init(void)
183
{
202
{
184
    ski_init();
203
    ski_init();
185
   
204
   
186
    ski_instance_t *instance =
205
    ski_instance_t *instance =
187
        malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
206
        malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
188
   
207
   
189
    if (instance) {
208
    if (instance) {
190
        instance->thread = thread_create(kskipoll, instance, TASK, 0,
209
        instance->thread = thread_create(kskipoll, instance, TASK, 0,
191
            "kskipoll", true);
210
            "kskipoll", true);
192
       
211
       
193
        if (!instance->thread) {
212
        if (!instance->thread) {
194
            free(instance);
213
            free(instance);
195
            return NULL;
214
            return NULL;
196
        }
215
        }
197
       
216
       
198
        instance->srlnin = NULL;
217
        instance->srlnin = NULL;
199
    }
218
    }
200
   
219
   
201
    return instance;
220
    return instance;
202
}
221
}
203
 
222
 
204
void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
223
void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
205
{
224
{
206
    ASSERT(instance);
225
    ASSERT(instance);
207
    ASSERT(srlnin);
226
    ASSERT(srlnin);
208
   
227
   
209
    instance->srlnin = srlnin;
228
    instance->srlnin = srlnin;
210
    thread_ready(instance->thread);
229
    thread_ready(instance->thread);
211
   
230
   
212
    sysinfo_set_item_val("kbd", NULL, true);
231
    sysinfo_set_item_val("kbd", NULL, true);
213
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
232
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
214
}
233
}
215
 
234
 
216
void ski_kbd_grab(void)
235
void ski_kbd_grab(void)
217
{
236
{
218
    kbd_disabled = false;
237
    kbd_disabled = false;
219
}
238
}
220
 
239
 
221
void ski_kbd_release(void)
240
void ski_kbd_release(void)
222
{
241
{
223
    kbd_disabled = true;
242
    kbd_disabled = true;
224
}
243
}
225
 
244
 
226
/** @}
245
/** @}
227
 */
246
 */
228
 
247