Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
78 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1702 cejka 29
 /** @addtogroup ia64  
30
 * @{
31
 */
32
/** @file
33
 */
34
 
78 jermar 35
#include <arch/ski/ski.h>
577 palkovsky 36
#include <console/console.h>
37
#include <console/chardev.h>
1507 vana 38
#include <arch/interrupt.h>
39
#include <sysinfo/sysinfo.h>
78 jermar 40
 
1507 vana 41
chardev_t ski_console;
42
chardev_t ski_uconsole;
577 palkovsky 43
static bool kb_disable;
1507 vana 44
int kbd_uspace=0;
78 jermar 45
 
586 jermar 46
static void ski_putchar(chardev_t *d, const char ch);
1780 jermar 47
static int32_t ski_getchar(void);
583 jermar 48
 
79 jermar 49
/** Display character on debug console
50
 *
51
 * Use SSC (Simulator System Call) to
52
 * display character on debug console.
53
 *
583 jermar 54
 * @param d Character device.
55
 * @param ch Character to be printed.
79 jermar 56
 */
586 jermar 57
void ski_putchar(chardev_t *d, const char ch)
78 jermar 58
{
892 vana 59
    __asm__ volatile (
78 jermar 60
        "mov r15=%0\n"
61
        "mov r32=%1\n"      /* r32 is in0 */
62
        "break 0x80000\n"   /* modifies r8 */
63
        :
64
        : "i" (SKI_PUTCHAR), "r" (ch)
65
        : "r15", "in0", "r8"
66
    );
67
 
583 jermar 68
    if (ch == '\n')
586 jermar 69
        ski_putchar(d, '\r');
78 jermar 70
}
519 vana 71
 
523 jermar 72
/** Ask debug console if a key was pressed.
519 vana 73
 *
74
 * Use SSC (Simulator System Call) to
75
 * get character from debug console.
523 jermar 76
 *
77
 * This call is non-blocking.
78
 *
79
 * @return ASCII code of pressed key or 0 if no key pressed.
519 vana 80
 */
1780 jermar 81
int32_t ski_getchar(void)
519 vana 82
{
1780 jermar 83
    uint64_t ch;
519 vana 84
 
892 vana 85
    __asm__ volatile (
584 jermar 86
        "mov r15=%1\n"
519 vana 87
        "break 0x80000;;\n" /* modifies r8 */
584 jermar 88
        "mov %0=r8;;\n"    
519 vana 89
 
584 jermar 90
        : "=r" (ch)
91
        : "i" (SKI_GETCHAR)
519 vana 92
        : "r15",  "r8"
93
    );
94
 
1780 jermar 95
    return (int32_t) ch;
519 vana 96
}
577 palkovsky 97
 
892 vana 98
/**
893 jermar 99
 * This is a blocking wrapper for ski_getchar().
100
 * To be used when the kernel crashes.
101
 */
892 vana 102
static char ski_getchar_blocking(chardev_t *d)
103
{
893 jermar 104
    int ch;
105
 
106
    while(!(ch=ski_getchar()))
107
        ;
108
    if(ch == '\r')
109
        ch = '\n';
892 vana 110
    return (char) ch;
111
}
112
 
577 palkovsky 113
/** Ask keyboard if a key was pressed. */
114
void poll_keyboard(void)
115
{
116
    char ch;
1570 vana 117
    static char last;
577 palkovsky 118
 
119
    if (kb_disable)
120
        return;
121
 
122
    ch = ski_getchar();
123
    if(ch == '\r')
124
        ch = '\n';
1507 vana 125
    if (ch){
126
        if(kbd_uspace){
127
            chardev_push_character(&ski_uconsole, ch);
128
            virtual_interrupt(IRQ_KBD,NULL);
129
        }
130
        else {
131
            chardev_push_character(&ski_console, ch);
1570 vana 132
        }  
133
        last = ch;     
134
        return;
135
    }  
1507 vana 136
 
1570 vana 137
    if (last){
138
        if(kbd_uspace){
139
            chardev_push_character(&ski_uconsole, 0);
140
            virtual_interrupt(IRQ_KBD,NULL);
141
        }
142
        else {
1507 vana 143
        }  
1570 vana 144
        last = 0;      
1507 vana 145
    }  
1570 vana 146
 
577 palkovsky 147
}
148
 
149
/* Called from getc(). */
583 jermar 150
static void ski_kb_enable(chardev_t *d)
577 palkovsky 151
{
152
    kb_disable = false;
153
}
154
 
155
/* Called from getc(). */
156
static void ski_kb_disable(chardev_t *d)
157
{
158
    kb_disable = true; 
159
}
160
 
161
 
162
static chardev_operations_t ski_ops = {
163
    .resume = ski_kb_enable,
164
    .suspend = ski_kb_disable,
892 vana 165
    .write = ski_putchar,
166
    .read = ski_getchar_blocking
577 palkovsky 167
};
168
 
169
 
170
/** Initialize debug console
171
 *
172
 * Issue SSC (Simulator System Call) to
173
 * to open debug console.
174
 */
175
void ski_init_console(void)
176
{
892 vana 177
    __asm__ volatile (
577 palkovsky 178
        "mov r15=%0\n"
179
        "break 0x80000\n"
180
        :
181
        : "i" (SKI_INIT_CONSOLE)
182
        : "r15", "r8"
183
    );
184
 
185
    chardev_initialize("ski_console", &ski_console, &ski_ops);
1507 vana 186
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
577 palkovsky 187
    stdin = &ski_console;
188
    stdout = &ski_console;
1507 vana 189
 
577 palkovsky 190
}
1507 vana 191
/** Setup console sysinfo (i.e. Keyboard IRQ)
192
 *
193
 * Because sysinfo neads memory allocation/dealocation
194
 * this functions should be called separetely from init.
195
 *
196
 */
197
void ski_set_console_sysinfo(void)
198
{
199
    sysinfo_set_item_val("kbd",NULL,true);
200
    sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
201
}
1702 cejka 202
 
203
 /** @}
204
 */
205