Subversion Repositories HelenOS

Rev

Rev 4153 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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