Subversion Repositories HelenOS

Rev

Rev 1888 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1888 Rev 1942
Line 35... Line 35...
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 <arch/interrupt.h>
38
#include <arch/interrupt.h>
39
#include <sysinfo/sysinfo.h>
39
#include <sysinfo/sysinfo.h>
-
 
40
#include <arch/types.h>
-
 
41
#include <typedefs.h>
-
 
42
#include <ddi/device.h>
-
 
43
#include <ddi/irq.h>
-
 
44
#include <ipc/irq.h>
-
 
45
#include <synch/spinlock.h>
-
 
46
#include <arch/asm.h>
-
 
47
 
-
 
48
#define SKI_KBD_INR 0
-
 
49
 
-
 
50
static irq_t ski_kbd_irq;
-
 
51
static devno_t ski_kbd_devno;
40
 
52
 
41
chardev_t ski_console;
53
chardev_t ski_console;
42
chardev_t ski_uconsole;
54
chardev_t ski_uconsole;
-
 
55
 
43
static bool kb_disable;
56
static bool kbd_disabled;
44
int kbd_uspace=0;
-
 
45
 
57
 
46
static void ski_putchar(chardev_t *d, const char ch);
58
static void ski_putchar(chardev_t *d, const char ch);
47
static int32_t ski_getchar(void);
59
static int32_t ski_getchar(void);
48
 
60
 
49
/** Display character on debug console
61
/** Display character on debug console
Line 55... Line 67...
55
 * @param ch Character to be printed.
67
 * @param ch Character to be printed.
56
 */
68
 */
57
void ski_putchar(chardev_t *d, const char ch)
69
void ski_putchar(chardev_t *d, const char ch)
58
{
70
{
59
    __asm__ volatile (
71
    __asm__ volatile (
60
        "mov r15=%0\n"
72
        "mov r15 = %0\n"
61
        "mov r32=%1\n"      /* r32 is in0 */
73
        "mov r32 = %1\n"    /* r32 is in0 */
62
        "break 0x80000\n"   /* modifies r8 */
74
        "break 0x80000\n"   /* modifies r8 */
63
        :
75
        :
64
        : "i" (SKI_PUTCHAR), "r" (ch)
76
        : "i" (SKI_PUTCHAR), "r" (ch)
65
        : "r15", "in0", "r8"
77
        : "r15", "in0", "r8"
66
    );
78
    );
Line 81... Line 93...
81
int32_t ski_getchar(void)
93
int32_t ski_getchar(void)
82
{
94
{
83
    uint64_t ch;
95
    uint64_t ch;
84
   
96
   
85
    __asm__ volatile (
97
    __asm__ volatile (
86
        "mov r15=%1\n"
98
        "mov r15 = %1\n"
87
        "break 0x80000;;\n" /* modifies r8 */
99
        "break 0x80000;;\n" /* modifies r8 */
88
        "mov %0=r8;;\n"    
100
        "mov %0 = r8;;\n"      
89
 
101
 
90
        : "=r" (ch)
102
        : "=r" (ch)
91
        : "i" (SKI_GETCHAR)
103
        : "i" (SKI_GETCHAR)
92
        : "r15",  "r8"
104
        : "r15", "r8"
93
    );
105
    );
94
 
106
 
95
    return (int32_t) ch;
107
    return (int32_t) ch;
96
}
108
}
97
 
109
 
Line 101... Line 113...
101
 */
113
 */
102
static char ski_getchar_blocking(chardev_t *d)
114
static char ski_getchar_blocking(chardev_t *d)
103
{
115
{
104
    int ch;
116
    int ch;
105
 
117
 
106
    while(!(ch=ski_getchar()))
118
    while(!(ch = ski_getchar()))
107
        ;
119
        ;
108
    if(ch == '\r')
120
    if(ch == '\r')
109
        ch = '\n';
121
        ch = '\n';
110
    return (char) ch;
122
    return (char) ch;
111
}
123
}
Line 113... Line 125...
113
/** Ask keyboard if a key was pressed. */
125
/** Ask keyboard if a key was pressed. */
114
void poll_keyboard(void)
126
void poll_keyboard(void)
115
{
127
{
116
    char ch;
128
    char ch;
117
    static char last;
129
    static char last;
-
 
130
    ipl_t ipl;
-
 
131
 
-
 
132
    ipl = interrupts_disable();
118
 
133
 
119
    if (kb_disable)
134
    if (kbd_disabled) {
-
 
135
        interrupts_restore(ipl);
120
        return;
136
        return;
-
 
137
    }
-
 
138
       
-
 
139
    spinlock_lock(&ski_kbd_irq.lock);
121
 
140
 
122
    ch = ski_getchar();
141
    ch = ski_getchar();
123
    if(ch == '\r')
142
    if(ch == '\r')
124
        ch = '\n';
143
        ch = '\n';
125
    if (ch){
144
    if (ch) {
126
        if(kbd_uspace){
145
        if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) {
127
            chardev_push_character(&ski_uconsole, ch);
146
            chardev_push_character(&ski_uconsole, ch);
128
            virtual_interrupt(IRQ_KBD,NULL);
147
            ipc_irq_send_notif(&ski_kbd_irq);
129
        }
-
 
130
        else {
148
        } else {
131
            chardev_push_character(&ski_console, ch);
149
            chardev_push_character(&ski_console, ch);
132
        }  
150
        }  
133
        last = ch;     
151
        last = ch;
-
 
152
        spinlock_unlock(&ski_kbd_irq.lock);
-
 
153
        interrupts_restore(ipl);
134
        return;
154
        return;
135
    }  
155
    }
136
 
156
 
137
    if (last){
157
    if (last) {
138
        if(kbd_uspace){
158
        if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) {
139
            chardev_push_character(&ski_uconsole, 0);
159
            chardev_push_character(&ski_uconsole, 0);
140
            virtual_interrupt(IRQ_KBD,NULL);
160
            ipc_irq_send_notif(&ski_kbd_irq);
141
        }
161
        }
142
        else {
-
 
143
        }  
-
 
144
        last = 0;      
162
        last = 0;
145
    }  
163
    }
146
 
164
 
-
 
165
    spinlock_unlock(&ski_kbd_irq.lock);
-
 
166
    interrupts_restore(ipl);
147
}
167
}
148
 
168
 
149
/* Called from getc(). */
169
/* Called from getc(). */
150
static void ski_kb_enable(chardev_t *d)
170
static void ski_kbd_enable(chardev_t *d)
151
{
171
{
152
    kb_disable = false;
172
    kbd_disabled = false;
153
}
173
}
154
 
174
 
155
/* Called from getc(). */
175
/* Called from getc(). */
156
static void ski_kb_disable(chardev_t *d)
176
static void ski_kbd_disable(chardev_t *d)
157
{
177
{
158
    kb_disable = true; 
178
    kbd_disabled = true;   
-
 
179
}
-
 
180
 
-
 
181
/** Decline to service hardware IRQ.
-
 
182
 *
-
 
183
 * This is only a virtual IRQ, so always decline.
-
 
184
 *
-
 
185
 * @return Always IRQ_DECLINE.
-
 
186
 */
-
 
187
static irq_ownership_t ski_kbd_claim(void)
-
 
188
{
-
 
189
    return IRQ_DECLINE;
159
}
190
}
160
 
191
 
161
static chardev_operations_t ski_ops = {
192
static chardev_operations_t ski_ops = {
162
    .resume = ski_kb_enable,
193
    .resume = ski_kbd_enable,
163
    .suspend = ski_kb_disable,
194
    .suspend = ski_kbd_disable,
164
    .write = ski_putchar,
195
    .write = ski_putchar,
165
    .read = ski_getchar_blocking
196
    .read = ski_getchar_blocking
166
};
197
};
167
 
198
 
168
/** Initialize debug console
199
/** Initialize debug console
Line 171... Line 202...
171
 * to open debug console.
202
 * to open debug console.
172
 */
203
 */
173
void ski_init_console(void)
204
void ski_init_console(void)
174
{
205
{
175
    __asm__ volatile (
206
    __asm__ volatile (
176
        "mov r15=%0\n"
207
        "mov r15 = %0\n"
177
        "break 0x80000\n"
208
        "break 0x80000\n"
178
        :
209
        :
179
        : "i" (SKI_INIT_CONSOLE)
210
        : "i" (SKI_INIT_CONSOLE)
180
        : "r15", "r8"
211
        : "r15", "r8"
181
    );
212
    );
Line 183... Line 214...
183
    chardev_initialize("ski_console", &ski_console, &ski_ops);
214
    chardev_initialize("ski_console", &ski_console, &ski_ops);
184
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
215
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
185
    stdin = &ski_console;
216
    stdin = &ski_console;
186
    stdout = &ski_console;
217
    stdout = &ski_console;
187
 
218
 
-
 
219
    ski_kbd_devno = device_assign_devno();
-
 
220
   
-
 
221
    irq_initialize(&ski_kbd_irq);
-
 
222
    ski_kbd_irq.inr = SKI_KBD_INR;
-
 
223
    ski_kbd_irq.devno = ski_kbd_devno;
-
 
224
    ski_kbd_irq.claim = ski_kbd_claim;
-
 
225
    irq_register(&ski_kbd_irq);
-
 
226
 
188
}
227
}
189
 
228
 
190
/** Setup console sysinfo (i.e. Keyboard IRQ)
229
/** Setup console sysinfo (i.e. Keyboard IRQ)
191
 *
230
 *
192
 * Because sysinfo neads memory allocation/dealocation
231
 * Because sysinfo neads memory allocation/dealocation
193
 * this functions should be called separetely from init.
232
 * this functions should be called separetely from init.
194
 *
233
 *
195
 */
234
 */
196
void ski_set_console_sysinfo(void)
235
void ski_set_console_sysinfo(void)
197
{
236
{
198
    sysinfo_set_item_val("kbd",NULL,true);
237
    sysinfo_set_item_val("kbd", NULL, true);
199
    sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
238
    sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR);
-
 
239
    sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno);
-
 
240
}
-
 
241
 
-
 
242
void ski_kbd_grab(void)
-
 
243
{
-
 
244
    ski_kbd_irq.notif_cfg.notify = false;
-
 
245
}
-
 
246
 
-
 
247
void ski_kbd_release(void)
-
 
248
{
-
 
249
    if (ski_kbd_irq.notif_cfg.answerbox)
-
 
250
        ski_kbd_irq.notif_cfg.notify = true;
200
}
251
}
201
 
252
 
202
/** @}
253
/** @}
203
 */
254
 */