Subversion Repositories HelenOS-historic

Rev

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

Rev 1507 Rev 1570
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
#include <arch/ski/ski.h>
29
#include <arch/ski/ski.h>
30
#include <console/console.h>
30
#include <console/console.h>
31
#include <console/chardev.h>
31
#include <console/chardev.h>
32
#include <arch/interrupt.h>
32
#include <arch/interrupt.h>
33
#include <sysinfo/sysinfo.h>
33
#include <sysinfo/sysinfo.h>
34
 
34
 
35
chardev_t ski_console;
35
chardev_t ski_console;
36
chardev_t ski_uconsole;
36
chardev_t ski_uconsole;
37
static bool kb_disable;
37
static bool kb_disable;
38
int kbd_uspace=0;
38
int kbd_uspace=0;
39
 
39
 
40
static void ski_putchar(chardev_t *d, const char ch);
40
static void ski_putchar(chardev_t *d, const char ch);
41
static __s32 ski_getchar(void);
41
static __s32 ski_getchar(void);
42
 
42
 
43
/** Display character on debug console
43
/** Display character on debug console
44
 *
44
 *
45
 * Use SSC (Simulator System Call) to
45
 * Use SSC (Simulator System Call) to
46
 * display character on debug console.
46
 * display character on debug console.
47
 *
47
 *
48
 * @param d Character device.
48
 * @param d Character device.
49
 * @param ch Character to be printed.
49
 * @param ch Character to be printed.
50
 */
50
 */
51
void ski_putchar(chardev_t *d, const char ch)
51
void ski_putchar(chardev_t *d, const char ch)
52
{
52
{
53
    __asm__ volatile (
53
    __asm__ volatile (
54
        "mov r15=%0\n"
54
        "mov r15=%0\n"
55
        "mov r32=%1\n"      /* r32 is in0 */
55
        "mov r32=%1\n"      /* r32 is in0 */
56
        "break 0x80000\n"   /* modifies r8 */
56
        "break 0x80000\n"   /* modifies r8 */
57
        :
57
        :
58
        : "i" (SKI_PUTCHAR), "r" (ch)
58
        : "i" (SKI_PUTCHAR), "r" (ch)
59
        : "r15", "in0", "r8"
59
        : "r15", "in0", "r8"
60
    );
60
    );
61
   
61
   
62
    if (ch == '\n')
62
    if (ch == '\n')
63
        ski_putchar(d, '\r');
63
        ski_putchar(d, '\r');
64
}
64
}
65
 
65
 
66
/** Ask debug console if a key was pressed.
66
/** Ask debug console if a key was pressed.
67
 *
67
 *
68
 * Use SSC (Simulator System Call) to
68
 * Use SSC (Simulator System Call) to
69
 * get character from debug console.
69
 * get character from debug console.
70
 *
70
 *
71
 * This call is non-blocking.
71
 * This call is non-blocking.
72
 *
72
 *
73
 * @return ASCII code of pressed key or 0 if no key pressed.
73
 * @return ASCII code of pressed key or 0 if no key pressed.
74
 */
74
 */
75
__s32 ski_getchar(void)
75
__s32 ski_getchar(void)
76
{
76
{
77
    __u64 ch;
77
    __u64 ch;
78
   
78
   
79
    __asm__ volatile (
79
    __asm__ volatile (
80
        "mov r15=%1\n"
80
        "mov r15=%1\n"
81
        "break 0x80000;;\n" /* modifies r8 */
81
        "break 0x80000;;\n" /* modifies r8 */
82
        "mov %0=r8;;\n"    
82
        "mov %0=r8;;\n"    
83
 
83
 
84
        : "=r" (ch)
84
        : "=r" (ch)
85
        : "i" (SKI_GETCHAR)
85
        : "i" (SKI_GETCHAR)
86
        : "r15",  "r8"
86
        : "r15",  "r8"
87
    );
87
    );
88
 
88
 
89
    return (__s32) ch;
89
    return (__s32) ch;
90
}
90
}
91
 
91
 
92
/**
92
/**
93
 * This is a blocking wrapper for ski_getchar().
93
 * This is a blocking wrapper for ski_getchar().
94
 * To be used when the kernel crashes.
94
 * To be used when the kernel crashes.
95
 */
95
 */
96
static char ski_getchar_blocking(chardev_t *d)
96
static char ski_getchar_blocking(chardev_t *d)
97
{
97
{
98
    int ch;
98
    int ch;
99
 
99
 
100
    while(!(ch=ski_getchar()))
100
    while(!(ch=ski_getchar()))
101
        ;
101
        ;
102
    if(ch == '\r')
102
    if(ch == '\r')
103
        ch = '\n';
103
        ch = '\n';
104
    return (char) ch;
104
    return (char) ch;
105
}
105
}
106
 
106
 
107
/** Ask keyboard if a key was pressed. */
107
/** Ask keyboard if a key was pressed. */
108
void poll_keyboard(void)
108
void poll_keyboard(void)
109
{
109
{
110
    char ch;
110
    char ch;
-
 
111
    static char last;
111
 
112
 
112
    if (kb_disable)
113
    if (kb_disable)
113
        return;
114
        return;
114
 
115
 
115
    ch = ski_getchar();
116
    ch = ski_getchar();
116
    if(ch == '\r')
117
    if(ch == '\r')
117
        ch = '\n';
118
        ch = '\n';
118
    if (ch){
119
    if (ch){
119
        if(kbd_uspace){
120
        if(kbd_uspace){
120
            chardev_push_character(&ski_uconsole, ch);
121
            chardev_push_character(&ski_uconsole, ch);
121
            virtual_interrupt(IRQ_KBD,NULL);
122
            virtual_interrupt(IRQ_KBD,NULL);
122
        }
123
        }
123
        else {
124
        else {
124
            chardev_push_character(&ski_console, ch);
125
            chardev_push_character(&ski_console, ch);
-
 
126
        }  
-
 
127
        last = ch;     
-
 
128
        return;
-
 
129
    }  
125
 
130
 
-
 
131
    if (last){
-
 
132
        if(kbd_uspace){
-
 
133
            chardev_push_character(&ski_uconsole, 0);
-
 
134
            virtual_interrupt(IRQ_KBD,NULL);
-
 
135
        }
-
 
136
        else {
126
        }  
137
        }  
127
       
138
        last = 0;      
128
    }  
139
    }  
-
 
140
 
129
}
141
}
130
 
142
 
131
/* Called from getc(). */
143
/* Called from getc(). */
132
static void ski_kb_enable(chardev_t *d)
144
static void ski_kb_enable(chardev_t *d)
133
{
145
{
134
    kb_disable = false;
146
    kb_disable = false;
135
}
147
}
136
 
148
 
137
/* Called from getc(). */
149
/* Called from getc(). */
138
static void ski_kb_disable(chardev_t *d)
150
static void ski_kb_disable(chardev_t *d)
139
{
151
{
140
    kb_disable = true; 
152
    kb_disable = true; 
141
}
153
}
142
 
154
 
143
 
155
 
144
static chardev_operations_t ski_ops = {
156
static chardev_operations_t ski_ops = {
145
    .resume = ski_kb_enable,
157
    .resume = ski_kb_enable,
146
    .suspend = ski_kb_disable,
158
    .suspend = ski_kb_disable,
147
    .write = ski_putchar,
159
    .write = ski_putchar,
148
    .read = ski_getchar_blocking
160
    .read = ski_getchar_blocking
149
};
161
};
150
 
162
 
151
 
163
 
152
/** Initialize debug console
164
/** Initialize debug console
153
 *
165
 *
154
 * Issue SSC (Simulator System Call) to
166
 * Issue SSC (Simulator System Call) to
155
 * to open debug console.
167
 * to open debug console.
156
 */
168
 */
157
void ski_init_console(void)
169
void ski_init_console(void)
158
{
170
{
159
    __asm__ volatile (
171
    __asm__ volatile (
160
        "mov r15=%0\n"
172
        "mov r15=%0\n"
161
        "break 0x80000\n"
173
        "break 0x80000\n"
162
        :
174
        :
163
        : "i" (SKI_INIT_CONSOLE)
175
        : "i" (SKI_INIT_CONSOLE)
164
        : "r15", "r8"
176
        : "r15", "r8"
165
    );
177
    );
166
 
178
 
167
    chardev_initialize("ski_console", &ski_console, &ski_ops);
179
    chardev_initialize("ski_console", &ski_console, &ski_ops);
168
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
180
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
169
    stdin = &ski_console;
181
    stdin = &ski_console;
170
    stdout = &ski_console;
182
    stdout = &ski_console;
171
 
183
 
172
}
184
}
173
/** Setup console sysinfo (i.e. Keyboard IRQ)
185
/** Setup console sysinfo (i.e. Keyboard IRQ)
174
 *
186
 *
175
 * Because sysinfo neads memory allocation/dealocation
187
 * Because sysinfo neads memory allocation/dealocation
176
 * this functions should be called separetely from init.
188
 * this functions should be called separetely from init.
177
 *
189
 *
178
 */
190
 */
179
void ski_set_console_sysinfo(void)
191
void ski_set_console_sysinfo(void)
180
{
192
{
181
    sysinfo_set_item_val("kbd",NULL,true);
193
    sysinfo_set_item_val("kbd",NULL,true);
182
    sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
194
    sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
183
}
195
}
184
 
196