Subversion Repositories HelenOS-historic

Rev

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

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