Subversion Repositories HelenOS

Rev

Rev 4223 | Rev 4313 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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