Subversion Repositories HelenOS-historic

Rev

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

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