Subversion Repositories HelenOS-historic

Rev

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