Subversion Repositories HelenOS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2215 kebrt 1
/*
2
 * Copyright (c) 2005-2007 Ondrej Palkovsky, Michal Kebrt
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
/** @addtogroup arm32
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
#include <interrupt.h>
36
#include <ipc/irq.h>
37
#include <console/chardev.h>
38
#include <arch/drivers/gxemul.h>
39
#include <console/console.h>
40
#include <sysinfo/sysinfo.h>
41
#include <print.h>
42
 
43
/** Address of devices. */
44
#define GXEMUL_VIDEORAM     0x10000000
45
#define GXEMUL_KBD_ADDRESS  0x10000000
46
#define GXEMUL_KBD_IRQ      0
47
 
48
static chardev_t console;
49
static irq_t gxemul_irq;
50
 
51
static void gxemul_write(chardev_t *dev, const char ch);
52
static void gxemul_enable(chardev_t *dev);
53
static void gxemul_disable(chardev_t *dev);
54
static char gxemul_do_read(chardev_t *dev);
55
 
56
static chardev_operations_t gxemul_ops = {
57
    .resume = gxemul_enable,
58
    .suspend = gxemul_disable,
59
    .write = gxemul_write,
60
    .read = gxemul_do_read,
61
};
62
 
63
/** Putchar that works with gxemul */
64
void gxemul_write(chardev_t *dev, const char ch)
65
{
66
    *((char *) GXEMUL_VIDEORAM) = ch;
67
}
68
 
69
/* Called from getc(). */
70
void gxemul_enable(chardev_t *dev)
71
{
72
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
73
}
74
 
75
/* Called from getc(). */
76
void gxemul_disable(chardev_t *dev)
77
{
78
//  cp0_mask_int(GXEMUL_KBD_IRQ);
79
}
80
 
81
/** Read character using polling, assume interrupts disabled */
82
static char gxemul_do_read(chardev_t *dev)
83
{
84
    char ch;
85
 
86
    while (1) {
87
        ch = *((volatile char *) GXEMUL_KBD_ADDRESS);
88
        if (ch) {
89
            if (ch == '\r')
90
                return '\n';
91
            if (ch == 0x7f)
92
                return '\b';
93
            return ch;
94
        }
95
    }
96
}
97
 
98
/** Process keyboard interrupt. */
99
static void gxemul_irq_handler(irq_t *irq, void *arg, ...)
100
{
101
    if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox))
102
        ipc_irq_send_notif(irq);
103
    else {
104
        char ch = 0;
105
 
106
            ch = *((char *) GXEMUL_KBD_ADDRESS);
107
            if (ch =='\r')
108
                ch = '\n';
109
            if (ch == 0x7f)
110
                ch = '\b';
111
            chardev_push_character(&console, ch);
112
    }
113
}
114
 
115
static irq_ownership_t gxemul_claim(void)
116
{
117
    return IRQ_ACCEPT;
118
}
119
 
120
void gxemul_kbd_grab(void)
121
{
122
    ipl_t ipl = interrupts_disable();
123
    spinlock_lock(&msim_irq.lock);
124
    gxemul_irq.notif_cfg.notify = false;
125
    spinlock_unlock(&gxemul_irq.lock);
126
    interrupts_restore(ipl);
127
}
128
 
129
void gxemul_kbd_release(void)
130
{
131
    ipl_t ipl = interrupts_disable();
132
    spinlock_lock(&gxemul_irq.lock);
133
    if (gxemul_irq.notif_cfg.answerbox)
134
        gxemul_irq.notif_cfg.notify = true;
135
    spinlock_unlock(&gxemul_irq.lock);
136
    interrupts_restore(ipl);
137
}
138
 
139
 
140
/* Return console object representing msim console */
141
void gxemul_console(devno_t devno)
142
{
143
    chardev_initialize("msim_console", &console, &gxemul_ops);
144
    stdin = &console;
145
    stdout = &console;
146
 
147
    irq_initialize(&gxemul_irq);
148
    gxemul_irq.devno = devno;
149
    gxemul_irq.inr = GXEMUL_KBD_IRQ;
150
    gxemul_irq.claim = gxemul_claim;
151
    gxemul_irq.handler = gxemul_irq_handler;
152
    irq_register(&gxemul_irq);
153
 
154
//  cp0_unmask_int(GXEMUL_KBD_IRQ);
155
 
156
    sysinfo_set_item_val("kbd", NULL, true);
157
    sysinfo_set_item_val("kbd.devno", NULL, devno);
158
    sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
159
    sysinfo_set_item_val("kbd.address.virtual", NULL, GXEMUL_KBD_ADDRESS);
160
}
161
 
162
/** @}
163
 */